All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Heiko Carstens" <hca@linux.ibm.com>
Cc: linux-s390@vger.kernel.org, "Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [PATCH 4/4] s390/maccess: Remove spinlock from __s390_kernel_write()
Date: Mon, 26 Oct 2026 12:40:06 +0000	[thread overview]
Message-ID: <sashiko-outbox-185225@kernel.org> (raw)
In-Reply-To: <20261026120329.1792436-5-hca@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] s390/maccess: RMW race in __s390_kernel_write() via apply_relocate_add()
--

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

s390/maccess: Remove spinlock from __s390_kernel_write()

This commit removes s390_kernel_write_lock from __s390_kernel_write() under
the assumption that all runtime callers hold text_mutex, and replaces the
spinlock with preempt_disable(), sync_core(), and preempt_enable().

> diff --git a/arch/s390/mm/maccess.c b/arch/s390/mm/maccess.c
> index f39968dd80638..cda3f81dfbc2f 100644
> --- a/arch/s390/mm/maccess.c
> +++ b/arch/s390/mm/maccess.c
[ ... ]
> @@ -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();

[Severity: High]
Can removing s390_kernel_write_lock cause a read-modify-write race in
s390_kernel_write_odd() when apply_relocate_add() is called by livepatching?

In arch/s390/kernel/module.c:apply_relocate_add(), s390_kernel_write() is
used whenever the module is already formed, without taking text_mutex:

    int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
                           unsigned int symindex, unsigned int relsec,
                           struct module *me)
    {
        bool early = me->state == MODULE_STATE_UNFORMED;
        void *(*write)(void *, const void *, size_t) = memcpy;

        if (!early)
            write = s390_kernel_write;

        return __apply_relocate_add(sechdrs, strtab, symindex, relsec, me,
                                    write);
    }

At runtime, livepatching reaches this path via:

    klp_enable_patch() / klp_module_coming()
      -> klp_init_object_loaded()
        -> klp_apply_object_relocs()
          -> klp_write_object_relocs()
            -> klp_write_section_relocs()
              -> apply_relocate_add()

Commit 5b384f933590 ("x86/module: Use text_mutex in apply_relocate_add()")
removed mutex_lock(&text_mutex) from klp_init_object_loaded() in
kernel/livepatch/core.c and added text_mutex only to x86, relying on
s390_kernel_write_lock to serialize s390's apply_relocate_add().

Because s390_kernel_write_odd() performs a non-atomic 8-byte
read-modify-write cycle on (dst & ~7UL) using mvc, ex, and sturg, could a
concurrent caller holding text_mutex (such as ftrace, jump_label, kprobes, or
bpf_arch_text_poke) modifying an instruction in the same 8-byte doubleword of
the livepatch module have its write clobbered?

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

  reply	other threads:[~2026-10-26 12:40 UTC|newest]

Thread overview: 13+ 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:16   ` sashiko-bot
2026-10-26 12:03 ` [PATCH 2/4] s390/ftrace: " Heiko Carstens
2026-10-26 12:24   ` sashiko-bot
2026-10-26 12:03 ` [PATCH 3/4] s390/bpf: " Heiko Carstens
2026-10-26 12:28   ` sashiko-bot
2026-10-26 12:03 ` [PATCH 4/4] s390/maccess: Remove spinlock from __s390_kernel_write() Heiko Carstens
2026-10-26 12:40   ` sashiko-bot [this message]
2026-10-26 13:04   ` Ilya Leoshkevich
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=sashiko-outbox-185225@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.