Re: [PATCH] x86: dovetail: Call trap exit code with hard IRQs disabled

Florian Bezdeka <[email protected]> Mon, 15 Jun 2026 11:56:54 +0200
Newsgroups dev.linux.lists.xenomai
Message-ID <[email protected]>
On Sat, 2026-06-13 at 19:43 +0200, Philippe Gerum wrote:
> Philippe Gerum <[email protected]> writes:
> 
> > Florian Bezdeka <[email protected]> writes:
> > 
> > > mark_trap_exit() should do the reverse operations of mark_trap_entry()
> > > keeping ordering in mind. Especially as oob_trap_unwind() is expecting
> > > hard IRQs to be off.
> > > 
> > 
> > oob_trap_unwind() does not require irqs to be disabled,
> > __oob_trap_unwind() already takes care of this. However, we do want
> > oob_trap_unwind() to return with irqs off unconditionally because
> > handle_oob_trap_exit() might not ensure this. So the original ordering
> > is right.
> 
> A better fix may be to disable hard irqs right before leaving
> __oob_trap_unwind(), instead of expecting handle_oob_trap_exit() - which
> is user-provided - to do so. This would make things clearer, and the
> conditional disabling in mark_trap_exit() pointless.

But wouldn't that unpair the irq enable/disable calls in the exit
handler? (evl only, cobalt has no implementation)

I clearly overlooked the hard_local_irq_disable() call in
__oob_trap_unwind().

Now looking at that again I think that the hard_cond_local_irq_disable()
call (that I moved) in mark_trap_exit() is a unnecessary for oob tasks.
The trap exit handler should have done the right thing already. That
would synchronize mark_trap_{entry,exit} on x86.

diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 6b5b33b4d511..8230b785664a 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -355,7 +355,9 @@ static __always_inline
 void mark_trap_exit(int trapnr, struct pt_regs *regs)
 {
        oob_trap_unwind(trapnr, regs);
-       hard_cond_local_irq_disable();
+
+       if (likely(running_inband()))
+               hard_cond_local_irq_disable();
 }