LVS
lvs-devel
Google
 
Web LinuxVirtualServer.org

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

To: 'Joe Perches' <joe@xxxxxxxxxxx>, "Jason A. Donenfeld" <Jason@xxxxxxxxx>, "linux-kernel@xxxxxxxxxxxxxxx" <linux-kernel@xxxxxxxxxxxxxxx>
Subject: RE: [PATCH v1 3/5] treewide: use get_random_u32() when possible
Cc: "linux-fbdev@xxxxxxxxxxxxxxx" <linux-fbdev@xxxxxxxxxxxxxxx>, "linux-doc@xxxxxxxxxxxxxxx" <linux-doc@xxxxxxxxxxxxxxx>, "linux-wireless@xxxxxxxxxxxxxxx" <linux-wireless@xxxxxxxxxxxxxxx>, "dri-devel@xxxxxxxxxxxxxxxxxxxxx" <dri-devel@xxxxxxxxxxxxxxxxxxxxx>, "linux-mm@xxxxxxxxx" <linux-mm@xxxxxxxxx>, "linux-sctp@xxxxxxxxxxxxxxx" <linux-sctp@xxxxxxxxxxxxxxx>, "target-devel@xxxxxxxxxxxxxxx" <target-devel@xxxxxxxxxxxxxxx>, "linux-mtd@xxxxxxxxxxxxxxxxxxx" <linux-mtd@xxxxxxxxxxxxxxxxxxx>, "linux-stm32@xxxxxxxxxxxxxxxxxxxxxxxxxxxx" <linux-stm32@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>, "drbd-dev@xxxxxxxxxxxxxxxx" <drbd-dev@xxxxxxxxxxxxxxxx>, "dev@xxxxxxxxxxxxxxx" <dev@xxxxxxxxxxxxxxx>, "rds-devel@xxxxxxxxxxxxxx" <rds-devel@xxxxxxxxxxxxxx>, "linux-scsi@xxxxxxxxxxxxxxx" <linux-scsi@xxxxxxxxxxxxxxx>, "dccp@xxxxxxxxxxxxxxx" <dccp@xxxxxxxxxxxxxxx>, "linux-rdma@xxxxxxxxxxxxxxx" <linux-rdma@xxxxxxxxxxxxxxx>, "kasan-dev@xxxxxxxxxxxxxxxx" <kasan-dev@xxxxxxxxxxxxxxxx>, "lvs-devel@xxxxxxxxxxxxxxx" <lvs-devel@xxxxxxxxxxxxxxx>, "SHA-cyfmac-dev-list@xxxxxxxxxxxx" <SHA-cyfmac-dev-list@xxxxxxxxxxxx>, "coreteam@xxxxxxxxxxxxx" <coreteam@xxxxxxxxxxxxx>, "tipc-discussion@xxxxxxxxxxxxxxxxxxxxx" <tipc-discussion@xxxxxxxxxxxxxxxxxxxxx>, "linux-ext4@xxxxxxxxxxxxxxx" <linux-ext4@xxxxxxxxxxxxxxx>, "linux-media@xxxxxxxxxxxxxxx" <linux-media@xxxxxxxxxxxxxxx>, "linux-actions@xxxxxxxxxxxxxxxxxxx" <linux-actions@xxxxxxxxxxxxxxxxxxx>, "linux-nfs@xxxxxxxxxxxxxxx" <linux-nfs@xxxxxxxxxxxxxxx>, "linux-block@xxxxxxxxxxxxxxx" <linux-block@xxxxxxxxxxxxxxx>, "dmaengine@xxxxxxxxxxxxxxx" <dmaengine@xxxxxxxxxxxxxxx>, "linux-nvme@xxxxxxxxxxxxxxxxxxx" <linux-nvme@xxxxxxxxxxxxxxxxxxx>, "linux-hams@xxxxxxxxxxxxxxx" <linux-hams@xxxxxxxxxxxxxxx>, "ceph-devel@xxxxxxxxxxxxxxx" <ceph-devel@xxxxxxxxxxxxxxx>, "linux-arm-kernel@xxxxxxxxxxxxxxxxxxx" <linux-arm-kernel@xxxxxxxxxxxxxxxxxxx>, "cake@xxxxxxxxxxxxxxxxxxxxx" <cake@xxxxxxxxxxxxxxxxxxxxx>, "brcm80211-dev-list.pdl@xxxxxxxxxxxx" <brcm80211-dev-list.pdl@xxxxxxxxxxxx>, "linux-raid@xxxxxxxxxxxxxxx" <linux-raid@xxxxxxxxxxxxxxx>, "netdev@xxxxxxxxxxxxxxx" <netdev@xxxxxxxxxxxxxxx>, "linux-usb@xxxxxxxxxxxxxxx" <linux-usb@xxxxxxxxxxxxxxx>, "linux-mmc@xxxxxxxxxxxxxxx" <linux-mmc@xxxxxxxxxxxxxxx>, "linux-f2fs-devel@xxxxxxxxxxxxxxxxxxxxx" <linux-f2fs-devel@xxxxxxxxxxxxxxxxxxxxx>, "linux-xfs@xxxxxxxxxxxxxxx" <linux-xfs@xxxxxxxxxxxxxxx>, "netfilter-devel@xxxxxxxxxxxxxxx" <netfilter-devel@xxxxxxxxxxxxxxx>, "linux-crypto@xxxxxxxxxxxxxxx" <linux-crypto@xxxxxxxxxxxxxxx>, "linux-fsdevel@xxxxxxxxxxxxxxx" <linux-fsdevel@xxxxxxxxxxxxxxx>, "linuxppc-dev@xxxxxxxxxxxxxxxx" <linuxppc-dev@xxxxxxxxxxxxxxxx>
From: David Laight <David.Laight@xxxxxxxxxx>
Date: Wed, 12 Oct 2022 21:29:02 +0000
From: Joe Perches
> Sent: 12 October 2022 20:17
> 
> On Wed, 2022-10-05 at 23:48 +0200, Jason A. Donenfeld wrote:
> > The prandom_u32() function has been a deprecated inline wrapper around
> > get_random_u32() for several releases now, and compiles down to the
> > exact same code. Replace the deprecated wrapper with a direct call to
> > the real function.
> []
> > diff --git a/drivers/infiniband/hw/cxgb4/cm.c 
> > b/drivers/infiniband/hw/cxgb4/cm.c
> []
> > @@ -734,7 +734,7 @@ static int send_connect(struct c4iw_ep *ep)
> >                                &ep->com.remote_addr;
> >     int ret;
> >     enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
> > -   u32 isn = (prandom_u32() & ~7UL) - 1;
> > +   u32 isn = (get_random_u32() & ~7UL) - 1;
> 
> trivia:
> 
> There are somewhat odd size mismatches here.
> 
> I had to think a tiny bit if random() returned a value from 0 to 7
> and was promoted to a 64 bit value then truncated to 32 bit.
> 
> Perhaps these would be clearer as ~7U and not ~7UL

That makes no difference - the compiler will generate the same code.

The real question is WTF is the code doing?
The '& ~7u' clears the bottom 3 bits.
The '- 1' then sets the bottom 3 bits and decrements the
(random) high bits.

So is the same as get_random_u32() | 7.
But I bet the coder had something else in mind.

        David

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


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