From: Florian Bezdeka <florian.bezdeka@siemens.com>
To: "Tobias Schaffner" <tobias.schaffner@siemens.com>,
<xenomai@lists.linux.dev>
Cc: <rpm@xenomai.org>, <jan.kiszka@siemens.com>
Subject: Re: [PATCH dovetail v2 3/4] riscv: dovetail: inherit the hard irq state on kernel page faults
Date: Sun, 22 Nov 2026 23:18:49 +0100 [thread overview]
Message-ID: <DN2371TJAB7G.334DTWMEPJTQI@siemens.com> (raw)
In-Reply-To: <20261121165933.57310-4-tobias.schaffner@siemens.com>
On Sat Nov 21, 2026 at 5:59 PM CET, Tobias Schaffner wrote:
> A page fault may hit kernel code which runs with hard irqs off, e.g. a
> kprobe whose fetch argument faults within the breakpoint trap. The fault
> handler still enables hard irqs for every kernel mode fault, so an
> interrupt may break into that code. If the fault is handled out-of-band,
> the handler also unstalls the in-band stage over the out-of-band stage.
>
> Enable hard irqs in handle_page_fault() only if the faulting code had
> them on and we run in-band, and stall the in-band stage on exit only if
> we run in-band.
>
> Fixes: 1d1fdeccecef ("riscv: dovetail: add core support")
> Signed-off-by: Tobias Schaffner <tobias.schaffner@siemens.com>
> ---
> arch/riscv/kernel/traps.c | 11 ++++-------
> arch/riscv/mm/fault.c | 7 +++++--
> 2 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c
> index a8e37ec27cc2..47799f18fa7d 100644
> --- a/arch/riscv/kernel/traps.c
> +++ b/arch/riscv/kernel/traps.c
> @@ -488,17 +488,14 @@ asmlinkage __visible __trap_section void do_trap_software_check(struct pt_regs *
> asmlinkage __visible noinstr void do_page_fault(struct pt_regs *regs)
> {
> irqentry_state_t state = irqentry_enter(regs);
> + bool inband = mark_trap_entry(regs);
>
> - mark_trap_entry(regs);
> -
> - BUG_ON(dovetail_debug() && !running_inband());
> -
> - if (!user_mode(regs))
> - hard_cond_local_irq_enable();
> + BUG_ON(dovetail_debug() && !inband && user_mode(regs));
>
> handle_page_fault(regs, state);
>
> - local_irq_disable();
> + if (inband)
> + local_irq_disable();
>
> mark_trap_exit(regs);
>
> diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c
> index c5709112c346..f72b49d8f15a 100644
> --- a/arch/riscv/mm/fault.c
> +++ b/arch/riscv/mm/fault.c
> @@ -317,8 +317,11 @@ void handle_page_fault(struct pt_regs *regs, irqentry_state_t state)
>
> /* Enable interrupts if they were enabled in the parent context. */
> #ifdef CONFIG_IRQ_PIPELINE
> - if (state.stage_info != IRQENTRY_INBAND_STALLED)
> - local_irq_enable_full();
> + if (running_inband() && !regs_irqs_disabled(regs)) {
> + hard_local_irq_enable();
> + if (state.stage_info != IRQENTRY_INBAND_STALLED)
> + local_irq_enable();
> + }
Is that part aligned with any of the other architectures?
I'm asking because it seems that the pattern used here has an ordering
problem.
Once we enabled hard IRQs with hard_local_irq_enable() hardware events
might come in, hitting an stalled inband stage. Means we log all the
events into the IRQ log.
When we unstall the inband stage with local_irq_enable(), that will
bring us a full IRQ log synchronization - over page fault handling.
As local_irq_enable_full() does it the other way around as well, I
think that the ordering is wrong.
If taken / aligned from/with an other arch: we should check that as well.
> #else
> if (!regs_irqs_disabled(regs))
> local_irq_enable();
next prev parent reply other threads:[~2026-11-22 22:18 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 16:59 [PATCH dovetail v2 0/4] riscv: dovetail: trap handling fixes Tobias Schaffner
2026-11-21 16:59 ` [PATCH dovetail v2 1/4] riscv: dovetail: do not notify traps again from do_trap() Tobias Schaffner
2026-11-21 16:59 ` [PATCH dovetail v2 2/4] riscv: dovetail: run kernel trap handlers the core did not demote for Tobias Schaffner
2026-11-21 16:59 ` [PATCH dovetail v2 3/4] riscv: dovetail: inherit the hard irq state on kernel page faults Tobias Schaffner
2026-11-22 22:12 ` Florian Bezdeka
2026-11-22 22:18 ` Florian Bezdeka [this message]
2026-11-23 11:39 ` Tobias Schaffner
2026-11-23 12:05 ` Florian Bezdeka
2026-11-23 12:26 ` Bezdeka, Florian
2026-11-23 13:43 ` Tobias Schaffner
2026-11-23 22:12 ` Florian Bezdeka
2026-11-24 19:53 ` Tobias Schaffner
2026-11-25 11:13 ` Florian Bezdeka
2026-11-27 12:25 ` Tobias Schaffner
2026-11-21 16:59 ` [PATCH dovetail v2 4/4] riscv: dovetail: read the CFI trap value from the saved registers Tobias Schaffner
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=DN2371TJAB7G.334DTWMEPJTQI@siemens.com \
--to=florian.bezdeka@siemens.com \
--cc=jan.kiszka@siemens.com \
--cc=rpm@xenomai.org \
--cc=tobias.schaffner@siemens.com \
--cc=xenomai@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.