From 2b221c1ba7fa406135e319b265ca610f03d6e4f9 Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Mon, 21 Apr 2025 13:47:22 -0700 Subject: [PATCH] prandom_bytes and family removed, switch to get_random_bytes variants In v6.1-rc5-2-ge9a688bcb193, get_random_u32_below() becomes available and can start replacing prandom_bytes_max(). Switch to it where we can. get_random_bytes() has been available since el7, so also replace prandom_bytes() where we're using it. Signed-off-by: Auke Kok --- kmod/src/Makefile.kernelcompat | 8 ++++++++ kmod/src/block.c | 2 +- kmod/src/inode.c | 2 +- kmod/src/kernelcompat.h | 4 ++++ kmod/src/quorum.c | 2 +- kmod/src/quota.c | 2 +- 6 files changed, 16 insertions(+), 4 deletions(-) diff --git a/kmod/src/Makefile.kernelcompat b/kmod/src/Makefile.kernelcompat index 81dc8a58..911e70de 100644 --- a/kmod/src/Makefile.kernelcompat +++ b/kmod/src/Makefile.kernelcompat @@ -496,3 +496,11 @@ endif ifneq (,$(shell grep 'struct posix_acl.*get_inode_acl' include/linux/fs.h)) ccflags-y += -DKC_GET_INODE_ACL endif + +# +# v6.1-rc5-2-ge9a688bcb193 +# +# get_random_u32_below() implementation +ifneq (,$(shell grep 'u32 get_random_u32_below' include/linux/random.h)) +ccflags-y += -DKC_HAVE_GET_RANDOM_U32_BELOW +endif diff --git a/kmod/src/block.c b/kmod/src/block.c index 463e1b01..a9a95d82 100644 --- a/kmod/src/block.c +++ b/kmod/src/block.c @@ -884,7 +884,7 @@ int scoutfs_block_dirty_ref(struct super_block *sb, struct scoutfs_alloc *alloc, hdr->magic = cpu_to_le32(magic); hdr->fsid = cpu_to_le64(sbi->fsid); hdr->blkno = cpu_to_le64(bl->blkno); - prandom_bytes(&hdr->seq, sizeof(hdr->seq)); + get_random_bytes(&hdr->seq, sizeof(hdr->seq)); trace_scoutfs_block_dirty_ref(sb, le64_to_cpu(ref->blkno), le64_to_cpu(ref->seq), le64_to_cpu(hdr->blkno), le64_to_cpu(hdr->seq)); diff --git a/kmod/src/inode.c b/kmod/src/inode.c index a4d118f1..e3458728 100644 --- a/kmod/src/inode.c +++ b/kmod/src/inode.c @@ -2068,7 +2068,7 @@ void scoutfs_inode_schedule_orphan_dwork(struct super_block *sb) low = (opts.orphan_scan_delay_ms * 80) / 100; high = (opts.orphan_scan_delay_ms * 120) / 100; - delay = msecs_to_jiffies(low + prandom_u32_max(high - low)) ?: 1; + delay = msecs_to_jiffies(low + get_random_u32_below(high - low)) ?: 1; mod_delayed_work(system_wq, &inf->orphan_scan_dwork, delay); } diff --git a/kmod/src/kernelcompat.h b/kmod/src/kernelcompat.h index 5564a12a..9f6fd2b4 100644 --- a/kmod/src/kernelcompat.h +++ b/kmod/src/kernelcompat.h @@ -489,4 +489,8 @@ static inline void stack_trace_print(unsigned long *entries, unsigned int nr_ent } #endif +#ifndef KC_HAVE_GET_RANDOM_U32_BELOW +#define get_random_u32_below prandom_u32_max +#endif + #endif diff --git a/kmod/src/quorum.c b/kmod/src/quorum.c index fc25904e..abb331cc 100644 --- a/kmod/src/quorum.c +++ b/kmod/src/quorum.c @@ -162,7 +162,7 @@ static void quorum_slot_sin(struct scoutfs_quorum_config *qconf, int i, struct s static ktime_t election_timeout(void) { return ktime_add_ms(ktime_get(), SCOUTFS_QUORUM_ELECT_MIN_MS + - prandom_u32_max(SCOUTFS_QUORUM_ELECT_VAR_MS)); + get_random_u32_below(SCOUTFS_QUORUM_ELECT_VAR_MS)); } static ktime_t heartbeat_interval(void) diff --git a/kmod/src/quota.c b/kmod/src/quota.c index fc2cd461..b9461a15 100644 --- a/kmod/src/quota.c +++ b/kmod/src/quota.c @@ -205,7 +205,7 @@ static struct squota_check *lookup_random_check(struct rhashtable *rht) tbl = rht_dereference_rcu(rht->tbl, rht); do { - for (s = 0, i = prandom_u32_max(tbl->size); + for (s = 0, i = get_random_u32_below(tbl->size); s < tbl->size; s++, i = (i + 1) % tbl->size) { rht_for_each_entry_rcu(chk, pos, tbl, i, head) {