From: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>
To: Shrikanth Hegde <sshegde@linux.ibm.com>,
"Mukesh Kumar Chaurasiya (IBM)" <mkchauras@gmail.com>
Cc: maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com,
ritesh.list@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: Re: [PATCH] powerpc/syscall: Avoid atomic test_and_clear_thread_flag on fast path
Date: Tue, 29 Sep 2026 14:43:33 +0200 [thread overview]
Message-ID: <b5b736c3-badf-4ceb-a4b7-00415bed19fe@kernel.org> (raw)
In-Reply-To: <84ceaa9a-79fb-4585-a571-7701750df5d1@linux.ibm.com>
Le 29/09/2026 à 11:50, Shrikanth Hegde a écrit :
>
>
> On 9/29/26 12:47 PM, Mukesh Kumar Chaurasiya (IBM) wrote:
>> 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.
>>
>
> Do you have numbers?
>
>> 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.
>>
>
> It probably needs a fixes tag.
It is not a bug, unless we can figure out a quantified regression.
>
>> 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)))
>
> I am bit surprised that test_and_clear_bit does
> atomic operations even when bit is not set.
It does (on ppc64 smp)
sync
1: ldarx
andc
stdcx.
bne 1b
sync
It is optimised to clear a bit that is set. When the bit is already
unset you still get the full sequence allthough it does nothing.
>
>> - return syscall_get_error(current, regs);
>> -
>> if (unlikely(r0 >= NR_syscalls)) {
>> if (unlikely(trap_is_unsupported_scv(regs))) {
>> /* Unsupported scv vector */
>
prev parent reply other threads:[~2026-09-29 12:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 7:17 Mukesh Kumar Chaurasiya (IBM)
2026-09-29 9:50 ` Shrikanth Hegde
2026-09-29 12:43 ` Christophe Leroy (CS GROUP) [this message]
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=b5b736c3-badf-4ceb-a4b7-00415bed19fe@kernel.org \
--to=chleroy@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mkchauras@gmail.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®