* [PATCH 0/3] Handle delay slot for extable lookup
@ 2024-02-01 15:46 Jiaxun Yang
2024-02-01 15:46 ` [PATCH 1/3] ptrace: Introduce exception_ip arch hook Jiaxun Yang
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Jiaxun Yang @ 2024-02-01 15:46 UTC (permalink / raw)
To: Oleg Nesterov, Thomas Bogendoerfer, Andrew Morton, Ben Hutchings
Cc: linux-arch, linux-kernel, linux-mips, linux-mm, Jiaxun Yang,
Xi Ruoyao, Linus Torvalds
Hi all,
This series fixed extable handling for architecture delay slot (MIPS).
Please see previous discussions at [1].
There are some other places in kernel not handling delay slots properly,
such as uprobe and kgdb, I'll sort them later.
Thanks!
[1]: https://lore.kernel.org/lkml/75e9fd7b08562ad9b456a5bdaacb7cc220311cc9.camel@xry111.site
To: Oleg Nesterov <oleg@redhat.com>
To: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
To: Andrew Morton <akpm@linux-foundation.org>
To: Ben Hutchings <ben@decadent.org.uk>
Cc: <linux-arch@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>
Cc: <linux-mips@vger.kernel.org>
Cc: <linux-mm@kvack.org>
Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
Jiaxun Yang (3):
ptrace: Introduce exception_ip arch hook
MIPS: Clear Cause.BD in instruction_pointer_set
mm/memory: Use exception ip to search exception tables
arch/alpha/include/asm/ptrace.h | 1 +
arch/arc/include/asm/ptrace.h | 1 +
arch/arm/include/asm/ptrace.h | 1 +
arch/csky/include/asm/ptrace.h | 1 +
arch/hexagon/include/uapi/asm/ptrace.h | 1 +
arch/loongarch/include/asm/ptrace.h | 1 +
arch/m68k/include/asm/ptrace.h | 1 +
arch/microblaze/include/asm/ptrace.h | 3 ++-
arch/mips/include/asm/ptrace.h | 2 ++
arch/mips/kernel/ptrace.c | 7 +++++++
arch/nios2/include/asm/ptrace.h | 3 ++-
arch/openrisc/include/asm/ptrace.h | 1 +
arch/parisc/include/asm/ptrace.h | 1 +
arch/s390/include/asm/ptrace.h | 1 +
arch/sparc/include/asm/ptrace.h | 2 ++
arch/um/include/asm/ptrace-generic.h | 1 +
mm/memory.c | 4 ++--
17 files changed, 28 insertions(+), 4 deletions(-)
---
base-commit: 06f658aadff0e483ee4f807b0b46c9e5cba62bfa
change-id: 20240131-exception_ip-194e4ad0e6ca
Best regards,
--
Jiaxun Yang <jiaxun.yang@flygoat.com>
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 1/3] ptrace: Introduce exception_ip arch hook 2024-02-01 15:46 [PATCH 0/3] Handle delay slot for extable lookup Jiaxun Yang @ 2024-02-01 15:46 ` Jiaxun Yang 2024-02-01 16:35 ` Xi Ruoyao 2024-02-01 15:46 ` [PATCH 2/3] MIPS: Clear Cause.BD in instruction_pointer_set Jiaxun Yang ` (2 subsequent siblings) 3 siblings, 1 reply; 9+ messages in thread From: Jiaxun Yang @ 2024-02-01 15:46 UTC (permalink / raw) To: Oleg Nesterov, Thomas Bogendoerfer, Andrew Morton, Ben Hutchings Cc: linux-arch, linux-kernel, linux-mips, linux-mm, Jiaxun Yang On architectures with delay slot, architecture level instruction pointer (or program counter) in pt_regs may differ from where exception was triggered. Introduce exception_ip hook to invoke architecture code and determine actual instruction pointer to the exception. Link: https://lore.kernel.org/lkml/00d1b813-c55f-4365-8d81-d70258e10b16@app.fastmail.com/ Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com> --- arch/alpha/include/asm/ptrace.h | 1 + arch/arc/include/asm/ptrace.h | 1 + arch/arm/include/asm/ptrace.h | 1 + arch/csky/include/asm/ptrace.h | 1 + arch/hexagon/include/uapi/asm/ptrace.h | 1 + arch/loongarch/include/asm/ptrace.h | 1 + arch/m68k/include/asm/ptrace.h | 1 + arch/microblaze/include/asm/ptrace.h | 3 ++- arch/mips/include/asm/ptrace.h | 1 + arch/mips/kernel/ptrace.c | 7 +++++++ arch/nios2/include/asm/ptrace.h | 3 ++- arch/openrisc/include/asm/ptrace.h | 1 + arch/parisc/include/asm/ptrace.h | 1 + arch/s390/include/asm/ptrace.h | 1 + arch/sparc/include/asm/ptrace.h | 2 ++ arch/um/include/asm/ptrace-generic.h | 1 + 16 files changed, 25 insertions(+), 2 deletions(-) diff --git a/arch/alpha/include/asm/ptrace.h b/arch/alpha/include/asm/ptrace.h index 3557ce64ed21..1ded3f2d09e9 100644 --- a/arch/alpha/include/asm/ptrace.h +++ b/arch/alpha/include/asm/ptrace.h @@ -8,6 +8,7 @@ #define arch_has_single_step() (1) #define user_mode(regs) (((regs)->ps & 8) != 0) #define instruction_pointer(regs) ((regs)->pc) +#define exception_ip(regs) instruction_pointer(regs) #define profile_pc(regs) instruction_pointer(regs) #define current_user_stack_pointer() rdusp() diff --git a/arch/arc/include/asm/ptrace.h b/arch/arc/include/asm/ptrace.h index 00b9318e551e..94084f1048df 100644 --- a/arch/arc/include/asm/ptrace.h +++ b/arch/arc/include/asm/ptrace.h @@ -105,6 +105,7 @@ struct callee_regs { #endif #define instruction_pointer(regs) ((regs)->ret) +#define exception_ip(regs) instruction_pointer(regs) #define profile_pc(regs) instruction_pointer(regs) /* return 1 if user mode or 0 if kernel mode */ diff --git a/arch/arm/include/asm/ptrace.h b/arch/arm/include/asm/ptrace.h index 7f44e88d1f25..fb4dc23eba78 100644 --- a/arch/arm/include/asm/ptrace.h +++ b/arch/arm/include/asm/ptrace.h @@ -89,6 +89,7 @@ static inline long regs_return_value(struct pt_regs *regs) } #define instruction_pointer(regs) (regs)->ARM_pc +#define exception_ip(regs) instruction_pointer(regs) #ifdef CONFIG_THUMB2_KERNEL #define frame_pointer(regs) (regs)->ARM_r7 diff --git a/arch/csky/include/asm/ptrace.h b/arch/csky/include/asm/ptrace.h index 0634b7895d81..a738630e64b0 100644 --- a/arch/csky/include/asm/ptrace.h +++ b/arch/csky/include/asm/ptrace.h @@ -22,6 +22,7 @@ #define user_mode(regs) (!((regs)->sr & PS_S)) #define instruction_pointer(regs) ((regs)->pc) +#define exception_ip(regs) instruction_pointer(regs) #define profile_pc(regs) instruction_pointer(regs) #define trap_no(regs) ((regs->sr >> 16) & 0xff) diff --git a/arch/hexagon/include/uapi/asm/ptrace.h b/arch/hexagon/include/uapi/asm/ptrace.h index 2a3ea14ad9b9..846471936237 100644 --- a/arch/hexagon/include/uapi/asm/ptrace.h +++ b/arch/hexagon/include/uapi/asm/ptrace.h @@ -25,6 +25,7 @@ #include <asm/registers.h> #define instruction_pointer(regs) pt_elr(regs) +#define exception_ip(regs) instruction_pointer(regs) #define user_stack_pointer(regs) ((regs)->r29) #define profile_pc(regs) instruction_pointer(regs) diff --git a/arch/loongarch/include/asm/ptrace.h b/arch/loongarch/include/asm/ptrace.h index f3ddaed9ef7f..a34327f0e69d 100644 --- a/arch/loongarch/include/asm/ptrace.h +++ b/arch/loongarch/include/asm/ptrace.h @@ -160,6 +160,7 @@ static inline void regs_set_return_value(struct pt_regs *regs, unsigned long val } #define instruction_pointer(regs) ((regs)->csr_era) +#define exception_ip(regs) instruction_pointer(regs) #define profile_pc(regs) instruction_pointer(regs) extern void die(const char *str, struct pt_regs *regs); diff --git a/arch/m68k/include/asm/ptrace.h b/arch/m68k/include/asm/ptrace.h index ea5a80ca1ab3..cb553e2ec73a 100644 --- a/arch/m68k/include/asm/ptrace.h +++ b/arch/m68k/include/asm/ptrace.h @@ -13,6 +13,7 @@ #define user_mode(regs) (!((regs)->sr & PS_S)) #define instruction_pointer(regs) ((regs)->pc) +#define exception_ip(regs) instruction_pointer(regs) #define profile_pc(regs) instruction_pointer(regs) #define current_pt_regs() \ (struct pt_regs *)((char *)current_thread_info() + THREAD_SIZE) - 1 diff --git a/arch/microblaze/include/asm/ptrace.h b/arch/microblaze/include/asm/ptrace.h index bfcb89df5e26..974c00fa7212 100644 --- a/arch/microblaze/include/asm/ptrace.h +++ b/arch/microblaze/include/asm/ptrace.h @@ -12,7 +12,8 @@ #define user_mode(regs) (!kernel_mode(regs)) #define instruction_pointer(regs) ((regs)->pc) -#define profile_pc(regs) instruction_pointer(regs) +#define exception_ip(regs) instruction_pointer(regs) +#define profile_pc(regs) instruction_pointer(regs) #define user_stack_pointer(regs) ((regs)->r1) static inline long regs_return_value(struct pt_regs *regs) diff --git a/arch/mips/include/asm/ptrace.h b/arch/mips/include/asm/ptrace.h index daf3cf244ea9..97589731fd40 100644 --- a/arch/mips/include/asm/ptrace.h +++ b/arch/mips/include/asm/ptrace.h @@ -154,6 +154,7 @@ static inline long regs_return_value(struct pt_regs *regs) } #define instruction_pointer(regs) ((regs)->cp0_epc) +extern unsigned long exception_ip(struct pt_regs *regs); #define profile_pc(regs) instruction_pointer(regs) extern asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall); diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c index d9df543f7e2c..59288c13b581 100644 --- a/arch/mips/kernel/ptrace.c +++ b/arch/mips/kernel/ptrace.c @@ -31,6 +31,7 @@ #include <linux/seccomp.h> #include <linux/ftrace.h> +#include <asm/branch.h> #include <asm/byteorder.h> #include <asm/cpu.h> #include <asm/cpu-info.h> @@ -48,6 +49,12 @@ #define CREATE_TRACE_POINTS #include <trace/events/syscalls.h> +unsigned long exception_ip(struct pt_regs *regs) +{ + return exception_epc(regs); +} +EXPORT_SYMBOL(exception_ip); + /* * Called by kernel/ptrace.c when detaching.. * diff --git a/arch/nios2/include/asm/ptrace.h b/arch/nios2/include/asm/ptrace.h index 9da34c3022a2..136f5679ae79 100644 --- a/arch/nios2/include/asm/ptrace.h +++ b/arch/nios2/include/asm/ptrace.h @@ -66,7 +66,8 @@ struct switch_stack { #define user_mode(regs) (((regs)->estatus & ESTATUS_EU)) #define instruction_pointer(regs) ((regs)->ra) -#define profile_pc(regs) instruction_pointer(regs) +#define exception_ip(regs) instruction_pointer(regs) +#define profile_pc(regs) instruction_pointer(regs) #define user_stack_pointer(regs) ((regs)->sp) extern void show_regs(struct pt_regs *); diff --git a/arch/openrisc/include/asm/ptrace.h b/arch/openrisc/include/asm/ptrace.h index 375147ff71fc..67c28484d17e 100644 --- a/arch/openrisc/include/asm/ptrace.h +++ b/arch/openrisc/include/asm/ptrace.h @@ -67,6 +67,7 @@ struct pt_regs { #define STACK_FRAME_OVERHEAD 128 /* size of minimum stack frame */ #define instruction_pointer(regs) ((regs)->pc) +#define exception_ip(regs) instruction_pointer(regs) #define user_mode(regs) (((regs)->sr & SPR_SR_SM) == 0) #define user_stack_pointer(regs) ((unsigned long)(regs)->sp) #define profile_pc(regs) instruction_pointer(regs) diff --git a/arch/parisc/include/asm/ptrace.h b/arch/parisc/include/asm/ptrace.h index eea3f3df0823..d7e8dcf26582 100644 --- a/arch/parisc/include/asm/ptrace.h +++ b/arch/parisc/include/asm/ptrace.h @@ -17,6 +17,7 @@ #define user_mode(regs) (((regs)->iaoq[0] & 3) != PRIV_KERNEL) #define user_space(regs) ((regs)->iasq[1] != PRIV_KERNEL) #define instruction_pointer(regs) ((regs)->iaoq[0] & ~3) +#define exception_ip(regs) instruction_pointer(regs) #define user_stack_pointer(regs) ((regs)->gr[30]) unsigned long profile_pc(struct pt_regs *); diff --git a/arch/s390/include/asm/ptrace.h b/arch/s390/include/asm/ptrace.h index d28bf8fb2799..a5255b2337af 100644 --- a/arch/s390/include/asm/ptrace.h +++ b/arch/s390/include/asm/ptrace.h @@ -211,6 +211,7 @@ static inline int test_and_clear_pt_regs_flag(struct pt_regs *regs, int flag) #define user_mode(regs) (((regs)->psw.mask & PSW_MASK_PSTATE) != 0) #define instruction_pointer(regs) ((regs)->psw.addr) +#define exception_ip(regs) instruction_pointer(regs) #define user_stack_pointer(regs)((regs)->gprs[15]) #define profile_pc(regs) instruction_pointer(regs) diff --git a/arch/sparc/include/asm/ptrace.h b/arch/sparc/include/asm/ptrace.h index d1419e669027..41ae186f2245 100644 --- a/arch/sparc/include/asm/ptrace.h +++ b/arch/sparc/include/asm/ptrace.h @@ -63,6 +63,7 @@ extern union global_cpu_snapshot global_cpu_snapshot[NR_CPUS]; #define force_successful_syscall_return() set_thread_noerror(1) #define user_mode(regs) (!((regs)->tstate & TSTATE_PRIV)) #define instruction_pointer(regs) ((regs)->tpc) +#define exception_ip(regs) instruction_pointer(regs) #define instruction_pointer_set(regs, val) do { \ (regs)->tpc = (val); \ (regs)->tnpc = (val)+4; \ @@ -142,6 +143,7 @@ static inline bool pt_regs_clear_syscall(struct pt_regs *regs) #define user_mode(regs) (!((regs)->psr & PSR_PS)) #define instruction_pointer(regs) ((regs)->pc) +#define exception_ip(regs) instruction_pointer(regs) #define user_stack_pointer(regs) ((regs)->u_regs[UREG_FP]) unsigned long profile_pc(struct pt_regs *); #else /* (!__ASSEMBLY__) */ diff --git a/arch/um/include/asm/ptrace-generic.h b/arch/um/include/asm/ptrace-generic.h index adf91ef553ae..f9ada287ca12 100644 --- a/arch/um/include/asm/ptrace-generic.h +++ b/arch/um/include/asm/ptrace-generic.h @@ -26,6 +26,7 @@ struct pt_regs { #define PT_REGS_SYSCALL_NR(r) UPT_SYSCALL_NR(&(r)->regs) #define instruction_pointer(regs) PT_REGS_IP(regs) +#define exception_ip(regs) instruction_pointer(regs) #define PTRACE_OLDSETOPTIONS 21 -- 2.43.0 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/3] ptrace: Introduce exception_ip arch hook 2024-02-01 15:46 ` [PATCH 1/3] ptrace: Introduce exception_ip arch hook Jiaxun Yang @ 2024-02-01 16:35 ` Xi Ruoyao 2024-02-01 17:13 ` Jiaxun Yang 0 siblings, 1 reply; 9+ messages in thread From: Xi Ruoyao @ 2024-02-01 16:35 UTC (permalink / raw) To: Jiaxun Yang, Oleg Nesterov, Thomas Bogendoerfer, Andrew Morton, Ben Hutchings Cc: linux-arch, linux-kernel, linux-mips, linux-mm On Thu, 2024-02-01 at 15:46 +0000, Jiaxun Yang wrote: > On architectures with delay slot, architecture level instruction > pointer (or program counter) in pt_regs may differ from where > exception was triggered. > > Introduce exception_ip hook to invoke architecture code and determine > actual instruction pointer to the exception. > > Link: > https://lore.kernel.org/lkml/00d1b813-c55f-4365-8d81-d70258e10b16@app.fastmail.com/ > Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com> How about adding something like #ifndef arch_exception_ip #define exception_ip(regs) instruction_pointer(regs) #else #define exception_ip(regs) arch_exception_ip(regs) #endif into a generic header, instead of having to add exception_ip definition everywhere? > --- > arch/alpha/include/asm/ptrace.h | 1 + > arch/arc/include/asm/ptrace.h | 1 + > arch/arm/include/asm/ptrace.h | 1 + > arch/csky/include/asm/ptrace.h | 1 + > arch/hexagon/include/uapi/asm/ptrace.h | 1 + > arch/loongarch/include/asm/ptrace.h | 1 + > arch/m68k/include/asm/ptrace.h | 1 + > arch/microblaze/include/asm/ptrace.h | 3 ++- > arch/mips/include/asm/ptrace.h | 1 + > arch/mips/kernel/ptrace.c | 7 +++++++ > arch/nios2/include/asm/ptrace.h | 3 ++- > arch/openrisc/include/asm/ptrace.h | 1 + > arch/parisc/include/asm/ptrace.h | 1 + > arch/s390/include/asm/ptrace.h | 1 + > arch/sparc/include/asm/ptrace.h | 2 ++ > arch/um/include/asm/ptrace-generic.h | 1 + > 16 files changed, 25 insertions(+), 2 deletions(-) > > diff --git a/arch/alpha/include/asm/ptrace.h > b/arch/alpha/include/asm/ptrace.h > index 3557ce64ed21..1ded3f2d09e9 100644 > --- a/arch/alpha/include/asm/ptrace.h > +++ b/arch/alpha/include/asm/ptrace.h > @@ -8,6 +8,7 @@ > #define arch_has_single_step() (1) > #define user_mode(regs) (((regs)->ps & 8) != 0) > #define instruction_pointer(regs) ((regs)->pc) > +#define exception_ip(regs) instruction_pointer(regs) > #define profile_pc(regs) instruction_pointer(regs) > #define current_user_stack_pointer() rdusp() > > diff --git a/arch/arc/include/asm/ptrace.h > b/arch/arc/include/asm/ptrace.h > index 00b9318e551e..94084f1048df 100644 > --- a/arch/arc/include/asm/ptrace.h > +++ b/arch/arc/include/asm/ptrace.h > @@ -105,6 +105,7 @@ struct callee_regs { > #endif > > #define instruction_pointer(regs) ((regs)->ret) > +#define exception_ip(regs) instruction_pointer(regs) > #define profile_pc(regs) instruction_pointer(regs) > > /* return 1 if user mode or 0 if kernel mode */ > diff --git a/arch/arm/include/asm/ptrace.h > b/arch/arm/include/asm/ptrace.h > index 7f44e88d1f25..fb4dc23eba78 100644 > --- a/arch/arm/include/asm/ptrace.h > +++ b/arch/arm/include/asm/ptrace.h > @@ -89,6 +89,7 @@ static inline long regs_return_value(struct pt_regs > *regs) > } > > #define instruction_pointer(regs) (regs)->ARM_pc > +#define > exception_ip(regs) instruction_pointer(regs) > > #ifdef CONFIG_THUMB2_KERNEL > #define frame_pointer(regs) (regs)->ARM_r7 > diff --git a/arch/csky/include/asm/ptrace.h > b/arch/csky/include/asm/ptrace.h > index 0634b7895d81..a738630e64b0 100644 > --- a/arch/csky/include/asm/ptrace.h > +++ b/arch/csky/include/asm/ptrace.h > @@ -22,6 +22,7 @@ > > #define user_mode(regs) (!((regs)->sr & PS_S)) > #define instruction_pointer(regs) ((regs)->pc) > +#define exception_ip(regs) instruction_pointer(regs) > #define profile_pc(regs) instruction_pointer(regs) > #define trap_no(regs) ((regs->sr >> 16) & 0xff) > > diff --git a/arch/hexagon/include/uapi/asm/ptrace.h > b/arch/hexagon/include/uapi/asm/ptrace.h > index 2a3ea14ad9b9..846471936237 100644 > --- a/arch/hexagon/include/uapi/asm/ptrace.h > +++ b/arch/hexagon/include/uapi/asm/ptrace.h > @@ -25,6 +25,7 @@ > #include <asm/registers.h> > > #define instruction_pointer(regs) pt_elr(regs) > +#define exception_ip(regs) instruction_pointer(regs) > #define user_stack_pointer(regs) ((regs)->r29) > > #define profile_pc(regs) instruction_pointer(regs) > diff --git a/arch/loongarch/include/asm/ptrace.h > b/arch/loongarch/include/asm/ptrace.h > index f3ddaed9ef7f..a34327f0e69d 100644 > --- a/arch/loongarch/include/asm/ptrace.h > +++ b/arch/loongarch/include/asm/ptrace.h > @@ -160,6 +160,7 @@ static inline void regs_set_return_value(struct > pt_regs *regs, unsigned long val > } > > #define instruction_pointer(regs) ((regs)->csr_era) > +#define exception_ip(regs) instruction_pointer(regs) > #define profile_pc(regs) instruction_pointer(regs) > > extern void die(const char *str, struct pt_regs *regs); > diff --git a/arch/m68k/include/asm/ptrace.h > b/arch/m68k/include/asm/ptrace.h > index ea5a80ca1ab3..cb553e2ec73a 100644 > --- a/arch/m68k/include/asm/ptrace.h > +++ b/arch/m68k/include/asm/ptrace.h > @@ -13,6 +13,7 @@ > > #define user_mode(regs) (!((regs)->sr & PS_S)) > #define instruction_pointer(regs) ((regs)->pc) > +#define exception_ip(regs) instruction_pointer(regs) > #define profile_pc(regs) instruction_pointer(regs) > #define current_pt_regs() \ > (struct pt_regs *)((char *)current_thread_info() + > THREAD_SIZE) - 1 > diff --git a/arch/microblaze/include/asm/ptrace.h > b/arch/microblaze/include/asm/ptrace.h > index bfcb89df5e26..974c00fa7212 100644 > --- a/arch/microblaze/include/asm/ptrace.h > +++ b/arch/microblaze/include/asm/ptrace.h > @@ -12,7 +12,8 @@ > #define user_mode(regs) (!kernel_mode(regs)) > > #define instruction_pointer(regs) ((regs)->pc) > -#define profile_pc(regs) instruction_pointer(regs) > +#define > exception_ip(regs) instruction_pointer(regs) > +#define > profile_pc(regs) instruction_pointer(regs) > #define user_stack_pointer(regs) ((regs)->r1) > > static inline long regs_return_value(struct pt_regs *regs) > diff --git a/arch/mips/include/asm/ptrace.h > b/arch/mips/include/asm/ptrace.h > index daf3cf244ea9..97589731fd40 100644 > --- a/arch/mips/include/asm/ptrace.h > +++ b/arch/mips/include/asm/ptrace.h > @@ -154,6 +154,7 @@ static inline long regs_return_value(struct > pt_regs *regs) > } > > #define instruction_pointer(regs) ((regs)->cp0_epc) > +extern unsigned long exception_ip(struct pt_regs *regs); > #define profile_pc(regs) instruction_pointer(regs) > > extern asmlinkage long syscall_trace_enter(struct pt_regs *regs, long > syscall); > diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c > index d9df543f7e2c..59288c13b581 100644 > --- a/arch/mips/kernel/ptrace.c > +++ b/arch/mips/kernel/ptrace.c > @@ -31,6 +31,7 @@ > #include <linux/seccomp.h> > #include <linux/ftrace.h> > > +#include <asm/branch.h> > #include <asm/byteorder.h> > #include <asm/cpu.h> > #include <asm/cpu-info.h> > @@ -48,6 +49,12 @@ > #define CREATE_TRACE_POINTS > #include <trace/events/syscalls.h> > > +unsigned long exception_ip(struct pt_regs *regs) > +{ > + return exception_epc(regs); > +} > +EXPORT_SYMBOL(exception_ip); > + > /* > * Called by kernel/ptrace.c when detaching.. > * > diff --git a/arch/nios2/include/asm/ptrace.h > b/arch/nios2/include/asm/ptrace.h > index 9da34c3022a2..136f5679ae79 100644 > --- a/arch/nios2/include/asm/ptrace.h > +++ b/arch/nios2/include/asm/ptrace.h > @@ -66,7 +66,8 @@ struct switch_stack { > #define user_mode(regs) (((regs)->estatus & ESTATUS_EU)) > > #define instruction_pointer(regs) ((regs)->ra) > -#define profile_pc(regs) instruction_pointer(regs) > +#define > exception_ip(regs) instruction_pointer(regs) > +#define > profile_pc(regs) instruction_pointer(regs) > #define user_stack_pointer(regs) ((regs)->sp) > extern void show_regs(struct pt_regs *); > > diff --git a/arch/openrisc/include/asm/ptrace.h > b/arch/openrisc/include/asm/ptrace.h > index 375147ff71fc..67c28484d17e 100644 > --- a/arch/openrisc/include/asm/ptrace.h > +++ b/arch/openrisc/include/asm/ptrace.h > @@ -67,6 +67,7 @@ struct pt_regs { > #define STACK_FRAME_OVERHEAD 128 /* size of minimum stack frame */ > > #define instruction_pointer(regs) ((regs)->pc) > +#define > exception_ip(regs) instruction_pointer(regs) > #define user_mode(regs) (((regs)->sr & > SPR_SR_SM) == 0) > #define user_stack_pointer(regs) ((unsigned long)(regs)->sp) > #define profile_pc(regs) instruction_pointer(regs) > diff --git a/arch/parisc/include/asm/ptrace.h > b/arch/parisc/include/asm/ptrace.h > index eea3f3df0823..d7e8dcf26582 100644 > --- a/arch/parisc/include/asm/ptrace.h > +++ b/arch/parisc/include/asm/ptrace.h > @@ -17,6 +17,7 @@ > #define user_mode(regs) (((regs)->iaoq[0] & > 3) != PRIV_KERNEL) > #define user_space(regs) ((regs)->iasq[1] != > PRIV_KERNEL) > #define instruction_pointer(regs) ((regs)->iaoq[0] & ~3) > +#define > exception_ip(regs) instruction_pointer(regs) > #define user_stack_pointer(regs) ((regs)->gr[30]) > unsigned long profile_pc(struct pt_regs *); > > diff --git a/arch/s390/include/asm/ptrace.h > b/arch/s390/include/asm/ptrace.h > index d28bf8fb2799..a5255b2337af 100644 > --- a/arch/s390/include/asm/ptrace.h > +++ b/arch/s390/include/asm/ptrace.h > @@ -211,6 +211,7 @@ static inline int > test_and_clear_pt_regs_flag(struct pt_regs *regs, int flag) > > #define user_mode(regs) (((regs)->psw.mask & PSW_MASK_PSTATE) != 0) > #define instruction_pointer(regs) ((regs)->psw.addr) > +#define exception_ip(regs) instruction_pointer(regs) > #define user_stack_pointer(regs)((regs)->gprs[15]) > #define profile_pc(regs) instruction_pointer(regs) > > diff --git a/arch/sparc/include/asm/ptrace.h > b/arch/sparc/include/asm/ptrace.h > index d1419e669027..41ae186f2245 100644 > --- a/arch/sparc/include/asm/ptrace.h > +++ b/arch/sparc/include/asm/ptrace.h > @@ -63,6 +63,7 @@ extern union global_cpu_snapshot > global_cpu_snapshot[NR_CPUS]; > #define force_successful_syscall_return() set_thread_noerror(1) > #define user_mode(regs) (!((regs)->tstate & TSTATE_PRIV)) > #define instruction_pointer(regs) ((regs)->tpc) > +#define exception_ip(regs) instruction_pointer(regs) > #define instruction_pointer_set(regs, val) do { \ > (regs)->tpc = (val); \ > (regs)->tnpc = (val)+4; \ > @@ -142,6 +143,7 @@ static inline bool pt_regs_clear_syscall(struct > pt_regs *regs) > > #define user_mode(regs) (!((regs)->psr & PSR_PS)) > #define instruction_pointer(regs) ((regs)->pc) > +#define exception_ip(regs) instruction_pointer(regs) > #define user_stack_pointer(regs) ((regs)->u_regs[UREG_FP]) > unsigned long profile_pc(struct pt_regs *); > #else /* (!__ASSEMBLY__) */ > diff --git a/arch/um/include/asm/ptrace-generic.h > b/arch/um/include/asm/ptrace-generic.h > index adf91ef553ae..f9ada287ca12 100644 > --- a/arch/um/include/asm/ptrace-generic.h > +++ b/arch/um/include/asm/ptrace-generic.h > @@ -26,6 +26,7 @@ struct pt_regs { > #define PT_REGS_SYSCALL_NR(r) UPT_SYSCALL_NR(&(r)->regs) > > #define instruction_pointer(regs) PT_REGS_IP(regs) > +#define exception_ip(regs) instruction_pointer(regs) > > #define PTRACE_OLDSETOPTIONS 21 > > -- Xi Ruoyao <xry111@xry111.site> School of Aerospace Science and Technology, Xidian University ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/3] ptrace: Introduce exception_ip arch hook 2024-02-01 16:35 ` Xi Ruoyao @ 2024-02-01 17:13 ` Jiaxun Yang 0 siblings, 0 replies; 9+ messages in thread From: Jiaxun Yang @ 2024-02-01 17:13 UTC (permalink / raw) To: Xi Ruoyao, Oleg Nesterov, Thomas Bogendoerfer, Andrew Morton, Ben Hutchings Cc: linux-arch, linux-kernel, linux-mips, linux-mm 在 2024/2/1 16:35, Xi Ruoyao 写道: > On Thu, 2024-02-01 at 15:46 +0000, Jiaxun Yang wrote: >> On architectures with delay slot, architecture level instruction >> pointer (or program counter) in pt_regs may differ from where >> exception was triggered. >> >> Introduce exception_ip hook to invoke architecture code and determine >> actual instruction pointer to the exception. >> >> Link: >> https://lore.kernel.org/lkml/00d1b813-c55f-4365-8d81-d70258e10b16@app.fastmail.com/ >> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com> > How about adding something like > > #ifndef arch_exception_ip > #define exception_ip(regs) instruction_pointer(regs) > #else > #define exception_ip(regs) arch_exception_ip(regs) > #endif > > into a generic header, instead of having to add exception_ip definition > everywhere? Actually I tried but failed, cuz there is no asm-generic version of ptrace.h, besides exception_ip shall be used at many scenarios so extable.h is also a no go. Thanks - Jiaxun > >> --- >> arch/alpha/include/asm/ptrace.h | 1 + >> arch/arc/include/asm/ptrace.h | 1 + >> arch/arm/include/asm/ptrace.h | 1 + >> arch/csky/include/asm/ptrace.h | 1 + >> arch/hexagon/include/uapi/asm/ptrace.h | 1 + >> arch/loongarch/include/asm/ptrace.h | 1 + >> arch/m68k/include/asm/ptrace.h | 1 + >> arch/microblaze/include/asm/ptrace.h | 3 ++- >> arch/mips/include/asm/ptrace.h | 1 + >> arch/mips/kernel/ptrace.c | 7 +++++++ >> arch/nios2/include/asm/ptrace.h | 3 ++- >> arch/openrisc/include/asm/ptrace.h | 1 + >> arch/parisc/include/asm/ptrace.h | 1 + >> arch/s390/include/asm/ptrace.h | 1 + >> arch/sparc/include/asm/ptrace.h | 2 ++ >> arch/um/include/asm/ptrace-generic.h | 1 + >> 16 files changed, 25 insertions(+), 2 deletions(-) >> >> diff --git a/arch/alpha/include/asm/ptrace.h >> b/arch/alpha/include/asm/ptrace.h >> index 3557ce64ed21..1ded3f2d09e9 100644 >> --- a/arch/alpha/include/asm/ptrace.h >> +++ b/arch/alpha/include/asm/ptrace.h >> @@ -8,6 +8,7 @@ >> #define arch_has_single_step() (1) >> #define user_mode(regs) (((regs)->ps & 8) != 0) >> #define instruction_pointer(regs) ((regs)->pc) >> +#define exception_ip(regs) instruction_pointer(regs) >> #define profile_pc(regs) instruction_pointer(regs) >> #define current_user_stack_pointer() rdusp() >> >> diff --git a/arch/arc/include/asm/ptrace.h >> b/arch/arc/include/asm/ptrace.h >> index 00b9318e551e..94084f1048df 100644 >> --- a/arch/arc/include/asm/ptrace.h >> +++ b/arch/arc/include/asm/ptrace.h >> @@ -105,6 +105,7 @@ struct callee_regs { >> #endif >> >> #define instruction_pointer(regs) ((regs)->ret) >> +#define exception_ip(regs) instruction_pointer(regs) >> #define profile_pc(regs) instruction_pointer(regs) >> >> /* return 1 if user mode or 0 if kernel mode */ >> diff --git a/arch/arm/include/asm/ptrace.h >> b/arch/arm/include/asm/ptrace.h >> index 7f44e88d1f25..fb4dc23eba78 100644 >> --- a/arch/arm/include/asm/ptrace.h >> +++ b/arch/arm/include/asm/ptrace.h >> @@ -89,6 +89,7 @@ static inline long regs_return_value(struct pt_regs >> *regs) >> } >> >> #define instruction_pointer(regs) (regs)->ARM_pc >> +#define >> exception_ip(regs) instruction_pointer(regs) >> >> #ifdef CONFIG_THUMB2_KERNEL >> #define frame_pointer(regs) (regs)->ARM_r7 >> diff --git a/arch/csky/include/asm/ptrace.h >> b/arch/csky/include/asm/ptrace.h >> index 0634b7895d81..a738630e64b0 100644 >> --- a/arch/csky/include/asm/ptrace.h >> +++ b/arch/csky/include/asm/ptrace.h >> @@ -22,6 +22,7 @@ >> >> #define user_mode(regs) (!((regs)->sr & PS_S)) >> #define instruction_pointer(regs) ((regs)->pc) >> +#define exception_ip(regs) instruction_pointer(regs) >> #define profile_pc(regs) instruction_pointer(regs) >> #define trap_no(regs) ((regs->sr >> 16) & 0xff) >> >> diff --git a/arch/hexagon/include/uapi/asm/ptrace.h >> b/arch/hexagon/include/uapi/asm/ptrace.h >> index 2a3ea14ad9b9..846471936237 100644 >> --- a/arch/hexagon/include/uapi/asm/ptrace.h >> +++ b/arch/hexagon/include/uapi/asm/ptrace.h >> @@ -25,6 +25,7 @@ >> #include <asm/registers.h> >> >> #define instruction_pointer(regs) pt_elr(regs) >> +#define exception_ip(regs) instruction_pointer(regs) >> #define user_stack_pointer(regs) ((regs)->r29) >> >> #define profile_pc(regs) instruction_pointer(regs) >> diff --git a/arch/loongarch/include/asm/ptrace.h >> b/arch/loongarch/include/asm/ptrace.h >> index f3ddaed9ef7f..a34327f0e69d 100644 >> --- a/arch/loongarch/include/asm/ptrace.h >> +++ b/arch/loongarch/include/asm/ptrace.h >> @@ -160,6 +160,7 @@ static inline void regs_set_return_value(struct >> pt_regs *regs, unsigned long val >> } >> >> #define instruction_pointer(regs) ((regs)->csr_era) >> +#define exception_ip(regs) instruction_pointer(regs) >> #define profile_pc(regs) instruction_pointer(regs) >> >> extern void die(const char *str, struct pt_regs *regs); >> diff --git a/arch/m68k/include/asm/ptrace.h >> b/arch/m68k/include/asm/ptrace.h >> index ea5a80ca1ab3..cb553e2ec73a 100644 >> --- a/arch/m68k/include/asm/ptrace.h >> +++ b/arch/m68k/include/asm/ptrace.h >> @@ -13,6 +13,7 @@ >> >> #define user_mode(regs) (!((regs)->sr & PS_S)) >> #define instruction_pointer(regs) ((regs)->pc) >> +#define exception_ip(regs) instruction_pointer(regs) >> #define profile_pc(regs) instruction_pointer(regs) >> #define current_pt_regs() \ >> (struct pt_regs *)((char *)current_thread_info() + >> THREAD_SIZE) - 1 >> diff --git a/arch/microblaze/include/asm/ptrace.h >> b/arch/microblaze/include/asm/ptrace.h >> index bfcb89df5e26..974c00fa7212 100644 >> --- a/arch/microblaze/include/asm/ptrace.h >> +++ b/arch/microblaze/include/asm/ptrace.h >> @@ -12,7 +12,8 @@ >> #define user_mode(regs) (!kernel_mode(regs)) >> >> #define instruction_pointer(regs) ((regs)->pc) >> -#define profile_pc(regs) instruction_pointer(regs) >> +#define >> exception_ip(regs) instruction_pointer(regs) >> +#define >> profile_pc(regs) instruction_pointer(regs) >> #define user_stack_pointer(regs) ((regs)->r1) >> >> static inline long regs_return_value(struct pt_regs *regs) >> diff --git a/arch/mips/include/asm/ptrace.h >> b/arch/mips/include/asm/ptrace.h >> index daf3cf244ea9..97589731fd40 100644 >> --- a/arch/mips/include/asm/ptrace.h >> +++ b/arch/mips/include/asm/ptrace.h >> @@ -154,6 +154,7 @@ static inline long regs_return_value(struct >> pt_regs *regs) >> } >> >> #define instruction_pointer(regs) ((regs)->cp0_epc) >> +extern unsigned long exception_ip(struct pt_regs *regs); >> #define profile_pc(regs) instruction_pointer(regs) >> >> extern asmlinkage long syscall_trace_enter(struct pt_regs *regs, long >> syscall); >> diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c >> index d9df543f7e2c..59288c13b581 100644 >> --- a/arch/mips/kernel/ptrace.c >> +++ b/arch/mips/kernel/ptrace.c >> @@ -31,6 +31,7 @@ >> #include <linux/seccomp.h> >> #include <linux/ftrace.h> >> >> +#include <asm/branch.h> >> #include <asm/byteorder.h> >> #include <asm/cpu.h> >> #include <asm/cpu-info.h> >> @@ -48,6 +49,12 @@ >> #define CREATE_TRACE_POINTS >> #include <trace/events/syscalls.h> >> >> +unsigned long exception_ip(struct pt_regs *regs) >> +{ >> + return exception_epc(regs); >> +} >> +EXPORT_SYMBOL(exception_ip); >> + >> /* >> * Called by kernel/ptrace.c when detaching.. >> * >> diff --git a/arch/nios2/include/asm/ptrace.h >> b/arch/nios2/include/asm/ptrace.h >> index 9da34c3022a2..136f5679ae79 100644 >> --- a/arch/nios2/include/asm/ptrace.h >> +++ b/arch/nios2/include/asm/ptrace.h >> @@ -66,7 +66,8 @@ struct switch_stack { >> #define user_mode(regs) (((regs)->estatus & ESTATUS_EU)) >> >> #define instruction_pointer(regs) ((regs)->ra) >> -#define profile_pc(regs) instruction_pointer(regs) >> +#define >> exception_ip(regs) instruction_pointer(regs) >> +#define >> profile_pc(regs) instruction_pointer(regs) >> #define user_stack_pointer(regs) ((regs)->sp) >> extern void show_regs(struct pt_regs *); >> >> diff --git a/arch/openrisc/include/asm/ptrace.h >> b/arch/openrisc/include/asm/ptrace.h >> index 375147ff71fc..67c28484d17e 100644 >> --- a/arch/openrisc/include/asm/ptrace.h >> +++ b/arch/openrisc/include/asm/ptrace.h >> @@ -67,6 +67,7 @@ struct pt_regs { >> #define STACK_FRAME_OVERHEAD 128 /* size of minimum stack frame */ >> >> #define instruction_pointer(regs) ((regs)->pc) >> +#define >> exception_ip(regs) instruction_pointer(regs) >> #define user_mode(regs) (((regs)->sr & >> SPR_SR_SM) == 0) >> #define user_stack_pointer(regs) ((unsigned long)(regs)->sp) >> #define profile_pc(regs) instruction_pointer(regs) >> diff --git a/arch/parisc/include/asm/ptrace.h >> b/arch/parisc/include/asm/ptrace.h >> index eea3f3df0823..d7e8dcf26582 100644 >> --- a/arch/parisc/include/asm/ptrace.h >> +++ b/arch/parisc/include/asm/ptrace.h >> @@ -17,6 +17,7 @@ >> #define user_mode(regs) (((regs)->iaoq[0] & >> 3) != PRIV_KERNEL) >> #define user_space(regs) ((regs)->iasq[1] != >> PRIV_KERNEL) >> #define instruction_pointer(regs) ((regs)->iaoq[0] & ~3) >> +#define >> exception_ip(regs) instruction_pointer(regs) >> #define user_stack_pointer(regs) ((regs)->gr[30]) >> unsigned long profile_pc(struct pt_regs *); >> >> diff --git a/arch/s390/include/asm/ptrace.h >> b/arch/s390/include/asm/ptrace.h >> index d28bf8fb2799..a5255b2337af 100644 >> --- a/arch/s390/include/asm/ptrace.h >> +++ b/arch/s390/include/asm/ptrace.h >> @@ -211,6 +211,7 @@ static inline int >> test_and_clear_pt_regs_flag(struct pt_regs *regs, int flag) >> >> #define user_mode(regs) (((regs)->psw.mask & PSW_MASK_PSTATE) != 0) >> #define instruction_pointer(regs) ((regs)->psw.addr) >> +#define exception_ip(regs) instruction_pointer(regs) >> #define user_stack_pointer(regs)((regs)->gprs[15]) >> #define profile_pc(regs) instruction_pointer(regs) >> >> diff --git a/arch/sparc/include/asm/ptrace.h >> b/arch/sparc/include/asm/ptrace.h >> index d1419e669027..41ae186f2245 100644 >> --- a/arch/sparc/include/asm/ptrace.h >> +++ b/arch/sparc/include/asm/ptrace.h >> @@ -63,6 +63,7 @@ extern union global_cpu_snapshot >> global_cpu_snapshot[NR_CPUS]; >> #define force_successful_syscall_return() set_thread_noerror(1) >> #define user_mode(regs) (!((regs)->tstate & TSTATE_PRIV)) >> #define instruction_pointer(regs) ((regs)->tpc) >> +#define exception_ip(regs) instruction_pointer(regs) >> #define instruction_pointer_set(regs, val) do { \ >> (regs)->tpc = (val); \ >> (regs)->tnpc = (val)+4; \ >> @@ -142,6 +143,7 @@ static inline bool pt_regs_clear_syscall(struct >> pt_regs *regs) >> >> #define user_mode(regs) (!((regs)->psr & PSR_PS)) >> #define instruction_pointer(regs) ((regs)->pc) >> +#define exception_ip(regs) instruction_pointer(regs) >> #define user_stack_pointer(regs) ((regs)->u_regs[UREG_FP]) >> unsigned long profile_pc(struct pt_regs *); >> #else /* (!__ASSEMBLY__) */ >> diff --git a/arch/um/include/asm/ptrace-generic.h >> b/arch/um/include/asm/ptrace-generic.h >> index adf91ef553ae..f9ada287ca12 100644 >> --- a/arch/um/include/asm/ptrace-generic.h >> +++ b/arch/um/include/asm/ptrace-generic.h >> @@ -26,6 +26,7 @@ struct pt_regs { >> #define PT_REGS_SYSCALL_NR(r) UPT_SYSCALL_NR(&(r)->regs) >> >> #define instruction_pointer(regs) PT_REGS_IP(regs) >> +#define exception_ip(regs) instruction_pointer(regs) >> >> #define PTRACE_OLDSETOPTIONS 21 >> >> -- --- Jiaxun Yang ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/3] MIPS: Clear Cause.BD in instruction_pointer_set 2024-02-01 15:46 [PATCH 0/3] Handle delay slot for extable lookup Jiaxun Yang 2024-02-01 15:46 ` [PATCH 1/3] ptrace: Introduce exception_ip arch hook Jiaxun Yang @ 2024-02-01 15:46 ` Jiaxun Yang 2024-02-01 15:46 ` [PATCH 3/3] mm/memory: Use exception ip to search exception tables Jiaxun Yang 2024-02-01 17:48 ` [PATCH 0/3] Handle delay slot for extable lookup Linus Torvalds 3 siblings, 0 replies; 9+ messages in thread From: Jiaxun Yang @ 2024-02-01 15:46 UTC (permalink / raw) To: Oleg Nesterov, Thomas Bogendoerfer, Andrew Morton, Ben Hutchings Cc: linux-arch, linux-kernel, linux-mips, linux-mm, Jiaxun Yang Clear Cause.BD after we use instruction_pointer_set to override EPC. This can prevent exception_epc check against instruction code at new return address. It won't be considered as "in delay slot" after epc being overridden anyway. Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com> --- arch/mips/include/asm/ptrace.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/mips/include/asm/ptrace.h b/arch/mips/include/asm/ptrace.h index 97589731fd40..845508008e90 100644 --- a/arch/mips/include/asm/ptrace.h +++ b/arch/mips/include/asm/ptrace.h @@ -60,6 +60,7 @@ static inline void instruction_pointer_set(struct pt_regs *regs, unsigned long val) { regs->cp0_epc = val; + regs->cp0_cause &= ~CAUSEF_BD; } /* Query offset/name of register from its name/offset */ -- 2.43.0 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 3/3] mm/memory: Use exception ip to search exception tables 2024-02-01 15:46 [PATCH 0/3] Handle delay slot for extable lookup Jiaxun Yang 2024-02-01 15:46 ` [PATCH 1/3] ptrace: Introduce exception_ip arch hook Jiaxun Yang 2024-02-01 15:46 ` [PATCH 2/3] MIPS: Clear Cause.BD in instruction_pointer_set Jiaxun Yang @ 2024-02-01 15:46 ` Jiaxun Yang 2024-02-03 13:15 ` kernel test robot 2024-02-03 13:37 ` kernel test robot 2024-02-01 17:48 ` [PATCH 0/3] Handle delay slot for extable lookup Linus Torvalds 3 siblings, 2 replies; 9+ messages in thread From: Jiaxun Yang @ 2024-02-01 15:46 UTC (permalink / raw) To: Oleg Nesterov, Thomas Bogendoerfer, Andrew Morton, Ben Hutchings Cc: linux-arch, linux-kernel, linux-mips, linux-mm, Jiaxun Yang, Xi Ruoyao, Linus Torvalds On architectures with delay slot, instruction_pointer() may differ from where exception was triggered. Use exception_ip we just introduced to search exception tables to get rid of the problem. Fixes: 4bce37a68ff8 ("mips/mm: Convert to using lock_mm_and_find_vma()") Reported-by: Xi Ruoyao <xry111@xry111.site> Link: https://lore.kernel.org/r/75e9fd7b08562ad9b456a5bdaacb7cc220311cc9.camel@xry111.site/ Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com> --- mm/memory.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 8d14ba440929..49433612444a 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5481,7 +5481,7 @@ static inline bool get_mmap_lock_carefully(struct mm_struct *mm, struct pt_regs return true; if (regs && !user_mode(regs)) { - unsigned long ip = instruction_pointer(regs); + unsigned long ip = exception_ip(regs); if (!search_exception_tables(ip)) return false; } @@ -5506,7 +5506,7 @@ static inline bool upgrade_mmap_lock_carefully(struct mm_struct *mm, struct pt_r { mmap_read_unlock(mm); if (regs && !user_mode(regs)) { - unsigned long ip = instruction_pointer(regs); + unsigned long ip = exception_ip(regs); if (!search_exception_tables(ip)) return false; } -- 2.43.0 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] mm/memory: Use exception ip to search exception tables 2024-02-01 15:46 ` [PATCH 3/3] mm/memory: Use exception ip to search exception tables Jiaxun Yang @ 2024-02-03 13:15 ` kernel test robot 2024-02-03 13:37 ` kernel test robot 1 sibling, 0 replies; 9+ messages in thread From: kernel test robot @ 2024-02-03 13:15 UTC (permalink / raw) To: Jiaxun Yang, Oleg Nesterov, Thomas Bogendoerfer, Andrew Morton, Ben Hutchings Cc: oe-kbuild-all, Linux Memory Management List, linux-arch, linux-kernel, linux-mips, Jiaxun Yang, Xi Ruoyao Hi Jiaxun, kernel test robot noticed the following build errors: [auto build test ERROR on 06f658aadff0e483ee4f807b0b46c9e5cba62bfa] url: https://github.com/intel-lab-lkp/linux/commits/Jiaxun-Yang/ptrace-Introduce-exception_ip-arch-hook/20240201-234906 base: 06f658aadff0e483ee4f807b0b46c9e5cba62bfa patch link: https://lore.kernel.org/r/20240201-exception_ip-v1-3-aa26ab3ee0b5%40flygoat.com patch subject: [PATCH 3/3] mm/memory: Use exception ip to search exception tables config: i386-buildonly-randconfig-002-20240203 (https://download.01.org/0day-ci/archive/20240203/202402032150.DmM8VjRz-lkp@intel.com/config) compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240203/202402032150.DmM8VjRz-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202402032150.DmM8VjRz-lkp@intel.com/ All errors (new ones prefixed by >>): mm/memory.c: In function 'get_mmap_lock_carefully': >> mm/memory.c:5484:22: error: implicit declaration of function 'exception_ip' [-Werror=implicit-function-declaration] unsigned long ip = exception_ip(regs); ^~~~~~~~~~~~ cc1: some warnings being treated as errors vim +/exception_ip +5484 mm/memory.c 5477 5478 static inline bool get_mmap_lock_carefully(struct mm_struct *mm, struct pt_regs *regs) 5479 { 5480 if (likely(mmap_read_trylock(mm))) 5481 return true; 5482 5483 if (regs && !user_mode(regs)) { > 5484 unsigned long ip = exception_ip(regs); 5485 if (!search_exception_tables(ip)) 5486 return false; 5487 } 5488 5489 return !mmap_read_lock_killable(mm); 5490 } 5491 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] mm/memory: Use exception ip to search exception tables 2024-02-01 15:46 ` [PATCH 3/3] mm/memory: Use exception ip to search exception tables Jiaxun Yang 2024-02-03 13:15 ` kernel test robot @ 2024-02-03 13:37 ` kernel test robot 1 sibling, 0 replies; 9+ messages in thread From: kernel test robot @ 2024-02-03 13:37 UTC (permalink / raw) To: Jiaxun Yang, Oleg Nesterov, Thomas Bogendoerfer, Andrew Morton, Ben Hutchings Cc: llvm, oe-kbuild-all, Linux Memory Management List, linux-arch, linux-kernel, linux-mips, Jiaxun Yang, Xi Ruoyao Hi Jiaxun, kernel test robot noticed the following build errors: [auto build test ERROR on 06f658aadff0e483ee4f807b0b46c9e5cba62bfa] url: https://github.com/intel-lab-lkp/linux/commits/Jiaxun-Yang/ptrace-Introduce-exception_ip-arch-hook/20240201-234906 base: 06f658aadff0e483ee4f807b0b46c9e5cba62bfa patch link: https://lore.kernel.org/r/20240201-exception_ip-v1-3-aa26ab3ee0b5%40flygoat.com patch subject: [PATCH 3/3] mm/memory: Use exception ip to search exception tables config: arm64-randconfig-001-20240203 (https://download.01.org/0day-ci/archive/20240203/202402032112.NBimLx5h-lkp@intel.com/config) compiler: clang version 15.0.7 (https://github.com/llvm/llvm-project.git 8dfdcc7b7bf66834a761bd8de445840ef68e4d1a) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240203/202402032112.NBimLx5h-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202402032112.NBimLx5h-lkp@intel.com/ All errors (new ones prefixed by >>): >> mm/memory.c:5484:22: error: call to undeclared function 'exception_ip'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration] unsigned long ip = exception_ip(regs); ^ mm/memory.c:5509:22: error: call to undeclared function 'exception_ip'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration] unsigned long ip = exception_ip(regs); ^ 2 errors generated. vim +/exception_ip +5484 mm/memory.c 5477 5478 static inline bool get_mmap_lock_carefully(struct mm_struct *mm, struct pt_regs *regs) 5479 { 5480 if (likely(mmap_read_trylock(mm))) 5481 return true; 5482 5483 if (regs && !user_mode(regs)) { > 5484 unsigned long ip = exception_ip(regs); 5485 if (!search_exception_tables(ip)) 5486 return false; 5487 } 5488 5489 return !mmap_read_lock_killable(mm); 5490 } 5491 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/3] Handle delay slot for extable lookup 2024-02-01 15:46 [PATCH 0/3] Handle delay slot for extable lookup Jiaxun Yang ` (2 preceding siblings ...) 2024-02-01 15:46 ` [PATCH 3/3] mm/memory: Use exception ip to search exception tables Jiaxun Yang @ 2024-02-01 17:48 ` Linus Torvalds 3 siblings, 0 replies; 9+ messages in thread From: Linus Torvalds @ 2024-02-01 17:48 UTC (permalink / raw) To: Jiaxun Yang Cc: Oleg Nesterov, Thomas Bogendoerfer, Andrew Morton, Ben Hutchings, linux-arch, linux-kernel, linux-mips, linux-mm, Xi Ruoyao On Thu, 1 Feb 2024 at 07:46, Jiaxun Yang <jiaxun.yang@flygoat.com> wrote: > > arch/alpha/include/asm/ptrace.h | 1 + > arch/arc/include/asm/ptrace.h | 1 + > arch/arm/include/asm/ptrace.h | 1 + > arch/csky/include/asm/ptrace.h | 1 + > arch/hexagon/include/uapi/asm/ptrace.h | 1 + > arch/loongarch/include/asm/ptrace.h | 1 + > arch/m68k/include/asm/ptrace.h | 1 + > arch/microblaze/include/asm/ptrace.h | 3 ++- > arch/mips/include/asm/ptrace.h | 2 ++ > arch/mips/kernel/ptrace.c | 7 +++++++ > arch/nios2/include/asm/ptrace.h | 3 ++- > arch/openrisc/include/asm/ptrace.h | 1 + > arch/parisc/include/asm/ptrace.h | 1 + > arch/s390/include/asm/ptrace.h | 1 + > arch/sparc/include/asm/ptrace.h | 2 ++ > arch/um/include/asm/ptrace-generic.h | 1 + > mm/memory.c | 4 ++-- > 17 files changed, 28 insertions(+), 4 deletions(-) The only user right now is mm/memory.c, and it doesn't even include <asm/ptrace.h>, but instead does the proper thing and includes <linux/ptrace.h> So please make <linux/ptrace.h> just do #ifndef exception_ip #define exception_ip(x) instruction_pointer(x) #endif and all those non-MIPS architecture updates should just go away, and the diffstat should look something like arch/mips/kernel/ptrace.c | 7 +++++++ include/linux/ptrace.h | 4 ++++ mm/memory.c | 4 ++-- instead. Linus ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-02-03 13:38 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-02-01 15:46 [PATCH 0/3] Handle delay slot for extable lookup Jiaxun Yang 2024-02-01 15:46 ` [PATCH 1/3] ptrace: Introduce exception_ip arch hook Jiaxun Yang 2024-02-01 16:35 ` Xi Ruoyao 2024-02-01 17:13 ` Jiaxun Yang 2024-02-01 15:46 ` [PATCH 2/3] MIPS: Clear Cause.BD in instruction_pointer_set Jiaxun Yang 2024-02-01 15:46 ` [PATCH 3/3] mm/memory: Use exception ip to search exception tables Jiaxun Yang 2024-02-03 13:15 ` kernel test robot 2024-02-03 13:37 ` kernel test robot 2024-02-01 17:48 ` [PATCH 0/3] Handle delay slot for extable lookup Linus Torvalds
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox