LVS
lvs-devel
Google
 
Web LinuxVirtualServer.org

Re: [PATCH v1 3/5] treewide: use get_random_u32() when possible

To: "Jason A. Donenfeld" <Jason@xxxxxxxxx>
Subject: Re: [PATCH v1 3/5] treewide: use get_random_u32() when possible
Cc: Jason Gunthorpe <jgg@xxxxxxxx>, linux-kernel@xxxxxxxxxxxxxxx, brcm80211-dev-list.pdl@xxxxxxxxxxxx, cake@xxxxxxxxxxxxxxxxxxxxx, ceph-devel@xxxxxxxxxxxxxxx, coreteam@xxxxxxxxxxxxx, dccp@xxxxxxxxxxxxxxx, dev@xxxxxxxxxxxxxxx, dmaengine@xxxxxxxxxxxxxxx, drbd-dev@xxxxxxxxxxxxxxxx, dri-devel@xxxxxxxxxxxxxxxxxxxxx, kasan-dev@xxxxxxxxxxxxxxxx, linux-actions@xxxxxxxxxxxxxxxxxxx, linux-arm-kernel@xxxxxxxxxxxxxxxxxxx, linux-block@xxxxxxxxxxxxxxx, linux-crypto@xxxxxxxxxxxxxxx, linux-doc@xxxxxxxxxxxxxxx, linux-ext4@xxxxxxxxxxxxxxx, linux-f2fs-devel@xxxxxxxxxxxxxxxxxxxxx, linux-fbdev@xxxxxxxxxxxxxxx, linux-fsdevel@xxxxxxxxxxxxxxx, linux-hams@xxxxxxxxxxxxxxx, linux-media@xxxxxxxxxxxxxxx, linux-mm@xxxxxxxxx, linux-mmc@xxxxxxxxxxxxxxx, linux-mtd@xxxxxxxxxxxxxxxxxxx, linux-nfs@xxxxxxxxxxxxxxx, linux-nvme@xxxxxxxxxxxxxxxxxxx, linux-raid@xxxxxxxxxxxxxxx, linux-rdma@xxxxxxxxxxxxxxx, linux-scsi@xxxxxxxxxxxxxxx, linux-sctp@xxxxxxxxxxxxxxx, linux-stm32@xxxxxxxxxxxxxxxxxxxxxxxxxxxx, linux-usb@xxxxxxxxxxxxxxx, linux-wireless@xxxxxxxxxxxxxxx, linux-xfs@xxxxxxxxxxxxxxx, linuxppc-dev@xxxxxxxxxxxxxxxx, lvs-devel@xxxxxxxxxxxxxxx, netdev@xxxxxxxxxxxxxxx, netfilter-devel@xxxxxxxxxxxxxxx, rds-devel@xxxxxxxxxxxxxx, SHA-cyfmac-dev-list@xxxxxxxxxxxx, target-devel@xxxxxxxxxxxxxxx, tipc-discussion@xxxxxxxxxxxxxxxxxxxxx
From: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
Date: Thu, 6 Oct 2022 16:20:31 +0300
On Thu, Oct 06, 2022 at 07:05:48AM -0600, Jason A. Donenfeld wrote:
> On Thu, Oct 6, 2022 at 6:47 AM Jason Gunthorpe <jgg@xxxxxxxx> wrote:
> > On Wed, Oct 05, 2022 at 11:48:42PM +0200, Jason A. Donenfeld wrote:

...

> > > -     u32 isn = (prandom_u32() & ~7UL) - 1;
> > > +     u32 isn = (get_random_u32() & ~7UL) - 1;
> >
> > Maybe this wants to be written as
> >
> > (prandom_max(U32_MAX >> 7) << 7) | 7

> > ?
> 
> Holy smokes. Yea I guess maybe? It doesn't exactly gain anything or
> make the code clearer though, and is a little bit more magical than
> I'd like on a first pass.

Shouldn't the two first 7s to be 3s?

...

> > > -     psn = prandom_u32() & 0xffffff;
> > > +     psn = get_random_u32() & 0xffffff;
> >
> >  prandom_max(0xffffff + 1)
> 
> That'd work, but again it's not more clear. Authors here are going for
> a 24-bit number, and masking seems like a clear way to express that.

We have some 24-bit APIs (and 48-bit) already in kernel, why not to have
get_random_u24() ?


-- 
With Best Regards,
Andy Shevchenko



<Prev in Thread] Current Thread [Next in Thread>