Skip to contentSkip to conversation

getting rid of asm/unaligned.h includes

RFC PATCH In review Al Viro 2 participants 2 messages Dec 12, 2023

Subsystems (3)
lore
Share & tools
lore

Al Viro

author
#0 lore raw

RFC PATCH 1/1 getting rid of asm/unaligned.h includes

The most common include of asm/*.h is that of asm/unaligned.h.
However, asm/unaligned.h is almost always the same - on everything other than arc and parisc it's simply an autogenerated include of asm-generic/unaligned.h. These two architectures do have asm/unaligned.h of their own. However, both instances consist of include of the same asm-generic/unaligned.h plus a few definitions that are never used outside of arch/{arc,parisc}/kernel/{trap,unaligned}.c.

Separating that cruft into arch/{arc,parisc}/kernel/unaligned.h
allows to kill *all* asm/unaligned.h instances. The first patch in the series does just that; the rest can be done mechanically just before the next -rc1 - remove unaligned.h from mandatory-y, move the file from asm-generic to linux and do a global search-and-replace of asm/unaligned.h to linux/unaligned.h.

I've put that into
git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git #headers.unaligned (both getting rid of non-default asm/unaligned.h instances and the mechanical followup conversion). The former patch follows below, the latter ends up being 10963 lines long, so if you want to see it, look at
https://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git/commit/?h=headers.unaligned&id=959598f725aa7721a4bad53c2e997c7255ff32dc
In any case, the second one is just for illustration purpose - it ought to be regenerated just before the close of next merge window.

I hadn't found any regressions on cross-builds. Not sure which
tree should that stuff go through; suggestions?

From 286cfede3d8ca0fad1528a61293650aa6d63be58 Mon Sep 17 00:00:00 2001
From: Al Viro <[email protected]>
Date: Tue, 5 Dec 2023 21:53:22 -0500
Subject: [PATCH 1/2] arc, parisc: get rid of private asm/unaligned.h

Declarations local to arch/*/kernel/*.c are better off *not* in a public header - arch/{arc,parisc}/kernel/unaligned.h is just fine for those bits.

With that done these asm/unaligned.h instances are reduced to include of asm-generic/unaligned.h and can be removed - unaligned.h is in mandatory-y in include/asm-generic/Kbuild.

---
 arch/arc/include/asm/unaligned.h    | 27 ---------------------------
 arch/arc/kernel/traps.c             |  1 +
 arch/arc/kernel/unaligned.c         |  1 +
 arch/arc/kernel/unaligned.h         | 16 ++++++++++++++++
 arch/parisc/include/asm/unaligned.h | 11 -----------
 arch/parisc/kernel/traps.c          |  2 ++
 arch/parisc/kernel/unaligned.c      |  1 +
 arch/parisc/kernel/unaligned.h      |  3 +++
 8 files changed, 24 insertions(+), 38 deletions(-)
 delete mode 100644 arch/arc/include/asm/unaligned.h
 create mode 100644 arch/arc/kernel/unaligned.h
 delete mode 100644 arch/parisc/include/asm/unaligned.h
 create mode 100644 arch/parisc/kernel/unaligned.h
arch/arc/include/asm/unaligned.h deleted +0 -27
deleted file mode 100644
index cf5a02382e0e..000000000000
@@ -1,27 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
- */
-
-#ifndef _ASM_ARC_UNALIGNED_H
-#define _ASM_ARC_UNALIGNED_H
-
-/* ARC700 can't handle unaligned Data accesses. */
-
-#include <asm-generic/unaligned.h>
-#include <asm/ptrace.h>
-
-#ifdef CONFIG_ARC_EMUL_UNALIGNED
-int misaligned_fixup(unsigned long address, struct pt_regs *regs,
-		     struct callee_regs *cregs);
-#else
-static inline int
-misaligned_fixup(unsigned long address, struct pt_regs *regs,
-		 struct callee_regs *cregs)
-{
-	/* Not fixed */
-	return 1;
-}
-#endif
-
-#endif /* _ASM_ARC_UNALIGNED_H */
arch/arc/kernel/traps.c +1 -0
index 9b9570b79362..8e40f0881e02 100644
@@ -20,6 +20,7 @@
 #include <asm/setup.h>
 #include <asm/unaligned.h>
 #include <asm/kprobes.h>
+#include "unaligned.h"
 
 void die(const char *str, struct pt_regs *regs, unsigned long address)
 {
arch/arc/kernel/unaligned.c +1 -0
index 99a9b92ed98d..d2f5ceaaed1b 100644
@@ -12,6 +12,7 @@
 #include <linux/ptrace.h>
 #include <linux/uaccess.h>
 #include <asm/disasm.h>
+#include "unaligned.h"
 
 #ifdef CONFIG_CPU_BIG_ENDIAN
 #define BE		1
arch/arc/kernel/unaligned.h new file +16 -0
new file mode 100644
index 000000000000..5244453bb85f
@@ -0,0 +1,16 @@
+struct pt_regs;
+struct callee_regs;
+
+#ifdef CONFIG_ARC_EMUL_UNALIGNED
+int misaligned_fixup(unsigned long address, struct pt_regs *regs,
+		     struct callee_regs *cregs);
+#else
+static inline int
+misaligned_fixup(unsigned long address, struct pt_regs *regs,
+		 struct callee_regs *cregs)
+{
+	/* Not fixed */
+	return 1;
+}
+#endif
+
arch/parisc/include/asm/unaligned.h deleted +0 -11
deleted file mode 100644
index c0621295100d..000000000000
@@ -1,11 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _ASM_PARISC_UNALIGNED_H
-#define _ASM_PARISC_UNALIGNED_H
-
-#include <asm-generic/unaligned.h>
-
-struct pt_regs;
-void handle_unaligned(struct pt_regs *regs);
-int check_unaligned(struct pt_regs *regs);
-
-#endif /* _ASM_PARISC_UNALIGNED_H */
arch/parisc/kernel/traps.c +2 -0
index 1107ca819ac8..7ab0d44ef698 100644
@@ -47,6 +47,8 @@
 #include <linux/kgdb.h>
 #include <linux/kprobes.h>
 
+#include "unaligned.h"
+
 #if defined(CONFIG_LIGHTWEIGHT_SPINLOCK_CHECK)
 #include <asm/spinlock.h>
 #endif
arch/parisc/kernel/unaligned.c +1 -0
index ce25acfe4889..39cd222366bb 100644
@@ -15,6 +15,7 @@
 #include <asm/unaligned.h>
 #include <asm/hardirq.h>
 #include <asm/traps.h>
+#include "unaligned.h"
 
 /* #define DEBUG_UNALIGNED 1 */
 
arch/parisc/kernel/unaligned.h new file +3 -0
new file mode 100644
index 000000000000..c1aa4b12e284
@@ -0,0 +1,3 @@
+struct pt_regs;
+void handle_unaligned(struct pt_regs *regs);
+int check_unaligned(struct pt_regs *regs);
Signature · 1 line
2.39.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 24 lines · Al Viro

The most common include of asm/*.h is that of asm/unaligned.h.
However, asm/unaligned.h is almost always the same - on everything other than arc and parisc it's simply an autogenerated include of asm-generic/unaligned.h. These two architectures do have asm/unaligned.h of their own. However, both instances consist of include of the same asm-generic/unaligned.h plus a few definitions that are never used outside of arch/{arc,parisc}/kernel/{trap,unaligned}.c.

Separating that cruft into arch/{arc,parisc}/kernel/unaligned.h
allows to kill *all* asm/unaligned.h instances. The first patch in the series does just that; the rest can be done mechanically just before the next -rc1 - remove unaligned.h from mandatory-y, move the file from asm-generic to linux and do a global search-and-replace of asm/unaligned.h to linux/unaligned.h.

I've put that into
git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git #headers.unaligned (both getting rid of non-default asm/unaligned.h instances and the mechanical followup conversion). The former patch follows below, the latter ends up being 10963 lines long, so if you want to see it, look at
https://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs.git/commit/?h=headers.unaligned&id=959598f725aa7721a4bad53c2e997c7255ff32dc
In any case, the second one is just for illustration purpose - it ought to be regenerated just before the close of next merge window.

Quoted 2 lines

I hadn't found any regressions on cross-builds. Not sure which
tree should that stuff go through; suggestions?

Anything that makes the 2nd patch easier for you works for me. I don't anticipate any conflicts in this area so you could keep it simple and keep arch patches in your tree along side the 2nd one and let them go directly to Linus whenever that happens.

Quoted 9 lines

From 286cfede3d8ca0fad1528a61293650aa6d63be58 Mon Sep 17 00:00:00 2001
From: Al Viro <[email protected]>
Date: Tue, 5 Dec 2023 21:53:22 -0500
Subject: [PATCH 1/2] arc, parisc: get rid of private asm/unaligned.h

Declarations local to arch/*/kernel/*.c are better off *not* in a public header - arch/{arc,parisc}/kernel/unaligned.h is just fine for those bits.

Quoted 5 lines

With that done these asm/unaligned.h instances are reduced to include of asm-generic/unaligned.h and can be removed - unaligned.h is in mandatory-y in include/asm-generic/Kbuild.