Linux s390 Architecture development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Heiko Carstens" <hca@linux.ibm.com>
Cc: "Vasily Gorbik" <gor@linux.ibm.com>,
	linux-s390@vger.kernel.org,
	"Christian Borntraeger" <borntraeger@linux.ibm.vom>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>
Subject: Re: [PATCH 8/9] s390/percpu: Provide arch_this_cpu_write() implementation
Date: Thu, 13 Aug 2026 21:53:09 +0000	[thread overview]
Message-ID: <20260813215309.9AEEE1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260317195436.2276810-9-hca@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Critical logic inversion in `percpu_exit()` migration fixup corrupts percpu pointers.
- [Low] Unused output constraint `[old__]` in `arch_this_cpu_write` inline assembly.
--

--- Patch [8]: [PATCH 8/9] s390/percpu: Provide arch_this_cpu_write() implementation ---
commit 2a32543383d043fdfafc28f075daae72847d527d
Author: Heiko Carstens <hca@linux.ibm.com>
s390/percpu: Provide arch_this_cpu_write() implementation

This commit provides an s390 specific implementation of
arch_this_cpu_write() instead of using the generic variant. It aims to
reduce the overhead of raw_local_irq_save/restore pairs and reduces the
text size of the kernel image.

> diff --git a/arch/s390/include/asm/percpu.h b/arch/s390/include/asm/percpu.h
> index 35e48d193d993..7a411b75bfa62 100644
> --- a/arch/s390/include/asm/percpu.h
> +++ b/arch/s390/include/asm/percpu.h
[ ... ]
> @@ -271,6 +271,38 @@
>  #define this_cpu_read_4(pcp) arch_this_cpu_read(pcp, "l")
>  #define this_cpu_read_8(pcp) arch_this_cpu_read(pcp, "lg")
>  
> +#define arch_this_cpu_write(pcp, val, op)				\
> +{									\
> +	unsigned long lc_pcpr, lc_pcpo;					\
> +	typedef typeof(pcp) pcp_op_T__;					\
> +	pcp_op_T__ val__ = (val);					\
> +	pcp_op_T__ old__, *ptr__;					\
> +									\
> +	lc_pcpr = offsetof(struct lowcore, percpu_register);		\
> +	lc_pcpo = offsetof(struct lowcore, percpu_offset);		\
> +	ptr__ = &(pcp);							\
> +	asm_inline volatile(						\
> +		MVIY_PERCPU("%[disppcpr]", "%[dispaltpcpr]", "%[ptr__]")\
> +		AG_ALT("%[disppcpo]", "%[dispaltpcpo]", "%[ptr__]")	\
> +		op "    %[val__],0(%[ptr__])\n"				\
> +		MVIY_ALT("%[disppcpr]", "%[dispaltpcpr]", "%%r0")	\
> +		: [old__] "=&d" (old__),				\

[Severity: Low]
Does this output constraint unnecessarily tie up a general-purpose register?
The compiler is forced to allocate a register for old__, but the inline
assembly string never references %[old__].

> +		  [ptr__] "+&a" (ptr__), "=m" (*ptr__),			\
> +		  "=m" (((struct lowcore *)0)->percpu_register)		\
> +		: [val__] "d" (val__),					\
[ ... ]

Looking at how these new percpu sections interact with migration fixups in
arch/s390/include/asm/entry-percpu.h, there might be a regression with the
instruction check:

arch/s390/include/asm/entry-percpu.h:percpu_exit() {
	...
	/*
	 * Within a percpu code section and process has been migrated to
	 * a different CPU. Check if the percpu base register needs to be
	 * updated. This is the case if the PSW does not point to the ADD
	 * instruction within the section
	 * - AG %rx,percpu_offset_in_lowcore(%r0,%r0)
	 * which adds the percpu offset to the percpu base register.
	 */
	if ((*(u16 *)psw_bits(regs->psw).ia & 0xff0f) != 0xe300)
		return;
	...
}

[Severity: Critical]
Is the condition in this check inverted? The fixup skips updating the offset
if the instruction is not the AG instruction (0xe300).

If a task executing the new arch_this_cpu_write() is interrupted and migrated
to another CPU, it seems the correct logic would be to return if the
instruction is the AG instruction (meaning it hasn't executed yet and no
fixup is needed), and proceed with the fixup if it is not the AG instruction
(meaning the AG instruction has already executed and the offset needs
updating).

Could this inverted logic result in skipping the fixup when interrupted after
the AG instruction, or applying it incorrectly when interrupted before the AG
instruction, leading to corrupted pointers or updates to the wrong CPU's
percpu variable?

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

  reply	other threads:[~2026-08-13 21:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-17 19:54 [PATCH 0/9] s390: Improve this_cpu operations Heiko Carstens
2026-03-17 19:54 ` [PATCH 1/9] s390/percpu: Provide arch_raw_cpu_ptr() Heiko Carstens
2026-03-17 19:54 ` [PATCH 2/9] s390/alternatives: Add new ALT_TYPE_PERCPU type Heiko Carstens
2026-03-17 19:54 ` [PATCH 3/9] s390/percpu: Infrastructure for more efficient this_cpu operations Heiko Carstens
2026-03-17 19:54 ` [PATCH 4/9] s390/percpu: Use new percpu code section for arch_this_cpu_add() Heiko Carstens
2026-03-17 19:54 ` [PATCH 5/9] s390/percpu: Use new percpu code section for arch_this_cpu_add_return() Heiko Carstens
2026-03-17 19:54 ` [PATCH 6/9] s390/percpu: Use new percpu code section for arch_this_cpu_[and|or]() Heiko Carstens
2026-03-17 19:54 ` [PATCH 7/9] s390/percpu: Provide arch_this_cpu_read() implementation Heiko Carstens
2026-03-17 19:54 ` [PATCH 8/9] s390/percpu: Provide arch_this_cpu_write() implementation Heiko Carstens
2026-08-13 21:53   ` sashiko-bot [this message]
2026-03-17 19:54 ` [PATCH 9/9] s390/percpu: Remove one and two byte this_cpu operation implementation Heiko Carstens
2026-08-13 22:01   ` sashiko-bot
2026-03-17 21:08 ` [PATCH 0/9] s390: Improve this_cpu operations Peter Zijlstra
2026-03-23 10:26 ` Juergen Christ

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=20260813215309.9AEEE1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.vom \
    --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