x86: dovetail: Fix inband IRQ state corruption on out-of-band compat syscall
Subsystems (3)
PATCH v2 1/1 x86: dovetail: Fix inband IRQ state corruption on out-of-band compat syscall
The following kernel splat was found when running the Xenomai 3 testsuite in compat on dovetail enabled kernels:
[ 513.620975] IRQ pipeline: some code running in oob context 'Xenomai'
called an in-band only routine
[ 513.620998] CPU: 0 PID: 510 Comm: smokey Not tainted 6.10.0+ #76
[ 513.621003] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
[ 513.621005] IRQ stage: Xenomai
[ 513.621007] Call Trace:
[ 513.621011] <TASK>
[ 513.621015] dump_stack_lvl+0x6f/0xd0
[ 513.621202] __inband_irq_enable+0xb/0x60
[ 513.621249] do_int80_emulation+0x68/0x160
[ 513.621265] asm_int80_emulation+0x1a/0x20
[ 513.621285] RIP: 0023:0xf7f692ba
[ 513.621288] Code: Unable to access opcode bytes at 0xf7f69290.
[ 513.621303] RSP: 002b:00000000ffeedf40 EFLAGS: 00000282 ORIG_RAX: 0000000000000127
[ 513.621307] RAX: ffffffffffffffda RBX: 00000000ffffff9c RCX: 00000000ffeedfa0
[ 513.621309] RDX: 0000000000088000 RSI: 0000000000000000 RDI: 00000000f7f7aff4
[ 513.621311] RBP: 00000000ffeedf88 R08: 0000000000000000 R09: 0000000000000000
[ 513.621313] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
[ 513.621315] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
[ 513.621319] </TASK>When entering the low level entry code from the out-of-band stage the in-band IRQ state was changed. That is now avoided by calling syscall_enter_from_user_enable_irqs() as all other entry points do.
---
Once again, sorry for breaking the 6.1 and 6.6 builds. I had two local branches named v6.{1,6} which actually contained 6.10...
I decided to move syscall_enter_from_user_enable_irqs() into the same location as it is for 6.10/6.11. This way we can keep the __always_inline flag and avoid an additional function call in the low level entry code.
Florian
arch/x86/entry/common.c | 2 +- include/linux/entry-common.h | 23 +++++++++++++++++++++++ kernel/entry/common.c | 24 ------------------------ 3 files changed, 24 insertions(+), 25 deletions(-)
arch/x86/entry/common.c +1 -1
@@ -210,7 +210,7 @@ __visible noinstr void do_int80_emulation(struct pt_regs *regs) nr =syscall_32_enter (regs); -local_irq_enable_full (); +syscall_enter_from_user_enable_irqs (); nr =syscall_enter_from_user_mode_work (regs, nr);if (dovetailing ()) {
include/linux/entry-common.h +23 -0
@@ -150,6 +150,29 @@ void syscall_enter_from_user_mode_prepare(struct pt_regs *regs);*/ long syscall_enter_from_user_mode_work (struct pt_regs *regs,long syscall); +static __always_inline void syscall_enter_from_user_enable_irqs(void) +{ +if (running_inband ()) { +/* +* If pipelining interrupts, prepare for emulating a +* stall -> unstall transition (we are currently +* unstalled), fixing up the IRQ trace state in order +* to keep lockdep happy (and silent). +*/ +stall_inband_nocheck (); +hard_cond_local_irq_enable (); +local_irq_enable (); + }else { +/* +* We are running on the out-of-band stage, don't mess +* with the in-band interrupt state. This is none of +* our business. We may manipulate the hardware state +* only. +*/ +hard_local_irq_enable (); + } +} +/** * syscall_enter_from_user_mode - Establish state and check and handle work * before invoking a syscall
kernel/entry/common.c +0 -24
@@ -92,30 +92,6 @@ static long syscall_trace_enter(struct pt_regs *regs, long syscall,return ret ? : syscall; } -static __always_inline void -syscall_enter_from_user_enable_irqs (void ) -{ -if (running_inband ()) { -/* -* If pipelining interrupts, prepare for emulating a -* stall -> unstall transition (we are currently -* unstalled), fixing up the IRQ trace state in order -* to keep lockdep happy (and silent). -*/ -stall_inband_nocheck (); -hard_cond_local_irq_enable (); -local_irq_enable (); - }else { -/* -* We are running on the out-of-band stage, don't mess -* with the in-band interrupt state. This is none of -* our business. We may manipulate the hardware state -* only. -*/ -hard_local_irq_enable (); - } -} -static __always_inline long __syscall_enter_from_user_work (struct pt_regs *regs,long syscall) {
Signature · 1 line
2.39.5
Quoted 31 lines · Florian Bezdeka
The following kernel splat was found when running the Xenomai 3 testsuite in compat on dovetail enabled kernels:
[ 513.620975] IRQ pipeline: some code running in oob context 'Xenomai' called an in-band only routine [ 513.620998] CPU: 0 PID: 510 Comm: smokey Not tainted 6.10.0+ #76 [ 513.621003] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 [ 513.621005] IRQ stage: Xenomai [ 513.621007] Call Trace: [ 513.621011] <TASK> [ 513.621015] dump_stack_lvl+0x6f/0xd0 [ 513.621202] __inband_irq_enable+0xb/0x60 [ 513.621249] do_int80_emulation+0x68/0x160 [ 513.621265] asm_int80_emulation+0x1a/0x20 [ 513.621285] RIP: 0023:0xf7f692ba [ 513.621288] Code: Unable to access opcode bytes at 0xf7f69290. [ 513.621303] RSP: 002b:00000000ffeedf40 EFLAGS: 00000282 ORIG_RAX: 0000000000000127 [ 513.621307] RAX: ffffffffffffffda RBX: 00000000ffffff9c RCX: 00000000ffeedfa0 [ 513.621309] RDX: 0000000000088000 RSI: 0000000000000000 RDI: 00000000f7f7aff4 [ 513.621311] RBP: 00000000ffeedf88 R08: 0000000000000000 R09: 0000000000000000 [ 513.621313] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 [ 513.621315] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 [ 513.621319] </TASK>When entering the low level entry code from the out-of-band stage the in-band IRQ state was changed. That is now avoided by calling
syscall_enter_from_user_enable_irqs()as all other entry points do.Signed-off-by Florian Bezdeka <[email protected]>---
Quoted 8 lines
Once again, sorry for breaking the 6.1 and 6.6 builds. I had two local branches named v6.{1,6} which actually contained 6.10...
I decided to move
syscall_enter_from_user_enable_irqs()into the same location as it is for 6.10/6.11. This way we can keep the__always_inlineflag and avoid an additional function call in the low level entry code.
Ok, works for me as well. Re-merged into all affected -rebase branches. Thanks.
Signature · 1 line
Philippe.