Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] arm64: Return early when break handler is found on linked-list
@ 2024-10-24  3:41 Liao Chang
  2024-10-24 14:50 ` Will Deacon
  2024-11-01 17:36 ` Catalin Marinas
  0 siblings, 2 replies; 4+ messages in thread
From: Liao Chang @ 2024-10-24  3:41 UTC (permalink / raw)
  To: mark.rutland, catalin.marinas, will, oliver.upton,
	kristina.martsenko, ptosi, liaochang1
  Cc: linux-arm-kernel, linux-kernel

The search for breakpoint handlers iterate through the entire
linked list. Given that all registered hook has a valid fn field, and no
registered hooks share the same mask and imm. This commit optimize the
efficiency slightly by returning early as a matching handler is found.

v2->v1:
Remove all WARN_ON(!hook->fn) in v1 as Will suggested.

Signed-off-by: Liao Chang <liaochang1@huawei.com>
---
 arch/arm64/kernel/debug-monitors.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
index c60a4a90c6a5..58f047de3e1c 100644
--- a/arch/arm64/kernel/debug-monitors.c
+++ b/arch/arm64/kernel/debug-monitors.c
@@ -303,7 +303,6 @@ static int call_break_hook(struct pt_regs *regs, unsigned long esr)
 {
 	struct break_hook *hook;
 	struct list_head *list;
-	int (*fn)(struct pt_regs *regs, unsigned long esr) = NULL;
 
 	list = user_mode(regs) ? &user_break_hook : &kernel_break_hook;
 
@@ -313,10 +312,10 @@ static int call_break_hook(struct pt_regs *regs, unsigned long esr)
 	 */
 	list_for_each_entry_rcu(hook, list, node) {
 		if ((esr_brk_comment(esr) & ~hook->mask) == hook->imm)
-			fn = hook->fn;
+			return hook->fn(regs, esr);
 	}
 
-	return fn ? fn(regs, esr) : DBG_HOOK_ERROR;
+	return DBG_HOOK_ERROR;
 }
 NOKPROBE_SYMBOL(call_break_hook);
 
-- 
2.34.1



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

* Re: [PATCH v2] arm64: Return early when break handler is found on linked-list
  2024-10-24  3:41 [PATCH v2] arm64: Return early when break handler is found on linked-list Liao Chang
@ 2024-10-24 14:50 ` Will Deacon
  2024-10-29  2:42   ` Liao, Chang
  2024-11-01 17:36 ` Catalin Marinas
  1 sibling, 1 reply; 4+ messages in thread
From: Will Deacon @ 2024-10-24 14:50 UTC (permalink / raw)
  To: Liao Chang
  Cc: mark.rutland, catalin.marinas, oliver.upton, kristina.martsenko,
	ptosi, linux-arm-kernel, linux-kernel

On Thu, Oct 24, 2024 at 03:41:20AM +0000, Liao Chang wrote:
> The search for breakpoint handlers iterate through the entire
> linked list. Given that all registered hook has a valid fn field, and no
> registered hooks share the same mask and imm. This commit optimize the
> efficiency slightly by returning early as a matching handler is found.
> 
> v2->v1:
> Remove all WARN_ON(!hook->fn) in v1 as Will suggested.

nit: Changelogs like ^^^ should go after the '---' line, otherwise they
end up in the git history.

> Signed-off-by: Liao Chang <liaochang1@huawei.com>
> ---
>  arch/arm64/kernel/debug-monitors.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
> index c60a4a90c6a5..58f047de3e1c 100644
> --- a/arch/arm64/kernel/debug-monitors.c
> +++ b/arch/arm64/kernel/debug-monitors.c
> @@ -303,7 +303,6 @@ static int call_break_hook(struct pt_regs *regs, unsigned long esr)
>  {
>  	struct break_hook *hook;
>  	struct list_head *list;
> -	int (*fn)(struct pt_regs *regs, unsigned long esr) = NULL;
>  
>  	list = user_mode(regs) ? &user_break_hook : &kernel_break_hook;
>  
> @@ -313,10 +312,10 @@ static int call_break_hook(struct pt_regs *regs, unsigned long esr)
>  	 */
>  	list_for_each_entry_rcu(hook, list, node) {
>  		if ((esr_brk_comment(esr) & ~hook->mask) == hook->imm)
> -			fn = hook->fn;
> +			return hook->fn(regs, esr);
>  	}
>  
> -	return fn ? fn(regs, esr) : DBG_HOOK_ERROR;
> +	return DBG_HOOK_ERROR;
>  }
>  NOKPROBE_SYMBOL(call_break_hook);

Acked-by: Will Deacon <will@kernel.org>

I assume Catalin will pick this one up (but he'll need to tweak the
commit message as per my comment above).

Will


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

* Re: [PATCH v2] arm64: Return early when break handler is found on linked-list
  2024-10-24 14:50 ` Will Deacon
@ 2024-10-29  2:42   ` Liao, Chang
  0 siblings, 0 replies; 4+ messages in thread
From: Liao, Chang @ 2024-10-29  2:42 UTC (permalink / raw)
  To: Will Deacon
  Cc: mark.rutland, catalin.marinas, oliver.upton, kristina.martsenko,
	ptosi, linux-arm-kernel, linux-kernel



在 2024/10/24 22:50, Will Deacon 写道:
> On Thu, Oct 24, 2024 at 03:41:20AM +0000, Liao Chang wrote:
>> The search for breakpoint handlers iterate through the entire
>> linked list. Given that all registered hook has a valid fn field, and no
>> registered hooks share the same mask and imm. This commit optimize the
>> efficiency slightly by returning early as a matching handler is found.
>>
>> v2->v1:
>> Remove all WARN_ON(!hook->fn) in v1 as Will suggested.
> 
> nit: Changelogs like ^^^ should go after the '---' line, otherwise they
> end up in the git history.

Will

Thanks for pointing out.

> 
>> Signed-off-by: Liao Chang <liaochang1@huawei.com>
>> ---
>>  arch/arm64/kernel/debug-monitors.c | 5 ++---
>>  1 file changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
>> index c60a4a90c6a5..58f047de3e1c 100644
>> --- a/arch/arm64/kernel/debug-monitors.c
>> +++ b/arch/arm64/kernel/debug-monitors.c
>> @@ -303,7 +303,6 @@ static int call_break_hook(struct pt_regs *regs, unsigned long esr)
>>  {
>>  	struct break_hook *hook;
>>  	struct list_head *list;
>> -	int (*fn)(struct pt_regs *regs, unsigned long esr) = NULL;
>>  
>>  	list = user_mode(regs) ? &user_break_hook : &kernel_break_hook;
>>  
>> @@ -313,10 +312,10 @@ static int call_break_hook(struct pt_regs *regs, unsigned long esr)
>>  	 */
>>  	list_for_each_entry_rcu(hook, list, node) {
>>  		if ((esr_brk_comment(esr) & ~hook->mask) == hook->imm)
>> -			fn = hook->fn;
>> +			return hook->fn(regs, esr);
>>  	}
>>  
>> -	return fn ? fn(regs, esr) : DBG_HOOK_ERROR;
>> +	return DBG_HOOK_ERROR;
>>  }
>>  NOKPROBE_SYMBOL(call_break_hook);
> 
> Acked-by: Will Deacon <will@kernel.org>
> 
> I assume Catalin will pick this one up (but he'll need to tweak the
> commit message as per my comment above).
> 
> Will

-- 
BR
Liao, Chang



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

* Re: [PATCH v2] arm64: Return early when break handler is found on linked-list
  2024-10-24  3:41 [PATCH v2] arm64: Return early when break handler is found on linked-list Liao Chang
  2024-10-24 14:50 ` Will Deacon
@ 2024-11-01 17:36 ` Catalin Marinas
  1 sibling, 0 replies; 4+ messages in thread
From: Catalin Marinas @ 2024-11-01 17:36 UTC (permalink / raw)
  To: mark.rutland, will, oliver.upton, kristina.martsenko, ptosi,
	Liao Chang
  Cc: linux-arm-kernel, linux-kernel

On Thu, 24 Oct 2024 03:41:20 +0000, Liao Chang wrote:
> The search for breakpoint handlers iterate through the entire
> linked list. Given that all registered hook has a valid fn field, and no
> registered hooks share the same mask and imm. This commit optimize the
> efficiency slightly by returning early as a matching handler is found.
> 
> v2->v1:
> Remove all WARN_ON(!hook->fn) in v1 as Will suggested.
> 
> [...]

Applied to arm64 (for-next/misc), thanks!

[1/1] arm64: Return early when break handler is found on linked-list
      https://git.kernel.org/arm64/c/9a0e3b92b02e

-- 
Catalin



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

end of thread, other threads:[~2024-11-01 17:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-24  3:41 [PATCH v2] arm64: Return early when break handler is found on linked-list Liao Chang
2024-10-24 14:50 ` Will Deacon
2024-10-29  2:42   ` Liao, Chang
2024-11-01 17:36 ` Catalin Marinas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox