x86: dovetail: preserve in-band stall state across handle_bug()
PATCH 1/1 x86: dovetail: preserve in-band stall state across handle_bug()
From: Jan Kiszka <[email protected]>
handle_bug() runs from the raw #UD entry, before irqentry_enter(), and returns straight to the exception site when a WARN() was handled. The trap only cleared the hardware interrupt flag, the in-band stall bit still reflects the state of the exception site.
When the site ran with hard irqs on, handle_bug() used local_irq_enable_full() and local_irq_disable_full() for the in-band stage, which also unstall then stall the in-band stage. As a result:
- a WARN() hit with in-band interrupts enabled returned with the in-band stage stalled, leaking a virtually disabled interrupt state into the interrupted code, until the next in-band irq enable.
- a WARN() hit with in-band interrupts disabled (e.g. under spin_lock_irqsave()) unstalled the in-band stage while reporting.
Only restore the hard interrupt state, like upstream does with the (then non-virtualized) interrupt flag, on both stages.
---
Taken from the root-cause analysis of
https://gitlab.com/Xenomai/xenomai-images/-/jobs/18096537042, forward- ported to 7.3. I asked the LLM why inband stalling was added, but it found "no reason". I asked if something in between the inband unstall and restall could expect finding inband unstalled, and it found nothing. Should be safe (TM).
arch/x86/kernel/traps.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
arch/x86/kernel/traps.c +4 -12
@@ -476,12 +476,8 @@ noinstr bool handle_bug(struct pt_regs *regs)* Since we're emulating a CALL with exceptions, restore the interrupt * state to what it was at the exception site. */ -if (regs->flags &X86_EFLAGS_IF ) { -if (running_oob ()) -hard_local_irq_enable (); -else -local_irq_enable_full (); - } +if (regs->flags &X86_EFLAGS_IF ) +hard_local_irq_enable ();switch (ud_type) {case BUG_UD1_WARN :
@@ -528,12 +524,8 @@ noinstr bool handle_bug(struct pt_regs *regs) regs->ip = addr; } -if (regs->flags &X86_EFLAGS_IF ) { -if (running_oob ()) -hard_local_irq_disable (); -else -local_irq_disable_full (); - } +if (regs->flags &X86_EFLAGS_IF ) +hard_local_irq_disable ();instrumentation_end ();return handled;
Signature · 1 line
2.47.3
Philippe Gerum
AppliedQuoted 58 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
handle_bug()runs from the raw #UD entry, beforeirqentry_enter(), and returns straight to the exception site when aWARN()was handled. The trap only cleared the hardware interrupt flag, the in-band stall bit still reflects the state of the exception site.When the site ran with hard irqs on,
handle_bug()usedlocal_irq_enable_full()andlocal_irq_disable_full()for the in-band stage, which also unstall then stall the in-band stage. As a result:- a
WARN()hit with in-band interrupts enabled returned with the in-band stage stalled, leaking a virtually disabled interrupt state into the interrupted code, until the next in-band irq enable.
- aWARN()hit with in-band interrupts disabled (e.g. underspin_lock_irqsave()) unstalled the in-band stage while reporting.Only restore the hard interrupt state, like upstream does with the (then non-virtualized) interrupt flag, on both stages.
Assisted-by opencode:Opus-5.5Signed-off-by Jan Kiszka <[email protected]>---
Taken from the root-cause analysis of
https://gitlab.com/Xenomai/xenomai-images/-/jobs/18096537042, forward- ported to 7.3. I asked the LLM why inband stalling was added, but it found "no reason". I asked if something in between the inband unstall and restall could expect finding inband unstalled, and it found nothing. Should be safe (TM).arch/x86/kernel/traps.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)arch/x86/kernel/traps.c +2
-7@@ -476,12 +476,8 @@ noinstr bool handle_bug(struct pt_regs *regs)* Since we're emulating a CALL with exceptions, restore the interrupt * state to what it was at the exception site. */ -if (regs->flags &X86_EFLAGS_IF ) { -if (running_oob ()) -hard_local_irq_enable (); -else -local_irq_enable_full (); - } +if (regs->flags &X86_EFLAGS_IF ) +hard_local_irq_enable ();switch (ud_type) {case BUG_UD1_WARN :@@ -528,12 +524,8 @@ noinstr bool handle_bug(struct pt_regs *regs) regs->ip = addr; } -if (regs->flags &X86_EFLAGS_IF ) {
arch/x86/kernel/traps.c noinstr bool handle_bug(struct pt_regs *regs) · line 531
Quoted 10 lines
arch/x86/kernel/traps.c +2
-5-if (running_oob ()) -hard_local_irq_disable (); -else -local_irq_disable_full (); - } +if (regs->flags &X86_EFLAGS_IF ) +hard_local_irq_disable ();instrumentation_end ();return handled;
Merged, thanks.
Signature · 1 line
Philippe.
Quoted 19 lines · Philippe Gerum
Quoted 17 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
handle_bug()runs from the raw #UD entry, beforeirqentry_enter(), and returns straight to the exception site when aWARN()was handled. The trap only cleared the hardware interrupt flag, the in-band stall bit still reflects the state of the exception site.When the site ran with hard irqs on,
handle_bug()usedlocal_irq_enable_full()andlocal_irq_disable_full()for the in-band stage, which also unstall then stall the in-band stage. As a result:- a
WARN()hit with in-band interrupts enabled returned with the in-band stage stalled, leaking a virtually disabled interrupt state into the interrupted code, until the next in-band irq enable.
- aWARN()hit with in-band interrupts disabled (e.g. underspin_lock_irqsave()) unstalled the in-band stage while reporting.
Quoted 5 lines
Quoted 5 lines
Only restore the hard interrupt state, like upstream does with the (then non-virtualized) interrupt flag, on both stages.
Assisted-by opencode:Opus-5.5Signed-off-by Jan Kiszka <[email protected]>
To simplify the next forward port and the usual history cleanup:
Could you please add / provide the Fixes: tags for all the patches recently merged? Thanks!
Quoted 6 lines
Merged, thanks.
Signature · 1 line
Philippe.
Quoted 23 lines · Florian Bezdeka
Quoted 22 lines · Philippe Gerum
Quoted 20 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
handle_bug()runs from the raw #UD entry, beforeirqentry_enter(), and returns straight to the exception site when aWARN()was handled. The trap only cleared the hardware interrupt flag, the in-band stall bit still reflects the state of the exception site.When the site ran with hard irqs on,
handle_bug()usedlocal_irq_enable_full()andlocal_irq_disable_full()for the in-band stage, which also unstall then stall the in-band stage. As a result:- a
WARN()hit with in-band interrupts enabled returned with the in-band stage stalled, leaking a virtually disabled interrupt state into the interrupted code, until the next in-band irq enable.
- aWARN()hit with in-band interrupts disabled (e.g. underspin_lock_irqsave()) unstalled the in-band stage while reporting.Only restore the hard interrupt state, like upstream does with the (then non-virtualized) interrupt flag, on both stages.
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
Assisted-by opencode:Opus-5.5Signed-off-by Jan Kiszka <[email protected]>To simplify the next forward port and the usual history cleanup:
Could you please add / provide the Fixes: tags for all the patches recently merged? Thanks!
Those are not overly important, specifically over time as rebasing are invalidating their commit IDs. AI is also good in identifying missed backports (found several for 6.18 or 6.12).
Jan
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center
Quoted 29 lines · Jan Kiszka
Quoted 28 lines · Florian Bezdeka
Quoted 19 lines · Philippe Gerum
Quoted 17 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
handle_bug()runs from the raw #UD entry, beforeirqentry_enter(), and returns straight to the exception site when aWARN()was handled. The trap only cleared the hardware interrupt flag, the in-band stall bit still reflects the state of the exception site.When the site ran with hard irqs on,
handle_bug()usedlocal_irq_enable_full()andlocal_irq_disable_full()for the in-band stage, which also unstall then stall the in-band stage. As a result:- a
WARN()hit with in-band interrupts enabled returned with the in-band stage stalled, leaking a virtually disabled interrupt state into the interrupted code, until the next in-band irq enable.
- aWARN()hit with in-band interrupts disabled (e.g. underspin_lock_irqsave()) unstalled the in-band stage while reporting.Quoted 5 lines
Quoted 5 lines
Only restore the hard interrupt state, like upstream does with the (then non-virtualized) interrupt flag, on both stages.
Assisted-by opencode:Opus-5.5Signed-off-by Jan Kiszka <[email protected]>To simplify the next forward port and the usual history cleanup:
Quoted 7 lines
Quoted 3 lines
Could you please add / provide the Fixes: tags for all the patches recently merged? Thanks!
Those are not overly important, specifically over time as rebasing are invalidating their commit IDs. AI is also good in identifying missed backports (found several for 6.18 or 6.12).
Please add them. It helps. IDs normally stay stable - at least for non LTS releases.
Please, don't make AI required.
Quoted 6 lines
Jan
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center