All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Christophe Leroy <christophe.leroy@c-s.fr>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Paul Mackerras <paulus@samba.org>
Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH v2 10/12] powerpc/entry32: Blacklist exception entry points for kprobe.
Date: Tue, 31 Mar 2020 22:35:22 +0530	[thread overview]
Message-ID: <1585673757.0rkxmweypy.naveen@linux.ibm.com> (raw)
In-Reply-To: <f61ac599855e674ebb592464d0ea32a3ba9c6644.1585670437.git.christophe.leroy@c-s.fr>

Christophe Leroy wrote:
> kprobe does not handle events happening in real mode.
> 
> As exception entry points are running with MMU disabled,
> blacklist them.
> 
> The handling of TLF_NAPPING and TLF_SLEEPING is moved before the
> CONFIG_TRACE_IRQFLAGS which contains 'reenable_mmu' because from there
> kprobe will be possible as the kernel will run with MMU enabled.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
> Acked-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> ---
> v2: Moved TLF_NAPPING and TLF_SLEEPING handling
> ---
>  arch/powerpc/kernel/entry_32.S | 37 ++++++++++++++++++++--------------
>  1 file changed, 22 insertions(+), 15 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
> index 94f78c03cb79..215aa3a6d4f7 100644
> --- a/arch/powerpc/kernel/entry_32.S
> +++ b/arch/powerpc/kernel/entry_32.S
> @@ -51,6 +51,7 @@ mcheck_transfer_to_handler:
>  	mfspr	r0,SPRN_DSRR1
>  	stw	r0,_DSRR1(r11)
>  	/* fall through */
> +_ASM_NOKPROBE_SYMBOL(mcheck_transfer_to_handler)
> 
>  	.globl	debug_transfer_to_handler
>  debug_transfer_to_handler:
> @@ -59,6 +60,7 @@ debug_transfer_to_handler:
>  	mfspr	r0,SPRN_CSRR1
>  	stw	r0,_CSRR1(r11)
>  	/* fall through */
> +_ASM_NOKPROBE_SYMBOL(debug_transfer_to_handler)
> 
>  	.globl	crit_transfer_to_handler
>  crit_transfer_to_handler:
> @@ -94,6 +96,7 @@ crit_transfer_to_handler:
>  	rlwinm	r0,r1,0,0,(31 - THREAD_SHIFT)
>  	stw	r0,KSP_LIMIT(r8)
>  	/* fall through */
> +_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
>  #endif
> 
>  #ifdef CONFIG_40x
> @@ -115,6 +118,7 @@ crit_transfer_to_handler:
>  	rlwinm	r0,r1,0,0,(31 - THREAD_SHIFT)
>  	stw	r0,KSP_LIMIT(r8)
>  	/* fall through */
> +_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
>  #endif
> 
>  /*
> @@ -127,6 +131,7 @@ crit_transfer_to_handler:
>  	.globl	transfer_to_handler_full
>  transfer_to_handler_full:
>  	SAVE_NVGPRS(r11)
> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler_full)
>  	/* fall through */
> 
>  	.globl	transfer_to_handler
> @@ -227,6 +232,23 @@ transfer_to_handler_cont:
>  	SYNC
>  	RFI				/* jump to handler, enable MMU */
> 
> +#if defined (CONFIG_PPC_BOOK3S_32) || defined(CONFIG_E500)
> +4:	rlwinm	r12,r12,0,~_TLF_NAPPING
> +	stw	r12,TI_LOCAL_FLAGS(r2)
> +	b	power_save_ppc32_restore
> +
> +7:	rlwinm	r12,r12,0,~_TLF_SLEEPING
> +	stw	r12,TI_LOCAL_FLAGS(r2)
> +	lwz	r9,_MSR(r11)		/* if sleeping, clear MSR.EE */
> +	rlwinm	r9,r9,0,~MSR_EE
> +	lwz	r12,_LINK(r11)		/* and return to address in LR */
> +	kuap_restore r11, r2, r3, r4, r5
> +	lwz	r2, GPR2(r11)
> +	b	fast_exception_return
> +#endif
> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler)
> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler_cont)
> +

A very minor nit is that the above NOKPROBE annotation actually covers 
the block of code below between the label '1:' till 'reenable_mmu', but 
isn't obvious from the code. Splitting off 'reenable_mmu' would have 
made that clear.

You don't have to fix that though -- a kprobe still won't be allowed 
there and anyone interested should be able to look up this mail chain.


- Naveen


WARNING: multiple messages have this Message-ID (diff)
From: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Christophe Leroy <christophe.leroy@c-s.fr>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Paul Mackerras <paulus@samba.org>
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 10/12] powerpc/entry32: Blacklist exception entry points for kprobe.
Date: Tue, 31 Mar 2020 22:35:22 +0530	[thread overview]
Message-ID: <1585673757.0rkxmweypy.naveen@linux.ibm.com> (raw)
In-Reply-To: <f61ac599855e674ebb592464d0ea32a3ba9c6644.1585670437.git.christophe.leroy@c-s.fr>

Christophe Leroy wrote:
> kprobe does not handle events happening in real mode.
> 
> As exception entry points are running with MMU disabled,
> blacklist them.
> 
> The handling of TLF_NAPPING and TLF_SLEEPING is moved before the
> CONFIG_TRACE_IRQFLAGS which contains 'reenable_mmu' because from there
> kprobe will be possible as the kernel will run with MMU enabled.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
> Acked-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
> ---
> v2: Moved TLF_NAPPING and TLF_SLEEPING handling
> ---
>  arch/powerpc/kernel/entry_32.S | 37 ++++++++++++++++++++--------------
>  1 file changed, 22 insertions(+), 15 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
> index 94f78c03cb79..215aa3a6d4f7 100644
> --- a/arch/powerpc/kernel/entry_32.S
> +++ b/arch/powerpc/kernel/entry_32.S
> @@ -51,6 +51,7 @@ mcheck_transfer_to_handler:
>  	mfspr	r0,SPRN_DSRR1
>  	stw	r0,_DSRR1(r11)
>  	/* fall through */
> +_ASM_NOKPROBE_SYMBOL(mcheck_transfer_to_handler)
> 
>  	.globl	debug_transfer_to_handler
>  debug_transfer_to_handler:
> @@ -59,6 +60,7 @@ debug_transfer_to_handler:
>  	mfspr	r0,SPRN_CSRR1
>  	stw	r0,_CSRR1(r11)
>  	/* fall through */
> +_ASM_NOKPROBE_SYMBOL(debug_transfer_to_handler)
> 
>  	.globl	crit_transfer_to_handler
>  crit_transfer_to_handler:
> @@ -94,6 +96,7 @@ crit_transfer_to_handler:
>  	rlwinm	r0,r1,0,0,(31 - THREAD_SHIFT)
>  	stw	r0,KSP_LIMIT(r8)
>  	/* fall through */
> +_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
>  #endif
> 
>  #ifdef CONFIG_40x
> @@ -115,6 +118,7 @@ crit_transfer_to_handler:
>  	rlwinm	r0,r1,0,0,(31 - THREAD_SHIFT)
>  	stw	r0,KSP_LIMIT(r8)
>  	/* fall through */
> +_ASM_NOKPROBE_SYMBOL(crit_transfer_to_handler)
>  #endif
> 
>  /*
> @@ -127,6 +131,7 @@ crit_transfer_to_handler:
>  	.globl	transfer_to_handler_full
>  transfer_to_handler_full:
>  	SAVE_NVGPRS(r11)
> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler_full)
>  	/* fall through */
> 
>  	.globl	transfer_to_handler
> @@ -227,6 +232,23 @@ transfer_to_handler_cont:
>  	SYNC
>  	RFI				/* jump to handler, enable MMU */
> 
> +#if defined (CONFIG_PPC_BOOK3S_32) || defined(CONFIG_E500)
> +4:	rlwinm	r12,r12,0,~_TLF_NAPPING
> +	stw	r12,TI_LOCAL_FLAGS(r2)
> +	b	power_save_ppc32_restore
> +
> +7:	rlwinm	r12,r12,0,~_TLF_SLEEPING
> +	stw	r12,TI_LOCAL_FLAGS(r2)
> +	lwz	r9,_MSR(r11)		/* if sleeping, clear MSR.EE */
> +	rlwinm	r9,r9,0,~MSR_EE
> +	lwz	r12,_LINK(r11)		/* and return to address in LR */
> +	kuap_restore r11, r2, r3, r4, r5
> +	lwz	r2, GPR2(r11)
> +	b	fast_exception_return
> +#endif
> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler)
> +_ASM_NOKPROBE_SYMBOL(transfer_to_handler_cont)
> +

A very minor nit is that the above NOKPROBE annotation actually covers 
the block of code below between the label '1:' till 'reenable_mmu', but 
isn't obvious from the code. Splitting off 'reenable_mmu' would have 
made that clear.

You don't have to fix that though -- a kprobe still won't be allowed 
there and anyone interested should be able to look up this mail chain.


- Naveen


  reply	other threads:[~2020-03-31 17:05 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-31 16:03 [PATCH v2 01/12] powerpc/52xx: Blacklist functions running with MMU disabled for kprobe Christophe Leroy
2020-03-31 16:03 ` Christophe Leroy
2020-03-31 16:03 ` [PATCH v2 02/12] powerpc/82xx: Blacklist pq2_restart() " Christophe Leroy
2020-03-31 16:03   ` Christophe Leroy
2020-03-31 16:03 ` [PATCH v2 03/12] powerpc/83xx: Blacklist mpc83xx_deep_resume() " Christophe Leroy
2020-03-31 16:03   ` Christophe Leroy
2020-03-31 16:03 ` [PATCH v2 04/12] powerpc/powermac: Blacklist functions running with MMU disabled " Christophe Leroy
2020-03-31 16:03   ` Christophe Leroy
2020-03-31 16:03 ` [PATCH v2 05/12] powerpc/mem: Blacklist flush_dcache_icache_phys() " Christophe Leroy
2020-03-31 16:03   ` Christophe Leroy
2020-03-31 16:03 ` [PATCH v2 06/12] powerpc/32s: Make local symbols non visible in hash_low Christophe Leroy
2020-03-31 16:03   ` Christophe Leroy
2020-03-31 16:03 ` [PATCH v2 07/12] powerpc/32s: Blacklist functions running with MMU disabled for kprobe Christophe Leroy
2020-03-31 16:03   ` Christophe Leroy
2020-03-31 16:03 ` [PATCH v2 08/12] powerpc/rtas: Remove machine_check_in_rtas() Christophe Leroy
2020-03-31 16:03   ` Christophe Leroy
2020-03-31 16:03 ` [PATCH v2 09/12] powerpc/32: Blacklist functions running with MMU disabled for kprobe Christophe Leroy
2020-03-31 16:03   ` Christophe Leroy
2020-03-31 16:03 ` [PATCH v2 10/12] powerpc/entry32: Blacklist exception entry points " Christophe Leroy
2020-03-31 16:03   ` Christophe Leroy
2020-03-31 17:05   ` Naveen N. Rao [this message]
2020-03-31 17:05     ` Naveen N. Rao
2020-03-31 16:03 ` [PATCH v2 11/12] powerpc/entry32: Blacklist syscall exit " Christophe Leroy
2020-03-31 16:03   ` Christophe Leroy
2020-03-31 16:03 ` [PATCH v2 12/12] powerpc/entry32: Blacklist exception " Christophe Leroy
2020-03-31 16:03   ` Christophe Leroy
2020-06-09  5:28 ` [PATCH v2 01/12] powerpc/52xx: Blacklist functions running with MMU disabled " Michael Ellerman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1585673757.0rkxmweypy.naveen@linux.ibm.com \
    --to=naveen.n.rao@linux.vnet.ibm.com \
    --cc=benh@kernel.crashing.org \
    --cc=christophe.leroy@c-s.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.