Skip to content

Commit 9d4ac93

Browse files
Alexey Perevalovtorvalds
authored andcommitted
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.com Signed-off-by: Alexey Perevalov <a.perevalov@samsung.com> Signed-off-by: Andrea 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: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 2376dd7 commit 9d4ac93

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

fs/userfaultfd.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ static inline void msg_init(struct uffd_msg *msg)
178178

179179
static inline struct uffd_msg userfault_msg(unsigned long address,
180180
unsigned int flags,
181-
unsigned long reason)
181+
unsigned long reason,
182+
unsigned int features)
182183
{
183184
struct uffd_msg msg;
184185
msg_init(&msg);
@@ -202,6 +203,8 @@ static inline struct uffd_msg userfault_msg(unsigned long address,
202203
* write protect fault.
203204
*/
204205
msg.arg.pagefault.flags |= UFFD_PAGEFAULT_FLAG_WP;
206+
if (features & UFFD_FEATURE_THREAD_ID)
207+
msg.arg.pagefault.ptid = task_pid_vnr(current);
205208
return msg;
206209
}
207210

@@ -422,7 +425,8 @@ int handle_userfault(struct vm_fault *vmf, unsigned long reason)
422425

423426
init_waitqueue_func_entry(&uwq.wq, userfaultfd_wake_function);
424427
uwq.wq.private = current;
425-
uwq.msg = userfault_msg(vmf->address, vmf->flags, reason);
428+
uwq.msg = userfault_msg(vmf->address, vmf->flags, reason,
429+
ctx->features);
426430
uwq.ctx = ctx;
427431
uwq.waken = false;
428432

include/uapi/linux/userfaultfd.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
UFFD_FEATURE_EVENT_UNMAP | \
2525
UFFD_FEATURE_MISSING_HUGETLBFS | \
2626
UFFD_FEATURE_MISSING_SHMEM | \
27-
UFFD_FEATURE_SIGBUS)
27+
UFFD_FEATURE_SIGBUS | \
28+
UFFD_FEATURE_THREAD_ID)
2829
#define UFFD_API_IOCTLS \
2930
((__u64)1 << _UFFDIO_REGISTER | \
3031
(__u64)1 << _UFFDIO_UNREGISTER | \
@@ -79,6 +80,7 @@ struct uffd_msg {
7980
struct {
8081
__u64 flags;
8182
__u64 address;
83+
__u32 ptid;
8284
} pagefault;
8385

8486
struct {
@@ -158,8 +160,9 @@ struct uffdio_api {
158160
* UFFD_FEATURE_SIGBUS feature means no page-fault
159161
* (UFFD_EVENT_PAGEFAULT) event will be delivered, instead
160162
* a SIGBUS signal will be sent to the faulting process.
161-
* The application process can enable this behavior by adding
162-
* it to uffdio_api.features.
163+
*
164+
* UFFD_FEATURE_THREAD_ID pid of the page faulted task_struct will
165+
* be returned, if feature is not requested 0 will be returned.
163166
*/
164167
#define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0)
165168
#define UFFD_FEATURE_EVENT_FORK (1<<1)
@@ -169,6 +172,7 @@ struct uffdio_api {
169172
#define UFFD_FEATURE_MISSING_SHMEM (1<<5)
170173
#define UFFD_FEATURE_EVENT_UNMAP (1<<6)
171174
#define UFFD_FEATURE_SIGBUS (1<<7)
175+
#define UFFD_FEATURE_THREAD_ID (1<<8)
172176
__u64 features;
173177

174178
__u64 ioctls;

0 commit comments

Comments
 (0)