From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kara Subject: Re: [PATCH v1 3/5] treewide: use get_random_u32() when possible Date: Thu, 6 Oct 2022 10:43:31 +0200 Message-ID: <20221006084331.4bdktc2zlvbaszym@quack3> References: <20221005214844.2699-1-Jason@zx2c4.com> <20221005214844.2699-4-Jason@zx2c4.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=In-Reply-To:Content-Type:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=T7S6oIxhAYkW+alnUKWtP6uIux66B8EsW4GqVBZ8bto=; b=EKXHnVqoSpVBCg8JcBPdAWX5w8 0XrpBPo8rnGgiQaYqOHPZWTQBlRaNPW7kiPc/lp+T5IV1f8On2yw/95gHSnYxFMZTowUXvmEIY6Kg GPuBx0wquB3B/89TpFnm9SMiuKoiEj7TzZ+zccvIPFsJq8E9CVWMc/6b/grcKObjvqNE=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To :From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=T7S6oIxhAYkW+alnUKWtP6uIux66B8EsW4GqVBZ8bto=; b=NxD79yjkx0BIG33ngvBGG8Lj38 KBX1l/KfQseT0lXHboQWy/GqzvlzZJOP6+vEz6vh6N0kQ/krfl453zBM/hAP+OknNQOMTXpNLM82U E8draC38Nsf8bKMqmqsvu83u+vivH5+1DVKGG05axv4zS1FRbvjFVpJKX42/lML2vH/o=; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1665045812; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=T7S6oIxhAYkW+alnUKWtP6uIux66B8EsW4GqVBZ8bto=; b=C+mCUjvr8q1OQndsJbfZXZJ3gLAGbiYxpXR3vx++9btLnUp9kZq0CQX7tRJDJnNrgG7sg5 VElWf3eFRacsDUxORP+nZNrrB49Kgh2Bx5MZY0rmM5+1STk9bN9MDPldTLpppqJY9Iu6qN Bmlx+AbYfSwFuf+/9j41GSaP+BDPvUk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1665045812; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=T7S6oIxhAYkW+alnUKWtP6uIux66B8EsW4GqVBZ8bto=; b=MznRw6bCrjyprmYZ/SVmvDwryyMeZenJtnn+Y1RkYEyFbKl4QJ6J7BM2yyxsWNj6DwaBEV ub8/BpYJGHJ7woDg== Content-Disposition: inline In-Reply-To: <20221005214844.2699-4-Jason@zx2c4.com> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net To: "Jason A. Donenfeld" Cc: Andrew Lunn , "Darrick J . Wong" , Ulf Hansson , dri-devel@lists.freedesktop.org, Andrii Nakryiko , Hans Verkuil , linux-sctp@vger.kernel.org, "Md . Haris Iqbal" , Miquel Raynal , Christoph Hellwig , Andy Gospodarek , Sergey Matyukevich , Rohit Maheshwari , Michael Ellerman , ceph-devel@vger.kernel.org, Christophe Leroy , Jozsef Kadlecsik , Nilesh Javali , Jean-Paul Roubelat , Dick Kennedy , Jay Vosburgh , Potnuri Bharat Teja , Vinay Kumar Yadav , linux-nfs@vg On Wed 05-10-22 23:48:42, 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. > > Signed-off-by: Jason A. Donenfeld ... > diff --git a/fs/ext2/ialloc.c b/fs/ext2/ialloc.c > index 998dd2ac8008..e439a872c398 100644 > --- a/fs/ext2/ialloc.c > +++ b/fs/ext2/ialloc.c > @@ -277,7 +277,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent) > int best_ndir = inodes_per_group; > int best_group = -1; > > - group = prandom_u32(); > + group = get_random_u32(); > parent_group = (unsigned)group % ngroups; > for (i = 0; i < ngroups; i++) { > group = (parent_group + i) % ngroups; The code here is effectively doing the parent_group = prandom_u32_max(ngroups); > diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c > index f73e5eb43eae..954ec9736a8d 100644 > --- a/fs/ext4/ialloc.c > +++ b/fs/ext4/ialloc.c > @@ -465,7 +465,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent, > ext4fs_dirhash(parent, qstr->name, qstr->len, &hinfo); > grp = hinfo.hash; > } else > - grp = prandom_u32(); > + grp = get_random_u32(); Similarly here we can use prandom_u32_max(ngroups) like: if (qstr) { ... parent_group = hinfo.hash % ngroups; } else parent_group = prandom_u32_max(ngroups); > diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c > index 9af68a7ecdcf..588cb09c5291 100644 > --- a/fs/ext4/mmp.c > +++ b/fs/ext4/mmp.c > @@ -265,7 +265,7 @@ static unsigned int mmp_new_seq(void) > u32 new_seq; > > do { > - new_seq = prandom_u32(); > + new_seq = get_random_u32(); > } while (new_seq > EXT4_MMP_SEQ_MAX); OK, here we again effectively implement prandom_u32_max(EXT4_MMP_SEQ_MAX + 1). Just presumably we didn't want to use modulo here because EXT4_MMP_SEQ_MAX is rather big and so the resulting 'new_seq' would be seriously non-uniform. Honza -- Jan Kara SUSE Labs, CR