* [PATCH] userfaultfd: wake on unregister for minor faults as well as missing
@ 2022-10-25 18:21 Axel Rasmussen
2022-10-25 18:34 ` Peter Xu
2022-10-25 18:44 ` Lokesh Gidra
0 siblings, 2 replies; 4+ messages in thread
From: Axel Rasmussen @ 2022-10-25 18:21 UTC (permalink / raw)
To: Alexander Viro, Andrew Morton, Peter Xu, Mike Kravetz
Cc: Axel Rasmussen, Lokesh Gidra, linux-fsdevel, linux-kernel, stable
This was an overlooked edge case when minor faults were added. In
general, minor faults have the same rough edge here as missing faults:
if we unregister while there are waiting threads, they will just remain
waiting forever, as there is no way for userspace to wake them after
unregistration. To work around this, userspace needs to carefully wake
everything before unregistering.
So, wake for minor faults just like we already do for missing faults as
part of the unregistration process.
Cc: stable@vger.kernel.org
Fixes: 7677f7fd8be7 ("userfaultfd: add minor fault registration mode")
Reported-by: Lokesh Gidra <lokeshgidra@google.com>
Signed-off-by: Axel Rasmussen <axelrasmussen@google.com>
---
fs/userfaultfd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index 07c81ab3fd4d..7daee4b9481c 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -1606,7 +1606,7 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
start = vma->vm_start;
vma_end = min(end, vma->vm_end);
- if (userfaultfd_missing(vma)) {
+ if (userfaultfd_missing(vma) || userfaultfd_minor(vma)) {
/*
* Wake any concurrent pending userfault while
* we unregister, so they will not hang
--
2.38.0.135.g90850a2211-goog
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] userfaultfd: wake on unregister for minor faults as well as missing
2022-10-25 18:21 [PATCH] userfaultfd: wake on unregister for minor faults as well as missing Axel Rasmussen
@ 2022-10-25 18:34 ` Peter Xu
2022-10-25 18:40 ` Axel Rasmussen
2022-10-25 18:44 ` Lokesh Gidra
1 sibling, 1 reply; 4+ messages in thread
From: Peter Xu @ 2022-10-25 18:34 UTC (permalink / raw)
To: Axel Rasmussen
Cc: Alexander Viro, Andrew Morton, Mike Kravetz, Lokesh Gidra,
linux-fsdevel, linux-kernel, stable
On Tue, Oct 25, 2022 at 11:21:49AM -0700, Axel Rasmussen wrote:
> This was an overlooked edge case when minor faults were added. In
> general, minor faults have the same rough edge here as missing faults:
> if we unregister while there are waiting threads, they will just remain
> waiting forever, as there is no way for userspace to wake them after
> unregistration. To work around this, userspace needs to carefully wake
> everything before unregistering.
>
> So, wake for minor faults just like we already do for missing faults as
> part of the unregistration process.
>
> Cc: stable@vger.kernel.org
> Fixes: 7677f7fd8be7 ("userfaultfd: add minor fault registration mode")
> Reported-by: Lokesh Gidra <lokeshgidra@google.com>
> Signed-off-by: Axel Rasmussen <axelrasmussen@google.com>
> ---
> fs/userfaultfd.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
> index 07c81ab3fd4d..7daee4b9481c 100644
> --- a/fs/userfaultfd.c
> +++ b/fs/userfaultfd.c
> @@ -1606,7 +1606,7 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
> start = vma->vm_start;
> vma_end = min(end, vma->vm_end);
>
> - if (userfaultfd_missing(vma)) {
> + if (userfaultfd_missing(vma) || userfaultfd_minor(vma)) {
> /*
> * Wake any concurrent pending userfault while
> * we unregister, so they will not hang
> --
> 2.38.0.135.g90850a2211-goog
Thanks, Axel. Is wr-protect mode also prone to this? Would a test case
help too?
--
Peter Xu
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] userfaultfd: wake on unregister for minor faults as well as missing
2022-10-25 18:34 ` Peter Xu
@ 2022-10-25 18:40 ` Axel Rasmussen
0 siblings, 0 replies; 4+ messages in thread
From: Axel Rasmussen @ 2022-10-25 18:40 UTC (permalink / raw)
To: Peter Xu
Cc: Alexander Viro, Andrew Morton, Mike Kravetz, Lokesh Gidra,
linux-fsdevel, linux-kernel, stable
On Tue, Oct 25, 2022 at 11:34 AM Peter Xu <peterx@redhat.com> wrote:
>
> On Tue, Oct 25, 2022 at 11:21:49AM -0700, Axel Rasmussen wrote:
> > This was an overlooked edge case when minor faults were added. In
> > general, minor faults have the same rough edge here as missing faults:
> > if we unregister while there are waiting threads, they will just remain
> > waiting forever, as there is no way for userspace to wake them after
> > unregistration. To work around this, userspace needs to carefully wake
> > everything before unregistering.
> >
> > So, wake for minor faults just like we already do for missing faults as
> > part of the unregistration process.
> >
> > Cc: stable@vger.kernel.org
> > Fixes: 7677f7fd8be7 ("userfaultfd: add minor fault registration mode")
> > Reported-by: Lokesh Gidra <lokeshgidra@google.com>
> > Signed-off-by: Axel Rasmussen <axelrasmussen@google.com>
> > ---
> > fs/userfaultfd.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
> > index 07c81ab3fd4d..7daee4b9481c 100644
> > --- a/fs/userfaultfd.c
> > +++ b/fs/userfaultfd.c
> > @@ -1606,7 +1606,7 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
> > start = vma->vm_start;
> > vma_end = min(end, vma->vm_end);
> >
> > - if (userfaultfd_missing(vma)) {
> > + if (userfaultfd_missing(vma) || userfaultfd_minor(vma)) {
> > /*
> > * Wake any concurrent pending userfault while
> > * we unregister, so they will not hang
> > --
> > 2.38.0.135.g90850a2211-goog
>
> Thanks, Axel. Is wr-protect mode also prone to this? Would a test case
> help too?
I'm not quite as familiar with uffd-wp, but I think so? At minimum, it
seems like waking can't *hurt*, and it would simplify the check
slightly -- if (userfaultfd_armed(vma)) {}
It would also mean if we add yet another registration mode in the
future, we wouldn't forget to update this.
I'll send a v2 to address both points.
>
> --
> Peter Xu
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] userfaultfd: wake on unregister for minor faults as well as missing
2022-10-25 18:21 [PATCH] userfaultfd: wake on unregister for minor faults as well as missing Axel Rasmussen
2022-10-25 18:34 ` Peter Xu
@ 2022-10-25 18:44 ` Lokesh Gidra
1 sibling, 0 replies; 4+ messages in thread
From: Lokesh Gidra @ 2022-10-25 18:44 UTC (permalink / raw)
To: Axel Rasmussen
Cc: Alexander Viro, Andrew Morton, Peter Xu, Mike Kravetz,
linux-fsdevel, linux-kernel, stable
Thanks for fixing this issue.
On Tue, Oct 25, 2022 at 11:21 AM Axel Rasmussen
<axelrasmussen@google.com> wrote:
>
> This was an overlooked edge case when minor faults were added. In
> general, minor faults have the same rough edge here as missing faults:
> if we unregister while there are waiting threads, they will just remain
> waiting forever, as there is no way for userspace to wake them after
> unregistration. To work around this, userspace needs to carefully wake
> everything before unregistering.
Actually, WAKE ioctl doesn't check if the provided range is registered
with userfaultfd or not. So, it's possible to wake the waiting threads
after unregisteration.
But, in this context, missing faults are the same as minor faults (and
wp too?). Therefore, waking the waiting threads as part of
unregistration is expected.
>
> So, wake for minor faults just like we already do for missing faults as
> part of the unregistration process.
>
> Cc: stable@vger.kernel.org
> Fixes: 7677f7fd8be7 ("userfaultfd: add minor fault registration mode")
> Reported-by: Lokesh Gidra <lokeshgidra@google.com>
> Signed-off-by: Axel Rasmussen <axelrasmussen@google.com>
> ---
> fs/userfaultfd.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
> index 07c81ab3fd4d..7daee4b9481c 100644
> --- a/fs/userfaultfd.c
> +++ b/fs/userfaultfd.c
> @@ -1606,7 +1606,7 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,
> start = vma->vm_start;
> vma_end = min(end, vma->vm_end);
>
> - if (userfaultfd_missing(vma)) {
> + if (userfaultfd_missing(vma) || userfaultfd_minor(vma)) {
> /*
> * Wake any concurrent pending userfault while
> * we unregister, so they will not hang
> --
> 2.38.0.135.g90850a2211-goog
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-10-25 18:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-25 18:21 [PATCH] userfaultfd: wake on unregister for minor faults as well as missing Axel Rasmussen
2022-10-25 18:34 ` Peter Xu
2022-10-25 18:40 ` Axel Rasmussen
2022-10-25 18:44 ` Lokesh Gidra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®