arch/arm64/kernel/syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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
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
> 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
© 2016 - 2025 Red Hat, Inc.