[PATCH 33/50] Split out irqflags_types.h

Kent Overstreet posted 50 patches 2 years ago
Only 14 patches received!
[PATCH 33/50] Split out irqflags_types.h
Posted by Kent Overstreet 2 years ago
We're working on only pulling in type definitions to sched.h whenever
possible.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 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

diff --git a/include/linux/irqflags.h b/include/linux/irqflags.h
index 2b665c32f5fe..147feebd508c 100644
--- a/include/linux/irqflags.h
+++ b/include/linux/irqflags.h
@@ -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);
 
diff --git a/include/linux/irqflags_types.h b/include/linux/irqflags_types.h
new file mode 100644
index 000000000000..c13f0d915097
--- /dev/null
+++ b/include/linux/irqflags_types.h
@@ -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 */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 3a58d3d7d264..d799427f6d1b 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -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>
-- 
2.43.0
[PATCH 34/50] mm_types_task.h: Trim dependencies
Posted by Kent Overstreet 2 years ago
more sched.h header dependency trimming

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 include/linux/mm_types_task.h | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/include/linux/mm_types_task.h b/include/linux/mm_types_task.h
index aa44fff8bb9d..724a731d5c2b 100644
--- a/include/linux/mm_types_task.h
+++ b/include/linux/mm_types_task.h
@@ -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)
-- 
2.43.0
[PATCH 35/50] cpumask: Split out cpumask_types.h
Posted by Kent Overstreet 2 years ago
More sched.h dependency trimming: this will help to kill the printk.h
dependency.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 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

diff --git a/arch/x86/include/asm/tlbbatch.h b/arch/x86/include/asm/tlbbatch.h
index 1ad56eb3e8a8..0550dea70c0f 100644
--- a/arch/x86/include/asm/tlbbatch.h
+++ b/arch/x86/include/asm/tlbbatch.h
@@ -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 {
 	/*
diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
index cfb545841a2c..b710dc4cd858 100644
--- a/include/linux/cpumask.h
+++ b/include/linux/cpumask.h
@@ -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
diff --git a/include/linux/cpumask_types.h b/include/linux/cpumask_types.h
new file mode 100644
index 000000000000..f4c032c9a81a
--- /dev/null
+++ b/include/linux/cpumask_types.h
@@ -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 */
-- 
2.43.0
[PATCH 36/50] syscall_user_dispatch.h: split out *_types.h
Posted by Kent Overstreet 2 years ago
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.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 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

diff --git a/include/linux/sched.h b/include/linux/sched.h
index d799427f6d1b..fea6d913e004 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -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>
diff --git a/include/linux/syscall_user_dispatch.h b/include/linux/syscall_user_dispatch.h
index 641ca8880995..3858a6ffdd5c 100644
--- a/include/linux/syscall_user_dispatch.h
+++ b/include/linux/syscall_user_dispatch.h
@@ -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)
diff --git a/include/linux/syscall_user_dispatch_types.h b/include/linux/syscall_user_dispatch_types.h
new file mode 100644
index 000000000000..3be36b06c7d7
--- /dev/null
+++ b/include/linux/syscall_user_dispatch_types.h
@@ -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 */
-- 
2.43.0
[PATCH 37/50] x86/signal: kill dependency on time.h
Posted by Kent Overstreet 2 years ago
this is unecessary, and was pulling in printk.h from uapi headers

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 arch/x86/include/uapi/asm/signal.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/x86/include/uapi/asm/signal.h b/arch/x86/include/uapi/asm/signal.h
index 777c3a0f4e23..f777346450ec 100644
--- a/arch/x86/include/uapi/asm/signal.h
+++ b/arch/x86/include/uapi/asm/signal.h
@@ -4,7 +4,6 @@
 
 #ifndef __ASSEMBLY__
 #include <linux/types.h>
-#include <linux/time.h>
 #include <linux/compiler.h>
 
 /* Avoid too many header ordering problems.  */
-- 
2.43.0
[PATCH 38/50] uapi/linux/resource.h: fix include
Posted by Kent Overstreet 2 years ago
We should't be depending on time.h; we should only be pulling in other
uapi headers.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 include/uapi/linux/resource.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/resource.h b/include/uapi/linux/resource.h
index ac5d6a3031db..4fc22908bc09 100644
--- a/include/uapi/linux/resource.h
+++ b/include/uapi/linux/resource.h
@@ -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>
 
 /*
-- 
2.43.0
[PATCH 39/50] refcount: Split out refcount_types.h
Posted by Kent Overstreet 2 years ago
More trimming of sched.h dependencies.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 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

diff --git a/include/linux/refcount.h b/include/linux/refcount.h
index a62fcca97486..85c6df0d1bef 100644
--- a/include/linux/refcount.h
+++ b/include/linux/refcount.h
@@ -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)
diff --git a/include/linux/refcount_types.h b/include/linux/refcount_types.h
new file mode 100644
index 000000000000..162004f06edf
--- /dev/null
+++ b/include/linux/refcount_types.h
@@ -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 */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index fea6d913e004..f52977af1511 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -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>
-- 
2.43.0
[PATCH 40/50] seccomp: Split out seccomp_types.h
Posted by Kent Overstreet 2 years ago
More pruning of sched.h dependencies.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 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

diff --git a/include/linux/sched.h b/include/linux/sched.h
index f52977af1511..9bfa61ab2750 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -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>
diff --git a/include/linux/seccomp.h b/include/linux/seccomp.h
index 1ec0d8dc4b69..26a53cea5761 100644
--- a/include/linux/seccomp.h
+++ b/include/linux/seccomp.h
@@ -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)
diff --git a/include/linux/seccomp_types.h b/include/linux/seccomp_types.h
new file mode 100644
index 000000000000..c6184582a0a0
--- /dev/null
+++ b/include/linux/seccomp_types.h
@@ -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 */
-- 
2.43.0
[PATCH 41/50] uidgid: Split out uidgid_types.h
Posted by Kent Overstreet 2 years ago
More sched.h dependency pruning.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 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

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 9bfa61ab2750..157e7af36bb7 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -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): */
diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
index b0542cd11aeb..ba20b62f13e1 100644
--- a/include/linux/uidgid.h
+++ b/include/linux/uidgid.h
@@ -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 }
 
diff --git a/include/linux/uidgid_types.h b/include/linux/uidgid_types.h
new file mode 100644
index 000000000000..b35ac4955a33
--- /dev/null
+++ b/include/linux/uidgid_types.h
@@ -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 */
-- 
2.43.0
Re: [PATCH 41/50] uidgid: Split out uidgid_types.h
Posted by Christian Brauner 2 years ago
On Fri, Dec 15, 2023 at 10:32:47PM -0500, Kent Overstreet wrote:
> More sched.h dependency pruning.
> 
> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
> ---

Looks good to me,
Reviewed-by: Christian Brauner <brauner@kernel.org>
[PATCH 42/50] sem: Split out sem_types.h
Posted by Kent Overstreet 2 years ago
More sched.h dependency pruning.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 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

diff --git a/include/linux/audit.h b/include/linux/audit.h
index 51b1b7054a23..93d97b56e1e4 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -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);
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 157e7af36bb7..98885e3a81e8 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -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>
diff --git a/include/linux/sem.h b/include/linux/sem.h
index 5608a500c43e..c4deefe42aeb 100644
--- a/include/linux/sem.h
+++ b/include/linux/sem.h
@@ -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;
diff --git a/include/linux/sem_types.h b/include/linux/sem_types.h
new file mode 100644
index 000000000000..73df1971a7ae
--- /dev/null
+++ b/include/linux/sem_types.h
@@ -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 */
-- 
2.43.0
Re: [PATCH 42/50] sem: Split out sem_types.h
Posted by Geert Uytterhoeven 2 years ago
Hi Kent,

On Sat, Dec 16, 2023 at 4:37 AM Kent Overstreet
<kent.overstreet@linux.dev> wrote:
> More sched.h dependency pruning.
>
> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>

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

> --- a/include/linux/audit.h
> +++ b/include/linux/audit.h
> @@ -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);
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 157e7af36bb7..98885e3a81e8 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -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>
> diff --git a/include/linux/sem.h b/include/linux/sem.h
> index 5608a500c43e..c4deefe42aeb 100644
> --- a/include/linux/sem.h
> +++ b/include/linux/sem.h
> @@ -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;
> diff --git a/include/linux/sem_types.h b/include/linux/sem_types.h
> new file mode 100644
> index 000000000000..73df1971a7ae
> --- /dev/null
> +++ b/include/linux/sem_types.h
> @@ -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 */
>
Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

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
Re: [PATCH 42/50] sem: Split out sem_types.h
Posted by Kent Overstreet 2 years ago
On Wed, Dec 20, 2023 at 12:53:46PM +0100, Geert Uytterhoeven wrote:
> Hi Kent,
> 
> On Sat, Dec 16, 2023 at 4:37 AM Kent Overstreet
> <kent.overstreet@linux.dev> wrote:
> > More sched.h dependency pruning.
> >
> > Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
> 
> 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

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.
Re: [PATCH 42/50] sem: Split out sem_types.h
Posted by Geert Uytterhoeven 1 year, 12 months ago
Hi Kent,

On Wed, Dec 20, 2023 at 10:39 PM Kent Overstreet
<kent.overstreet@linux.dev> wrote:
> On Wed, Dec 20, 2023 at 12:53:46PM +0100, Geert Uytterhoeven wrote:
> > On Sat, Dec 16, 2023 at 4:37 AM Kent Overstreet
> > <kent.overstreet@linux.dev> wrote:
> > > More sched.h dependency pruning.
> > >
> > > Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
> >
> > 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
>
> Is this a build failure on linux-next, or that specific commit?

On this 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.

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

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

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
[PATCH 43/50] lockdep: move held_lock to lockdep_types.h
Posted by Kent Overstreet 2 years ago
held_lock is embedded in task_struct, and we don't want sched.h pulling
in all of lockdep.h

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
 include/linux/lockdep.h       | 57 -----------------------------------
 include/linux/lockdep_types.h | 57 +++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 57 deletions(-)

diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
index dc2844b071c2..08b0d1d9d78b 100644
--- a/include/linux/lockdep.h
+++ b/include/linux/lockdep.h
@@ -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:
  */
diff --git a/include/linux/lockdep_types.h b/include/linux/lockdep_types.h
index 2ebc323d345a..9c533c8d701e 100644
--- a/include/linux/lockdep_types.h
+++ b/include/linux/lockdep_types.h
@@ -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 */
+	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 */
 
 /*
-- 
2.43.0
Re: [PATCH 43/50] lockdep: move held_lock to lockdep_types.h
Posted by Waiman Long 2 years ago
On 12/15/23 22:32, Kent Overstreet wrote:
> held_lock is embedded in task_struct, and we don't want sched.h pulling
> in all of lockdep.h
>
> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
> ---
>   include/linux/lockdep.h       | 57 -----------------------------------
>   include/linux/lockdep_types.h | 57 +++++++++++++++++++++++++++++++++++
>   2 files changed, 57 insertions(+), 57 deletions(-)
>
> diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h
> index dc2844b071c2..08b0d1d9d78b 100644
> --- a/include/linux/lockdep.h
> +++ b/include/linux/lockdep.h
> @@ -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:
>    */
> diff --git a/include/linux/lockdep_types.h b/include/linux/lockdep_types.h
> index 2ebc323d345a..9c533c8d701e 100644
> --- a/include/linux/lockdep_types.h
> +++ b/include/linux/lockdep_types.h
> @@ -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 */
> +	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 */
>   
>   /*
Acked-by: Waiman Long <longman@redhat.com>