linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64/kernel/probes: Use BUG_ON instead of if condition followed by BUG.
@ 2021-03-30 11:57 zhouchuangao
  2021-03-30 12:08 ` Will Deacon
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: zhouchuangao @ 2021-03-30 11:57 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon, Masami Hiramatsu,
	Jean-Philippe Brucker, Andrew Morton, Qais Yousef, zhouchuangao,
	linux-arm-kernel, linux-kernel

It can be optimized at compile time.

Signed-off-by: zhouchuangao <zhouchuangao@vivo.com>
---
 arch/arm64/kernel/probes/kprobes.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
index 66aac28..ecf0f61 100644
--- a/arch/arm64/kernel/probes/kprobes.c
+++ b/arch/arm64/kernel/probes/kprobes.c
@@ -264,8 +264,7 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr)
 		 * normal page fault.
 		 */
 		instruction_pointer_set(regs, (unsigned long) cur->addr);
-		if (!instruction_pointer(regs))
-			BUG();
+		BUG_ON(!instruction_pointer(regs));
 
 		if (kcb->kprobe_status == KPROBE_REENTER)
 			restore_previous_kprobe(kcb);
-- 
2.7.4


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

* Re: [PATCH] arm64/kernel/probes: Use BUG_ON instead of if condition followed by BUG.
  2021-03-30 11:57 [PATCH] arm64/kernel/probes: Use BUG_ON instead of if condition followed by BUG zhouchuangao
@ 2021-03-30 12:08 ` Will Deacon
  2021-04-01 10:49   ` 周传高
  2021-04-01 21:21 ` Masami Hiramatsu
  2021-04-14 10:07 ` Catalin Marinas
  2 siblings, 1 reply; 5+ messages in thread
From: Will Deacon @ 2021-03-30 12:08 UTC (permalink / raw)
  To: zhouchuangao
  Cc: Catalin Marinas, Masami Hiramatsu, Jean-Philippe Brucker,
	Andrew Morton, Qais Yousef, linux-arm-kernel, linux-kernel

On Tue, Mar 30, 2021 at 04:57:50AM -0700, zhouchuangao wrote:
> It can be optimized at compile time.

Hmm, I don't see it (and I also don't understand why we care). Do you have
numbers showing that this is worthwhile?

Will

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

* Re:Re: [PATCH] arm64/kernel/probes: Use BUG_ON instead of if condition followed by BUG.
  2021-03-30 12:08 ` Will Deacon
@ 2021-04-01 10:49   ` 周传高
  0 siblings, 0 replies; 5+ messages in thread
From: 周传高 @ 2021-04-01 10:49 UTC (permalink / raw)
  To: Will Deacon
  Cc: Catalin Marinas, Masami Hiramatsu, Jean-Philippe Brucker,
	Andrew Morton, Qais Yousef, linux-arm-kernel, linux-kernel


>On Tue, Mar 30, 2021 at 04:57:50AM -0700, zhouchuangao wrote:>> It can be optimized at compile time.
>
>Hmm, I don't see it (and I also don't understand why we care). Do you have
>numbers showing that this is worthwhile?
>

#define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while (0)

BUG_ON uses unlikely in if(). Through disassembly, we can see that
brk #0x800 is compiled to the end of the function.
As you can see below:
    ......
    ffffff8008660bec:   d65f03c0    ret
    ffffff8008660bf0:   d4210000    brk #0x800

Usually, the condition in if () is not satisfied. For the multi-stage pipeline, 
we do not need to perform fetch decode and excute operation on brk 
instruction.

In my opinion, this can improve the efficiency of the multi-stage pipeline.

zhouchuangao

>Will



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

* Re: [PATCH] arm64/kernel/probes: Use BUG_ON instead of if condition followed by BUG.
  2021-03-30 11:57 [PATCH] arm64/kernel/probes: Use BUG_ON instead of if condition followed by BUG zhouchuangao
  2021-03-30 12:08 ` Will Deacon
@ 2021-04-01 21:21 ` Masami Hiramatsu
  2021-04-14 10:07 ` Catalin Marinas
  2 siblings, 0 replies; 5+ messages in thread
From: Masami Hiramatsu @ 2021-04-01 21:21 UTC (permalink / raw)
  To: zhouchuangao
  Cc: Catalin Marinas, Will Deacon, Jean-Philippe Brucker,
	Andrew Morton, Qais Yousef, linux-arm-kernel, linux-kernel

On Tue, 30 Mar 2021 04:57:50 -0700
zhouchuangao <zhouchuangao@vivo.com> wrote:

> It can be optimized at compile time.
> 

Anyway, this seems to make the code simpler.

Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>

Thanks!

> Signed-off-by: zhouchuangao <zhouchuangao@vivo.com>
> ---
>  arch/arm64/kernel/probes/kprobes.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c
> index 66aac28..ecf0f61 100644
> --- a/arch/arm64/kernel/probes/kprobes.c
> +++ b/arch/arm64/kernel/probes/kprobes.c
> @@ -264,8 +264,7 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr)
>  		 * normal page fault.
>  		 */
>  		instruction_pointer_set(regs, (unsigned long) cur->addr);
> -		if (!instruction_pointer(regs))
> -			BUG();
> +		BUG_ON(!instruction_pointer(regs));
>  
>  		if (kcb->kprobe_status == KPROBE_REENTER)
>  			restore_previous_kprobe(kcb);
> -- 
> 2.7.4
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

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

* Re: [PATCH] arm64/kernel/probes: Use BUG_ON instead of if condition followed by BUG.
  2021-03-30 11:57 [PATCH] arm64/kernel/probes: Use BUG_ON instead of if condition followed by BUG zhouchuangao
  2021-03-30 12:08 ` Will Deacon
  2021-04-01 21:21 ` Masami Hiramatsu
@ 2021-04-14 10:07 ` Catalin Marinas
  2 siblings, 0 replies; 5+ messages in thread
From: Catalin Marinas @ 2021-04-14 10:07 UTC (permalink / raw)
  To: Masami Hiramatsu, Jean-Philippe Brucker, Qais Yousef,
	Andrew Morton, Will Deacon, linux-kernel, zhouchuangao,
	linux-arm-kernel
  Cc: Catalin Marinas

On Tue, 30 Mar 2021 04:57:50 -0700, zhouchuangao wrote:
> It can be optimized at compile time.

Applied to arm64 (for-next/misc), it saves one line ;). Thanks!

[1/1] arm64/kernel/probes: Use BUG_ON instead of if condition followed by BUG.
      https://git.kernel.org/arm64/c/839157876f97

-- 
Catalin


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

end of thread, other threads:[~2021-04-14 10:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-30 11:57 [PATCH] arm64/kernel/probes: Use BUG_ON instead of if condition followed by BUG zhouchuangao
2021-03-30 12:08 ` Will Deacon
2021-04-01 10:49   ` 周传高
2021-04-01 21:21 ` Masami Hiramatsu
2021-04-14 10:07 ` Catalin Marinas

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).