Commit d811914d authored by Mike Rapoport's avatar Mike Rapoport Committed by Linus Torvalds

userfaultfd: non-cooperative: rename *EVENT_MADVDONTNEED to *EVENT_REMOVE

Patch series "userfaultfd: non-cooperative: add madvise() event for
MADV_REMOVE request".

These patches add notification of madvise(MADV_REMOVE) event to
non-cooperative userfaultfd monitor.

The first pacth renames EVENT_MADVDONTNEED to EVENT_REMOVE along with
relevant functions and structures.  Using _REMOVE instead of
_MADVDONTNEED describes the event semantics more clearly and I hope it's
not too late for such change in the ABI.

This patch (of 3):

The UFFD_EVENT_MADVDONTNEED purpose is to notify uffd monitor about
removal of certain range from address space tracked by userfaultfd.
Hence, UFFD_EVENT_REMOVE seems to better reflect the operation
semantics.  Respectively, 'madv_dn' field of uffd_msg is renamed to
'remove' and the madvise_userfault_dontneed callback is renamed to
userfaultfd_remove.

Link: http://lkml.kernel.org/r/1484814154-1557-2-git-send-email-rppt@linux.vnet.ibm.comSigned-off-by: default avatarMike Rapoport <rppt@linux.vnet.ibm.com>
Reviewed-by: default avatarAndrea Arcangeli <aarcange@redhat.com>
Acked-by: default avatarHillf Danton <hillf.zj@alibaba-inc.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 0262d9c8
...@@ -681,7 +681,7 @@ void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *vm_ctx, ...@@ -681,7 +681,7 @@ void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *vm_ctx,
userfaultfd_event_wait_completion(ctx, &ewq); userfaultfd_event_wait_completion(ctx, &ewq);
} }
void madvise_userfault_dontneed(struct vm_area_struct *vma, void userfaultfd_remove(struct vm_area_struct *vma,
struct vm_area_struct **prev, struct vm_area_struct **prev,
unsigned long start, unsigned long end) unsigned long start, unsigned long end)
{ {
...@@ -690,7 +690,7 @@ void madvise_userfault_dontneed(struct vm_area_struct *vma, ...@@ -690,7 +690,7 @@ void madvise_userfault_dontneed(struct vm_area_struct *vma,
struct userfaultfd_wait_queue ewq; struct userfaultfd_wait_queue ewq;
ctx = vma->vm_userfaultfd_ctx.ctx; ctx = vma->vm_userfaultfd_ctx.ctx;
if (!ctx || !(ctx->features & UFFD_FEATURE_EVENT_MADVDONTNEED)) if (!ctx || !(ctx->features & UFFD_FEATURE_EVENT_REMOVE))
return; return;
userfaultfd_ctx_get(ctx); userfaultfd_ctx_get(ctx);
...@@ -700,9 +700,9 @@ void madvise_userfault_dontneed(struct vm_area_struct *vma, ...@@ -700,9 +700,9 @@ void madvise_userfault_dontneed(struct vm_area_struct *vma,
msg_init(&ewq.msg); msg_init(&ewq.msg);
ewq.msg.event = UFFD_EVENT_MADVDONTNEED; ewq.msg.event = UFFD_EVENT_REMOVE;
ewq.msg.arg.madv_dn.start = start; ewq.msg.arg.remove.start = start;
ewq.msg.arg.madv_dn.end = end; ewq.msg.arg.remove.end = end;
userfaultfd_event_wait_completion(ctx, &ewq); userfaultfd_event_wait_completion(ctx, &ewq);
......
...@@ -61,7 +61,7 @@ extern void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *, ...@@ -61,7 +61,7 @@ extern void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *,
unsigned long from, unsigned long to, unsigned long from, unsigned long to,
unsigned long len); unsigned long len);
extern void madvise_userfault_dontneed(struct vm_area_struct *vma, extern void userfaultfd_remove(struct vm_area_struct *vma,
struct vm_area_struct **prev, struct vm_area_struct **prev,
unsigned long start, unsigned long start,
unsigned long end); unsigned long end);
...@@ -112,7 +112,7 @@ static inline void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *ctx, ...@@ -112,7 +112,7 @@ static inline void mremap_userfaultfd_complete(struct vm_userfaultfd_ctx *ctx,
{ {
} }
static inline void madvise_userfault_dontneed(struct vm_area_struct *vma, static inline void userfaultfd_remove(struct vm_area_struct *vma,
struct vm_area_struct **prev, struct vm_area_struct **prev,
unsigned long start, unsigned long start,
unsigned long end) unsigned long end)
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#define UFFD_API ((__u64)0xAA) #define UFFD_API ((__u64)0xAA)
#define UFFD_API_FEATURES (UFFD_FEATURE_EVENT_FORK | \ #define UFFD_API_FEATURES (UFFD_FEATURE_EVENT_FORK | \
UFFD_FEATURE_EVENT_REMAP | \ UFFD_FEATURE_EVENT_REMAP | \
UFFD_FEATURE_EVENT_MADVDONTNEED | \ UFFD_FEATURE_EVENT_REMOVE | \
UFFD_FEATURE_MISSING_HUGETLBFS | \ UFFD_FEATURE_MISSING_HUGETLBFS | \
UFFD_FEATURE_MISSING_SHMEM) UFFD_FEATURE_MISSING_SHMEM)
#define UFFD_API_IOCTLS \ #define UFFD_API_IOCTLS \
...@@ -92,7 +92,7 @@ struct uffd_msg { ...@@ -92,7 +92,7 @@ struct uffd_msg {
struct { struct {
__u64 start; __u64 start;
__u64 end; __u64 end;
} madv_dn; } remove;
struct { struct {
/* unused reserved fields */ /* unused reserved fields */
...@@ -109,7 +109,7 @@ struct uffd_msg { ...@@ -109,7 +109,7 @@ struct uffd_msg {
#define UFFD_EVENT_PAGEFAULT 0x12 #define UFFD_EVENT_PAGEFAULT 0x12
#define UFFD_EVENT_FORK 0x13 #define UFFD_EVENT_FORK 0x13
#define UFFD_EVENT_REMAP 0x14 #define UFFD_EVENT_REMAP 0x14
#define UFFD_EVENT_MADVDONTNEED 0x15 #define UFFD_EVENT_REMOVE 0x15
/* flags for UFFD_EVENT_PAGEFAULT */ /* flags for UFFD_EVENT_PAGEFAULT */
#define UFFD_PAGEFAULT_FLAG_WRITE (1<<0) /* If this was a write fault */ #define UFFD_PAGEFAULT_FLAG_WRITE (1<<0) /* If this was a write fault */
...@@ -155,7 +155,7 @@ struct uffdio_api { ...@@ -155,7 +155,7 @@ struct uffdio_api {
#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)
#define UFFD_FEATURE_EVENT_REMAP (1<<2) #define UFFD_FEATURE_EVENT_REMAP (1<<2)
#define UFFD_FEATURE_EVENT_MADVDONTNEED (1<<3) #define UFFD_FEATURE_EVENT_REMOVE (1<<3)
#define UFFD_FEATURE_MISSING_HUGETLBFS (1<<4) #define UFFD_FEATURE_MISSING_HUGETLBFS (1<<4)
#define UFFD_FEATURE_MISSING_SHMEM (1<<5) #define UFFD_FEATURE_MISSING_SHMEM (1<<5)
__u64 features; __u64 features;
......
...@@ -479,7 +479,7 @@ static long madvise_dontneed(struct vm_area_struct *vma, ...@@ -479,7 +479,7 @@ static long madvise_dontneed(struct vm_area_struct *vma,
if (!can_madv_dontneed_vma(vma)) if (!can_madv_dontneed_vma(vma))
return -EINVAL; return -EINVAL;
madvise_userfault_dontneed(vma, prev, start, end); userfaultfd_remove(vma, prev, start, end);
zap_page_range(vma, start, end - start); zap_page_range(vma, start, end - start);
return 0; return 0;
} }
......
...@@ -398,12 +398,12 @@ static void *uffd_poll_thread(void *arg) ...@@ -398,12 +398,12 @@ static void *uffd_poll_thread(void *arg)
uffd = msg.arg.fork.ufd; uffd = msg.arg.fork.ufd;
pollfd[0].fd = uffd; pollfd[0].fd = uffd;
break; break;
case UFFD_EVENT_MADVDONTNEED: case UFFD_EVENT_REMOVE:
uffd_reg.range.start = msg.arg.madv_dn.start; uffd_reg.range.start = msg.arg.remove.start;
uffd_reg.range.len = msg.arg.madv_dn.end - uffd_reg.range.len = msg.arg.remove.end -
msg.arg.madv_dn.start; msg.arg.remove.start;
if (ioctl(uffd, UFFDIO_UNREGISTER, &uffd_reg.range)) if (ioctl(uffd, UFFDIO_UNREGISTER, &uffd_reg.range))
fprintf(stderr, "madv_dn failure\n"), exit(1); fprintf(stderr, "remove failure\n"), exit(1);
break; break;
case UFFD_EVENT_REMAP: case UFFD_EVENT_REMAP:
area_dst = (char *)(unsigned long)msg.arg.remap.to; area_dst = (char *)(unsigned long)msg.arg.remap.to;
...@@ -570,7 +570,7 @@ static int userfaultfd_open(int features) ...@@ -570,7 +570,7 @@ static int userfaultfd_open(int features)
* mremap, the entire monitored area is accessed in a single pass for * mremap, the entire monitored area is accessed in a single pass for
* HUGETLB_TEST. * HUGETLB_TEST.
* The release of the pages currently generates event only for * The release of the pages currently generates event only for
* anonymous memory (UFFD_EVENT_MADVDONTNEED), hence it is not checked * anonymous memory (UFFD_EVENT_REMOVE), hence it is not checked
* for hugetlb and shmem. * for hugetlb and shmem.
*/ */
static int faulting_process(void) static int faulting_process(void)
...@@ -715,14 +715,14 @@ static int userfaultfd_events_test(void) ...@@ -715,14 +715,14 @@ static int userfaultfd_events_test(void)
pid_t pid; pid_t pid;
char c; char c;
printf("testing events (fork, remap, madv_dn): "); printf("testing events (fork, remap, remove): ");
fflush(stdout); fflush(stdout);
if (release_pages(area_dst)) if (release_pages(area_dst))
return 1; return 1;
features = UFFD_FEATURE_EVENT_FORK | UFFD_FEATURE_EVENT_REMAP | features = UFFD_FEATURE_EVENT_FORK | UFFD_FEATURE_EVENT_REMAP |
UFFD_FEATURE_EVENT_MADVDONTNEED; UFFD_FEATURE_EVENT_REMOVE;
if (userfaultfd_open(features) < 0) if (userfaultfd_open(features) < 0)
return 1; return 1;
fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK); fcntl(uffd, F_SETFL, uffd_flags | O_NONBLOCK);
......
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