linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] random: add 8-bit and 16-bit batches
@ 2022-09-28 16:50 Jason A. Donenfeld
  2022-11-25  4:10 ` Sandy Harris
  0 siblings, 1 reply; 3+ messages in thread
From: Jason A. Donenfeld @ 2022-09-28 16:50 UTC (permalink / raw)
  To: linux-kernel, linux-crypto; +Cc: Jason A. Donenfeld

There are numerous places in the kernel that would be sped up by having
smaller batches. Currently those callsites do `get_random_u32() & 0xff`
or similar. Since these are pretty spread out, and will require patches
to multiple different trees, let's get ahead of the curve and lay the
foundation for `get_random_u8()` and `get_random_u16()`, so that it's
then possible to start submitting conversion patches leisurely.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/char/random.c  | 2 ++
 include/linux/random.h | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index f2aa3ab1b458..64ee16ffb8b7 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -506,6 +506,8 @@ EXPORT_SYMBOL(get_random_ ##type);
 
 DEFINE_BATCHED_ENTROPY(u64)
 DEFINE_BATCHED_ENTROPY(u32)
+DEFINE_BATCHED_ENTROPY(u16)
+DEFINE_BATCHED_ENTROPY(u8)
 
 #ifdef CONFIG_SMP
 /*
diff --git a/include/linux/random.h b/include/linux/random.h
index a9e6e16f9774..2c130f8f18e5 100644
--- a/include/linux/random.h
+++ b/include/linux/random.h
@@ -38,6 +38,8 @@ static inline int unregister_random_vmfork_notifier(struct notifier_block *nb) {
 #endif
 
 void get_random_bytes(void *buf, size_t len);
+u8 get_random_u8(void);
+u16 get_random_u16(void);
 u32 get_random_u32(void);
 u64 get_random_u64(void);
 static inline unsigned int get_random_int(void)
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] random: add 8-bit and 16-bit batches
  2022-09-28 16:50 [PATCH] random: add 8-bit and 16-bit batches Jason A. Donenfeld
@ 2022-11-25  4:10 ` Sandy Harris
  2022-11-25 15:04   ` David Laight
  0 siblings, 1 reply; 3+ messages in thread
From: Sandy Harris @ 2022-11-25  4:10 UTC (permalink / raw)
  To: Jason A. Donenfeld; +Cc: linux-kernel, linux-crypto

On Thu, Sep 29, 2022 at 1:33 AM Jason A. Donenfeld <Jason@zx2c4.com> wrote:
>
> There are numerous places in the kernel that would be sped up by having
> smaller batches. ...

>  void get_random_bytes(void *buf, size_t len);
> +u8 get_random_u8(void);
> +u16 get_random_u16(void);
>  u32 get_random_u32(void);
>  u64 get_random_u64(void);
>  static inline unsigned int get_random_int(void)

To me, the 32-bit & 64-bit functions look like an
obviously good idea. However, I cannot see
that the 8-bit or 16-bit functions are needed.

Even library functions like getchar() return an
int & whatever you return, it is going to be
handled as an int-sized item if it goes in a
register, so what's the point?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH] random: add 8-bit and 16-bit batches
  2022-11-25  4:10 ` Sandy Harris
@ 2022-11-25 15:04   ` David Laight
  0 siblings, 0 replies; 3+ messages in thread
From: David Laight @ 2022-11-25 15:04 UTC (permalink / raw)
  To: 'Sandy Harris', Jason A. Donenfeld; +Cc: linux-kernel, linux-crypto

From: Sandy Harris
> Sent: 25 November 2022 04:11
> 
> On Thu, Sep 29, 2022 at 1:33 AM Jason A. Donenfeld <Jason@zx2c4.com> wrote:
> >
> > There are numerous places in the kernel that would be sped up by having
> > smaller batches. ...
> 
> >  void get_random_bytes(void *buf, size_t len);
> > +u8 get_random_u8(void);
> > +u16 get_random_u16(void);
> >  u32 get_random_u32(void);
> >  u64 get_random_u64(void);
> >  static inline unsigned int get_random_int(void)
> 
> To me, the 32-bit & 64-bit functions look like an
> obviously good idea. However, I cannot see
> that the 8-bit or 16-bit functions are needed.
> 
> Even library functions like getchar() return an
> int & whatever you return, it is going to be
> handled as an int-sized item if it goes in a
> register, so what's the point?

They avoid 'using up' random values the callers wont use.
This can save expensive re-hashing (etc).

OTOH the return types should probably be u32 even though the
domain is smaller.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-25 15:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-28 16:50 [PATCH] random: add 8-bit and 16-bit batches Jason A. Donenfeld
2022-11-25  4:10 ` Sandy Harris
2022-11-25 15:04   ` David Laight

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).