Revert "BACKPORT: ANDROID: userfaultfd: add MMAP_TRYLOCK mode for COPY/ZEROPAGE"
This reverts commit fa49c6bf49.
This commit is contained in:
@@ -1759,9 +1759,7 @@ static int userfaultfd_copy(struct userfaultfd_ctx *ctx,
|
||||
ret = -EINVAL;
|
||||
if (uffdio_copy.src + uffdio_copy.len <= uffdio_copy.src)
|
||||
goto out;
|
||||
if (uffdio_copy.mode & ~(UFFDIO_COPY_MODE_DONTWAKE|
|
||||
UFFDIO_COPY_MODE_WP|
|
||||
UFFDIO_COPY_MODE_MMAP_TRYLOCK))
|
||||
if (uffdio_copy.mode & ~(UFFDIO_COPY_MODE_DONTWAKE|UFFDIO_COPY_MODE_WP))
|
||||
goto out;
|
||||
if (mmget_not_zero(ctx->mm)) {
|
||||
ret = mcopy_atomic(ctx->mm, uffdio_copy.dst, uffdio_copy.src,
|
||||
@@ -1812,14 +1810,13 @@ static int userfaultfd_zeropage(struct userfaultfd_ctx *ctx,
|
||||
if (ret)
|
||||
goto out;
|
||||
ret = -EINVAL;
|
||||
if (uffdio_zeropage.mode & ~(UFFDIO_ZEROPAGE_MODE_DONTWAKE|
|
||||
UFFDIO_ZEROPAGE_MODE_MMAP_TRYLOCK))
|
||||
if (uffdio_zeropage.mode & ~UFFDIO_ZEROPAGE_MODE_DONTWAKE)
|
||||
goto out;
|
||||
|
||||
if (mmget_not_zero(ctx->mm)) {
|
||||
ret = mfill_zeropage(ctx->mm, uffdio_zeropage.range.start,
|
||||
uffdio_zeropage.range.len,
|
||||
&ctx->mmap_changing, uffdio_zeropage.mode);
|
||||
&ctx->mmap_changing);
|
||||
mmput(ctx->mm);
|
||||
} else {
|
||||
return -ESRCH;
|
||||
|
||||
@@ -32,9 +32,6 @@
|
||||
#define UFFD_SHARED_FCNTL_FLAGS (O_CLOEXEC | O_NONBLOCK)
|
||||
#define UFFD_FLAGS_SET (EFD_SHARED_FCNTL_FLAGS)
|
||||
|
||||
static_assert(UFFDIO_ZEROPAGE_MODE_MMAP_TRYLOCK == UFFDIO_COPY_MODE_MMAP_TRYLOCK);
|
||||
#define UFFDIO_MODE_MMAP_TRYLOCK UFFDIO_COPY_MODE_MMAP_TRYLOCK
|
||||
|
||||
extern int sysctl_unprivileged_userfaultfd;
|
||||
|
||||
extern int handle_userfault(struct vm_fault *vmf, unsigned long reason);
|
||||
@@ -64,8 +61,9 @@ extern ssize_t mcopy_atomic(struct mm_struct *dst_mm, unsigned long dst_start,
|
||||
unsigned long src_start, unsigned long len,
|
||||
bool *mmap_changing, __u64 mode);
|
||||
extern ssize_t mfill_zeropage(struct mm_struct *dst_mm,
|
||||
unsigned long dst_start, unsigned long len,
|
||||
bool *mmap_changing, __u64 mode);
|
||||
unsigned long dst_start,
|
||||
unsigned long len,
|
||||
bool *mmap_changing);
|
||||
extern ssize_t mcopy_continue(struct mm_struct *dst_mm, unsigned long dst_start,
|
||||
unsigned long len, bool *mmap_changing);
|
||||
|
||||
|
||||
@@ -232,7 +232,6 @@ struct uffdio_copy {
|
||||
* according to the uffdio_register.ioctls.
|
||||
*/
|
||||
#define UFFDIO_COPY_MODE_WP ((__u64)1<<1)
|
||||
#define UFFDIO_COPY_MODE_MMAP_TRYLOCK ((__u64)1<<63)
|
||||
__u64 mode;
|
||||
|
||||
/*
|
||||
@@ -245,7 +244,6 @@ struct uffdio_copy {
|
||||
struct uffdio_zeropage {
|
||||
struct uffdio_range range;
|
||||
#define UFFDIO_ZEROPAGE_MODE_DONTWAKE ((__u64)1<<0)
|
||||
#define UFFDIO_ZEROPAGE_MODE_MMAP_TRYLOCK ((__u64)1<<63)
|
||||
__u64 mode;
|
||||
|
||||
/*
|
||||
|
||||
@@ -553,19 +553,14 @@ static __always_inline ssize_t __mcopy_atomic(struct mm_struct *dst_mm,
|
||||
copied = 0;
|
||||
page = NULL;
|
||||
retry:
|
||||
err = -EAGAIN;
|
||||
if (mode & UFFDIO_MODE_MMAP_TRYLOCK) {
|
||||
if (!down_read_trylock(&dst_mm->mmap_sem))
|
||||
goto out;
|
||||
} else {
|
||||
down_read(&dst_mm->mmap_sem);
|
||||
}
|
||||
down_read(&dst_mm->mmap_sem);
|
||||
|
||||
/*
|
||||
* If memory mappings are changing because of non-cooperative
|
||||
* operation (e.g. mremap) running in parallel, bail out and
|
||||
* request the user to retry later
|
||||
*/
|
||||
err = -EAGAIN;
|
||||
if (mmap_changing && READ_ONCE(*mmap_changing))
|
||||
goto out_unlock;
|
||||
|
||||
@@ -731,10 +726,10 @@ ssize_t mcopy_atomic(struct mm_struct *dst_mm, unsigned long dst_start,
|
||||
}
|
||||
|
||||
ssize_t mfill_zeropage(struct mm_struct *dst_mm, unsigned long start,
|
||||
unsigned long len, bool *mmap_changing, __u64 mode)
|
||||
unsigned long len, bool *mmap_changing)
|
||||
{
|
||||
return __mcopy_atomic(dst_mm, start, 0, len, MCOPY_ATOMIC_ZEROPAGE,
|
||||
mmap_changing, mode);
|
||||
mmap_changing, 0);
|
||||
}
|
||||
|
||||
ssize_t mcopy_continue(struct mm_struct *dst_mm, unsigned long start,
|
||||
|
||||
Reference in New Issue
Block a user