* [PATCH] prandom: remove next_pseudo_random32
@ 2025-02-10 13:35 Markus Theil
2025-02-10 13:39 ` Jason A. Donenfeld
0 siblings, 1 reply; 13+ messages in thread
From: Markus Theil @ 2025-02-10 13:35 UTC (permalink / raw)
To: linux-kernel; +Cc: intel-gfx, netdev, Jason, tytso, Markus Theil
next_pseudo_random32 implements a LCG with known bad
statistical properties and is only used in two pieces
of testing code. Remove and convert users to the remaining
single PRNG interface in prandom/random32.
This removes another option of using an insecure PRNG.
This is a preliminary patch for further prandom cleanup:
- In another upcoming patch, I'd like to add more warnings,
that prandom must not be used for cryptographic purposes.
- Replace the LFSR113 generator with Xoshiro256++, which is
known to have better statistical properties and does not
need warmup, when seeded properly.
Signed-off-by: Markus Theil <theil.markus@gmail.com>
---
drivers/gpu/drm/i915/selftests/i915_gem.c | 7 ++++---
drivers/media/test-drivers/vivid/vivid-vid-cap.c | 4 +++-
include/linux/prandom.h | 6 ------
3 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/drivers/gpu/drm/i915/selftests/i915_gem.c b/drivers/gpu/drm/i915/selftests/i915_gem.c
index 0727492576be..14efa6edd9e6 100644
--- a/drivers/gpu/drm/i915/selftests/i915_gem.c
+++ b/drivers/gpu/drm/i915/selftests/i915_gem.c
@@ -45,13 +45,15 @@ static void trash_stolen(struct drm_i915_private *i915)
struct i915_ggtt *ggtt = to_gt(i915)->ggtt;
const u64 slot = ggtt->error_capture.start;
const resource_size_t size = resource_size(&i915->dsm.stolen);
+ struct rnd_state prng;
unsigned long page;
- u32 prng = 0x12345678;
/* XXX: fsck. needs some more thought... */
if (!i915_ggtt_has_aperture(ggtt))
return;
+ prandom_seed_state(&prng, 0x12345678);
+
for (page = 0; page < size; page += PAGE_SIZE) {
const dma_addr_t dma = i915->dsm.stolen.start + page;
u32 __iomem *s;
@@ -64,8 +66,7 @@ static void trash_stolen(struct drm_i915_private *i915)
s = io_mapping_map_atomic_wc(&ggtt->iomap, slot);
for (x = 0; x < PAGE_SIZE / sizeof(u32); x++) {
- prng = next_pseudo_random32(prng);
- iowrite32(prng, &s[x]);
+ iowrite32(prandom_u32_state(&prng), &s[x]);
}
io_mapping_unmap_atomic(s);
}
diff --git a/drivers/media/test-drivers/vivid/vivid-vid-cap.c b/drivers/media/test-drivers/vivid/vivid-vid-cap.c
index b166d90177c6..166372d5f927 100644
--- a/drivers/media/test-drivers/vivid/vivid-vid-cap.c
+++ b/drivers/media/test-drivers/vivid/vivid-vid-cap.c
@@ -300,8 +300,10 @@ void vivid_update_quality(struct vivid_dev *dev)
*/
freq_modulus = (dev->tv_freq - 676 /* (43.25-1) * 16 */) % (6 * 16);
if (freq_modulus > 2 * 16) {
+ struct rnd_state prng;
+ prandom_seed_state(&prng, dev->tv_freq ^ 0x55);
tpg_s_quality(&dev->tpg, TPG_QUAL_NOISE,
- next_pseudo_random32(dev->tv_freq ^ 0x55) & 0x3f);
+ prandom_u32_state(&prng) & 0x3f);
return;
}
if (freq_modulus < 12 /*0.75 * 16*/ || freq_modulus > 20 /*1.25 * 16*/)
diff --git a/include/linux/prandom.h b/include/linux/prandom.h
index f2ed5b72b3d6..ff7dcc3fa105 100644
--- a/include/linux/prandom.h
+++ b/include/linux/prandom.h
@@ -47,10 +47,4 @@ static inline void prandom_seed_state(struct rnd_state *state, u64 seed)
state->s4 = __seed(i, 128U);
}
-/* Pseudo random number generator from numerical recipes. */
-static inline u32 next_pseudo_random32(u32 seed)
-{
- return seed * 1664525 + 1013904223;
-}
-
#endif
--
2.47.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH] prandom: remove next_pseudo_random32
2025-02-10 13:35 [PATCH] prandom: remove next_pseudo_random32 Markus Theil
@ 2025-02-10 13:39 ` Jason A. Donenfeld
2025-02-10 23:07 ` Andi Shyti
2025-02-11 6:33 ` [PATCH v2 0/3] " Markus Theil
0 siblings, 2 replies; 13+ messages in thread
From: Jason A. Donenfeld @ 2025-02-10 13:39 UTC (permalink / raw)
To: Markus Theil; +Cc: linux-kernel, intel-gfx, netdev, tytso
Hey Markus,
Thanks for this. I hadn't realized that next_pseudo_random32() only
had two users left. Excellent.
I'll queue this up in the random tree (unless there are objections
from the maintainers of that test code).
Jason
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] prandom: remove next_pseudo_random32
2025-02-10 13:39 ` Jason A. Donenfeld
@ 2025-02-10 23:07 ` Andi Shyti
2025-02-11 6:13 ` Markus Theil
2025-02-11 6:33 ` [PATCH v2 0/3] " Markus Theil
1 sibling, 1 reply; 13+ messages in thread
From: Andi Shyti @ 2025-02-10 23:07 UTC (permalink / raw)
To: Jason A. Donenfeld; +Cc: Markus Theil, linux-kernel, intel-gfx, netdev, tytso
Hi,
On Mon, Feb 10, 2025 at 02:39:43PM +0100, Jason A. Donenfeld wrote:
> Hey Markus,
>
> Thanks for this. I hadn't realized that next_pseudo_random32() only
> had two users left. Excellent.
>
> I'll queue this up in the random tree (unless there are objections
> from the maintainers of that test code).
actually would be better if we apply the i915 part in drm-tip
rather than waiting for kernel releases to receive this change in
our branch. It has been source of conflicts and headaches.
May I ask Markus to split the patch in two parts and we handle
the i915 side?
Thanks,
Andi
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH] prandom: remove next_pseudo_random32
2025-02-10 23:07 ` Andi Shyti
@ 2025-02-11 6:13 ` Markus Theil
0 siblings, 0 replies; 13+ messages in thread
From: Markus Theil @ 2025-02-11 6:13 UTC (permalink / raw)
To: Andi Shyti, Jason A. Donenfeld; +Cc: linux-kernel, intel-gfx, netdev, tytso
Hi,
On 11.02.25 00:07, Andi Shyti wrote:
> actually would be better if we apply the i915 part in drm-tip
> rather than waiting for kernel releases to receive this change in
> our branch. It has been source of conflicts and headaches.
>
> May I ask Markus to split the patch in two parts and we handle
> the i915 side?
>
Sure, will do in a v2.
Markus
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 0/3] prandom: remove next_pseudo_random32
2025-02-10 13:39 ` Jason A. Donenfeld
2025-02-10 23:07 ` Andi Shyti
@ 2025-02-11 6:33 ` Markus Theil
2025-02-11 6:33 ` [PATCH v2 1/3] drm/i915/selftests: use prandom in selftest Markus Theil
` (3 more replies)
1 sibling, 4 replies; 13+ messages in thread
From: Markus Theil @ 2025-02-11 6:33 UTC (permalink / raw)
To: linux-kernel, andi.shyti; +Cc: intel-gfx, netdev, Jason, tytso, Markus Theil
next_pseudo_random32 implements a LCG with known bad statistical
properties and is only used in two pieces of testing code. Remove and
convert the remaining two users to the single PRNG interface in
prandom.h
This removes another option of using an insecure PRNG.
Markus Theil (3):
drm/i915/selftests: use prandom in selftest
media: vivid: use prandom
prandom: remove next_pseudo_random32
drivers/gpu/drm/i915/selftests/i915_gem.c | 7 ++++---
drivers/media/test-drivers/vivid/vivid-vid-cap.c | 4 +++-
include/linux/prandom.h | 6 ------
3 files changed, 7 insertions(+), 10 deletions(-)
--
2.47.2
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 1/3] drm/i915/selftests: use prandom in selftest
2025-02-11 6:33 ` [PATCH v2 0/3] " Markus Theil
@ 2025-02-11 6:33 ` Markus Theil
2025-02-13 17:19 ` Andi Shyti
2025-02-11 6:33 ` [PATCH v2 2/3] media: vivid: use prandom Markus Theil
` (2 subsequent siblings)
3 siblings, 1 reply; 13+ messages in thread
From: Markus Theil @ 2025-02-11 6:33 UTC (permalink / raw)
To: linux-kernel, andi.shyti; +Cc: intel-gfx, netdev, Jason, tytso, Markus Theil
This is part of a prandom cleanup, which removes
next_pseudo_random32 and replaces it with the standard PRNG.
Signed-off-by: Markus Theil <theil.markus@gmail.com>
---
drivers/gpu/drm/i915/selftests/i915_gem.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/i915/selftests/i915_gem.c b/drivers/gpu/drm/i915/selftests/i915_gem.c
index 0727492576be..14efa6edd9e6 100644
--- a/drivers/gpu/drm/i915/selftests/i915_gem.c
+++ b/drivers/gpu/drm/i915/selftests/i915_gem.c
@@ -45,13 +45,15 @@ static void trash_stolen(struct drm_i915_private *i915)
struct i915_ggtt *ggtt = to_gt(i915)->ggtt;
const u64 slot = ggtt->error_capture.start;
const resource_size_t size = resource_size(&i915->dsm.stolen);
+ struct rnd_state prng;
unsigned long page;
- u32 prng = 0x12345678;
/* XXX: fsck. needs some more thought... */
if (!i915_ggtt_has_aperture(ggtt))
return;
+ prandom_seed_state(&prng, 0x12345678);
+
for (page = 0; page < size; page += PAGE_SIZE) {
const dma_addr_t dma = i915->dsm.stolen.start + page;
u32 __iomem *s;
@@ -64,8 +66,7 @@ static void trash_stolen(struct drm_i915_private *i915)
s = io_mapping_map_atomic_wc(&ggtt->iomap, slot);
for (x = 0; x < PAGE_SIZE / sizeof(u32); x++) {
- prng = next_pseudo_random32(prng);
- iowrite32(prng, &s[x]);
+ iowrite32(prandom_u32_state(&prng), &s[x]);
}
io_mapping_unmap_atomic(s);
}
--
2.47.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 2/3] media: vivid: use prandom
2025-02-11 6:33 ` [PATCH v2 0/3] " Markus Theil
2025-02-11 6:33 ` [PATCH v2 1/3] drm/i915/selftests: use prandom in selftest Markus Theil
@ 2025-02-11 6:33 ` Markus Theil
2025-02-11 6:33 ` [PATCH v2 3/3] prandom: remove next_pseudo_random32 Markus Theil
2025-02-13 14:27 ` [PATCH v2 0/3] " Krzysztof Karas
3 siblings, 0 replies; 13+ messages in thread
From: Markus Theil @ 2025-02-11 6:33 UTC (permalink / raw)
To: linux-kernel, andi.shyti; +Cc: intel-gfx, netdev, Jason, tytso, Markus Theil
This is part of a prandom cleanup, which removes
next_pseudo_random32 and replaces it with the standard PRNG.
Signed-off-by: Markus Theil <theil.markus@gmail.com>
---
drivers/media/test-drivers/vivid/vivid-vid-cap.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/media/test-drivers/vivid/vivid-vid-cap.c b/drivers/media/test-drivers/vivid/vivid-vid-cap.c
index b166d90177c6..166372d5f927 100644
--- a/drivers/media/test-drivers/vivid/vivid-vid-cap.c
+++ b/drivers/media/test-drivers/vivid/vivid-vid-cap.c
@@ -300,8 +300,10 @@ void vivid_update_quality(struct vivid_dev *dev)
*/
freq_modulus = (dev->tv_freq - 676 /* (43.25-1) * 16 */) % (6 * 16);
if (freq_modulus > 2 * 16) {
+ struct rnd_state prng;
+ prandom_seed_state(&prng, dev->tv_freq ^ 0x55);
tpg_s_quality(&dev->tpg, TPG_QUAL_NOISE,
- next_pseudo_random32(dev->tv_freq ^ 0x55) & 0x3f);
+ prandom_u32_state(&prng) & 0x3f);
return;
}
if (freq_modulus < 12 /*0.75 * 16*/ || freq_modulus > 20 /*1.25 * 16*/)
--
2.47.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 3/3] prandom: remove next_pseudo_random32
2025-02-11 6:33 ` [PATCH v2 0/3] " Markus Theil
2025-02-11 6:33 ` [PATCH v2 1/3] drm/i915/selftests: use prandom in selftest Markus Theil
2025-02-11 6:33 ` [PATCH v2 2/3] media: vivid: use prandom Markus Theil
@ 2025-02-11 6:33 ` Markus Theil
2025-02-13 14:27 ` [PATCH v2 0/3] " Krzysztof Karas
3 siblings, 0 replies; 13+ messages in thread
From: Markus Theil @ 2025-02-11 6:33 UTC (permalink / raw)
To: linux-kernel, andi.shyti; +Cc: intel-gfx, netdev, Jason, tytso, Markus Theil
next_pseudo_random32 implements a LCG with known bad statistical
properties and was only used in two pieces of testing code.
After the users are converted to prandom as part of this series,
remove the LCG here.
This removes another option of using an insecure PRNG.
Signed-off-by: Markus Theil <theil.markus@gmail.com>
---
include/linux/prandom.h | 6 ------
1 file changed, 6 deletions(-)
diff --git a/include/linux/prandom.h b/include/linux/prandom.h
index f2ed5b72b3d6..ff7dcc3fa105 100644
--- a/include/linux/prandom.h
+++ b/include/linux/prandom.h
@@ -47,10 +47,4 @@ static inline void prandom_seed_state(struct rnd_state *state, u64 seed)
state->s4 = __seed(i, 128U);
}
-/* Pseudo random number generator from numerical recipes. */
-static inline u32 next_pseudo_random32(u32 seed)
-{
- return seed * 1664525 + 1013904223;
-}
-
#endif
--
2.47.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v2 0/3] prandom: remove next_pseudo_random32
2025-02-11 6:33 ` [PATCH v2 0/3] " Markus Theil
` (2 preceding siblings ...)
2025-02-11 6:33 ` [PATCH v2 3/3] prandom: remove next_pseudo_random32 Markus Theil
@ 2025-02-13 14:27 ` Krzysztof Karas
3 siblings, 0 replies; 13+ messages in thread
From: Krzysztof Karas @ 2025-02-13 14:27 UTC (permalink / raw)
To: Markus Theil; +Cc: linux-kernel, intel-gfx, netdev
Hi Markus,
> next_pseudo_random32 implements a LCG with known bad statistical
> properties and is only used in two pieces of testing code. Remove and
> convert the remaining two users to the single PRNG interface in
> prandom.h
>
> This removes another option of using an insecure PRNG.
>
> Markus Theil (3):
> drm/i915/selftests: use prandom in selftest
> media: vivid: use prandom
> prandom: remove next_pseudo_random32
>
> drivers/gpu/drm/i915/selftests/i915_gem.c | 7 ++++---
> drivers/media/test-drivers/vivid/vivid-vid-cap.c | 4 +++-
> include/linux/prandom.h | 6 ------
> 3 files changed, 7 insertions(+), 10 deletions(-)
>
The series looks good:
Reviewed-by: Krzysztof Karas <krzysztof.karas@intel.com>
on all the patches.
Best Regards,
Krzysztof
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/3] drm/i915/selftests: use prandom in selftest
2025-02-11 6:33 ` [PATCH v2 1/3] drm/i915/selftests: use prandom in selftest Markus Theil
@ 2025-02-13 17:19 ` Andi Shyti
2025-03-19 17:13 ` Jason A. Donenfeld
0 siblings, 1 reply; 13+ messages in thread
From: Andi Shyti @ 2025-02-13 17:19 UTC (permalink / raw)
To: Markus Theil; +Cc: linux-kernel, andi.shyti, intel-gfx, netdev, Jason, tytso
Hi Markus,
On Tue, Feb 11, 2025 at 07:33:30AM +0100, Markus Theil wrote:
> This is part of a prandom cleanup, which removes
> next_pseudo_random32 and replaces it with the standard PRNG.
>
> Signed-off-by: Markus Theil <theil.markus@gmail.com>
I merged just this patch in drm-intel-gt-next.
Thanks,
Andi
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/3] drm/i915/selftests: use prandom in selftest
2025-02-13 17:19 ` Andi Shyti
@ 2025-03-19 17:13 ` Jason A. Donenfeld
2025-03-21 12:37 ` Jani Nikula
0 siblings, 1 reply; 13+ messages in thread
From: Jason A. Donenfeld @ 2025-03-19 17:13 UTC (permalink / raw)
To: Andi Shyti; +Cc: Markus Theil, linux-kernel, intel-gfx, netdev, tytso
Hi Andi,
On Thu, Feb 13, 2025 at 06:19:12PM +0100, Andi Shyti wrote:
> Hi Markus,
>
> On Tue, Feb 11, 2025 at 07:33:30AM +0100, Markus Theil wrote:
> > This is part of a prandom cleanup, which removes
> > next_pseudo_random32 and replaces it with the standard PRNG.
> >
> > Signed-off-by: Markus Theil <theil.markus@gmail.com>
>
> I merged just this patch in drm-intel-gt-next.
This is minorly annoying for me... What am I supposed to do with patches
2 and 3? Take them through my tree for 6.16 in like half a year? Can I
just take the v1 into my tree and we can get this done with straight
forwardly? Or do you have a different suggestion for me?
Jason
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/3] drm/i915/selftests: use prandom in selftest
2025-03-19 17:13 ` Jason A. Donenfeld
@ 2025-03-21 12:37 ` Jani Nikula
2025-03-21 12:52 ` Jason A. Donenfeld
0 siblings, 1 reply; 13+ messages in thread
From: Jani Nikula @ 2025-03-21 12:37 UTC (permalink / raw)
To: Jason A. Donenfeld, Andi Shyti
Cc: Markus Theil, linux-kernel, intel-gfx, netdev, tytso
On Wed, 19 Mar 2025, "Jason A. Donenfeld" <Jason@zx2c4.com> wrote:
> Hi Andi,
>
> On Thu, Feb 13, 2025 at 06:19:12PM +0100, Andi Shyti wrote:
>> Hi Markus,
>>
>> On Tue, Feb 11, 2025 at 07:33:30AM +0100, Markus Theil wrote:
>> > This is part of a prandom cleanup, which removes
>> > next_pseudo_random32 and replaces it with the standard PRNG.
>> >
>> > Signed-off-by: Markus Theil <theil.markus@gmail.com>
>>
>> I merged just this patch in drm-intel-gt-next.
>
> This is minorly annoying for me... What am I supposed to do with patches
> 2 and 3? Take them through my tree for 6.16 in like half a year? Can I
> just take the v1 into my tree and we can get this done with straight
> forwardly? Or do you have a different suggestion for me?
Feel free to apply it to your tree too. It's not ideal to have two
commits for the same thing, but oh well.
Acked-by: Jani Nikula <jani.nikula@intel.com>
--
Jani Nikula, Intel
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/3] drm/i915/selftests: use prandom in selftest
2025-03-21 12:37 ` Jani Nikula
@ 2025-03-21 12:52 ` Jason A. Donenfeld
0 siblings, 0 replies; 13+ messages in thread
From: Jason A. Donenfeld @ 2025-03-21 12:52 UTC (permalink / raw)
To: Jani Nikula
Cc: Andi Shyti, Markus Theil, linux-kernel, intel-gfx, netdev, tytso
On Fri, Mar 21, 2025 at 02:37:15PM +0200, Jani Nikula wrote:
> On Wed, 19 Mar 2025, "Jason A. Donenfeld" <Jason@zx2c4.com> wrote:
> > Hi Andi,
> >
> > On Thu, Feb 13, 2025 at 06:19:12PM +0100, Andi Shyti wrote:
> >> Hi Markus,
> >>
> >> On Tue, Feb 11, 2025 at 07:33:30AM +0100, Markus Theil wrote:
> >> > This is part of a prandom cleanup, which removes
> >> > next_pseudo_random32 and replaces it with the standard PRNG.
> >> >
> >> > Signed-off-by: Markus Theil <theil.markus@gmail.com>
> >>
> >> I merged just this patch in drm-intel-gt-next.
> >
> > This is minorly annoying for me... What am I supposed to do with patches
> > 2 and 3? Take them through my tree for 6.16 in like half a year? Can I
> > just take the v1 into my tree and we can get this done with straight
> > forwardly? Or do you have a different suggestion for me?
>
> Feel free to apply it to your tree too. It's not ideal to have two
> commits for the same thing, but oh well.
>
> Acked-by: Jani Nikula <jani.nikula@intel.com>
Oh that's a good idea. Thanks!
Jason
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2025-03-21 12:52 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-10 13:35 [PATCH] prandom: remove next_pseudo_random32 Markus Theil
2025-02-10 13:39 ` Jason A. Donenfeld
2025-02-10 23:07 ` Andi Shyti
2025-02-11 6:13 ` Markus Theil
2025-02-11 6:33 ` [PATCH v2 0/3] " Markus Theil
2025-02-11 6:33 ` [PATCH v2 1/3] drm/i915/selftests: use prandom in selftest Markus Theil
2025-02-13 17:19 ` Andi Shyti
2025-03-19 17:13 ` Jason A. Donenfeld
2025-03-21 12:37 ` Jani Nikula
2025-03-21 12:52 ` Jason A. Donenfeld
2025-02-11 6:33 ` [PATCH v2 2/3] media: vivid: use prandom Markus Theil
2025-02-11 6:33 ` [PATCH v2 3/3] prandom: remove next_pseudo_random32 Markus Theil
2025-02-13 14:27 ` [PATCH v2 0/3] " Krzysztof Karas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).