[2/2] entry: move the enter path to header files
Commit Message
In order to allow inlining the generic entry C functions,
move them to include/linux/entry-common.h.
Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
---
include/linux/entry-common.h | 123 +++++++++++++++++++++++++++++++++--
kernel/entry/common.c | 113 --------------------------------
2 files changed, 118 insertions(+), 118 deletions(-)
Comments
Hi Sven,
kernel test robot noticed the following build errors:
[auto build test ERROR on tip/core/entry]
[also build test ERROR on linus/master v6.4-rc2 next-20230516]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Sven-Schnelle/entry-move-the-exit-path-to-header-files/20230516-230146
base: tip/core/entry
patch link: https://lore.kernel.org/r/20230516133810.171487-3-svens%40linux.ibm.com
patch subject: [PATCH 2/2] entry: move the enter path to header files
config: i386-randconfig-a002
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/c7a1b9f03d3d4636253dc7900059338289083917
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Sven-Schnelle/entry-move-the-exit-path-to-header-files/20230516-230146
git checkout c7a1b9f03d3d4636253dc7900059338289083917
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash arch/x86/kvm/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202305170355.BPcuMv9z-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from arch/x86/kvm/vmx/vmx.c:41:
In file included from arch/x86/include/asm/idtentry.h:11:
include/linux/entry-common.h:574:2: error: implicit declaration of function 'audit_syscall_exit' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
audit_syscall_exit(regs);
^
>> include/linux/entry-common.h:669:15: error: duplicate 'inline' declaration specifier [-Werror,-Wduplicate-decl-specifier]
static inline __always_inline void syscall_enter_audit(struct pt_regs *regs, long syscall)
^
include/linux/compiler_attributes.h:55:41: note: expanded from macro '__always_inline'
#define __always_inline inline __attribute__((__always_inline__))
^
include/linux/compiler_types.h:187:16: note: expanded from macro 'inline'
#define inline inline __gnu_inline __inline_maybe_unused notrace
^
In file included from arch/x86/kvm/vmx/vmx.c:41:
In file included from arch/x86/include/asm/idtentry.h:11:
include/linux/entry-common.h:671:15: error: implicit declaration of function 'audit_context' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
if (unlikely(audit_context())) {
^
include/linux/entry-common.h:671:15: note: did you mean 'put_io_context'?
include/linux/iocontext.h:119:6: note: 'put_io_context' declared here
void put_io_context(struct io_context *ioc);
^
In file included from arch/x86/kvm/vmx/vmx.c:41:
In file included from arch/x86/include/asm/idtentry.h:11:
include/linux/entry-common.h:675:3: error: implicit declaration of function 'audit_syscall_entry' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
audit_syscall_entry(syscall, args[0], args[1], args[2], args[3]);
^
4 errors generated.
vim +/inline +669 include/linux/entry-common.h
556
557 static void syscall_exit_work(struct pt_regs *regs, unsigned long work)
558 {
559 bool step;
560
561 /*
562 * If the syscall was rolled back due to syscall user dispatching,
563 * then the tracers below are not invoked for the same reason as
564 * the entry side was not invoked in syscall_trace_enter(): The ABI
565 * of these syscalls is unknown.
566 */
567 if (work & SYSCALL_WORK_SYSCALL_USER_DISPATCH) {
568 if (unlikely(current->syscall_dispatch.on_dispatch)) {
569 current->syscall_dispatch.on_dispatch = false;
570 return;
571 }
572 }
573
> 574 audit_syscall_exit(regs);
575
576 if (work & SYSCALL_WORK_SYSCALL_TRACEPOINT)
577 trace_sys_exit(regs, syscall_get_return_value(current, regs));
578
579 step = report_single_step(work);
580 if (step || work & SYSCALL_WORK_SYSCALL_TRACE)
581 ptrace_report_syscall_exit(regs, step);
582 }
583
584 /*
585 * Syscall specific exit to user mode preparation. Runs with interrupts
586 * enabled.
587 */
588 static __always_inline void syscall_exit_to_user_mode_prepare(struct pt_regs *regs)
589 {
590 unsigned long work = READ_ONCE(current_thread_info()->syscall_work);
591 unsigned long nr = syscall_get_nr(current, regs);
592
593 CT_WARN_ON(ct_state() != CONTEXT_KERNEL);
594
595 if (IS_ENABLED(CONFIG_PROVE_LOCKING)) {
596 if (WARN(irqs_disabled(), "syscall %lu left IRQs disabled", nr))
597 local_irq_enable();
598 }
599
600 rseq_syscall(regs);
601
602 /*
603 * Do one-time syscall specific work. If these work items are
604 * enabled, we want to run them exactly once per syscall exit with
605 * interrupts enabled.
606 */
607 if (unlikely(work & SYSCALL_WORK_EXIT))
608 syscall_exit_work(regs, work);
609 }
610
611 static __always_inline void __syscall_exit_to_user_mode_work(struct pt_regs *regs)
612 {
613 syscall_exit_to_user_mode_prepare(regs);
614 local_irq_disable_exit_to_user();
615 exit_to_user_mode_prepare(regs);
616 }
617
618 static __always_inline void syscall_exit_to_user_mode_work(struct pt_regs *regs)
619 {
620 __syscall_exit_to_user_mode_work(regs);
621 }
622
623 /* See comment for exit_to_user_mode() in entry-common.h */
624 static __always_inline void __exit_to_user_mode(void)
625 {
626 instrumentation_begin();
627 trace_hardirqs_on_prepare();
628 lockdep_hardirqs_on_prepare();
629 instrumentation_end();
630
631 user_enter_irqoff();
632 arch_exit_to_user_mode();
633 lockdep_hardirqs_on(CALLER_ADDR0);
634 }
635
636
637 static __always_inline void irqentry_exit_to_user_mode(struct pt_regs *regs)
638 {
639 instrumentation_begin();
640 exit_to_user_mode_prepare(regs);
641 instrumentation_end();
642 __exit_to_user_mode();
643 }
644
645 static __always_inline void __enter_from_user_mode(struct pt_regs *regs)
646 {
647 arch_enter_from_user_mode(regs);
648 lockdep_hardirqs_off(CALLER_ADDR0);
649
650 CT_WARN_ON(__ct_state() != CONTEXT_USER);
651 user_exit_irqoff();
652
653 instrumentation_begin();
654 kmsan_unpoison_entry_regs(regs);
655 trace_hardirqs_off_finish();
656 instrumentation_end();
657 }
658
659 static __always_inline void enter_from_user_mode(struct pt_regs *regs)
660 {
661 __enter_from_user_mode(regs);
662 }
663
664 static __always_inline void exit_to_user_mode(void)
665 {
666 __exit_to_user_mode();
667 }
668
> 669 static inline __always_inline void syscall_enter_audit(struct pt_regs *regs, long syscall)
670 {
671 if (unlikely(audit_context())) {
672 unsigned long args[6];
673
674 syscall_get_arguments(current, regs, args);
675 audit_syscall_entry(syscall, args[0], args[1], args[2], args[3]);
676 }
677 }
678
@@ -15,6 +15,8 @@
#include <trace/events/syscalls.h>
+bool syscall_user_dispatch(struct pt_regs *regs);
+
/*
* Define dummy _TIF work flags if not defined by the architecture or for
* disabled functionality.
@@ -103,7 +105,7 @@ static __always_inline void arch_enter_from_user_mode(struct pt_regs *regs) {}
* done between establishing state and enabling interrupts. The caller must
* enable interrupts before invoking syscall_enter_from_user_mode_work().
*/
-void enter_from_user_mode(struct pt_regs *regs);
+static void enter_from_user_mode(struct pt_regs *regs);
/**
* syscall_enter_from_user_mode_prepare - Establish state and enable interrupts
@@ -120,7 +122,7 @@ void enter_from_user_mode(struct pt_regs *regs);
* This is invoked when there is extra architecture specific functionality
* to be done between establishing state and handling user mode entry work.
*/
-void syscall_enter_from_user_mode_prepare(struct pt_regs *regs);
+static void syscall_enter_from_user_mode_prepare(struct pt_regs *regs);
/**
* syscall_enter_from_user_mode_work - Check and handle work before invoking
@@ -145,7 +147,7 @@ void syscall_enter_from_user_mode_prepare(struct pt_regs *regs);
* ptrace_report_syscall_entry(), __secure_computing(), trace_sys_enter()
* 2) Invocation of audit_syscall_entry()
*/
-long syscall_enter_from_user_mode_work(struct pt_regs *regs, long syscall);
+static long syscall_enter_from_user_mode_work(struct pt_regs *regs, long syscall);
/**
* syscall_enter_from_user_mode - Establish state and check and handle work
@@ -164,7 +166,7 @@ long syscall_enter_from_user_mode_work(struct pt_regs *regs, long syscall);
* Returns: The original or a modified syscall number. See
* syscall_enter_from_user_mode_work() for further explanation.
*/
-long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall);
+static long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall);
/**
* local_irq_enable_exit_to_user - Exit to user variant of local_irq_enable()
@@ -281,7 +283,7 @@ void arch_do_signal_or_restart(struct pt_regs *regs);
* non-instrumentable.
* The caller has to invoke syscall_exit_to_user_mode_work() before this.
*/
-void exit_to_user_mode(void);
+static void exit_to_user_mode(void);
/**
* syscall_exit_to_user_mode_work - Handle work before returning to user mode
@@ -640,5 +642,116 @@ static __always_inline void irqentry_exit_to_user_mode(struct pt_regs *regs)
__exit_to_user_mode();
}
+static __always_inline void __enter_from_user_mode(struct pt_regs *regs)
+{
+ arch_enter_from_user_mode(regs);
+ lockdep_hardirqs_off(CALLER_ADDR0);
+
+ CT_WARN_ON(__ct_state() != CONTEXT_USER);
+ user_exit_irqoff();
+
+ instrumentation_begin();
+ kmsan_unpoison_entry_regs(regs);
+ trace_hardirqs_off_finish();
+ instrumentation_end();
+}
+
+static __always_inline void enter_from_user_mode(struct pt_regs *regs)
+{
+ __enter_from_user_mode(regs);
+}
+
+static __always_inline void exit_to_user_mode(void)
+{
+ __exit_to_user_mode();
+}
+
+static inline __always_inline void syscall_enter_audit(struct pt_regs *regs, long syscall)
+{
+ if (unlikely(audit_context())) {
+ unsigned long args[6];
+
+ syscall_get_arguments(current, regs, args);
+ audit_syscall_entry(syscall, args[0], args[1], args[2], args[3]);
+ }
+}
+
+static __always_inline long syscall_trace_enter(struct pt_regs *regs, long syscall,
+ unsigned long work)
+{
+ long ret = 0;
+
+ /*
+ * Handle Syscall User Dispatch. This must comes first, since
+ * the ABI here can be something that doesn't make sense for
+ * other syscall_work features.
+ */
+ if (work & SYSCALL_WORK_SYSCALL_USER_DISPATCH) {
+ if (syscall_user_dispatch(regs))
+ return -1L;
+ }
+
+ /* Handle ptrace */
+ if (work & (SYSCALL_WORK_SYSCALL_TRACE | SYSCALL_WORK_SYSCALL_EMU)) {
+ ret = ptrace_report_syscall_entry(regs);
+ if (ret || (work & SYSCALL_WORK_SYSCALL_EMU))
+ return -1L;
+ }
+
+ /* Do seccomp after ptrace, to catch any tracer changes. */
+ if (work & SYSCALL_WORK_SECCOMP) {
+ ret = __secure_computing(NULL);
+ if (ret == -1L)
+ return ret;
+ }
+
+ /* Either of the above might have changed the syscall number */
+ syscall = syscall_get_nr(current, regs);
+
+ if (unlikely(work & SYSCALL_WORK_SYSCALL_TRACEPOINT))
+ trace_sys_enter(regs, syscall);
+
+ syscall_enter_audit(regs, syscall);
+
+ return ret ? : syscall;
+}
+
+static __always_inline long
+__syscall_enter_from_user_work(struct pt_regs *regs, long syscall)
+{
+ unsigned long work = READ_ONCE(current_thread_info()->syscall_work);
+
+ if (work & SYSCALL_WORK_ENTER)
+ syscall = syscall_trace_enter(regs, syscall, work);
+
+ return syscall;
+}
+
+static __always_inline long syscall_enter_from_user_mode_work(struct pt_regs *regs, long syscall)
+{
+ return __syscall_enter_from_user_work(regs, syscall);
+}
+
+static __always_inline long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall)
+{
+ long ret;
+
+ __enter_from_user_mode(regs);
+
+ instrumentation_begin();
+ local_irq_enable();
+ ret = __syscall_enter_from_user_work(regs, syscall);
+ instrumentation_end();
+
+ return ret;
+}
+
+static __always_inline void syscall_enter_from_user_mode_prepare(struct pt_regs *regs)
+{
+ __enter_from_user_mode(regs);
+ instrumentation_begin();
+ local_irq_enable();
+ instrumentation_end();
+}
#endif
@@ -15,119 +15,6 @@
#define CREATE_TRACE_POINTS
#include <trace/events/syscalls.h>
-/* See comment for enter_from_user_mode() in entry-common.h */
-static __always_inline void __enter_from_user_mode(struct pt_regs *regs)
-{
- arch_enter_from_user_mode(regs);
- lockdep_hardirqs_off(CALLER_ADDR0);
-
- CT_WARN_ON(__ct_state() != CONTEXT_USER);
- user_exit_irqoff();
-
- instrumentation_begin();
- kmsan_unpoison_entry_regs(regs);
- trace_hardirqs_off_finish();
- instrumentation_end();
-}
-
-void noinstr enter_from_user_mode(struct pt_regs *regs)
-{
- __enter_from_user_mode(regs);
-}
-
-static inline void syscall_enter_audit(struct pt_regs *regs, long syscall)
-{
- if (unlikely(audit_context())) {
- unsigned long args[6];
-
- syscall_get_arguments(current, regs, args);
- audit_syscall_entry(syscall, args[0], args[1], args[2], args[3]);
- }
-}
-
-static long syscall_trace_enter(struct pt_regs *regs, long syscall,
- unsigned long work)
-{
- long ret = 0;
-
- /*
- * Handle Syscall User Dispatch. This must comes first, since
- * the ABI here can be something that doesn't make sense for
- * other syscall_work features.
- */
- if (work & SYSCALL_WORK_SYSCALL_USER_DISPATCH) {
- if (syscall_user_dispatch(regs))
- return -1L;
- }
-
- /* Handle ptrace */
- if (work & (SYSCALL_WORK_SYSCALL_TRACE | SYSCALL_WORK_SYSCALL_EMU)) {
- ret = ptrace_report_syscall_entry(regs);
- if (ret || (work & SYSCALL_WORK_SYSCALL_EMU))
- return -1L;
- }
-
- /* Do seccomp after ptrace, to catch any tracer changes. */
- if (work & SYSCALL_WORK_SECCOMP) {
- ret = __secure_computing(NULL);
- if (ret == -1L)
- return ret;
- }
-
- /* Either of the above might have changed the syscall number */
- syscall = syscall_get_nr(current, regs);
-
- if (unlikely(work & SYSCALL_WORK_SYSCALL_TRACEPOINT))
- trace_sys_enter(regs, syscall);
-
- syscall_enter_audit(regs, syscall);
-
- return ret ? : syscall;
-}
-
-static __always_inline long
-__syscall_enter_from_user_work(struct pt_regs *regs, long syscall)
-{
- unsigned long work = READ_ONCE(current_thread_info()->syscall_work);
-
- if (work & SYSCALL_WORK_ENTER)
- syscall = syscall_trace_enter(regs, syscall, work);
-
- return syscall;
-}
-
-long syscall_enter_from_user_mode_work(struct pt_regs *regs, long syscall)
-{
- return __syscall_enter_from_user_work(regs, syscall);
-}
-
-noinstr long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall)
-{
- long ret;
-
- __enter_from_user_mode(regs);
-
- instrumentation_begin();
- local_irq_enable();
- ret = __syscall_enter_from_user_work(regs, syscall);
- instrumentation_end();
-
- return ret;
-}
-
-noinstr void syscall_enter_from_user_mode_prepare(struct pt_regs *regs)
-{
- __enter_from_user_mode(regs);
- instrumentation_begin();
- local_irq_enable();
- instrumentation_end();
-}
-
-void noinstr exit_to_user_mode(void)
-{
- __exit_to_user_mode();
-}
-
/* Workaround to allow gradual conversion of architecture code */
void __weak arch_do_signal_or_restart(struct pt_regs *regs) { }