All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrea Arcangeli <aarcange@redhat.com>
To: Wei Yang <richardw.yang@linux.intel.com>
Cc: linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk,
	linux-fsdevel@vger.kernel.org, Peter Xu <peterx@redhat.com>
Subject: Re: [PATCH] fs/userfaultfd.c: simplify the calculation of new_flags
Date: Fri, 4 Oct 2019 19:28:34 -0400	[thread overview]
Message-ID: <20191004232834.GP13922@redhat.com> (raw)
In-Reply-To: <20191004224640.GC32588@richard>

On Sat, Oct 05, 2019 at 06:46:40AM +0800, Wei Yang wrote:
> On Wed, Oct 02, 2019 at 08:45:05PM -0400, Andrea Arcangeli wrote:
> >Hello,
> >
> >On Tue, Aug 06, 2019 at 01:38:59PM +0800, Wei Yang wrote:
> >> Finally new_flags equals old vm_flags *OR* vm_flags.
> >> 
> >> It is not necessary to mask them first.
> >> 
> >> Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
> >> ---
> >>  fs/userfaultfd.c | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >> 
> >> diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
> >> index ccbdbd62f0d8..653d8f7c453c 100644
> >> --- a/fs/userfaultfd.c
> >> +++ b/fs/userfaultfd.c
> >> @@ -1457,7 +1457,7 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,
> >>  			start = vma->vm_start;
> >>  		vma_end = min(end, vma->vm_end);
> >>  
> >> -		new_flags = (vma->vm_flags & ~vm_flags) | vm_flags;
> >> +		new_flags = vma->vm_flags | vm_flags;
> >>  		prev = vma_merge(mm, prev, start, vma_end, new_flags,
> >>  				 vma->anon_vma, vma->vm_file, vma->vm_pgoff,
> >>  				 vma_policy(vma),
> >
> >And then how do you clear the flags after the above?
> >
> >It must be possible to clear the flags (from
> >UFFDIO_REGISTER_MODE_MISSING|UFFDIO_REGISTER_MODE_WP to only one set
> >or invert).
> >
> >We have no WP support upstream yet, so maybe that's why it looks
> >superfluous in practice, but in theory it isn't because it would then
> >need to be reversed by Peter's (CC'ed) -wp patchset.
> >
> >The register code has already the right placeholder to support -wp and
> >so it's better not to break them.
> >
> >I would recommend reviewing the uffd-wp support and working on testing
> >the uffd-wp code instead of changing the above.
> >
> 
> Sorry, I don't get your point. This change is valid to me even from arithmetic
> point of view.
> 
>     vm_flags == VM_UFFD_MISSING | VM_UFFD_WP
> 
> The effect of current code is clear these two bits then add them. This equals
> to just add these two bits.
> 
> I am not sure which part I lost.

The cleaned removed the "& ~" and that was enough to quickly tell the
cleaned up version was wrong.

What I should have noticed right away as well is that the code was
already wrong, sorry. That code doesn't require a noop code cleanup,
it requires a fix and the "& ~" needs to stay.

This isn't going to make any difference upstream until the uffd-wp
support is merged so it is enough to queue it in Peter's queue, or you
can merge it independently.

Thanks,
Andrea

From a0f17bef184c6bb9b99294f202eefb50b6eb43cd Mon Sep 17 00:00:00 2001
From: Andrea Arcangeli <aarcange@redhat.com>
Date: Fri, 4 Oct 2019 19:09:59 -0400
Subject: [PATCH 1/1] uffd: wp: clear VM_UFFD_MISSING or VM_UFFD_WP during
 userfaultfd_register()

If the registration is repeated without VM_UFFD_MISSING or VM_UFFD_WP
they need to be cleared. Currently setting UFFDIO_REGISTER_MODE_WP
returns -EINVAL, so this patch is a noop until the
UFFDIO_REGISTER_MODE_WP support is applied.

Reported-by: Wei Yang <richardw.yang@linux.intel.com>
Signed-off-by: Andrea Arcangeli <aarcange@redhat.com>
---
 fs/userfaultfd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index fe6d804a38dc..97596bb65dd5 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -1458,7 +1458,8 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx,
 			start = vma->vm_start;
 		vma_end = min(end, vma->vm_end);
 
-		new_flags = (vma->vm_flags & ~vm_flags) | vm_flags;
+		new_flags = (vma->vm_flags &
+			     ~(VM_UFFD_MISSING|VM_UFFD_WP)) | vm_flags;
 		prev = vma_merge(mm, prev, start, vma_end, new_flags,
 				 vma->anon_vma, vma->vm_file, vma->vm_pgoff,
 				 vma_policy(vma),


  reply	other threads:[~2019-10-04 23:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-06  5:38 [PATCH] fs/userfaultfd.c: simplify the calculation of new_flags Wei Yang
2019-09-12  2:54 ` Wei Yang
2019-10-03  0:45 ` Andrea Arcangeli
2019-10-04 22:46   ` Wei Yang
2019-10-04 23:28     ` Andrea Arcangeli [this message]
2019-10-04 23:38       ` Wei Yang
2019-10-09  3:51       ` Peter Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191004232834.GP13922@redhat.com \
    --to=aarcange@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterx@redhat.com \
    --cc=richardw.yang@linux.intel.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.