From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f198.google.com (mail-pf0-f198.google.com [209.85.192.198]) by kanga.kvack.org (Postfix) with ESMTP id 9CF926B0038 for ; Wed, 22 Mar 2017 14:29:20 -0400 (EDT) Received: by mail-pf0-f198.google.com with SMTP id o126so366310545pfb.2 for ; Wed, 22 Mar 2017 11:29:20 -0700 (PDT) Received: from mailout4.w1.samsung.com (mailout4.w1.samsung.com. [210.118.77.14]) by mx.google.com with ESMTPS id g64si457060pfj.10.2017.03.22.11.29.19 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 Mar 2017 11:29:19 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0ON8002UWBCSBN10@mailout4.w1.samsung.com> for linux-mm@kvack.org; Wed, 22 Mar 2017 18:29:16 +0000 (GMT) From: Alexey Perevalov Subject: [PATCH v2] Illuminate thread id to user space Date: Wed, 22 Mar 2017 21:29:05 +0300 Message-id: <1490207346-9703-1-git-send-email-a.perevalov@samsung.com> References: Sender: owner-linux-mm@kvack.org List-ID: To: Andrea Arcangeli Cc: "Dr . David Alan Gilbert" , linux-mm@kvack.org, i.maximets@samsung.com, a.perevalov@samsung.com Hi Andrea, This is updated patch, difference since previous version is following: - process thread id is provided only when it was requested with UFFD_FEATURE_THREAD_ID bit. - pid from namespace is provided, so locking thread's gettid in namespace and msg.arg.pagefault.ptid will be equal. - current patch is based on git://git.kernel.org/pub/scm/linux/kernel/git/andrea/aa.git userfault branch too, but rebased. Alexey Perevalov (1): userfaultfd: provide pid in userfault msg fs/userfaultfd.c | 8 ++++++-- include/uapi/linux/userfaultfd.h | 8 +++++++- 2 files changed, 13 insertions(+), 3 deletions(-) -- 2.7.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f200.google.com (mail-pf0-f200.google.com [209.85.192.200]) by kanga.kvack.org (Postfix) with ESMTP id 187EC6B0337 for ; Wed, 22 Mar 2017 14:29:25 -0400 (EDT) Received: by mail-pf0-f200.google.com with SMTP id r89so45048575pfi.1 for ; Wed, 22 Mar 2017 11:29:25 -0700 (PDT) Received: from mailout3.w1.samsung.com (mailout3.w1.samsung.com. [210.118.77.13]) by mx.google.com with ESMTPS id s19si1941414pfg.28.2017.03.22.11.29.23 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 Mar 2017 11:29:24 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0ON8003SWBCWBC10@mailout3.w1.samsung.com> for linux-mm@kvack.org; Wed, 22 Mar 2017 18:29:20 +0000 (GMT) From: Alexey Perevalov Subject: [PATCH v2] userfaultfd: provide pid in userfault msg Date: Wed, 22 Mar 2017 21:29:06 +0300 Message-id: <1490207346-9703-2-git-send-email-a.perevalov@samsung.com> In-reply-to: <1490207346-9703-1-git-send-email-a.perevalov@samsung.com> References: <1490207346-9703-1-git-send-email-a.perevalov@samsung.com> Sender: owner-linux-mm@kvack.org List-ID: To: Andrea Arcangeli Cc: "Dr . David Alan Gilbert" , linux-mm@kvack.org, i.maximets@samsung.com, a.perevalov@samsung.com It could be useful for calculating downtime during postcopy live migration per vCPU. Side observer or application itself will be informed about proper task's sleep during userfaultfd processing. Process's thread id is being provided when user requeste it by setting UFFD_FEATURE_THREAD_ID bit into uffdio_api.features. Signed-off-by: Alexey Perevalov --- fs/userfaultfd.c | 8 ++++++-- include/uapi/linux/userfaultfd.h | 8 +++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 24fd7e0..14c30d4 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -180,7 +180,8 @@ static inline void msg_init(struct uffd_msg *msg) static inline struct uffd_msg userfault_msg(unsigned long address, unsigned int flags, - unsigned long reason) + unsigned long reason, + unsigned int features) { struct uffd_msg msg; msg_init(&msg); @@ -204,6 +205,8 @@ static inline struct uffd_msg userfault_msg(unsigned long address, * write protect fault. */ msg.arg.pagefault.flags |= UFFD_PAGEFAULT_FLAG_WP; + if (features & UFFD_FEATURE_THREAD_ID) + msg.arg.pagefault.ptid = task_pid_vnr(current); return msg; } @@ -408,7 +411,8 @@ int handle_userfault(struct vm_fault *vmf, unsigned long reason) init_waitqueue_func_entry(&uwq.wq, userfaultfd_wake_function); uwq.wq.private = current; - uwq.msg = userfault_msg(vmf->address, vmf->flags, reason); + uwq.msg = userfault_msg(vmf->address, vmf->flags, reason, + ctx->features); uwq.ctx = ctx; uwq.waken = false; diff --git a/include/uapi/linux/userfaultfd.h b/include/uapi/linux/userfaultfd.h index 819e235..84e4a1e 100644 --- a/include/uapi/linux/userfaultfd.h +++ b/include/uapi/linux/userfaultfd.h @@ -24,7 +24,8 @@ UFFD_FEATURE_EVENT_REMOVE | \ UFFD_FEATURE_EVENT_UNMAP | \ UFFD_FEATURE_MISSING_HUGETLBFS | \ - UFFD_FEATURE_MISSING_SHMEM) + UFFD_FEATURE_MISSING_SHMEM | \ + UFFD_FEATURE_THREAD_ID) #define UFFD_API_IOCTLS \ ((__u64)1 << _UFFDIO_REGISTER | \ (__u64)1 << _UFFDIO_UNREGISTER | \ @@ -83,6 +84,7 @@ struct uffd_msg { struct { __u64 flags; __u64 address; + pid_t ptid; } pagefault; struct { @@ -158,6 +160,9 @@ struct uffdio_api { * UFFD_FEATURE_MISSING_SHMEM works the same as * UFFD_FEATURE_MISSING_HUGETLBFS, but it applies to shmem * (i.e. tmpfs and other shmem based APIs). + * + * UFFD_FEATURE_THREAD_ID pid of the page faulted task_struct will + * be returned, if feature is not requested 0 will be returned. */ #define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0) #define UFFD_FEATURE_EVENT_FORK (1<<1) @@ -166,6 +171,7 @@ struct uffdio_api { #define UFFD_FEATURE_MISSING_HUGETLBFS (1<<4) #define UFFD_FEATURE_MISSING_SHMEM (1<<5) #define UFFD_FEATURE_EVENT_UNMAP (1<<6) +#define UFFD_FEATURE_THREAD_ID (1<<7) __u64 features; __u64 ioctls; -- 2.7.4 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf0-f200.google.com (mail-pf0-f200.google.com [209.85.192.200]) by kanga.kvack.org (Postfix) with ESMTP id DF5556B0038 for ; Thu, 23 Mar 2017 05:42:31 -0400 (EDT) Received: by mail-pf0-f200.google.com with SMTP id c23so381854953pfj.0 for ; Thu, 23 Mar 2017 02:42:31 -0700 (PDT) Received: from out4434.biz.mail.alibaba.com (out4434.biz.mail.alibaba.com. [47.88.44.34]) by mx.google.com with ESMTP id e67si3533256pfa.169.2017.03.23.02.42.29 for ; Thu, 23 Mar 2017 02:42:31 -0700 (PDT) Reply-To: "Hillf Danton" From: "Hillf Danton" References: <1490207346-9703-1-git-send-email-a.perevalov@samsung.com> <1490207346-9703-2-git-send-email-a.perevalov@samsung.com> In-Reply-To: <1490207346-9703-2-git-send-email-a.perevalov@samsung.com> Subject: Re: [PATCH v2] userfaultfd: provide pid in userfault msg Date: Thu, 23 Mar 2017 17:42:16 +0800 Message-ID: <00af01d2a3b9$c23b5030$46b1f090$@alibaba-inc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Content-Language: zh-cn Sender: owner-linux-mm@kvack.org List-ID: To: 'Alexey Perevalov' , 'Andrea Arcangeli' Cc: "'Dr . David Alan Gilbert'" , linux-mm@kvack.org, i.maximets@samsung.com On March 23, 2017 2:29 AM Alexey Perevalov wrote: > > static inline struct uffd_msg userfault_msg(unsigned long address, > unsigned int flags, > - unsigned long reason) > + unsigned long reason, > + unsigned int features) Nit: the type of feature is u64 by define. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg0-f72.google.com (mail-pg0-f72.google.com [74.125.83.72]) by kanga.kvack.org (Postfix) with ESMTP id 1174D6B0038 for ; Thu, 23 Mar 2017 06:07:20 -0400 (EDT) Received: by mail-pg0-f72.google.com with SMTP id b2so427184351pgc.6 for ; Thu, 23 Mar 2017 03:07:20 -0700 (PDT) Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com. [210.118.77.11]) by mx.google.com with ESMTPS id g1si5026140pln.322.2017.03.23.03.07.18 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 23 Mar 2017 03:07:19 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0ON9008CWIS32990@mailout1.w1.samsung.com> for linux-mm@kvack.org; Thu, 23 Mar 2017 10:07:15 +0000 (GMT) Subject: Re: [PATCH v2] userfaultfd: provide pid in userfault msg From: Alexey Perevalov Message-id: <9c1b88f6-b862-efd5-725f-a5fd083599dc@samsung.com> Date: Thu, 23 Mar 2017 13:07:12 +0300 MIME-version: 1.0 In-reply-to: <00af01d2a3b9$c23b5030$46b1f090$@alibaba-inc.com> Content-type: text/plain; charset=utf-8; format=flowed Content-transfer-encoding: 7bit References: <1490207346-9703-1-git-send-email-a.perevalov@samsung.com> <1490207346-9703-2-git-send-email-a.perevalov@samsung.com> <00af01d2a3b9$c23b5030$46b1f090$@alibaba-inc.com> Sender: owner-linux-mm@kvack.org List-ID: To: Hillf Danton Cc: 'Andrea Arcangeli' , "'Dr . David Alan Gilbert'" , linux-mm@kvack.org, i.maximets@samsung.com On 03/23/2017 12:42 PM, Hillf Danton wrote: > On March 23, 2017 2:29 AM Alexey Perevalov wrote: >> static inline struct uffd_msg userfault_msg(unsigned long address, >> unsigned int flags, >> - unsigned long reason) >> + unsigned long reason, >> + unsigned int features) > Nit: the type of feature is u64 by define. > Yes, you right, it's different types, especially for 32bit architectures. -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg0-f71.google.com (mail-pg0-f71.google.com [74.125.83.71]) by kanga.kvack.org (Postfix) with ESMTP id 89F216B0038 for ; Sat, 25 Mar 2017 07:47:45 -0400 (EDT) Received: by mail-pg0-f71.google.com with SMTP id n5so6902352pgd.19 for ; Sat, 25 Mar 2017 04:47:45 -0700 (PDT) Received: from mailout4.w1.samsung.com (mailout4.w1.samsung.com. [210.118.77.14]) by mx.google.com with ESMTPS id n73si4349948pfb.276.2017.03.25.04.47.44 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 25 Mar 2017 04:47:44 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OND00L9GCRHCI50@mailout4.w1.samsung.com> for linux-mm@kvack.org; Sat, 25 Mar 2017 11:47:41 +0000 (GMT) Subject: Re: [PATCH v2] userfaultfd: provide pid in userfault msg From: Alexey Perevalov Message-id: <105a751b-254a-d2e3-441e-1418a8e30905@samsung.com> Date: Sat, 25 Mar 2017 14:47:37 +0300 MIME-version: 1.0 In-reply-to: <00af01d2a3b9$c23b5030$46b1f090$@alibaba-inc.com> Content-type: text/plain; charset=utf-8; format=flowed Content-transfer-encoding: 7bit References: <1490207346-9703-1-git-send-email-a.perevalov@samsung.com> <1490207346-9703-2-git-send-email-a.perevalov@samsung.com> <00af01d2a3b9$c23b5030$46b1f090$@alibaba-inc.com> Sender: owner-linux-mm@kvack.org List-ID: To: Hillf Danton , 'Andrea Arcangeli' Cc: "'Dr . David Alan Gilbert'" , linux-mm@kvack.org, i.maximets@samsung.com Hi, Hillf On 03/23/2017 12:42 PM, Hillf Danton wrote: > On March 23, 2017 2:29 AM Alexey Perevalov wrote: >> static inline struct uffd_msg userfault_msg(unsigned long address, >> unsigned int flags, >> - unsigned long reason) >> + unsigned long reason, >> + unsigned int features) > Nit: the type of feature is u64 by define. > > > > > Yes, let me clarify once again, type of features is u64, but in struct uffdio_api, which used for handling UFFDIO_API. Function userfault_msg is using in handle_userfault, when only context (struct userfaultfd_ctx) is available, features inside context is type of unsigned int and uffd_ctx_features is using for casting. It's more likely question to maintainer, but due to userfaultfd_ctx is internal only structure, it's not a big problem to extend it in the future. -- Best regards, Alexey Perevalov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg0-f69.google.com (mail-pg0-f69.google.com [74.125.83.69]) by kanga.kvack.org (Postfix) with ESMTP id B58DD6B0333 for ; Sun, 26 Mar 2017 23:57:59 -0400 (EDT) Received: by mail-pg0-f69.google.com with SMTP id g124so25512103pgc.1 for ; Sun, 26 Mar 2017 20:57:59 -0700 (PDT) Received: from out4441.biz.mail.alibaba.com (out4441.biz.mail.alibaba.com. [47.88.44.41]) by mx.google.com with ESMTP id x188si11241495pgb.304.2017.03.26.20.57.57 for ; Sun, 26 Mar 2017 20:57:58 -0700 (PDT) Reply-To: "Hillf Danton" From: "Hillf Danton" References: <1490207346-9703-1-git-send-email-a.perevalov@samsung.com> <1490207346-9703-2-git-send-email-a.perevalov@samsung.com> <00af01d2a3b9$c23b5030$46b1f090$@alibaba-inc.com> <105a751b-254a-d2e3-441e-1418a8e30905@samsung.com> In-Reply-To: <105a751b-254a-d2e3-441e-1418a8e30905@samsung.com> Subject: Re: [PATCH v2] userfaultfd: provide pid in userfault msg Date: Mon, 27 Mar 2017 11:57:43 +0800 Message-ID: <015d01d2a6ae$4a3abf10$deb03d30$@alibaba-inc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Content-Language: zh-cn Sender: owner-linux-mm@kvack.org List-ID: To: 'Alexey Perevalov' , 'Andrea Arcangeli' Cc: "'Dr . David Alan Gilbert'" , linux-mm@kvack.org, i.maximets@samsung.com On March 25, 2017 7:48 PM Alexey Perevalov wrote: > On 03/23/2017 12:42 PM, Hillf Danton wrote: > > On March 23, 2017 2:29 AM Alexey Perevalov wrote: > >> static inline struct uffd_msg userfault_msg(unsigned long address, > >> unsigned int flags, > >> - unsigned long reason) > >> + unsigned long reason, > >> + unsigned int features) > > Nit: the type of feature is u64 by define. > > Yes, let me clarify once again, Thanks:) > type of features is u64, but in struct uffdio_api, which used for handling > UFFDIO_API. > Function userfault_msg is using in handle_userfault, when only > context (struct userfaultfd_ctx) is available, features inside context is > type of unsigned int and uffd_ctx_features is using for casting. > It's more likely question to maintainer, but due to userfaultfd_ctx is > internal only > structure, it's not a big problem to extend it in the future. > You are right. Hillf -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt0-f198.google.com (mail-qt0-f198.google.com [209.85.216.198]) by kanga.kvack.org (Postfix) with ESMTP id E91DA6B0390 for ; Wed, 29 Mar 2017 13:19:07 -0400 (EDT) Received: by mail-qt0-f198.google.com with SMTP id j30so7182176qta.2 for ; Wed, 29 Mar 2017 10:19:07 -0700 (PDT) Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id x38si6718856qtx.134.2017.03.29.10.19.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Mar 2017 10:19:06 -0700 (PDT) Date: Wed, 29 Mar 2017 19:19:03 +0200 From: Andrea Arcangeli Subject: Re: [PATCH v2] userfaultfd: provide pid in userfault msg Message-ID: <20170329171903.GG25920@redhat.com> References: <1490207346-9703-1-git-send-email-a.perevalov@samsung.com> <1490207346-9703-2-git-send-email-a.perevalov@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1490207346-9703-2-git-send-email-a.perevalov@samsung.com> Sender: owner-linux-mm@kvack.org List-ID: To: Alexey Perevalov Cc: "Dr . David Alan Gilbert" , linux-mm@kvack.org, i.maximets@samsung.com, Mike Rapoport , Mike Kravetz Hello, On Wed, Mar 22, 2017 at 09:29:06PM +0300, Alexey Perevalov wrote: > static inline struct uffd_msg userfault_msg(unsigned long address, > unsigned int flags, > - unsigned long reason) > + unsigned long reason, > + unsigned int features) userfaultfd_ctx.features is an int so this looks fine to me too. It's in kernel representation and we do the validation with a __u64 on the stack in userfaultfd_api() so that we -EINVAL any unknown bit >=32 to retain backwards compatibility and so we can start using bits over 32 sometime later (by turning the above in a long long). If the validation passes we then store the "known" (i.e. <32bit) features in userfaultfd_ctx.features and we keep passing it around as an int so we can pass it as an int above too. > @@ -83,6 +84,7 @@ struct uffd_msg { > struct { > __u64 flags; > __u64 address; > + pid_t ptid; > } pagefault; Now that you made it conditional to a feature flag this could now be put in an union and I think it'd better be a __u32 (or __u64 if the pid space is expected to grow beyond 32bit any time in the future, probably unlikely so __u32 could be enough). Last thing I wonder is what happens if you pass the uffd from a container under a PID namespace to some process outside the PID namespace through unix domains sockets. Then the tpid seen by the other container will be remapped and it may not be meaningful but considering this is used for statistical purposes it will still work. The security is handled through the unix domain sockets in such case, if the app gives up voluntarily its uffd then it's ok the app outside the namespace sees the tpid inside (and the same in the other way around). The important issue that got fixed in v2 and that I worried about in v1, is the tpid seen by an uffd inside the namespace is the namespace tpid and not the one seen outside the namespace that must never be shown to userland. Any other comment about merging this new uffd feature? Thanks, Andrea -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org