From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B63B9C4332F for ; Thu, 13 Oct 2022 09:25:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C7B66B0071; Thu, 13 Oct 2022 05:25:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 277966B0073; Thu, 13 Oct 2022 05:25:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1404D8E0001; Thu, 13 Oct 2022 05:25:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id F36146B0071 for ; Thu, 13 Oct 2022 05:25:28 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BC5B71C6E30 for ; Thu, 13 Oct 2022 09:25:28 +0000 (UTC) X-FDA: 80015393136.30.83E99B3 Received: from mail.sf-mail.de (mail.sf-mail.de [116.202.16.50]) by imf24.hostedemail.com (Postfix) with ESMTP id 21D2A180031 for ; Thu, 13 Oct 2022 09:25:26 +0000 (UTC) Received: (qmail 7803 invoked from network); 13 Oct 2022 09:25:01 -0000 Received: from p200300cf070ada0076d435fffeb7be92.dip0.t-ipconnect.de ([2003:cf:70a:da00:76d4:35ff:feb7:be92]:60562 HELO eto.sf-tec.de) (auth=eike@sf-mail.de) by mail.sf-mail.de (Qsmtpd 0.38dev) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPSA for ; Thu, 13 Oct 2022 11:25:01 +0200 From: Rolf Eike Beer To: linux-kernel@vger.kernel.org, patches@lists.linux.dev, "Jason A. Donenfeld" , Andrew Morton , Florian Westphal , Herbert Xu , Thomas Graf , kasan-dev@googlegroups.com Cc: Greg Kroah-Hartman , kernel-janitors@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-block@vger.kernel.org, linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-media@vger.kernel.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-mmc@vger.kernel.org, linux-mtd@lists.infradead.org, linux-nvme@lists.infradead.org, linux-parisc@vger.kernel.org, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, linux-um@lists.infradead.org, linux-usb@vger.kernel.org, linux-wireless@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev, netdev@vger.kernel.org, sparclinux@vger.kernel.org, x86@kernel.org Subject: Re: [PATCH v6 5/7] treewide: use get_random_u32() when possible Date: Thu, 13 Oct 2022 11:25:11 +0200 Message-ID: <3026360.ZldQQBzMgz@eto.sf-tec.de> In-Reply-To: <20221010230613.1076905-6-Jason@zx2c4.com> References: <20221010230613.1076905-1-Jason@zx2c4.com> <20221010230613.1076905-6-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart3480752.mCL07Ym2y3"; micalg="pgp-sha1"; protocol="application/pgp-signature" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665653127; a=rsa-sha256; cv=none; b=Vmw3zCTuugNZEp4Mx14faK7EAgit7KXlI8VX9DFWXtfDGV4lOof27GkdofqMICgXHuDv0z eTo/Fbbea7+mbVg/kbc50k7aMnPzv5CgdVmwHs7jBiZo1K+LvsakyozycSq9jK1d5yLXsz l8BIBlWldkTDAverH8u2bI/xRqp4uJE= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.hostedemail.com: domain of eike-kernel@sf-tec.de designates 116.202.16.50 as permitted sender) smtp.mailfrom=eike-kernel@sf-tec.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665653127; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PGr43rTMVVBU9j82VQ+fX4s9a8yR0WyR1v8YT5dHHAU=; b=1z7rGp4ticAG0xGuoLfMS6MKfwOy0gR/TH2B6uB4hbwPlAloyHSFZaruUFqvKq/rhDQrGz miqGV6IBqRLp8WgX8+yoWmrcJKOwZXa5iSrGtcs2NP21P842Ro96+P4YIx9P27s+t0Cqx3 ZT9lc+9aAt252K06aUEhaGU6rr17qwA= X-Stat-Signature: gjudkgdfzikmudib8w35fqziexroh8zt X-Rspamd-Queue-Id: 21D2A180031 Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.hostedemail.com: domain of eike-kernel@sf-tec.de designates 116.202.16.50 as permitted sender) smtp.mailfrom=eike-kernel@sf-tec.de X-Rspam-User: X-Rspamd-Server: rspam03 X-HE-Tag: 1665653126-294135 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: --nextPart3480752.mCL07Ym2y3 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1"; protected-headers="v1" From: Rolf Eike Beer Date: Thu, 13 Oct 2022 11:25:11 +0200 Message-ID: <3026360.ZldQQBzMgz@eto.sf-tec.de> In-Reply-To: <20221010230613.1076905-6-Jason@zx2c4.com> MIME-Version: 1.0 Am Dienstag, 11. Oktober 2022, 01:06:11 CEST schrieb Jason A. Donenfeld: > 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. The same also applies to get_random_int(), which is > just a wrapper around get_random_u32(). This was done as a basic find > and replace. >=20 > Reviewed-by: Greg Kroah-Hartman > Reviewed-by: Kees Cook > Reviewed-by: Yury Norov > Acked-by: Toke H=F8iland-J=F8rgensen # for sch_cake > Acked-by: Chuck Lever # for nfsd > Reviewed-by: Jan Kara # for ext4 > Acked-by: Mika Westerberg # for > thunderbolt Acked-by: Darrick J. Wong # for xfs > Signed-off-by: Jason A. Donenfeld > --- > Documentation/networking/filter.rst | 2 +- > arch/parisc/kernel/process.c | 2 +- > arch/parisc/kernel/sys_parisc.c | 4 ++-- > arch/s390/mm/mmap.c | 2 +- > arch/x86/kernel/cpu/amd.c | 2 +- > drivers/gpu/drm/i915/i915_gem_gtt.c | 6 +++--- > drivers/gpu/drm/i915/selftests/i915_selftest.c | 2 +- > drivers/gpu/drm/tests/drm_buddy_test.c | 2 +- > drivers/gpu/drm/tests/drm_mm_test.c | 2 +- > drivers/infiniband/hw/cxgb4/cm.c | 4 ++-- > drivers/infiniband/hw/hfi1/tid_rdma.c | 2 +- > drivers/infiniband/hw/mlx4/mad.c | 2 +- > drivers/infiniband/ulp/ipoib/ipoib_cm.c | 2 +- > drivers/md/raid5-cache.c | 2 +- > .../media/test-drivers/vivid/vivid-touch-cap.c | 4 ++-- > drivers/misc/habanalabs/gaudi2/gaudi2.c | 2 +- > drivers/net/bonding/bond_main.c | 2 +- > drivers/net/ethernet/broadcom/cnic.c | 2 +- > .../chelsio/inline_crypto/chtls/chtls_cm.c | 2 +- > drivers/net/ethernet/rocker/rocker_main.c | 6 +++--- > .../wireless/broadcom/brcm80211/brcmfmac/pno.c | 2 +- > .../net/wireless/marvell/mwifiex/cfg80211.c | 4 ++-- > .../net/wireless/microchip/wilc1000/cfg80211.c | 2 +- > .../net/wireless/quantenna/qtnfmac/cfg80211.c | 2 +- > drivers/net/wireless/ti/wlcore/main.c | 2 +- > drivers/nvme/common/auth.c | 2 +- > drivers/scsi/cxgbi/cxgb4i/cxgb4i.c | 4 ++-- > drivers/target/iscsi/cxgbit/cxgbit_cm.c | 2 +- > drivers/thunderbolt/xdomain.c | 2 +- > drivers/video/fbdev/uvesafb.c | 2 +- > fs/exfat/inode.c | 2 +- > fs/ext4/ialloc.c | 2 +- > fs/ext4/ioctl.c | 4 ++-- > fs/ext4/mmp.c | 2 +- > fs/f2fs/namei.c | 2 +- > fs/fat/inode.c | 2 +- > fs/nfsd/nfs4state.c | 4 ++-- > fs/ntfs3/fslog.c | 6 +++--- > fs/ubifs/journal.c | 2 +- > fs/xfs/libxfs/xfs_ialloc.c | 2 +- > fs/xfs/xfs_icache.c | 2 +- > fs/xfs/xfs_log.c | 2 +- > include/net/netfilter/nf_queue.h | 2 +- > include/net/red.h | 2 +- > include/net/sock.h | 2 +- > kernel/bpf/bloom_filter.c | 2 +- > kernel/bpf/core.c | 2 +- > kernel/bpf/hashtab.c | 2 +- > kernel/bpf/verifier.c | 2 +- > kernel/kcsan/selftest.c | 2 +- > lib/random32.c | 2 +- > lib/reed_solomon/test_rslib.c | 6 +++--- > lib/test_fprobe.c | 2 +- > lib/test_kprobes.c | 2 +- > lib/test_min_heap.c | 6 +++--- > lib/test_rhashtable.c | 6 +++--- > mm/shmem.c | 2 +- > mm/slab.c | 2 +- > net/core/pktgen.c | 4 ++-- > net/ipv4/route.c | 2 +- > net/ipv4/tcp_cdg.c | 2 +- > net/ipv4/udp.c | 2 +- > net/ipv6/ip6_flowlabel.c | 2 +- > net/ipv6/output_core.c | 2 +- > net/netfilter/ipvs/ip_vs_conn.c | 2 +- > net/netfilter/xt_statistic.c | 2 +- > net/openvswitch/actions.c | 2 +- > net/sched/sch_cake.c | 2 +- > net/sched/sch_netem.c | 18 +++++++++--------- > net/sunrpc/auth_gss/gss_krb5_wrap.c | 4 ++-- > net/sunrpc/xprt.c | 2 +- > net/unix/af_unix.c | 2 +- > 72 files changed, 101 insertions(+), 101 deletions(-) >=20 > diff --git a/lib/test_rhashtable.c b/lib/test_rhashtable.c > index 5a1dd4736b56..b358a74ed7ed 100644 > --- a/lib/test_rhashtable.c > +++ b/lib/test_rhashtable.c > @@ -291,7 +291,7 @@ static int __init test_rhltable(unsigned int entries) > if (WARN_ON(err)) > goto out_free; >=20 > - k =3D prandom_u32(); > + k =3D get_random_u32(); > ret =3D 0; > for (i =3D 0; i < entries; i++) { > rhl_test_objects[i].value.id =3D k; This one looks ok. > @@ -369,12 +369,12 @@ static int __init test_rhltable(unsigned int entrie= s) > pr_info("test %d random rhlist add/delete operations\n", entries); > for (j =3D 0; j < entries; j++) { > u32 i =3D prandom_u32_max(entries); > - u32 prand =3D prandom_u32(); > + u32 prand =3D get_random_u32(); >=20 > cond_resched(); >=20 > if (prand =3D=3D 0) > - prand =3D prandom_u32(); > + prand =3D get_random_u32(); >=20 > if (prand & 1) { > prand >>=3D 1; But this doesn't make any sense to me. It needs a bit more context: > continue; > } Why would one change prand wen it will be overwritten in the next loop anyw= ay? > err =3D rhltable_remove(&rhlt, &rhl_test_objects[i].list_node, test_rht_= params); > if (test_bit(i, obj_in_table)) { > clear_bit(i, obj_in_table); > if (WARN(err, "cannot remove element at slot %d", i)) > continue; > } else { > if (WARN(err !=3D -ENOENT, "removed non-existent element %d, error %d n= ot %d", > i, err, -ENOENT)) > continue; > } > > if (prand & 1) { > prand >>=3D 1; > continue; > } The same code again, and in this case it is impossible to reach, as the che= ck=20 already returned false before. Should these have been something like this in the first place: if (prand & 1) prand >>=3D1; else continue; At least as the code looks now this only ever needs a single bit of randomn= ess, and the later checks and the shift can go away, but I suspect that somethin= g=20 else was meant with that code. =46lorian, can you comment and maybe fix it? When possible use prandom_u8()= as=20 it seems to me that you only need 3 bytes of randomness here anyway. Or you wanted to move the variable before the loop and keep the random state between the loops and only reseed when all '1' bits have been consumed. But= =20 even in this case the later checks seem wrong as the value has not changed = in=20 between. Eike --nextPart3480752.mCL07Ym2y3 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQSaYVDeqwKa3fTXNeNcpIk+abn8TgUCY0fZeAAKCRBcpIk+abn8 TntwAJ9xzxWkK3p1U0eDZrP7KBVqifG2qQCfX+QJlO38O9/0GmN/6UVEEt2C1l8= =+1Dc -----END PGP SIGNATURE----- --nextPart3480752.mCL07Ym2y3--