diff mbox series

MIPS: fix kernel_stack_pointer()

Message ID 20210129043507.30488-1-huangpei@loongson.cn (mailing list archive)
State New, archived
Headers show
Series MIPS: fix kernel_stack_pointer() | expand

Commit Message

Huang Pei Jan. 29, 2021, 4:35 a.m. UTC
MIPS always save kernel stack pointer in regs[29]

Signed-off-by: Huang Pei <huangpei@loongson.cn>
---
 arch/mips/include/asm/ptrace.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Thomas Bogendoerfer Feb. 1, 2021, 12:23 p.m. UTC | #1
On Fri, Jan 29, 2021 at 12:35:07PM +0800, Huang Pei wrote:
> MIPS always save kernel stack pointer in regs[29]
> 
> Signed-off-by: Huang Pei <huangpei@loongson.cn>
> ---
>  arch/mips/include/asm/ptrace.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/mips/include/asm/ptrace.h b/arch/mips/include/asm/ptrace.h
> index 1e76774b36dd..daf3cf244ea9 100644
> --- a/arch/mips/include/asm/ptrace.h
> +++ b/arch/mips/include/asm/ptrace.h
> @@ -53,7 +53,7 @@ struct pt_regs {
>  
>  static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
>  {
> -	return regs->regs[31];
> +	return regs->regs[29];

hmm, I'm still wondering where the trick is... looks like this is used
for uprobes, so nobody has ever used uprobes or I'm missing something.

How did you find that ?

Thomas.
Huang Pei Feb. 2, 2021, 1:32 a.m. UTC | #2
On Mon, Feb 01, 2021 at 01:23:52PM +0100, Thomas Bogendoerfer wrote:
> On Fri, Jan 29, 2021 at 12:35:07PM +0800, Huang Pei wrote:
> > MIPS always save kernel stack pointer in regs[29]
> > 
> > Signed-off-by: Huang Pei <huangpei@loongson.cn>
> > ---
> >  arch/mips/include/asm/ptrace.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/arch/mips/include/asm/ptrace.h b/arch/mips/include/asm/ptrace.h
> > index 1e76774b36dd..daf3cf244ea9 100644
> > --- a/arch/mips/include/asm/ptrace.h
> > +++ b/arch/mips/include/asm/ptrace.h
> > @@ -53,7 +53,7 @@ struct pt_regs {
> >  
> >  static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
> >  {
> > -	return regs->regs[31];
> > +	return regs->regs[29];
> 
> hmm, I'm still wondering where the trick is... looks like this is used
> for uprobes, so nobody has ever used uprobes or I'm missing something.
> 
> How did you find that ?
> 
> Thomas.
> 
> -- 
> Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
> good idea.                                                [ RFC1925, 2.3 ]


Long story for short, 

+. I think I had fix this bug in 2018, when I backported Uprobe from my
4.4 branch to CentOS 7 3.10. I just knwo it is *not* following MIPS
ABI, but I do not know how it destroy the cool function of
Kprobe/Uprobe, since the failure in porting eBPF from upstream to 3.10
just leave the fix in 3.10, totally forgotten.

+. In 2020, I was told to validate the effect of GNU XHash, and it came
to me that using Uprobe to count the number of "strcmp" called in ld.so,
so I found this fix again.

+. With more work on Kprobe/Kprobe_event/Uprobe, I found it hit only when
accessing arguments of Kprobe/Uprobe, so simple counting numbers of probe
fired would not trigger it
Thomas Bogendoerfer Feb. 3, 2021, 10:36 a.m. UTC | #3
On Tue, Feb 02, 2021 at 09:32:31AM +0800, Huang Pei wrote:
> On Mon, Feb 01, 2021 at 01:23:52PM +0100, Thomas Bogendoerfer wrote:
> > On Fri, Jan 29, 2021 at 12:35:07PM +0800, Huang Pei wrote:
> > > MIPS always save kernel stack pointer in regs[29]
> > > 
> > > Signed-off-by: Huang Pei <huangpei@loongson.cn>
> > > ---
> > >  arch/mips/include/asm/ptrace.h | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/arch/mips/include/asm/ptrace.h b/arch/mips/include/asm/ptrace.h
> > > index 1e76774b36dd..daf3cf244ea9 100644
> > > --- a/arch/mips/include/asm/ptrace.h
> > > +++ b/arch/mips/include/asm/ptrace.h
> > > @@ -53,7 +53,7 @@ struct pt_regs {
> > >  
> > >  static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
> > >  {
> > > -	return regs->regs[31];
> > > +	return regs->regs[29];
> > 
> > hmm, I'm still wondering where the trick is... looks like this is used
> > for uprobes, so nobody has ever used uprobes or I'm missing something.
> > 
> > How did you find that ?
> > 
> > Thomas.
> > 
> > -- 
> > Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
> > good idea.                                                [ RFC1925, 2.3 ]
> 
> 
> Long story for short, 
> 
> +. I think I had fix this bug in 2018, when I backported Uprobe from my
> 4.4 branch to CentOS 7 3.10. I just knwo it is *not* following MIPS
> ABI, but I do not know how it destroy the cool function of
> Kprobe/Uprobe, since the failure in porting eBPF from upstream to 3.10
> just leave the fix in 3.10, totally forgotten.
> 
> +. In 2020, I was told to validate the effect of GNU XHash, and it came
> to me that using Uprobe to count the number of "strcmp" called in ld.so,
> so I found this fix again.
> 
> +. With more work on Kprobe/Kprobe_event/Uprobe, I found it hit only when
> accessing arguments of Kprobe/Uprobe, so simple counting numbers of probe
> fired would not trigger it

Thank you for the explanation, applied to mips-next.

Thomas.
diff mbox series

Patch

diff --git a/arch/mips/include/asm/ptrace.h b/arch/mips/include/asm/ptrace.h
index 1e76774b36dd..daf3cf244ea9 100644
--- a/arch/mips/include/asm/ptrace.h
+++ b/arch/mips/include/asm/ptrace.h
@@ -53,7 +53,7 @@  struct pt_regs {
 
 static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
 {
-	return regs->regs[31];
+	return regs->regs[29];
 }
 
 static inline void instruction_pointer_set(struct pt_regs *regs,