Skip to contentSkip to conversation

random: Resolve circular include dependency and include <linux/percpu.h>

PATCH RESEND Superseded Uros Bizjak 8 participants 29 messages Sep 9, 2024 – Sep 12, 2024

Subsystems (23)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover random: Resolve circular include dependency and include <linux/percpu.h>

Resent due to missing linux-kernel@ mailing list inclusion.

There were several attempts to resolve circular include dependency after the addition of percpu.h: 1c9df907da83 ("random: fix circular include dependency on arm64 after addition of percpu.h"), c0842fbc1b18 ("random32: move the pseudo-random 32-bit definitions to prandom.h") and finally d9f29deb7fe8 ("prandom: Remove unused include") that completely removes the inclusion of <linux/percpu.h>.

Due to legacy reasons, <linux/random.h> includes <linux/prandom.h>, but with the commit entry remark:

--quote--
A further cleanup step would be to remove this from <linux/random.h> entirely, and make people who use the prandom infrastructure include just the new header file. That's a bit of a churn patch, but grepping for "prandom_" and "next_pseudo_random32" "struct rnd_state" should catch most users.

But it turns out that that nice cleanup step is fairly painful, because a _lot_ of code currently seems to depend on the implicit include of <linux/random.h>, which can currently come in a lot of ways, including such fairly core headfers as <linux/net.h>.

So the "nice cleanup" part may or may never happen. --/quote--

We would like to include <linux/percpu.h> in <linux/prandom.h>. In [1] we would like to repurpose __percpu tag as a named address space qualifier, where __percpu macro uses defines from <linux/percpu.h>.

The major roadblock to inclusion of <linux/percpu.h> is the above mentioned legacy inclusion of <linux/prandom.h> in <linux/random.h> that causes circular include dependency that prevents <linux/percpu.h> inclusion.

This patch series is the "nice cleanup" part that:

a) Substitutes the inclusion of <linux/random.h> with the inclusion of <linux/prandom.h> where needed (patches 1 - 17).

b) Removes legacy inclusion of <linux/prandom.h> from <linux/random.h> (patch 18).

c) Includes <linux/percpu.h> in <linux/prandom.h> (patch 19).

The whole series was tested by compiling the kernel for x86_64 allconfig and some popular architectures, namely arm64 defconfig, powerpc defconfig and loongarch defconfig.

[1] https://lore.kernel.org/lkml/[email protected]/

Cc Dave Hansen <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
Cc Jani Nikula <[email protected]>
Cc Joonas Lahtinen <[email protected]>
Cc Rodrigo Vivi <[email protected]>
Cc Tvrtko Ursulin <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Cc Hans Verkuil <[email protected]>
Cc Mauro Carvalho Chehab <[email protected]>
Cc Miquel Raynal <[email protected]>
Cc Richard Weinberger <[email protected]>
Cc Vignesh Raghavendra <[email protected]>
Cc Eric Biggers <[email protected]>
Cc "Theodore Y. Ts'o" <[email protected]>
Cc Jaegeuk Kim <[email protected]>
Cc "Jason A. Donenfeld" <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc John Fastabend <[email protected]>
Cc Andrii Nakryiko <[email protected]>
Cc Martin KaFai Lau <[email protected]>
Cc Eduard Zingerman <[email protected]>
Cc Song Liu <[email protected]>
Cc Yonghong Song <[email protected]>
Cc KP Singh <[email protected]>
Cc Stanislav Fomichev <[email protected]>
Cc Hao Luo <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Brendan Higgins <[email protected]>
Cc David Gow <[email protected]>
Cc Rae Moar <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Jiri Pirko <[email protected]>
Cc Petr Mladek <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Rasmus Villemoes <[email protected]>
Cc Sergey Senozhatsky <[email protected]>
Cc Stephen Hemminger <[email protected]>
Cc Jamal Hadi Salim <[email protected]>
Cc Cong Wang <[email protected]>
Cc Kent Overstreet <[email protected]>

---
v2: - Reword commit messages to mention the removal of legacy inclusion
of <linux/prandom.h> from <linux/random.h>
- Add missing substitution in crypto/testmgr.c
(reported by kernel test robot)
- Add Acked-by:.

Uros Bizjak (19):
x86/kaslr: Include <linux/prandom.h> instead of <linux/random.h>
crypto: testmgr: Include <linux/prandom.h> instead of <linux/random.h> drm/i915/selftests: Include <linux/prandom.h> instead of
<linux/random.h>
drm/lib: Include <linux/prandom.h> instead of <linux/random.h>
media: vivid: Include <linux/prandom.h> in vivid-vid-cap.c
mtd: tests: Include <linux/prandom.h> instead of <linux/random.h>
fscrypt: Include <linux/once.h> in fs/crypto/keyring.c
scsi: libfcoe: Include <linux/prandom.h> instead of <linux/random.h>
bpf: Include <linux/prandom.h> instead of <linux/random.h> lib/interval_tree_test.c: Include <linux/prandom.h> instead of
<linux/random.h>
kunit: string-stream-test: Include <linux/prandom.h> instead of
<linux/random.h>
random32: Include <linux/prandom.h> instead of <linux/random.h> lib/rbtree-test: Include <linux/prandom.h> instead of <linux/random.h> bpf/tests: Include <linux/prandom.h> instead of <linux/random.h> lib/test_parman: Include <linux/prandom.h> instead of <linux/random.h> lib/test_scanf: Include <linux/prandom.h> instead of <linux/random.h>
netem: Include <linux/prandom.h> in sch_netem.c
random: Do not include <linux/prandom.h> in <linux/random.h>
prandom: Include <linux/percpu.h> in <linux/prandom.h>

 arch/x86/mm/kaslr.c                              | 2 +-
 crypto/testmgr.c                                 | 2 +-
 drivers/gpu/drm/i915/selftests/i915_gem.c        | 2 +-
 drivers/gpu/drm/i915/selftests/i915_random.h     | 2 +-
 drivers/gpu/drm/i915/selftests/scatterlist.c     | 2 +-
 drivers/gpu/drm/lib/drm_random.h                 | 2 +-
 drivers/media/test-drivers/vivid/vivid-vid-cap.c | 1 +
 drivers/mtd/tests/oobtest.c                      | 2 +-
 drivers/mtd/tests/pagetest.c                     | 2 +-
 drivers/mtd/tests/subpagetest.c                  | 2 +-
 fs/crypto/keyring.c                              | 1 +
 include/linux/prandom.h                          | 1 +
 include/linux/random.h                           | 7 -------
 include/scsi/libfcoe.h                           | 2 +-
 kernel/bpf/core.c                                | 2 +-
 lib/interval_tree_test.c                         | 2 +-
 lib/kunit/string-stream-test.c                   | 1 +
 lib/random32.c                                   | 2 +-
 lib/rbtree_test.c                                | 2 +-
 lib/test_bpf.c                                   | 2 +-
 lib/test_parman.c                                | 2 +-
 lib/test_scanf.c                                 | 2 +-
 net/sched/sch_netem.c                            | 1 +
 23 files changed, 22 insertions(+), 24 deletions(-)
Signature · 1 line
2.46.0
#1 lore raw

PATCH RESEND v2 1/19 x86/kaslr: Include <linux/prandom.h> instead of <linux/random.h>

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Cc Dave Hansen <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/mm/kaslr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/mm/kaslr.c +1 -1
index 230f1dee4f09..e17e6e27b7ec 100644
@@ -22,7 +22,7 @@
 
 #include <linux/kernel.h>
 #include <linux/init.h>
-#include <linux/random.h>
+#include <linux/prandom.h>
 #include <linux/memblock.h>
 #include <linux/pgtable.h>
 
Signature · 1 line
2.46.0
#2 lore raw

PATCH RESEND v2 2/19 crypto: testmgr: Include <linux/prandom.h> instead of <linux/random.h>

In reply to Uros Bizjak

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Cc Herbert Xu <[email protected]>
Cc "David S. Miller" <[email protected]>
---
 crypto/testmgr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/testmgr.c +1 -1
index f02cb075bd68..eeb7edd99a93 100644
@@ -23,7 +23,7 @@
 #include <linux/fips.h>
 #include <linux/module.h>
 #include <linux/once.h>
-#include <linux/random.h>
+#include <linux/prandom.h>
 #include <linux/scatterlist.h>
 #include <linux/slab.h>
 #include <linux/string.h>
Signature · 1 line
2.46.0
#4 lore raw

PATCH RESEND v2 3/19 drm/i915/selftests: Include <linux/prandom.h> instead of <linux/random.h>

In reply to Uros Bizjak

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Cc Joonas Lahtinen <[email protected]>
Cc Rodrigo Vivi <[email protected]>
Cc Tvrtko Ursulin <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/i915/selftests/i915_gem.c    | 2 +-
 drivers/gpu/drm/i915/selftests/i915_random.h | 2 +-
 drivers/gpu/drm/i915/selftests/scatterlist.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/selftests/i915_gem.c +1 -1
index 61da4ed9d521..0727492576be 100644
@@ -4,7 +4,7 @@
  * Copyright © 2018 Intel Corporation
  */
 
-#include <linux/random.h>
+#include <linux/prandom.h>
 
 #include "gem/i915_gem_internal.h"
 #include "gem/i915_gem_pm.h"
drivers/gpu/drm/i915/selftests/i915_random.h +1 -1
index 05364eca20f7..70330a2e80f2 100644
@@ -26,7 +26,7 @@
 #define __I915_SELFTESTS_RANDOM_H__
 
 #include <linux/math64.h>
-#include <linux/random.h>
+#include <linux/prandom.h>
 
 #include "../i915_selftest.h"
 
drivers/gpu/drm/i915/selftests/scatterlist.c +1 -1
index 805c4bfb85fe..7e59591bbed6 100644
@@ -22,7 +22,7 @@
  */
 
 #include <linux/prime_numbers.h>
-#include <linux/random.h>
+#include <linux/prandom.h>
 
 #include "i915_selftest.h"
 #include "i915_utils.h"
Signature · 1 line
2.46.0
#5 lore raw

PATCH RESEND v2 4/19 drm/lib: Include <linux/prandom.h> instead of <linux/random.h>

In reply to Uros Bizjak

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/lib/drm_random.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/lib/drm_random.h +1 -1
index 5543bf0474bc..9f827260a89d 100644
@@ -6,7 +6,7 @@
  * be transposed to lib/ at the earliest convenience.
  */
 
-#include <linux/random.h>
+#include <linux/prandom.h>
 
 #define DRM_RND_STATE_INITIALIZER(seed__) ({				\
 	struct rnd_state state__;					\
Signature · 1 line
2.46.0
#6 lore raw

PATCH RESEND v2 5/19 media: vivid: Include <linux/prandom.h> in vivid-vid-cap.c

In reply to Uros Bizjak

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Cc Hans Verkuil <[email protected]>
Cc Mauro Carvalho Chehab <[email protected]>
---
 drivers/media/test-drivers/vivid/vivid-vid-cap.c | 1 +
 1 file changed, 1 insertion(+)
drivers/media/test-drivers/vivid/vivid-vid-cap.c +1 -0
index 69620e0a35a0..184460eb356e 100644
@@ -10,6 +10,7 @@
 #include <linux/sched.h>
 #include <linux/vmalloc.h>
 #include <linux/videodev2.h>
+#include <linux/prandom.h>
 #include <linux/v4l2-dv-timings.h>
 #include <media/v4l2-common.h>
 #include <media/v4l2-event.h>
Signature · 1 line
2.46.0
#8 lore raw

PATCH RESEND v2 6/19 mtd: tests: Include <linux/prandom.h> instead of <linux/random.h>

In reply to Uros Bizjak

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Cc Miquel Raynal <[email protected]>
Cc Richard Weinberger <[email protected]>
Cc Vignesh Raghavendra <[email protected]>
---
 drivers/mtd/tests/oobtest.c     | 2 +-
 drivers/mtd/tests/pagetest.c    | 2 +-
 drivers/mtd/tests/subpagetest.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/mtd/tests/oobtest.c +1 -1
index 13fed398937e..e1ee68f8b8f8 100644
@@ -17,7 +17,7 @@
 #include <linux/mtd/mtd.h>
 #include <linux/slab.h>
 #include <linux/sched.h>
-#include <linux/random.h>
+#include <linux/prandom.h>
 
 #include "mtd_test.h"
 
drivers/mtd/tests/pagetest.c +1 -1
index 8eb40b6e6dfa..6878700d2fc0 100644
@@ -17,7 +17,7 @@
 #include <linux/mtd/mtd.h>
 #include <linux/slab.h>
 #include <linux/sched.h>
-#include <linux/random.h>
+#include <linux/prandom.h>
 
 #include "mtd_test.h"
 
drivers/mtd/tests/subpagetest.c +1 -1
index 05250a080139..f34bbf033c4d 100644
@@ -15,7 +15,7 @@
 #include <linux/mtd/mtd.h>
 #include <linux/slab.h>
 #include <linux/sched.h>
-#include <linux/random.h>
+#include <linux/prandom.h>
 
 #include "mtd_test.h"
 
Signature · 1 line
2.46.0
#10 lore raw

PATCH RESEND v2 7/19 fscrypt: Include <linux/once.h> in fs/crypto/keyring.c

In reply to Uros Bizjak

Include <linux/once.h> header to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Cc Eric Biggers <[email protected]>
Cc "Theodore Y. Ts'o" <[email protected]>
Cc Jaegeuk Kim <[email protected]>

---
v2: Include <linux/once.h> instead of <linux/prandom.h>

---
 fs/crypto/keyring.c | 1 +
 1 file changed, 1 insertion(+)
fs/crypto/keyring.c +1 -0
index 6681a71625f0..82fcc5683649 100644
@@ -22,6 +22,7 @@
 #include <crypto/skcipher.h>
 #include <linux/key-type.h>
 #include <linux/random.h>
+#include <linux/once.h>
 #include <linux/seq_file.h>
 
 #include "fscrypt_private.h"
Signature · 1 line
2.46.0
#12 lore raw

PATCH RESEND v2 8/19 scsi: libfcoe: Include <linux/prandom.h> instead of <linux/random.h>

In reply to Uros Bizjak

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Cc Hannes Reinecke <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
---
 include/scsi/libfcoe.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/scsi/libfcoe.h +1 -1
index 3c5899290aed..6616348e59b9 100644
@@ -15,7 +15,7 @@
 #include <linux/skbuff.h>
 #include <linux/workqueue.h>
 #include <linux/local_lock.h>
-#include <linux/random.h>
+#include <linux/prandom.h>
 #include <scsi/fc/fc_fcoe.h>
 #include <scsi/libfc.h>
 #include <scsi/fcoe_sysfs.h>
Signature · 1 line
2.46.0
#14 lore raw

PATCH RESEND v2 9/19 bpf: Include <linux/prandom.h> instead of <linux/random.h>

In reply to Uros Bizjak

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Cc Alexei Starovoitov <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc John Fastabend <[email protected]>
Cc Andrii Nakryiko <[email protected]>
Cc Martin KaFai Lau <[email protected]>
Cc Eduard Zingerman <[email protected]>
Cc Song Liu <[email protected]>
Cc Yonghong Song <[email protected]>
Cc KP Singh <[email protected]>
Cc Stanislav Fomichev <[email protected]>
Cc Hao Luo <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 kernel/bpf/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/core.c +1 -1
index 7ee62e38faf0..3f0d1eb7f5b0 100644
@@ -21,7 +21,7 @@
 #include <linux/filter.h>
 #include <linux/skbuff.h>
 #include <linux/vmalloc.h>
-#include <linux/random.h>
+#include <linux/prandom.h>
 #include <linux/bpf.h>
 #include <linux/btf.h>
 #include <linux/objtool.h>
Signature · 1 line
2.46.0
#15 lore raw

PATCH RESEND v2 10/19 lib/interval_tree_test.c: Include <linux/prandom.h> instead of <linux/random.h>

In reply to Uros Bizjak

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

---
 lib/interval_tree_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/interval_tree_test.c +1 -1
index f37f4d44faa9..837064b83a6c 100644
@@ -2,7 +2,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/interval_tree.h>
-#include <linux/random.h>
+#include <linux/prandom.h>
 #include <linux/slab.h>
 #include <asm/timex.h>
 
Signature · 1 line
2.46.0
#16 lore raw

PATCH RESEND v2 11/19 kunit: string-stream-test: Include <linux/prandom.h> instead of <linux/random.h>

In reply to Uros Bizjak

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Cc Brendan Higgins <[email protected]>
Cc David Gow <[email protected]>
Cc Rae Moar <[email protected]>
---
 lib/kunit/string-stream-test.c | 1 +
 1 file changed, 1 insertion(+)
lib/kunit/string-stream-test.c +1 -0
index 7511442ea98f..7734e33156f9 100644
@@ -9,6 +9,7 @@
 #include <kunit/static_stub.h>
 #include <kunit/test.h>
 #include <linux/ktime.h>
+#include <linux/prandom.h>
 #include <linux/slab.h>
 #include <linux/timekeeping.h>
 
Signature · 1 line
2.46.0
#17 lore raw

PATCH RESEND v2 12/19 random32: Include <linux/prandom.h> instead of <linux/random.h>

In reply to Uros Bizjak

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Cc Andrew Morton <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
---
 lib/random32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/random32.c +1 -1
index 32060b852668..31fc2ca68856 100644
@@ -36,7 +36,7 @@
 #include <linux/percpu.h>
 #include <linux/export.h>
 #include <linux/jiffies.h>
-#include <linux/random.h>
+#include <linux/prandom.h>
 #include <linux/sched.h>
 #include <linux/bitops.h>
 #include <linux/slab.h>
Signature · 1 line
2.46.0
#18 lore raw

PATCH RESEND v2 13/19 lib/rbtree-test: Include <linux/prandom.h> instead of <linux/random.h>

In reply to Uros Bizjak

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

---
 lib/rbtree_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/rbtree_test.c +1 -1
index 41ae3c7570d3..8655a76d29a1 100644
@@ -2,7 +2,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/rbtree_augmented.h>
-#include <linux/random.h>
+#include <linux/prandom.h>
 #include <linux/slab.h>
 #include <asm/timex.h>
 
Signature · 1 line
2.46.0
#19 lore raw

PATCH RESEND v2 14/19 bpf/tests: Include <linux/prandom.h> instead of <linux/random.h>

In reply to Uros Bizjak

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Cc Andrew Morton <[email protected]>
Cc Alexei Starovoitov <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc Andrii Nakryiko <[email protected]>
Cc Martin KaFai Lau <[email protected]>
Cc Eduard Zingerman <[email protected]>
Cc Song Liu <[email protected]>
Cc Yonghong Song <[email protected]>
Cc John Fastabend <[email protected]>
Cc KP Singh <[email protected]>
Cc Stanislav Fomichev <[email protected]>
Cc Hao Luo <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 lib/test_bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/test_bpf.c +1 -1
index ca4b0eea81a2..eb4a1915e4d2 100644
@@ -14,7 +14,7 @@
 #include <linux/skbuff.h>
 #include <linux/netdevice.h>
 #include <linux/if_vlan.h>
-#include <linux/random.h>
+#include <linux/prandom.h>
 #include <linux/highmem.h>
 #include <linux/sched.h>
 
Signature · 1 line
2.46.0
#20 lore raw

PATCH RESEND v2 15/19 lib/test_parman: Include <linux/prandom.h> instead of <linux/random.h>

In reply to Uros Bizjak

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Cc Andrew Morton <[email protected]>
Cc Jiri Pirko <[email protected]>
---
 lib/test_parman.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/test_parman.c +1 -1
index 35e32243693c..f9b97426a337 100644
@@ -39,7 +39,7 @@
 #include <linux/slab.h>
 #include <linux/bitops.h>
 #include <linux/err.h>
-#include <linux/random.h>
+#include <linux/prandom.h>
 #include <linux/parman.h>
 
 #define TEST_PARMAN_PRIO_SHIFT 7 /* defines number of prios for testing */
Signature · 1 line
2.46.0
#21 lore raw

PATCH RESEND v2 16/19 lib/test_scanf: Include <linux/prandom.h> instead of <linux/random.h>

In reply to Uros Bizjak

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Cc Petr Mladek <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Rasmus Villemoes <[email protected]>
Cc Sergey Senozhatsky <[email protected]>
Cc Andrew Morton <[email protected]>
---
 lib/test_scanf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/test_scanf.c +1 -1
index 7257b1768545..44f8508c9d88 100644
@@ -11,7 +11,7 @@
 #include <linux/module.h>
 #include <linux/overflow.h>
 #include <linux/printk.h>
-#include <linux/random.h>
+#include <linux/prandom.h>
 #include <linux/slab.h>
 #include <linux/string.h>
 
Signature · 1 line
2.46.0
#23 lore raw

PATCH RESEND v2 17/19 netem: Include <linux/prandom.h> in sch_netem.c

In reply to Uros Bizjak

Include <linux/prandom.h> header to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Cc Stephen Hemminger <[email protected]>
Cc Jamal Hadi Salim <[email protected]>
Cc Cong Wang <[email protected]>
Cc Jiri Pirko <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
---
 net/sched/sch_netem.c | 1 +
 1 file changed, 1 insertion(+)
net/sched/sch_netem.c +1 -0
index 0f8d581438c3..2d919f590772 100644
@@ -17,6 +17,7 @@
 #include <linux/errno.h>
 #include <linux/skbuff.h>
 #include <linux/vmalloc.h>
+#include <linux/prandom.h>
 #include <linux/rtnetlink.h>
 #include <linux/reciprocal_div.h>
 #include <linux/rbtree.h>
Signature · 1 line
2.46.0
#24 lore raw

PATCH RESEND v2 18/19 random: Do not include <linux/prandom.h> in <linux/random.h>

In reply to Uros Bizjak

Files that use prandom infrastructure are now converted to use <linux/prandom.h> header instead of <linux/random.h>. Remove the legacy inclusion of <linux/prandom.h> from <linux/random.h>.

This is the "nice cleanup" part, wished in c0842fbc1b18.

Fixes c0842fbc1b18 ("random32: move the pseudo-random 32-bit definitions to prandom.h")
Cc "Theodore Ts'o" <[email protected]>
Cc "Jason A. Donenfeld" <[email protected]>
Cc Linus Torvalds <[email protected]>
---
 include/linux/random.h | 7 -------
 1 file changed, 7 deletions(-)
include/linux/random.h +0 -7
index b0a940af4fff..333cecfca93f 100644
@@ -145,13 +145,6 @@ declare_get_random_var_wait(u64, u32)
 declare_get_random_var_wait(long, unsigned long)
 #undef declare_get_random_var
 
-/*
- * This is designed to be standalone for just prandom
- * users, but for now we include it from <linux/random.h>
- * for legacy reasons.
- */
-#include <linux/prandom.h>
-
 #ifdef CONFIG_SMP
 int random_prepare_cpu(unsigned int cpu);
 int random_online_cpu(unsigned int cpu);
Signature · 1 line
2.46.0
#25 lore raw

PATCH RESEND v2 19/19 prandom: Include <linux/percpu.h> in <linux/prandom.h>

In reply to Uros Bizjak

<linux/percpu.h> include was removed from <linux/prandom.h> in d9f29deb7fe8 ("prandom: Remove unused include") because this inclusion broke arm64 due to a circular dependency on include files.

__percpu tag is defined in include/linux/compiler_types.h, so there is currently no direct need for the inclusion of <linux/percpu.h>. However, in [1] we would like to repurpose __percpu tag as a named address space qualifier, where __percpu macro uses defines from <linux/percpu.h>.

The circular dependency was removed in xxxxxxxxxxxx ("random: Do not include <linux/prandom.h> in <linux/random.h>") and it cleared the path for the inclusion of <linux/percpu.h> in <linux/prandom.h>.

This patch is basically a revert of d9f29deb7fe8
("prandom: Remove unused include").

[1] https://lore.kernel.org/lkml/[email protected]/

Cc "Theodore Ts'o" <[email protected]>
Cc "Jason A. Donenfeld" <[email protected]>
Cc Kent Overstreet <[email protected]>
---
 include/linux/prandom.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/prandom.h +1 -0
index f7f1e5251c67..f2ed5b72b3d6 100644
@@ -10,6 +10,7 @@
 
 #include <linux/types.h>
 #include <linux/once.h>
+#include <linux/percpu.h>
 #include <linux/random.h>
 
 struct rnd_state {
Signature · 1 line
2.46.0
maintainer Acked-by on v2 6/19
#9 lore raw

Re: [PATCH RESEND v2 06/19] mtd: tests: Include <linux/prandom.h> instead of <linux/random.h>

In reply to Uros Bizjak

Hi Uros,

[email protected] wrote on Mon, 9 Sep 2024 09:53:49 +0200:

Quoted 3 lines

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Quoted 5 lines
Cc Miquel Raynal <[email protected]>
Cc Richard Weinberger <[email protected]>
Cc Vignesh Raghavendra <[email protected]>

Miquèl

Acked-by on v2 5/19
#7 lore raw

Re: [PATCH RESEND v2 05/19] media: vivid: Include <linux/prandom.h> in vivid-vid-cap.c

In reply to Uros Bizjak
Quoted 5 lines · Uros Bizjak

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Regards,

Hans

Quoted 19 lines
Cc Hans Verkuil <[email protected]>
Cc Mauro Carvalho Chehab <[email protected]>
---
 drivers/media/test-drivers/vivid/vivid-vid-cap.c | 1 +
 1 file changed, 1 insertion(+)
drivers/media/test-drivers/vivid/vivid-vid-cap.c +1 -0
index 69620e0a35a0..184460eb356e 100644
@@ -10,6 +10,7 @@
 #include <linux/sched.h>
 #include <linux/vmalloc.h>
 #include <linux/videodev2.h>
+#include <linux/prandom.h>
 #include <linux/v4l2-dv-timings.h>
 #include <media/v4l2-common.h>
 #include <media/v4l2-event.h>
Acked-by on v2 16/19
#22 lore raw

Re: [PATCH RESEND v2 16/19] lib/test_scanf: Include <linux/prandom.h> instead of <linux/random.h>

In reply to Uros Bizjak
Quoted 5 lines · Uros Bizjak

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

I have just acked v1 and missed that there already is v2. Just for record:

Best Regards,
Petr

#26 lore raw
In reply to Uros Bizjak

Hi Uros,

Quoted 7 lines · Uros Bizjak

a) Substitutes the inclusion of <linux/random.h> with the inclusion of <linux/prandom.h> where needed (patches 1 - 17).

b) Removes legacy inclusion of <linux/prandom.h> from <linux/random.h> (patch 18).

c) Includes <linux/percpu.h> in <linux/prandom.h> (patch 19).

Thanks for doing this. That seems like a fine initiative to me. (I'm also curious about the future percpu changes you've got planned.)

Tree-wise, were you expecting me to take this through random.git? And if so, what timeframe did you have in mind? For 6.12 next week (can you poke folks for acks in time?), or punt it for 6.13? Or did you have a different tree in mind for treewide changes (in which case, I'll send you an ack for the [p]random.h changes).

Regards,
Jason

#27 lore raw
Quoted 11 lines · Jason A. Donenfeld
Quoted 7 lines · Uros Bizjak

a) Substitutes the inclusion of <linux/random.h> with the inclusion of <linux/prandom.h> where needed (patches 1 - 17).

b) Removes legacy inclusion of <linux/prandom.h> from <linux/random.h> (patch 18).

c) Includes <linux/percpu.h> in <linux/prandom.h> (patch 19).

Thanks for doing this. That seems like a fine initiative to me. (I'm also curious about the future percpu changes you've got planned.)

As explained in the cover letter, recent GCCs are able to track address space of variables in percpu address space from the declaration to its usage site. There are certain rules regarding casts of variables and their pointers (when this named address space is not considered a subspace of the generic address space), so it is possible to create much more effective checks for cast-from-as type casts than what sparse can achieve.

Besides GCC, clang can define various named address space via address_space attribute:

--cut here--
#define __as(N) __attribute__((address_space(N)))

void *foo(void __as(1) *x) { return x; } // error

void *bar(void __as(1) *x) { return (void *)x; } // fine --cut here--

When compiling this, the compiler returns:

clang-as.c:3:37: error: returning '__as(1) void *' from a function with result type 'void *' changes address space of pointer

Although clang currently errors out when __seg_gs and __seg_fs named address space designators are used, we can explore its named address spaces functionality to implement percpu checks for all targets. The percpu address space checks patchset, referred to in the cover letter, also supports this functionality when per_cpu_qual is defined to __attribute__((address_space(N))).

Perhaps we can use different address spaces to also handle __user, __iomem and __rcu address spaces. This way the compiler will be able to handle address space checks instead of sparse.

Quoted 5 lines

Tree-wise, were you expecting me to take this through random.git? And if so, what timeframe did you have in mind? For 6.12 next week (can you poke folks for acks in time?), or punt it for 6.13? Or did you have a different tree in mind for treewide changes (in which case, I'll send you an ack for the [p]random.h changes).

I think that the best approach is to target this patchset for linux 6.13 via random.git tree. I will prepare a v3 after 6.12rc1, so when committed to random.git, the patchset will be able to spend some time in linux-next. This way, there will be plenty of time for CI robots to do additional checks also for some less popular targets (although individual patches are dead simple, removing these kinds of "legacy" includes can be tricky), and I will also be able to collect Acked-by:s in the meantime.

While the patchset is an improvement by itself, its inclusion is not time sensitive. The follow up percpu named address checking functionality requires a very recent feature (__typeof_unqual__ keyword), which is only supported in recent compilers (gcc-14 and clang-20). Besides compiler support, sparse doesn't know about __typeof_unqual__, resulting in broken type tracing and hundreds of sparse errors with C=1 due to unknown keyword.

So, I think we are not in a hurry and can take the slow and safe path.

Thanks and best regards,
Uros.

#28 lore raw

Hi Uros,

Quoted 8 lines · Uros Bizjak

Besides GCC, clang can define various named address space via address_space attribute:

--cut here--
#define __as(N) __attribute__((address_space(N)))

void *foo(void __as(1) *x) { return x; } // error

Quoted 7 lines

void *bar(void __as(1) *x) { return (void *)x; } // fine --cut here--

When compiling this, the compiler returns:

clang-as.c:3:37: error: returning '__as(1) void *' from a function with result type 'void *' changes address space of pointer

Super cool. Looking forward to having it all wired up and the bugs we'll find with it.

Quoted 17 lines

I think that the best approach is to target this patchset for linux 6.13 via random.git tree. I will prepare a v3 after 6.12rc1, so when committed to random.git, the patchset will be able to spend some time in linux-next. This way, there will be plenty of time for CI robots to do additional checks also for some less popular targets (although individual patches are dead simple, removing these kinds of "legacy" includes can be tricky), and I will also be able to collect Acked-by:s in the meantime.

While the patchset is an improvement by itself, its inclusion is not time sensitive. The follow up percpu named address checking functionality requires a very recent feature (__typeof_unqual__ keyword), which is only supported in recent compilers (gcc-14 and clang-20). Besides compiler support, sparse doesn't know about __typeof_unqual__, resulting in broken type tracing and hundreds of sparse errors with C=1 due to unknown keyword.

Quoted 1 line

So, I think we are not in a hurry and can take the slow and safe path.

Okay, sure, that sounds good to me. I'll keep my eyes open for v3 in a few weeks then.

Jason

maintainer Acked-by on v2 7/19
#11 lore raw

Re: [PATCH RESEND v2 07/19] fscrypt: Include <linux/once.h> in fs/crypto/keyring.c

In reply to Uros Bizjak
Quoted 18 lines · Uros Bizjak

Include <linux/once.h> header to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Cc Eric Biggers <[email protected]>
Cc "Theodore Y. Ts'o" <[email protected]>
Cc Jaegeuk Kim <[email protected]>

---
v2: Include <linux/once.h> instead of <linux/prandom.h>

---
 fs/crypto/keyring.c | 1 +
 1 file changed, 1 insertion(+)
fs/crypto/keyring.c +0 -0
index 6681a71625f0..82fcc5683649 100644

fs/crypto/keyring.c line 28

Quoted 7 lines
fs/crypto/keyring.c +1 -0
@@ -22,6 +22,7 @@
 #include <crypto/skcipher.h>
 #include <linux/key-type.h>
 #include <linux/random.h>
+#include <linux/once.h>
 #include <linux/seq_file.h>
 
 #include "fscrypt_private.h"

- Eric

Reviewed-by on v2 8/19
#13 lore raw

Re: [PATCH RESEND v2 08/19] scsi: libfcoe: Include <linux/prandom.h> instead of <linux/random.h>

In reply to Uros Bizjak
Quoted 17 lines · Uros Bizjak

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Cc Hannes Reinecke <[email protected]>
Cc "James E.J. Bottomley" <[email protected]>
Cc "Martin K. Petersen" <[email protected]>
---
  include/scsi/libfcoe.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
include/scsi/libfcoe.h +0 -0
index 3c5899290aed..6616348e59b9 100644

include/scsi/libfcoe.h line 21

Quoted 8 lines
include/scsi/libfcoe.h +1 -1
@@ -15,7 +15,7 @@
  #include <linux/skbuff.h>
  #include <linux/workqueue.h>
  #include <linux/local_lock.h>
-#include <linux/random.h>
+#include <linux/prandom.h>
  #include <scsi/fc/fc_fcoe.h>
  #include <scsi/libfc.h>
  #include <scsi/fcoe_sysfs.h>
maintainer Acked-by on v2 2/19
#3 lore raw

Re: [PATCH RESEND v2 02/19] crypto: testmgr: Include <linux/prandom.h> instead of <linux/random.h>

In reply to Uros Bizjak
Quoted 10 lines · Uros Bizjak

Substitute the inclusion of <linux/random.h> header with <linux/prandom.h> to allow the removal of legacy inclusion of <linux/prandom.h> from <linux/random.h>.

Cc Herbert Xu <[email protected]>
Cc "David S. Miller" <[email protected]>

---
crypto/testmgr.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt