public inbox for linux-hams@vger.kernel.org
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld via dev" <ovs-dev-yBygre7rU0TnMu66kgdUjQ@public.gmane.org>
To: Jan Kara <jack-AlSwsSmVLrQ@public.gmane.org>
Cc: Andrew Lunn <andrew-g2DYL2Zd6BY@public.gmane.org>,
	"Darrick J . Wong"
	<djwong-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	linux-block-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Marcelo Ricardo Leitner
	<marcelo.leitner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org,
	Andrii Nakryiko <andrii-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Hans Verkuil <hverkuil-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org>,
	linux-sctp-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	"Md . Haris Iqbal"
	<haris.iqbal-vEVw2sk9H7kAvxtiuMwx3w@public.gmane.org>,
	Miquel Raynal
	<miquel.raynal-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org>,
	Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org>,
	Andy Gospodarek <andy-QlMahl40kYEqcZcGjlUOXw@public.gmane.org>,
	Sergey Matyukevich
	<geomatsi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Rohit Maheshwari <rohitm-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org>,
	Michael Ellerman <mpe-Gsx/Oe8HsFggBc27wqDAHg@public.gmane.org>,
	Christophe Leroy
	<christophe.leroy-2tlSp11Fh4xulxpn9UvDqw@public.gmane.org>,
	Jozsef Kadlecsik <kadlec-Cap9r6Oaw4JrovVCs/uTlw@public.gmane.org>,
	Nilesh Javali <njavali-eYqpPyKDWXRBDgjK7y7TUQ@public.gmane.org>,
	Jean-Paul Roubelat <jpr-3OwtVqItl4LYtjvyW6yDsg@public.gmane.org>,
	Dan Williams
	<dan.j.williams-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
	Dick Kennedy
	<dick.kennedy-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>,
	Jay Vosburgh <j.vosburgh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Potnuri Bharat Teja
	<bharat-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org>
Subject: Re: [f2fs-dev] [PATCH v1 3/5] treewide: use get_random_u32() when possible
Date: Thu, 6 Oct 2022 06:33:15 -0600	[thread overview]
Message-ID: <Yz7LCyIAHC6l5mG9@zx2c4.com> (raw)
In-Reply-To: <20221006084331.4bdktc2zlvbaszym@quack3>

On Thu, Oct 06, 2022 at 10:43:31AM +0200, Jan Kara wrote:
> The code here is effectively doing the
> 
> 	parent_group = prandom_u32_max(ngroups);
> 
> Similarly here we can use prandom_u32_max(ngroups) like:
> 
> 		if (qstr) {
> 			...
> 			parent_group = hinfo.hash % ngroups;
> 		} else
> 			parent_group = prandom_u32_max(ngroups);

Nice catch. I'll move these to patch #1.


> > 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.

I'm not handling this during this patch set, but if in the course of
review we find enough places that want actually uniformly bounded
integers, I'll implement efficient rejection sampling to clean up these
cases, with something faster and general, and add a new function for it.
So far this is the first case to come up, but we'll probably eventually
find others. So I'll make note of this.

Jason

  reply	other threads:[~2022-10-06 12:33 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-05 21:48 [PATCH v1 0/5] treewide cleanup of random integer usage Jason A. Donenfeld via dev
2022-10-05 21:48 ` [PATCH v1 1/5] treewide: use prandom_u32_max() when possible Jason A. Donenfeld via Linux-f2fs-devel
     [not found]   ` <20221005214844.2699-2-Jason-OnJsPKxuuEcAvxtiuMwx3w@public.gmane.org>
2022-10-06  4:16     ` Kees Cook
2022-10-06  4:22       ` KP Singh
2022-10-06 12:45       ` Jason A. Donenfeld via dev
2022-10-06 12:55         ` Jason Gunthorpe
2022-10-06 13:05           ` Andy Shevchenko
2022-10-05 21:48 ` [PATCH v1 3/5] treewide: use get_random_u32() " Jason A. Donenfeld via Linux-f2fs-devel
2022-10-06  8:43   ` Jan Kara
2022-10-06 12:33     ` Jason A. Donenfeld via dev [this message]
2022-10-06 13:01       ` [f2fs-dev] " Andy Shevchenko
2022-10-06 13:07         ` Jason A. Donenfeld via Linux-f2fs-devel
2022-10-06 12:47   ` Jason Gunthorpe
     [not found]     ` <Yz7OdfKZeGkpZSKb-uk2M96/98Pc@public.gmane.org>
2022-10-06 13:05       ` Jason A. Donenfeld via dev
2022-10-06 13:15         ` Jason Gunthorpe
2022-10-06 13:20         ` Andy Shevchenko
     [not found]   ` <20221005214844.2699-4-Jason-OnJsPKxuuEcAvxtiuMwx3w@public.gmane.org>
2022-10-12 19:16     ` Joe Perches
2022-10-12 19:16   ` Joe Perches
     [not found]   ` <f8ad3ba44d28dec1a5f7626b82c5e9c2aeefa729.camel@perches.com>
     [not found]     ` <f8ad3ba44d28dec1a5f7626b82c5e9c2aeefa729.camel-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>
2022-10-12 21:29       ` David Laight
     [not found]         ` <d45bd258e033453b85a137112e7694e1-1XygrNkDbNvwg4NCKwmqgw@public.gmane.org>
2022-10-13  1:37           ` Joe Perches
2022-10-05 21:48 ` [PATCH v1 4/5] treewide: use get_random_bytes " Jason A. Donenfeld via Linux-f2fs-devel
2022-10-06  4:45   ` Kees Cook
     [not found]   ` <20221005214844.2699-5-Jason-OnJsPKxuuEcAvxtiuMwx3w@public.gmane.org>
2022-10-06  4:48     ` Kees Cook
     [not found] ` <20221005214844.2699-1-Jason-OnJsPKxuuEcAvxtiuMwx3w@public.gmane.org>
2022-10-05 21:48   ` [PATCH v1 2/5] treewide: use get_random_{u8, u16}() " Jason A. Donenfeld via dev
     [not found]     ` <20221005214844.2699-3-Jason-OnJsPKxuuEcAvxtiuMwx3w@public.gmane.org>
2022-10-06  4:38       ` Kees Cook
2022-10-06 12:28         ` Jason A. Donenfeld via dev
2022-10-05 21:48   ` [PATCH v1 5/5] prandom: remove unused functions Jason A. Donenfeld via dev
     [not found]     ` <20221005214844.2699-6-Jason-OnJsPKxuuEcAvxtiuMwx3w@public.gmane.org>
2022-10-06  4:39       ` Kees Cook
2022-10-06  4:55   ` [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 via dev

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=Yz7LCyIAHC6l5mG9@zx2c4.com \
    --to=ovs-dev-ybygre7ru0tnmu66kgdujq@public.gmane.org \
    --cc=Jason-OnJsPKxuuEcAvxtiuMwx3w@public.gmane.org \
    --cc=andrew-g2DYL2Zd6BY@public.gmane.org \
    --cc=andrii-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=andy-QlMahl40kYEqcZcGjlUOXw@public.gmane.org \
    --cc=bharat-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org \
    --cc=christophe.leroy-2tlSp11Fh4xulxpn9UvDqw@public.gmane.org \
    --cc=dan.j.williams-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=dick.kennedy-dY08KVG/lbpWk0Htik3J/w@public.gmane.org \
    --cc=djwong-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=geomatsi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=haris.iqbal-vEVw2sk9H7kAvxtiuMwx3w@public.gmane.org \
    --cc=hch-jcswGhMUV9g@public.gmane.org \
    --cc=hverkuil-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org \
    --cc=j.vosburgh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=jack-AlSwsSmVLrQ@public.gmane.org \
    --cc=jpr-3OwtVqItl4LYtjvyW6yDsg@public.gmane.org \
    --cc=kadlec-Cap9r6Oaw4JrovVCs/uTlw@public.gmane.org \
    --cc=linux-block-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-sctp-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=marcelo.leitner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=miquel.raynal-LDxbnhwyfcJBDgjK7y7TUQ@public.gmane.org \
    --cc=mpe-Gsx/Oe8HsFggBc27wqDAHg@public.gmane.org \
    --cc=njavali-eYqpPyKDWXRBDgjK7y7TUQ@public.gmane.org \
    --cc=rohitm-ut6Up61K2wZBDgjK7y7TUQ@public.gmane.org \
    /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