fs/userfaultfd.c: simplify the calculation of new_flags
PATCH 1/1 fs/userfaultfd.c: simplify the calculation of new_flags
Finally new_flags equals old vm_flags *OR* vm_flags.
It is not necessary to mask them first.
--- fs/userfaultfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/userfaultfd.c +1 -1
@@ -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),
Signature · 1 line
2.17.1
Ping~
Quoted 24 lines · Wei Yang
Finally
new_flagsequals oldvm_flags*OR*vm_flags.It is not necessary to mask them first.
Signed-off-by Wei Yang <[email protected]>---
fs/userfaultfd.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)fs/userfaultfd.c +1
-1@@ -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),Signature · 1 line
2.17.1
Signature · 2 lines
Wei Yang Help you, Help me
Hello,
Quoted 14 lines · Wei Yang
Finally
new_flagsequals oldvm_flags*OR*vm_flags.It is not necessary to mask them first.
Signed-off-by Wei Yang <[email protected]>--- fs/userfaultfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/userfaultfd.c +0
-0
fs/userfaultfd.c static int userfaultfd_register(struct userfaultfd_ctx *ctx, · line 1463
Quoted 8 lines
fs/userfaultfd.c +1
-1@@ -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.
Thanks,
Andrea
Quoted 36 lines · Andrea Arcangeli
Hello,
Quoted 14 lines · Wei Yang
Finally
new_flagsequals oldvm_flags*OR*vm_flags.It is not necessary to mask them first.
Signed-off-by Wei Yang <[email protected]>--- fs/userfaultfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/userfaultfd.c +0
-0fs/userfaultfd.c static int userfaultfd_register(struct userfaultfd_ctx *ctx, · line 1463
Quoted 8 lines
fs/userfaultfd.c +1
-1@@ -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.
Quoted 6 lines
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.
Quoted 2 lines
Thanks,
Andrea
Signature · 2 lines
Wei Yang Help you, Help me
Quoted 47 lines · Wei Yang
Quoted 36 lines · Andrea Arcangeli
Hello,
Quoted 14 lines · Wei Yang
Finally
new_flagsequals oldvm_flags*OR*vm_flags.It is not necessary to mask them first.
Signed-off-by Wei Yang <[email protected]>--- fs/userfaultfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/userfaultfd.c +0
-0fs/userfaultfd.c static int userfaultfd_register(struct userfaultfd_ctx *ctx, · line 1463
Quoted 8 lines
fs/userfaultfd.c +1
-1@@ -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.
Quoted 6 lines
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.
Quoted 6 lines
vm_flags == VM_UFFD_MISSING | VM_UFFD_WPThe 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 <[email protected]>
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.
--- fs/userfaultfd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/userfaultfd.c +2 -1
@@ -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),
Wei Yang
Reviewed-byQuoted 58 lines · Andrea Arcangeli
Quoted 47 lines · Wei Yang
Quoted 36 lines · Andrea Arcangeli
Hello,
Quoted 14 lines · Wei Yang
Finally
new_flagsequals oldvm_flags*OR*vm_flags.It is not necessary to mask them first.
Signed-off-by Wei Yang <[email protected]>--- fs/userfaultfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/userfaultfd.c +0
-0fs/userfaultfd.c static int userfaultfd_register(struct userfaultfd_ctx *ctx, · line 1463
Quoted 8 lines
fs/userfaultfd.c +1
-1@@ -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.
Quoted 6 lines
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.
Quoted 6 lines
vm_flags == VM_UFFD_MISSING | VM_UFFD_WPThe 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.
Quoted 8 lines
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.
ok, I get your point.
Quoted 9 lines
Thanks,
AndreaQuoted 1 line
From
a0f17bef184c6bb9b99294f202eefb50b6eb43cdMon Sep 17 00:00:00 2001From: Andrea Arcangeli <[email protected]>
Date: Fri, 4 Oct 2019 19:09:59 -0400
Subject: [PATCH 1/1] uffd: wp: clearVM_UFFD_MISSINGorVM_UFFD_WPduringuserfaultfd_register()
Quoted 7 lines
If the registration is repeated without
VM_UFFD_MISSINGorVM_UFFD_WPthey need to be cleared. Currently settingUFFDIO_REGISTER_MODE_WPreturns-EINVAL, so this patch is a noop until theUFFDIO_REGISTER_MODE_WPsupport is applied.Reported-by Wei Yang <[email protected]>Signed-off-by Andrea Arcangeli <[email protected]>
Quoted 18 lines
---
fs/userfaultfd.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)fs/userfaultfd.c +2
-1@@ -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),
Signature · 2 lines
Wei Yang Help you, Help me
Quoted 58 lines · Andrea Arcangeli
Quoted 47 lines · Wei Yang
Quoted 36 lines · Andrea Arcangeli
Hello,
Quoted 14 lines · Wei Yang
Finally
new_flagsequals oldvm_flags*OR*vm_flags.It is not necessary to mask them first.
Signed-off-by Wei Yang <[email protected]>--- fs/userfaultfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/userfaultfd.c +0
-0fs/userfaultfd.c static int userfaultfd_register(struct userfaultfd_ctx *ctx, · line 1463
Quoted 8 lines
fs/userfaultfd.c +1
-1@@ -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.
Quoted 6 lines
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.
Quoted 6 lines
vm_flags == VM_UFFD_MISSING | VM_UFFD_WPThe 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.
Quoted 7 lines
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.
IMHO it's good to have it as independent patch so at least it won't confuse another reader of the master branch. But just in case, I've also queued it in my local tree of uffd-wp.
Thanks,
Signature · 1 line
Peter Xu