mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Mukesh Kumar Chaurasiya (IBM)" <mkchauras@gmail.com>
To: maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com,
	chleroy@kernel.org, ritesh.list@gmail.com, sshegde@linux.ibm.com,
	mkchauras@gmail.com, ruanjinjie@huawei.com, tglx@kernel.org,
	mkchauras@linux.ibm.com, ryan.roberts@arm.com,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: [PATCH] powerpc/syscall: Avoid atomic test_and_clear_thread_flag on fast path
Date: Tue, 29 Sep 2026 12:47:44 +0530	[thread overview]
Message-ID: <20260929071744.2965058-1-mkchauras@gmail.com> (raw)

In system_call_exception(), test_and_clear_thread_flag(TIF_SYSCALL_RET)
performs an atomic bit test-and-clear operation on every system call entry.
This introduces an unnecessary performance regression on the syscall fast
path.

Combine the TIF_SYSCALL_RET check with the unlikely error condition from
syscall_enter_from_user_mode_randomize_stack() using non-atomic
test_thread_flag(). If the flag is set or entry failed, only then clear the
flag via clear_thread_flag() and return the error value.

Signed-off-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras@gmail.com>
---
 arch/powerpc/kernel/syscall.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
index fbefe1927b10..8529827d697f 100644
--- a/arch/powerpc/kernel/syscall.c
+++ b/arch/powerpc/kernel/syscall.c
@@ -18,14 +18,12 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
 	long ret;
 	syscall_fn f;
 
-	if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0))) {
+	if (unlikely(!syscall_enter_from_user_mode_randomize_stack(regs, &r0) ||
+			test_thread_flag(TIF_SYSCALL_RET))) {
 		clear_thread_flag(TIF_SYSCALL_RET);
 		return syscall_get_error(current, regs);
 	}
 
-	if (unlikely(test_and_clear_thread_flag(TIF_SYSCALL_RET)))
-		return syscall_get_error(current, regs);
-
 	if (unlikely(r0 >= NR_syscalls)) {
 		if (unlikely(trap_is_unsupported_scv(regs))) {
 			/* Unsupported scv vector */
-- 
2.55.0


             reply	other threads:[~2026-09-29  7:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29  7:17 Mukesh Kumar Chaurasiya (IBM) [this message]
2026-09-29  9:50 ` Shrikanth Hegde
2026-09-29 12:43   ` Christophe Leroy (CS GROUP)

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=20260929071744.2965058-1-mkchauras@gmail.com \
    --to=mkchauras@gmail.com \
    --cc=chleroy@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mkchauras@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=ritesh.list@gmail.com \
    --cc=ruanjinjie@huawei.com \
    --cc=ryan.roberts@arm.com \
    --cc=sshegde@linux.ibm.com \
    --cc=tglx@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®