From: Peter Xu <peterx@redhat.com>
To: stsp <stsp2@yandex.ru>
Cc: Linux kernel <linux-kernel@vger.kernel.org>,
Muhammad Usama Anjum <usama.anjum@collabora.com>
Subject: Re: userfaultfd: two-step UFFDIO_API always gives -EINVAL
Date: Mon, 25 Nov 2024 10:59:28 -0500 [thread overview]
Message-ID: <Z0Se4BuVfqwjeCWV@x1n> (raw)
In-Reply-To: <2d35e5f7-2edc-4ef0-b71b-82186c0627b0@yandex.ru>
On Sat, Nov 23, 2024 at 06:13:01PM +0300, stsp wrote:
> Hello.
>
> I tried to use userfaultfd and got
> that strange result: when I first do
> UFFDIO_API ioctl with features = 0,
> it succeeds. I check the needed
> features, and they are all in place.
> But on the second step, where I
> request the needed features,
> UFFDIO_API gives -EINVAL no matter
> what features I requested (or even
> set features to 0 again).
>
> A quick look into the kernel code
> suggests that the problem is that
> uffd_ctx_features() doesn't check
> user_features for being 0, and just
> sets UFFD_FEATURE_INITIALIZED
> with no features at all. After that,
> userfaultfd_api() should always
> fail with -EINVAL when doing this:
>
> ctx_features = uffd_ctx_features(features);
> ret = -EINVAL;
> if (cmpxchg(&ctx->features, 0, ctx_features) != 0)
> goto err_out;
>
> But I haven't checked my finding
> by rebuilding the kernel.
> So is this broken or am I missing
> something?
I agree it's slightly confusing but it's intended. It's like that since
the start, so I think we should still keep the behavior.
The userapp needs to create one extra userfaultfd to detect supported
features in the kernel. To use it after a probe request, you'll need to
close() the fd, redo the userfaultfd syscall to create another fd.
The kernel cannot assume features==0 to be a pure query, because not all
userfaultfd features requires setting of a feature bit. E.g., the default
anonymous missing traps doesn't require any feature bit to set. So the
initial UFFDIO_API(features=0) is the enablement of such feature.
Thanks,
--
Peter Xu
next prev parent reply other threads:[~2024-11-25 15:59 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-23 15:13 userfaultfd: two-step UFFDIO_API always gives -EINVAL stsp
2024-11-25 9:05 ` stsp
2024-11-25 15:59 ` Peter Xu [this message]
2024-11-25 16:15 ` stsp
2024-11-25 16:58 ` Peter Xu
2024-11-25 17:07 ` stsp
2024-11-25 17:13 ` Peter Xu
2024-11-25 17:32 ` stsp
2024-11-25 17:44 ` Peter Xu
2024-11-25 18:01 ` stsp
2024-11-25 18:44 ` Muhammad Usama Anjum
2024-11-26 7:32 ` stsp
2024-11-26 15:56 ` Peter Xu
2024-11-26 16:16 ` stsp
2024-11-26 17:41 ` Peter Xu
2024-11-26 9:41 ` stsp
2024-11-25 22:42 ` Axel Rasmussen
2024-11-26 7:39 ` stsp
2024-11-26 15:50 ` 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=Z0Se4BuVfqwjeCWV@x1n \
--to=peterx@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stsp2@yandex.ru \
--cc=usama.anjum@collabora.com \
/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.