Skip to contentSkip to conversation

big header dependency cleanup targeting sched.h

PATCH In review Kent Overstreet 11 participants 96 messages Dec 16, 2023 – Mar 8, 2024

Subsystems (33)
DRM drivers Memory management x86 VFS +29 more subsystems
lore
Share & tools
lore
#0 lore raw

cover big header dependency cleanup targeting sched.h

the issue being targeted here is that sched.h is entirely too much of an everything header, and a nexus of recursive header dependencies.

the main strategy is to try to only pull type definitions into sched.h, by splitting out *_types.h versions of sched.h dependencies, and secondarily moving code out of sched.h into more appropriate locations.

this patchset does not go quite as far as I would have liked; arch/x86/include/asm/processor.h also pulls in way too much, and I would like to also split out a _types.h version for that, but that would entail changing every arch's version of that header and I'm not going to tackle that yet.

if we do get that done, the number of headers pulled in by sched.h will be cut approximately in half (from well over 300 to 170-180) on an allyesconfig.

build tested on x86, still needs build testing on other archs

https://evilpiepirate.org/git/bcachefs.git/log/?h=header_cleanup

Kent Overstreet (49):
drivers/gpu/drm/i915/i915_memcpy.c: fix missing includes x86/kernel/fpu/bugs.c: fix missing include x86/lib/cache-smp.c: fix missing include x86/include/asm/debugreg.h: fix missing include x86/include/asm/paravirt_types.h: fix missing include task_stack.h: add missing include
nsproxy.h: add missing include
kernel/fork.c: add missing include
kmsan: add missing types.h dependency time_namespace.h: fix missing include
nodemask: Split out include/linux/nodemask_types.h
prandom: Remove unused include
timekeeping: Kill percpu.h dependency
arm64: Fix circular header dependency
kernel/numa.c: Move logging out of numa.h
sched.h: Move (spin|rwlock)_needbreak() to spinlock.h ktime.h: move ktime_t to types.h
hrtimers: Split out hrtimer_types.h
locking/mutex: split out mutex_types.h
posix-cpu-timers: Split out posix-timers_types.h locking/seqlock: Split out seqlock_types.h
pid: Split out pid_types.h
sched.h: move pid helpers to pid.h
plist: Split out plist_types.h
rslib: kill bogus dependency on list.h
timerqueue: Split out timerqueue_types.h
signal: Kill bogus dependency on list.h
timers: Split out timer_types.h
workqueue: Split out workqueue_types.h
shm: Slim down dependencies
ipc: Kill bogus dependency on spinlock.h
Split out irqflags_types.h
mm_types_task.h: Trim dependencies
cpumask: Split out cpumask_types.h syscall_user_dispatch.h: split out *_types.h x86/signal: kill dependency on time.h uapi/linux/resource.h: fix include
refcount: Split out refcount_types.h
seccomp: Split out seccomp_types.h
uidgid: Split out uidgid_types.h
sem: Split out sem_types.h
lockdep: move held_lock to lockdep_types.h
restart_block: Trim includes
rseq: Split out rseq.h from sched.h
preempt.h: Kill dependency on list.h
thread_info, uaccess.h: Move HARDENED_USERCOPY to better location Kill unnecessary kernel.h include
kill unnecessary thread_info.h include
Kill sched.h dependency on rcupdate.h

Matthew Wilcox (Oracle) (1):
wait: Remove uapi header file from main header file

 arch/arm64/include/asm/spectre.h            |   4 +-
 arch/x86/include/asm/current.h              |   1 +
 arch/x86/include/asm/debugreg.h             |   1 +
 arch/x86/include/asm/fpu/types.h            |   2 +
 arch/x86/include/asm/paravirt_types.h       |   2 +
 arch/x86/include/asm/percpu.h               |   2 +-
 arch/x86/include/asm/preempt.h              |   1 -
 arch/x86/include/asm/tlbbatch.h             |   2 +-
 arch/x86/include/uapi/asm/signal.h          |   1 -
 arch/x86/kernel/fpu/bugs.c                  |   1 +
 arch/x86/kernel/signal.c                    |   1 +
 arch/x86/lib/cache-smp.c                    |   1 +
 drivers/gpu/drm/i915/i915_memcpy.c          |   2 +
 drivers/target/target_core_xcopy.c          |   1 +
 fs/exec.c                                   |   1 +
 include/linux/audit.h                       |   1 +
 include/linux/cpumask.h                     |   4 +-
 include/linux/cpumask_types.h               |  12 +
 include/linux/dma-fence.h                   |   1 +
 include/linux/hrtimer.h                     |  46 +--
 include/linux/hrtimer_types.h               |  50 +++
 include/linux/ipc.h                         |   2 +-
 include/linux/irqflags.h                    |  14 +-
 include/linux/irqflags_types.h              |  22 ++
 include/linux/kmsan_types.h                 |   2 +
 include/linux/ktime.h                       |   8 +-
 include/linux/lockdep.h                     |  57 ----
 include/linux/lockdep_types.h               |  57 ++++
 include/linux/mm_types_task.h               |   7 +-
 include/linux/mutex.h                       |  52 +---
 include/linux/mutex_types.h                 |  71 +++++
 include/linux/nodemask.h                    |   2 +-
 include/linux/nodemask_types.h              |  10 +
 include/linux/nsproxy.h                     |   1 +
 include/linux/numa.h                        |  18 +-
 include/linux/pid.h                         | 140 ++++++++-
 include/linux/pid_types.h                   |  16 +
 include/linux/plist.h                       |  12 +-
 include/linux/plist_types.h                 |  17 ++
 include/linux/posix-timers.h                |  68 +----
 include/linux/posix-timers_types.h          |  72 +++++
 include/linux/prandom.h                     |   1 -
 include/linux/preempt.h                     |   6 +-
 include/linux/rcupdate.h                    |  11 +
 include/linux/refcount.h                    |  13 +-
 include/linux/refcount_types.h              |  19 ++
 include/linux/restart_block.h               |   2 +-
 include/linux/resume_user_mode.h            |   1 +
 include/linux/rhashtable-types.h            |   2 +-
 include/linux/rseq.h                        | 131 ++++++++
 include/linux/rslib.h                       |   1 -
 include/linux/sched.h                       | 320 ++------------------
 include/linux/sched/signal.h                |   1 +
 include/linux/sched/task_stack.h            |   1 +
 include/linux/seccomp.h                     |  22 +-
 include/linux/seccomp_types.h               |  26 ++
 include/linux/sem.h                         |  10 +-
 include/linux/sem_types.h                   |  13 +
 include/linux/seqlock.h                     |  79 +----
 include/linux/seqlock_types.h               |  93 ++++++
 include/linux/shm.h                         |   4 +-
 include/linux/signal.h                      |   1 +
 include/linux/signal_types.h                |   2 +-
 include/linux/spinlock.h                    |  31 ++
 include/linux/syscall_user_dispatch.h       |   9 +-
 include/linux/syscall_user_dispatch_types.h |  22 ++
 include/linux/thread_info.h                 |  49 ---
 include/linux/time_namespace.h              |   3 +
 include/linux/timekeeping.h                 |   1 +
 include/linux/timer.h                       |  16 +-
 include/linux/timer_types.h                 |  23 ++
 include/linux/timerqueue.h                  |  13 +-
 include/linux/timerqueue_types.h            |  17 ++
 include/linux/types.h                       |   3 +
 include/linux/uaccess.h                     |  49 +++
 include/linux/uidgid.h                      |  11 +-
 include/linux/uidgid_types.h                |  15 +
 include/linux/uio.h                         |   2 +-
 include/linux/wait.h                        |   1 -
 include/linux/workqueue.h                   |  16 +-
 include/linux/workqueue_types.h             |  25 ++
 include/uapi/linux/resource.h               |   2 +-
 init/init_task.c                            |   1 +
 ipc/shm.c                                   |   1 +
 kernel/Makefile                             |   1 +
 kernel/exit.c                               |   4 +-
 kernel/fork.c                               |   2 +
 kernel/futex/core.c                         |   1 +
 kernel/futex/requeue.c                      |   1 +
 kernel/futex/waitwake.c                     |   1 +
 kernel/numa.c                               |  24 ++
 kernel/pid_namespace.c                      |   1 +
 kernel/sched/core.c                         |   1 +
 mm/swapfile.c                               |   1 +
 security/selinux/hooks.c                    |   1 +
 security/smack/smack_lsm.c                  |   1 +
 96 files changed, 1068 insertions(+), 825 deletions(-)
 create mode 100644 include/linux/cpumask_types.h
 create mode 100644 include/linux/hrtimer_types.h
 create mode 100644 include/linux/irqflags_types.h
 create mode 100644 include/linux/mutex_types.h
 create mode 100644 include/linux/nodemask_types.h
 create mode 100644 include/linux/pid_types.h
 create mode 100644 include/linux/plist_types.h
 create mode 100644 include/linux/posix-timers_types.h
 create mode 100644 include/linux/refcount_types.h
 create mode 100644 include/linux/rseq.h
 create mode 100644 include/linux/seccomp_types.h
 create mode 100644 include/linux/sem_types.h
 create mode 100644 include/linux/seqlock_types.h
 create mode 100644 include/linux/syscall_user_dispatch_types.h
 create mode 100644 include/linux/timer_types.h
 create mode 100644 include/linux/timerqueue_types.h
 create mode 100644 include/linux/uidgid_types.h
 create mode 100644 include/linux/workqueue_types.h
 create mode 100644 kernel/numa.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/50 drivers/gpu/drm/i915/i915_memcpy.c: fix missing includes

---
 drivers/gpu/drm/i915/i915_memcpy.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/i915/i915_memcpy.c +2 -0
index 1b021a4902de..40b288136841 100644
@@ -23,6 +23,8 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/string.h>
+#include <asm/cpufeature.h>
 #include <asm/fpu/api.h>
 
 #include "i915_memcpy.h"
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 01/50] drivers/gpu/drm/i915/i915_memcpy.c: fix missing includes

Quoted 1 line · Kent Overstreet

This seems to have been merged to v6.8-rc1 as commit 86b9357c1bbe ("drivers/gpu/drm/i915/i915_memcpy.c: fix missing includes") without Cc'ing the relevant lists or people, with no commit message or reviews, or the CI we mandate for every single patch.

Sure it's trivial, but please extend the same courtesy to us as you'd expect everyone else to extend to you before just merging stuff in the trees you maintain.

Thanks,
Jani.

Quoted 17 lines
---
 drivers/gpu/drm/i915/i915_memcpy.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/i915/i915_memcpy.c +2 -0
index 1b021a4902de..40b288136841 100644
@@ -23,6 +23,8 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/string.h>
+#include <asm/cpufeature.h>
 #include <asm/fpu/api.h>
 
 #include "i915_memcpy.h"
Signature · 1 line
Jani Nikula, Intel
#3 lore raw

PATCH 2/50 x86/kernel/fpu/bugs.c: fix missing include

In reply to Kent Overstreet
---
 arch/x86/kernel/fpu/bugs.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/kernel/fpu/bugs.c +1 -0
index 794e70151203..a06b876bbf2d 100644
@@ -2,6 +2,7 @@
 /*
  * x86 FPU bug checks:
  */
+#include <asm/cpufeature.h>
 #include <asm/fpu/api.h>
 
 /*
Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH 02/50] x86/kernel/fpu/bugs.c: fix missing include

For the x86 patches [2-5/50], should the patch subject be a bit more generic rather than having the full file name listed.

For example, this patch could be "x86/fpu: Fix missing include".

Quoted 5 lines · Kent Overstreet
---
 arch/x86/kernel/fpu/bugs.c | 1 +
 1 file changed, 1 insertion(+)
#5 lore raw

Re: [PATCH 02/50] x86/kernel/fpu/bugs.c: fix missing include

Quoted 4 lines · Sohil Mehta

For the x86 patches [2-5/50], should the patch subject be a bit more generic rather than having the full file name listed.

For example, this patch could be "x86/fpu: Fix missing include".

In the latest version of the patchset I've just rolled all of the arch/x86 missing includes into one patch.

#6 lore raw

PATCH 3/50 x86/lib/cache-smp.c: fix missing include

In reply to Kent Overstreet
---
 arch/x86/lib/cache-smp.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/lib/cache-smp.c +1 -0
index 7c48ff4ae8d1..7af743bd3b13 100644
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
+#include <asm/paravirt.h>
 #include <linux/smp.h>
 #include <linux/export.h>
 
Signature · 1 line
2.43.0
#7 lore raw

Re: [PATCH 03/50] x86/lib/cache-smp.c: fix missing include

arch/x86/lib/cache-smp.c line 5

Quoted 10 lines
arch/x86/lib/cache-smp.c +1 -0
index 7c48ff4ae8d1..7af743bd3b13 100644
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
+#include <asm/paravirt.h>
 #include <linux/smp.h>
 #include <linux/export.h>
 

I believe the norm is to have the linux/ includes first, followed by the the asm/ ones. Shouldn't this case be the same?

Sohil

#8 lore raw

Re: [PATCH 03/50] x86/lib/cache-smp.c: fix missing include

Quoted 5 lines · Sohil Mehta
Quoted 5 lines
arch/x86/lib/cache-smp.c +0 -0
index 7c48ff4ae8d1..7af743bd3b13 100644
@@ -1,4 +1,5 @@
Quoted 8 lines

arch/x86/lib/cache-smp.c line 5

Quoted 5 lines
arch/x86/lib/cache-smp.c +1 -0
 // SPDX-License-Identifier: GPL-2.0
+#include <asm/paravirt.h>
 #include <linux/smp.h>
 #include <linux/export.h>
 

I believe the norm is to have the linux/ includes first, followed by the the asm/ ones. Shouldn't this case be the same?

I haven't seen that? I generally do the reverse, simpler includes first, not that I have any reason for that...

#9 lore raw

Re: [PATCH 03/50] x86/lib/cache-smp.c: fix missing include

Quoted 6 lines · Kent Overstreet
Quoted 2 lines · Sohil Mehta

I believe the norm is to have the linux/ includes first, followed by the the asm/ ones. Shouldn't this case be the same?

I haven't seen that? I generally do the reverse, simpler includes first, not that I have any reason for that...

I couldn't find a kernel Documentation link handy. But, I found this email from Boris:
https://lore.kernel.org/lkml/[email protected]/

I believe at least arch/x86 follows this for the most part. One simple reason is to make it easier to find headers when a ton of them are included in the same file.

Sohil

#10 lore raw

PATCH 4/50 x86/include/asm/debugreg.h: fix missing include

In reply to Kent Overstreet
---
 arch/x86/include/asm/debugreg.h | 1 +
 1 file changed, 1 insertion(+)
arch/x86/include/asm/debugreg.h +1 -0
index 66eb5e1ac4fb..0cec92c430cc 100644
@@ -5,6 +5,7 @@
 #include <linux/bug.h>
 #include <linux/percpu.h>
 #include <uapi/asm/debugreg.h>
+#include <asm/cpufeature.h>
 
 DECLARE_PER_CPU(unsigned long, cpu_dr7);
 
Signature · 1 line
2.43.0
#11 lore raw

PATCH 5/50 x86/include/asm/paravirt_types.h: fix missing include

In reply to Kent Overstreet
---
 arch/x86/include/asm/paravirt_types.h | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/include/asm/paravirt_types.h +2 -0
index 772d03487520..3cfcd5db083b 100644
@@ -3,6 +3,8 @@
 #define _ASM_X86_PARAVIRT_TYPES_H
 
 #ifndef __ASSEMBLY__
+#include <linux/types.h>
+
 /* These all sit in the .parainstructions section to tell us what to patch. */
 struct paravirt_patch_site {
 	u8 *instr;		/* original instructions */
Signature · 1 line
2.43.0
#12 lore raw

PATCH 6/50 task_stack.h: add missing include

In reply to Kent Overstreet
---
 include/linux/sched/task_stack.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/sched/task_stack.h +1 -0
index f158b025c175..ccd72b978e1f 100644
@@ -8,6 +8,7 @@
 
 #include <linux/sched.h>
 #include <linux/magic.h>
+#include <linux/refcount.h>
 
 #ifdef CONFIG_THREAD_INFO_IN_TASK
 
Signature · 1 line
2.43.0
#13 lore raw

PATCH 7/50 nsproxy.h: add missing include

In reply to Kent Overstreet
---
 include/linux/nsproxy.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/nsproxy.h +1 -0
index 771cb0285872..5601d14e2886 100644
@@ -2,6 +2,7 @@
 #ifndef _LINUX_NSPROXY_H
 #define _LINUX_NSPROXY_H
 
+#include <linux/refcount.h>
 #include <linux/spinlock.h>
 #include <linux/sched.h>
 
Signature · 1 line
2.43.0
#14 lore raw

PATCH 8/50 kernel/fork.c: add missing include

In reply to Kent Overstreet
---
 kernel/fork.c | 1 +
 1 file changed, 1 insertion(+)
kernel/fork.c +1 -0
index 10917c3e1f03..319e61297bfb 100644
@@ -53,6 +53,7 @@
 #include <linux/seccomp.h>
 #include <linux/swap.h>
 #include <linux/syscalls.h>
+#include <linux/syscall_user_dispatch.h>
 #include <linux/jiffies.h>
 #include <linux/futex.h>
 #include <linux/compat.h>
Signature · 1 line
2.43.0
#15 lore raw

PATCH 9/50 kmsan: add missing types.h dependency

In reply to Kent Overstreet

more header dependency pruning/fixing

---
 include/linux/kmsan_types.h | 2 ++
 1 file changed, 2 insertions(+)
include/linux/kmsan_types.h +2 -0
index 8bfa6c98176d..929287981afe 100644
@@ -9,6 +9,8 @@
 #ifndef _LINUX_KMSAN_TYPES_H
 #define _LINUX_KMSAN_TYPES_H
 
+#include <linux/types.h>
+
 /* These constants are defined in the MSan LLVM instrumentation pass. */
 #define KMSAN_RETVAL_SIZE 800
 #define KMSAN_PARAM_SIZE 800
Signature · 1 line
2.43.0
#16 lore raw

PATCH 10/50 time_namespace.h: fix missing include

In reply to Kent Overstreet
---
 include/linux/time_namespace.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/time_namespace.h +1 -0
index 03d9c5ac01d1..5258d81cef17 100644
@@ -7,6 +7,7 @@
 #include <linux/nsproxy.h>
 #include <linux/ns_common.h>
 #include <linux/err.h>
+#include <linux/time64.h>
 
 struct user_namespace;
 extern struct user_namespace init_user_ns;
Signature · 1 line
2.43.0
#17 lore raw

PATCH 11/50 nodemask: Split out include/linux/nodemask_types.h

In reply to Kent Overstreet

sched.h, which defines task_struct, needs nodemask_t - but sched.h is a frequently used header and ideally shouldn't be pulling in any more code that it needs to.

This splits out nodemask_types.h which has the definition sched.h needs, which will avoid a circular header dependency in the alloc tagging patch series, and as a bonus should speed up kernel build times.

---
 include/linux/nodemask.h       |  2 +-
 include/linux/nodemask_types.h | 10 ++++++++++
 include/linux/sched.h          |  2 +-
 3 files changed, 12 insertions(+), 2 deletions(-)
 create mode 100644 include/linux/nodemask_types.h
include/linux/nodemask.h +1 -1
index 8d07116caaf1..b61438313a73 100644
@@ -93,10 +93,10 @@
 #include <linux/threads.h>
 #include <linux/bitmap.h>
 #include <linux/minmax.h>
+#include <linux/nodemask_types.h>
 #include <linux/numa.h>
 #include <linux/random.h>
 
-typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t;
 extern nodemask_t _unused_nodemask_arg_;
 
 /**
include/linux/nodemask_types.h new file +10 -0
new file mode 100644
index 000000000000..6b28d97ea6ed
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LINUX_NODEMASK_TYPES_H
+#define __LINUX_NODEMASK_TYPES_H
+
+#include <linux/bitops.h>
+#include <linux/numa.h>
+
+typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t;
+
+#endif /* __LINUX_NODEMASK_TYPES_H */
include/linux/sched.h +1 -1
index 292c31697248..5a5b7b122682 100644
@@ -20,7 +20,7 @@
 #include <linux/hrtimer.h>
 #include <linux/irqflags.h>
 #include <linux/seccomp.h>
-#include <linux/nodemask.h>
+#include <linux/nodemask_types.h>
 #include <linux/rcupdate.h>
 #include <linux/refcount.h>
 #include <linux/resource.h>
Signature · 1 line
2.43.0
#18 lore raw

PATCH 12/50 prandom: Remove unused include

prandom.h doesn't use percpu.h - this fixes some circular header issues.

---
 include/linux/prandom.h | 1 -
 1 file changed, 1 deletion(-)
include/linux/prandom.h +0 -1
index f2ed5b72b3d6..f7f1e5251c67 100644
@@ -10,7 +10,6 @@
 
 #include <linux/types.h>
 #include <linux/once.h>
-#include <linux/percpu.h>
 #include <linux/random.h>
 
 struct rnd_state {
Signature · 1 line
2.43.0
#19 lore raw

Re: [PATCH 12/50] prandom: Remove unused include

Quoted 13 lines · Kent Overstreet

prandom.h doesn't use percpu.h - this fixes some circular header issues.

---
 include/linux/prandom.h | 1 -
 1 file changed, 1 deletion(-)
include/linux/prandom.h +0 -0
index f2ed5b72b3d6..f7f1e5251c67 100644

include/linux/prandom.h line 15

Quoted 7 lines
include/linux/prandom.h +0 -1
@@ -10,7 +10,6 @@
 
 #include <linux/types.h>
 #include <linux/once.h>
-#include <linux/percpu.h>
 #include <linux/random.h>
 
 struct rnd_state {

In this header file:

    22	void prandom_seed_full_state(struct rnd_state __percpu *pcpu_state);

so where does it get __percpu from?

Signature · 3 lines
#Randy
https://people.kernel.org/tglx/notes-about-netiquette
https://subspace.kernel.org/etiquette.html
#20 lore raw

Re: [PATCH 12/50] prandom: Remove unused include

Quoted 22 lines · Randy Dunlap
Quoted 19 lines · Kent Overstreet

prandom.h doesn't use percpu.h - this fixes some circular header issues.

---
 include/linux/prandom.h | 1 -
 1 file changed, 1 deletion(-)
include/linux/prandom.h +0 -1
index f2ed5b72b3d6..f7f1e5251c67 100644
@@ -10,7 +10,6 @@
 
 #include <linux/types.h>
 #include <linux/once.h>
-#include <linux/percpu.h>
 #include <linux/random.h>
 
Quoted 7 lines

include/linux/prandom.h line 15

Quoted 1 line
include/linux/prandom.h +0 -0
 struct rnd_state {

In this header file:

    22	void prandom_seed_full_state(struct rnd_state __percpu *pcpu_state);

so where does it get __percpu from?

That comes from compiler.h -> compiler_types.h... cscope :)

#21 lore raw

PATCH 13/50 timekeeping: Kill percpu.h dependency

In reply to Kent Overstreet

Slimming down recursive header includes.

---
 include/linux/hrtimer.h        | 2 +-
 include/linux/time_namespace.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
include/linux/hrtimer.h +1 -1
index f2044d5a652b..02d264ca9dce 100644
@@ -16,7 +16,7 @@
 #include <linux/rbtree.h>
 #include <linux/init.h>
 #include <linux/list.h>
-#include <linux/percpu.h>
+#include <linux/percpu-defs.h>
 #include <linux/seqlock.h>
 #include <linux/timer.h>
 #include <linux/timerqueue.h>
include/linux/time_namespace.h +2 -0
index 5258d81cef17..876e31b4461d 100644
@@ -12,6 +12,8 @@
 struct user_namespace;
 extern struct user_namespace init_user_ns;
 
+struct vm_area_struct;
+
 struct timens_offsets {
 	struct timespec64 monotonic;
 	struct timespec64 boottime;
Signature · 1 line
2.43.0
#22 lore raw

PATCH 14/50 arm64: Fix circular header dependency

In reply to Kent Overstreet

Replace linux/percpu.h include with asm/percpu.h to avoid circular dependency.

---
 arch/arm64/include/asm/spectre.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/include/asm/spectre.h +2 -2
index 06c357d83b13..0c4d9045c31f 100644
@@ -13,8 +13,8 @@
 #define __BP_HARDEN_HYP_VECS_SZ	((BP_HARDEN_EL2_SLOTS - 1) * SZ_2K)
 
 #ifndef __ASSEMBLY__
-
-#include <linux/percpu.h>
+#include <linux/smp.h>
+#include <asm/percpu.h>
 
 #include <asm/cpufeature.h>
 #include <asm/virt.h>
Signature · 1 line
2.43.0
#23 lore raw

PATCH 15/50 kernel/numa.c: Move logging out of numa.h

In reply to Kent Overstreet

Moving these stub functions to a .c file means we can kill a sched.h dependency on printk.h.

---
 include/linux/numa.h | 18 +++++-------------
 kernel/Makefile      |  1 +
 kernel/numa.c        | 24 ++++++++++++++++++++++++
 3 files changed, 30 insertions(+), 13 deletions(-)
 create mode 100644 kernel/numa.c
include/linux/numa.h +5 -13
index a904861de800..aeab3d9f57ae 100644
@@ -22,34 +22,26 @@
 #endif
 
 #ifdef CONFIG_NUMA
-#include <linux/printk.h>
 #include <asm/sparsemem.h>
 
 /* Generic implementation available */
 int numa_nearest_node(int node, unsigned int state);
 
 #ifndef memory_add_physaddr_to_nid
-static inline int memory_add_physaddr_to_nid(u64 start)
-{
-	pr_info_once("Unknown online node for memory at 0x%llx, assuming node 0\n",
-			start);
-	return 0;
-}
+int memory_add_physaddr_to_nid(u64 start);
 #endif
+
 #ifndef phys_to_target_node
-static inline int phys_to_target_node(u64 start)
-{
-	pr_info_once("Unknown target node for memory at 0x%llx, assuming node 0\n",
-			start);
-	return 0;
-}
+int phys_to_target_node(u64 start);
 #endif
+
 #ifndef numa_fill_memblks
 static inline int __init numa_fill_memblks(u64 start, u64 end)
 {
 	return NUMA_NO_MEMBLK;
 }
 #endif
+
 #else /* !CONFIG_NUMA */
 static inline int numa_nearest_node(int node, unsigned int state)
 {
kernel/Makefile +1 -0
index 3947122d618b..ce105a5558fc 100644
@@ -114,6 +114,7 @@ obj-$(CONFIG_SHADOW_CALL_STACK) += scs.o
 obj-$(CONFIG_HAVE_STATIC_CALL) += static_call.o
 obj-$(CONFIG_HAVE_STATIC_CALL_INLINE) += static_call_inline.o
 obj-$(CONFIG_CFI_CLANG) += cfi.o
+obj-$(CONFIG_NUMA) += numa.o
 
 obj-$(CONFIG_PERF_EVENTS) += events/
 
kernel/numa.c new file +24 -0
new file mode 100644
index 000000000000..c24c72f45989
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <linux/printk.h>
+#include <linux/numa.h>
+
+/* Stub functions: */
+
+#ifndef memory_add_physaddr_to_nid
+int memory_add_physaddr_to_nid(u64 start)
+{
+	pr_info_once("Unknown online node for memory at 0x%llx, assuming node 0\n",
+			start);
+	return 0;
+}
+#endif
+
+#ifndef phys_to_target_node
+int phys_to_target_node(u64 start)
+{
+	pr_info_once("Unknown target node for memory at 0x%llx, assuming node 0\n",
+			start);
+	return 0;
+}
+#endif
Signature · 1 line
2.43.0
#24 lore raw

Re: [PATCH 15/50] kernel/numa.c: Move logging out of numa.h

Quoted 100 lines · Kent Overstreet

Moving these stub functions to a .c file means we can kill a sched.h dependency on printk.h.

---
 include/linux/numa.h | 18 +++++-------------
 kernel/Makefile      |  1 +
 kernel/numa.c        | 24 ++++++++++++++++++++++++
 3 files changed, 30 insertions(+), 13 deletions(-)
 create mode 100644 kernel/numa.c
include/linux/numa.h +5 -13
index a904861de800..aeab3d9f57ae 100644
@@ -22,34 +22,26 @@
 #endif
 
 #ifdef CONFIG_NUMA
-#include <linux/printk.h>
 #include <asm/sparsemem.h>
 
 /* Generic implementation available */
 int numa_nearest_node(int node, unsigned int state);
 
 #ifndef memory_add_physaddr_to_nid
-static inline int memory_add_physaddr_to_nid(u64 start)
-{
-	pr_info_once("Unknown online node for memory at 0x%llx, assuming node 0\n",
-			start);
-	return 0;
-}
+int memory_add_physaddr_to_nid(u64 start);
 #endif
+
 #ifndef phys_to_target_node
-static inline int phys_to_target_node(u64 start)
-{
-	pr_info_once("Unknown target node for memory at 0x%llx, assuming node 0\n",
-			start);
-	return 0;
-}
+int phys_to_target_node(u64 start);
 #endif
+
 #ifndef numa_fill_memblks
 static inline int __init numa_fill_memblks(u64 start, u64 end)
 {
 	return NUMA_NO_MEMBLK;
 }
 #endif
+
 #else /* !CONFIG_NUMA */
 static inline int numa_nearest_node(int node, unsigned int state)
 {
kernel/Makefile +1 -0
index 3947122d618b..ce105a5558fc 100644
@@ -114,6 +114,7 @@ obj-$(CONFIG_SHADOW_CALL_STACK) += scs.o
 obj-$(CONFIG_HAVE_STATIC_CALL) += static_call.o
 obj-$(CONFIG_HAVE_STATIC_CALL_INLINE) += static_call_inline.o
 obj-$(CONFIG_CFI_CLANG) += cfi.o
+obj-$(CONFIG_NUMA) += numa.o
 
 obj-$(CONFIG_PERF_EVENTS) += events/
 
kernel/numa.c new file +24 -0
new file mode 100644
index 000000000000..c24c72f45989
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <linux/printk.h>
+#include <linux/numa.h>
+
+/* Stub functions: */
+
+#ifndef memory_add_physaddr_to_nid
+int memory_add_physaddr_to_nid(u64 start)
+{
+	pr_info_once("Unknown online node for memory at 0x%llx, assuming node 0\n",
+			start);
+	return 0;
+}
+#endif
+
+#ifndef phys_to_target_node
+int phys_to_target_node(u64 start)
+{
+	pr_info_once("Unknown target node for memory at 0x%llx, assuming node 0\n",
+			start);
+	return 0;
+}
+#endif
Signature · 1 line
2.43.0

These need EXPORT_SYMBOL_GPL() now like the architecture specific implementations because they are no longer inlined. My arm64 builds fail with:

ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/acpi/nfit/nfit.ko] undefined!
ERROR: modpost: "phys_to_target_node" [drivers/acpi/nfit/nfit.ko] undefined!
ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/virtio/virtio_mem.ko] undefined!
ERROR: modpost: "phys_to_target_node" [drivers/dax/dax_cxl.ko] undefined!
ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/dax/dax_cxl.ko] undefined!
ERROR: modpost: "phys_to_target_node" [drivers/cxl/cxl_acpi.ko] undefined!
ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/cxl/cxl_pmem.ko] undefined!
ERROR: modpost: "phys_to_target_node" [drivers/cxl/cxl_pmem.ko] undefined!
ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/hv/hv_balloon.ko] undefined!

Cheers,
Nathan

#25 lore raw

Re: [PATCH 15/50] kernel/numa.c: Move logging out of numa.h

Quoted 5 lines · Nathan Chancellor

On Fri, Dec 15, 2023 at 10:26:14PM -0500, Kent Overstreet wrote:
These need EXPORT_SYMBOL_GPL() now like the architecture specific implementations because they are no longer inlined. My arm64 builds fail with:

Quoted 9 lines

ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/acpi/nfit/nfit.ko] undefined!
ERROR: modpost: "phys_to_target_node" [drivers/acpi/nfit/nfit.ko] undefined!
ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/virtio/virtio_mem.ko] undefined!
ERROR: modpost: "phys_to_target_node" [drivers/dax/dax_cxl.ko] undefined!
ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/dax/dax_cxl.ko] undefined!
ERROR: modpost: "phys_to_target_node" [drivers/cxl/cxl_acpi.ko] undefined!
ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/cxl/cxl_pmem.ko] undefined!
ERROR: modpost: "phys_to_target_node" [drivers/cxl/cxl_pmem.ko] undefined!
ERROR: modpost: "memory_add_physaddr_to_nid" [drivers/hv/hv_balloon.ko] undefined!

Applied the following:

commit 7ae175e405b44b9897c04bbf177e3e08ab25710a

Author: Kent Overstreet <[email protected]>
Date:   Tue Dec 19 16:02:26 2023 -0500

fixup! kernel/numa.c: Move logging out of numa.h

kernel/numa.c +2 -0
index c24c72f45989..67ca6b8585c0 100644
@@ -12,6 +12,7 @@ int memory_add_physaddr_to_nid(u64 start)
 			start);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
 #endif
 
 #ifndef phys_to_target_node
@@ -21,4 +22,5 @@ int phys_to_target_node(u64 start)
 			start);
 	return 0;
 }
+EXPORT_SYMBOL_GPL(phys_to_target_node);
 #endif
#26 lore raw

Re: [PATCH 15/50] kernel/numa.c: Move logging out of numa.h

In reply to Kent Overstreet

kernel/numa.c

Quoted 5 lines · Kent Overstreet
kernel/numa.c new file +0 -0
new file mode 100644
index 000000000000..c24c72f45989

Should this be a new file or would these functions fit better in, eg, mempolicy.c which is already built only if CONFIG_NUMA?

#27 lore raw

Re: [PATCH 15/50] kernel/numa.c: Move logging out of numa.h

Quoted 9 lines · Matthew Wilcox

kernel/numa.c

Quoted 5 lines · Kent Overstreet
kernel/numa.c new file +0 -0
new file mode 100644
index 000000000000..c24c72f45989

Should this be a new file or would these functions fit better in, eg, mempolicy.c which is already built only if CONFIG_NUMA?

that does look like a bit of a disorganized dumping ground though, I wonder if anyone would want to start mm/numa/ and do a bit of organizing?

#28 lore raw

PATCH 16/50 sched.h: Move (spin|rwlock)_needbreak() to spinlock.h

In reply to Kent Overstreet

This lets us kill the dependency on spinlock.h.

---
 include/linux/sched.h    | 31 -------------------------------
 include/linux/spinlock.h | 31 +++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 31 deletions(-)
include/linux/sched.h +0 -31
index 5a5b7b122682..7501a3451a20 100644
@@ -2227,37 +2227,6 @@ static inline bool preempt_model_preemptible(void)
 	return preempt_model_full() || preempt_model_rt();
 }
 
-/*
- * Does a critical section need to be broken due to another
- * task waiting?: (technically does not depend on CONFIG_PREEMPTION,
- * but a general need for low latency)
- */
-static inline int spin_needbreak(spinlock_t *lock)
-{
-#ifdef CONFIG_PREEMPTION
-	return spin_is_contended(lock);
-#else
-	return 0;
-#endif
-}
-
-/*
- * Check if a rwlock is contended.
- * Returns non-zero if there is another task waiting on the rwlock.
- * Returns zero if the lock is not contended or the system / underlying
- * rwlock implementation does not support contention detection.
- * Technically does not depend on CONFIG_PREEMPTION, but a general need
- * for low latency.
- */
-static inline int rwlock_needbreak(rwlock_t *lock)
-{
-#ifdef CONFIG_PREEMPTION
-	return rwlock_is_contended(lock);
-#else
-	return 0;
-#endif
-}
-
 static __always_inline bool need_resched(void)
 {
 	return unlikely(tif_need_resched());
include/linux/spinlock.h +31 -0
index 31d3d747a9db..0c71f06454d9 100644
@@ -449,6 +449,37 @@ static __always_inline int spin_is_contended(spinlock_t *lock)
 	return raw_spin_is_contended(&lock->rlock);
 }
 
+/*
+ * Does a critical section need to be broken due to another
+ * task waiting?: (technically does not depend on CONFIG_PREEMPTION,
+ * but a general need for low latency)
+ */
+static inline int spin_needbreak(spinlock_t *lock)
+{
+#ifdef CONFIG_PREEMPTION
+	return spin_is_contended(lock);
+#else
+	return 0;
+#endif
+}
+
+/*
+ * Check if a rwlock is contended.
+ * Returns non-zero if there is another task waiting on the rwlock.
+ * Returns zero if the lock is not contended or the system / underlying
+ * rwlock implementation does not support contention detection.
+ * Technically does not depend on CONFIG_PREEMPTION, but a general need
+ * for low latency.
+ */
+static inline int rwlock_needbreak(rwlock_t *lock)
+{
+#ifdef CONFIG_PREEMPTION
+	return rwlock_is_contended(lock);
+#else
+	return 0;
+#endif
+}
+
 #define assert_spin_locked(lock)	assert_raw_spin_locked(&(lock)->rlock)
 
 #else  /* !CONFIG_PREEMPT_RT */
Signature · 1 line
2.43.0
#29 lore raw

Re: [PATCH 16/50] sched.h: Move (spin|rwlock)_needbreak() to spinlock.h

Quoted 94 lines · Kent Overstreet

This lets us kill the dependency on spinlock.h.

---
 include/linux/sched.h    | 31 -------------------------------
 include/linux/spinlock.h | 31 +++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 31 deletions(-)
include/linux/sched.h +0 -31
index 5a5b7b122682..7501a3451a20 100644
@@ -2227,37 +2227,6 @@ static inline bool preempt_model_preemptible(void)
 	return preempt_model_full() || preempt_model_rt();
 }
 
-/*
- * Does a critical section need to be broken due to another
- * task waiting?: (technically does not depend on CONFIG_PREEMPTION,
- * but a general need for low latency)
- */
-static inline int spin_needbreak(spinlock_t *lock)
-{
-#ifdef CONFIG_PREEMPTION
-	return spin_is_contended(lock);
-#else
-	return 0;
-#endif
-}
-
-/*
- * Check if a rwlock is contended.
- * Returns non-zero if there is another task waiting on the rwlock.
- * Returns zero if the lock is not contended or the system / underlying
- * rwlock implementation does not support contention detection.
- * Technically does not depend on CONFIG_PREEMPTION, but a general need
- * for low latency.
- */
-static inline int rwlock_needbreak(rwlock_t *lock)
-{
-#ifdef CONFIG_PREEMPTION
-	return rwlock_is_contended(lock);
-#else
-	return 0;
-#endif
-}
-
 static __always_inline bool need_resched(void)
 {
 	return unlikely(tif_need_resched());
include/linux/spinlock.h +31 -0
index 31d3d747a9db..0c71f06454d9 100644
@@ -449,6 +449,37 @@ static __always_inline int spin_is_contended(spinlock_t *lock)
 	return raw_spin_is_contended(&lock->rlock);
 }
 
+/*
+ * Does a critical section need to be broken due to another
+ * task waiting?: (technically does not depend on CONFIG_PREEMPTION,
+ * but a general need for low latency)
+ */
+static inline int spin_needbreak(spinlock_t *lock)
+{
+#ifdef CONFIG_PREEMPTION
+	return spin_is_contended(lock);
+#else
+	return 0;
+#endif
+}
+
+/*
+ * Check if a rwlock is contended.
+ * Returns non-zero if there is another task waiting on the rwlock.
+ * Returns zero if the lock is not contended or the system / underlying
+ * rwlock implementation does not support contention detection.
+ * Technically does not depend on CONFIG_PREEMPTION, but a general need
+ * for low latency.
+ */
+static inline int rwlock_needbreak(rwlock_t *lock)
+{
+#ifdef CONFIG_PREEMPTION
+	return rwlock_is_contended(lock);
+#else
+	return 0;
+#endif
+}
+
 #define assert_spin_locked(lock)	assert_raw_spin_locked(&(lock)->rlock)
 
 #else  /* !CONFIG_PREEMPT_RT */
Signature · 1 line
2.43.0

Hello Kent,

This patch is breaking PREEMPT_RT builds, but it can be easily fixed.

I sent a patch on the fix, please take a look:
https://lore.kernel.org/all/[email protected]/

Thanks!
Leo

#30 lore raw

PATCH 17/50 ktime.h: move ktime_t to types.h

In reply to Kent Overstreet

ktime.h pulls in quite a few headers recursively (including printk.h) - this is going to help with trimming sched.h dependencies.

---
 include/linux/ktime.h | 8 +++-----
 include/linux/types.h | 3 +++
 2 files changed, 6 insertions(+), 5 deletions(-)
include/linux/ktime.h +3 -5
index 73f20deb497d..3a4e723eae0f 100644
@@ -21,12 +21,10 @@
 #ifndef _LINUX_KTIME_H
 #define _LINUX_KTIME_H
 
-#include <linux/time.h>
-#include <linux/jiffies.h>
 #include <asm/bug.h>
-
-/* Nanosecond scalar representation for kernel time values */
-typedef s64	ktime_t;
+#include <linux/jiffies.h>
+#include <linux/time.h>
+#include <linux/types.h>
 
 /**
  * ktime_set - Set a ktime_t variable from a seconds/nanoseconds value
include/linux/types.h +3 -0
index 253168bb3fe1..2bc8766ba20c 100644
@@ -120,6 +120,9 @@ typedef s64			int64_t;
 #define aligned_be64		__aligned_be64
 #define aligned_le64		__aligned_le64
 
+/* Nanosecond scalar representation for kernel time values */
+typedef s64	ktime_t;
+
 /**
  * The type used for indexing onto a disc or disc partition.
  *
Signature · 1 line
2.43.0
#31 lore raw

PATCH 18/50 hrtimers: Split out hrtimer_types.h

In reply to Kent Overstreet

We need to reduce the scope of what's included in sched.h: task_struct includes a hrtimer, so split out the core types into their own header.

---
 include/linux/hrtimer.h       | 44 ++----------------------------
 include/linux/hrtimer_types.h | 50 +++++++++++++++++++++++++++++++++++
 include/linux/sched.h         |  2 +-
 3 files changed, 53 insertions(+), 43 deletions(-)
 create mode 100644 include/linux/hrtimer_types.h
include/linux/hrtimer.h +2 -42
index 02d264ca9dce..87e3bedf8eb0 100644
@@ -13,13 +13,13 @@
 #define _LINUX_HRTIMER_H
 
 #include <linux/hrtimer_defs.h>
-#include <linux/rbtree.h>
+#include <linux/hrtimer_types.h>
 #include <linux/init.h>
 #include <linux/list.h>
 #include <linux/percpu-defs.h>
+#include <linux/rbtree.h>
 #include <linux/seqlock.h>
 #include <linux/timer.h>
-#include <linux/timerqueue.h>
 
 struct hrtimer_clock_base;
 struct hrtimer_cpu_base;
@@ -59,14 +59,6 @@ enum hrtimer_mode {
 	HRTIMER_MODE_REL_PINNED_HARD = HRTIMER_MODE_REL_PINNED | HRTIMER_MODE_HARD,
 };
 
-/*
- * Return values for the callback function
- */
-enum hrtimer_restart {
-	HRTIMER_NORESTART,	/* Timer is not restarted */
-	HRTIMER_RESTART,	/* Timer must be restarted */
-};
-
 /*
  * Values to track state of the timer
  *
@@ -94,38 +86,6 @@ enum hrtimer_restart {
 #define HRTIMER_STATE_INACTIVE	0x00
 #define HRTIMER_STATE_ENQUEUED	0x01
 
-/**
- * struct hrtimer - the basic hrtimer structure
- * @node:	timerqueue node, which also manages node.expires,
- *		the absolute expiry time in the hrtimers internal
- *		representation. The time is related to the clock on
- *		which the timer is based. Is setup by adding
- *		slack to the _softexpires value. For non range timers
- *		identical to _softexpires.
- * @_softexpires: the absolute earliest expiry time of the hrtimer.
- *		The time which was given as expiry time when the timer
- *		was armed.
- * @function:	timer expiry callback function
- * @base:	pointer to the timer base (per cpu and per clock)
- * @state:	state information (See bit values above)
- * @is_rel:	Set if the timer was armed relative
- * @is_soft:	Set if hrtimer will be expired in soft interrupt context.
- * @is_hard:	Set if hrtimer will be expired in hard interrupt context
- *		even on RT.
- *
- * The hrtimer structure must be initialized by hrtimer_init()
- */
-struct hrtimer {
-	struct timerqueue_node		node;
-	ktime_t				_softexpires;
-	enum hrtimer_restart		(*function)(struct hrtimer *);
-	struct hrtimer_clock_base	*base;
-	u8				state;
-	u8				is_rel;
-	u8				is_soft;
-	u8				is_hard;
-};
-
 /**
  * struct hrtimer_sleeper - simple sleeper structure
  * @timer:	embedded timer structure
include/linux/hrtimer_types.h new file +50 -0

50 lines not on this page · raw message

include/linux/sched.h +1 -1
index 7501a3451a20..3762809652da 100644
@@ -17,7 +17,7 @@
 #include <linux/kmsan_types.h>
 #include <linux/mutex.h>
 #include <linux/plist.h>
-#include <linux/hrtimer.h>
+#include <linux/hrtimer_types.h>
 #include <linux/irqflags.h>
 #include <linux/seccomp.h>
 #include <linux/nodemask_types.h>
Signature · 1 line
2.43.0
#32 lore raw

PATCH 19/50 locking/mutex: split out mutex_types.h

In reply to Kent Overstreet

Trimming down sched.h dependencies: we don't want to include more than the base types.

Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Will Deacon <[email protected]>
Cc Waiman Long <[email protected]>
Cc Boqun Feng <[email protected]>
---
 include/linux/mutex.h       | 52 +--------------------------
 include/linux/mutex_types.h | 71 +++++++++++++++++++++++++++++++++++++
 include/linux/sched.h       |  2 +-
 3 files changed, 73 insertions(+), 52 deletions(-)
 create mode 100644 include/linux/mutex_types.h
include/linux/mutex.h +1 -51
index a33aa9eb9fc3..0dfba5df6524 100644
@@ -20,6 +20,7 @@
 #include <linux/osq_lock.h>
 #include <linux/debug_locks.h>
 #include <linux/cleanup.h>
+#include <linux/mutex_types.h>
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 # define __DEP_MAP_MUTEX_INITIALIZER(lockname)			\
@@ -33,49 +34,6 @@
 
 #ifndef CONFIG_PREEMPT_RT
 
-/*
- * Simple, straightforward mutexes with strict semantics:
- *
- * - only one task can hold the mutex at a time
- * - only the owner can unlock the mutex
- * - multiple unlocks are not permitted
- * - recursive locking is not permitted
- * - a mutex object must be initialized via the API
- * - a mutex object must not be initialized via memset or copying
- * - task may not exit with mutex held
- * - memory areas where held locks reside must not be freed
- * - held mutexes must not be reinitialized
- * - mutexes may not be used in hardware or software interrupt
- *   contexts such as tasklets and timers
- *
- * These semantics are fully enforced when DEBUG_MUTEXES is
- * enabled. Furthermore, besides enforcing the above rules, the mutex
- * debugging code also implements a number of additional features
- * that make lock debugging easier and faster:
- *
- * - uses symbolic names of mutexes, whenever they are printed in debug output
- * - point-of-acquire tracking, symbolic lookup of function names
- * - list of all locks held in the system, printout of them
- * - owner tracking
- * - detects self-recursing locks and prints out all relevant info
- * - detects multi-task circular deadlocks and prints out all affected
- *   locks and tasks (and only those tasks)
- */
-struct mutex {
-	atomic_long_t		owner;
-	raw_spinlock_t		wait_lock;
-#ifdef CONFIG_MUTEX_SPIN_ON_OWNER
-	struct optimistic_spin_queue osq; /* Spinner MCS lock */
-#endif
-	struct list_head	wait_list;
-#ifdef CONFIG_DEBUG_MUTEXES
-	void			*magic;
-#endif
-#ifdef CONFIG_DEBUG_LOCK_ALLOC
-	struct lockdep_map	dep_map;
-#endif
-};
-
 #ifdef CONFIG_DEBUG_MUTEXES
 
 #define __DEBUG_MUTEX_INITIALIZER(lockname)				\
@@ -131,14 +89,6 @@ extern bool mutex_is_locked(struct mutex *lock);
 /*
  * Preempt-RT variant based on rtmutexes.
  */
-#include <linux/rtmutex.h>
-
-struct mutex {
-	struct rt_mutex_base	rtmutex;
-#ifdef CONFIG_DEBUG_LOCK_ALLOC
-	struct lockdep_map	dep_map;
-#endif
-};
 
 #define __MUTEX_INITIALIZER(mutexname)					\
 {									\
include/linux/mutex_types.h new file +71 -0

71 lines not on this page · raw message

include/linux/sched.h +1 -1
index 3762809652da..e8892789969b 100644
@@ -15,7 +15,7 @@
 #include <linux/sem.h>
 #include <linux/shm.h>
 #include <linux/kmsan_types.h>
-#include <linux/mutex.h>
+#include <linux/mutex_types.h>
 #include <linux/plist.h>
 #include <linux/hrtimer_types.h>
 #include <linux/irqflags.h>
Signature · 1 line
2.43.0
reviewer
#33 lore raw

Re: [PATCH 19/50] locking/mutex: split out mutex_types.h

Quoted 80 lines · Kent Overstreet

Trimming down sched.h dependencies: we don't want to include more than the base types.

Cc Peter Zijlstra<[email protected]>
Cc Ingo Molnar<[email protected]>
Cc Will Deacon<[email protected]>
Cc Waiman Long<[email protected]>
Cc Boqun Feng<[email protected]>
---
  include/linux/mutex.h       | 52 +--------------------------
  include/linux/mutex_types.h | 71 +++++++++++++++++++++++++++++++++++++
  include/linux/sched.h       |  2 +-
  3 files changed, 73 insertions(+), 52 deletions(-)

create mode 100644 include/linux/mutex_types.h

include/linux/mutex.h +1 -43
index a33aa9eb9fc3..0dfba5df6524 100644
@@ -20,6 +20,7 @@
  #include <linux/osq_lock.h>
  #include <linux/debug_locks.h>
  #include <linux/cleanup.h>
+#include <linux/mutex_types.h>
 
  #ifdef CONFIG_DEBUG_LOCK_ALLOC
  # define __DEP_MAP_MUTEX_INITIALIZER(lockname)			\
@@ -33,49 +34,6 @@
 
  #ifndef CONFIG_PREEMPT_RT
 
-/*
- * Simple, straightforward mutexes with strict semantics:
- *
- * - only one task can hold the mutex at a time
- * - only the owner can unlock the mutex
- * - multiple unlocks are not permitted
- * - recursive locking is not permitted
- * - a mutex object must be initialized via the API
- * - a mutex object must not be initialized via memset or copying
- * - task may not exit with mutex held
- * - memory areas where held locks reside must not be freed
- * - held mutexes must not be reinitialized
- * - mutexes may not be used in hardware or software interrupt
- *   contexts such as tasklets and timers
- *
- * These semantics are fully enforced when DEBUG_MUTEXES is
- * enabled. Furthermore, besides enforcing the above rules, the mutex
- * debugging code also implements a number of additional features
- * that make lock debugging easier and faster:
- *
- * - uses symbolic names of mutexes, whenever they are printed in debug output
- * - point-of-acquire tracking, symbolic lookup of function names
- * - list of all locks held in the system, printout of them
- * - owner tracking
- * - detects self-recursing locks and prints out all relevant info
- * - detects multi-task circular deadlocks and prints out all affected
- *   locks and tasks (and only those tasks)
- */
-struct mutex {
-	atomic_long_t		owner;
-	raw_spinlock_t		wait_lock;
-#ifdef CONFIG_MUTEX_SPIN_ON_OWNER
-	struct optimistic_spin_queue osq; /* Spinner MCS lock */
-#endif
-	struct list_head	wait_list;
-#ifdef CONFIG_DEBUG_MUTEXES
-	void			*magic;
-#endif
-#ifdef CONFIG_DEBUG_LOCK_ALLOC
-	struct lockdep_map	dep_map;
-#endif
-};
-
  #ifdef CONFIG_DEBUG_MUTEXES
 
  #define __DEBUG_MUTEX_INITIALIZER(lockname)				\

include/linux/mutex.h extern bool mutex_is_locked(struct mutex *lock); · line 134

Quoted 4 lines
include/linux/mutex.h +0 -1
@@ -131,14 +89,6 @@ extern bool mutex_is_locked(struct mutex *lock);
  /*
   * Preempt-RT variant based on rtmutexes.
   */
-#include <linux/rtmutex.h>

Including rtmutex.h here means that mutex_types.h is no longer a simple header for types only. So unless you also break out a rtmutex_types.h, it is inconsistent.

Besides, the kernel/sched code does use mutex_lock/unlock calls quite frequently. With this patch, mutex.h will not be directly included. I suspect that it is indirectly included via other header files. This may be an issue with some configurations.

Cheers, Longman

reviewer
#34 lore raw

Re: [PATCH 19/50] locking/mutex: split out mutex_types.h

Quoted 80 lines · Kent Overstreet

Trimming down sched.h dependencies: we don't want to include more than the base types.

Cc Peter Zijlstra<[email protected]>
Cc Ingo Molnar<[email protected]>
Cc Will Deacon<[email protected]>
Cc Waiman Long<[email protected]>
Cc Boqun Feng<[email protected]>
---
  include/linux/mutex.h       | 52 +--------------------------
  include/linux/mutex_types.h | 71 +++++++++++++++++++++++++++++++++++++
  include/linux/sched.h       |  2 +-
  3 files changed, 73 insertions(+), 52 deletions(-)

create mode 100644 include/linux/mutex_types.h

include/linux/mutex.h +1 -43
index a33aa9eb9fc3..0dfba5df6524 100644
@@ -20,6 +20,7 @@
  #include <linux/osq_lock.h>
  #include <linux/debug_locks.h>
  #include <linux/cleanup.h>
+#include <linux/mutex_types.h>
 
  #ifdef CONFIG_DEBUG_LOCK_ALLOC
  # define __DEP_MAP_MUTEX_INITIALIZER(lockname)			\
@@ -33,49 +34,6 @@
 
  #ifndef CONFIG_PREEMPT_RT
 
-/*
- * Simple, straightforward mutexes with strict semantics:
- *
- * - only one task can hold the mutex at a time
- * - only the owner can unlock the mutex
- * - multiple unlocks are not permitted
- * - recursive locking is not permitted
- * - a mutex object must be initialized via the API
- * - a mutex object must not be initialized via memset or copying
- * - task may not exit with mutex held
- * - memory areas where held locks reside must not be freed
- * - held mutexes must not be reinitialized
- * - mutexes may not be used in hardware or software interrupt
- *   contexts such as tasklets and timers
- *
- * These semantics are fully enforced when DEBUG_MUTEXES is
- * enabled. Furthermore, besides enforcing the above rules, the mutex
- * debugging code also implements a number of additional features
- * that make lock debugging easier and faster:
- *
- * - uses symbolic names of mutexes, whenever they are printed in debug output
- * - point-of-acquire tracking, symbolic lookup of function names
- * - list of all locks held in the system, printout of them
- * - owner tracking
- * - detects self-recursing locks and prints out all relevant info
- * - detects multi-task circular deadlocks and prints out all affected
- *   locks and tasks (and only those tasks)
- */
-struct mutex {
-	atomic_long_t		owner;
-	raw_spinlock_t		wait_lock;
-#ifdef CONFIG_MUTEX_SPIN_ON_OWNER
-	struct optimistic_spin_queue osq; /* Spinner MCS lock */
-#endif
-	struct list_head	wait_list;
-#ifdef CONFIG_DEBUG_MUTEXES
-	void			*magic;
-#endif
-#ifdef CONFIG_DEBUG_LOCK_ALLOC
-	struct lockdep_map	dep_map;
-#endif
-};
-
  #ifdef CONFIG_DEBUG_MUTEXES
 
  #define __DEBUG_MUTEX_INITIALIZER(lockname)				\

include/linux/mutex.h extern bool mutex_is_locked(struct mutex *lock); · line 134

Quoted 4 lines
include/linux/mutex.h +0 -1
@@ -131,14 +89,6 @@ extern bool mutex_is_locked(struct mutex *lock);
  /*
   * Preempt-RT variant based on rtmutexes.
   */
-#include <linux/rtmutex.h>

Including rtmutex.h here means that mutex_types.h is no longer a simple header for types only. So unless you also break out a rtmutex_types.h, it is inconsistent.

Besides, the kernel/sched code does use mutex_lock/unlock calls quite frequently. With this patch, mutex.h will not be directly included. I suspect that it is indirectly included via other header files. This may be an issue with some configurations.

Cheers, Longman

#35 lore raw

Re: [PATCH 19/50] locking/mutex: split out mutex_types.h

In reply to Waiman Long
Quoted 6 lines · Waiman Long
Quoted 1 line · Kent Overstreet

-#include <linux/rtmutex.h>

Including rtmutex.h here means that mutex_types.h is no longer a simple header for types only. So unless you also break out a rtmutex_types.h, it is inconsistent.

good observation, I'll have to leave it for the next round of cleanups though since the merge window is approaching and I'll have to redo all the testing.

Quoted 4 lines

Besides, the kernel/sched code does use mutex_lock/unlock calls quite frequently. With this patch, mutex.h will not be directly included. I suspect that it is indirectly included via other header files. This may be an issue with some configurations.

I've now put it through randconfig testing on every arch that debian includes a compiler for (excluding sh and xtensa, which throw internal compiler errors) and that one hasn't come up yet.

could still be included indirectly though - I haven't checked for that one specifically yet.

reviewer
#36 lore raw

Re: [PATCH 19/50] locking/mutex: split out mutex_types.h

Quoted 14 lines · Kent Overstreet
Quoted 5 lines · Waiman Long
Quoted 1 line · Kent Overstreet

-#include <linux/rtmutex.h>

Including rtmutex.h here means that mutex_types.h is no longer a simple header for types only. So unless you also break out a rtmutex_types.h, it is inconsistent.

good observation, I'll have to leave it for the next round of cleanups though since the merge window is approaching and I'll have to redo all the testing.

Quoted 4 lines

Besides, the kernel/sched code does use mutex_lock/unlock calls quite frequently. With this patch, mutex.h will not be directly included. I suspect that it is indirectly included via other header files. This may be an issue with some configurations.

Quoted 6 lines

I've now put it through randconfig testing on every arch that debian includes a compiler for (excluding sh and xtensa, which throw internal compiler errors) and that one hasn't come up yet.

could still be included indirectly though - I haven't checked for that one specifically yet.

If you are replacing mutex.h in include/linux/sched.h by mutex_types.h, I would suggest you add mutex.h to kernel/sched/sched.h to ensure this header file is included by the scheduler code.

Cheers,
Longman

#37 lore raw

Re: [PATCH 19/50] locking/mutex: split out mutex_types.h

Quoted 20 lines · Waiman Long
Quoted 18 lines · Kent Overstreet
Quoted 5 lines · Waiman Long
Quoted 1 line · Kent Overstreet

-#include <linux/rtmutex.h>

Including rtmutex.h here means that mutex_types.h is no longer a simple header for types only. So unless you also break out a rtmutex_types.h, it is inconsistent.

good observation, I'll have to leave it for the next round of cleanups though since the merge window is approaching and I'll have to redo all the testing.

Quoted 4 lines

Besides, the kernel/sched code does use mutex_lock/unlock calls quite frequently. With this patch, mutex.h will not be directly included. I suspect that it is indirectly included via other header files. This may be an issue with some configurations.

I've now put it through randconfig testing on every arch that debian includes a compiler for (excluding sh and xtensa, which throw internal compiler errors) and that one hasn't come up yet.

Quoted 6 lines
Quoted 2 lines

could still be included indirectly though - I haven't checked for that one specifically yet.

If you are replacing mutex.h in include/linux/sched.h by mutex_types.h, I would suggest you add mutex.h to kernel/sched/sched.h to ensure this header file is included by the scheduler code.

It already does, via mutex_api.h...

reviewer
#38 lore raw

Re: [PATCH 19/50] locking/mutex: split out mutex_types.h

Quoted 20 lines · Kent Overstreet
Quoted 19 lines · Waiman Long
Quoted 18 lines · Kent Overstreet
Quoted 5 lines · Waiman Long
Quoted 1 line · Kent Overstreet

-#include <linux/rtmutex.h>

Including rtmutex.h here means that mutex_types.h is no longer a simple header for types only. So unless you also break out a rtmutex_types.h, it is inconsistent.

good observation, I'll have to leave it for the next round of cleanups though since the merge window is approaching and I'll have to redo all the testing.

Quoted 4 lines

Besides, the kernel/sched code does use mutex_lock/unlock calls quite frequently. With this patch, mutex.h will not be directly included. I suspect that it is indirectly included via other header files. This may be an issue with some configurations.

I've now put it through randconfig testing on every arch that debian includes a compiler for (excluding sh and xtensa, which throw internal compiler errors) and that one hasn't come up yet.

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

could still be included indirectly though - I haven't checked for that one specifically yet.

If you are replacing mutex.h in include/linux/sched.h by mutex_types.h, I would suggest you add mutex.h to kernel/sched/sched.h to ensure this header file is included by the scheduler code.

It already does, via mutex_api.h...

You are right. I am not aware that there is a mutex_api.h header file which is just an alias of mutex.h.

Cheers,
Longman

#39 lore raw

PATCH 20/50 posix-cpu-timers: Split out posix-timers_types.h

In reply to Kent Overstreet

Trimming down sched.h dependencies: we don't want to include more than the base types.

---
 include/linux/posix-timers.h       | 68 ++--------------------------
 include/linux/posix-timers_types.h | 72 ++++++++++++++++++++++++++++++
 include/linux/sched.h              |  2 +-
 3 files changed, 76 insertions(+), 66 deletions(-)
 create mode 100644 include/linux/posix-timers_types.h
include/linux/posix-timers.h +3 -65
index d607f51404fc..750b0647258d 100644
@@ -2,40 +2,16 @@
 #ifndef _linux_POSIX_TIMERS_H
 #define _linux_POSIX_TIMERS_H
 
-#include <linux/spinlock.h>
+#include <linux/alarmtimer.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
-#include <linux/alarmtimer.h>
+#include <linux/posix-timers_types.h>
+#include <linux/spinlock.h>
 #include <linux/timerqueue.h>
 
 struct kernel_siginfo;
 struct task_struct;
 
-/*
- * Bit fields within a clockid:
- *
- * The most significant 29 bits hold either a pid or a file descriptor.
- *
- * Bit 2 indicates whether a cpu clock refers to a thread or a process.
- *
- * Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3.
- *
- * A clockid is invalid if bits 2, 1, and 0 are all set.
- */
-#define CPUCLOCK_PID(clock)		((pid_t) ~((clock) >> 3))
-#define CPUCLOCK_PERTHREAD(clock) \
-	(((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0)
-
-#define CPUCLOCK_PERTHREAD_MASK	4
-#define CPUCLOCK_WHICH(clock)	((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK)
-#define CPUCLOCK_CLOCK_MASK	3
-#define CPUCLOCK_PROF		0
-#define CPUCLOCK_VIRT		1
-#define CPUCLOCK_SCHED		2
-#define CPUCLOCK_MAX		3
-#define CLOCKFD			CPUCLOCK_MAX
-#define CLOCKFD_MASK		(CPUCLOCK_PERTHREAD_MASK|CPUCLOCK_CLOCK_MASK)
-
 static inline clockid_t make_process_cpuclock(const unsigned int pid,
 		const clockid_t clock)
 {
@@ -109,44 +85,6 @@ static inline void cpu_timer_setexpires(struct cpu_timer *ctmr, u64 exp)
 	ctmr->node.expires = exp;
 }
 
-/**
- * posix_cputimer_base - Container per posix CPU clock
- * @nextevt:		Earliest-expiration cache
- * @tqhead:		timerqueue head for cpu_timers
- */
-struct posix_cputimer_base {
-	u64			nextevt;
-	struct timerqueue_head	tqhead;
-};
-
-/**
- * posix_cputimers - Container for posix CPU timer related data
- * @bases:		Base container for posix CPU clocks
- * @timers_active:	Timers are queued.
- * @expiry_active:	Timer expiry is active. Used for
- *			process wide timers to avoid multiple
- *			task trying to handle expiry concurrently
- *
- * Used in task_struct and signal_struct
- */
-struct posix_cputimers {
-	struct posix_cputimer_base	bases[CPUCLOCK_MAX];
-	unsigned int			timers_active;
-	unsigned int			expiry_active;
-};
-
-/**
- * posix_cputimers_work - Container for task work based posix CPU timer expiry
- * @work:	The task work to be scheduled
- * @mutex:	Mutex held around expiry in context of this task work
- * @scheduled:  @work has been scheduled already, no further processing
- */
-struct posix_cputimers_work {
-	struct callback_head	work;
-	struct mutex		mutex;
-	unsigned int		scheduled;
-};
-
 static inline void posix_cputimers_init(struct posix_cputimers *pct)
 {
 	memset(pct, 0, sizeof(*pct));
include/linux/posix-timers_types.h new file +72 -0

72 lines not on this page · raw message

include/linux/sched.h +1 -1
index e8892789969b..6d803d0904d9 100644
@@ -31,7 +31,7 @@
 #include <linux/syscall_user_dispatch.h>
 #include <linux/mm_types_task.h>
 #include <linux/task_io_accounting.h>
-#include <linux/posix-timers.h>
+#include <linux/posix-timers_types.h>
 #include <linux/rseq.h>
 #include <linux/seqlock.h>
 #include <linux/kcsan.h>
Signature · 1 line
2.43.0
#40 lore raw

PATCH 21/50 locking/seqlock: Split out seqlock_types.h

In reply to Kent Overstreet

Trimming down sched.h dependencies: we don't want to include more than the base types.

Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Will Deacon <[email protected]>
Cc Waiman Long <[email protected]>
Cc Boqun Feng <[email protected]>
---
 include/linux/sched.h         |  2 +-
 include/linux/seqlock.h       | 79 +----------------------------
 include/linux/seqlock_types.h | 93 +++++++++++++++++++++++++++++++++++
 3 files changed, 96 insertions(+), 78 deletions(-)
 create mode 100644 include/linux/seqlock_types.h
include/linux/sched.h +1 -1
index 6d803d0904d9..436f7ce1450a 100644
@@ -33,7 +33,7 @@
 #include <linux/task_io_accounting.h>
 #include <linux/posix-timers_types.h>
 #include <linux/rseq.h>
-#include <linux/seqlock.h>
+#include <linux/seqlock_types.h>
 #include <linux/kcsan.h>
 #include <linux/rv.h>
 #include <linux/livepatch_sched.h>
include/linux/seqlock.h +2 -77

115 lines not on this page · raw message

include/linux/seqlock_types.h new file +93 -0

93 lines not on this page · raw message

Signature · 1 line
2.43.0
reviewer Acked-by on v1 21/50
#41 lore raw

Re: [PATCH 21/50] locking/seqlock: Split out seqlock_types.h

Quoted 243 lines · Kent Overstreet

Trimming down sched.h dependencies: we don't want to include more than the base types.

Cc Peter Zijlstra <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Will Deacon <[email protected]>
Cc Waiman Long <[email protected]>
Cc Boqun Feng <[email protected]>
---
  include/linux/sched.h         |  2 +-
  include/linux/seqlock.h       | 79 +----------------------------
  include/linux/seqlock_types.h | 93 +++++++++++++++++++++++++++++++++++
  3 files changed, 96 insertions(+), 78 deletions(-)

create mode 100644 include/linux/seqlock_types.h

include/linux/sched.h +1 -1
index 6d803d0904d9..436f7ce1450a 100644
@@ -33,7 +33,7 @@
  #include <linux/task_io_accounting.h>
  #include <linux/posix-timers_types.h>
  #include <linux/rseq.h>
-#include <linux/seqlock.h>
+#include <linux/seqlock_types.h>
  #include <linux/kcsan.h>
  #include <linux/rv.h>
  #include <linux/livepatch_sched.h>
include/linux/seqlock.h +2 -77
index e92f9d5577ba..d90d8ee29d81 100644
@@ -18,6 +18,7 @@
  #include <linux/lockdep.h>
  #include <linux/mutex.h>
  #include <linux/preempt.h>
+#include <linux/seqlock_types.h>
  #include <linux/spinlock.h>
 
  #include <asm/processor.h>
@@ -37,37 +38,6 @@
   */
  #define KCSAN_SEQLOCK_REGION_MAX 1000
 
-/*
- * Sequence counters (seqcount_t)
- *
- * This is the raw counting mechanism, without any writer protection.
- *
- * Write side critical sections must be serialized and non-preemptible.
- *
- * If readers can be invoked from hardirq or softirq contexts,
- * interrupts or bottom halves must also be respectively disabled before
- * entering the write section.
- *
- * This mechanism can't be used if the protected data contains pointers,
- * as the writer can invalidate a pointer that a reader is following.
- *
- * If the write serialization mechanism is one of the common kernel
- * locking primitives, use a sequence counter with associated lock
- * (seqcount_LOCKNAME_t) instead.
- *
- * If it's desired to automatically handle the sequence counter writer
- * serialization and non-preemptibility requirements, use a sequential
- * lock (seqlock_t) instead.
- *
- * See Documentation/locking/seqlock.rst
- */
-typedef struct seqcount {
-	unsigned sequence;
-#ifdef CONFIG_DEBUG_LOCK_ALLOC
-	struct lockdep_map dep_map;
-#endif
-} seqcount_t;
-
  static inline void __seqcount_init(seqcount_t *s, const char *name,
  					  struct lock_class_key *key)
  {
@@ -131,28 +101,6 @@ static inline void seqcount_lockdep_reader_access(const seqcount_t *s)
   * See Documentation/locking/seqlock.rst
   */
 
-/*
- * For PREEMPT_RT, seqcount_LOCKNAME_t write side critical sections cannot
- * disable preemption. It can lead to higher latencies, and the write side
- * sections will not be able to acquire locks which become sleeping locks
- * (e.g. spinlock_t).
- *
- * To remain preemptible while avoiding a possible livelock caused by the
- * reader preempting the writer, use a different technique: let the reader
- * detect if a seqcount_LOCKNAME_t writer is in progress. If that is the
- * case, acquire then release the associated LOCKNAME writer serialization
- * lock. This will allow any possibly-preempted writer to make progress
- * until the end of its writer serialization lock critical section.
- *
- * This lock-unlock technique must be implemented for all of PREEMPT_RT
- * sleeping locks.  See Documentation/locking/locktypes.rst
- */
-#if defined(CONFIG_LOCKDEP) || defined(CONFIG_PREEMPT_RT)
-#define __SEQ_LOCK(expr)	expr
-#else
-#define __SEQ_LOCK(expr)
-#endif
-
  /*
   * typedef seqcount_LOCKNAME_t - sequence counter with LOCKNAME associated
   * @seqcount:	The real sequence counter
@@ -194,11 +142,6 @@ static inline void seqcount_lockdep_reader_access(const seqcount_t *s)
   * @lockbase:		prefix for associated lock/unlock
   */
  #define SEQCOUNT_LOCKNAME(lockname, locktype, preemptible, lockbase)	\
-typedef struct seqcount_##lockname {					\
-	seqcount_t		seqcount;				\
-	__SEQ_LOCK(locktype	*lock);					\
-} seqcount_##lockname##_t;						\
-									\
  static __always_inline seqcount_t *					\
  __seqprop_##lockname##_ptr(seqcount_##lockname##_t *s)			\
  {									\
@@ -284,6 +227,7 @@ SEQCOUNT_LOCKNAME(raw_spinlock, raw_spinlock_t,  false,    raw_spin)
  SEQCOUNT_LOCKNAME(spinlock,     spinlock_t,      __SEQ_RT, spin)
  SEQCOUNT_LOCKNAME(rwlock,       rwlock_t,        __SEQ_RT, read)
  SEQCOUNT_LOCKNAME(mutex,        struct mutex,    true,     mutex)
+#undef SEQCOUNT_LOCKNAME
 
  /*
   * SEQCNT_LOCKNAME_ZERO - static initializer for seqcount_LOCKNAME_t
@@ -794,25 +738,6 @@ static inline void raw_write_seqcount_latch(seqcount_latch_t *s)
  	smp_wmb();      /* increment "sequence" before following stores */
  }
 
-/*
- * Sequential locks (seqlock_t)
- *
- * Sequence counters with an embedded spinlock for writer serialization
- * and non-preemptibility.
- *
- * For more info, see:
- *    - Comments on top of seqcount_t
- *    - Documentation/locking/seqlock.rst
- */
-typedef struct {
-	/*
-	 * Make sure that readers don't starve writers on PREEMPT_RT: use
-	 * seqcount_spinlock_t instead of seqcount_t. Check __SEQ_LOCK().
-	 */
-	seqcount_spinlock_t seqcount;
-	spinlock_t lock;
-} seqlock_t;
-
  #define __SEQLOCK_UNLOCKED(lockname)					\
  	{								\
  		.seqcount = SEQCNT_SPINLOCK_ZERO(lockname, &(lockname).lock), \
include/linux/seqlock_types.h new file +83 -0
new file mode 100644
index 000000000000..dfdf43e3fa3d
@@ -0,0 +1,93 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LINUX_SEQLOCK_TYPES_H
+#define __LINUX_SEQLOCK_TYPES_H
+
+#include <linux/lockdep_types.h>
+#include <linux/mutex_types.h>
+#include <linux/spinlock_types.h>
+
+/*
+ * Sequence counters (seqcount_t)
+ *
+ * This is the raw counting mechanism, without any writer protection.
+ *
+ * Write side critical sections must be serialized and non-preemptible.
+ *
+ * If readers can be invoked from hardirq or softirq contexts,
+ * interrupts or bottom halves must also be respectively disabled before
+ * entering the write section.
+ *
+ * This mechanism can't be used if the protected data contains pointers,
+ * as the writer can invalidate a pointer that a reader is following.
+ *
+ * If the write serialization mechanism is one of the common kernel
+ * locking primitives, use a sequence counter with associated lock
+ * (seqcount_LOCKNAME_t) instead.
+ *
+ * If it's desired to automatically handle the sequence counter writer
+ * serialization and non-preemptibility requirements, use a sequential
+ * lock (seqlock_t) instead.
+ *
+ * See Documentation/locking/seqlock.rst
+ */
+typedef struct seqcount {
+	unsigned sequence;
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+	struct lockdep_map dep_map;
+#endif
+} seqcount_t;
+
+/*
+ * For PREEMPT_RT, seqcount_LOCKNAME_t write side critical sections cannot
+ * disable preemption. It can lead to higher latencies, and the write side
+ * sections will not be able to acquire locks which become sleeping locks
+ * (e.g. spinlock_t).
+ *
+ * To remain preemptible while avoiding a possible livelock caused by the
+ * reader preempting the writer, use a different technique: let the reader
+ * detect if a seqcount_LOCKNAME_t writer is in progress. If that is the
+ * case, acquire then release the associated LOCKNAME writer serialization
+ * lock. This will allow any possibly-preempted writer to make progress
+ * until the end of its writer serialization lock critical section.
+ *
+ * This lock-unlock technique must be implemented for all of PREEMPT_RT
+ * sleeping locks.  See Documentation/locking/locktypes.rst
+ */
+#if defined(CONFIG_LOCKDEP) || defined(CONFIG_PREEMPT_RT)
+#define __SEQ_LOCK(expr)	expr
+#else
+#define __SEQ_LOCK(expr)
+#endif
+
+#define SEQCOUNT_LOCKNAME(lockname, locktype, preemptible, lockbase)	\
+typedef struct seqcount_##lockname {					\
+	seqcount_t		seqcount;				\
+	__SEQ_LOCK(locktype	*lock);					\
+} seqcount_##lockname##_t;
+
+SEQCOUNT_LOCKNAME(raw_spinlock, raw_spinlock_t,  false,    raw_spin)
+SEQCOUNT_LOCKNAME(spinlock,     spinlock_t,      __SEQ_RT, spin)
+SEQCOUNT_LOCKNAME(rwlock,       rwlock_t,        __SEQ_RT, read)
+SEQCOUNT_LOCKNAME(mutex,        struct mutex,    true,     mutex)
+#undef SEQCOUNT_LOCKNAME
+
+/*
+ * Sequential locks (seqlock_t)
+ *
+ * Sequence counters with an embedded spinlock for writer serialization
+ * and non-preemptibility.
+ *
+ * For more info, see:
+ *    - Comments on top of seqcount_t
+ *    - Documentation/locking/seqlock.rst
+ */

include/linux/seqlock_types.h line 93

Quoted 10 lines
include/linux/seqlock_types.h new file +10 -0
+typedef struct {
+	/*
+	 * Make sure that readers don't starve writers on PREEMPT_RT: use
+	 * seqcount_spinlock_t instead of seqcount_t. Check __SEQ_LOCK().
+	 */
+	seqcount_spinlock_t seqcount;
+	spinlock_t lock;
+} seqlock_t;
+
+#endif /* __LINUX_SEQLOCK_TYPES_H */

seqlock.h is directly included in kernel/sched/sched.h, so breaking out seqlock_types.h and including only that in include/linux/sched.h should be OK.

#42 lore raw

PATCH 22/50 pid: Split out pid_types.h

In reply to Kent Overstreet

Trimming down sched.h dependencies: we dont't want to include more than the base types.

Cc Kees Cook <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Will Drewry <[email protected]>
---
 drivers/target/target_core_xcopy.c |  1 +
 include/linux/pid.h                | 15 ++-------------
 include/linux/pid_types.h          | 16 ++++++++++++++++
 include/linux/sched.h              |  2 +-
 include/linux/seccomp.h            |  2 ++
 5 files changed, 22 insertions(+), 14 deletions(-)
 create mode 100644 include/linux/pid_types.h
drivers/target/target_core_xcopy.c +1 -0
index 91ed015b588c..4128631c9dfd 100644
@@ -15,6 +15,7 @@
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/list.h>
+#include <linux/rculist.h>
 #include <linux/configfs.h>
 #include <linux/ratelimit.h>
 #include <scsi/scsi_proto.h>
include/linux/pid.h +2 -13
index 653a527574c4..f254c3a45b9b 100644
@@ -2,18 +2,10 @@
 #ifndef _LINUX_PID_H
 #define _LINUX_PID_H
 
+#include <linux/pid_types.h>
 #include <linux/rculist.h>
-#include <linux/wait.h>
 #include <linux/refcount.h>
-
-enum pid_type
-{
-	PIDTYPE_PID,
-	PIDTYPE_TGID,
-	PIDTYPE_PGID,
-	PIDTYPE_SID,
-	PIDTYPE_MAX,
-};
+#include <linux/wait.h>
 
 /*
  * What is struct pid?
@@ -110,9 +102,6 @@ extern void exchange_tids(struct task_struct *task, struct task_struct *old);
 extern void transfer_pid(struct task_struct *old, struct task_struct *new,
 			 enum pid_type);
 
-struct pid_namespace;
-extern struct pid_namespace init_pid_ns;
-
 extern int pid_max;
 extern int pid_max_min, pid_max_max;
 
include/linux/pid_types.h new file +16 -0
new file mode 100644
index 000000000000..c2aee1d91dcf
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_PID_TYPES_H
+#define _LINUX_PID_TYPES_H
+
+enum pid_type {
+	PIDTYPE_PID,
+	PIDTYPE_TGID,
+	PIDTYPE_PGID,
+	PIDTYPE_SID,
+	PIDTYPE_MAX,
+};
+
+struct pid_namespace;
+extern struct pid_namespace init_pid_ns;
+
+#endif /* _LINUX_PID_TYPES_H */
include/linux/sched.h +1 -1
index 436f7ce1450a..37cc9d257073 100644
@@ -11,7 +11,7 @@
 
 #include <asm/current.h>
 
-#include <linux/pid.h>
+#include <linux/pid_types.h>
 #include <linux/sem.h>
 #include <linux/shm.h>
 #include <linux/kmsan_types.h>
include/linux/seccomp.h +2 -0
index 175079552f68..1ec0d8dc4b69 100644
@@ -126,6 +126,8 @@ static inline long seccomp_get_metadata(struct task_struct *task,
 
 #ifdef CONFIG_SECCOMP_CACHE_DEBUG
 struct seq_file;
+struct pid_namespace;
+struct pid;
 
 int proc_pid_seccomp_cache(struct seq_file *m, struct pid_namespace *ns,
 			   struct pid *pid, struct task_struct *task);
Signature · 1 line
2.43.0
#43 lore raw

PATCH 23/50 sched.h: move pid helpers to pid.h

This is needed for killing the sched.h dependency on rcupdate.h, and pid.h is a better place for this code anyways.

---
 include/linux/pid.h          | 125 +++++++++++++++++++++++++++++++++++
 include/linux/sched.h        | 122 ----------------------------------
 include/linux/sched/signal.h |   1 +
 3 files changed, 126 insertions(+), 122 deletions(-)
include/linux/pid.h +125 -0
index f254c3a45b9b..395cacce1179 100644
@@ -4,7 +4,9 @@
 
 #include <linux/pid_types.h>
 #include <linux/rculist.h>
+#include <linux/rcupdate.h>
 #include <linux/refcount.h>
+#include <linux/sched.h>
 #include <linux/wait.h>
 
 /*
@@ -204,4 +206,127 @@ pid_t pid_vnr(struct pid *pid);
 		}							\
 		task = tg___;						\
 	} while_each_pid_task(pid, type, task)
+
+static inline struct pid *task_pid(struct task_struct *task)
+{
+	return task->thread_pid;
+}
+
+/*
+ * the helpers to get the task's different pids as they are seen
+ * from various namespaces
+ *
+ * task_xid_nr()     : global id, i.e. the id seen from the init namespace;
+ * task_xid_vnr()    : virtual id, i.e. the id seen from the pid namespace of
+ *                     current.
+ * task_xid_nr_ns()  : id seen from the ns specified;
+ *
+ * see also pid_nr() etc in include/linux/pid.h
+ */
+pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type, struct pid_namespace *ns);
+
+static inline pid_t task_pid_nr(struct task_struct *tsk)
+{
+	return tsk->pid;
+}
+
+static inline pid_t task_pid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
+{
+	return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns);
+}
+
+static inline pid_t task_pid_vnr(struct task_struct *tsk)
+{
+	return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
+}
+
+
+static inline pid_t task_tgid_nr(struct task_struct *tsk)
+{
+	return tsk->tgid;
+}
+
+/**
+ * pid_alive - check that a task structure is not stale
+ * @p: Task structure to be checked.
+ *
+ * Test if a process is not yet dead (at most zombie state)
+ * If pid_alive fails, then pointers within the task structure
+ * can be stale and must not be dereferenced.
+ *
+ * Return: 1 if the process is alive. 0 otherwise.
+ */
+static inline int pid_alive(const struct task_struct *p)
+{
+	return p->thread_pid != NULL;
+}
+
+static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
+{
+	return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns);
+}
+
+static inline pid_t task_pgrp_vnr(struct task_struct *tsk)
+{
+	return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL);
+}
+
+
+static inline pid_t task_session_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
+{
+	return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns);
+}
+
+static inline pid_t task_session_vnr(struct task_struct *tsk)
+{
+	return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL);
+}
+
+static inline pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
+{
+	return __task_pid_nr_ns(tsk, PIDTYPE_TGID, ns);
+}
+
+static inline pid_t task_tgid_vnr(struct task_struct *tsk)
+{
+	return __task_pid_nr_ns(tsk, PIDTYPE_TGID, NULL);
+}
+
+static inline pid_t task_ppid_nr_ns(const struct task_struct *tsk, struct pid_namespace *ns)
+{
+	pid_t pid = 0;
+
+	rcu_read_lock();
+	if (pid_alive(tsk))
+		pid = task_tgid_nr_ns(rcu_dereference(tsk->real_parent), ns);
+	rcu_read_unlock();
+
+	return pid;
+}
+
+static inline pid_t task_ppid_nr(const struct task_struct *tsk)
+{
+	return task_ppid_nr_ns(tsk, &init_pid_ns);
+}
+
+/* Obsolete, do not use: */
+static inline pid_t task_pgrp_nr(struct task_struct *tsk)
+{
+	return task_pgrp_nr_ns(tsk, &init_pid_ns);
+}
+
+/**
+ * is_global_init - check if a task structure is init. Since init
+ * is free to have sub-threads we need to check tgid.
+ * @tsk: Task structure to be checked.
+ *
+ * Check if a task structure is the first user space task the kernel created.
+ *
+ * Return: 1 if the task structure is init. 0 otherwise.
+ */
+static inline int is_global_init(struct task_struct *tsk)
+{
+	return task_tgid_nr(tsk) == 1;
+}
+
 #endif /* _LINUX_PID_H */
include/linux/sched.h +0 -122

134 lines not on this page · raw message

include/linux/sched/signal.h +1 -0
index 3499c1a8b929..b847d8fa75a9 100644
@@ -9,6 +9,7 @@
 #include <linux/sched/task.h>
 #include <linux/cred.h>
 #include <linux/refcount.h>
+#include <linux/pid.h>
 #include <linux/posix-timers.h>
 #include <linux/mm_types.h>
 #include <asm/ptrace.h>
Signature · 1 line
2.43.0
#44 lore raw

PATCH 24/50 plist: Split out plist_types.h

In reply to Kent Overstreet

Trimming down sched.h dependencies: we don't want to include more than the base types.

---
 include/linux/plist.h       | 12 +-----------
 include/linux/plist_types.h | 17 +++++++++++++++++
 include/linux/sched.h       |  2 +-
 init/init_task.c            |  1 +
 kernel/futex/core.c         |  1 +
 kernel/futex/requeue.c      |  1 +
 kernel/futex/waitwake.c     |  1 +
 mm/swapfile.c               |  1 +
 8 files changed, 24 insertions(+), 12 deletions(-)
 create mode 100644 include/linux/plist_types.h
include/linux/plist.h +1 -11
index 0f352c1d3c80..8c1c8adf7fe9 100644
@@ -75,20 +75,10 @@
 
 #include <linux/container_of.h>
 #include <linux/list.h>
-#include <linux/types.h>
+#include <linux/plist_types.h>
 
 #include <asm/bug.h>
 
-struct plist_head {
-	struct list_head node_list;
-};
-
-struct plist_node {
-	int			prio;
-	struct list_head	prio_list;
-	struct list_head	node_list;
-};
-
 /**
  * PLIST_HEAD_INIT - static struct plist_head initializer
  * @head:	struct plist_head variable name
include/linux/plist_types.h new file +17 -0
new file mode 100644
index 000000000000..c37e784330af
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef _LINUX_PLIST_TYPES_H
+#define _LINUX_PLIST_TYPES_H
+
+#include <linux/types.h>
+
+struct plist_head {
+	struct list_head node_list;
+};
+
+struct plist_node {
+	int			prio;
+	struct list_head	prio_list;
+	struct list_head	node_list;
+};
+
+#endif /* _LINUX_PLIST_TYPES_H */
include/linux/sched.h +1 -1
index 9e2708c2cfa6..8c230f24688b 100644
@@ -16,7 +16,7 @@
 #include <linux/shm.h>
 #include <linux/kmsan_types.h>
 #include <linux/mutex_types.h>
-#include <linux/plist.h>
+#include <linux/plist_types.h>
 #include <linux/hrtimer_types.h>
 #include <linux/irqflags.h>
 #include <linux/seccomp.h>
init/init_task.c +1 -0
index 5727d42149c3..56220898a256 100644
@@ -12,6 +12,7 @@
 #include <linux/audit.h>
 #include <linux/numa.h>
 #include <linux/scs.h>
+#include <linux/plist.h>
 
 #include <linux/uaccess.h>
 
kernel/futex/core.c +1 -0
index dad981a865b8..e0e853412c15 100644
@@ -34,6 +34,7 @@
 #include <linux/compat.h>
 #include <linux/jhash.h>
 #include <linux/pagemap.h>
+#include <linux/plist.h>
 #include <linux/memblock.h>
 #include <linux/fault-inject.h>
 #include <linux/slab.h>
kernel/futex/requeue.c +1 -0
index eb21f065816b..b47bb764b352 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 
+#include <linux/plist.h>
 #include <linux/sched/signal.h>
 
 #include "futex.h"
kernel/futex/waitwake.c +1 -0
index 61b112897a84..3a10375d9521 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 
+#include <linux/plist.h>
 #include <linux/sched/task.h>
 #include <linux/sched/signal.h>
 #include <linux/freezer.h>
mm/swapfile.c +1 -0
index 4bc70f459164..25019af07181 100644
@@ -42,6 +42,7 @@
 #include <linux/completion.h>
 #include <linux/suspend.h>
 #include <linux/zswap.h>
+#include <linux/plist.h>
 
 #include <asm/tlbflush.h>
 #include <linux/swapops.h>
Signature · 1 line
2.43.0
#45 lore raw

PATCH 25/50 wait: Remove uapi header file from main header file

In reply to Kent Overstreet

From: "Matthew Wilcox (Oracle)" <[email protected]>

There's really no overlap between uapi/linux/wait.h and linux/wait.h. There are two files which rely on the uapi file being implcitly included, so explicitly include it there and remove it from the main header file.

---
 include/linux/wait.h   | 1 -
 kernel/exit.c          | 4 +++-
 kernel/pid_namespace.c | 1 +
 3 files changed, 4 insertions(+), 2 deletions(-)
include/linux/wait.h +0 -1
index 3473b663176f..8aa3372f21a0 100644
@@ -9,7 +9,6 @@
 #include <linux/spinlock.h>
 
 #include <asm/current.h>
-#include <uapi/linux/wait.h>
 
 typedef struct wait_queue_entry wait_queue_entry_t;
 
kernel/exit.c +3 -1
index ee9f43bed49a..2ef33047371b 100644
@@ -69,8 +69,10 @@
 #include <linux/rethook.h>
 #include <linux/sysfs.h>
 #include <linux/user_events.h>
-
 #include <linux/uaccess.h>
+
+#include <uapi/linux/wait.h>
+
 #include <asm/unistd.h>
 #include <asm/mmu_context.h>
 
kernel/pid_namespace.c +1 -0
index 3028b2218aa4..7ade20e95232 100644
@@ -23,6 +23,7 @@
 #include <linux/sched/task.h>
 #include <linux/sched/signal.h>
 #include <linux/idr.h>
+#include <uapi/linux/wait.h>
 #include "pid_sysctl.h"
 
 static DEFINE_MUTEX(pid_caches_mutex);
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 25/50
#46 lore raw

Re: [PATCH 25/50] wait: Remove uapi header file from main header file

Quoted 9 lines · Kent Overstreet

From: "Matthew Wilcox (Oracle)" <[email protected]>

There's really no overlap between uapi/linux/wait.h and linux/wait.h. There are two files which rely on the uapi file being implcitly included, so explicitly include it there and remove it from the main header file.

---

#47 lore raw

PATCH 26/50 rslib: kill bogus dependency on list.h

In reply to Kent Overstreet

list_head is defined in types.h, not list.h - this kills a sched.h dependency.

---
 include/linux/rslib.h | 1 -
 1 file changed, 1 deletion(-)
include/linux/rslib.h +0 -1
index 238bb85243d3..a04dacbdc8ae 100644
@@ -10,7 +10,6 @@
 #ifndef _RSLIB_H_
 #define _RSLIB_H_
 
-#include <linux/list.h>
 #include <linux/types.h>	/* for gfp_t */
 #include <linux/gfp.h>		/* for GFP_KERNEL */
 
Signature · 1 line
2.43.0
#48 lore raw

Re: [PATCH 26/50] rslib: kill bogus dependency on list.h

Quoted 13 lines · Kent Overstreet

list_head is defined in types.h, not list.h - this kills a sched.h dependency.

---
 include/linux/rslib.h | 1 -
 1 file changed, 1 deletion(-)
include/linux/rslib.h +0 -0
index 238bb85243d3..a04dacbdc8ae 100644

include/linux/rslib.h line 15

Quoted 7 lines
include/linux/rslib.h +0 -1
@@ -10,7 +10,6 @@
 #ifndef _RSLIB_H_
 #define _RSLIB_H_
 
-#include <linux/list.h>
 #include <linux/types.h>	/* for gfp_t */
 #include <linux/gfp.h>		/* for GFP_KERNEL */
 

What about line 47?

    47		struct list_head list;
Signature · 3 lines
#Randy
https://people.kernel.org/tglx/notes-about-netiquette
https://subspace.kernel.org/etiquette.html
#49 lore raw

Re: [PATCH 26/50] rslib: kill bogus dependency on list.h

Quoted 19 lines · Randy Dunlap
Quoted 16 lines · Kent Overstreet

list_head is defined in types.h, not list.h - this kills a sched.h dependency.

---
 include/linux/rslib.h | 1 -
 1 file changed, 1 deletion(-)
include/linux/rslib.h +0 -0
index 238bb85243d3..a04dacbdc8ae 100644
@@ -10,7 +10,6 @@
 #ifndef _RSLIB_H_
 #define _RSLIB_H_
 
Quoted 8 lines

include/linux/rslib.h line 15

Quoted 4 lines
include/linux/rslib.h +0 -1
-#include <linux/list.h>
 #include <linux/types.h>	/* for gfp_t */
 #include <linux/gfp.h>		/* for GFP_KERNEL */
 

What about line 47?

    47		struct list_head list;

It's in types.h.

#50 lore raw

Re: [PATCH 26/50] rslib: kill bogus dependency on list.h

In reply to Randy Dunlap
Quoted 19 lines · Randy Dunlap
Quoted 16 lines · Kent Overstreet

list_head is defined in types.h, not list.h - this kills a sched.h dependency.

---
 include/linux/rslib.h | 1 -
 1 file changed, 1 deletion(-)
include/linux/rslib.h +0 -0
index 238bb85243d3..a04dacbdc8ae 100644
@@ -10,7 +10,6 @@
 #ifndef _RSLIB_H_
 #define _RSLIB_H_
 
Quoted 9 lines

include/linux/rslib.h line 15

Quoted 4 lines
include/linux/rslib.h +0 -1
-#include <linux/list.h>
 #include <linux/types.h>	/* for gfp_t */
 #include <linux/gfp.h>		/* for GFP_KERNEL */
 

What about line 47?

    47		struct list_head list;

I see. :)
it's in types.h, not list.h, as you explained!

Signature · 3 lines
#Randy
https://people.kernel.org/tglx/notes-about-netiquette
https://subspace.kernel.org/etiquette.html
#51 lore raw

PATCH 27/50 timerqueue: Split out timerqueue_types.h

In reply to Kent Overstreet

Trimming down sched.h dependencies: timerqueue_types can include just rbtree_types.h instead of pulling in rbtree.h.

---
 include/linux/hrtimer_types.h      |  2 +-
 include/linux/posix-timers_types.h |  2 +-
 include/linux/timerqueue.h         | 13 +------------
 include/linux/timerqueue_types.h   | 17 +++++++++++++++++
 4 files changed, 20 insertions(+), 14 deletions(-)
 create mode 100644 include/linux/timerqueue_types.h
include/linux/hrtimer_types.h +1 -1
index f4ef391b96a7..ad66a3081735 100644
@@ -3,7 +3,7 @@
 #define _LINUX_HRTIMER_TYPES_H
 
 #include <linux/types.h>
-#include <linux/timerqueue.h>
+#include <linux/timerqueue_types.h>
 
 struct hrtimer_clock_base;
 
include/linux/posix-timers_types.h +1 -1
index 57fec639a9bb..2b1f30ee2db0 100644
@@ -3,7 +3,7 @@
 #define _linux_POSIX_TIMERS_TYPES_H
 
 #include <linux/mutex_types.h>
-#include <linux/timerqueue.h>
+#include <linux/timerqueue_types.h>
 #include <linux/types.h>
 
 /*
include/linux/timerqueue.h +1 -12
index adc80e29168e..62973f7d4610 100644
@@ -3,18 +3,7 @@
 #define _LINUX_TIMERQUEUE_H
 
 #include <linux/rbtree.h>
-#include <linux/ktime.h>
-
-
-struct timerqueue_node {
-	struct rb_node node;
-	ktime_t expires;
-};
-
-struct timerqueue_head {
-	struct rb_root_cached rb_root;
-};
-
+#include <linux/timerqueue_types.h>
 
 extern bool timerqueue_add(struct timerqueue_head *head,
 			   struct timerqueue_node *node);
include/linux/timerqueue_types.h new file +17 -0
new file mode 100644
index 000000000000..dc298d0923e3
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_TIMERQUEUE_TYPES_H
+#define _LINUX_TIMERQUEUE_TYPES_H
+
+#include <linux/rbtree_types.h>
+#include <linux/types.h>
+
+struct timerqueue_node {
+	struct rb_node node;
+	ktime_t expires;
+};
+
+struct timerqueue_head {
+	struct rb_root_cached rb_root;
+};
+
+#endif /* _LINUX_TIMERQUEUE_TYPES_H */
Signature · 1 line
2.43.0
#52 lore raw

PATCH 28/50 signal: Kill bogus dependency on list.h

In reply to Kent Overstreet

list_head is in types.h, not list.h.

---
 include/linux/signal.h       | 1 +
 include/linux/signal_types.h | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
include/linux/signal.h +1 -0
index 3b98e7a28538..f19816832f05 100644
@@ -3,6 +3,7 @@
 #define _LINUX_SIGNAL_H
 
 #include <linux/bug.h>
+#include <linux/list.h>
 #include <linux/signal_types.h>
 #include <linux/string.h>
 
include/linux/signal_types.h +1 -1
index a70b2bdbf4d9..caf4f7a59ab9 100644
@@ -6,7 +6,7 @@
  * Basic signal handling related data type definitions:
  */
 
-#include <linux/list.h>
+#include <linux/types.h>
 #include <uapi/linux/signal.h>
 
 typedef struct kernel_siginfo {
Signature · 1 line
2.43.0
#53 lore raw

PATCH 29/50 timers: Split out timer_types.h

In reply to Kent Overstreet

Cutting down on sched.h dependencies: this is going to be used in workqueue_types.h in the next patch, so we can kill the sched.h dependency on workqueue.h.

---
 include/linux/timer.h       | 16 +---------------
 include/linux/timer_types.h | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+), 15 deletions(-)
 create mode 100644 include/linux/timer_types.h
include/linux/timer.h +1 -15
index 26a545bb0153..f18a2f1eb79e 100644
@@ -7,21 +7,7 @@
 #include <linux/stddef.h>
 #include <linux/debugobjects.h>
 #include <linux/stringify.h>
-
-struct timer_list {
-	/*
-	 * All fields that change during normal runtime grouped to the
-	 * same cacheline
-	 */
-	struct hlist_node	entry;
-	unsigned long		expires;
-	void			(*function)(struct timer_list *);
-	u32			flags;
-
-#ifdef CONFIG_LOCKDEP
-	struct lockdep_map	lockdep_map;
-#endif
-};
+#include <linux/timer_types.h>
 
 #ifdef CONFIG_LOCKDEP
 /*
include/linux/timer_types.h new file +23 -0
new file mode 100644
index 000000000000..fae5a388f914
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_TIMER_TYPES_H
+#define _LINUX_TIMER_TYPES_H
+
+#include <linux/lockdep_types.h>
+#include <linux/types.h>
+
+struct timer_list {
+	/*
+	 * All fields that change during normal runtime grouped to the
+	 * same cacheline
+	 */
+	struct hlist_node	entry;
+	unsigned long		expires;
+	void			(*function)(struct timer_list *);
+	u32			flags;
+
+#ifdef CONFIG_LOCKDEP
+	struct lockdep_map	lockdep_map;
+#endif
+};
+
+#endif /* _LINUX_TIMER_TYPES_H */
Signature · 1 line
2.43.0
#54 lore raw

PATCH 30/50 workqueue: Split out workqueue_types.h

In reply to Kent Overstreet

More sched.h dependency culling - this lets us kill a rhashtable-types.h dependency on workqueue.h.

---
 include/linux/dma-fence.h        |  1 +
 include/linux/rhashtable-types.h |  2 +-
 include/linux/timekeeping.h      |  1 +
 include/linux/workqueue.h        | 16 +---------------
 include/linux/workqueue_types.h  | 25 +++++++++++++++++++++++++
 5 files changed, 29 insertions(+), 16 deletions(-)
 create mode 100644 include/linux/workqueue_types.h
include/linux/dma-fence.h +1 -0
index b3772edca2e6..e06bad467f55 100644
@@ -21,6 +21,7 @@
 #include <linux/sched.h>
 #include <linux/printk.h>
 #include <linux/rcupdate.h>
+#include <linux/timekeeping.h>
 
 struct dma_fence;
 struct dma_fence_ops;
include/linux/rhashtable-types.h +1 -1
index 57467cbf4c5b..b6f3797277ff 100644
@@ -12,7 +12,7 @@
 #include <linux/atomic.h>
 #include <linux/compiler.h>
 #include <linux/mutex.h>
-#include <linux/workqueue.h>
+#include <linux/workqueue_types.h>
 
 struct rhash_head {
 	struct rhash_head __rcu		*next;
include/linux/timekeeping.h +1 -0
index fe1e467ba046..7c43e98cf211 100644
@@ -4,6 +4,7 @@
 
 #include <linux/errno.h>
 #include <linux/clocksource_ids.h>
+#include <linux/ktime.h>
 
 /* Included from linux/ktime.h */
 
include/linux/workqueue.h +1 -15
index 24b1e5070f4d..f1bb2e35301f 100644
@@ -14,12 +14,7 @@
 #include <linux/atomic.h>
 #include <linux/cpumask.h>
 #include <linux/rcupdate.h>
-
-struct workqueue_struct;
-
-struct work_struct;
-typedef void (*work_func_t)(struct work_struct *work);
-void delayed_work_timer_fn(struct timer_list *t);
+#include <linux/workqueue_types.h>
 
 /*
  * The first word is the work queue pointer and the flags rolled into
@@ -95,15 +90,6 @@ enum {
 #define WORK_STRUCT_FLAG_MASK    ((1ul << WORK_STRUCT_FLAG_BITS) - 1)
 #define WORK_STRUCT_WQ_DATA_MASK (~WORK_STRUCT_FLAG_MASK)
 
-struct work_struct {
-	atomic_long_t data;
-	struct list_head entry;
-	work_func_t func;
-#ifdef CONFIG_LOCKDEP
-	struct lockdep_map lockdep_map;
-#endif
-};
-
 #define WORK_DATA_INIT()	ATOMIC_LONG_INIT((unsigned long)WORK_STRUCT_NO_POOL)
 #define WORK_DATA_STATIC_INIT()	\
 	ATOMIC_LONG_INIT((unsigned long)(WORK_STRUCT_NO_POOL | WORK_STRUCT_STATIC))
include/linux/workqueue_types.h new file +25 -0
new file mode 100644
index 000000000000..4c38824f3ab4
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_WORKQUEUE_TYPES_H
+#define _LINUX_WORKQUEUE_TYPES_H
+
+#include <linux/atomic.h>
+#include <linux/lockdep_types.h>
+#include <linux/timer_types.h>
+#include <linux/types.h>
+
+struct workqueue_struct;
+
+struct work_struct;
+typedef void (*work_func_t)(struct work_struct *work);
+void delayed_work_timer_fn(struct timer_list *t);
+
+struct work_struct {
+	atomic_long_t data;
+	struct list_head entry;
+	work_func_t func;
+#ifdef CONFIG_LOCKDEP
+	struct lockdep_map lockdep_map;
+#endif
+};
+
+#endif /* _LINUX_WORKQUEUE_TYPES_H */
Signature · 1 line
2.43.0
#55 lore raw

PATCH 31/50 shm: Slim down dependencies

In reply to Kent Overstreet

list_head is in types.h, not list.h., and the uapi header wasn't needed.

---
 include/linux/shm.h        | 4 ++--
 ipc/shm.c                  | 1 +
 security/selinux/hooks.c   | 1 +
 security/smack/smack_lsm.c | 1 +
 4 files changed, 5 insertions(+), 2 deletions(-)
include/linux/shm.h +2 -2
index d8e69aed3d32..c55bef0538e5 100644
@@ -2,12 +2,12 @@
 #ifndef _LINUX_SHM_H_
 #define _LINUX_SHM_H_
 
-#include <linux/list.h>
+#include <linux/types.h>
 #include <asm/page.h>
-#include <uapi/linux/shm.h>
 #include <asm/shmparam.h>
 
 struct file;
+struct task_struct;
 
 #ifdef CONFIG_SYSVIPC
 struct sysv_shm {
ipc/shm.c +1 -0
index 222aaf035afb..a89f001a8bf0 100644
@@ -29,6 +29,7 @@
 #include <linux/mm.h>
 #include <linux/hugetlb.h>
 #include <linux/shm.h>
+#include <uapi/linux/shm.h>
 #include <linux/init.h>
 #include <linux/file.h>
 #include <linux/mman.h>
security/selinux/hooks.c +1 -0
index feda711c6b7b..b9ccc98421e9 100644
@@ -85,6 +85,7 @@
 #include <linux/export.h>
 #include <linux/msg.h>
 #include <linux/shm.h>
+#include <uapi/linux/shm.h>
 #include <linux/bpf.h>
 #include <linux/kernfs.h>
 #include <linux/stringhash.h>	/* for hashlen_string() */
security/smack/smack_lsm.c +1 -0
index 65130a791f57..7a5600834f16 100644
@@ -37,6 +37,7 @@
 #include <linux/personality.h>
 #include <linux/msg.h>
 #include <linux/shm.h>
+#include <uapi/linux/shm.h>
 #include <linux/binfmts.h>
 #include <linux/parser.h>
 #include <linux/fs_context.h>
Signature · 1 line
2.43.0
#56 lore raw

PATCH 32/50 ipc: Kill bogus dependency on spinlock.h

In reply to Kent Overstreet

pruning sched.h dependencies, headers shouldn't pull in more than they need.

---
 include/linux/ipc.h   | 2 +-
 include/linux/sched.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
include/linux/ipc.h +1 -1
index e1c9eea6015b..9b1434247aab 100644
@@ -2,7 +2,7 @@
 #ifndef _LINUX_IPC_H
 #define _LINUX_IPC_H
 
-#include <linux/spinlock.h>
+#include <linux/spinlock_types.h>
 #include <linux/uidgid.h>
 #include <linux/rhashtable-types.h>
 #include <uapi/linux/ipc.h>
include/linux/sched.h +2 -0
index 8c230f24688b..3a58d3d7d264 100644
@@ -2139,6 +2139,8 @@ extern bool sched_task_on_rq(struct task_struct *p);
 extern unsigned long get_wchan(struct task_struct *p);
 extern struct task_struct *cpu_curr_snapshot(int cpu);
 
+#include <asm/spinlock.h>
+
 /*
  * In order to reduce various lock holder preemption latencies provide an
  * interface to see if a vCPU is currently running or not.
Signature · 1 line
2.43.0
#57 lore raw

Re: [PATCH 22/50] pid: Split out pid_types.h

In reply to Kent Overstreet
Quoted 8 lines · Kent Overstreet

Trimming down sched.h dependencies: we dont't want to include more than the base types.

Cc Kees Cook <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Will Drewry <[email protected]>

---

Hm, ideally the struct upid and struct pid definitions could also be moved and then included in pid.h?

Quoted 106 lines
 drivers/target/target_core_xcopy.c |  1 +
 include/linux/pid.h                | 15 ++-------------
 include/linux/pid_types.h          | 16 ++++++++++++++++
 include/linux/sched.h              |  2 +-
 include/linux/seccomp.h            |  2 ++
 5 files changed, 22 insertions(+), 14 deletions(-)
 create mode 100644 include/linux/pid_types.h
drivers/target/target_core_xcopy.c +1 -0
index 91ed015b588c..4128631c9dfd 100644
@@ -15,6 +15,7 @@
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/list.h>
+#include <linux/rculist.h>
 #include <linux/configfs.h>
 #include <linux/ratelimit.h>
 #include <scsi/scsi_proto.h>
include/linux/pid.h +2 -13
index 653a527574c4..f254c3a45b9b 100644
@@ -2,18 +2,10 @@
 #ifndef _LINUX_PID_H
 #define _LINUX_PID_H
 
+#include <linux/pid_types.h>
 #include <linux/rculist.h>
-#include <linux/wait.h>
 #include <linux/refcount.h>
-
-enum pid_type
-{
-	PIDTYPE_PID,
-	PIDTYPE_TGID,
-	PIDTYPE_PGID,
-	PIDTYPE_SID,
-	PIDTYPE_MAX,
-};
+#include <linux/wait.h>
 
 /*
  * What is struct pid?
@@ -110,9 +102,6 @@ extern void exchange_tids(struct task_struct *task, struct task_struct *old);
 extern void transfer_pid(struct task_struct *old, struct task_struct *new,
 			 enum pid_type);
 
-struct pid_namespace;
-extern struct pid_namespace init_pid_ns;
-
 extern int pid_max;
 extern int pid_max_min, pid_max_max;
 
include/linux/pid_types.h new file +16 -0
new file mode 100644
index 000000000000..c2aee1d91dcf
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_PID_TYPES_H
+#define _LINUX_PID_TYPES_H
+
+enum pid_type {
+	PIDTYPE_PID,
+	PIDTYPE_TGID,
+	PIDTYPE_PGID,
+	PIDTYPE_SID,
+	PIDTYPE_MAX,
+};
+
+struct pid_namespace;
+extern struct pid_namespace init_pid_ns;
+
+#endif /* _LINUX_PID_TYPES_H */
include/linux/sched.h +1 -1
index 436f7ce1450a..37cc9d257073 100644
@@ -11,7 +11,7 @@
 
 #include <asm/current.h>
 
-#include <linux/pid.h>
+#include <linux/pid_types.h>
 #include <linux/sem.h>
 #include <linux/shm.h>
 #include <linux/kmsan_types.h>
include/linux/seccomp.h +2 -0
index 175079552f68..1ec0d8dc4b69 100644
@@ -126,6 +126,8 @@ static inline long seccomp_get_metadata(struct task_struct *task,
 
 #ifdef CONFIG_SECCOMP_CACHE_DEBUG
 struct seq_file;
+struct pid_namespace;
+struct pid;
 
 int proc_pid_seccomp_cache(struct seq_file *m, struct pid_namespace *ns,
 			   struct pid *pid, struct task_struct *task);
Signature · 1 line
2.43.0
#58 lore raw

PATCH 33/50 Split out irqflags_types.h

In reply to Kent Overstreet

We're working on only pulling in type definitions to sched.h whenever possible.

---
 include/linux/irqflags.h       | 14 +-------------
 include/linux/irqflags_types.h | 22 ++++++++++++++++++++++
 include/linux/sched.h          |  2 +-
 3 files changed, 24 insertions(+), 14 deletions(-)
 create mode 100644 include/linux/irqflags_types.h
include/linux/irqflags.h +1 -13
index 2b665c32f5fe..147feebd508c 100644
@@ -12,6 +12,7 @@
 #ifndef _LINUX_TRACE_IRQFLAGS_H
 #define _LINUX_TRACE_IRQFLAGS_H
 
+#include <linux/irqflags_types.h>
 #include <linux/typecheck.h>
 #include <linux/cleanup.h>
 #include <asm/irqflags.h>
@@ -34,19 +35,6 @@
 
 #ifdef CONFIG_TRACE_IRQFLAGS
 
-/* Per-task IRQ trace events information. */
-struct irqtrace_events {
-	unsigned int	irq_events;
-	unsigned long	hardirq_enable_ip;
-	unsigned long	hardirq_disable_ip;
-	unsigned int	hardirq_enable_event;
-	unsigned int	hardirq_disable_event;
-	unsigned long	softirq_disable_ip;
-	unsigned long	softirq_enable_ip;
-	unsigned int	softirq_disable_event;
-	unsigned int	softirq_enable_event;
-};
-
 DECLARE_PER_CPU(int, hardirqs_enabled);
 DECLARE_PER_CPU(int, hardirq_context);
 
include/linux/irqflags_types.h new file +22 -0
new file mode 100644
index 000000000000..c13f0d915097
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_IRQFLAGS_TYPES_H
+#define _LINUX_IRQFLAGS_TYPES_H
+
+#ifdef CONFIG_TRACE_IRQFLAGS
+
+/* Per-task IRQ trace events information. */
+struct irqtrace_events {
+	unsigned int	irq_events;
+	unsigned long	hardirq_enable_ip;
+	unsigned long	hardirq_disable_ip;
+	unsigned int	hardirq_enable_event;
+	unsigned int	hardirq_disable_event;
+	unsigned long	softirq_disable_ip;
+	unsigned long	softirq_enable_ip;
+	unsigned int	softirq_disable_event;
+	unsigned int	softirq_enable_event;
+};
+
+#endif
+
+#endif /* _LINUX_IRQFLAGS_TYPES_H */
include/linux/sched.h +1 -1
index 3a58d3d7d264..d799427f6d1b 100644
@@ -11,6 +11,7 @@
 
 #include <asm/current.h>
 
+#include <linux/irqflags_types.h>
 #include <linux/pid_types.h>
 #include <linux/sem.h>
 #include <linux/shm.h>
@@ -18,7 +19,6 @@
 #include <linux/mutex_types.h>
 #include <linux/plist_types.h>
 #include <linux/hrtimer_types.h>
-#include <linux/irqflags.h>
 #include <linux/seccomp.h>
 #include <linux/nodemask_types.h>
 #include <linux/rcupdate.h>
Signature · 1 line
2.43.0
#59 lore raw

PATCH 34/50 mm_types_task.h: Trim dependencies

more sched.h header dependency trimming

---
 include/linux/mm_types_task.h | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
include/linux/mm_types_task.h +2 -5
index aa44fff8bb9d..724a731d5c2b 100644
@@ -9,11 +9,6 @@
  */
 
 #include <linux/types.h>
-#include <linux/threads.h>
-#include <linux/atomic.h>
-#include <linux/cpumask.h>
-
-#include <asm/page.h>
 
 #ifdef CONFIG_ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
 #include <asm/tlbbatch.h>
@@ -36,6 +31,8 @@ enum {
 	NR_MM_COUNTERS
 };
 
+struct page;
+
 struct page_frag {
 	struct page *page;
 #if (BITS_PER_LONG > 32) || (PAGE_SIZE >= 65536)
Signature · 1 line
2.43.0
#60 lore raw

PATCH 35/50 cpumask: Split out cpumask_types.h

In reply to Kent Overstreet

More sched.h dependency trimming: this will help to kill the printk.h dependency.

---
 arch/x86/include/asm/tlbbatch.h |  2 +-
 include/linux/cpumask.h         |  4 +---
 include/linux/cpumask_types.h   | 12 ++++++++++++
 3 files changed, 14 insertions(+), 4 deletions(-)
 create mode 100644 include/linux/cpumask_types.h
arch/x86/include/asm/tlbbatch.h +1 -1
index 1ad56eb3e8a8..0550dea70c0f 100644
@@ -2,7 +2,7 @@
 #ifndef _ARCH_X86_TLBBATCH_H
 #define _ARCH_X86_TLBBATCH_H
 
-#include <linux/cpumask.h>
+#include <linux/cpumask_types.h>
 
 struct arch_tlbflush_unmap_batch {
 	/*
include/linux/cpumask.h +1 -3
index cfb545841a2c..b710dc4cd858 100644
@@ -14,9 +14,7 @@
 #include <linux/bug.h>
 #include <linux/gfp_types.h>
 #include <linux/numa.h>
-
-/* Don't assign or return these: may not be this big! */
-typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t;
+#include <linux/cpumask_types.h>
 
 /**
  * cpumask_bits - get the bits in a cpumask
include/linux/cpumask_types.h new file +12 -0
new file mode 100644
index 000000000000..f4c032c9a81a
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LINUX_CPUMASK_TYPES_H
+#define __LINUX_CPUMASK_TYPES_H
+
+#include <linux/bitops.h>
+#include <linux/types.h>
+#include <linux/threads.h>
+
+/* Don't assign or return these: may not be this big! */
+typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t;
+
+#endif /* __LINUX_CPUMASK_TYPES_H */
Signature · 1 line
2.43.0
#61 lore raw

PATCH 36/50 syscall_user_dispatch.h: split out *_types.h

In reply to Kent Overstreet

thread_info.h pulls in a lot of junk that sched.h that we don't need; in particular, this helps to kill the printk.h dependency.

---
 include/linux/sched.h                       |  2 +-
 include/linux/syscall_user_dispatch.h       |  9 +--------
 include/linux/syscall_user_dispatch_types.h | 22 +++++++++++++++++++++
 3 files changed, 24 insertions(+), 9 deletions(-)
 create mode 100644 include/linux/syscall_user_dispatch_types.h
include/linux/sched.h +1 -1
index d799427f6d1b..fea6d913e004 100644
@@ -28,7 +28,7 @@
 #include <linux/sched/prio.h>
 #include <linux/sched/types.h>
 #include <linux/signal_types.h>
-#include <linux/syscall_user_dispatch.h>
+#include <linux/syscall_user_dispatch_types.h>
 #include <linux/mm_types_task.h>
 #include <linux/task_io_accounting.h>
 #include <linux/posix-timers_types.h>
include/linux/syscall_user_dispatch.h +1 -8
index 641ca8880995..3858a6ffdd5c 100644
@@ -6,16 +6,10 @@
 #define _SYSCALL_USER_DISPATCH_H
 
 #include <linux/thread_info.h>
+#include <linux/syscall_user_dispatch_types.h>
 
 #ifdef CONFIG_GENERIC_ENTRY
 
-struct syscall_user_dispatch {
-	char __user	*selector;
-	unsigned long	offset;
-	unsigned long	len;
-	bool		on_dispatch;
-};
-
 int set_syscall_user_dispatch(unsigned long mode, unsigned long offset,
 			      unsigned long len, char __user *selector);
 
@@ -29,7 +23,6 @@ int syscall_user_dispatch_set_config(struct task_struct *task, unsigned long siz
 				     void __user *data);
 
 #else
-struct syscall_user_dispatch {};
 
 static inline int set_syscall_user_dispatch(unsigned long mode, unsigned long offset,
 					    unsigned long len, char __user *selector)
include/linux/syscall_user_dispatch_types.h new file +22 -0
new file mode 100644
index 000000000000..3be36b06c7d7
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _SYSCALL_USER_DISPATCH_TYPES_H
+#define _SYSCALL_USER_DISPATCH_TYPES_H
+
+#include <linux/types.h>
+
+#ifdef CONFIG_GENERIC_ENTRY
+
+struct syscall_user_dispatch {
+	char __user	*selector;
+	unsigned long	offset;
+	unsigned long	len;
+	bool		on_dispatch;
+};
+
+#else
+
+struct syscall_user_dispatch {};
+
+#endif
+
+#endif /* _SYSCALL_USER_DISPATCH_TYPES_H */
Signature · 1 line
2.43.0
#62 lore raw

PATCH 37/50 x86/signal: kill dependency on time.h

In reply to Kent Overstreet

this is unecessary, and was pulling in printk.h from uapi headers

---
 arch/x86/include/uapi/asm/signal.h | 1 -
 1 file changed, 1 deletion(-)
arch/x86/include/uapi/asm/signal.h +0 -1
index 777c3a0f4e23..f777346450ec 100644
@@ -4,7 +4,6 @@
 
 #ifndef __ASSEMBLY__
 #include <linux/types.h>
-#include <linux/time.h>
 #include <linux/compiler.h>
 
 /* Avoid too many header ordering problems.  */
Signature · 1 line
2.43.0
#63 lore raw

PATCH 38/50 uapi/linux/resource.h: fix include

In reply to Kent Overstreet

We should't be depending on time.h; we should only be pulling in other uapi headers.

---
 include/uapi/linux/resource.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/linux/resource.h +1 -1
index ac5d6a3031db..4fc22908bc09 100644
@@ -2,7 +2,7 @@
 #ifndef _UAPI_LINUX_RESOURCE_H
 #define _UAPI_LINUX_RESOURCE_H
 
-#include <linux/time.h>
+#include <linux/time_types.h>
 #include <linux/types.h>
 
 /*
Signature · 1 line
2.43.0
#64 lore raw

PATCH 39/50 refcount: Split out refcount_types.h

In reply to Kent Overstreet

More trimming of sched.h dependencies.

---
 include/linux/refcount.h       | 13 +------------
 include/linux/refcount_types.h | 19 +++++++++++++++++++
 include/linux/sched.h          |  2 +-
 3 files changed, 21 insertions(+), 13 deletions(-)
 create mode 100644 include/linux/refcount_types.h
include/linux/refcount.h +1 -12
index a62fcca97486..85c6df0d1bef 100644
@@ -96,22 +96,11 @@
 #include <linux/bug.h>
 #include <linux/compiler.h>
 #include <linux/limits.h>
+#include <linux/refcount_types.h>
 #include <linux/spinlock_types.h>
 
 struct mutex;
 
-/**
- * typedef refcount_t - variant of atomic_t specialized for reference counts
- * @refs: atomic_t counter field
- *
- * The counter saturates at REFCOUNT_SATURATED and will not move once
- * there. This avoids wrapping the counter and causing 'spurious'
- * use-after-free bugs.
- */
-typedef struct refcount_struct {
-	atomic_t refs;
-} refcount_t;
-
 #define REFCOUNT_INIT(n)	{ .refs = ATOMIC_INIT(n), }
 #define REFCOUNT_MAX		INT_MAX
 #define REFCOUNT_SATURATED	(INT_MIN / 2)
include/linux/refcount_types.h new file +19 -0
new file mode 100644
index 000000000000..162004f06edf
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_REFCOUNT_TYPES_H
+#define _LINUX_REFCOUNT_TYPES_H
+
+#include <linux/types.h>
+
+/**
+ * typedef refcount_t - variant of atomic_t specialized for reference counts
+ * @refs: atomic_t counter field
+ *
+ * The counter saturates at REFCOUNT_SATURATED and will not move once
+ * there. This avoids wrapping the counter and causing 'spurious'
+ * use-after-free bugs.
+ */
+typedef struct refcount_struct {
+	atomic_t refs;
+} refcount_t;
+
+#endif /* _LINUX_REFCOUNT_TYPES_H */
include/linux/sched.h +1 -1
index fea6d913e004..f52977af1511 100644
@@ -22,7 +22,7 @@
 #include <linux/seccomp.h>
 #include <linux/nodemask_types.h>
 #include <linux/rcupdate.h>
-#include <linux/refcount.h>
+#include <linux/refcount_types.h>
 #include <linux/resource.h>
 #include <linux/latencytop.h>
 #include <linux/sched/prio.h>
Signature · 1 line
2.43.0
#65 lore raw

PATCH 40/50 seccomp: Split out seccomp_types.h

In reply to Kent Overstreet

More pruning of sched.h dependencies.

---
 include/linux/sched.h         |  2 +-
 include/linux/seccomp.h       | 20 +-------------------
 include/linux/seccomp_types.h | 26 ++++++++++++++++++++++++++
 3 files changed, 28 insertions(+), 20 deletions(-)
 create mode 100644 include/linux/seccomp_types.h
include/linux/sched.h +1 -1
index f52977af1511..9bfa61ab2750 100644
@@ -19,7 +19,7 @@
 #include <linux/mutex_types.h>
 #include <linux/plist_types.h>
 #include <linux/hrtimer_types.h>
-#include <linux/seccomp.h>
+#include <linux/seccomp_types.h>
 #include <linux/nodemask_types.h>
 #include <linux/rcupdate.h>
 #include <linux/refcount_types.h>
include/linux/seccomp.h +1 -19
index 1ec0d8dc4b69..26a53cea5761 100644
@@ -19,27 +19,9 @@
 
 #include <linux/thread_info.h>
 #include <linux/atomic.h>
+#include <linux/seccomp_types.h>
 #include <asm/seccomp.h>
 
-struct seccomp_filter;
-/**
- * struct seccomp - the state of a seccomp'ed process
- *
- * @mode:  indicates one of the valid values above for controlled
- *         system calls available to a process.
- * @filter_count: number of seccomp filters
- * @filter: must always point to a valid seccomp-filter or NULL as it is
- *          accessed without locking during system call entry.
- *
- *          @filter must only be accessed from the context of current as there
- *          is no read locking.
- */
-struct seccomp {
-	int mode;
-	atomic_t filter_count;
-	struct seccomp_filter *filter;
-};
-
 #ifdef CONFIG_HAVE_ARCH_SECCOMP_FILTER
 extern int __secure_computing(const struct seccomp_data *sd);
 static inline int secure_computing(void)
include/linux/seccomp_types.h new file +26 -0
new file mode 100644
index 000000000000..c6184582a0a0
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_SECCOMP_TYPES_H
+#define _LINUX_SECCOMP_TYPES_H
+
+#include <linux/types.h>
+
+struct seccomp_filter;
+/**
+ * struct seccomp - the state of a seccomp'ed process
+ *
+ * @mode:  indicates one of the valid values above for controlled
+ *         system calls available to a process.
+ * @filter_count: number of seccomp filters
+ * @filter: must always point to a valid seccomp-filter or NULL as it is
+ *          accessed without locking during system call entry.
+ *
+ *          @filter must only be accessed from the context of current as there
+ *          is no read locking.
+ */
+struct seccomp {
+	int mode;
+	atomic_t filter_count;
+	struct seccomp_filter *filter;
+};
+
+#endif /* _LINUX_SECCOMP_TYPES_H */
Signature · 1 line
2.43.0
#66 lore raw

PATCH 41/50 uidgid: Split out uidgid_types.h

In reply to Kent Overstreet

More sched.h dependency pruning.

---
 include/linux/sched.h        |  1 +
 include/linux/uidgid.h       | 11 +----------
 include/linux/uidgid_types.h | 15 +++++++++++++++
 3 files changed, 17 insertions(+), 10 deletions(-)
 create mode 100644 include/linux/uidgid_types.h
include/linux/sched.h +1 -0
index 9bfa61ab2750..157e7af36bb7 100644
@@ -37,6 +37,7 @@
 #include <linux/kcsan.h>
 #include <linux/rv.h>
 #include <linux/livepatch_sched.h>
+#include <linux/uidgid_types.h>
 #include <asm/kmap_size.h>
 
 /* task_struct member predeclarations (sorted alphabetically): */
include/linux/uidgid.h +1 -10
index b0542cd11aeb..ba20b62f13e1 100644
@@ -12,21 +12,12 @@
  * to detect when we overlook these differences.
  *
  */
-#include <linux/types.h>
+#include <linux/uidgid_types.h>
 #include <linux/highuid.h>
 
 struct user_namespace;
 extern struct user_namespace init_user_ns;
 
-typedef struct {
-	uid_t val;
-} kuid_t;
-
-
-typedef struct {
-	gid_t val;
-} kgid_t;
-
 #define KUIDT_INIT(value) (kuid_t){ value }
 #define KGIDT_INIT(value) (kgid_t){ value }
 
include/linux/uidgid_types.h new file +15 -0
new file mode 100644
index 000000000000..b35ac4955a33
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_UIDGID_TYPES_H
+#define _LINUX_UIDGID_TYPES_H
+
+#include <linux/types.h>
+
+typedef struct {
+	uid_t val;
+} kuid_t;
+
+typedef struct {
+	gid_t val;
+} kgid_t;
+
+#endif /* _LINUX_UIDGID_TYPES_H */
Signature · 1 line
2.43.0
#68 lore raw

PATCH 42/50 sem: Split out sem_types.h

In reply to Kent Overstreet

More sched.h dependency pruning.

---
 include/linux/audit.h     |  1 +
 include/linux/sched.h     |  3 ++-
 include/linux/sem.h       | 10 +---------
 include/linux/sem_types.h | 13 +++++++++++++
 4 files changed, 17 insertions(+), 10 deletions(-)
 create mode 100644 include/linux/sem_types.h
include/linux/audit.h +1 -0
index 51b1b7054a23..93d97b56e1e4 100644
@@ -400,6 +400,7 @@ static inline void audit_ptrace(struct task_struct *t)
 }
 
 				/* Private API (for audit.c only) */
+struct kern_ipc_perm;
 extern void __audit_ipc_obj(struct kern_ipc_perm *ipcp);
 extern void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, umode_t mode);
 extern void __audit_bprm(struct linux_binprm *bprm);
include/linux/sched.h +2 -1
index 157e7af36bb7..98885e3a81e8 100644
@@ -13,12 +13,13 @@
 
 #include <linux/irqflags_types.h>
 #include <linux/pid_types.h>
-#include <linux/sem.h>
+#include <linux/sem_types.h>
 #include <linux/shm.h>
 #include <linux/kmsan_types.h>
 #include <linux/mutex_types.h>
 #include <linux/plist_types.h>
 #include <linux/hrtimer_types.h>
+#include <linux/timer_types.h>
 #include <linux/seccomp_types.h>
 #include <linux/nodemask_types.h>
 #include <linux/rcupdate.h>
include/linux/sem.h +1 -9
index 5608a500c43e..c4deefe42aeb 100644
@@ -3,25 +3,17 @@
 #define _LINUX_SEM_H
 
 #include <uapi/linux/sem.h>
+#include <linux/sem_types.h>
 
 struct task_struct;
-struct sem_undo_list;
 
 #ifdef CONFIG_SYSVIPC
 
-struct sysv_sem {
-	struct sem_undo_list *undo_list;
-};
-
 extern int copy_semundo(unsigned long clone_flags, struct task_struct *tsk);
 extern void exit_sem(struct task_struct *tsk);
 
 #else
 
-struct sysv_sem {
-	/* empty */
-};
-
 static inline int copy_semundo(unsigned long clone_flags, struct task_struct *tsk)
 {
 	return 0;
include/linux/sem_types.h new file +13 -0
new file mode 100644
index 000000000000..73df1971a7ae
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_SEM_TYPES_H
+#define _LINUX_SEM_TYPES_H
+
+struct sem_undo_list;
+
+struct sysv_sem {
+#ifdef CONFIG_SYSVIPC
+	struct sem_undo_list *undo_list;
+#endif
+};
+
+#endif /* _LINUX_SEM_TYPES_H */
Signature · 1 line
2.43.0
#69 lore raw

Re: [PATCH 42/50] sem: Split out sem_types.h

Hi Kent,

Quoted 3 lines · Kent Overstreet

More sched.h dependency pruning.

Thanks for your patch, which is now commit eb72d60ccaed883a ("sem:
Split out sem_types.h") in next-20231220.

$ make ARCH=m68k defconfig arch/m68k/kernel/asm-offsets.i
*** Default configuration is based on 'multi_defconfig'
#
# No change to .config
#
  UPD     include/config/kernel.release
  UPD     include/generated/utsrelease.h
  CC      arch/m68k/kernel/asm-offsets.s
In file included from arch/m68k/kernel/asm-offsets.c:15:
./include/linux/sched.h:551:3: error: conflicting types for
‘____cacheline_aligned’
  551 | } ____cacheline_aligned;
      |   ^~~~~~~~~~~~~~~~~~~~~
./include/linux/sched.h:509:3: note: previous declaration of
‘____cacheline_aligned’ was here
  509 | } ____cacheline_aligned;
      |   ^~~~~~~~~~~~~~~~~~~~~
make[3]: *** [scripts/Makefile.build:116:
arch/m68k/kernel/asm-offsets.s] Error 1
make[2]: *** [Makefile:1191: prepare0] Error 2
make[1]: *** [Makefile:350: __build_one_by_one] Error 2
make: *** [Makefile:234: __sub-make] Error 2
Quoted 70 lines
include/linux/audit.h +1 -0
@@ -400,6 +400,7 @@ static inline void audit_ptrace(struct task_struct *t)
 }
 
                                /* Private API (for audit.c only) */
+struct kern_ipc_perm;
 extern void __audit_ipc_obj(struct kern_ipc_perm *ipcp);
 extern void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, umode_t mode);
 extern void __audit_bprm(struct linux_binprm *bprm);
include/linux/sched.h +2 -1
index 157e7af36bb7..98885e3a81e8 100644
@@ -13,12 +13,13 @@
 
 #include <linux/irqflags_types.h>
 #include <linux/pid_types.h>
-#include <linux/sem.h>
+#include <linux/sem_types.h>
 #include <linux/shm.h>
 #include <linux/kmsan_types.h>
 #include <linux/mutex_types.h>
 #include <linux/plist_types.h>
 #include <linux/hrtimer_types.h>
+#include <linux/timer_types.h>
 #include <linux/seccomp_types.h>
 #include <linux/nodemask_types.h>
 #include <linux/rcupdate.h>
include/linux/sem.h +1 -9
index 5608a500c43e..c4deefe42aeb 100644
@@ -3,25 +3,17 @@
 #define _LINUX_SEM_H
 
 #include <uapi/linux/sem.h>
+#include <linux/sem_types.h>
 
 struct task_struct;
-struct sem_undo_list;
 
 #ifdef CONFIG_SYSVIPC
 
-struct sysv_sem {
-       struct sem_undo_list *undo_list;
-};
-
 extern int copy_semundo(unsigned long clone_flags, struct task_struct *tsk);
 extern void exit_sem(struct task_struct *tsk);
 
 #else
 
-struct sysv_sem {
-       /* empty */
-};
-
 static inline int copy_semundo(unsigned long clone_flags, struct task_struct *tsk)
 {
        return 0;
include/linux/sem_types.h new file +3 -0
new file mode 100644
index 000000000000..73df1971a7ae
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_SEM_TYPES_H
+#define _LINUX_SEM_TYPES_H

include/linux/sem_types.h line 13

Quoted 10 lines
include/linux/sem_types.h new file +10 -0
+
+struct sem_undo_list;
+
+struct sysv_sem {
+#ifdef CONFIG_SYSVIPC
+       struct sem_undo_list *undo_list;
+#endif
+};
+
+#endif /* _LINUX_SEM_TYPES_H */

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#70 lore raw

Re: [PATCH 42/50] sem: Split out sem_types.h

Quoted 25 lines · Geert Uytterhoeven

Hi Kent,

Quoted 3 lines · Kent Overstreet

More sched.h dependency pruning.

Thanks for your patch, which is now commit eb72d60ccaed883a ("sem:
Split out sem_types.h") in next-20231220.

$ make ARCH=m68k defconfig arch/m68k/kernel/asm-offsets.i
*** Default configuration is based on 'multi_defconfig'
#
# No change to .config
#
  UPD     include/config/kernel.release
  UPD     include/generated/utsrelease.h
  CC      arch/m68k/kernel/asm-offsets.s
In file included from arch/m68k/kernel/asm-offsets.c:15:
./include/linux/sched.h:551:3: error: conflicting types for
‘____cacheline_aligned’
  551 | } ____cacheline_aligned;
      |   ^~~~~~~~~~~~~~~~~~~~~
./include/linux/sched.h:509:3: note: previous declaration of
Quoted 8 lines
‘____cacheline_aligned’ was here
  509 | } ____cacheline_aligned;
      |   ^~~~~~~~~~~~~~~~~~~~~
make[3]: *** [scripts/Makefile.build:116:
arch/m68k/kernel/asm-offsets.s] Error 1
make[2]: *** [Makefile:1191: prepare0] Error 2
make[1]: *** [Makefile:350: __build_one_by_one] Error 2
make: *** [Makefile:234: __sub-make] Error 2

Is this a build failure on linux-next, or that specific commit?

It looks like this should be fixed in a later commit that includes cache.h in sched.h; I'll move that include back to this patch.

#71 lore raw

Re: [PATCH 42/50] sem: Split out sem_types.h

Hi Kent,

Quoted 33 lines · Kent Overstreet
Quoted 23 lines · Geert Uytterhoeven
Quoted 3 lines · Kent Overstreet

More sched.h dependency pruning.

Thanks for your patch, which is now commit eb72d60ccaed883a ("sem:
Split out sem_types.h") in next-20231220.

$ make ARCH=m68k defconfig arch/m68k/kernel/asm-offsets.i
*** Default configuration is based on 'multi_defconfig'
#
# No change to .config
#
  UPD     include/config/kernel.release
  UPD     include/generated/utsrelease.h
  CC      arch/m68k/kernel/asm-offsets.s
In file included from arch/m68k/kernel/asm-offsets.c:15:
./include/linux/sched.h:551:3: error: conflicting types for
‘____cacheline_aligned’
  551 | } ____cacheline_aligned;
      |   ^~~~~~~~~~~~~~~~~~~~~
./include/linux/sched.h:509:3: note: previous declaration of
Quoted 8 lines
‘____cacheline_aligned’ was here
  509 | } ____cacheline_aligned;
      |   ^~~~~~~~~~~~~~~~~~~~~
make[3]: *** [scripts/Makefile.build:116:
arch/m68k/kernel/asm-offsets.s] Error 1
make[2]: *** [Makefile:1191: prepare0] Error 2
make[1]: *** [Makefile:350: __build_one_by_one] Error 2
make: *** [Makefile:234: __sub-make] Error 2
Quoted 1 line

Is this a build failure on linux-next, or that specific commit?

On this specific commit.

Quoted 2 lines

It looks like this should be fixed in a later commit that includes cache.h in sched.h; I'll move that include back to this patch.

Indeed. The robots reported a build failure, and bisection arrived at this (different) build failure first.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#72 lore raw

PATCH 43/50 lockdep: move held_lock to lockdep_types.h

In reply to Kent Overstreet

held_lock is embedded in task_struct, and we don't want sched.h pulling in all of lockdep.h

---
 include/linux/lockdep.h       | 57 -----------------------------------
 include/linux/lockdep_types.h | 57 +++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 57 deletions(-)
include/linux/lockdep.h +0 -57
index dc2844b071c2..08b0d1d9d78b 100644
@@ -82,63 +82,6 @@ struct lock_chain {
 	u64				chain_key;
 };
 
-#define MAX_LOCKDEP_KEYS_BITS		13
-#define MAX_LOCKDEP_KEYS		(1UL << MAX_LOCKDEP_KEYS_BITS)
-#define INITIAL_CHAIN_KEY		-1
-
-struct held_lock {
-	/*
-	 * One-way hash of the dependency chain up to this point. We
-	 * hash the hashes step by step as the dependency chain grows.
-	 *
-	 * We use it for dependency-caching and we skip detection
-	 * passes and dependency-updates if there is a cache-hit, so
-	 * it is absolutely critical for 100% coverage of the validator
-	 * to have a unique key value for every unique dependency path
-	 * that can occur in the system, to make a unique hash value
-	 * as likely as possible - hence the 64-bit width.
-	 *
-	 * The task struct holds the current hash value (initialized
-	 * with zero), here we store the previous hash value:
-	 */
-	u64				prev_chain_key;
-	unsigned long			acquire_ip;
-	struct lockdep_map		*instance;
-	struct lockdep_map		*nest_lock;
-#ifdef CONFIG_LOCK_STAT
-	u64 				waittime_stamp;
-	u64				holdtime_stamp;
-#endif
-	/*
-	 * class_idx is zero-indexed; it points to the element in
-	 * lock_classes this held lock instance belongs to. class_idx is in
-	 * the range from 0 to (MAX_LOCKDEP_KEYS-1) inclusive.
-	 */
-	unsigned int			class_idx:MAX_LOCKDEP_KEYS_BITS;
-	/*
-	 * The lock-stack is unified in that the lock chains of interrupt
-	 * contexts nest ontop of process context chains, but we 'separate'
-	 * the hashes by starting with 0 if we cross into an interrupt
-	 * context, and we also keep do not add cross-context lock
-	 * dependencies - the lock usage graph walking covers that area
-	 * anyway, and we'd just unnecessarily increase the number of
-	 * dependencies otherwise. [Note: hardirq and softirq contexts
-	 * are separated from each other too.]
-	 *
-	 * The following field is used to detect when we cross into an
-	 * interrupt context:
-	 */
-	unsigned int irq_context:2; /* bit 0 - soft, bit 1 - hard */
-	unsigned int trylock:1;						/* 16 bits */
-
-	unsigned int read:2;        /* see lock_acquire() comment */
-	unsigned int check:1;       /* see lock_acquire() comment */
-	unsigned int hardirqs_off:1;
-	unsigned int sync:1;
-	unsigned int references:11;					/* 32 bits */
-	unsigned int pin_count;
-};
-
 /*
  * Initialization, self-test and debugging-output methods:
  */
include/linux/lockdep_types.h +57 -0

63 lines not on this page · raw message

Signature · 1 line
2.43.0
reviewer Acked-by on v1 43/50
#73 lore raw

Re: [PATCH 43/50] lockdep: move held_lock to lockdep_types.h

Quoted 135 lines · Kent Overstreet

held_lock is embedded in task_struct, and we don't want sched.h pulling in all of lockdep.h

---
  include/linux/lockdep.h       | 57 -----------------------------------
  include/linux/lockdep_types.h | 57 +++++++++++++++++++++++++++++++++++
  2 files changed, 57 insertions(+), 57 deletions(-)
include/linux/lockdep.h +0 -57
index dc2844b071c2..08b0d1d9d78b 100644
@@ -82,63 +82,6 @@ struct lock_chain {
  	u64				chain_key;
  };
 
-#define MAX_LOCKDEP_KEYS_BITS		13
-#define MAX_LOCKDEP_KEYS		(1UL << MAX_LOCKDEP_KEYS_BITS)
-#define INITIAL_CHAIN_KEY		-1
-
-struct held_lock {
-	/*
-	 * One-way hash of the dependency chain up to this point. We
-	 * hash the hashes step by step as the dependency chain grows.
-	 *
-	 * We use it for dependency-caching and we skip detection
-	 * passes and dependency-updates if there is a cache-hit, so
-	 * it is absolutely critical for 100% coverage of the validator
-	 * to have a unique key value for every unique dependency path
-	 * that can occur in the system, to make a unique hash value
-	 * as likely as possible - hence the 64-bit width.
-	 *
-	 * The task struct holds the current hash value (initialized
-	 * with zero), here we store the previous hash value:
-	 */
-	u64				prev_chain_key;
-	unsigned long			acquire_ip;
-	struct lockdep_map		*instance;
-	struct lockdep_map		*nest_lock;
-#ifdef CONFIG_LOCK_STAT
-	u64 				waittime_stamp;
-	u64				holdtime_stamp;
-#endif
-	/*
-	 * class_idx is zero-indexed; it points to the element in
-	 * lock_classes this held lock instance belongs to. class_idx is in
-	 * the range from 0 to (MAX_LOCKDEP_KEYS-1) inclusive.
-	 */
-	unsigned int			class_idx:MAX_LOCKDEP_KEYS_BITS;
-	/*
-	 * The lock-stack is unified in that the lock chains of interrupt
-	 * contexts nest ontop of process context chains, but we 'separate'
-	 * the hashes by starting with 0 if we cross into an interrupt
-	 * context, and we also keep do not add cross-context lock
-	 * dependencies - the lock usage graph walking covers that area
-	 * anyway, and we'd just unnecessarily increase the number of
-	 * dependencies otherwise. [Note: hardirq and softirq contexts
-	 * are separated from each other too.]
-	 *
-	 * The following field is used to detect when we cross into an
-	 * interrupt context:
-	 */
-	unsigned int irq_context:2; /* bit 0 - soft, bit 1 - hard */
-	unsigned int trylock:1;						/* 16 bits */
-
-	unsigned int read:2;        /* see lock_acquire() comment */
-	unsigned int check:1;       /* see lock_acquire() comment */
-	unsigned int hardirqs_off:1;
-	unsigned int sync:1;
-	unsigned int references:11;					/* 32 bits */
-	unsigned int pin_count;
-};
-
  /*
   * Initialization, self-test and debugging-output methods:
   */
include/linux/lockdep_types.h +50 -0
index 2ebc323d345a..9c533c8d701e 100644
@@ -198,6 +198,63 @@ struct lockdep_map {
 
  struct pin_cookie { unsigned int val; };
 
+#define MAX_LOCKDEP_KEYS_BITS		13
+#define MAX_LOCKDEP_KEYS		(1UL << MAX_LOCKDEP_KEYS_BITS)
+#define INITIAL_CHAIN_KEY		-1
+
+struct held_lock {
+	/*
+	 * One-way hash of the dependency chain up to this point. We
+	 * hash the hashes step by step as the dependency chain grows.
+	 *
+	 * We use it for dependency-caching and we skip detection
+	 * passes and dependency-updates if there is a cache-hit, so
+	 * it is absolutely critical for 100% coverage of the validator
+	 * to have a unique key value for every unique dependency path
+	 * that can occur in the system, to make a unique hash value
+	 * as likely as possible - hence the 64-bit width.
+	 *
+	 * The task struct holds the current hash value (initialized
+	 * with zero), here we store the previous hash value:
+	 */
+	u64				prev_chain_key;
+	unsigned long			acquire_ip;
+	struct lockdep_map		*instance;
+	struct lockdep_map		*nest_lock;
+#ifdef CONFIG_LOCK_STAT
+	u64 				waittime_stamp;
+	u64				holdtime_stamp;
+#endif
+	/*
+	 * class_idx is zero-indexed; it points to the element in
+	 * lock_classes this held lock instance belongs to. class_idx is in
+	 * the range from 0 to (MAX_LOCKDEP_KEYS-1) inclusive.
+	 */
+	unsigned int			class_idx:MAX_LOCKDEP_KEYS_BITS;
+	/*
+	 * The lock-stack is unified in that the lock chains of interrupt
+	 * contexts nest ontop of process context chains, but we 'separate'
+	 * the hashes by starting with 0 if we cross into an interrupt
+	 * context, and we also keep do not add cross-context lock
+	 * dependencies - the lock usage graph walking covers that area
+	 * anyway, and we'd just unnecessarily increase the number of
+	 * dependencies otherwise. [Note: hardirq and softirq contexts
+	 * are separated from each other too.]
+	 *
+	 * The following field is used to detect when we cross into an
+	 * interrupt context:
+	 */
+	unsigned int irq_context:2; /* bit 0 - soft, bit 1 - hard */
+	unsigned int trylock:1;						/* 16 bits */
+
+	unsigned int read:2;        /* see lock_acquire() comment */

include/linux/lockdep_types.h struct lockdep_map { · line 260

Quoted 10 lines
include/linux/lockdep_types.h +7 -0
+	unsigned int check:1;       /* see lock_acquire() comment */
+	unsigned int hardirqs_off:1;
+	unsigned int sync:1;
+	unsigned int references:11;					/* 32 bits */
+	unsigned int pin_count;
+};
+
  #else /* !CONFIG_LOCKDEP */
 
  /*
#74 lore raw

PATCH 44/50 restart_block: Trim includes

In reply to Kent Overstreet

We don't actually use any timekeeping types, no need to pull in time64.h.

Also, sched.h uses restart_block; add it as a direct dependency.

---
 include/linux/restart_block.h | 2 +-
 include/linux/sched.h         | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
include/linux/restart_block.h +1 -1
index 980a65594412..13f17676c5f4 100644
@@ -7,8 +7,8 @@
 
 #include <linux/compiler.h>
 #include <linux/types.h>
-#include <linux/time64.h>
 
+struct __kernel_timespec;
 struct timespec;
 struct old_timespec32;
 struct pollfd;
include/linux/sched.h +1 -0
index 98885e3a81e8..ec739277c39b 100644
@@ -33,6 +33,7 @@
 #include <linux/mm_types_task.h>
 #include <linux/task_io_accounting.h>
 #include <linux/posix-timers_types.h>
+#include <linux/restart_block.h>
 #include <linux/rseq.h>
 #include <linux/seqlock_types.h>
 #include <linux/kcsan.h>
Signature · 1 line
2.43.0
#75 lore raw

PATCH 45/50 rseq: Split out rseq.h from sched.h

We're trying to get sched.h down to more or less just types only, not code - rseq can live in its own header.

This helps us kill the dependency on preempt.h in sched.h.

---
 arch/x86/kernel/signal.c         |   1 +
 fs/exec.c                        |   1 +
 include/linux/resume_user_mode.h |   1 +
 include/linux/rseq.h             | 131 +++++++++++++++++++++++++++++++
 include/linux/sched.h            | 125 +----------------------------
 kernel/fork.c                    |   1 +
 kernel/sched/core.c              |   1 +
 7 files changed, 137 insertions(+), 124 deletions(-)
 create mode 100644 include/linux/rseq.h
arch/x86/kernel/signal.c +1 -0
index 65fe2094da59..31b6f5dddfc2 100644
@@ -27,6 +27,7 @@
 #include <linux/context_tracking.h>
 #include <linux/entry-common.h>
 #include <linux/syscalls.h>
+#include <linux/rseq.h>
 
 #include <asm/processor.h>
 #include <asm/ucontext.h>
fs/exec.c +1 -0
index 4aa19b24f281..41773af7e3dc 100644
@@ -66,6 +66,7 @@
 #include <linux/coredump.h>
 #include <linux/time_namespace.h>
 #include <linux/user_events.h>
+#include <linux/rseq.h>
 
 #include <linux/uaccess.h>
 #include <asm/mmu_context.h>
include/linux/resume_user_mode.h +1 -0
index f8f3e958e9cf..e0135e0adae0 100644
@@ -6,6 +6,7 @@
 #include <linux/sched.h>
 #include <linux/task_work.h>
 #include <linux/memcontrol.h>
+#include <linux/rseq.h>
 #include <linux/blk-cgroup.h>
 
 /**
include/linux/rseq.h new file +131 -0

131 lines not on this page · raw message

include/linux/sched.h +1 -124

137 lines not on this page · raw message

kernel/fork.c +1 -0
index 319e61297bfb..53816393995b 100644
@@ -100,6 +100,7 @@
 #include <linux/stackprotector.h>
 #include <linux/user_events.h>
 #include <linux/iommu.h>
+#include <linux/rseq.h>
 
 #include <asm/pgalloc.h>
 #include <linux/uaccess.h>
kernel/sched/core.c +1 -0
index a708d225c28e..d04cf3c47899 100644
@@ -57,6 +57,7 @@
 #include <linux/profile.h>
 #include <linux/psi.h>
 #include <linux/rcuwait_api.h>
+#include <linux/rseq.h>
 #include <linux/sched/wake_q.h>
 #include <linux/scs.h>
 #include <linux/slab.h>
Signature · 1 line
2.43.0
#76 lore raw

PATCH 46/50 preempt.h: Kill dependency on list.h

In reply to Kent Overstreet

We really only need types.h, list.h is big.

---
 include/linux/preempt.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
include/linux/preempt.h +4 -2
index 9aa6358a1a16..7233e9cf1bab 100644
@@ -9,7 +9,7 @@
 
 #include <linux/linkage.h>
 #include <linux/cleanup.h>
-#include <linux/list.h>
+#include <linux/types.h>
 
 /*
  * We put the hardirq and softirq counter into the preemption
@@ -360,7 +360,9 @@ void preempt_notifier_unregister(struct preempt_notifier *notifier);
 static inline void preempt_notifier_init(struct preempt_notifier *notifier,
 				     struct preempt_ops *ops)
 {
-	INIT_HLIST_NODE(&notifier->link);
+	/* INIT_HLIST_NODE() open coded, to avoid dependency on list.h */
+	notifier->link.next = NULL;
+	notifier->link.pprev = NULL;
 	notifier->ops = ops;
 }
 
Signature · 1 line
2.43.0
#77 lore raw

Re: [PATCH 46/50] preempt.h: Kill dependency on list.h

include/linux/preempt.h void preempt_notifier_unregister(struct preempt_notifier *notifier); · line 365

Quoted 4 lines · Kent Overstreet
include/linux/preempt.h +3 -1
-	INIT_HLIST_NODE(&notifier->link);
+	/* INIT_HLIST_NODE() open coded, to avoid dependency on list.h */
+	notifier->link.next = NULL;
+	notifier->link.pprev = NULL;

Arguably INIT_HLIST_NODE() belongs in types.h -- we already have RCUREF_INIT() and ATOMIC_INIT() in there.

#78 lore raw

Re: [PATCH 46/50] preempt.h: Kill dependency on list.h

Quoted 9 lines · Matthew Wilcox

include/linux/preempt.h void preempt_notifier_unregister(struct preempt_notifier *notifier); · line 365

Quoted 4 lines · Kent Overstreet
include/linux/preempt.h +3 -1
-	INIT_HLIST_NODE(&notifier->link);
+	/* INIT_HLIST_NODE() open coded, to avoid dependency on list.h */
+	notifier->link.next = NULL;
+	notifier->link.pprev = NULL;

Arguably INIT_HLIST_NODE() belongs in types.h -- we already have RCUREF_INIT() and ATOMIC_INIT() in there.

That would be far better than open-coding it.

Signature · 3 lines
#Randy
https://people.kernel.org/tglx/notes-about-netiquette
https://subspace.kernel.org/etiquette.html
#79 lore raw

Re: [PATCH 46/50] preempt.h: Kill dependency on list.h

In reply to Matthew Wilcox
Quoted 8 lines · Matthew Wilcox

include/linux/preempt.h void preempt_notifier_unregister(struct preempt_notifier *notifier); · line 365

Quoted 4 lines · Kent Overstreet
include/linux/preempt.h +3 -1
-	INIT_HLIST_NODE(&notifier->link);
+	/* INIT_HLIST_NODE() open coded, to avoid dependency on list.h */
+	notifier->link.next = NULL;
+	notifier->link.pprev = NULL;

Arguably INIT_HLIST_NODE() belongs in types.h -- we already have RCUREF_INIT() and ATOMIC_INIT() in there.

I think I'd prefer to keep types.h as minimal as possible - as soon as we start putting non type stuff in there people won't know what the distinction is and it'll grow.

preempt.h is a bit unusual too, normally we'd just split out a _types.h header there but it's not so easy to split up usefully.

#80 lore raw

Re: [PATCH 46/50] preempt.h: Kill dependency on list.h

Quoted 10 lines · Kent Overstreet
Quoted 8 lines · Matthew Wilcox

include/linux/preempt.h void preempt_notifier_unregister(struct preempt_notifier *notifier); · line 365

Quoted 4 lines · Kent Overstreet
include/linux/preempt.h +3 -1
-	INIT_HLIST_NODE(&notifier->link);
+	/* INIT_HLIST_NODE() open coded, to avoid dependency on list.h */
+	notifier->link.next = NULL;
+	notifier->link.pprev = NULL;

Arguably INIT_HLIST_NODE() belongs in types.h -- we already have RCUREF_INIT() and ATOMIC_INIT() in there.

Quoted 7 lines

I think I'd prefer to keep types.h as minimal as possible - as soon as we start putting non type stuff in there people won't know what the distinction is and it'll grow.

preempt.h is a bit unusual too, normally we'd just split out a _types.h header there but it's not so easy to split up usefully.

I don't feel like I have NAK power, but if I did, I would NAK open coding of INIT_HLIST_HEAD() or anything like it. I would expect some $maintainer to do likewise, but I could be surprised.

Signature · 3 lines
#Randy
https://people.kernel.org/tglx/notes-about-netiquette
https://subspace.kernel.org/etiquette.html
#81 lore raw

Re: [PATCH 46/50] preempt.h: Kill dependency on list.h

Quoted 17 lines · Randy Dunlap
Quoted 14 lines · Kent Overstreet
Quoted 8 lines · Matthew Wilcox

include/linux/preempt.h void preempt_notifier_unregister(struct preempt_notifier *notifier); · line 365

Quoted 4 lines · Kent Overstreet
include/linux/preempt.h +3 -1
-	INIT_HLIST_NODE(&notifier->link);
+	/* INIT_HLIST_NODE() open coded, to avoid dependency on list.h */
+	notifier->link.next = NULL;
+	notifier->link.pprev = NULL;

Arguably INIT_HLIST_NODE() belongs in types.h -- we already have RCUREF_INIT() and ATOMIC_INIT() in there.

I think I'd prefer to keep types.h as minimal as possible - as soon as we start putting non type stuff in there people won't know what the distinction is and it'll grow.

Quoted 8 lines
Quoted 3 lines

preempt.h is a bit unusual too, normally we'd just split out a _types.h header there but it's not so easy to split up usefully.

I don't feel like I have NAK power, but if I did, I would NAK open coding of INIT_HLIST_HEAD() or anything like it. I would expect some $maintainer to do likewise, but I could be surprised.

There is another solution here (although I prefer moving INIT_HLIST_HEAD into types.h). The preprocessor allows redefinitions as long as the two definitions match exactly. So you can copy INIT_HLIST_HEAD into preempt.h and if the definition ever changes, we'll notice.

#82 lore raw

Re: [PATCH 46/50] preempt.h: Kill dependency on list.h

Quoted 27 lines · Matthew Wilcox
Quoted 17 lines · Randy Dunlap
Quoted 14 lines · Kent Overstreet
Quoted 8 lines · Matthew Wilcox

include/linux/preempt.h void preempt_notifier_unregister(struct preempt_notifier *notifier); · line 365

Quoted 4 lines · Kent Overstreet
include/linux/preempt.h +3 -1
-	INIT_HLIST_NODE(&notifier->link);
+	/* INIT_HLIST_NODE() open coded, to avoid dependency on list.h */
+	notifier->link.next = NULL;
+	notifier->link.pprev = NULL;

Arguably INIT_HLIST_NODE() belongs in types.h -- we already have RCUREF_INIT() and ATOMIC_INIT() in there.

I think I'd prefer to keep types.h as minimal as possible - as soon as we start putting non type stuff in there people won't know what the distinction is and it'll grow.

Quoted 8 lines
Quoted 3 lines

preempt.h is a bit unusual too, normally we'd just split out a _types.h header there but it's not so easy to split up usefully.

I don't feel like I have NAK power, but if I did, I would NAK open coding of INIT_HLIST_HEAD() or anything like it. I would expect some $maintainer to do likewise, but I could be surprised.

Quoted 4 lines

There is another solution here (although I prefer moving INIT_HLIST_HEAD into types.h). The preprocessor allows redefinitions as long as the two definitions match exactly. So you can copy INIT_HLIST_HEAD into preempt.h and if the definition ever changes, we'll notice.

I like it.

#83 lore raw

Re: [PATCH 46/50] preempt.h: Kill dependency on list.h

Quoted 28 lines · Kent Overstreet
Quoted 27 lines · Matthew Wilcox
Quoted 25 lines · Randy Dunlap
Quoted 10 lines · Kent Overstreet
Quoted 8 lines · Matthew Wilcox

include/linux/preempt.h void preempt_notifier_unregister(struct preempt_notifier *notifier); · line 365

Quoted 4 lines · Kent Overstreet
include/linux/preempt.h +3 -1
-	INIT_HLIST_NODE(&notifier->link);
+	/* INIT_HLIST_NODE() open coded, to avoid dependency on list.h */
+	notifier->link.next = NULL;
+	notifier->link.pprev = NULL;

Arguably INIT_HLIST_NODE() belongs in types.h -- we already have RCUREF_INIT() and ATOMIC_INIT() in there.

Quoted 7 lines

I think I'd prefer to keep types.h as minimal as possible - as soon as we start putting non type stuff in there people won't know what the distinction is and it'll grow.

preempt.h is a bit unusual too, normally we'd just split out a _types.h header there but it's not so easy to split up usefully.

I don't feel like I have NAK power, but if I did, I would NAK open coding of INIT_HLIST_HEAD() or anything like it. I would expect some $maintainer to do likewise, but I could be surprised.

Quoted 6 lines
Quoted 4 lines

There is another solution here (although I prefer moving INIT_HLIST_HEAD into types.h). The preprocessor allows redefinitions as long as the two definitions match exactly. So you can copy INIT_HLIST_HEAD into preempt.h and if the definition ever changes, we'll notice.

I like it.

Possible to revert 490d6ab170c9 ? although with something list this inserted:

	struct hlist_node *_p = h;

and then use _p instead of h (or the old macro's 'ptr')

The code looks the same to me, although I could have mucked something
up: https://godbolt.org/z/z76nsqGx3

although Andrew prefers inlines for type checking.

Signature · 3 lines
#Randy
https://people.kernel.org/tglx/notes-about-netiquette
https://subspace.kernel.org/etiquette.html
#84 lore raw

Re: [PATCH 46/50] preempt.h: Kill dependency on list.h

Quoted 41 lines · Randy Dunlap
Quoted 28 lines · Kent Overstreet
Quoted 27 lines · Matthew Wilcox
Quoted 25 lines · Randy Dunlap
Quoted 10 lines · Kent Overstreet
Quoted 8 lines · Matthew Wilcox

Review

Quoted 4 lines · Kent Overstreet
(quoted diff) +3 -1
-	INIT_HLIST_NODE(&notifier->link);
+	/* INIT_HLIST_NODE() open coded, to avoid dependency on list.h */
+	notifier->link.next = NULL;
+	notifier->link.pprev = NULL;

Arguably INIT_HLIST_NODE() belongs in types.h -- we already have RCUREF_INIT() and ATOMIC_INIT() in there.

Quoted 7 lines

I think I'd prefer to keep types.h as minimal as possible - as soon as we start putting non type stuff in there people won't know what the distinction is and it'll grow.

preempt.h is a bit unusual too, normally we'd just split out a _types.h header there but it's not so easy to split up usefully.

I don't feel like I have NAK power, but if I did, I would NAK open coding of INIT_HLIST_HEAD() or anything like it. I would expect some $maintainer to do likewise, but I could be surprised.

Quoted 6 lines
Quoted 4 lines

There is another solution here (although I prefer moving INIT_HLIST_HEAD into types.h). The preprocessor allows redefinitions as long as the two definitions match exactly. So you can copy INIT_HLIST_HEAD into preempt.h and if the definition ever changes, we'll notice.

I like it.

Possible to revert 490d6ab170c9 ? although with something list this inserted:

Quoted 7 lines
	struct hlist_node *_p = h;

and then use _p instead of h (or the old macro's 'ptr')

The code looks the same to me, although I could have mucked something
up: https://godbolt.org/z/z76nsqGx3

although Andrew prefers inlines for type checking.

I prefer inlines whenever possible too, a macro should really be a signal that 'something interesting is going on here'.

I'm just going with my original version.

#85 lore raw

Re: [PATCH 46/50] preempt.h: Kill dependency on list.h

In reply to Randy Dunlap
Quoted 17 lines · Randy Dunlap
Quoted 14 lines · Kent Overstreet
Quoted 8 lines · Matthew Wilcox

include/linux/preempt.h void preempt_notifier_unregister(struct preempt_notifier *notifier); · line 365

Quoted 4 lines · Kent Overstreet
include/linux/preempt.h +3 -1
-	INIT_HLIST_NODE(&notifier->link);
+	/* INIT_HLIST_NODE() open coded, to avoid dependency on list.h */
+	notifier->link.next = NULL;
+	notifier->link.pprev = NULL;

Arguably INIT_HLIST_NODE() belongs in types.h -- we already have RCUREF_INIT() and ATOMIC_INIT() in there.

I think I'd prefer to keep types.h as minimal as possible - as soon as we start putting non type stuff in there people won't know what the distinction is and it'll grow.

Quoted 8 lines
Quoted 3 lines

preempt.h is a bit unusual too, normally we'd just split out a _types.h header there but it's not so easy to split up usefully.

I don't feel like I have NAK power, but if I did, I would NAK open coding of INIT_HLIST_HEAD() or anything like it. I would expect some $maintainer to do likewise, but I could be surprised.

It's INIT_HLIST_HEAD(), there's approximately zero chance of the implementation changing, and there's a comment.

#86 lore raw

Re: [PATCH 46/50] preempt.h: Kill dependency on list.h

Quoted 22 lines · Kent Overstreet
Quoted 21 lines · Randy Dunlap
Quoted 17 lines · Kent Overstreet
Quoted 8 lines · Matthew Wilcox

include/linux/preempt.h void preempt_notifier_unregister(struct preempt_notifier *notifier); · line 365

Quoted 4 lines · Kent Overstreet
include/linux/preempt.h +3 -1
-	INIT_HLIST_NODE(&notifier->link);
+	/* INIT_HLIST_NODE() open coded, to avoid dependency on list.h */
+	notifier->link.next = NULL;
+	notifier->link.pprev = NULL;

Arguably INIT_HLIST_NODE() belongs in types.h -- we already have RCUREF_INIT() and ATOMIC_INIT() in there.

I think I'd prefer to keep types.h as minimal as possible - as soon as we start putting non type stuff in there people won't know what the distinction is and it'll grow.

preempt.h is a bit unusual too, normally we'd just split out a _types.h header there but it's not so easy to split up usefully.

Quoted 7 lines
Quoted 4 lines

I don't feel like I have NAK power, but if I did, I would NAK open coding of INIT_HLIST_HEAD() or anything like it. I would expect some $maintainer to do likewise, but I could be surprised.

It's INIT_HLIST_HEAD(), there's approximately zero chance of the implementation changing, and there's a comment.

s/_HEAD/_NODE/ for both of us. :)

Signature · 3 lines
#Randy
https://people.kernel.org/tglx/notes-about-netiquette
https://subspace.kernel.org/etiquette.html
#87 lore raw

PATCH 47/50 thread_info, uaccess.h: Move HARDENED_USERCOPY to better location

In reply to Kent Overstreet

thread_info.h is needed by sched.h, and we're trying to slim down dependencies there - bug.h is a big one.

And the HARDENED_USERCOPY stuff is used in uaccess.h, so it makes more sense there anyways.

---
 include/linux/thread_info.h | 49 -------------------------------------
 include/linux/uaccess.h     | 49 +++++++++++++++++++++++++++++++++++++
 include/linux/uio.h         |  2 +-
 3 files changed, 50 insertions(+), 50 deletions(-)
include/linux/thread_info.h +0 -49
index 9ea0b28068f4..85d99c556cb5 100644
@@ -10,7 +10,6 @@
 
 #include <linux/types.h>
 #include <linux/limits.h>
-#include <linux/bug.h>
 #include <linux/restart_block.h>
 #include <linux/errno.h>
 
@@ -204,54 +203,6 @@ static inline int arch_within_stack_frames(const void * const stack,
 }
 #endif
 
-#ifdef CONFIG_HARDENED_USERCOPY
-extern void __check_object_size(const void *ptr, unsigned long n,
-					bool to_user);
-
-static __always_inline void check_object_size(const void *ptr, unsigned long n,
-					      bool to_user)
-{
-	if (!__builtin_constant_p(n))
-		__check_object_size(ptr, n, to_user);
-}
-#else
-static inline void check_object_size(const void *ptr, unsigned long n,
-				     bool to_user)
-{ }
-#endif /* CONFIG_HARDENED_USERCOPY */
-
-extern void __compiletime_error("copy source size is too small")
-__bad_copy_from(void);
-extern void __compiletime_error("copy destination size is too small")
-__bad_copy_to(void);
-
-void __copy_overflow(int size, unsigned long count);
-
-static inline void copy_overflow(int size, unsigned long count)
-{
-	if (IS_ENABLED(CONFIG_BUG))
-		__copy_overflow(size, count);
-}
-
-static __always_inline __must_check bool
-check_copy_size(const void *addr, size_t bytes, bool is_source)
-{
-	int sz = __builtin_object_size(addr, 0);
-	if (unlikely(sz >= 0 && sz < bytes)) {
-		if (!__builtin_constant_p(bytes))
-			copy_overflow(sz, bytes);
-		else if (is_source)
-			__bad_copy_from();
-		else
-			__bad_copy_to();
-		return false;
-	}
-	if (WARN_ON_ONCE(bytes > INT_MAX))
-		return false;
-	check_object_size(addr, bytes, is_source);
-	return true;
-}
-
 #ifndef arch_setup_new_exec
 static inline void arch_setup_new_exec(void) { }
 #endif
include/linux/uaccess.h +49 -0

61 lines not on this page · raw message

include/linux/uio.h +1 -1
index b6214cbf2a43..084262b68106 100644
@@ -6,7 +6,7 @@
 #define __LINUX_UIO_H
 
 #include <linux/kernel.h>
-#include <linux/thread_info.h>
+#include <linux/uaccess.h>
 #include <linux/mm_types.h>
 #include <uapi/linux/uio.h>
 
Signature · 1 line
2.43.0
#88 lore raw

PATCH 48/50 Kill unnecessary kernel.h include

In reply to Kent Overstreet

More trimming down unnecessary includes.

---
 arch/x86/include/asm/current.h | 1 +
 arch/x86/include/asm/percpu.h  | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
arch/x86/include/asm/current.h +1 -0
index a1168e7b69e5..dd4b67101bb7 100644
@@ -2,6 +2,7 @@
 #ifndef _ASM_X86_CURRENT_H
 #define _ASM_X86_CURRENT_H
 
+#include <linux/build_bug.h>
 #include <linux/compiler.h>
 
 #ifndef __ASSEMBLY__
arch/x86/include/asm/percpu.h +1 -1
index 20624b80f890..5e01883eb51e 100644
@@ -24,8 +24,8 @@
 
 #else /* ...!ASSEMBLY */
 
-#include <linux/kernel.h>
 #include <linux/stringify.h>
+#include <asm/asm.h>
 
 #ifdef CONFIG_SMP
 #define __percpu_prefix		"%%"__stringify(__percpu_seg)":"
Signature · 1 line
2.43.0
#89 lore raw

PATCH 49/50 kill unnecessary thread_info.h include

In reply to Kent Overstreet
---
 arch/x86/include/asm/fpu/types.h | 2 ++
 arch/x86/include/asm/preempt.h   | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)
arch/x86/include/asm/fpu/types.h +2 -0
index eb810074f1e7..3dad7cf25505 100644
@@ -5,6 +5,8 @@
 #ifndef _ASM_X86_FPU_H
 #define _ASM_X86_FPU_H
 
+#include <asm/page_types.h>
+
 /*
  * The legacy x87 FPU state format, as saved by FSAVE and
  * restored by the FRSTOR instructions:
arch/x86/include/asm/preempt.h +0 -1
index 4527e1430c6d..af77235fded6 100644
@@ -6,7 +6,6 @@
 #include <asm/percpu.h>
 #include <asm/current.h>
 
-#include <linux/thread_info.h>
 #include <linux/static_call_types.h>
 
 /* We use the MSB mostly because its available */
Signature · 1 line
2.43.0
#90 lore raw

PATCH 50/50 Kill sched.h dependency on rcupdate.h

In reply to Kent Overstreet

by moving cond_resched_rcu() to rcupdate.h, we can kill another big sched.h dependency.

---
 include/linux/rcupdate.h | 11 +++++++++++
 include/linux/sched.h    | 13 +++----------
 2 files changed, 14 insertions(+), 10 deletions(-)
include/linux/rcupdate.h +11 -0
index f7206b2623c9..8ebfa57e0164 100644
@@ -1058,4 +1058,15 @@ extern int rcu_normal;
 
 DEFINE_LOCK_GUARD_0(rcu, rcu_read_lock(), rcu_read_unlock())
 
+#if defined(CONFIG_DEBUG_ATOMIC_SLEEP) || !defined(CONFIG_PREEMPT_RCU)
+#define cond_resched_rcu()		\
+do {					\
+	rcu_read_unlock();		\
+	cond_resched();			\
+	rcu_read_lock();		\
+} while (0)
+#else
+#define cond_resched_rcu()
+#endif
+
 #endif /* __LINUX_RCUPDATE_H */
include/linux/sched.h +3 -10
index d528057c99e4..b781ac7e0a02 100644
@@ -10,8 +10,11 @@
 #include <uapi/linux/sched.h>
 
 #include <asm/current.h>
+#include <linux/thread_info.h>
+#include <linux/preempt.h>
 
 #include <linux/irqflags_types.h>
+#include <linux/smp_types.h>
 #include <linux/pid_types.h>
 #include <linux/sem_types.h>
 #include <linux/shm.h>
@@ -22,7 +25,6 @@
 #include <linux/timer_types.h>
 #include <linux/seccomp_types.h>
 #include <linux/nodemask_types.h>
-#include <linux/rcupdate.h>
 #include <linux/refcount_types.h>
 #include <linux/resource.h>
 #include <linux/latencytop.h>
@@ -2058,15 +2060,6 @@ extern int __cond_resched_rwlock_write(rwlock_t *lock);
 	__cond_resched_rwlock_write(lock);					\
 })
 
-static inline void cond_resched_rcu(void)
-{
-#if defined(CONFIG_DEBUG_ATOMIC_SLEEP) || !defined(CONFIG_PREEMPT_RCU)
-	rcu_read_unlock();
-	cond_resched();
-	rcu_read_lock();
-#endif
-}
-
 #ifdef CONFIG_PREEMPT_DYNAMIC
 
 extern bool preempt_model_none(void);
Signature · 1 line
2.43.0
maintainer
#91 lore raw

Re: [PATCH 50/50] Kill sched.h dependency on rcupdate.h

Quoted 4 lines · Kent Overstreet

by moving cond_resched_rcu() to rcupdate.h, we can kill another big sched.h dependency.

Could you please instead move the cond_resched_rcu() function to include/linux/rcupdate_wait.h? This would avoid breaking Ingo's separation that makes it possible to include rcupdate.h without also pulling in sched.h.

Thanx, Paul

Quoted 68 lines
---
 include/linux/rcupdate.h | 11 +++++++++++
 include/linux/sched.h    | 13 +++----------
 2 files changed, 14 insertions(+), 10 deletions(-)
include/linux/rcupdate.h +11 -0
index f7206b2623c9..8ebfa57e0164 100644
@@ -1058,4 +1058,15 @@ extern int rcu_normal;
 
 DEFINE_LOCK_GUARD_0(rcu, rcu_read_lock(), rcu_read_unlock())
 
+#if defined(CONFIG_DEBUG_ATOMIC_SLEEP) || !defined(CONFIG_PREEMPT_RCU)
+#define cond_resched_rcu()		\
+do {					\
+	rcu_read_unlock();		\
+	cond_resched();			\
+	rcu_read_lock();		\
+} while (0)
+#else
+#define cond_resched_rcu()
+#endif
+
 #endif /* __LINUX_RCUPDATE_H */
include/linux/sched.h +3 -10
index d528057c99e4..b781ac7e0a02 100644
@@ -10,8 +10,11 @@
 #include <uapi/linux/sched.h>
 
 #include <asm/current.h>
+#include <linux/thread_info.h>
+#include <linux/preempt.h>
 
 #include <linux/irqflags_types.h>
+#include <linux/smp_types.h>
 #include <linux/pid_types.h>
 #include <linux/sem_types.h>
 #include <linux/shm.h>
@@ -22,7 +25,6 @@
 #include <linux/timer_types.h>
 #include <linux/seccomp_types.h>
 #include <linux/nodemask_types.h>
-#include <linux/rcupdate.h>
 #include <linux/refcount_types.h>
 #include <linux/resource.h>
 #include <linux/latencytop.h>
@@ -2058,15 +2060,6 @@ extern int __cond_resched_rwlock_write(rwlock_t *lock);
 	__cond_resched_rwlock_write(lock);					\
 })
 
-static inline void cond_resched_rcu(void)
-{
-#if defined(CONFIG_DEBUG_ATOMIC_SLEEP) || !defined(CONFIG_PREEMPT_RCU)
-	rcu_read_unlock();
-	cond_resched();
-	rcu_read_lock();
-#endif
-}
-
 #ifdef CONFIG_PREEMPT_DYNAMIC
 
 extern bool preempt_model_none(void);
Signature · 1 line
2.43.0
#92 lore raw

Re: [PATCH 50/50] Kill sched.h dependency on rcupdate.h

Quoted 10 lines · Paul E. McKenney
Quoted 4 lines · Kent Overstreet

by moving cond_resched_rcu() to rcupdate.h, we can kill another big sched.h dependency.

Could you please instead move the cond_resched_rcu() function to include/linux/rcupdate_wait.h? This would avoid breaking Ingo's separation that makes it possible to include rcupdate.h without also pulling in sched.h.

Yep, will do.

#93 lore raw

Re: [PATCH 50/50] Kill sched.h dependency on rcupdate.h

In reply to Kent Overstreet

Hi Kent,

Quoted 4 lines · Kent Overstreet

by moving cond_resched_rcu() to rcupdate.h, we can kill another big sched.h dependency.

Thanks for your patch, which is now commit dc00f26faea81dc0 ("Kill sched.h dependency on rcupdate.h") in next-20231220.

Reported-by [email protected]
$ make ARCH=m68k defconfig arch/m68k/kernel/asm-offsets.i
*** Default configuration is based on 'multi_defconfig'
#
# No change to .config
#
  UPD     include/config/kernel.release
  UPD     include/generated/utsrelease.h
  CC      arch/m68k/kernel/asm-offsets.s
In file included from ./include/asm-generic/bug.h:7,
                 from ./arch/m68k/include/asm/bug.h:32,
                 from ./include/linux/bug.h:5,
                 from ./include/linux/thread_info.h:13,
                 from ./arch/m68k/include/asm/processor.h:11,
                 from ./include/linux/sched.h:13,
                 from arch/m68k/kernel/asm-offsets.c:15:
./arch/m68k/include/asm/processor.h: In function ‘set_fc’:
./arch/m68k/include/asm/processor.h:91:15: error: implicit declaration
of function ‘in_interrupt’ [-Werror=implicit-function-declaration]
   91 |  WARN_ON_ONCE(in_interrupt());
      |               ^~~~~~~~~~~~
./include/linux/once_lite.h:28:27: note: in definition of macro
‘DO_ONCE_LITE_IF’
   28 |   bool __ret_do_once = !!(condition);   \
      |                           ^~~~~~~~~
./arch/m68k/include/asm/processor.h:91:2: note: in expansion of macro
‘WARN_ON_ONCE’
   91 |  WARN_ON_ONCE(in_interrupt());
      |  ^~~~~~~~~~~~
cc1: some warnings being treated as errors
make[3]: *** [scripts/Makefile.build:116:
arch/m68k/kernel/asm-offsets.s] Error 1
make[2]: *** [Makefile:1191: prepare0] Error 2
make[1]: *** [Makefile:350: __build_one_by_one] Error 2
make: *** [Makefile:234: __sub-make] Error 2
Quoted 48 lines
include/linux/rcupdate.h +11 -0
@@ -1058,4 +1058,15 @@ extern int rcu_normal;
 
 DEFINE_LOCK_GUARD_0(rcu, rcu_read_lock(), rcu_read_unlock())
 
+#if defined(CONFIG_DEBUG_ATOMIC_SLEEP) || !defined(CONFIG_PREEMPT_RCU)
+#define cond_resched_rcu()             \
+do {                                   \
+       rcu_read_unlock();              \
+       cond_resched();                 \
+       rcu_read_lock();                \
+} while (0)
+#else
+#define cond_resched_rcu()
+#endif
+
 #endif /* __LINUX_RCUPDATE_H */
include/linux/sched.h +3 -3
index d528057c99e4..b781ac7e0a02 100644
@@ -10,8 +10,11 @@
 #include <uapi/linux/sched.h>
 
 #include <asm/current.h>
+#include <linux/thread_info.h>
+#include <linux/preempt.h>
 
 #include <linux/irqflags_types.h>
+#include <linux/smp_types.h>
 #include <linux/pid_types.h>
 #include <linux/sem_types.h>
 #include <linux/shm.h>
@@ -22,7 +25,6 @@
 #include <linux/timer_types.h>
 #include <linux/seccomp_types.h>
 #include <linux/nodemask_types.h>
-#include <linux/rcupdate.h>
 #include <linux/refcount_types.h>
 #include <linux/resource.h>
 #include <linux/latencytop.h>
@@ -2058,15 +2060,6 @@ extern int __cond_resched_rwlock_write(rwlock_t *lock);
        __cond_resched_rwlock_write(lock);                                      \
 })
 
-static inline void cond_resched_rcu(void)
-{

include/linux/sched.h extern int __cond_resched_rwlock_write(rwlock_t *lock); · line 2065

Quoted 10 lines
include/linux/sched.h +0 -7
-#if defined(CONFIG_DEBUG_ATOMIC_SLEEP) || !defined(CONFIG_PREEMPT_RCU)
-       rcu_read_unlock();
-       cond_resched();
-       rcu_read_lock();
-#endif
-}
-
 #ifdef CONFIG_PREEMPT_DYNAMIC
 
 extern bool preempt_model_none(void);

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#94 lore raw

Re: [PATCH 50/50] Kill sched.h dependency on rcupdate.h

Quoted 40 lines · Geert Uytterhoeven

Hi Kent,

Quoted 4 lines · Kent Overstreet

by moving cond_resched_rcu() to rcupdate.h, we can kill another big sched.h dependency.

Thanks for your patch, which is now commit dc00f26faea81dc0 ("Kill sched.h dependency on rcupdate.h") in next-20231220.

Reported-by [email protected]
$ make ARCH=m68k defconfig arch/m68k/kernel/asm-offsets.i
*** Default configuration is based on 'multi_defconfig'
#
# No change to .config
#
  UPD     include/config/kernel.release
  UPD     include/generated/utsrelease.h
  CC      arch/m68k/kernel/asm-offsets.s
In file included from ./include/asm-generic/bug.h:7,
                 from ./arch/m68k/include/asm/bug.h:32,
                 from ./include/linux/bug.h:5,
                 from ./include/linux/thread_info.h:13,
                 from ./arch/m68k/include/asm/processor.h:11,
                 from ./include/linux/sched.h:13,
                 from arch/m68k/kernel/asm-offsets.c:15:
./arch/m68k/include/asm/processor.h: In function ‘set_fc’:
./arch/m68k/include/asm/processor.h:91:15: error: implicit declaration
of function ‘in_interrupt’ [-Werror=implicit-function-declaration]
   91 |  WARN_ON_ONCE(in_interrupt());
      |               ^~~~~~~~~~~~
./include/linux/once_lite.h:28:27: note: in definition of macro
‘DO_ONCE_LITE_IF’
   28 |   bool __ret_do_once = !!(condition);   \
      |                           ^~~~~~~~~
./arch/m68k/include/asm/processor.h:91:2: note: in expansion of macro
‘WARN_ON_ONCE’
Quoted 8 lines
   91 |  WARN_ON_ONCE(in_interrupt());
      |  ^~~~~~~~~~~~
cc1: some warnings being treated as errors
make[3]: *** [scripts/Makefile.build:116:
arch/m68k/kernel/asm-offsets.s] Error 1
make[2]: *** [Makefile:1191: prepare0] Error 2
make[1]: *** [Makefile:350: __build_one_by_one] Error 2
make: *** [Makefile:234: __sub-make] Error 2

Applying this fix:

commit 0d7bdfe9726b275c7e9398047763a144c790b575

Author: Kent Overstreet <[email protected]>
Date:   Wed Dec 20 16:39:21 2023 -0500

m68k: Fix missing include

arch/m68k/include/asm/processor.h +1 -0
index 7a2da780830b..8f2676c3a988 100644
@@ -8,6 +8,7 @@
 #ifndef __ASM_M68K_PROCESSOR_H
 #define __ASM_M68K_PROCESSOR_H
 
+#include <linux/preempt.h>
 #include <linux/thread_info.h>
 #include <asm/fpu.h>
 #include <asm/ptrace.h>
maintainer Acked-by
#95 lore raw

Re: [PATCH 50/50] Kill sched.h dependency on rcupdate.h

Hi Kent,

Quoted 50 lines · Kent Overstreet
Quoted 38 lines · Geert Uytterhoeven
Quoted 4 lines · Kent Overstreet

by moving cond_resched_rcu() to rcupdate.h, we can kill another big sched.h dependency.

Thanks for your patch, which is now commit dc00f26faea81dc0 ("Kill sched.h dependency on rcupdate.h") in next-20231220.

Reported-by [email protected]
$ make ARCH=m68k defconfig arch/m68k/kernel/asm-offsets.i
*** Default configuration is based on 'multi_defconfig'
#
# No change to .config
#
  UPD     include/config/kernel.release
  UPD     include/generated/utsrelease.h
  CC      arch/m68k/kernel/asm-offsets.s
In file included from ./include/asm-generic/bug.h:7,
                 from ./arch/m68k/include/asm/bug.h:32,
                 from ./include/linux/bug.h:5,
                 from ./include/linux/thread_info.h:13,
                 from ./arch/m68k/include/asm/processor.h:11,
                 from ./include/linux/sched.h:13,
                 from arch/m68k/kernel/asm-offsets.c:15:
./arch/m68k/include/asm/processor.h: In function ‘set_fc’:
./arch/m68k/include/asm/processor.h:91:15: error: implicit declaration
of function ‘in_interrupt’ [-Werror=implicit-function-declaration]
   91 |  WARN_ON_ONCE(in_interrupt());
      |               ^~~~~~~~~~~~
./include/linux/once_lite.h:28:27: note: in definition of macro
‘DO_ONCE_LITE_IF’
   28 |   bool __ret_do_once = !!(condition);   \
      |                           ^~~~~~~~~
./arch/m68k/include/asm/processor.h:91:2: note: in expansion of macro
‘WARN_ON_ONCE’
Quoted 8 lines
   91 |  WARN_ON_ONCE(in_interrupt());
      |  ^~~~~~~~~~~~
cc1: some warnings being treated as errors
make[3]: *** [scripts/Makefile.build:116:
arch/m68k/kernel/asm-offsets.s] Error 1
make[2]: *** [Makefile:1191: prepare0] Error 2
make[1]: *** [Makefile:350: __build_one_by_one] Error 2
make: *** [Makefile:234: __sub-make] Error 2

Applying this fix:

Quoted 7 lines

commit 0d7bdfe9726b275c7e9398047763a144c790b575

Author: Kent Overstreet <[email protected]>
Date:   Wed Dec 20 16:39:21 2023 -0500

m68k: Fix missing include

LGTM.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds