From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev,
tglx@linutronix.de, linux-crypto@vger.kernel.org,
linux-api@vger.kernel.org, x86@kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>,
Carlos O'Donell <carlos@redhat.com>,
Arnd Bergmann <arnd@arndb.de>,
Christian Brauner <brauner@kernel.org>
Subject: Re: [PATCH v10 1/4] random: add vgetrandom_alloc() syscall
Date: Fri, 2 Dec 2022 15:38:20 +0100 [thread overview]
Message-ID: <Y4oN3JDG4uH2+OUo@zx2c4.com> (raw)
In-Reply-To: <Y4eG9cUE28s0YpgO@zx2c4.com>
On Wed, Nov 30, 2022 at 05:38:13PM +0100, Jason A. Donenfeld wrote:
> On Wed, Nov 30, 2022 at 04:39:55PM +0100, Jason A. Donenfeld wrote:
> > 2) Convert vgetrandom_alloc() into a clone3-style syscall, as Christian
> > suggested earlier, which might allow for a bit more overloading
> > capability. That would be a struct that looks like:
> >
> > struct vgetrandom_alloc_args {
> > __aligned_u64 flags;
> > __aligned_u64 states;
> > __aligned_u64 num;
> > __aligned_u64 size_of_each;
> > }
> >
> > - If flags is VGRA_ALLOCATE, states and size_of_each must be zero on
> > input, while num is the hint, as is the case now. On output, states,
> > size_of_each, and num are filled in.
> >
> > - If flags is VGRA_DEALLOCATE, states, size_of_each, and num must be as
> > they were originally, and then it deallocates.
> >
> > I suppose (2) would alleviate your concerns entirely, without future
> > uncertainty over what it'd be like to add special cases to munmap(). And
> > it'd add a bit more future proofing to the syscall, depending on what we
> > do.
> >
> > So maybe I'm warming up to that approach a bit.
>
> So I just did a little quick implementation to see what it'd feel like,
> and actually, it's quite simple, and might address a lot of concerns all
> at once. What do you think of the below? Documentation and such still
> needs work obviously, but the bones should be there.
Well, despite writing into the ether here, I continue to chase my tail
around in circles over this. After Adhemerval expressed a sort of "meh"
opinion to me on IRC around doing the clone3-like thing, I went down a
mm rabbit hole and started looking at all the various ways memory is
allocated in userspace and under what conditions and for what and why.
Turns out there are a few drivers doing interesting things in this
space.
The long and short of it is that:
- All addresses involve maps and page tables.
- Allocating is mapping, deallocating is unmapping, and there's no way
around that.
- Memory that's "special" usually comes with special attributes or
operations on its vma.
So, this makes me think that `munmap` is the fine *and correct* API for
deallocation. It's what everything else uses, even "special" things. And
it doesn't constrain us in the future in case this gets "registered"
somehow, as Florian described it, because it's still attached to
current->mm and will still always go through the same mapping APIs
anyway.
In light of that, I'm going to stick with the original API design, and
not do the clone3() args struct thing and the VGRA_DEALLOCATE flag.
However, I think it'd be a good idea to add an additional parameter of
"unsigned long addr", which is enforced/reserved to be always 0 for now.
This might prove useful for something together with the currently unused
flags argument, sometime in the future.
Jason
next prev parent reply other threads:[~2022-12-02 14:38 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-29 21:06 [PATCH v10 0/4] implement getrandom() in vDSO Jason A. Donenfeld
2022-11-29 21:06 ` [PATCH v10 1/4] random: add vgetrandom_alloc() syscall Jason A. Donenfeld
2022-11-29 22:02 ` Thomas Gleixner
2022-11-30 0:59 ` Jason A. Donenfeld
2022-11-30 1:37 ` Thomas Gleixner
2022-11-30 1:42 ` Jason A. Donenfeld
2022-11-30 22:39 ` David Laight
2022-12-01 0:14 ` Jason A. Donenfeld
2022-11-30 10:51 ` Florian Weimer
2022-11-30 15:39 ` Jason A. Donenfeld
2022-11-30 16:38 ` Jason A. Donenfeld
2022-12-02 14:38 ` Jason A. Donenfeld [this message]
2022-12-01 2:16 ` Jason A. Donenfeld
2022-12-02 17:17 ` Florian Weimer
2022-12-02 18:29 ` Jason A. Donenfeld
2022-11-29 21:06 ` [PATCH v10 2/4] arch: allocate vgetrandom_alloc() syscall number Jason A. Donenfeld
2022-11-30 8:56 ` Geert Uytterhoeven
2022-11-30 10:06 ` Jason A. Donenfeld
2022-11-30 10:51 ` Arnd Bergmann
2022-11-29 21:06 ` [PATCH v10 3/4] random: introduce generic vDSO getrandom() implementation Jason A. Donenfeld
2022-11-29 22:42 ` Thomas Gleixner
2022-11-30 1:09 ` Jason A. Donenfeld
2022-11-30 10:44 ` Florian Weimer
2022-11-30 14:51 ` Jason A. Donenfeld
2022-11-30 14:59 ` Jason A. Donenfeld
2022-11-30 15:07 ` Arnd Bergmann
2022-11-30 15:12 ` Jason A. Donenfeld
2022-11-30 15:29 ` Arnd Bergmann
2022-11-30 15:47 ` Jason A. Donenfeld
2022-11-30 16:13 ` Arnd Bergmann
2022-11-30 16:40 ` Jason A. Donenfeld
2022-11-30 17:00 ` Thomas Gleixner
2022-11-29 21:06 ` [PATCH v10 4/4] x86: vdso: Wire up getrandom() vDSO implementation Jason A. Donenfeld
2022-11-29 22:52 ` Thomas Gleixner
2022-11-30 1:11 ` Jason A. Donenfeld
2022-11-30 5:22 ` Eric Biggers
2022-11-30 10:12 ` Jason A. Donenfeld
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=Y4oN3JDG4uH2+OUo@zx2c4.com \
--to=jason@zx2c4.com \
--cc=adhemerval.zanella@linaro.org \
--cc=arnd@arndb.de \
--cc=brauner@kernel.org \
--cc=carlos@redhat.com \
--cc=fweimer@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=patches@lists.linux.dev \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox