Re: [PATCH v1 0/5] convert tree to get_random_u32_{below,above,between}()

2022-10-24 Thread Jason A. Donenfeld
On Sun, Oct 23, 2022 at 05:07:13PM -0400, Theodore Ts'o wrote:
> On Fri, Oct 21, 2022 at 11:03:22PM -0700, Jakub Kicinski wrote:
> > On Sat, 22 Oct 2022 07:47:06 +0200 Jason A. Donenfeld wrote:
> > > On Fri, Oct 21, 2022 at 10:32:42PM -0700, Jakub Kicinski wrote:
> > > > But whatever. I mean - hopefully there aren't any conflicts in the ~50
> > > > networking files you touch. I just wish that people didn't pipe up with
> > > > the tree wide changes right after the merge window. Feels like the
> > > > worst possible timing.  
> > > 
> > > Oh, if the timing is what makes this especially worrisome, I have
> > > no qualms about rebasing much later, and reposting this series then.
> > > I'll do that.
> > 
> > Cool, thanks! I promise to not be grumpy if you repost around rc6 :)
> 
> One way of making things less painful for the stable branch and for
> the upstream branch is to *add* new helpers instead of playing
> replacement games like s/prandom_u32_max/get_random_u32_below/.  This
> is what causes the patch conflict problems.
> 
> One advantage of at least adding the new functions to the stable
> branches, even if we don't do the wholesale replacement, is that it

That's a good idea. I'll also save the removal commit, anyhow, for a
separate thing at the end of 6.2 rc1, so that -next doesn't have issues
either.  That's how things wound up going down for the first tranche of
these, and that worked well.

Jason


Re: [PATCH v1 0/5] convert tree to get_random_u32_{below,above,between}()

2022-10-24 Thread Jason Gunthorpe
On Fri, Oct 21, 2022 at 09:43:58PM -0400, Jason A. Donenfeld wrote:
> Hey everyone,
> 
> Here's the second and final tranche of tree-wide conversions to get
> random integer handling a bit tamer. It's predominantly another
> Coccinelle-based patchset.
> 
> First we s/prandom_u32_max/get_random_u32_below/, since the former is
> just a deprecated alias for the latter. Then in the next commit we can
> remove prandom_u32_max all together. I'm quite happy about finally being
> able to do that. It means that prandom.h is now only for deterministic and 
> repeatable randomness, not non-deterministic/cryptographic randomness.
> That line is no longer blurred.
> 
> Then, in order to clean up a bunch of inefficient patterns, we introduce
> two trivial static inline helper functions built on top of
> get_random_u32_below: get_random_u32_above and get_random_u32_between.
> These are pretty straight forward to use and understand. Then the final
> two patches convert some gnarly open-coded number juggling to use these
> helpers.
> 
> I've used Coccinelle for all the treewide patches, so hopefully review
> is rather uneventful. I didn't accept all of the changes that Coccinelle
> proposed, though, as these tend to be somewhat context-specific. I erred
> on the side of just going with the most obvious cases, at least this
> time through. And then we can address more complicated cases through
> actual maintainer trees.
> 
> Since get_random_u32_below() sits in my random.git tree, these patches
> too will flow through that same tree.
> 
For drivers/infiniband

Reviewed-by: Jason Gunthorpe 

Jason


Re: [PATCH v1 0/5] convert tree to get_random_u32_{below,above,between}()

2022-10-23 Thread Theodore Ts'o
On Fri, Oct 21, 2022 at 11:03:22PM -0700, Jakub Kicinski wrote:
> On Sat, 22 Oct 2022 07:47:06 +0200 Jason A. Donenfeld wrote:
> > On Fri, Oct 21, 2022 at 10:32:42PM -0700, Jakub Kicinski wrote:
> > > But whatever. I mean - hopefully there aren't any conflicts in the ~50
> > > networking files you touch. I just wish that people didn't pipe up with
> > > the tree wide changes right after the merge window. Feels like the
> > > worst possible timing.  
> > 
> > Oh, if the timing is what makes this especially worrisome, I have
> > no qualms about rebasing much later, and reposting this series then.
> > I'll do that.
> 
> Cool, thanks! I promise to not be grumpy if you repost around rc6 :)

One way of making things less painful for the stable branch and for
the upstream branch is to *add* new helpers instead of playing
replacement games like s/prandom_u32_max/get_random_u32_below/.  This
is what causes the patch conflict problems.

One advantage of at least adding the new functions to the stable
branches, even if we don't do the wholesale replacement, is that it
makes it much less likely that a backported patch, which uses the new
API, won't fail to compile --- and of course, the major headache case
is one where it's not noticed at first because it didn't get picked up
in people's test compiles until after the Linux x.y.z release has been
pushed out.

Whether it's worth doing the wholesale replacement is a different
question, but separating "add the new functions with one or two use
cases so the functions are actulaly _used_" from the "convert the
world to use the new functions" from the "remove the old functions",
might life easier.

- Ted


Re: [PATCH v1 0/5] convert tree to get_random_u32_{below,above,between}()

2022-10-22 Thread Greg Kroah-Hartman
On Fri, Oct 21, 2022 at 09:43:58PM -0400, Jason A. Donenfeld wrote:
> Hey everyone,
> 
> Here's the second and final tranche of tree-wide conversions to get
> random integer handling a bit tamer. It's predominantly another
> Coccinelle-based patchset.
> 
> First we s/prandom_u32_max/get_random_u32_below/, since the former is
> just a deprecated alias for the latter. Then in the next commit we can
> remove prandom_u32_max all together. I'm quite happy about finally being
> able to do that. It means that prandom.h is now only for deterministic and 
> repeatable randomness, not non-deterministic/cryptographic randomness.
> That line is no longer blurred.
> 
> Then, in order to clean up a bunch of inefficient patterns, we introduce
> two trivial static inline helper functions built on top of
> get_random_u32_below: get_random_u32_above and get_random_u32_between.
> These are pretty straight forward to use and understand. Then the final
> two patches convert some gnarly open-coded number juggling to use these
> helpers.
> 
> I've used Coccinelle for all the treewide patches, so hopefully review
> is rather uneventful. I didn't accept all of the changes that Coccinelle
> proposed, though, as these tend to be somewhat context-specific. I erred
> on the side of just going with the most obvious cases, at least this
> time through. And then we can address more complicated cases through
> actual maintainer trees.
> 
> Since get_random_u32_below() sits in my random.git tree, these patches
> too will flow through that same tree.
> 
> Regards,
> Jason


Reviewed-by: Greg Kroah-Hartman 


Re: [PATCH v1 0/5] convert tree to get_random_u32_{below,above,between}()

2022-10-22 Thread Jakub Kicinski
On Sat, 22 Oct 2022 07:47:06 +0200 Jason A. Donenfeld wrote:
> On Fri, Oct 21, 2022 at 10:32:42PM -0700, Jakub Kicinski wrote:
> > But whatever. I mean - hopefully there aren't any conflicts in the ~50
> > networking files you touch. I just wish that people didn't pipe up with
> > the tree wide changes right after the merge window. Feels like the
> > worst possible timing.  
> 
> Oh, if the timing is what makes this especially worrisome, I have
> no qualms about rebasing much later, and reposting this series then.
> I'll do that.

Cool, thanks! I promise to not be grumpy if you repost around rc6 :)


Re: [PATCH v1 0/5] convert tree to get_random_u32_{below,above,between}()

2022-10-21 Thread Jason A. Donenfeld
On Fri, Oct 21, 2022 at 10:32:42PM -0700, Jakub Kicinski wrote:
> But whatever. I mean - hopefully there aren't any conflicts in the ~50
> networking files you touch. I just wish that people didn't pipe up with
> the tree wide changes right after the merge window. Feels like the
> worst possible timing.

Oh, if the timing is what makes this especially worrisome, I have
no qualms about rebasing much later, and reposting this series then.
I'll do that.

Jason


Re: [PATCH v1 0/5] convert tree to get_random_u32_{below,above,between}()

2022-10-21 Thread Jakub Kicinski
On Sat, 22 Oct 2022 00:23:00 -0400 Jason A. Donenfeld wrote:
> > How big is it?  Can you provide a stable branch to pull in the new
> > helpers and then everyone will be able to apply the patches to their
> > subsystem?  
> 
> It's a patch. But what you suggest sounds crazy to me. Supply some
> branch and have every tree merge that branch separately, in duplicate,
> and then get all of the conversion patches through every tree, and then
> somehow coordinate the removal of the deprecated function after all of
> that, and then baby sit the grand orchestration of all this over the
> course of two and half months, watch it fail because of some
> unmaintained corner that's affected, and then try to herd it through for
> another two and a half months after that? Holy crap. That's torture.

I clean up some random networking API every couple of releases.
Unfortunately other subsystems use networking APIs too, so I have 
to do what you describe as "torture". It's not that hard in my
experience but perhaps I'm incredibly gifted. Or resilient to pain.

> Were this an actually technically interesting patchset that required
> some really detailed expert review, maybe that'd have some iota of
> merit. But this is a really boring refactoring, mostly automated with
> Coccinelle. If having to baby sit one hundred separate patches over the
> course of months, handling confusion of walking maintainers through the
> exercise of merging some weird duplicate branch into their trees before,
> and so forth, is required to get this kind of grunt work done, I'm just
> going to wind up losing all motivation for this kind of thing, and
> naturally, as a matter of human nature, stop doing it. The result will
> be that we have garbage pile up over time that operates on the principle
> of "least hassle to deal with for the time being" rather than "love of
> the code and a desire for long term maintainability and quality". The
> former is sometimes how things go. The latter is what I'm striving for.
> 
> So what you suggest sounds really dreadful to me. Sorry.
> 
> Instead, this series follows the same template as the last one, and the
> last one was much more nuanced and invasive and went fine. In the very
> worst case, it'll require me to be on the ball with what's happening
> with -next, which is something I've done before and can do again.

Not sure what you mean by "being on the ball with what's happening with
-next" surely it's Steven who'll be fixing the conflicts and paying
with his time? Or carrying extra patches because neither you will be
able to convert the new cases in your tree nor in the origin tree since
it won't have your new helpers.

To me putting the new helpers first, on a clean branch off Linus's tree
so in case of emergency it can be pulled into a random^W arbitrary tree
is just good hygiene.

But whatever. I mean - hopefully there aren't any conflicts in the ~50
networking files you touch. I just wish that people didn't pipe up with
the tree wide changes right after the merge window. Feels like the
worst possible timing.


Re: [PATCH v1 0/5] convert tree to get_random_u32_{below,above,between}()

2022-10-21 Thread Jason A. Donenfeld
On Fri, Oct 21, 2022 at 08:55:22PM -0700, Jakub Kicinski wrote:
> On Fri, 21 Oct 2022 21:43:58 -0400 Jason A. Donenfeld wrote:
> > Since get_random_u32_below() sits in my random.git tree, these patches
> > too will flow through that same tree.
> 
> How big is it?  Can you provide a stable branch to pull in the new
> helpers and then everyone will be able to apply the patches to their
> subsystem?

It's a patch. But what you suggest sounds crazy to me. Supply some
branch and have every tree merge that branch separately, in duplicate,
and then get all of the conversion patches through every tree, and then
somehow coordinate the removal of the deprecated function after all of
that, and then baby sit the grand orchestration of all this over the
course of two and half months, watch it fail because of some
unmaintained corner that's affected, and then try to herd it through for
another two and a half months after that? Holy crap. That's torture.

Were this an actually technically interesting patchset that required
some really detailed expert review, maybe that'd have some iota of
merit. But this is a really boring refactoring, mostly automated with
Coccinelle. If having to baby sit one hundred separate patches over the
course of months, handling confusion of walking maintainers through the
exercise of merging some weird duplicate branch into their trees before,
and so forth, is required to get this kind of grunt work done, I'm just
going to wind up losing all motivation for this kind of thing, and
naturally, as a matter of human nature, stop doing it. The result will
be that we have garbage pile up over time that operates on the principle
of "least hassle to deal with for the time being" rather than "love of
the code and a desire for long term maintainability and quality". The
former is sometimes how things go. The latter is what I'm striving for.

So what you suggest sounds really dreadful to me. Sorry.

Instead, this series follows the same template as the last one, and the
last one was much more nuanced and invasive and went fine. In the very
worst case, it'll require me to be on the ball with what's happening
with -next, which is something I've done before and can do again.

Jason


Re: [PATCH v1 0/5] convert tree to get_random_u32_{below,above,between}()

2022-10-21 Thread Jakub Kicinski
On Fri, 21 Oct 2022 21:43:58 -0400 Jason A. Donenfeld wrote:
> Since get_random_u32_below() sits in my random.git tree, these patches
> too will flow through that same tree.

How big is it?  Can you provide a stable branch to pull in the new
helpers and then everyone will be able to apply the patches to their
subsystem?



[PATCH v1 0/5] convert tree to get_random_u32_{below,above,between}()

2022-10-21 Thread Jason A. Donenfeld
Hey everyone,

Here's the second and final tranche of tree-wide conversions to get
random integer handling a bit tamer. It's predominantly another
Coccinelle-based patchset.

First we s/prandom_u32_max/get_random_u32_below/, since the former is
just a deprecated alias for the latter. Then in the next commit we can
remove prandom_u32_max all together. I'm quite happy about finally being
able to do that. It means that prandom.h is now only for deterministic and 
repeatable randomness, not non-deterministic/cryptographic randomness.
That line is no longer blurred.

Then, in order to clean up a bunch of inefficient patterns, we introduce
two trivial static inline helper functions built on top of
get_random_u32_below: get_random_u32_above and get_random_u32_between.
These are pretty straight forward to use and understand. Then the final
two patches convert some gnarly open-coded number juggling to use these
helpers.

I've used Coccinelle for all the treewide patches, so hopefully review
is rather uneventful. I didn't accept all of the changes that Coccinelle
proposed, though, as these tend to be somewhat context-specific. I erred
on the side of just going with the most obvious cases, at least this
time through. And then we can address more complicated cases through
actual maintainer trees.

Since get_random_u32_below() sits in my random.git tree, these patches
too will flow through that same tree.

Regards,
Jason

Cc: Kees Cook 
Cc: Greg Kroah-Hartman 
Cc: Jakub Kicinski 
Cc: Russell King 
Cc: Catalin Marinas 
Cc: Thomas Bogendoerfer 
Cc: Heiko Carstens 
Cc: Herbert Xu 
Cc: Christoph Böhmwalder 
Cc: Jani Nikula 
Cc: Jason Gunthorpe 
Cc: Sakari Ailus 
Cc: Martin K. Petersen 
Cc: Theodore Ts'o 
Cc: Andreas Dilger 
Cc: Jaegeuk Kim 
Cc: Richard Weinberger 
Cc: Darrick J. Wong 
Cc: SeongJae Park 
Cc: Thomas Gleixner 
Cc: Andrew Morton 
Cc: Michael Ellerman 
Cc: Helge Deller 
Cc: net...@vger.kernel.org
Cc: linux-cry...@vger.kernel.org
Cc: linux-bl...@vger.kernel.org
Cc: linux-fsde...@vger.kernel.org
Cc: linux-me...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: loonga...@lists.linux.dev
Cc: linux-m...@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-...@vger.kernel.org
Cc: linux-par...@vger.kernel.org

Jason A. Donenfeld (5):
  treewide: use get_random_u32_below() instead of deprecated function
  prandom: remove prandom_u32_max()
  random: add helpers for random numbers with given floor or range
  treewide: use get_random_u32_{above,below}() instead of manual loop
  treewide: use get_random_u32_between() when possible

 arch/arm/kernel/process.c |  2 +-
 arch/arm64/kernel/process.c   |  2 +-
 arch/loongarch/kernel/process.c   |  2 +-
 arch/loongarch/kernel/vdso.c  |  2 +-
 arch/mips/kernel/process.c|  2 +-
 arch/mips/kernel/vdso.c   |  2 +-
 arch/parisc/kernel/vdso.c |  2 +-
 arch/powerpc/crypto/crc-vpmsum_test.c |  4 +-
 arch/powerpc/kernel/process.c |  2 +-
 arch/s390/kernel/process.c|  2 +-
 arch/s390/kernel/vdso.c   |  2 +-
 arch/sparc/vdso/vma.c |  2 +-
 arch/um/kernel/process.c  |  2 +-
 arch/x86/entry/vdso/vma.c |  2 +-
 arch/x86/kernel/module.c  |  2 +-
 arch/x86/kernel/process.c |  2 +-
 arch/x86/mm/pat/cpa-test.c|  4 +-
 crypto/rsa-pkcs1pad.c |  2 +-
 crypto/testmgr.c  | 86 +--
 drivers/block/drbd/drbd_receiver.c|  4 +-
 drivers/bus/mhi/host/internal.h   |  2 +-
 drivers/dma-buf/st-dma-fence-chain.c  |  6 +-
 .../gpu/drm/i915/gem/i915_gem_execbuffer.c|  2 +-
 .../drm/i915/gt/intel_execlists_submission.c  |  2 +-
 drivers/gpu/drm/i915/intel_memory_region.c|  4 +-
 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|  2 +-
 drivers/md/bcache/request.c   |  2 +-
 drivers/media/common/v4l2-tpg/v4l2-tpg-core.c |  8 +-
 .../media/test-drivers/vidtv/vidtv_demod.c|  8 +-
 .../test-drivers/vivid/vivid-kthread-cap.c|  2 +-
 .../test-drivers/vivid/vivid-kthread-out.c|  2 +-
 .../media/test-drivers/vivid/vivid-radio-rx.c |  4 +-
 .../media/test-drivers/vivid/vivid-sdr-cap.c  |  2 +-
 .../test-drivers/vivid/vivid-touch-cap.c  |  2 +-
 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|  8 +-
 drivers/mtd/ubi/debug.c   |  2 +-
 drivers/mtd/ubi/debug.h