linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/7] powerpc/entry: cleanup syscall entry
       [not found] <20241012035621.1245-3-luming.yu@shingroup.cn>
@ 2024-10-12  3:56 ` Luming Yu
  2024-10-12  3:56 ` [PATCH 3/7] powerpc/debug: implement HAVE_USER_RETURN_NOTIFIER Luming Yu
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Luming Yu @ 2024-10-12  3:56 UTC (permalink / raw)
  To: linuxppc-dev, linux-kernel, mpe, npiggin, christophe.leroy,
	jialong.yang, luming.yu
  Cc: Luming Yu

cleanup do_syscall_trace_enter/leave and do_seccomp.

Signed-off-by: Luming Yu <luming.yu@shingroup.cn>
---
 arch/powerpc/kernel/interrupt.c     |   5 -
 arch/powerpc/kernel/ptrace/ptrace.c | 141 ----------------------------
 2 files changed, 146 deletions(-)

diff --git a/arch/powerpc/kernel/interrupt.c b/arch/powerpc/kernel/interrupt.c
index c4f6d3c69ba9..8c532cecbc60 100644
--- a/arch/powerpc/kernel/interrupt.c
+++ b/arch/powerpc/kernel/interrupt.c
@@ -293,11 +293,6 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3,
 		regs->gpr[3] = r3;
 	}
 
-	if (unlikely(ti_flags & _TIF_SYSCALL_DOTRACE)) {
-		do_syscall_trace_leave(regs);
-		ret |= _TIF_RESTOREALL;
-	}
-
 	local_irq_disable();
 	ret = interrupt_exit_user_prepare_main(ret, regs);
 
diff --git a/arch/powerpc/kernel/ptrace/ptrace.c b/arch/powerpc/kernel/ptrace/ptrace.c
index 727ed4a14545..6cd180bc36ab 100644
--- a/arch/powerpc/kernel/ptrace/ptrace.c
+++ b/arch/powerpc/kernel/ptrace/ptrace.c
@@ -21,9 +21,6 @@
 #include <asm/switch_to.h>
 #include <asm/debug.h>
 
-#define CREATE_TRACE_POINTS
-#include <trace/events/syscalls.h>
-
 #include "ptrace-decl.h"
 
 /*
@@ -195,144 +192,6 @@ long arch_ptrace(struct task_struct *child, long request,
 	return ret;
 }
 
-#ifdef CONFIG_SECCOMP
-static int do_seccomp(struct pt_regs *regs)
-{
-	if (!test_thread_flag(TIF_SECCOMP))
-		return 0;
-
-	/*
-	 * The ABI we present to seccomp tracers is that r3 contains
-	 * the syscall return value and orig_gpr3 contains the first
-	 * syscall parameter. This is different to the ptrace ABI where
-	 * both r3 and orig_gpr3 contain the first syscall parameter.
-	 */
-	regs->gpr[3] = -ENOSYS;
-
-	/*
-	 * We use the __ version here because we have already checked
-	 * TIF_SECCOMP. If this fails, there is nothing left to do, we
-	 * have already loaded -ENOSYS into r3, or seccomp has put
-	 * something else in r3 (via SECCOMP_RET_ERRNO/TRACE).
-	 */
-	if (__secure_computing(NULL))
-		return -1;
-
-	/*
-	 * The syscall was allowed by seccomp, restore the register
-	 * state to what audit expects.
-	 * Note that we use orig_gpr3, which means a seccomp tracer can
-	 * modify the first syscall parameter (in orig_gpr3) and also
-	 * allow the syscall to proceed.
-	 */
-	regs->gpr[3] = regs->orig_gpr3;
-
-	return 0;
-}
-#else
-static inline int do_seccomp(struct pt_regs *regs) { return 0; }
-#endif /* CONFIG_SECCOMP */
-
-/**
- * do_syscall_trace_enter() - Do syscall tracing on kernel entry.
- * @regs: the pt_regs of the task to trace (current)
- *
- * Performs various types of tracing on syscall entry. This includes seccomp,
- * ptrace, syscall tracepoints and audit.
- *
- * The pt_regs are potentially visible to userspace via ptrace, so their
- * contents is ABI.
- *
- * One or more of the tracers may modify the contents of pt_regs, in particular
- * to modify arguments or even the syscall number itself.
- *
- * It's also possible that a tracer can choose to reject the system call. In
- * that case this function will return an illegal syscall number, and will put
- * an appropriate return value in regs->r3.
- *
- * Return: the (possibly changed) syscall number.
- */
-long do_syscall_trace_enter(struct pt_regs *regs)
-{
-	u32 flags;
-
-	flags = read_thread_flags() & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE);
-
-	if (flags) {
-		int rc = ptrace_report_syscall_entry(regs);
-
-		if (unlikely(flags & _TIF_SYSCALL_EMU)) {
-			/*
-			 * A nonzero return code from
-			 * ptrace_report_syscall_entry() tells us to prevent
-			 * the syscall execution, but we are not going to
-			 * execute it anyway.
-			 *
-			 * Returning -1 will skip the syscall execution. We want
-			 * to avoid clobbering any registers, so we don't goto
-			 * the skip label below.
-			 */
-			return -1;
-		}
-
-		if (rc) {
-			/*
-			 * The tracer decided to abort the syscall. Note that
-			 * the tracer may also just change regs->gpr[0] to an
-			 * invalid syscall number, that is handled below on the
-			 * exit path.
-			 */
-			goto skip;
-		}
-	}
-
-	/* Run seccomp after ptrace; allow it to set gpr[3]. */
-	if (do_seccomp(regs))
-		return -1;
-
-	/* Avoid trace and audit when syscall is invalid. */
-	if (regs->gpr[0] >= NR_syscalls)
-		goto skip;
-
-	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
-		trace_sys_enter(regs, regs->gpr[0]);
-
-	if (!is_32bit_task())
-		audit_syscall_entry(regs->gpr[0], regs->gpr[3], regs->gpr[4],
-				    regs->gpr[5], regs->gpr[6]);
-	else
-		audit_syscall_entry(regs->gpr[0],
-				    regs->gpr[3] & 0xffffffff,
-				    regs->gpr[4] & 0xffffffff,
-				    regs->gpr[5] & 0xffffffff,
-				    regs->gpr[6] & 0xffffffff);
-
-	/* Return the possibly modified but valid syscall number */
-	return regs->gpr[0];
-
-skip:
-	/*
-	 * If we are aborting explicitly, or if the syscall number is
-	 * now invalid, set the return value to -ENOSYS.
-	 */
-	regs->gpr[3] = -ENOSYS;
-	return -1;
-}
-
-void do_syscall_trace_leave(struct pt_regs *regs)
-{
-	int step;
-
-	audit_syscall_exit(regs);
-
-	if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
-		trace_sys_exit(regs, regs->result);
-
-	step = test_thread_flag(TIF_SINGLESTEP);
-	if (step || test_thread_flag(TIF_SYSCALL_TRACE))
-		ptrace_report_syscall_exit(regs, step);
-}
-
 void __init pt_regs_check(void);
 
 /*
-- 
2.42.0.windows.2



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/7] powerpc/debug: implement HAVE_USER_RETURN_NOTIFIER
       [not found] <20241012035621.1245-3-luming.yu@shingroup.cn>
  2024-10-12  3:56 ` [PATCH 2/7] powerpc/entry: cleanup syscall entry Luming Yu
@ 2024-10-12  3:56 ` Luming Yu
  2024-10-12  3:56 ` [PATCH 4/7] powerpc/debug: hook to user return notifier infrastructure Luming Yu
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Luming Yu @ 2024-10-12  3:56 UTC (permalink / raw)
  To: linuxppc-dev, linux-kernel, mpe, npiggin, christophe.leroy,
	jialong.yang, luming.yu
  Cc: Luming Yu

enable the common entry of user return notifier for powerpc as
a debug feature.

Signed-off-by Luming Yu <luming.yu@shingroup.cn>
---
 arch/powerpc/Kconfig                    |  1 +
 arch/powerpc/include/asm/entry-common.h | 16 ++++++++++++++++
 arch/powerpc/include/asm/thread_info.h  |  2 ++
 arch/powerpc/kernel/process.c           |  2 ++
 4 files changed, 21 insertions(+)
 create mode 100644 arch/powerpc/include/asm/entry-common.h

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 261c9116d6fa..9a1e6669fa24 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -277,6 +277,7 @@ config PPC
 	select HAVE_STACKPROTECTOR		if PPC64 && $(cc-option,-mstack-protector-guard=tls -mstack-protector-guard-reg=r13)
 	select HAVE_STATIC_CALL			if PPC32
 	select HAVE_SYSCALL_TRACEPOINTS
+	select HAVE_USER_RETURN_NOTIFIER
 	select HAVE_VIRT_CPU_ACCOUNTING
 	select HAVE_VIRT_CPU_ACCOUNTING_GEN
 	select HOTPLUG_SMT			if HOTPLUG_CPU
diff --git a/arch/powerpc/include/asm/entry-common.h b/arch/powerpc/include/asm/entry-common.h
new file mode 100644
index 000000000000..51f1eb767696
--- /dev/null
+++ b/arch/powerpc/include/asm/entry-common.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef ARCH_POWERPC_ENTRY_COMMON_H
+#define ARCH_POWERPC_ENTRY_COMMON_H
+
+#include <linux/user-return-notifier.h>
+
+static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
+						  unsigned long ti_work)
+{
+	if (ti_work & _TIF_USER_RETURN_NOTIFY)
+		fire_user_return_notifiers();
+}
+
+#define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare
+
+#endif
diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
index 9df2bcf28544..c52ca3aaebb5 100644
--- a/arch/powerpc/include/asm/thread_info.h
+++ b/arch/powerpc/include/asm/thread_info.h
@@ -118,6 +118,7 @@ void arch_setup_new_exec(void);
 #endif
 #define TIF_POLLING_NRFLAG	19	/* true if poll_idle() is polling TIF_NEED_RESCHED */
 #define TIF_32BIT		20	/* 32 bit binary */
+#define TIF_USER_RETURN_NOTIFY	21	/* notify kernel of userspace return */
 
 /* as above, but as bit values */
 #define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
@@ -126,6 +127,7 @@ void arch_setup_new_exec(void);
 #define _TIF_NOTIFY_SIGNAL	(1<<TIF_NOTIFY_SIGNAL)
 #define _TIF_POLLING_NRFLAG	(1<<TIF_POLLING_NRFLAG)
 #define _TIF_32BIT		(1<<TIF_32BIT)
+#define _TIF_USER_RETURN_NOTIFY	(1<<TIF_USER_RETURN_NOTIFY)
 #define _TIF_RESTORE_TM		(1<<TIF_RESTORE_TM)
 #define _TIF_PATCH_PENDING	(1<<TIF_PATCH_PENDING)
 #define _TIF_SYSCALL_AUDIT	(1<<TIF_SYSCALL_AUDIT)
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 392404688cec..70a9ea949798 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -38,6 +38,7 @@
 #include <linux/uaccess.h>
 #include <linux/pkeys.h>
 #include <linux/seq_buf.h>
+#include <linux/user-return-notifier.h>
 
 #include <asm/interrupt.h>
 #include <asm/io.h>
@@ -1386,6 +1387,7 @@ struct task_struct *__switch_to(struct task_struct *prev,
 	if (current->thread.regs)
 		restore_math(current->thread.regs);
 #endif /* CONFIG_PPC_BOOK3S_64 */
+	propagate_user_return_notify(prev, new);
 
 	return last;
 }
-- 
2.42.0.windows.2



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/7] powerpc/debug: hook to user return notifier infrastructure
       [not found] <20241012035621.1245-3-luming.yu@shingroup.cn>
  2024-10-12  3:56 ` [PATCH 2/7] powerpc/entry: cleanup syscall entry Luming Yu
  2024-10-12  3:56 ` [PATCH 3/7] powerpc/debug: implement HAVE_USER_RETURN_NOTIFIER Luming Yu
@ 2024-10-12  3:56 ` Luming Yu
  2024-10-12  3:56 ` [PATCH 5/7] powerpc/entry: add irqentry_state and generic entry support Luming Yu
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Luming Yu @ 2024-10-12  3:56 UTC (permalink / raw)
  To: linuxppc-dev, linux-kernel, mpe, npiggin, christophe.leroy,
	jialong.yang, luming.yu
  Cc: Luming Yu

calls back to all registered user return notifier functions.

Signed-off-by: Luming Yu <luming.yu@shingroup.cn>
---
 arch/powerpc/kernel/interrupt.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/powerpc/kernel/interrupt.c b/arch/powerpc/kernel/interrupt.c
index 8c532cecbc60..609ba48034de 100644
--- a/arch/powerpc/kernel/interrupt.c
+++ b/arch/powerpc/kernel/interrupt.c
@@ -19,6 +19,7 @@
 #include <asm/time.h>
 #include <asm/tm.h>
 #include <asm/unistd.h>
+#include <asm/entry-common.h>
 
 #if defined(CONFIG_PPC_ADV_DEBUG_REGS) && defined(CONFIG_PPC32)
 unsigned long global_dbcr0[NR_CPUS];
@@ -245,6 +246,8 @@ interrupt_exit_user_prepare_main(unsigned long ret, struct pt_regs *regs)
 	/* Restore user access locks last */
 	kuap_user_restore(regs);
 
+	arch_exit_to_user_mode_prepare(regs, ti_flags);
+
 	return ret;
 }
 
-- 
2.42.0.windows.2



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/7] powerpc/entry: add irqentry_state and generic entry support
       [not found] <20241012035621.1245-3-luming.yu@shingroup.cn>
                   ` (2 preceding siblings ...)
  2024-10-12  3:56 ` [PATCH 4/7] powerpc/debug: hook to user return notifier infrastructure Luming Yu
@ 2024-10-12  3:56 ` Luming Yu
  2024-10-12  9:35   ` Christophe Leroy
  2024-10-12  3:56 ` [PATCH 6/7] powerpc/entry: factout irqentry-state Luming Yu
  2024-10-12  3:56 ` [PATCH 7/7] powerpc/entry: fix 32bit compile issue for common entry Luming Yu
  5 siblings, 1 reply; 10+ messages in thread
From: Luming Yu @ 2024-10-12  3:56 UTC (permalink / raw)
  To: linuxppc-dev, linux-kernel, mpe, npiggin, christophe.leroy,
	jialong.yang, luming.yu
  Cc: Luming Yu

generic irq entry support via generic irqentry is added for powerpc.
There may be duplciate calls and missing callbacks requires further
work.

Signed-off-by: Luming Yu <luming.yu@shingroup.cn>
---
 arch/powerpc/include/asm/entry-common.h | 32 ++++++++++++++++
 arch/powerpc/kernel/interrupt.c         | 51 +++++--------------------
 arch/powerpc/kernel/signal.c            |  7 ++++
 arch/powerpc/kernel/syscall.c           |  2 -
 4 files changed, 49 insertions(+), 43 deletions(-)

diff --git a/arch/powerpc/include/asm/entry-common.h b/arch/powerpc/include/asm/entry-common.h
index 51f1eb767696..faa829e15b5d 100644
--- a/arch/powerpc/include/asm/entry-common.h
+++ b/arch/powerpc/include/asm/entry-common.h
@@ -3,6 +3,7 @@
 #define ARCH_POWERPC_ENTRY_COMMON_H
 
 #include <linux/user-return-notifier.h>
+#include <asm/switch_to.h>
 
 static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
 						  unsigned long ti_work)
@@ -13,4 +14,35 @@ static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
 
 #define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare
 
+static inline void arch_exit_to_user_mode_work(struct pt_regs *regs,
+						unsigned long ti_work)
+{
+
+	if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && IS_ENABLED(CONFIG_PPC_FPU)) {
+		if (IS_ENABLED(CONFIG_PPC_TRANSACTIONAL_MEM) &&
+				unlikely((ti_work & _TIF_RESTORE_TM))) {
+			restore_tm_state(regs);
+		} else {
+			unsigned long mathflags = MSR_FP;
+
+			if (cpu_has_feature(CPU_FTR_VSX))
+				mathflags |= MSR_VEC | MSR_VSX;
+			else if (cpu_has_feature(CPU_FTR_ALTIVEC))
+				mathflags |= MSR_VEC;
+
+			/*
+			 * If userspace MSR has all available FP bits set,
+			 * then they are live and no need to restore. If not,
+			 * it means the regs were given up and restore_math
+			 * may decide to restore them (to avoid taking an FP
+			 * fault).
+			 */
+			if ((regs->msr & mathflags) != mathflags)
+				restore_math(regs);
+		}
+	}
+}
+
+#define arch_exit_to_user_mode_work arch_exit_to_user_mode_work
+
 #endif
diff --git a/arch/powerpc/kernel/interrupt.c b/arch/powerpc/kernel/interrupt.c
index 609ba48034de..42af9217136d 100644
--- a/arch/powerpc/kernel/interrupt.c
+++ b/arch/powerpc/kernel/interrupt.c
@@ -3,6 +3,7 @@
 #include <linux/context_tracking.h>
 #include <linux/err.h>
 #include <linux/compat.h>
+#include <linux/entry-common.h>
 #include <linux/sched/debug.h> /* for show_regs */
 
 #include <asm/kup.h>
@@ -183,47 +184,11 @@ interrupt_exit_user_prepare_main(unsigned long ret, struct pt_regs *regs)
 
 again:
 	ti_flags = read_thread_flags();
-	while (unlikely(ti_flags & (_TIF_USER_WORK_MASK & ~_TIF_RESTORE_TM))) {
-		local_irq_enable();
-		if (ti_flags & _TIF_NEED_RESCHED) {
-			schedule();
-		} else {
-			/*
-			 * SIGPENDING must restore signal handler function
-			 * argument GPRs, and some non-volatiles (e.g., r1).
-			 * Restore all for now. This could be made lighter.
-			 */
-			if (ti_flags & _TIF_SIGPENDING)
-				ret |= _TIF_RESTOREALL;
-			do_notify_resume(regs, ti_flags);
-		}
-		local_irq_disable();
-		ti_flags = read_thread_flags();
-	}
 
-	if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && IS_ENABLED(CONFIG_PPC_FPU)) {
-		if (IS_ENABLED(CONFIG_PPC_TRANSACTIONAL_MEM) &&
-				unlikely((ti_flags & _TIF_RESTORE_TM))) {
-			restore_tm_state(regs);
-		} else {
-			unsigned long mathflags = MSR_FP;
-
-			if (cpu_has_feature(CPU_FTR_VSX))
-				mathflags |= MSR_VEC | MSR_VSX;
-			else if (cpu_has_feature(CPU_FTR_ALTIVEC))
-				mathflags |= MSR_VEC;
-
-			/*
-			 * If userspace MSR has all available FP bits set,
-			 * then they are live and no need to restore. If not,
-			 * it means the regs were given up and restore_math
-			 * may decide to restore them (to avoid taking an FP
-			 * fault).
-			 */
-			if ((regs->msr & mathflags) != mathflags)
-				restore_math(regs);
-		}
-	}
+	if (ti_flags & _TIF_SIGPENDING)
+		ret |= _TIF_RESTOREALL;
+	if (unlikely(ti_flags & EXIT_TO_USER_MODE_WORK))
+		ti_flags = exit_to_user_mode_loop(regs, ti_flags);
 
 	check_return_regs_valid(regs);
 
@@ -297,11 +262,15 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3,
 	}
 
 	local_irq_disable();
-	ret = interrupt_exit_user_prepare_main(ret, regs);
+	if (ti_flags & _TIF_RESTOREALL)
+		ret |= _TIF_RESTOREALL;
 
+	if (ti_flags & _TIF_SIGPENDING)
+		ret |= _TIF_RESTOREALL;
 #ifdef CONFIG_PPC64
 	regs->exit_result = ret;
 #endif
+	syscall_exit_to_user_mode(regs);
 
 	return ret;
 }
diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal.c
index aa17e62f3754..da21e7fef46a 100644
--- a/arch/powerpc/kernel/signal.c
+++ b/arch/powerpc/kernel/signal.c
@@ -11,6 +11,7 @@
 #include <linux/uprobes.h>
 #include <linux/key.h>
 #include <linux/context_tracking.h>
+#include <linux/entry-common.h>
 #include <linux/livepatch.h>
 #include <linux/syscalls.h>
 #include <asm/hw_breakpoint.h>
@@ -368,3 +369,9 @@ void signal_fault(struct task_struct *tsk, struct pt_regs *regs,
 		printk_ratelimited(regs->msr & MSR_64BIT ? fm64 : fm32, tsk->comm,
 				   task_pid_nr(tsk), where, ptr, regs->nip, regs->link);
 }
+
+void arch_do_signal_or_restart(struct pt_regs *regs)
+{
+	BUG_ON(regs != current->thread.regs);
+	do_signal(current);
+}
diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
index e0338bd8d383..97f158d13944 100644
--- a/arch/powerpc/kernel/syscall.c
+++ b/arch/powerpc/kernel/syscall.c
@@ -185,8 +185,6 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
 	 * So the resulting 6 or 7 bits of entropy is seen in SP[9:4] or SP[9:3].
 	 */
 	choose_random_kstack_offset(mftb());
-	/*common entry*/
-	syscall_exit_to_user_mode(regs);
 
 	return ret;
 }
-- 
2.42.0.windows.2



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 6/7] powerpc/entry: factout irqentry-state
       [not found] <20241012035621.1245-3-luming.yu@shingroup.cn>
                   ` (3 preceding siblings ...)
  2024-10-12  3:56 ` [PATCH 5/7] powerpc/entry: add irqentry_state and generic entry support Luming Yu
@ 2024-10-12  3:56 ` Luming Yu
  2024-10-15 15:42   ` Thomas Gleixner
  2024-10-12  3:56 ` [PATCH 7/7] powerpc/entry: fix 32bit compile issue for common entry Luming Yu
  5 siblings, 1 reply; 10+ messages in thread
From: Luming Yu @ 2024-10-12  3:56 UTC (permalink / raw)
  To: linuxppc-dev, linux-kernel, mpe, npiggin, christophe.leroy,
	jialong.yang, luming.yu
  Cc: Luming Yu

To have lowlevel paca.h include high level entry-common.h cause
include file dependency mess. Split irqentry-state.h to have
the irqentry_state.h can be included in low level paca.h

Signed-off-by: Luming Yu <luming.yu@shingroup.cn>
---
 arch/powerpc/include/asm/paca.h |  2 ++
 arch/powerpc/kernel/interrupt.c |  2 ++
 include/linux/entry-common.h    | 24 ------------------------
 include/linux/irqentry-state.h  | 28 ++++++++++++++++++++++++++++
 4 files changed, 32 insertions(+), 24 deletions(-)
 create mode 100644 include/linux/irqentry-state.h

diff --git a/arch/powerpc/include/asm/paca.h b/arch/powerpc/include/asm/paca.h
index e667d455ecb4..83ebe8e914b7 100644
--- a/arch/powerpc/include/asm/paca.h
+++ b/arch/powerpc/include/asm/paca.h
@@ -13,6 +13,7 @@
 #ifdef CONFIG_PPC64
 
 #include <linux/cache.h>
+#include <linux/irqentry-state.h>
 #include <linux/string.h>
 #include <asm/types.h>
 #include <asm/mmu.h>
@@ -282,6 +283,7 @@ struct paca_struct {
 	struct mce_info *mce_info;
 	u8 mce_pending_irq_work;
 #endif /* CONFIG_PPC_BOOK3S_64 */
+	irqentry_state_t irqentry_s;
 } ____cacheline_aligned;
 
 extern void copy_mm_to_paca(struct mm_struct *mm);
diff --git a/arch/powerpc/kernel/interrupt.c b/arch/powerpc/kernel/interrupt.c
index 42af9217136d..8e4cabb0c592 100644
--- a/arch/powerpc/kernel/interrupt.c
+++ b/arch/powerpc/kernel/interrupt.c
@@ -311,6 +311,7 @@ notrace unsigned long interrupt_exit_user_prepare(struct pt_regs *regs)
 	BUG_ON(regs_is_unrecoverable(regs));
 	BUG_ON(arch_irq_disabled_regs(regs));
 	CT_WARN_ON(ct_state() == CONTEXT_USER);
+	local_paca->irqentry_s = irqentry_enter(regs);
 
 	/*
 	 * We don't need to restore AMR on the way back to userspace for KUAP.
@@ -423,6 +424,7 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs)
 	 * AMR value from the check above.
 	 */
 	kuap_kernel_restore(regs, kuap);
+	irqentry_exit(regs, local_paca->irqentry_s);
 
 	return ret;
 }
diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h
index d95ab85f96ba..6521171469f2 100644
--- a/include/linux/entry-common.h
+++ b/include/linux/entry-common.h
@@ -352,30 +352,6 @@ void irqentry_enter_from_user_mode(struct pt_regs *regs);
  */
 void irqentry_exit_to_user_mode(struct pt_regs *regs);
 
-#ifndef irqentry_state
-/**
- * struct irqentry_state - Opaque object for exception state storage
- * @exit_rcu: Used exclusively in the irqentry_*() calls; signals whether the
- *            exit path has to invoke ct_irq_exit().
- * @lockdep: Used exclusively in the irqentry_nmi_*() calls; ensures that
- *           lockdep state is restored correctly on exit from nmi.
- *
- * This opaque object is filled in by the irqentry_*_enter() functions and
- * must be passed back into the corresponding irqentry_*_exit() functions
- * when the exception is complete.
- *
- * Callers of irqentry_*_[enter|exit]() must consider this structure opaque
- * and all members private.  Descriptions of the members are provided to aid in
- * the maintenance of the irqentry_*() functions.
- */
-typedef struct irqentry_state {
-	union {
-		bool	exit_rcu;
-		bool	lockdep;
-	};
-} irqentry_state_t;
-#endif
-
 /**
  * irqentry_enter - Handle state tracking on ordinary interrupt entries
  * @regs:	Pointer to pt_regs of interrupted context
diff --git a/include/linux/irqentry-state.h b/include/linux/irqentry-state.h
new file mode 100644
index 000000000000..d4ddeb1c6ab6
--- /dev/null
+++ b/include/linux/irqentry-state.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LINUX_IRQENTRYCOMMON_H
+#define __LINUX_IRQENTRYCOMMON_H
+
+#ifndef irqentry_state
+/**
+ * struct irqentry_state - Opaque object for exception state storage
+ * @exit_rcu: Used exclusively in the irqentry_*() calls; signals whether the
+ *            exit path has to invoke ct_irq_exit().
+ * @lockdep: Used exclusively in the irqentry_nmi_*() calls; ensures that
+ *           lockdep state is restored correctly on exit from nmi.
+ *
+ * This opaque object is filled in by the irqentry_*_enter() functions and
+ * must be passed back into the corresponding irqentry_*_exit() functions
+ * when the exception is complete.
+ *
+ * Callers of irqentry_*_[enter|exit]() must consider this structure opaque
+ * and all members private.  Descriptions of the members are provided to aid in
+ * the maintenance of the irqentry_*() functions.
+ */
+typedef struct irqentry_state {
+	union {
+		bool	exit_rcu;
+		bool	lockdep;
+	};
+} irqentry_state_t;
+#endif
+#endif
-- 
2.42.0.windows.2



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 7/7] powerpc/entry: fix 32bit compile issue for common entry
       [not found] <20241012035621.1245-3-luming.yu@shingroup.cn>
                   ` (4 preceding siblings ...)
  2024-10-12  3:56 ` [PATCH 6/7] powerpc/entry: factout irqentry-state Luming Yu
@ 2024-10-12  3:56 ` Luming Yu
  5 siblings, 0 replies; 10+ messages in thread
From: Luming Yu @ 2024-10-12  3:56 UTC (permalink / raw)
  To: linuxppc-dev, linux-kernel, mpe, npiggin, christophe.leroy,
	jialong.yang, luming.yu
  Cc: Luming Yu

fix irqentry in 32bit code path and hw_irq helpers.

Signed-off-by: Luming Yu <luming.yu@shingroup.cn>
---
 arch/powerpc/include/asm/hw_irq.h | 6 ++++++
 arch/powerpc/kernel/interrupt.c   | 4 ++++
 include/linux/entry-common.h      | 1 +
 3 files changed, 11 insertions(+)

diff --git a/arch/powerpc/include/asm/hw_irq.h b/arch/powerpc/include/asm/hw_irq.h
index a3d591784c95..99104f95e1d7 100644
--- a/arch/powerpc/include/asm/hw_irq.h
+++ b/arch/powerpc/include/asm/hw_irq.h
@@ -469,6 +469,12 @@ static inline bool arch_irqs_disabled(void)
 	return arch_irqs_disabled_flags(arch_local_save_flags());
 }
 
+/*for common entry*/
+static __always_inline bool regs_irqs_disabled(struct pt_regs *regs)
+{
+	return arch_irqs_disabled();
+}
+
 #define hard_irq_disable()		arch_local_irq_disable()
 
 static inline bool arch_irq_disabled_regs(struct pt_regs *regs)
diff --git a/arch/powerpc/kernel/interrupt.c b/arch/powerpc/kernel/interrupt.c
index 8e4cabb0c592..31167700f894 100644
--- a/arch/powerpc/kernel/interrupt.c
+++ b/arch/powerpc/kernel/interrupt.c
@@ -311,7 +311,9 @@ notrace unsigned long interrupt_exit_user_prepare(struct pt_regs *regs)
 	BUG_ON(regs_is_unrecoverable(regs));
 	BUG_ON(arch_irq_disabled_regs(regs));
 	CT_WARN_ON(ct_state() == CONTEXT_USER);
+#ifdef CONFIG_PPC64
 	local_paca->irqentry_s = irqentry_enter(regs);
+#endif
 
 	/*
 	 * We don't need to restore AMR on the way back to userspace for KUAP.
@@ -424,7 +426,9 @@ notrace unsigned long interrupt_exit_kernel_prepare(struct pt_regs *regs)
 	 * AMR value from the check above.
 	 */
 	kuap_kernel_restore(regs, kuap);
+#ifdef CONFIG_PPC64
 	irqentry_exit(regs, local_paca->irqentry_s);
+#endif
 
 	return ret;
 }
diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h
index 6521171469f2..b68eada65a8a 100644
--- a/include/linux/entry-common.h
+++ b/include/linux/entry-common.h
@@ -8,6 +8,7 @@
 #include <linux/seccomp.h>
 #include <linux/sched.h>
 
+#include <linux/irqentry-state.h>
 #include <asm/entry-common.h>
 
 /*
-- 
2.42.0.windows.2



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 5/7] powerpc/entry: add irqentry_state and generic entry support
  2024-10-12  3:56 ` [PATCH 5/7] powerpc/entry: add irqentry_state and generic entry support Luming Yu
@ 2024-10-12  9:35   ` Christophe Leroy
  2024-10-12 11:27     ` 虞陆铭
  0 siblings, 1 reply; 10+ messages in thread
From: Christophe Leroy @ 2024-10-12  9:35 UTC (permalink / raw)
  To: Luming Yu, linuxppc-dev, linux-kernel, mpe, npiggin, jialong.yang,
	luming.yu



Le 12/10/2024 à 05:56, Luming Yu a écrit :
> generic irq entry support via generic irqentry is added for powerpc.
> There may be duplciate calls and missing callbacks requires further
> work.
> 
> Signed-off-by: Luming Yu <luming.yu@shingroup.cn>

This patch doesn't apply.

Applying: powerpc/entry: add irqentry_state and generic entry support
error: patch failed: arch/powerpc/kernel/interrupt.c:3
error: arch/powerpc/kernel/interrupt.c: patch does not apply
Patch failed at 0005 powerpc/entry: add irqentry_state and generic entry 
support

I tried on v6.11, v6.12-rc2 and next-20241011

> ---
>   arch/powerpc/include/asm/entry-common.h | 32 ++++++++++++++++
>   arch/powerpc/kernel/interrupt.c         | 51 +++++--------------------
>   arch/powerpc/kernel/signal.c            |  7 ++++
>   arch/powerpc/kernel/syscall.c           |  2 -
>   4 files changed, 49 insertions(+), 43 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/entry-common.h b/arch/powerpc/include/asm/entry-common.h
> index 51f1eb767696..faa829e15b5d 100644
> --- a/arch/powerpc/include/asm/entry-common.h
> +++ b/arch/powerpc/include/asm/entry-common.h
> @@ -3,6 +3,7 @@
>   #define ARCH_POWERPC_ENTRY_COMMON_H
>   
>   #include <linux/user-return-notifier.h>
> +#include <asm/switch_to.h>
>   
>   static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
>   						  unsigned long ti_work)
> @@ -13,4 +14,35 @@ static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
>   
>   #define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare
>   
> +static inline void arch_exit_to_user_mode_work(struct pt_regs *regs,
> +						unsigned long ti_work)
> +{
> +
> +	if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && IS_ENABLED(CONFIG_PPC_FPU)) {
> +		if (IS_ENABLED(CONFIG_PPC_TRANSACTIONAL_MEM) &&
> +				unlikely((ti_work & _TIF_RESTORE_TM))) {
> +			restore_tm_state(regs);
> +		} else {
> +			unsigned long mathflags = MSR_FP;
> +
> +			if (cpu_has_feature(CPU_FTR_VSX))
> +				mathflags |= MSR_VEC | MSR_VSX;
> +			else if (cpu_has_feature(CPU_FTR_ALTIVEC))
> +				mathflags |= MSR_VEC;
> +
> +			/*
> +			 * If userspace MSR has all available FP bits set,
> +			 * then they are live and no need to restore. If not,
> +			 * it means the regs were given up and restore_math
> +			 * may decide to restore them (to avoid taking an FP
> +			 * fault).
> +			 */
> +			if ((regs->msr & mathflags) != mathflags)
> +				restore_math(regs);
> +		}
> +	}
> +}
> +
> +#define arch_exit_to_user_mode_work arch_exit_to_user_mode_work
> +
>   #endif
> diff --git a/arch/powerpc/kernel/interrupt.c b/arch/powerpc/kernel/interrupt.c
> index 609ba48034de..42af9217136d 100644
> --- a/arch/powerpc/kernel/interrupt.c
> +++ b/arch/powerpc/kernel/interrupt.c
> @@ -3,6 +3,7 @@
>   #include <linux/context_tracking.h>
>   #include <linux/err.h>
>   #include <linux/compat.h>
> +#include <linux/entry-common.h>
>   #include <linux/sched/debug.h> /* for show_regs */
>   
>   #include <asm/kup.h>
> @@ -183,47 +184,11 @@ interrupt_exit_user_prepare_main(unsigned long ret, struct pt_regs *regs)
>   
>   again:
>   	ti_flags = read_thread_flags();
> -	while (unlikely(ti_flags & (_TIF_USER_WORK_MASK & ~_TIF_RESTORE_TM))) {
> -		local_irq_enable();
> -		if (ti_flags & _TIF_NEED_RESCHED) {
> -			schedule();
> -		} else {
> -			/*
> -			 * SIGPENDING must restore signal handler function
> -			 * argument GPRs, and some non-volatiles (e.g., r1).
> -			 * Restore all for now. This could be made lighter.
> -			 */
> -			if (ti_flags & _TIF_SIGPENDING)
> -				ret |= _TIF_RESTOREALL;
> -			do_notify_resume(regs, ti_flags);
> -		}
> -		local_irq_disable();
> -		ti_flags = read_thread_flags();
> -	}
>   
> -	if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && IS_ENABLED(CONFIG_PPC_FPU)) {
> -		if (IS_ENABLED(CONFIG_PPC_TRANSACTIONAL_MEM) &&
> -				unlikely((ti_flags & _TIF_RESTORE_TM))) {
> -			restore_tm_state(regs);
> -		} else {
> -			unsigned long mathflags = MSR_FP;
> -
> -			if (cpu_has_feature(CPU_FTR_VSX))
> -				mathflags |= MSR_VEC | MSR_VSX;
> -			else if (cpu_has_feature(CPU_FTR_ALTIVEC))
> -				mathflags |= MSR_VEC;
> -
> -			/*
> -			 * If userspace MSR has all available FP bits set,
> -			 * then they are live and no need to restore. If not,
> -			 * it means the regs were given up and restore_math
> -			 * may decide to restore them (to avoid taking an FP
> -			 * fault).
> -			 */
> -			if ((regs->msr & mathflags) != mathflags)
> -				restore_math(regs);
> -		}
> -	}
> +	if (ti_flags & _TIF_SIGPENDING)
> +		ret |= _TIF_RESTOREALL;
> +	if (unlikely(ti_flags & EXIT_TO_USER_MODE_WORK))
> +		ti_flags = exit_to_user_mode_loop(regs, ti_flags);
>   
>   	check_return_regs_valid(regs);
>   
> @@ -297,11 +262,15 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3,
>   	}
>   
>   	local_irq_disable();
> -	ret = interrupt_exit_user_prepare_main(ret, regs);
> +	if (ti_flags & _TIF_RESTOREALL)
> +		ret |= _TIF_RESTOREALL;
>   
> +	if (ti_flags & _TIF_SIGPENDING)
> +		ret |= _TIF_RESTOREALL;
>   #ifdef CONFIG_PPC64
>   	regs->exit_result = ret;
>   #endif
> +	syscall_exit_to_user_mode(regs);
>   
>   	return ret;
>   }
> diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal.c
> index aa17e62f3754..da21e7fef46a 100644
> --- a/arch/powerpc/kernel/signal.c
> +++ b/arch/powerpc/kernel/signal.c
> @@ -11,6 +11,7 @@
>   #include <linux/uprobes.h>
>   #include <linux/key.h>
>   #include <linux/context_tracking.h>
> +#include <linux/entry-common.h>
>   #include <linux/livepatch.h>
>   #include <linux/syscalls.h>
>   #include <asm/hw_breakpoint.h>
> @@ -368,3 +369,9 @@ void signal_fault(struct task_struct *tsk, struct pt_regs *regs,
>   		printk_ratelimited(regs->msr & MSR_64BIT ? fm64 : fm32, tsk->comm,
>   				   task_pid_nr(tsk), where, ptr, regs->nip, regs->link);
>   }
> +
> +void arch_do_signal_or_restart(struct pt_regs *regs)
> +{
> +	BUG_ON(regs != current->thread.regs);
> +	do_signal(current);
> +}
> diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
> index e0338bd8d383..97f158d13944 100644
> --- a/arch/powerpc/kernel/syscall.c
> +++ b/arch/powerpc/kernel/syscall.c
> @@ -185,8 +185,6 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
>   	 * So the resulting 6 or 7 bits of entropy is seen in SP[9:4] or SP[9:3].
>   	 */
>   	choose_random_kstack_offset(mftb());
> -	/*common entry*/
> -	syscall_exit_to_user_mode(regs);
>   
>   	return ret;
>   }


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 5/7] powerpc/entry: add irqentry_state and generic entry support
  2024-10-12  9:35   ` Christophe Leroy
@ 2024-10-12 11:27     ` 虞陆铭
  0 siblings, 0 replies; 10+ messages in thread
From: 虞陆铭 @ 2024-10-12 11:27 UTC (permalink / raw)
  To: Christophe Leroy, linuxppc-dev, linux-kernel, mpe, npiggin,
	jialong.yang, luming.yu

Le 12/10/2024 à 05:56, Luming Yu a écrit :
>> generic irq entry support via generic irqentry is added for powerpc.
>> There may be duplciate calls and missing callbacks requires further
>> work.
>> 
>> Signed-off-by: Luming Yu <luming.yu@shingroup.cn>
>
>This patch doesn't apply.

sorry to hear that. :-(
 
the ppc linux-ci github workflow result:
https://github.com/lumingyu2024/linux-ci/actions/runs/11293630743
>
>Applying: powerpc/entry: add irqentry_state and generic entry support
>error: patch failed: arch/powerpc/kernel/interrupt.c:3
>error: arch/powerpc/kernel/interrupt.c: patch does not apply
>Patch failed at 0005 powerpc/entry: add irqentry_state and generic entry 
>support
>
>I tried on v6.11, v6.12-rc2 and next-20241011
v6.7-rc2 is the branch on top of which I did git send-email -7.
please try it sync with linux ci https://github.com/linuxppc/linux-ci/compare/merge...lumingyu2024:linux-ci:merge
Or I can do a rebase against  v6.12-rc2 later.

> ---
>   arch/powerpc/include/asm/entry-common.h | 32 ++++++++++++++++
>   arch/powerpc/kernel/interrupt.c         | 51 +++++--------------------
>   arch/powerpc/kernel/signal.c            |  7 ++++
>   arch/powerpc/kernel/syscall.c           |  2 -
>   4 files changed, 49 insertions(+), 43 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/entry-common.h b/arch/powerpc/include/asm/entry-common.h
> index 51f1eb767696..faa829e15b5d 100644
> --- a/arch/powerpc/include/asm/entry-common.h
> +++ b/arch/powerpc/include/asm/entry-common.h
> @@ -3,6 +3,7 @@
>   #define ARCH_POWERPC_ENTRY_COMMON_H
>   
>   #include <linux/user-return-notifier.h>
> +#include <asm/switch_to.h>
>   
>   static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
>   						  unsigned long ti_work)
> @@ -13,4 +14,35 @@ static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
>   
>   #define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare
>   
> +static inline void arch_exit_to_user_mode_work(struct pt_regs *regs,
> +						unsigned long ti_work)
> +{
> +
> +	if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && IS_ENABLED(CONFIG_PPC_FPU)) {
> +		if (IS_ENABLED(CONFIG_PPC_TRANSACTIONAL_MEM) &&
> +				unlikely((ti_work & _TIF_RESTORE_TM))) {
> +			restore_tm_state(regs);
> +		} else {
> +			unsigned long mathflags = MSR_FP;
> +
> +			if (cpu_has_feature(CPU_FTR_VSX))
> +				mathflags |= MSR_VEC | MSR_VSX;
> +			else if (cpu_has_feature(CPU_FTR_ALTIVEC))
> +				mathflags |= MSR_VEC;
> +
> +			/*
> +			 * If userspace MSR has all available FP bits set,
> +			 * then they are live and no need to restore. If not,
> +			 * it means the regs were given up and restore_math
> +			 * may decide to restore them (to avoid taking an FP
> +			 * fault).
> +			 */
> +			if ((regs->msr & mathflags) != mathflags)
> +				restore_math(regs);
> +		}
> +	}
> +}
> +
> +#define arch_exit_to_user_mode_work arch_exit_to_user_mode_work
> +
>   #endif
> diff --git a/arch/powerpc/kernel/interrupt.c b/arch/powerpc/kernel/interrupt.c
> index 609ba48034de..42af9217136d 100644
> --- a/arch/powerpc/kernel/interrupt.c
> +++ b/arch/powerpc/kernel/interrupt.c
> @@ -3,6 +3,7 @@
>   #include <linux/context_tracking.h>
>   #include <linux/err.h>
>   #include <linux/compat.h>
> +#include <linux/entry-common.h>
>   #include <linux/sched/debug.h> /* for show_regs */
>   
>   #include <asm/kup.h>
> @@ -183,47 +184,11 @@ interrupt_exit_user_prepare_main(unsigned long ret, struct pt_regs *regs)
>   
>   again:
>   	ti_flags = read_thread_flags();
> -	while (unlikely(ti_flags & (_TIF_USER_WORK_MASK & ~_TIF_RESTORE_TM))) {
> -		local_irq_enable();
> -		if (ti_flags & _TIF_NEED_RESCHED) {
> -			schedule();
> -		} else {
> -			/*
> -			 * SIGPENDING must restore signal handler function
> -			 * argument GPRs, and some non-volatiles (e.g., r1).
> -			 * Restore all for now. This could be made lighter.
> -			 */
> -			if (ti_flags & _TIF_SIGPENDING)
> -				ret |= _TIF_RESTOREALL;
> -			do_notify_resume(regs, ti_flags);
> -		}
> -		local_irq_disable();
> -		ti_flags = read_thread_flags();
> -	}
>   
> -	if (IS_ENABLED(CONFIG_PPC_BOOK3S_64) && IS_ENABLED(CONFIG_PPC_FPU)) {
> -		if (IS_ENABLED(CONFIG_PPC_TRANSACTIONAL_MEM) &&
> -				unlikely((ti_flags & _TIF_RESTORE_TM))) {
> -			restore_tm_state(regs);
> -		} else {
> -			unsigned long mathflags = MSR_FP;
> -
> -			if (cpu_has_feature(CPU_FTR_VSX))
> -				mathflags |= MSR_VEC | MSR_VSX;
> -			else if (cpu_has_feature(CPU_FTR_ALTIVEC))
> -				mathflags |= MSR_VEC;
> -
> -			/*
> -			 * If userspace MSR has all available FP bits set,
> -			 * then they are live and no need to restore. If not,
> -			 * it means the regs were given up and restore_math
> -			 * may decide to restore them (to avoid taking an FP
> -			 * fault).
> -			 */
> -			if ((regs->msr & mathflags) != mathflags)
> -				restore_math(regs);
> -		}
> -	}
> +	if (ti_flags & _TIF_SIGPENDING)
> +		ret |= _TIF_RESTOREALL;
> +	if (unlikely(ti_flags & EXIT_TO_USER_MODE_WORK))
> +		ti_flags = exit_to_user_mode_loop(regs, ti_flags);
>   
>   	check_return_regs_valid(regs);
>   
> @@ -297,11 +262,15 @@ notrace unsigned long syscall_exit_prepare(unsigned long r3,
>   	}
>   
>   	local_irq_disable();
> -	ret = interrupt_exit_user_prepare_main(ret, regs);
> +	if (ti_flags & _TIF_RESTOREALL)
> +		ret |= _TIF_RESTOREALL;
>   
> +	if (ti_flags & _TIF_SIGPENDING)
> +		ret |= _TIF_RESTOREALL;
>   #ifdef CONFIG_PPC64
>   	regs->exit_result = ret;
>   #endif
> +	syscall_exit_to_user_mode(regs);
>   
>   	return ret;
>   }
> diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal.c
> index aa17e62f3754..da21e7fef46a 100644
> --- a/arch/powerpc/kernel/signal.c
> +++ b/arch/powerpc/kernel/signal.c
> @@ -11,6 +11,7 @@
>   #include <linux/uprobes.h>
>   #include <linux/key.h>
>   #include <linux/context_tracking.h>
> +#include <linux/entry-common.h>
>   #include <linux/livepatch.h>
>   #include <linux/syscalls.h>
>   #include <asm/hw_breakpoint.h>
> @@ -368,3 +369,9 @@ void signal_fault(struct task_struct *tsk, struct pt_regs *regs,
>   		printk_ratelimited(regs->msr & MSR_64BIT ? fm64 : fm32, tsk->comm,
>   				   task_pid_nr(tsk), where, ptr, regs->nip, regs->link);
>   }
> +
> +void arch_do_signal_or_restart(struct pt_regs *regs)
> +{
> +	BUG_ON(regs != current->thread.regs);
> +	do_signal(current);
> +}
> diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
> index e0338bd8d383..97f158d13944 100644
> --- a/arch/powerpc/kernel/syscall.c
> +++ b/arch/powerpc/kernel/syscall.c
> @@ -185,8 +185,6 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
>   	 * So the resulting 6 or 7 bits of entropy is seen in SP[9:4] or SP[9:3].
>   	 */
>   	choose_random_kstack_offset(mftb());
> -	/*common entry*/
> -	syscall_exit_to_user_mode(regs);
>   
>   	return ret;
>   }

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 6/7] powerpc/entry: factout irqentry-state
  2024-10-12  3:56 ` [PATCH 6/7] powerpc/entry: factout irqentry-state Luming Yu
@ 2024-10-15 15:42   ` Thomas Gleixner
  2024-11-11  3:45     ` Luming Yu
  0 siblings, 1 reply; 10+ messages in thread
From: Thomas Gleixner @ 2024-10-15 15:42 UTC (permalink / raw)
  To: Luming Yu, linuxppc-dev, linux-kernel, mpe, npiggin,
	christophe.leroy, jialong.yang, luming.yu
  Cc: Luming Yu

On Sat, Oct 12 2024 at 11:56, Luming Yu wrote:

> To have lowlevel paca.h include high level entry-common.h cause
> include file dependency mess. Split irqentry-state.h to have
> the irqentry_state.h can be included in low level paca.h

What's the rationale for this?

> Signed-off-by: Luming Yu <luming.yu@shingroup.cn>
> ---
>  arch/powerpc/include/asm/paca.h |  2 ++
>  arch/powerpc/kernel/interrupt.c |  2 ++
>  include/linux/entry-common.h    | 24 ------------------------
>  include/linux/irqentry-state.h  | 28 ++++++++++++++++++++++++++++

This is not how it works. Split the include file in a first step and
then make changes to the PPC side.

> diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h
> index d95ab85f96ba..6521171469f2 100644
> --- a/include/linux/entry-common.h
> +++ b/include/linux/entry-common.h
> @@ -352,30 +352,6 @@ void irqentry_enter_from_user_mode(struct pt_regs *regs);
>   */
>  void irqentry_exit_to_user_mode(struct pt_regs *regs);
>  
> -#ifndef irqentry_state
> -/**
> - * struct irqentry_state - Opaque object for exception state storage
> - * @exit_rcu: Used exclusively in the irqentry_*() calls; signals whether the
> - *            exit path has to invoke ct_irq_exit().
> - * @lockdep: Used exclusively in the irqentry_nmi_*() calls; ensures that
> - *           lockdep state is restored correctly on exit from nmi.
> - *
> - * This opaque object is filled in by the irqentry_*_enter() functions and
> - * must be passed back into the corresponding irqentry_*_exit() functions
> - * when the exception is complete.
> - *
> - * Callers of irqentry_*_[enter|exit]() must consider this structure opaque
> - * and all members private.  Descriptions of the members are provided to aid in
> - * the maintenance of the irqentry_*() functions.
> - */
> -typedef struct irqentry_state {
> -	union {
> -		bool	exit_rcu;
> -		bool	lockdep;
> -	};
> -} irqentry_state_t;
> -#endif
> -
>  /**
>   * irqentry_enter - Handle state tracking on ordinary interrupt entries
>   * @regs:	Pointer to pt_regs of interrupted context
> diff --git a/include/linux/irqentry-state.h b/include/linux/irqentry-state.h
> new file mode 100644
> index 000000000000..d4ddeb1c6ab6
> --- /dev/null
> +++ b/include/linux/irqentry-state.h
> @@ -0,0 +1,28 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef __LINUX_IRQENTRYCOMMON_H
> +#define __LINUX_IRQENTRYCOMMON_H

The guards reflect the header file name and are not randomly chosen strings.

But aside of that. How is any of this supposed to compile?

You move the typedef into a separate header and then nothing (except
powerpc) includes it. Oh well.

Thanks,

        tglx


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 6/7] powerpc/entry: factout irqentry-state
  2024-10-15 15:42   ` Thomas Gleixner
@ 2024-11-11  3:45     ` Luming Yu
  0 siblings, 0 replies; 10+ messages in thread
From: Luming Yu @ 2024-11-11  3:45 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: linuxppc-dev, linux-kernel, mpe, npiggin, christophe.leroy,
	luming.yu

On Tue, Oct 15, 2024 at 05:42:45PM +0200, Thomas Gleixner wrote:
> On Sat, Oct 12 2024 at 11:56, Luming Yu wrote:
> 
> > To have lowlevel paca.h include high level entry-common.h cause
> > include file dependency mess. Split irqentry-state.h to have
> > the irqentry_state.h can be included in low level paca.h
> 
> What's the rationale for this?
> 
> > Signed-off-by: Luming Yu <luming.yu@shingroup.cn>
> > ---
> >  arch/powerpc/include/asm/paca.h |  2 ++
> >  arch/powerpc/kernel/interrupt.c |  2 ++
> >  include/linux/entry-common.h    | 24 ------------------------
> >  include/linux/irqentry-state.h  | 28 ++++++++++++++++++++++++++++
> 
> This is not how it works. Split the include file in a first step and
> then make changes to the PPC side.
> 
> > diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h
> > index d95ab85f96ba..6521171469f2 100644
> > --- a/include/linux/entry-common.h
> > +++ b/include/linux/entry-common.h
> > @@ -352,30 +352,6 @@ void irqentry_enter_from_user_mode(struct pt_regs *regs);
> >   */
> >  void irqentry_exit_to_user_mode(struct pt_regs *regs);
> >  
> > -#ifndef irqentry_state
> > -/**
> > - * struct irqentry_state - Opaque object for exception state storage
> > - * @exit_rcu: Used exclusively in the irqentry_*() calls; signals whether the
> > - *            exit path has to invoke ct_irq_exit().
> > - * @lockdep: Used exclusively in the irqentry_nmi_*() calls; ensures that
> > - *           lockdep state is restored correctly on exit from nmi.
> > - *
> > - * This opaque object is filled in by the irqentry_*_enter() functions and
> > - * must be passed back into the corresponding irqentry_*_exit() functions
> > - * when the exception is complete.
> > - *
> > - * Callers of irqentry_*_[enter|exit]() must consider this structure opaque
> > - * and all members private.  Descriptions of the members are provided to aid in
> > - * the maintenance of the irqentry_*() functions.
> > - */
> > -typedef struct irqentry_state {
> > -	union {
> > -		bool	exit_rcu;
> > -		bool	lockdep;
> > -	};
> > -} irqentry_state_t;
> > -#endif
> > -
> >  /**
> >   * irqentry_enter - Handle state tracking on ordinary interrupt entries
> >   * @regs:	Pointer to pt_regs of interrupted context
> > diff --git a/include/linux/irqentry-state.h b/include/linux/irqentry-state.h
> > new file mode 100644
> > index 000000000000..d4ddeb1c6ab6
> > --- /dev/null
> > +++ b/include/linux/irqentry-state.h
> > @@ -0,0 +1,28 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +#ifndef __LINUX_IRQENTRYCOMMON_H
> > +#define __LINUX_IRQENTRYCOMMON_H
> 
> The guards reflect the header file name and are not randomly chosen strings.
> 
> But aside of that. How is any of this supposed to compile?
> 
> You move the typedef into a separate header and then nothing (except
> powerpc) includes it. Oh well.
thanks for review, I will fix it in V3.
> 
> Thanks,
> 
>         tglx
> 



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-11-11  3:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20241012035621.1245-3-luming.yu@shingroup.cn>
2024-10-12  3:56 ` [PATCH 2/7] powerpc/entry: cleanup syscall entry Luming Yu
2024-10-12  3:56 ` [PATCH 3/7] powerpc/debug: implement HAVE_USER_RETURN_NOTIFIER Luming Yu
2024-10-12  3:56 ` [PATCH 4/7] powerpc/debug: hook to user return notifier infrastructure Luming Yu
2024-10-12  3:56 ` [PATCH 5/7] powerpc/entry: add irqentry_state and generic entry support Luming Yu
2024-10-12  9:35   ` Christophe Leroy
2024-10-12 11:27     ` 虞陆铭
2024-10-12  3:56 ` [PATCH 6/7] powerpc/entry: factout irqentry-state Luming Yu
2024-10-15 15:42   ` Thomas Gleixner
2024-11-11  3:45     ` Luming Yu
2024-10-12  3:56 ` [PATCH 7/7] powerpc/entry: fix 32bit compile issue for common entry Luming Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).