x86/syscalls: shrink entry/syscall_32.i via IWYU
Subsystems (2)
PATCH 1/1 x86/syscalls: shrink entry/syscall_32.i via IWYU
This diff uses an open source tool include-what-you-use (IWYU) to modify the include list, changing indirect includes to direct includes. IWYU is implemented using the IWYUScripts github repository which is a tool that is currently undergoing development. These changes seek to improve build times.
This change to entry/syscall_32.c resulted in a preprocessed size of entry/syscall_32.i from 64002 lines to 47986 lines (-25%) for the x86 defconfig.
--- arch/x86/entry/syscall_32.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/entry/syscall_32.c +2 -1
@@ -4,7 +4,7 @@#include <linux/linkage.h> #include <linux/sys.h> #include <linux/cache.h> -#include <linux/syscalls.h> +#include <linux/ptrace.h> #include <asm/syscall.h> #ifdef CONFIG_IA32_EMULATION
@@ -16,6 +16,7 @@#define __SYSCALL (nr, sym) extern long __ia32_##sym(const struct pt_regs *);#include <asm/syscalls_32.h> +#undef __SYSCALL#define __SYSCALL (nr, sym) __ia32_##sym,
---
base-commit: fbafc3e621c3f4ded43720fdb1d6ce1728ec664e
change-id: 20231227-syscall32-2c6d62fe51c9
Best regards,
Signature · 1 line
Tanzir Hasan <[email protected]>
Quoted 20 lines · Tanzir Hasan
This diff uses an open source tool include-what-you-use (IWYU) to modify the include list, changing indirect includes to direct includes. IWYU is implemented using the IWYUScripts github repository which is a tool that is currently undergoing development. These changes seek to improve build times.
This change to
entry/syscall_32.cresulted in a preprocessed size of entry/syscall_32.i from 64002 lines to 47986 lines (-25%) for the x86 defconfig.Signed-off-by Tanzir Hasan <[email protected]>--- arch/x86/entry/syscall_32.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/x86/entry/syscall_32.c +0
-0
arch/x86/entry/syscall_32.c line 8
Quoted 6 lines
arch/x86/entry/syscall_32.c +1
-1@@ -4,7 +4,7 @@#include <linux/linkage.h> #include <linux/sys.h> #include <linux/cache.h> -#include <linux/syscalls.h> +#include <linux/ptrace.h> #include <asm/syscall.h>
Really? What do we need linux/ptrace.h for? Because if it's struct pt_regs for the generated externs, we might as well have just said
struct pt_regs;
and that would be it.
<digs around a bit>
As the matter of fact, all you need out of those includes is this:
struct pt_regs;
typedef long (*sys_call_ptr_t)(const struct pt_regs *); extern const sys_call_ptr_t sys_call_table[];
#if defined(CONFIG_X86_32)
#define ia32_sys_call_table sys_call_table
#else
/*
* These may not exist, but still put the prototypes in so we
* can use IS_ENABLED().
*/
extern const sys_call_ptr_t ia32_sys_call_table[]; extern const sys_call_ptr_t x32_sys_call_table[]; #endif
That's _it_. The same goes for syscall_64.c and syscall_x32.c. Oh, and lose the __visible/asmlinkage junk in there - none of that stuff is used from asm these days. See the patch below - Untested But Should Work(tm):
arch/x86/entry/common.c +2 -0
@@ -36,6 +36,8 @@#include <asm/syscall.h> #include <asm/irq_stack.h> +#include "syscall.h" +#ifdef CONFIG_X86_64 static __always_inline bool do_syscall_x64(struct pt_regs *regs, int nr)
arch/x86/entry/syscall.h new file +13 -0
@@ -0,0 +1,13 @@ +struct pt_regs ; +typedef long (*sys_call_ptr_t )(const struct pt_regs *); +extern const sys_call_ptr_t sys_call_table[]; +#if defined(CONFIG_X86_32 ) +#define ia32_sys_call_table sys_call_table +#else +/* +* These may not exist, but still put the prototypes in so we +* can use IS_ENABLED(). +*/ +extern const sys_call_ptr_t ia32_sys_call_table[]; +extern const sys_call_ptr_t x32_sys_call_table[]; +#endif
arch/x86/entry/syscall_32.c +2 -6
@@ -1,11 +1,7 @@// SPDX-License-Identifier: GPL-2.0 /* System call table for i386. */ -#include <linux/linkage.h> -#include <linux/sys.h> -#include <linux/cache.h> -#include <linux/syscalls.h> -#include <asm/syscall.h> +#include "syscall.h" #ifdef CONFIG_IA32_EMULATION #define __SYSCALL_WITH_COMPAT (nr, native, compat) __SYSCALL(nr, compat)
@@ -20,6 +16,6 @@#define __SYSCALL (nr, sym) __ia32_##sym, -__visible const sys_call_ptr_t ia32_sys_call_table[] = { +const sys_call_ptr_t ia32_sys_call_table[] = {#include <asm/syscalls_32.h> };
arch/x86/entry/syscall_64.c +2 -6
@@ -1,11 +1,7 @@// SPDX-License-Identifier: GPL-2.0 /* System call table for x86-64. */ -#include <linux/linkage.h> -#include <linux/sys.h> -#include <linux/cache.h> -#include <linux/syscalls.h> -#include <asm/syscall.h> +#include "syscall.h" #define __SYSCALL (nr, sym) extern long __x64_##sym(const struct pt_regs *);#include <asm/syscalls_64.h>
@@ -13,6 +9,6 @@#define __SYSCALL (nr, sym) __x64_##sym, -asmlinkage const sys_call_ptr_t sys_call_table[] = { +const sys_call_ptr_t sys_call_table[] = {#include <asm/syscalls_64.h> };
arch/x86/entry/syscall_x32.c +2 -6
@@ -1,11 +1,7 @@// SPDX-License-Identifier: GPL-2.0 /* System call table for x32 ABI. */ -#include <linux/linkage.h> -#include <linux/sys.h> -#include <linux/cache.h> -#include <linux/syscalls.h> -#include <asm/syscall.h> +#include "syscall.h" #define __SYSCALL (nr, sym) extern long __x64_##sym(const struct pt_regs *);#include <asm/syscalls_x32.h>
@@ -13,6 +9,6 @@#define __SYSCALL (nr, sym) __x64_##sym, -asmlinkage const sys_call_ptr_t x32_sys_call_table[] = { +const sys_call_ptr_t x32_sys_call_table[] = {#include <asm/syscalls_x32.h> };
arch/x86/include/asm/syscall.h +0 -14
@@ -16,20 +16,6 @@#include <asm/thread_info.h> /* for TS_COMPAT */ #include <asm/unistd.h> -typedef long (*sys_call_ptr_t )(const struct pt_regs *); -extern const sys_call_ptr_t sys_call_table[]; - -#if defined(CONFIG_X86_32 ) -#define ia32_sys_call_table sys_call_table -#else -/* -* These may not exist, but still put the prototypes in so we -* can use IS_ENABLED(). -*/ -extern const sys_call_ptr_t ia32_sys_call_table[]; -extern const sys_call_ptr_t x32_sys_call_table[]; -#endif -/* * Only the low 32 bits of orig_ax are meaningful, so we return int. * This importantly ignores the high bits on 64-bit, so comparisons
H. Peter Anvin
reviewerQuoted 179 lines · Al Viro
Quoted 20 lines · Tanzir Hasan
This diff uses an open source tool include-what-you-use (IWYU) to modify the include list, changing indirect includes to direct includes. IWYU is implemented using the IWYUScripts github repository which is a tool that is currently undergoing development. These changes seek to improve build times.
This change to
entry/syscall_32.cresulted in a preprocessed size of entry/syscall_32.i from 64002 lines to 47986 lines (-25%) for the x86 defconfig.Signed-off-by Tanzir Hasan <[email protected]>--- arch/x86/entry/syscall_32.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/x86/entry/syscall_32.c +0
-0arch/x86/entry/syscall_32.c line 8
Quoted 6 lines
arch/x86/entry/syscall_32.c +1
-1@@ -4,7 +4,7 @@#include <linux/linkage.h> #include <linux/sys.h> #include <linux/cache.h> -#include <linux/syscalls.h> +#include <linux/ptrace.h> #include <asm/syscall.h> Really? What do we need
linux/ptrace.hfor? Because if it's structpt_regsfor the generated externs, we might as well have just said
structpt_regs;
and that would be it.<digs around a bit>
As the matter of fact, all you need out of those includes is this:
struct
pt_regs;
typedef long (*sys_call_ptr_t)(const structpt_regs*); extern constsys_call_ptr_tsys_call_table[];
#ifdefined(CONFIG_X86_32)
#defineia32_sys_call_tablesys_call_table
#else
/*
* These may not exist, but still put the prototypes in so we
* can useIS_ENABLED().
*/
extern constsys_call_ptr_tia32_sys_call_table[]; extern constsys_call_ptr_tx32_sys_call_table[]; #endifThat's _it_. The same goes for
syscall_64.candsyscall_x32.c. Oh, and lose the __visible/asmlinkage junk in there - none of that stuff is used from asm these days. See the patch below - Untested But Should Work(tm):arch/x86/entry/common.c +2
-0@@ -36,6 +36,8 @@#include <asm/syscall.h> #include <asm/irq_stack.h> +#include "syscall.h" +#ifdef CONFIG_X86_64 static __always_inline bool do_syscall_x64(struct pt_regs *regs, int nr)arch/x86/entry/syscall.h new file +13
-0@@ -0,0 +1,13 @@ +struct pt_regs ; +typedef long (*sys_call_ptr_t )(const struct pt_regs *); +extern const sys_call_ptr_t sys_call_table[]; +#if defined(CONFIG_X86_32 ) +#define ia32_sys_call_table sys_call_table +#else +/* +* These may not exist, but still put the prototypes in so we +* can use IS_ENABLED(). +*/ +extern const sys_call_ptr_t ia32_sys_call_table[]; +extern const sys_call_ptr_t x32_sys_call_table[]; +#endif arch/x86/entry/syscall_32.c +2
-6@@ -1,11 +1,7 @@// SPDX-License-Identifier: GPL-2.0 /* System call table for i386. */ -#include <linux/linkage.h> -#include <linux/sys.h> -#include <linux/cache.h> -#include <linux/syscalls.h> -#include <asm/syscall.h> +#include "syscall.h" #ifdef CONFIG_IA32_EMULATION #define __SYSCALL_WITH_COMPAT (nr, native, compat) __SYSCALL(nr, compat)@@ -20,6 +16,6 @@#define __SYSCALL (nr, sym) __ia32_##sym, -__visible const sys_call_ptr_t ia32_sys_call_table[] = { +const sys_call_ptr_t ia32_sys_call_table[] = {#include <asm/syscalls_32.h> };arch/x86/entry/syscall_64.c +2
-6@@ -1,11 +1,7 @@// SPDX-License-Identifier: GPL-2.0 /* System call table for x86-64. */ -#include <linux/linkage.h> -#include <linux/sys.h> -#include <linux/cache.h> -#include <linux/syscalls.h> -#include <asm/syscall.h> +#include "syscall.h" #define __SYSCALL (nr, sym) extern long __x64_##sym(const struct pt_regs *);#include <asm/syscalls_64.h> @@ -13,6 +9,6 @@#define __SYSCALL (nr, sym) __x64_##sym, -asmlinkage const sys_call_ptr_t sys_call_table[] = { +const sys_call_ptr_t sys_call_table[] = {#include <asm/syscalls_64.h> };arch/x86/entry/syscall_x32.c +2
-6@@ -1,11 +1,7 @@// SPDX-License-Identifier: GPL-2.0 /* System call table for x32 ABI. */ -#include <linux/linkage.h> -#include <linux/sys.h> -#include <linux/cache.h> -#include <linux/syscalls.h> -#include <asm/syscall.h> +#include "syscall.h" #define __SYSCALL (nr, sym) extern long __x64_##sym(const struct pt_regs *);#include <asm/syscalls_x32.h> @@ -13,6 +9,6 @@#define __SYSCALL (nr, sym) __x64_##sym, -asmlinkage const sys_call_ptr_t x32_sys_call_table[] = { +const sys_call_ptr_t x32_sys_call_table[] = {#include <asm/syscalls_x32.h> };arch/x86/include/asm/syscall.h +0
-7@@ -16,20 +16,6 @@#include <asm/thread_info.h> /* for TS_COMPAT */ #include <asm/unistd.h> -typedef long (*sys_call_ptr_t )(const struct pt_regs *); -extern const sys_call_ptr_t sys_call_table[]; - -#if defined(CONFIG_X86_32 ) -#define ia32_sys_call_table sys_call_table -#else -/*
arch/x86/include/asm/syscall.h line 21
Quoted 10 lines
arch/x86/include/asm/syscall.h +0
-7-* These may not exist, but still put the prototypes in so we -* can use IS_ENABLED(). -*/ -extern const sys_call_ptr_t ia32_sys_call_table[]; -extern const sys_call_ptr_t x32_sys_call_table[]; -#endif -/* * Only the low 32 bits of orig_ax are meaningful, so we return int. * This importantly ignores the high bits on 64-bit, so comparisons
__visible is for LTO, no?
Quoted 5 lines · H. Peter Anvin
Quoted 3 lines
/*
* Only the low 32 bits oforig_axare meaningful, so we return int.
* This importantly ignores the high bits on 64-bit, so comparisons
__visibleis for LTO, no?
If we need it in cases when array defined in entry/syscall_32.c and used in entry/common.c, I would respectfully suggest that whatever we need it for is misguided garbage. I don't think that LTO does need it, though. How is arch/x86/entry/{syscall_32,common}.c different from e.g. fs/{namespace,d_path}.c, where we have fs/namespace.c:100:__cacheline_aligned_in_smp DEFINE_SEQLOCK(mount_lock); andfs/d_path.c:166: read_seqbegin_or_lock(&mount_lock, &m_seq);
respectively?
H. Peter Anvin
reviewerQuoted 7 lines · Al Viro
Quoted 5 lines · H. Peter Anvin
Quoted 3 lines
/*
* Only the low 32 bits oforig_axare meaningful, so we return int.
* This importantly ignores the high bits on 64-bit, so comparisons
__visibleis for LTO, no?
Quoted 9 lines
If we need it in cases when array defined in
entry/syscall_32.cand used inentry/common.c, I would respectfully suggest that whatever we need it for is misguided garbage. I don't think that LTO does need it, though. How isarch/x86/entry/{syscall_32,common}.cdifferent from e.g.fs/{namespace,d_path}.c, where we have fs/namespace.c:100:__cacheline_aligned_in_smpDEFINE_SEQLOCK(mount_lock); andfs/d_path.c:166:read_seqbegin_or_lock(&mount_lock, &m_seq);
respectively?
You're correct of course; __visible for LTO is for functions called from assembly *at the point of definition*, not declaration and certainly not as a type.
Quoted 39 lines · Al Viro
Quoted 20 lines · Tanzir Hasan
This diff uses an open source tool include-what-you-use (IWYU) to modify the include list, changing indirect includes to direct includes. IWYU is implemented using the IWYUScripts github repository which is a tool that is currently undergoing development. These changes seek to improve build times.
This change to
entry/syscall_32.cresulted in a preprocessed size of entry/syscall_32.i from 64002 lines to 47986 lines (-25%) for the x86 defconfig.Signed-off-by Tanzir Hasan <[email protected]>--- arch/x86/entry/syscall_32.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/x86/entry/syscall_32.c +0
-0arch/x86/entry/syscall_32.c line 8
Quoted 6 lines
arch/x86/entry/syscall_32.c +1
-1@@ -4,7 +4,7 @@#include <linux/linkage.h> #include <linux/sys.h> #include <linux/cache.h> -#include <linux/syscalls.h> +#include <linux/ptrace.h> #include <asm/syscall.h> Really? What do we need
linux/ptrace.hfor? Because if it's structpt_regsfor the generated externs, we might as well have just said
structpt_regs;
and that would be it.<digs around a bit>
As the matter of fact, all you need out of those includes is this:
Quoted 13 lines
struct
pt_regs;
typedef long (*sys_call_ptr_t)(const structpt_regs*); extern constsys_call_ptr_tsys_call_table[];
#ifdefined(CONFIG_X86_32)
#defineia32_sys_call_tablesys_call_table
#else
/*
* These may not exist, but still put the prototypes in so we
* can useIS_ENABLED().
*/
extern constsys_call_ptr_tia32_sys_call_table[]; extern constsys_call_ptr_tx32_sys_call_table[]; #endif
I see that only pt_regs is necessary and I understand this approach. I was wondering if using this approach would reduce readability. Once we add the snippet, the file builds even after removing the following lines:
#include <linux/linkage.h>
#include <linux/sys.h>
#include <linux/cache.h>
#include <linux/ptrace.h>
#include <asm/syscall.h>
It is possible to remove them all, but do you think any should be kept?
Best,
Tanzir
Quoted 4 lines · Al Viro
That's _it_. The same goes for
syscall_64.candsyscall_x32.c. Oh, and lose the __visible/asmlinkage junk in there - none of that stuff is used from asm these days. See the patch below - Untested But Should Work(tm):
Unfortunately, there's this in kernel/trace/trace_syscalls.c:
unsigned long __init __weak arch_syscall_addr(int nr)
{
return (unsigned long)sys_call_table[nr];
}How is that supposed to work for anything biarch? Including amd64 with CONFIG_COMPAT enabled?
Confused...
Quoted 10 lines · Al Viro
Quoted 4 lines · Al Viro
That's _it_. The same goes for
syscall_64.candsyscall_x32.c. Oh, and lose the __visible/asmlinkage junk in there - none of that stuff is used from asm these days. See the patch below - Untested But Should Work(tm):Unfortunately, there's this in
kernel/trace/trace_syscalls.c:
Quoted 7 lines
unsigned long
__init__weakarch_syscall_addr(int nr){ return (unsigned long)sys_call_table[nr]; }How is that supposed to work for anything biarch? Including amd64 with
CONFIG_COMPATenabled?
commit f431b634f24d ("tracing/syscalls: Allow archs to ignore tracing compat syscalls")
added a comment block about ARCH_TRACE_IGNORE_COMPAT_SYSCALLS, which is defined for x86 in arch/x86/include/asm/ftrace.h.
The implementation of arch_syscall_addr for mips is quite complex; dependent on quite a few different configs.
Signature · 2 lines
Thanks, ~Nick Desaulniers