Skip to content

Commit

Permalink
locking/seqlock, headers: Untangle the spaghetti monster
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Aug 6, 2020
1 parent b354519 commit 0cd39f4
Show file tree
Hide file tree
Showing 29 changed files with 38 additions and 15 deletions.
1 change: 1 addition & 0 deletions arch/sh/include/asm/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
1 change: 1 addition & 0 deletions arch/sh/kernel/machvec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions arch/sparc/include/asm/timer_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
3 changes: 2 additions & 1 deletion arch/sparc/include/asm/vvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
1 change: 0 additions & 1 deletion arch/sparc/kernel/vdso.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/asm/fixmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions arch/x86/kernel/apic/apic_noop.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* like self-ipi, etc...
*/
#include <linux/cpumask.h>
#include <linux/thread_info.h>

#include <asm/apic.h>

Expand Down
1 change: 1 addition & 0 deletions arch/x86/kernel/apic/hw_nmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Bits copied from original nmi.c file
*
*/
#include <linux/thread_info.h>
#include <asm/apic.h>
#include <asm/nmi.h>

Expand Down
1 change: 1 addition & 0 deletions arch/x86/kernel/apic/probe_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions arch/x86/kernel/cpu/amd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions arch/x86/kernel/cpu/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions arch/x86/kernel/cpu/hygon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions arch/x86/kernel/cpu/intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions arch/x86/kernel/jailhouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions arch/x86/kernel/tsc_msr.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include <linux/kernel.h>
#include <linux/thread_info.h>

#include <asm/apic.h>
#include <asm/cpu_device_id.h>
Expand Down
1 change: 1 addition & 0 deletions arch/x86/mm/init_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions arch/x86/xen/apic.c
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
1 change: 1 addition & 0 deletions arch/x86/xen/smp_hvm.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/thread_info.h>
#include <asm/smp.h>

#include <xen/events.h>
Expand Down
4 changes: 2 additions & 2 deletions arch/x86/xen/suspend_pv.c
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 2 additions & 0 deletions include/linux/dynamic_queue_limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions include/linux/hrtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
1 change: 1 addition & 0 deletions include/linux/ktime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions include/linux/lockdep.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define __LINUX_LOCKDEP_H

#include <linux/lockdep_types.h>
#include <linux/smp.h>
#include <asm/percpu.h>

struct task_struct;
Expand Down
11 changes: 11 additions & 0 deletions include/linux/mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -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): */
Expand Down
1 change: 0 additions & 1 deletion include/linux/seqlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
1 change: 0 additions & 1 deletion include/linux/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#define _LINUX_TIME_H

# include <linux/cache.h>
# include <linux/seqlock.h>
# include <linux/math64.h>
# include <linux/time64.h>

Expand Down
1 change: 1 addition & 0 deletions include/linux/videodev2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
8 changes: 0 additions & 8 deletions include/linux/ww_mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0cd39f4

Please sign in to comment.