public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] arm64: add unlikely hint to MTE async fault check in el0_svc_common
@ 2025-09-19  3:33 Li Qiang
  2025-09-22 10:59 ` Will Deacon
  2025-11-11 20:17 ` Catalin Marinas
  0 siblings, 2 replies; 4+ messages in thread
From: Li Qiang @ 2025-09-19  3:33 UTC (permalink / raw)
  To: catalin.marinas, will; +Cc: linux-arm-kernel, linux-kernel, Li Qiang

Add unlikely() hint to the _TIF_MTE_ASYNC_FAULT flag check in
el0_svc_common() since asynchronous MTE faults are expected to be
rare occurrences during normal system call execution.

This optimization helps the compiler to improve instruction caching
and branch prediction for the common case where no asynchronous
MTE faults are pending, while maintaining correct behavior for
the exceptional case where such faults need to be handled prior
to system call execution.

Signed-off-by: Li Qiang <liqiang01@kylinos.cn>
---
 arch/arm64/kernel/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c
index c442fcec6b9e..7eb13f4c87da 100644
--- a/arch/arm64/kernel/syscall.c
+++ b/arch/arm64/kernel/syscall.c
@@ -96,7 +96,7 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr,
 	 * (Similarly for HVC and SMC elsewhere.)
 	 */
 
-	if (flags & _TIF_MTE_ASYNC_FAULT) {
+	if (unlikely(flags & _TIF_MTE_ASYNC_FAULT)) {
 		/*
 		 * Process the asynchronous tag check fault before the actual
 		 * syscall. do_notify_resume() will send a signal to userspace
-- 
2.25.1



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

* Re: [PATCH] arm64: add unlikely hint to MTE async fault check in el0_svc_common
  2025-09-19  3:33 [PATCH] arm64: add unlikely hint to MTE async fault check in el0_svc_common Li Qiang
@ 2025-09-22 10:59 ` Will Deacon
  2025-09-28  9:01   ` Li Qiang
  2025-11-11 20:17 ` Catalin Marinas
  1 sibling, 1 reply; 4+ messages in thread
From: Will Deacon @ 2025-09-22 10:59 UTC (permalink / raw)
  To: Li Qiang; +Cc: catalin.marinas, linux-arm-kernel, linux-kernel

On Fri, Sep 19, 2025 at 11:33:27AM +0800, Li Qiang wrote:
> Add unlikely() hint to the _TIF_MTE_ASYNC_FAULT flag check in
> el0_svc_common() since asynchronous MTE faults are expected to be
> rare occurrences during normal system call execution.
> 
> This optimization helps the compiler to improve instruction caching
> and branch prediction for the common case where no asynchronous
> MTE faults are pending, while maintaining correct behavior for
> the exceptional case where such faults need to be handled prior
> to system call execution.
> 
> Signed-off-by: Li Qiang <liqiang01@kylinos.cn>
> ---
>  arch/arm64/kernel/syscall.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Does this result in a measurable performance difference?

Will


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

* Re: [PATCH] arm64: add unlikely hint to MTE async fault check in el0_svc_common
  2025-09-22 10:59 ` Will Deacon
@ 2025-09-28  9:01   ` Li Qiang
  0 siblings, 0 replies; 4+ messages in thread
From: Li Qiang @ 2025-09-28  9:01 UTC (permalink / raw)
  To: will; +Cc: catalin.marinas, linux-arm-kernel, linux-kernel

> Does this result in a measurable performance difference?
> Will

Hi,

I did not observe a measurable performance difference in micro-benchmarks 
(e.g. syscall latency tests), since asynchronous MTE faults are extremely 
rare and the branch is almost never taken.

However, `el0_svc_common()` is a very hot path. Without the `unlikely()` 
hint, the compiler may not optimize for the common case, and after an 
I-cache eviction or branch predictor state reset the fault check can 
be mispredicted. Marking it as `unlikely()` makes the fast path layout 
clearer and reduces the chance of branch misprediction in cold-start 
situations, consistent with how other rare-condition checks are annotated.

Thanks,
Li Qiang


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

* Re: [PATCH] arm64: add unlikely hint to MTE async fault check in el0_svc_common
  2025-09-19  3:33 [PATCH] arm64: add unlikely hint to MTE async fault check in el0_svc_common Li Qiang
  2025-09-22 10:59 ` Will Deacon
@ 2025-11-11 20:17 ` Catalin Marinas
  1 sibling, 0 replies; 4+ messages in thread
From: Catalin Marinas @ 2025-11-11 20:17 UTC (permalink / raw)
  To: will, Li Qiang; +Cc: linux-arm-kernel, linux-kernel

On Fri, 19 Sep 2025 11:33:27 +0800, Li Qiang wrote:
> Add unlikely() hint to the _TIF_MTE_ASYNC_FAULT flag check in
> el0_svc_common() since asynchronous MTE faults are expected to be
> rare occurrences during normal system call execution.
> 
> This optimization helps the compiler to improve instruction caching
> and branch prediction for the common case where no asynchronous
> MTE faults are pending, while maintaining correct behavior for
> the exceptional case where such faults need to be handled prior
> to system call execution.
> 
> [...]

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

[1/1] arm64: add unlikely hint to MTE async fault check in el0_svc_common
      https://git.kernel.org/arm64/c/df717b9564c8

-- 
Catalin



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

end of thread, other threads:[~2025-11-11 20:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-19  3:33 [PATCH] arm64: add unlikely hint to MTE async fault check in el0_svc_common Li Qiang
2025-09-22 10:59 ` Will Deacon
2025-09-28  9:01   ` Li Qiang
2025-11-11 20:17 ` Catalin Marinas

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