From: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
To: linux-kernel@vger.kernel.org
Cc: Andi Kleen <ak@linux.intel.com>, Martin Liska <mliska@suse.cz>,
Jiri Slaby <jslaby@suse.cz>
Subject: [PATCH 27/46] linkage, lto: use C version for SYSCALL_ALIAS() / cond_syscall()
Date: Mon, 14 Nov 2022 12:43:25 +0100 [thread overview]
Message-ID: <20221114114344.18650-28-jirislaby@kernel.org> (raw)
In-Reply-To: <20221114114344.18650-1-jirislaby@kernel.org>
From: Andi Kleen <ak@linux.intel.com>
With LTO, aliases get largely resolved in the compiler, not in the
linker.
Implement cond_syscall() and SYSCALL_ALIAS() in C to let the compiler
understand the aliases so that it can resolve them properly.
Likely, the architecture specific versions are now not needed anymore,
but they are kept for now.
There is one subtlety here:
The assembler version didn't care whether there was a prototype or not.
This variant assumes there is no prototype because it uses a dummy
(void) signature. This works for sys_ni.c, but breaks for
kernel/time/posix-stubs.c. To avoid problems there, a second variant of
the macro (_PROTO) is added. That uses the previously declared type
(by typeof()).
I actually tried to avoid this by adding prototypes for SYS_NI() and use
only the _PROTO variant, but it resulted in very large patches and lots
of problems with all the different cases. Eventually, I gave up and just
use the prototype case in posix-stubs.c
[js] gcc >= 8 emits Wattribute-alias warning. Work around that by
__diag_*(). This is ugly, but due to gcc bug, I see no better
option. Suggestions welcome.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Martin Liska <mliska@suse.cz>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
include/linux/linkage.h | 16 ++++++++--------
kernel/time/posix-stubs.c | 19 +++++++++++++++++--
2 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/include/linux/linkage.h b/include/linux/linkage.h
index 1feab6136b5b..688b9bb80e96 100644
--- a/include/linux/linkage.h
+++ b/include/linux/linkage.h
@@ -23,17 +23,17 @@
#endif
#ifndef cond_syscall
-#define cond_syscall(x) asm( \
- ".weak " __stringify(x) "\n\t" \
- ".set " __stringify(x) "," \
- __stringify(sys_ni_syscall))
+#define cond_syscall(x) \
+ extern long x(void) __attribute__((alias("sys_ni_syscall"), weak));
#endif
#ifndef SYSCALL_ALIAS
-#define SYSCALL_ALIAS(alias, name) asm( \
- ".globl " __stringify(alias) "\n\t" \
- ".set " __stringify(alias) "," \
- __stringify(name))
+#define SYSCALL_ALIAS(a, name) \
+ long a(void) __attribute__((alias(__stringify(name))))
+#define SYSCALL_ALIAS_PROTO(a, name) \
+ typeof(a) a __attribute__((alias(__stringify(name))))
+#else
+#define SYSCALL_ALIAS_PROTO(a, name) SYSCALL_ALIAS(a, name)
#endif
#define __page_aligned_data __section(".data..page_aligned") __aligned(PAGE_SIZE)
diff --git a/kernel/time/posix-stubs.c b/kernel/time/posix-stubs.c
index 90ea5f373e50..23e1a63adc2b 100644
--- a/kernel/time/posix-stubs.c
+++ b/kernel/time/posix-stubs.c
@@ -31,13 +31,21 @@ asmlinkage long sys_ni_posix_timers(void)
}
#ifndef SYS_NI
-#define SYS_NI(name) SYSCALL_ALIAS(sys_##name, sys_ni_posix_timers)
+#define SYS_NI(name) SYSCALL_ALIAS_PROTO(sys_##name, sys_ni_posix_timers)
#endif
#ifndef COMPAT_SYS_NI
-#define COMPAT_SYS_NI(name) SYSCALL_ALIAS(compat_sys_##name, sys_ni_posix_timers)
+#define COMPAT_SYS_NI(name) \
+ SYSCALL_ALIAS_PROTO(compat_sys_##name, sys_ni_posix_timers)
#endif
+/*
+ * This cannot go to SYS_NI() or SYSCALL_ALIAS_PROTO() due to gcc bug fixed in
+ * gcc >= 13 (cf. PR 97498). I wonder how is __SYSCALL_DEFINEx() able to work?
+ */
+__diag_push();
+__diag_ignore(GCC, 8, "-Wattribute-alias", "Alias to nonimplemented syscall");
+
SYS_NI(timer_create);
SYS_NI(timer_gettime);
SYS_NI(timer_getoverrun);
@@ -51,6 +59,8 @@ SYS_NI(clock_adjtime32);
SYS_NI(alarm);
#endif
+__diag_pop();
+
/*
* We preserve minimal support for CLOCK_REALTIME and CLOCK_MONOTONIC
* as it is easy to remain compatible with little code. CLOCK_BOOTTIME
@@ -157,6 +167,9 @@ SYSCALL_DEFINE4(clock_nanosleep, const clockid_t, which_clock, int, flags,
which_clock);
}
+__diag_push();
+__diag_ignore(GCC, 8, "-Wattribute-alias", "Alias to nonimplemented syscall");
+
#ifdef CONFIG_COMPAT
COMPAT_SYS_NI(timer_create);
#endif
@@ -170,6 +183,8 @@ COMPAT_SYS_NI(setitimer);
SYS_NI(timer_settime32);
SYS_NI(timer_gettime32);
+__diag_pop();
+
SYSCALL_DEFINE2(clock_settime32, const clockid_t, which_clock,
struct old_timespec32 __user *, tp)
{
--
2.38.1
next prev parent reply other threads:[~2022-11-14 11:47 UTC|newest]
Thread overview: 87+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-14 11:42 [PATCH 00/46] gcc-LTO support for the kernel Jiri Slaby (SUSE)
2022-11-14 11:42 ` [PATCH 01/46] x86/boot: robustify calling startup_{32,64}() from the decompressor code Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 02/46] kbuild: pass jobserver to cmd_ld_vmlinux.o Jiri Slaby (SUSE)
2022-11-14 17:57 ` Masahiro Yamada
2022-11-15 6:36 ` Jiri Slaby
2022-11-14 11:43 ` [PATCH 03/46] kbuild: lto: preserve MAKEFLAGS for module linking Jiri Slaby (SUSE)
2022-11-14 18:02 ` Masahiro Yamada
2022-11-14 11:43 ` [PATCH 04/46] compiler.h: introduce __visible_on_lto Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 05/46] compiler.h: introduce __global_on_lto Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 06/46] Compiler Attributes, lto: introduce __noreorder Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 07/46] tracepoint, lto: Mark static call functions as __visible Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 08/46] static_call, lto: Mark static keys " Jiri Slaby (SUSE)
2022-11-14 15:51 ` Peter Zijlstra
2022-11-14 18:52 ` Josh Poimboeuf
2022-11-14 20:34 ` Andi Kleen
2022-11-17 8:24 ` Peter Zijlstra
2022-11-14 18:57 ` Josh Poimboeuf
2022-11-14 11:43 ` [PATCH 09/46] static_call, lto: Mark static_call_return0() " Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 10/46] static_call, lto: Mark func_a() as __visible_on_lto Jiri Slaby (SUSE)
2022-11-14 15:54 ` Peter Zijlstra
2022-11-14 20:29 ` Andi Kleen
2022-11-14 11:43 ` [PATCH 11/46] x86/alternative, lto: Mark int3_*() as global and __visible Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 12/46] x86/paravirt, lto: Mark native_steal_clock() as __visible_on_lto Jiri Slaby (SUSE)
2022-11-14 15:58 ` Peter Zijlstra
2022-11-14 11:43 ` [PATCH 13/46] x86/preempt, lto: Mark preempt_schedule_*thunk() as __visible Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 14/46] x86/sev, lto: Mark cpuid_table_copy as __visible_on_lto Jiri Slaby (SUSE)
2022-11-14 16:02 ` Peter Zijlstra
2022-11-14 11:43 ` [PATCH 15/46] x86/xen, lto: Mark xen_vcpu_stolen() as __visible Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 16/46] x86, lto: Mark gdt_page and native_sched_clock() " Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 17/46] amd, lto: Mark amd pmu and pstate functions as __visible_on_lto Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 18/46] entry, lto: Mark raw_irqentry_exit_cond_resched() as __visible Jiri Slaby (SUSE)
2022-11-16 23:30 ` Thomas Gleixner
2022-11-17 8:40 ` Peter Zijlstra
2022-11-17 22:07 ` Andi Kleen
2022-11-18 1:28 ` Thomas Gleixner
2022-11-19 0:50 ` Andi Kleen
2022-11-19 8:50 ` Thomas Gleixner
2022-11-22 9:32 ` Jiri Slaby
2022-11-14 11:43 ` [PATCH 19/46] export, lto: Mark __kstrtab* in EXPORT_SYMBOL() as global and __visible Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 20/46] softirq, lto: Mark irq_enter/exit_rcu() as __visible Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 21/46] btf, lto: pass scope as strings Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 22/46] btf, lto: Make all BTF IDs global on LTO Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 23/46] init.h, lto: mark initcalls as __noreorder Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 24/46] bpf, lto: mark interpreter jump table " Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 25/46] sched, lto: mark sched classes " Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 26/46] x86/apic, lto: Mark apic_driver*() " Jiri Slaby (SUSE)
2022-11-14 11:43 ` Jiri Slaby (SUSE) [this message]
2022-11-14 11:43 ` [PATCH 28/46] scripts, lto: re-add gcc-ld Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 29/46] scripts, lto: use CONFIG_LTO for many LTO specific actions Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 30/46] Kbuild, lto: Add Link Time Optimization support Jiri Slaby (SUSE)
2022-11-14 18:55 ` Josh Poimboeuf
2022-11-15 13:31 ` Martin Liška
2022-11-14 11:43 ` [PATCH 31/46] x86/purgatory, lto: Disable gcc LTO for purgatory Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 32/46] x86/realmode, lto: Disable gcc LTO for real mode code Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 33/46] x86/vdso, lto: Disable gcc LTO for the vdso Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 34/46] scripts, lto: disable gcc LTO for some mod sources Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 35/46] Kbuild, lto: disable gcc LTO for bounds+asm-offsets Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 36/46] lib/string, lto: disable gcc LTO for string.o Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 37/46] Compiler attributes, lto: disable __flatten with LTO Jiri Slaby (SUSE)
2022-11-14 17:01 ` Miguel Ojeda
2022-11-14 11:43 ` [PATCH 38/46] Kbuild, lto: don't include weak source file symbols in System.map Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 39/46] x86, lto: Disable relative init pointers with gcc LTO Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 40/46] x86/livepatch, lto: Disable live patching " Jiri Slaby (SUSE)
2022-11-14 19:07 ` Josh Poimboeuf
2022-11-14 20:28 ` Andi Kleen
2022-11-14 22:00 ` Josh Poimboeuf
2022-11-15 13:32 ` Martin Liška
2022-11-17 20:00 ` Song Liu
2022-11-14 11:43 ` [PATCH 41/46] x86/lib, lto: Mark 32bit mem{cpy,move,set} as __used Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 42/46] mm/kasan, lto: Mark kasan " Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 43/46] scripts, lto: check C symbols for modversions Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 44/46] scripts/bloat-o-meter, lto: handle gcc LTO Jiri Slaby (SUSE)
2022-11-14 11:43 ` [PATCH 45/46] kasan, lto: remove extra BUILD_BUG() in memory_is_poisoned Jiri Slaby (SUSE)
2022-11-26 17:07 ` Andrey Konovalov
2022-11-14 11:43 ` [PATCH 46/46] x86, lto: Finally enable gcc LTO for x86 Jiri Slaby (SUSE)
2022-11-14 11:56 ` [PATCH 00/46] gcc-LTO support for the kernel Ard Biesheuvel
2022-11-14 12:04 ` Jiri Slaby
2022-11-14 19:40 ` Ard Biesheuvel
2022-11-17 8:28 ` Peter Zijlstra
2022-11-17 8:50 ` Richard Biener
2022-11-17 11:42 ` Peter Zijlstra
2022-11-17 11:49 ` Ard Biesheuvel
2022-11-17 13:55 ` Richard Biener
2022-11-17 14:32 ` Peter Zijlstra
2022-11-17 14:40 ` Richard Biener
2022-11-17 15:15 ` Ard Biesheuvel
2022-11-17 11:48 ` Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221114114344.18650-28-jirislaby@kernel.org \
--to=jirislaby@kernel.org \
--cc=ak@linux.intel.com \
--cc=jslaby@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=mliska@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox