locking/seqlock, headers: Untangle the spaghetti monster
authorPeter Zijlstra <peterz@infradead.org>
Thu, 6 Aug 2020 12:35:11 +0000 (14:35 +0200)
committerIngo Molnar <mingo@kernel.org>
Thu, 6 Aug 2020 14:13:13 +0000 (16:13 +0200)
By using lockdep_assert_*() from seqlock.h, the spaghetti monster
attacked.

Attack back by reducing seqlock.h dependencies from two key high level headers:

 - <linux/seqlock.h>:               -Remove <linux/ww_mutex.h>
 - <linux/time.h>:                  -Remove <linux/seqlock.h>
 - <linux/sched.h>:                 +Add    <linux/seqlock.h>

The price was to add it to sched.h ...

Core header fallout, we add direct header dependencies instead of gaining them
parasitically from higher level headers:

 - <linux/dynamic_queue_limits.h>:  +Add <asm/bug.h>
 - <linux/hrtimer.h>:               +Add <linux/seqlock.h>
 - <linux/ktime.h>:                 +Add <asm/bug.h>
 - <linux/lockdep.h>:               +Add <linux/smp.h>
 - <linux/sched.h>:                 +Add <linux/seqlock.h>
 - <linux/videodev2.h>:             +Add <linux/kernel.h>

Arch headers fallout:

 - PARISC: <asm/timex.h>:           +Add <asm/special_insns.h>
 - SH:     <asm/io.h>:              +Add <asm/page.h>
 - SPARC:  <asm/timer_64.h>:        +Add <uapi/asm/asi.h>
 - SPARC:  <asm/vvar.h>:            +Add <asm/processor.h>, <asm/barrier.h>
                                    -Remove <linux/seqlock.h>
 - X86:    <asm/fixmap.h>:          +Add <asm/pgtable_types.h>
                                    -Remove <asm/acpi.h>

There's also a bunch of parasitic header dependency fallout in .c files, not listed
separately.

[ mingo: Extended the changelog, split up & fixed the original patch. ]

Co-developed-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20200804133438.GK2674@hirez.programming.kicks-ass.net
29 files changed:
arch/sh/include/asm/io.h
arch/sh/kernel/machvec.c
arch/sparc/include/asm/timer_64.h
arch/sparc/include/asm/vvar.h
arch/sparc/kernel/vdso.c
arch/x86/include/asm/fixmap.h
arch/x86/kernel/apic/apic_noop.c
arch/x86/kernel/apic/hw_nmi.c
arch/x86/kernel/apic/probe_64.c
arch/x86/kernel/cpu/amd.c
arch/x86/kernel/cpu/common.c
arch/x86/kernel/cpu/hygon.c
arch/x86/kernel/cpu/intel.c
arch/x86/kernel/jailhouse.c
arch/x86/kernel/tsc_msr.c
arch/x86/mm/init_32.c
arch/x86/xen/apic.c
arch/x86/xen/smp_hvm.c
arch/x86/xen/suspend_pv.c
include/linux/dynamic_queue_limits.h
include/linux/hrtimer.h
include/linux/ktime.h
include/linux/lockdep.h
include/linux/mutex.h
include/linux/sched.h
include/linux/seqlock.h
include/linux/time.h
include/linux/videodev2.h
include/linux/ww_mutex.h

index 26f0f9b4658b203526a221f71869e4911f193067..ec587b583822e0bb887f4ec2e7a6dee4ea4f88da 100644 (file)
@@ -17,6 +17,7 @@
 #include <asm/cache.h>
 #include <asm/addrspace.h>
 #include <asm/machvec.h>
+#include <asm/page.h>
 #include <linux/pgtable.h>
 #include <asm-generic/iomap.h>
 
index beadbbdb44867759cd4a835fb61f56a26efba8b2..76bd8955d4fe410b6e3002c2025c41df84c1c2cf 100644 (file)
@@ -15,6 +15,7 @@
 #include <asm/setup.h>
 #include <asm/io.h>
 #include <asm/irq.h>
+#include <asm/processor.h>
 
 #define MV_NAME_SIZE 32
 
index c7e4fb601a5748e7104be1bdccffe754784780c7..dcfad4613e1875cc74e90d0420d313bf5d79ae59 100644 (file)
@@ -7,6 +7,7 @@
 #ifndef _SPARC64_TIMER_H
 #define _SPARC64_TIMER_H
 
+#include <uapi/asm/asi.h>
 #include <linux/types.h>
 #include <linux/init.h>
 
index 0289503d1cb0752b8b7c40b1ee6b473ad77d62ea..6eaf5cfcaae1319808e63884d624899895d9b6a5 100644 (file)
@@ -6,7 +6,8 @@
 #define _ASM_SPARC_VVAR_DATA_H
 
 #include <asm/clocksource.h>
-#include <linux/seqlock.h>
+#include <asm/processor.h>
+#include <asm/barrier.h>
 #include <linux/time.h>
 #include <linux/types.h>
 
index 58880662b271d11c76ec3f8153726eb823c69807..0e27437eb97bff16aba53b1634c7e9fa7db20b46 100644 (file)
@@ -7,7 +7,6 @@
  *  a different vsyscall implementation for Linux/IA32 and for the name.
  */
 
-#include <linux/seqlock.h>
 #include <linux/time.h>
 #include <linux/timekeeper_internal.h>
 
index b9527a54db995a08df022355218488fb4dd09684..0f0dd645b59420613252349b349d630e70c4078b 100644 (file)
@@ -26,9 +26,9 @@
 
 #ifndef __ASSEMBLY__
 #include <linux/kernel.h>
-#include <asm/acpi.h>
 #include <asm/apicdef.h>
 #include <asm/page.h>
+#include <asm/pgtable_types.h>
 #ifdef CONFIG_X86_32
 #include <linux/threads.h>
 #include <asm/kmap_types.h>
index 98c9bb75d1854d9ca14c0c43779c8da161dbb954..780c702969b7ab3ef60ed711202ca555436b15c7 100644 (file)
@@ -10,6 +10,7 @@
  * like self-ipi, etc...
  */
 #include <linux/cpumask.h>
+#include <linux/thread_info.h>
 
 #include <asm/apic.h>
 
index d1fc62a6732074dca8a376664a80e8a7099dcae0..34a992e275ef42b94e6f0fb057ff160617cd972a 100644 (file)
@@ -9,6 +9,7 @@
  *  Bits copied from original nmi.c file
  *
  */
+#include <linux/thread_info.h>
 #include <asm/apic.h>
 #include <asm/nmi.h>
 
index 29f0e0984557ebb152d7fcf971398d0e1cf5b63b..bd3835d6b5358dcfb7be957842f0d6205ff108c2 100644 (file)
@@ -8,6 +8,7 @@
  * Martin Bligh, Andi Kleen, James Bottomley, John Stultz, and
  * James Cleverdon.
  */
+#include <linux/thread_info.h>
 #include <asm/apic.h>
 
 #include "local.h"
index d4806eac9325ca13e0cf98cfe4c70f3a141cb63e..dcc3d943c68fec33e8708da0f5b7f02b99414a2d 100644 (file)
@@ -15,6 +15,7 @@
 #include <asm/cpu.h>
 #include <asm/spec-ctrl.h>
 #include <asm/smp.h>
+#include <asm/numa.h>
 #include <asm/pci-direct.h>
 #include <asm/delay.h>
 #include <asm/debugreg.h>
index 95c090a45b4b4a9cc5cf463176183378743cb93f..52b565016eb1f3abe897597b730ebaf94b9888ad 100644 (file)
@@ -45,6 +45,7 @@
 #include <asm/mtrr.h>
 #include <asm/hwcap2.h>
 #include <linux/numa.h>
+#include <asm/numa.h>
 #include <asm/asm.h>
 #include <asm/bugs.h>
 #include <asm/cpu.h>
index 4e28c1fc874997ac1274e348d65e998a1958458c..ac6c30e5801da2c19ca65ae2b0811c0791587c16 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <asm/cpu.h>
 #include <asm/smp.h>
+#include <asm/numa.h>
 #include <asm/cacheinfo.h>
 #include <asm/spec-ctrl.h>
 #include <asm/delay.h>
index 0ab48f1cdf848faf6e9e6429d85f4dc815324f68..6eb42d7a3dfdfc6118fa4baf497a2ae9332f8031 100644 (file)
@@ -23,6 +23,7 @@
 #include <asm/cmdline.h>
 #include <asm/traps.h>
 #include <asm/resctrl.h>
+#include <asm/numa.h>
 
 #ifdef CONFIG_X86_64
 #include <linux/topology.h>
index 2caf5b990bf6a7b115eeef259caab9f95ed1aafb..4eb8f2d19a872f7bce16e680c7600ab9708b59c6 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/serial_8250.h>
 #include <asm/apic.h>
 #include <asm/io_apic.h>
+#include <asm/acpi.h>
 #include <asm/cpu.h>
 #include <asm/hypervisor.h>
 #include <asm/i8259.h>
index 4fec6f3a1858b2cc8d440716a230cb6cca3e9890..46c72f2ec32fa4ad1dc240e93e01f23d4f2b1066 100644 (file)
@@ -7,6 +7,7 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/thread_info.h>
 
 #include <asm/apic.h>
 #include <asm/cpu_device_id.h>
index 8b4afad84f4a454dfd555277e238dc06ab7d444a..d46a5cf6ccb0ff13b1e5de3522a603952dc719c0 100644 (file)
@@ -52,6 +52,7 @@
 #include <asm/cpu_entry_area.h>
 #include <asm/init.h>
 #include <asm/pgtable_areas.h>
+#include <asm/numa.h>
 
 #include "mm_internal.h"
 
index 2df7d089ad545df3002130bbe1472c96c774557b..1aff4ae65655d87411bf96c5bd8f2ff9952fd5e8 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/init.h>
+#include <linux/thread_info.h>
 
 #include <asm/x86_init.h>
 #include <asm/apic.h>
index f8d39440b2923fff0be8848e886db829a51b2e1f..f5e7db4f82abb63039ce49271ecbe87f857a1655 100644 (file)
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
+#include <linux/thread_info.h>
 #include <asm/smp.h>
 
 #include <xen/events.h>
index 8303b58c79a983085235a29c1b6aa653f11d1091..cae9660f4c67f4ca94441bd4c01ff17b18406bea 100644 (file)
@@ -1,11 +1,11 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/types.h>
 
-#include <asm/fixmap.h>
-
 #include <asm/xen/hypercall.h>
 #include <asm/xen/page.h>
 
+#include <asm/fixmap.h>
+
 #include "xen-ops.h"
 
 void xen_pv_pre_suspend(void)
index 99fc06f0afc1b6c818ddc19b09ecdebc29d2bed2..407c2f281b6446e203e5a88ca36bc284370f0cb6 100644 (file)
@@ -38,6 +38,8 @@
 
 #ifdef __KERNEL__
 
+#include <asm/bug.h>
+
 struct dql {
        /* Fields accessed in enqueue path (dql_queued) */
        unsigned int    num_queued;             /* Total ever queued */
index 25993b86ac5cacc1cbb651f8227e25d00adf531b..107cedd7019a4d2fa907231b91397b4118e7b7f5 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/init.h>
 #include <linux/list.h>
 #include <linux/percpu.h>
+#include <linux/seqlock.h>
 #include <linux/timer.h>
 #include <linux/timerqueue.h>
 
index 42d2e6ac35f29036583e831723f0e15732eda729..a12b5523cc18e699fea0f36ca49b65dbfdfeb015 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <linux/time.h>
 #include <linux/jiffies.h>
+#include <asm/bug.h>
 
 /* Nanosecond scalar representation for kernel time values */
 typedef s64    ktime_t;
index 39a35699d0d69e3c773cd2ae4dbeb7a0e776ab31..62a382d1845bd56a2cd7c6f4398056723e39142f 100644 (file)
@@ -11,6 +11,7 @@
 #define __LINUX_LOCKDEP_H
 
 #include <linux/lockdep_types.h>
+#include <linux/smp.h>
 #include <asm/percpu.h>
 
 struct task_struct;
index ae197cc00cc874070ca106667cccdd498eed151d..dcd185cbfe793b6f9d325dfabd6db87297d32383 100644 (file)
@@ -65,6 +65,17 @@ struct mutex {
 #endif
 };
 
+struct ww_class;
+struct ww_acquire_ctx;
+
+struct ww_mutex {
+       struct mutex base;
+       struct ww_acquire_ctx *ctx;
+#ifdef CONFIG_DEBUG_MUTEXES
+       struct ww_class *ww_class;
+#endif
+};
+
 /*
  * This is the control structure for tasks blocked on mutex,
  * which resides on the blocked task's kernel stack:
index 9a9d8263962da9f9725b2634e96f564cb71aacf3..7c7a9499d7bc7151f581bfe9983790da23039bfb 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/task_io_accounting.h>
 #include <linux/posix-timers.h>
 #include <linux/rseq.h>
+#include <linux/seqlock.h>
 #include <linux/kcsan.h>
 
 /* task_struct member predeclarations (sorted alphabetically): */
index a076f783aa36161b6801f59781e0d9fb8d4b5672..962d9768945f0a26d366fb663cccaf6aeaeff635 100644 (file)
@@ -19,7 +19,6 @@
 #include <linux/mutex.h>
 #include <linux/preempt.h>
 #include <linux/spinlock.h>
-#include <linux/ww_mutex.h>
 
 #include <asm/processor.h>
 
index 4c325bf44ce001238467e28019af6e42646a0d53..b142cb5f5a5331a4dad3be8f2776435d18a66d5b 100644 (file)
@@ -3,7 +3,6 @@
 #define _LINUX_TIME_H
 
 # include <linux/cache.h>
-# include <linux/seqlock.h>
 # include <linux/math64.h>
 # include <linux/time64.h>
 
index 16c0ed6c50a7f6ad67319c49108deabcba977a42..219037f4c08dadcc1a20e4736ddf88aba72f6d9c 100644 (file)
@@ -57,6 +57,7 @@
 #define __LINUX_VIDEODEV2_H
 
 #include <linux/time.h>     /* need struct timeval */
+#include <linux/kernel.h>
 #include <uapi/linux/videodev2.h>
 
 #endif /* __LINUX_VIDEODEV2_H */
index d7554252404cb3d8f53f33b911149513d187e0e5..850424e5d03061ea22c33b215ef3192119d652dc 100644 (file)
@@ -48,14 +48,6 @@ struct ww_acquire_ctx {
 #endif
 };
 
-struct ww_mutex {
-       struct mutex base;
-       struct ww_acquire_ctx *ctx;
-#ifdef CONFIG_DEBUG_MUTEXES
-       struct ww_class *ww_class;
-#endif
-};
-
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 # define __WW_CLASS_MUTEX_INITIALIZER(lockname, class) \
                , .ww_class = class