From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev,
tglx@linutronix.de, linux-crypto@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>,
Linux API <linux-api@vger.kernel.org>
Subject: Re: [PATCH v6 2/3] random: introduce generic vDSO getrandom() implementation
Date: Thu, 24 Nov 2022 02:18:20 +0100 [thread overview]
Message-ID: <Y37GXIQVvUvRac6D@zx2c4.com> (raw)
In-Reply-To: <842fd97b-c958-7b0d-2c77-6927c7ab4d72@rasmusvillemoes.dk>
Hi Rasmus,
On Wed, Nov 23, 2022 at 09:51:04AM +0100, Rasmus Villemoes wrote:
> On 21/11/2022 16.29, Jason A. Donenfeld wrote:
>
> Cc += linux-api
>
> >
> > if (!new_block)
> > goto out;
> > new_cap = grnd_allocator.cap + num;
> > new_states = reallocarray(grnd_allocator.states, new_cap, sizeof(*grnd_allocator.states));
> > if (!new_states) {
> > munmap(new_block, num * size_per_each);
>
> Hm. This does leak an implementation detail of vgetrandom_alloc(),
> namely that it is based on mmap() of that size rounded up to page size.
> Do we want to commit to this being the proper way of disposing of a
> succesful vgetrandom_alloc(), or should there also be a
> vgetrandom_free(void *states, long num, long size_per_each)?
Yes, this is intentional, and this is exactly what I wanted to do. There
are various wrappers of vm_mmap() throughout, mmap being one of them,
and they typically then resort to munmap to unmap it. This is how
userspace handles memory - maps, always maps. So I think doing that is
fine and consistent.
However, your point about it relying on it being a rounded up size isn't
correct. `munmap` will unmap the whole page if the size you pass lies
within a page. So `num * size_of_each` will always do the right thing,
without needing to have userspace code round anything up. (From the man
page: "The address addr must be a multiple of the page size (but length
need not be). All pages containing a part of the indicated range are
unmapped.") And as you can see in my example code, nothing is rounded
up. So I don't know why you made that comment.
> And if so, what color should the bikeshed really have. I.e.,
No color, thanks.
> Also, should vgetrandom_alloc() take a void *hint argument that
> would/could be passed through to mmap() to give userspace some control
> over where the memory is located - possibly only in the future, i.e.
> insist on it being NULL for now, but it could open the possibility for
> adding e.g. VGRND_MAP_FIXED[_NOREPLACE] that would translate to the
> corresponding MAP_ flags.
I think adding more control is exactly what this is trying to avoid.
It's very intentionally *not* a general allocator function, but
something specific for vDSO getrandom(). However, it does already, in
this very patchset here, take a (currently unused) flags argument, in
case we have the need for later extension.
In the meantime, however, I'm not very interested in complicating this
interface into oblivion. Firstly, it ensures nothing will get done. But
moreover, this interface needs to be somewhat future-proof, yes, but it
does not need to be a general syscall; rather, it's a specific syscall
for a specific task.
Jason
next prev parent reply other threads:[~2022-11-24 1:18 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-21 15:29 [PATCH v6 0/3] implement getrandom() in vDSO Jason A. Donenfeld
2022-11-21 15:29 ` [PATCH v6 1/3] random: add vgetrandom_alloc() syscall Jason A. Donenfeld
2022-11-23 10:46 ` Florian Weimer
2022-11-24 1:04 ` Jason A. Donenfeld
2022-11-24 5:25 ` Florian Weimer
2022-11-24 12:03 ` Jason A. Donenfeld
2022-11-24 12:15 ` Florian Weimer
2022-11-24 12:24 ` Jason A. Donenfeld
2022-11-24 12:48 ` Jason A. Donenfeld
2022-11-24 13:18 ` Arnd Bergmann
2022-11-24 12:49 ` Christian Brauner
2022-11-24 12:57 ` Jason A. Donenfeld
2022-11-24 16:30 ` Jason A. Donenfeld
2022-11-21 15:29 ` [PATCH v6 2/3] random: introduce generic vDSO getrandom() implementation Jason A. Donenfeld
2022-11-23 8:51 ` Rasmus Villemoes
2022-11-24 1:18 ` Jason A. Donenfeld [this message]
2022-11-25 8:02 ` Rasmus Villemoes
2022-11-23 10:48 ` Florian Weimer
2022-11-24 1:08 ` Jason A. Donenfeld
2022-11-24 5:28 ` Florian Weimer
2022-11-24 11:57 ` Jason A. Donenfeld
2022-11-21 15:29 ` [PATCH v6 3/3] x86: vdso: Wire up getrandom() vDSO implementation Jason A. Donenfeld
2022-11-22 20:14 ` [PATCH v6 0/3] implement getrandom() in vDSO 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=Y37GXIQVvUvRac6D@zx2c4.com \
--to=jason@zx2c4.com \
--cc=adhemerval.zanella@linaro.org \
--cc=carlos@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=linux@rasmusvillemoes.dk \
--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