Linux s390 Architecture development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Heiko Carstens" <hca@linux.ibm.com>
Cc: "Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	linux-s390@vger.kernel.org,
	"Alexander Gordeev" <agordeev@linux.ibm.com>
Subject: Re: [PATCH v3 11/11] s390/percpu: Rework to simplify percpu_entry() and percpu_exit()
Date: Mon, 21 Sep 2026 08:52:52 +0000	[thread overview]
Message-ID: <20260921085253.5E0881F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260921084005.4022574-12-hca@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] s390/percpu: GCC can allocate %r0 for offset register causing memory corruption
--

commit 7d2dae81caa8a6021304f844d79c9291c54c5a8b
Author: Heiko Carstens <hca@linux.ibm.com>

s390/percpu: Rework to simplify percpu_entry() and percpu_exit()

This commit reworks s390 percpu code sections to use a new register encoding
strategy similar to arm64. It removes the need to check specific instructions
during interrupts by using a register pair to encode the percpu variable
address and offset, adjusting them in percpu_exit() upon CPU migration.

Link: https://lore.kernel.org/all/20260908151741.394589-1-mark.rutland@arm.com/

> diff --git a/arch/s390/include/asm/percpu.h b/arch/s390/include/asm/percpu.h
> index 46368131b932b..db30f5ac40427 100644
> --- a/arch/s390/include/asm/percpu.h
> +++ b/arch/s390/include/asm/percpu.h
[ ... ]
> +#define __PCPU_LA(regptr, regoff, regpcp)					\
> +	"	la	" regptr ",0(" regoff "," regpcp ")\n"

[Severity: Critical]
Does this code safely handle the case where regoff is assigned to %r0?
The la (load address) instruction treats %r0 as 0 when used as an index or
base register. If regoff evaluates to %r0, the instruction would effectively
ignore the percpu offset entirely. This could cause subsequent atomic
operations to modify the base .data..percpu variable instead of the current
CPU's local instance.

> +
> +#define __PCPU_CALC_REGVAL(regpcp, regoff)					\
> +	"(" regpcp " << " __stringify(PCPU_REG_PCP_SHIFT) ") |"			\
> +	"(" regoff " << " __stringify(PCPU_REG_OFF_SHIFT) ")"
> +
> +#define __PCPU_CHECK_REGS(regpcp, regoff, regptr)				\
> +	".if " regoff " & 1\n"							\
> +	"	.error \"Percpu offset register must be even\"\n"		\
> +	".endif\n"								\
> +	".if " regptr " != " regoff " + 1\n"					\
> +	"	.error \"Percpu pointer and offset register must be a pair\"\n" \
> +	".endif\n"								\
> +	".if " regptr " == 0\n"							\
> +	"	.error \"Percpu pointer register must be non-zero\"\n"		\

[Severity: Critical]
Does this assembler check protect against the %r0 base/index semantic
described above? It looks like it checks regptr instead of regoff. If the
compiler allocates the %r0 and %r1 pair, regptr will be %r1, which silently
bypasses this check. Should this be checking if regoff is 0 instead?

[ ... ]
> @@ -158,25 +194,27 @@ do {										\
>  	if (__builtin_constant_p(val__) &&					\
>  	    ((szcast)val__ > -129) && ((szcast)val__ < 128)) {			\
>  		asm volatile(							\
> -			__PCPU_BEGIN("%[lcreg]","%[lcoff]","%[ptr__]")		\
> -			op2 "   0(%[ptr__]),%[val__]\n"				\
> +			__PCPU_BEGIN("%[lcreg]","%[lcoff]","%[ptr__]",		\
> +				      "%[pair__]","%N[pair__]")			\
> +			op2 "   0(%N[pair__]),%[val__]\n"			\
>  			__PCPU_END("%[lcreg]")					\
> -			: [ptr__] "+&a" (ptr__), "+m" (*ptr__),			\
> +			: [pair__] "=&d" (rp__.pair), "+m" (*ptr__),		\

[Severity: Critical]
Can GCC allocate %r0 for the pair here? The "=&d" constraint allows the
compiler to select any general-purpose register, meaning it could allocate
the %r0 and %r1 pair for rp__.pair. Would using "=&a" (address registers)
instead prevent %r0 allocation and avoid the code generation issue with the
la instruction above? This seems to apply to all modified percpu macros in
this file using the "=&d" constraint for the register pair.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260921084005.4022574-1-hca@linux.ibm.com?part=11

  reply	other threads:[~2026-09-21  8:52 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21  8:39 [PATCH v3 00/11] s390: More this_cpu_*() changes Heiko Carstens
2026-09-21  8:39 ` [PATCH v3 01/11] s390/percpu: Fix comment typo Heiko Carstens
2026-09-21  8:41   ` sashiko-bot
2026-09-21  8:39 ` [PATCH v3 02/11] s390/percpu: Add sanity check to GEN_MVIY macro Heiko Carstens
2026-09-21  8:44   ` sashiko-bot
2026-09-21  8:39 ` [PATCH v3 03/11] s390/lowcore: Remove _AC() from LOWCORE_ALT_ADDRESS Heiko Carstens
2026-09-21  8:45   ` sashiko-bot
2026-09-21  8:39 ` [PATCH v3 04/11] s390/percpu: Let MVIY_PERCPU() calculate alternative displacement Heiko Carstens
2026-09-21  8:45   ` sashiko-bot
2026-09-21  8:39 ` [PATCH v3 05/11] s390/percpu/lowcore: Add and use LC_PERCPU lowcore offset defines Heiko Carstens
2026-09-21  8:45   ` sashiko-bot
2026-09-21  8:40 ` [PATCH v3 06/11] s390/percpu: Rename inline assembly symbolic names Heiko Carstens
2026-09-21  8:44   ` sashiko-bot
2026-09-21  8:40 ` [PATCH v3 07/11] s390/percpu: Use __PCPU_BEGIN() and __PCPU_END() for inline assemblies Heiko Carstens
2026-09-21  8:45   ` sashiko-bot
2026-09-21  8:40 ` [PATCH v3 08/11] s390/percpu: Use percpu code section for this_cpu_cmpxchg128() Heiko Carstens
2026-09-21  8:46   ` sashiko-bot
2026-09-21  8:40 ` [PATCH v3 09/11] s390/percpu: Use percpu code section for this_cpu_xchg() Heiko Carstens
2026-09-21  8:45   ` sashiko-bot
2026-09-21  8:40 ` [PATCH v3 10/11] s390/percpu: Use percpu code section for this_cpu_cmpxchg() Heiko Carstens
2026-09-21  8:52   ` sashiko-bot
2026-09-21  8:40 ` [PATCH v3 11/11] s390/percpu: Rework to simplify percpu_entry() and percpu_exit() Heiko Carstens
2026-09-21  8:52   ` sashiko-bot [this message]
2026-09-21  9:55   ` David Laight
2026-09-21 10:07     ` Mark Rutland
2026-09-21 10:17       ` Heiko Carstens
2026-09-21  9:15 ` [PATCH v3 00/11] s390: More this_cpu_*() changes Heiko Carstens

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=20260921085253.5E0881F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-s390@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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