From: Ilya Leoshkevich <iii@linux.ibm.com>
To: Heiko Carstens <hca@linux.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org
Subject: Re: [PATCH 4/4] s390/maccess: Remove spinlock from __s390_kernel_write()
Date: Mon, 26 Oct 2026 14:04:02 +0100 [thread overview]
Message-ID: <b27e1bb4-9112-4df0-9595-90b5419acafa@linux.ibm.com> (raw)
In-Reply-To: <20261026120329.1792436-5-hca@linux.ibm.com>
On 10/26/26 13:03, Heiko Carstens wrote:
> The spinlock in __s390_kernel_write() was introduced to serialize the
> read-modify-write sequence against concurrent callers. Now that all
> relevant runtime callers of s390_kernel_write() hold the text_mutex, the
> spinlock is not required anymore.
Do we want to enforce this with __must_hold?
> Replace it with preempt_disable() / preempt_enable() and sync_core().
> Previously, CPU serialization was implicitly done by other
> instructions. Make this explicit with sync_core() instead of
> relying on that.
>
> Preemption is disabled so that sync_core() issues the CPU serialization
> instruction on the same CPU that executed the stores. This completes all
> previous stores and makes them visible to other CPUs.
>
> Other CPUs need to perform CPU serialization, e.g. with text_poke_sync(),
> to discard already prefetched instructions.
>
> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
> ---
> arch/s390/mm/maccess.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/arch/s390/mm/maccess.c b/arch/s390/mm/maccess.c
> index f39968dd8063..cda3f81dfbc2 100644
> --- a/arch/s390/mm/maccess.c
> +++ b/arch/s390/mm/maccess.c
> @@ -6,6 +6,7 @@
> *
> */
>
> +#include <linux/text-patching.h>
> #include <linux/uaccess.h>
> #include <linux/kernel.h>
> #include <linux/types.h>
> @@ -60,22 +61,20 @@ static notrace long s390_kernel_write_odd(void *dst, const void *src, size_t siz
> * bytes from destination at an eight byte boundary, modifies the bytes
> * requested and writes the result back in a loop.
> */
> -static DEFINE_SPINLOCK(s390_kernel_write_lock);
> -
> notrace void *__s390_kernel_write(void *dst, const void *src, size_t size)
> {
> void *tmp = dst;
> - unsigned long flags;
> long copied;
>
> - spin_lock_irqsave(&s390_kernel_write_lock, flags);
> + preempt_disable();
> while (size) {
> copied = s390_kernel_write_odd(tmp, src, size);
> tmp += copied;
> src += copied;
> size -= copied;
> }
> - spin_unlock_irqrestore(&s390_kernel_write_lock, flags);
> + sync_core();
> + preempt_enable();
>
> return dst;
> }
I've been looking at sync_core() and started thinking about the safety
of this interface w.r.t. CPUs concurrently executing the code being
patched, since locking protects only against concurrent readers and
writers, but not executors.
If there is only one active CPU, for example, during ftrace
initialization, then everything is fine.
If there are other active CPUs and we make modifications within a single
aligned u64, then sync_core() is required, because even though
text_poke_sync() nominally takes care of this, it may sync our core
last. However, I wonder, what would it take to make it always sync the
current core first?
Finally, and most importantly, if there are other active CPUs and we
patch multiple u64s, then we are broken, since the other CPUs may see
partial instructions. I'm not sure if it's worth bothering with, but
maybe consider adding a WARN_ONCE() to guard against this?
next prev parent reply other threads:[~2026-10-26 13:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 12:03 [PATCH 0/4] s390: Consistent usage of text_mutex Heiko Carstens
2026-10-26 12:03 ` [PATCH 1/4] s390/jump_label: Serialize text patching with text_mutex Heiko Carstens
2026-10-26 12:03 ` [PATCH 2/4] s390/ftrace: " Heiko Carstens
2026-10-26 12:03 ` [PATCH 3/4] s390/bpf: " Heiko Carstens
2026-10-26 12:03 ` [PATCH 4/4] s390/maccess: Remove spinlock from __s390_kernel_write() Heiko Carstens
2026-10-26 13:04 ` Ilya Leoshkevich [this message]
2026-10-26 14:19 ` Heiko Carstens
2026-10-27 10:09 ` kernel test robot
2026-10-27 10:09 ` kernel test robot
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=b27e1bb4-9112-4df0-9595-90b5419acafa@linux.ibm.com \
--to=iii@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=svens@linux.ibm.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®