From: Florian Weimer <fweimer@redhat.com>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
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>
Subject: Re: [PATCH v6 2/3] random: introduce generic vDSO getrandom() implementation
Date: Thu, 24 Nov 2022 06:28:44 +0100 [thread overview]
Message-ID: <875yf47wfn.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <Y37EHHq41KBvgr8z@zx2c4.com> (Jason A. Donenfeld's message of "Thu, 24 Nov 2022 02:08:44 +0100")
* Jason A. Donenfeld:
> Hi Florian,
>
> On Wed, Nov 23, 2022 at 11:48:06AM +0100, Florian Weimer wrote:
>> * Jason A. Donenfeld:
>>
>> > static void *vgetrandom_alloc(size_t *num, size_t *size_per_each, unsigned int flags)
>> > {
>> > unsigned long ret = syscall(__NR_vgetrandom_alloc, num, size_per_each, flags);
>> > return ret > -4096UL ? NULL : (void *)ret;
>> > }
>>
>> The traditional syscall function returns -1 on error and set errors, so
>> using unsing long and the 4096 is quite misleading.
>
> Not sure I have any idea at all whatsoever about what you're talking
> about. Firstly, the function you quoted is from the "sample userspace
> code" in the commit message, so it might not be code for the context you
> have in mind.
I'm talking about the syscall function that is available through
userspace via <sys/syscall.h>.
> Secondly, it's just doing the thing to figure out if the return value is
> an error value or a pointer. Were we in glibc, we'd write this as:
>
> return INTERNAL_SYSCALL_ERROR_P(r) ? NULL : (void *) r;
>
> Right? And if you look at the expansion of that glibc macro, it's just:
>
> #define INTERNAL_SYSCALL_ERROR_P(val) \
> ((unsigned long int) (val) > -4096UL)
>
> So it looks like the same exact thing?
syscall already does internally (with a translation to -1, not NULL), so
the caller shouldn't do it again. The userspace syscall function does
*not* return an error code.
Thanks,
Florian
next prev parent reply other threads:[~2022-11-24 5:28 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
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 [this message]
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=875yf47wfn.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=Jason@zx2c4.com \
--cc=adhemerval.zanella@linaro.org \
--cc=carlos@redhat.com \
--cc=gregkh@linuxfoundation.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;
as well as URLs for NNTP newsgroup(s).