diff mbox series

[4/5] powerpc/kprobes: Setup consistent pt_regs across kprobes, optprobes and KPROBES_ON_FTRACE

Message ID 1d0cb183f48c4179646c0c5e183fd296da58f4ca.1666262278.git.naveen.n.rao@linux.vnet.ibm.com (mailing list archive)
State New
Headers show
Series powerpc/kprobes: preempt related changes and cleanups | expand

Commit Message

Naveen N. Rao Oct. 20, 2022, 5:29 p.m. UTC
Ensure a more consistent pt_regs across kprobes, optprobes and
KPROBES_ON_FTRACE:
- Drop setting trap to 0x700 under optprobes. This is not accurate and
  is unnecessary. Instead, zero it out for both optprobes and
  KPROBES_ON_FTRACE.
- Save irq soft mask in the ftrace handler, similar to what we do in
  optprobes and trap-based kprobes.
- Drop setting orig_gpr3 and result to zero in optprobes. These are not
  relevant under kprobes and should not be used by the handlers.

Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
---
 arch/powerpc/kernel/optprobes_head.S        | 5 +----
 arch/powerpc/kernel/trace/ftrace_mprofile.S | 6 ++++++
 2 files changed, 7 insertions(+), 4 deletions(-)

Comments

Nicholas Piggin Nov. 7, 2022, 11:15 a.m. UTC | #1
On Fri Oct 21, 2022 at 3:29 AM AEST, Naveen N. Rao wrote:
> Ensure a more consistent pt_regs across kprobes, optprobes and
> KPROBES_ON_FTRACE:
> - Drop setting trap to 0x700 under optprobes. This is not accurate and
>   is unnecessary. Instead, zero it out for both optprobes and
>   KPROBES_ON_FTRACE.

Okay I think.

> - Save irq soft mask in the ftrace handler, similar to what we do in
>   optprobes and trap-based kprobes.

This advertises the irqs status of regs correctly, whereas previously
it was uninitialised.

> - Drop setting orig_gpr3 and result to zero in optprobes. These are not
>   relevant under kprobes and should not be used by the handlers.

This is for CFAR, which we can't get anyway because we just branched
here. I would rather zero it explicitly though.

Otherwise,

Reviewed-by: Nicholas Piggin <npiggin@gmail.com>

>
> Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> ---
>  arch/powerpc/kernel/optprobes_head.S        | 5 +----
>  arch/powerpc/kernel/trace/ftrace_mprofile.S | 6 ++++++
>  2 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/arch/powerpc/kernel/optprobes_head.S b/arch/powerpc/kernel/optprobes_head.S
> index cd4e7bc32609d3..06df09b4e8b155 100644
> --- a/arch/powerpc/kernel/optprobes_head.S
> +++ b/arch/powerpc/kernel/optprobes_head.S
> @@ -49,11 +49,8 @@ optprobe_template_entry:
>  	/* Save SPRS */
>  	mfmsr	r5
>  	PPC_STL	r5,_MSR(r1)
> -	li	r5,0x700
> -	PPC_STL	r5,_TRAP(r1)
>  	li	r5,0
> -	PPC_STL	r5,ORIG_GPR3(r1)
> -	PPC_STL	r5,RESULT(r1)
> +	PPC_STL	r5,_TRAP(r1)
>  	mfctr	r5
>  	PPC_STL	r5,_CTR(r1)
>  	mflr	r5
> diff --git a/arch/powerpc/kernel/trace/ftrace_mprofile.S b/arch/powerpc/kernel/trace/ftrace_mprofile.S
> index d031093bc43671..f82004089426e6 100644
> --- a/arch/powerpc/kernel/trace/ftrace_mprofile.S
> +++ b/arch/powerpc/kernel/trace/ftrace_mprofile.S
> @@ -107,6 +107,12 @@
>  	PPC_STL	r9, _CTR(r1)
>  	PPC_STL	r10, _XER(r1)
>  	PPC_STL	r11, _CCR(r1)
> +#ifdef CONFIG_PPC64
> +	lbz     r7, PACAIRQSOFTMASK(r13)
> +	std     r7, SOFTE(r1)
> +#endif
> +	li	r8, 0
> +	PPC_STL	r8, _TRAP(r1)
>  	.endif
>  
>  	/* Load &pt_regs in r6 for call below */
> -- 
> 2.38.0
Naveen N. Rao Nov. 8, 2022, 10:52 a.m. UTC | #2
Nicholas Piggin wrote:
> On Fri Oct 21, 2022 at 3:29 AM AEST, Naveen N. Rao wrote:
>> Ensure a more consistent pt_regs across kprobes, optprobes and
>> KPROBES_ON_FTRACE:
>> - Drop setting trap to 0x700 under optprobes. This is not accurate and
>>   is unnecessary. Instead, zero it out for both optprobes and
>>   KPROBES_ON_FTRACE.
> 
> Okay I think.
> 
>> - Save irq soft mask in the ftrace handler, similar to what we do in
>>   optprobes and trap-based kprobes.
> 
> This advertises the irqs status of regs correctly, whereas previously
> it was uninitialised.
> 
>> - Drop setting orig_gpr3 and result to zero in optprobes. These are not
>>   relevant under kprobes and should not be used by the handlers.
> 
> This is for CFAR, which we can't get anyway because we just branched
> here. I would rather zero it explicitly though.

Is there a strong reason to zero those out?

The reason I dropped zero'ing of orig_gpr3 and result is to make 
optprobes consistent with KPROBES_ON_FTRACE. If we want to retain 
zero'ing orig_gpr3/result for optprobes, I think we should then go ahead 
and zero those out in ftrace_regs_caller too.

Thanks,
Naveen
diff mbox series

Patch

diff --git a/arch/powerpc/kernel/optprobes_head.S b/arch/powerpc/kernel/optprobes_head.S
index cd4e7bc32609d3..06df09b4e8b155 100644
--- a/arch/powerpc/kernel/optprobes_head.S
+++ b/arch/powerpc/kernel/optprobes_head.S
@@ -49,11 +49,8 @@  optprobe_template_entry:
 	/* Save SPRS */
 	mfmsr	r5
 	PPC_STL	r5,_MSR(r1)
-	li	r5,0x700
-	PPC_STL	r5,_TRAP(r1)
 	li	r5,0
-	PPC_STL	r5,ORIG_GPR3(r1)
-	PPC_STL	r5,RESULT(r1)
+	PPC_STL	r5,_TRAP(r1)
 	mfctr	r5
 	PPC_STL	r5,_CTR(r1)
 	mflr	r5
diff --git a/arch/powerpc/kernel/trace/ftrace_mprofile.S b/arch/powerpc/kernel/trace/ftrace_mprofile.S
index d031093bc43671..f82004089426e6 100644
--- a/arch/powerpc/kernel/trace/ftrace_mprofile.S
+++ b/arch/powerpc/kernel/trace/ftrace_mprofile.S
@@ -107,6 +107,12 @@ 
 	PPC_STL	r9, _CTR(r1)
 	PPC_STL	r10, _XER(r1)
 	PPC_STL	r11, _CCR(r1)
+#ifdef CONFIG_PPC64
+	lbz     r7, PACAIRQSOFTMASK(r13)
+	std     r7, SOFTE(r1)
+#endif
+	li	r8, 0
+	PPC_STL	r8, _TRAP(r1)
 	.endif
 
 	/* Load &pt_regs in r6 for call below */