From: Andrew Donnellan <ajd@linux.ibm.com>
To: Christophe Leroy <christophe.leroy@csgroup.eu>,
"Ritesh Harjani (IBM)" <riteshh@linux.ibm.com>,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
maddy@linux.ibm.com, mpe@ellerman.id.au, peterz@infradead.org,
jpoimboe@kernel.org, jbaron@akamai.com
Cc: npiggin@gmail.com, rostedt@goodmis.org, ardb@kernel.org,
Erhard Furtner <erhard_f@mailbox.org>
Subject: Re: [PATCH RFC] powerpc: Panic on jump label code patching failure
Date: Mon, 08 Sep 2025 11:45:52 +1000 [thread overview]
Message-ID: <c8c5778822344161acec7101fa9f19726ca99d31.camel@linux.ibm.com> (raw)
In-Reply-To: <1b4cc6d5-5f5b-4b39-8fdf-ac02c94cd5e2@csgroup.eu>
On Sat, 2025-09-06 at 08:42 +0200, Christophe Leroy wrote:
> > arch_jump_label_transform() is mainly getting called from
> > __jump_level_update() and it's used for enabling or updating static keys /
> > branch.
> >
> > But static keys can also be used by drivers / module subsystem whose
> > initialization happens late. Although I understand that if the above
> > fails, it might fail much before, from the arch setup code itself, but
> > panic() still feels like a big hammer.
>
> But not being able to patch the kernel as required means that you get a
> kernel behaving differently from what is expected.
>
> Imagine a kernel running on a board that is controlling a saw. There is
> a patch_instruction() to activate the safety feature which detects when
> your hands are too close to the blade. Do you want the kernel to
> continue running seamlessly when that patch_instruction() fails ? I'm
> sure you don't !
This is my thinking exactly - a failed patch leaves the kernel in an abnormal
state, and we don't have the infrastructure to safely roll back any patches that
have already succeeded or other associated state changes, so this should be
treated as an unrecoverable error. The resulting kernel is a different kernel
from the one you expect to have.
The fact that drivers/modules can trigger this just means that drivers/modules
can permanently ruin your kernel too, which makes this more important not less,
I think?
>
> >
> > Would pr_err() print with WARN_ON_ONCE(1) would suffice in case of an
> > err?
>
> No, that's not enough, you can't rely on a kernel that will no behave as
> expected.
>
> >
> > Also you said you ran into a problem at just one call site where above
> > was silently failing. With the above change are you able to hit the
> > panic() now? Because from what I see in patch_instruction(), it mainly
> > will boil down to calling __patch_mem() which always returns 0.
>
> As far as I can see, __patch_mem() returns -EPERM when
> __put_kernel_nofault() fails:
>
> static int __patch_mem(void *exec_addr, unsigned long val, void
> *patch_addr, bool is_dword)
> {
> if (!IS_ENABLED(CONFIG_PPC64) || likely(!is_dword)) {
> /* For big endian correctness: plain address would use the
> wrong half */
> u32 val32 = val;
>
> __put_kernel_nofault(patch_addr, &val32, u32, failed);
> } else {
> __put_kernel_nofault(patch_addr, &val, u64, failed);
> }
>
> asm ("dcbst 0, %0; sync; icbi 0,%1; sync; isync" :: "r" (patch_addr),
> "r" (exec_addr));
>
> return 0;
>
> failed:
> mb(); /* sync */
> return -EPERM;
> }
Yes, I can confirm that -EPERM from __patch_mem() is what I was seeing, and I
experimented with the assembly to confirm that it was triggered by the stw in
__put_kernel_nofault(). __put_kernel_nofault() uses the address of the failed:
label to create a handler in the exception table for when the store instruction
faults.
>
>
> > Although there are other places where there can be an error returned,
> > so I was wondering if that is what you were hitting or something else?
>
> Andrew was hitting the -EPERM because the memory area was read-only.
>
> Christophe
--
Andrew Donnellan OzLabs, ADL Canberra
ajd@linux.ibm.com IBM Australia Limited
next prev parent reply other threads:[~2025-09-08 1:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-05 6:11 [PATCH RFC] powerpc: Panic on jump label code patching failure Andrew Donnellan
2025-09-05 6:34 ` Christophe Leroy
2025-09-06 3:52 ` Ritesh Harjani
2025-09-06 6:42 ` Christophe Leroy
2025-09-08 1:45 ` Andrew Donnellan [this message]
2025-09-09 3:19 ` Ritesh Harjani
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=c8c5778822344161acec7101fa9f19726ca99d31.camel@linux.ibm.com \
--to=ajd@linux.ibm.com \
--cc=ardb@kernel.org \
--cc=christophe.leroy@csgroup.eu \
--cc=erhard_f@mailbox.org \
--cc=jbaron@akamai.com \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
--cc=peterz@infradead.org \
--cc=riteshh@linux.ibm.com \
--cc=rostedt@goodmis.org \
/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