From: "Christoph Böhmwalder" <christoph.boehmwalder@linbit.com>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>, linux-kernel@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>,
linux-block@vger.kernel.org,
Lars Ellenberg <lars.ellenberg@linbit.com>,
Philipp Reisner <philipp.reisner@linbit.com>,
drbd-dev@lists.linbit.com
Subject: Re: [Drbd-dev] [PATCH v1 1/5] treewide: use prandom_u32_max() when possible
Date: Thu, 6 Oct 2022 11:07:54 +0200 [thread overview]
Message-ID: <892bcf4d-70d9-8833-9449-c55fa719158e@linbit.com> (raw)
In-Reply-To: <20221005214844.2699-2-Jason@zx2c4.com>
On 05.10.22 23:48, Jason A. Donenfeld wrote:
> Rather than incurring a division or requesting too many random bytes for
> the given range, use the prandom_u32_max() function, which only takes
> the minimum required bytes from the RNG and avoids divisions.
>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
> arch/x86/mm/pat/cpa-test.c | 4 +-
> crypto/testmgr.c | 86 +++++++++----------
> drivers/block/drbd/drbd_receiver.c | 4 +-
For the drbd part:
Reviewed-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com>
> drivers/infiniband/core/cma.c | 2 +-
> drivers/infiniband/hw/cxgb4/id_table.c | 4 +-
> drivers/infiniband/hw/hns/hns_roce_ah.c | 5 +-
> drivers/infiniband/ulp/rtrs/rtrs-clt.c | 3 +-
> drivers/mmc/core/core.c | 4 +-
> drivers/mmc/host/dw_mmc.c | 2 +-
> drivers/mtd/nand/raw/nandsim.c | 4 +-
> drivers/mtd/tests/mtd_nandecctest.c | 10 +--
> drivers/mtd/tests/stresstest.c | 17 +---
> drivers/mtd/ubi/debug.c | 2 +-
> drivers/mtd/ubi/debug.h | 6 +-
> drivers/net/ethernet/broadcom/cnic.c | 3 +-
> .../chelsio/inline_crypto/chtls/chtls_io.c | 4 +-
> drivers/net/hamradio/baycom_epp.c | 2 +-
> drivers/net/hamradio/hdlcdrv.c | 2 +-
> drivers/net/hamradio/yam.c | 2 +-
> drivers/net/phy/at803x.c | 2 +-
> .../broadcom/brcm80211/brcmfmac/p2p.c | 2 +-
> .../net/wireless/intel/iwlwifi/mvm/mac-ctxt.c | 2 +-
> drivers/scsi/fcoe/fcoe_ctlr.c | 4 +-
> drivers/scsi/qedi/qedi_main.c | 2 +-
> fs/ceph/inode.c | 2 +-
> fs/ceph/mdsmap.c | 2 +-
> fs/ext4/super.c | 7 +-
> fs/f2fs/gc.c | 2 +-
> fs/f2fs/segment.c | 8 +-
> fs/ubifs/debug.c | 8 +-
> fs/ubifs/lpt_commit.c | 14 +--
> fs/ubifs/tnc_commit.c | 2 +-
> fs/xfs/libxfs/xfs_alloc.c | 2 +-
> fs/xfs/libxfs/xfs_ialloc.c | 2 +-
> fs/xfs/xfs_error.c | 2 +-
> kernel/time/clocksource.c | 2 +-
> lib/fault-inject.c | 2 +-
> lib/find_bit_benchmark.c | 4 +-
> lib/reed_solomon/test_rslib.c | 6 +-
> lib/sbitmap.c | 4 +-
> lib/test_list_sort.c | 2 +-
> lib/test_vmalloc.c | 17 +---
> net/ceph/mon_client.c | 2 +-
> net/ceph/osd_client.c | 2 +-
> net/core/neighbour.c | 2 +-
> net/core/pktgen.c | 43 +++++-----
> net/core/stream.c | 2 +-
> net/ipv4/igmp.c | 6 +-
> net/ipv4/inet_connection_sock.c | 2 +-
> net/ipv4/inet_hashtables.c | 2 +-
> net/ipv6/addrconf.c | 8 +-
> net/ipv6/mcast.c | 10 +--
> net/netfilter/ipvs/ip_vs_twos.c | 4 +-
> net/packet/af_packet.c | 2 +-
> net/sched/act_gact.c | 2 +-
> net/sched/act_sample.c | 2 +-
> net/sched/sch_netem.c | 4 +-
> net/sctp/socket.c | 2 +-
> net/sunrpc/cache.c | 2 +-
> net/sunrpc/xprtsock.c | 2 +-
> net/tipc/socket.c | 2 +-
> net/xfrm/xfrm_state.c | 2 +-
> 62 files changed, 173 insertions(+), 196 deletions(-)
>
[...]
> diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
> index af4c7d65490b..d8b1417dc503 100644
> --- a/drivers/block/drbd/drbd_receiver.c
> +++ b/drivers/block/drbd/drbd_receiver.c
> @@ -781,7 +781,7 @@ static struct socket *drbd_wait_for_connect(struct drbd_connection *connection,
>
> timeo = connect_int * HZ;
> /* 28.5% random jitter */
> - timeo += (prandom_u32() & 1) ? timeo / 7 : -timeo / 7;
> + timeo += prandom_u32_max(2) ? timeo / 7 : -timeo / 7;
>
> err = wait_for_completion_interruptible_timeout(&ad->door_bell, timeo);
> if (err <= 0)
> @@ -1004,7 +1004,7 @@ static int conn_connect(struct drbd_connection *connection)
> drbd_warn(connection, "Error receiving initial packet\n");
> sock_release(s);
> randomize:
> - if (prandom_u32() & 1)
> + if (prandom_u32_max(2))
> goto retry;
> }
> }[...]
(Had to cut out most of the CC list because Google complains about "too many
recipients").
--
Christoph Böhmwalder
LINBIT | Keeping the Digital World Running
DRBD HA — Disaster Recovery — Software defined Storage
next prev parent reply other threads:[~2022-10-06 9:07 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-05 21:48 [Drbd-dev] [PATCH v1 0/5] treewide cleanup of random integer usage Jason A. Donenfeld
2022-10-05 21:48 ` [Drbd-dev] [PATCH v1 1/5] treewide: use prandom_u32_max() when possible Jason A. Donenfeld
2022-10-06 4:16 ` Kees Cook
2022-10-06 4:22 ` KP Singh
2022-10-06 12:45 ` Jason A. Donenfeld
2022-10-06 12:55 ` Jason Gunthorpe
2022-10-06 13:05 ` Andy Shevchenko
2022-10-06 9:07 ` Christoph Böhmwalder [this message]
2022-10-05 21:48 ` [Drbd-dev] [PATCH v1 2/5] treewide: use get_random_{u8, u16}() " Jason A. Donenfeld
2022-10-06 4:38 ` Kees Cook
2022-10-06 12:28 ` Jason A. Donenfeld
2022-10-05 21:48 ` [Drbd-dev] [PATCH v1 3/5] treewide: use get_random_u32() " Jason A. Donenfeld
2022-10-06 8:43 ` Jan Kara
2022-10-06 12:33 ` [Drbd-dev] [f2fs-dev] " Jason A. Donenfeld
2022-10-06 13:01 ` Andy Shevchenko
2022-10-06 13:07 ` Jason A. Donenfeld
2022-10-06 12:47 ` [Drbd-dev] " Jason Gunthorpe
2022-10-06 13:05 ` Jason A. Donenfeld
2022-10-06 13:15 ` Jason Gunthorpe
2022-10-06 13:20 ` Andy Shevchenko
2022-10-12 19:16 ` Joe Perches
2022-10-12 21:29 ` David Laight
2022-10-13 1:37 ` Joe Perches
2022-10-05 21:48 ` [Drbd-dev] [PATCH v1 4/5] treewide: use get_random_bytes " Jason A. Donenfeld
2022-10-06 4:45 ` Kees Cook
2022-10-06 4:48 ` Kees Cook
2022-10-05 21:48 ` [Drbd-dev] [PATCH v1 5/5] prandom: remove unused functions Jason A. Donenfeld
2022-10-06 4:39 ` Kees Cook
2022-10-06 4:55 ` [Drbd-dev] [PATCH v1 0/5] treewide cleanup of random integer usage Kees Cook
2022-10-06 5:40 ` Kees Cook
2022-10-06 12:53 ` Jason A. Donenfeld
2022-10-06 13:49 ` [Drbd-dev] [f2fs-dev] " 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=892bcf4d-70d9-8833-9449-c55fa719158e@linbit.com \
--to=christoph.boehmwalder@linbit.com \
--cc=Jason@zx2c4.com \
--cc=axboe@kernel.dk \
--cc=drbd-dev@lists.linbit.com \
--cc=lars.ellenberg@linbit.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=philipp.reisner@linbit.com \
/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