Commit 9d4ac934 authored by Alexey Perevalov's avatar Alexey Perevalov Committed by Linus Torvalds

userfaultfd: provide pid in userfault msg

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.

Link: http://lkml.kernel.org/r/20170802165145.22628-6-aarcange@redhat.comSigned-off-by: default avatarAlexey Perevalov <a.perevalov@samsung.com>
Signed-off-by: default avatarAndrea Arcangeli <aarcange@redhat.com>
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 2376dd7c
...@@ -178,7 +178,8 @@ static inline void msg_init(struct uffd_msg *msg) ...@@ -178,7 +178,8 @@ static inline void msg_init(struct uffd_msg *msg)
static inline struct uffd_msg userfault_msg(unsigned long address, static inline struct uffd_msg userfault_msg(unsigned long address,
unsigned int flags, unsigned int flags,
unsigned long reason) unsigned long reason,
unsigned int features)
{ {
struct uffd_msg msg; struct uffd_msg msg;
msg_init(&msg); msg_init(&msg);
...@@ -202,6 +203,8 @@ static inline struct uffd_msg userfault_msg(unsigned long address, ...@@ -202,6 +203,8 @@ static inline struct uffd_msg userfault_msg(unsigned long address,
* write protect fault. * write protect fault.
*/ */
msg.arg.pagefault.flags |= UFFD_PAGEFAULT_FLAG_WP; msg.arg.pagefault.flags |= UFFD_PAGEFAULT_FLAG_WP;
if (features & UFFD_FEATURE_THREAD_ID)
msg.arg.pagefault.ptid = task_pid_vnr(current);
return msg; return msg;
} }
...@@ -422,7 +425,8 @@ int handle_userfault(struct vm_fault *vmf, unsigned long reason) ...@@ -422,7 +425,8 @@ int handle_userfault(struct vm_fault *vmf, unsigned long reason)
init_waitqueue_func_entry(&uwq.wq, userfaultfd_wake_function); init_waitqueue_func_entry(&uwq.wq, userfaultfd_wake_function);
uwq.wq.private = current; 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.ctx = ctx;
uwq.waken = false; uwq.waken = false;
......
...@@ -24,7 +24,8 @@ ...@@ -24,7 +24,8 @@
UFFD_FEATURE_EVENT_UNMAP | \ UFFD_FEATURE_EVENT_UNMAP | \
UFFD_FEATURE_MISSING_HUGETLBFS | \ UFFD_FEATURE_MISSING_HUGETLBFS | \
UFFD_FEATURE_MISSING_SHMEM | \ UFFD_FEATURE_MISSING_SHMEM | \
UFFD_FEATURE_SIGBUS) UFFD_FEATURE_SIGBUS | \
UFFD_FEATURE_THREAD_ID)
#define UFFD_API_IOCTLS \ #define UFFD_API_IOCTLS \
((__u64)1 << _UFFDIO_REGISTER | \ ((__u64)1 << _UFFDIO_REGISTER | \
(__u64)1 << _UFFDIO_UNREGISTER | \ (__u64)1 << _UFFDIO_UNREGISTER | \
...@@ -79,6 +80,7 @@ struct uffd_msg { ...@@ -79,6 +80,7 @@ struct uffd_msg {
struct { struct {
__u64 flags; __u64 flags;
__u64 address; __u64 address;
__u32 ptid;
} pagefault; } pagefault;
struct { struct {
...@@ -158,8 +160,9 @@ struct uffdio_api { ...@@ -158,8 +160,9 @@ struct uffdio_api {
* UFFD_FEATURE_SIGBUS feature means no page-fault * UFFD_FEATURE_SIGBUS feature means no page-fault
* (UFFD_EVENT_PAGEFAULT) event will be delivered, instead * (UFFD_EVENT_PAGEFAULT) event will be delivered, instead
* a SIGBUS signal will be sent to the faulting process. * a SIGBUS signal will be sent to the faulting process.
* The application process can enable this behavior by adding *
* it to uffdio_api.features. * 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_PAGEFAULT_FLAG_WP (1<<0)
#define UFFD_FEATURE_EVENT_FORK (1<<1) #define UFFD_FEATURE_EVENT_FORK (1<<1)
...@@ -169,6 +172,7 @@ struct uffdio_api { ...@@ -169,6 +172,7 @@ struct uffdio_api {
#define UFFD_FEATURE_MISSING_SHMEM (1<<5) #define UFFD_FEATURE_MISSING_SHMEM (1<<5)
#define UFFD_FEATURE_EVENT_UNMAP (1<<6) #define UFFD_FEATURE_EVENT_UNMAP (1<<6)
#define UFFD_FEATURE_SIGBUS (1<<7) #define UFFD_FEATURE_SIGBUS (1<<7)
#define UFFD_FEATURE_THREAD_ID (1<<8)
__u64 features; __u64 features;
__u64 ioctls; __u64 ioctls;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment