mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Venkat <venkat88@linux.ibm.com>
To: Thibault Ferrante <thibault.ferrante@canonical.com>
Cc: linuxppc-dev@lists.ozlabs.org, maddy@linux.ibm.com,
	mpe@ellerman.id.au, npiggin@gmail.com, shuah@kernel.org,
	chleroy@kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] selftests/powerpc/tm: Fix tcheck() reading uninitialised CR value
Date: Wed, 9 Sep 2026 10:58:23 +0530	[thread overview]
Message-ID: <4206CE63-979B-4464-BECE-F89D0B1BDC91@linux.ibm.com> (raw)
In-Reply-To: <20260907215420.1258678-1-thibault.ferrante@canonical.com>



> On 8 Sep 2026, at 3:24 AM, Thibault Ferrante <thibault.ferrante@canonical.com> wrote:
> 
> tcheck() is used to check the current transaction state (active,
> suspended, doomed) via the "tcheck" instruction, which writes its
> result into CR field 0. The inline asm declared a GPR output operand
> for this result but never actually moved the CR into it.
> 
> Every caller (tcheck_doomed(), tcheck_active(), tcheck_suspended(),
> tcheck_transactional()) has effectively been testing bits of an unrelated,
> arbitrary register value since this helper was introduced.
> The "& 4" mask discards the TDOOMED and TS_lsb (suspended) bits before
> they ever reach the callers, so tcheck_doomed() and tcheck_suspended()
> can never return true, and tcheck_transactional() degrades to being
> equivalent to tcheck_active().
> 
> Fix tcheck() to actually move CR into the output register with mfcr,
> and widen the mask from "& 4" to "& 0xf" so the full CR0 nibble
> (TDOOMED | TS_msb | TS_lsb | reserved) is preserved for the callers.
> 
> This bug has been present since tcheck() was introduced.
> 
> Link: https://bugs.launchpad.net/bugs/2107442
> Fixes: 8e03bd4e70b6 ("selftests/powerpc: Add TM tcheck helpers in C")
> Signed-off-by: Thibault Ferrante <thibault.ferrante@canonical.com>
> ---

Applied this patch on top of latest mainline and all the signal selftests are passing.


Please add below tags.

Reported-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
Tested-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
Closes: https://lore.kernel.org/all/364996ce-aba2-4213-8d20-7dd481b43fe6@linux.ibm.com/

With this Patch:


# make run_tests 
# timeout set to 0
# selftests: powerpc/signal: signal
ok 1 selftests: powerpc/signal: signal
# timeout set to 0
# selftests: powerpc/signal: signal_tm
ok 2 selftests: powerpc/signal: signal_tm
# timeout set to 0
# selftests: powerpc/signal: sigfuz
ok 3 selftests: powerpc/signal: sigfuz
# timeout set to 0
# selftests: powerpc/signal: sigreturn_vdso
ok 4 selftests: powerpc/signal: sigreturn_vdso
# timeout set to 0
# selftests: powerpc/signal: sig_sc_double_restart
ok 5 selftests: powerpc/signal: sig_sc_double_restart
# timeout set to 0
# selftests: powerpc/signal: sigreturn_kernel
ok 6 selftests: powerpc/signal: sigreturn_kernel
# timeout set to 0
# selftests: powerpc/signal: sigreturn_unaligned
ok 7 selftests: powerpc/signal: sigreturn_unaligned

Regards,
Venkat.



> tools/testing/selftests/powerpc/tm/tm.h | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/powerpc/tm/tm.h b/tools/testing/selftests/powerpc/tm/tm.h
> index c03c6e778876..6024ce4ba6ff 100644
> --- a/tools/testing/selftests/powerpc/tm/tm.h
> +++ b/tools/testing/selftests/powerpc/tm/tm.h
> @@ -105,8 +105,12 @@ static inline bool failure_is_nesting(void)
> static inline int tcheck(void)
> {
> long cr;
> - asm volatile ("tcheck 0" : "=r"(cr) : : "cr0");
> - return (cr >> 28) & 4;
> + asm volatile("tcheck 0;"
> +     "mfcr %0;"
> +     : "=r"(cr)
> +     :
> +     : "cr0");
> + return (cr >> 28) & 0xf;
> }
> 
> static inline bool tcheck_doomed(void)
> -- 
> 2.55.0
> 


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

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-07 21:54 Thibault Ferrante
2026-09-09  5:28 ` Venkat [this message]
2026-09-09  8:56   ` Christophe Leroy (CS GROUP)
2026-09-09 10:05     ` Thibault Ferrante

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=4206CE63-979B-4464-BECE-F89D0B1BDC91@linux.ibm.com \
    --to=venkat88@linux.ibm.com \
    --cc=chleroy@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=shuah@kernel.org \
    --cc=thibault.ferrante@canonical.com \
    /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®