public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"patches@lists.linux.dev" <patches@lists.linux.dev>
Cc: "linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>,
	"x86@kernel.org" <x86@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>,
	Carlos O'Donell <carlos@redhat.com>
Subject: Re: [PATCH v4 2/3] random: introduce generic vDSO getrandom() implementation
Date: Fri, 18 Nov 2022 19:34:26 +0000	[thread overview]
Message-ID: <ecfd265b-49e7-79b2-1818-e08a2c652db0@csgroup.eu> (raw)
In-Reply-To: <20221118172839.2653829-3-Jason@zx2c4.com>



Le 18/11/2022 à 18:28, Jason A. Donenfeld a écrit :
> Provide a generic C vDSO getrandom() implementation, which operates on
> an opaque state returned by vgetrandom_alloc() and produces random bytes
> the same way as getrandom(). This has a the API signature:
> 
>    ssize_t vgetrandom(void *buffer, size_t len, unsigned int flags, void *opaque_state);
> 

...

> diff --git a/lib/vdso/getrandom.c b/lib/vdso/getrandom.c
> new file mode 100644
> index 000000000000..b253e9247706
> --- /dev/null
> +++ b/lib/vdso/getrandom.c
> @@ -0,0 +1,109 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (C) 2022 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/atomic.h>
> +#include <linux/fs.h>
> +#include <vdso/datapage.h>
> +#include <asm/vdso/getrandom.h>
> +#include <asm/vdso/vsyscall.h>
> +#include "getrandom.h"
> +
> +#undef memcpy
> +#define memcpy(d,s,l) __builtin_memcpy(d,s,l)
> +#undef memset
> +#define memset(d,c,l) __builtin_memset(d,c,l)
> +
> +#define CHACHA_FOR_VDSO_INCLUDE
> +#include "../crypto/chacha.c"
> +
> +static void memcpy_and_zero(void *dst, void *src, size_t len)
> +{
> +#define CASCADE(type) \
> +	while (len >= sizeof(type)) { \
> +		*(type *)dst = *(type *)src; \
> +		*(type *)src = 0; \
> +		dst += sizeof(type); \
> +		src += sizeof(type); \
> +		len -= sizeof(type); \
> +	}
> +#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
> +#if BITS_PER_LONG == 64
> +	CASCADE(u64);
> +#endif
> +	CASCADE(u32);
> +	CASCADE(u16);
> +#endif
> +	CASCADE(u8);
> +#undef CASCADE
> +}
> +
> +static __always_inline ssize_t
> +__cvdso_getrandom(void *buffer, size_t len, unsigned int flags, void *opaque_state)
> +{
> +	struct vgetrandom_state *state = opaque_state;
> +	const struct vdso_rng_data *rng_info = __arch_get_vdso_rng_data();

In order to ease wiring up to powerpc, can it be done the same way as 
commit e876f0b69dc9 ("lib/vdso: Allow architectures to provide the vdso 
data pointer")

> +	u32 chacha_state[CHACHA_STATE_WORDS];
> +	ssize_t ret = min_t(size_t, MAX_RW_COUNT, len);
> +	unsigned long current_generation;
> +	size_t batch_len;
> +

Thanks,
Christophe

  reply	other threads:[~2022-11-18 19:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-18 17:28 [PATCH v4 0/3] implement getrandom() in vDSO Jason A. Donenfeld
2022-11-18 17:28 ` [PATCH v4 1/3] random: add vgetrandom_alloc() syscall Jason A. Donenfeld
2022-11-19  0:20   ` Jason A. Donenfeld
2022-11-18 17:28 ` [PATCH v4 2/3] random: introduce generic vDSO getrandom() implementation Jason A. Donenfeld
2022-11-18 19:34   ` Christophe Leroy [this message]
2022-11-18 23:55     ` Jason A. Donenfeld
2022-11-19  0:04       ` Jason A. Donenfeld
2022-11-19  7:51         ` Christophe Leroy
2022-11-19 11:43           ` Jason A. Donenfeld
2022-11-19 12:12             ` Jason A. Donenfeld
2022-11-18 17:28 ` [PATCH v4 3/3] x86: vdso: Wire up getrandom() vDSO implementation 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=ecfd265b-49e7-79b2-1818-e08a2c652db0@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --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