Skip to content

Commit 0b88147

Browse files
jan-kiszkagregkh
authored andcommitted
Drivers: hv: vmbus: Use kthread for vmbus interrupts on PREEMPT_RT
commit f8e6343 upstream. Resolves the following lockdep report when booting PREEMPT_RT on Hyper-V with related guest support enabled: [ 1.127941] hv_vmbus: registering driver hyperv_drm [ 1.132518] ============================= [ 1.132519] [ BUG: Invalid wait context ] [ 1.132521] 6.19.0-rc8+ #9 Not tainted [ 1.132524] ----------------------------- [ 1.132525] swapper/0/0 is trying to lock: [ 1.132526] ffff8b9381bb3c90 (&channel->sched_lock){....}-{3:3}, at: vmbus_chan_sched+0xc4/0x2b0 [ 1.132543] other info that might help us debug this: [ 1.132544] context-{2:2} [ 1.132545] 1 lock held by swapper/0/0: [ 1.132547] #0: ffffffffa010c4c0 (rcu_read_lock){....}-{1:3}, at: vmbus_chan_sched+0x31/0x2b0 [ 1.132557] stack backtrace: [ 1.132560] CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Not tainted 6.19.0-rc8+ #9 PREEMPT_{RT,(lazy)} [ 1.132565] Hardware name: Microsoft Corporation Virtual Machine/Virtual Machine, BIOS Hyper-V UEFI Release v4.1 09/25/2025 [ 1.132567] Call Trace: [ 1.132570] <IRQ> [ 1.132573] dump_stack_lvl+0x6e/0xa0 [ 1.132581] __lock_acquire+0xee0/0x21b0 [ 1.132592] lock_acquire+0xd5/0x2d0 [ 1.132598] ? vmbus_chan_sched+0xc4/0x2b0 [ 1.132606] ? lock_acquire+0xd5/0x2d0 [ 1.132613] ? vmbus_chan_sched+0x31/0x2b0 [ 1.132619] rt_spin_lock+0x3f/0x1f0 [ 1.132623] ? vmbus_chan_sched+0xc4/0x2b0 [ 1.132629] ? vmbus_chan_sched+0x31/0x2b0 [ 1.132634] vmbus_chan_sched+0xc4/0x2b0 [ 1.132641] vmbus_isr+0x2c/0x150 [ 1.132648] __sysvec_hyperv_callback+0x5f/0xa0 [ 1.132654] sysvec_hyperv_callback+0x88/0xb0 [ 1.132658] </IRQ> [ 1.132659] <TASK> [ 1.132660] asm_sysvec_hyperv_callback+0x1a/0x20 As code paths that handle vmbus IRQs use sleepy locks under PREEMPT_RT, the vmbus_isr execution needs to be moved into thread context. Open- coding this allows to skip the IPI that irq_work would additionally bring and which we do not need, being an IRQ, never an NMI. This affects both x86 and arm64, therefore hook into the common driver logic. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Reviewed-by: Florian Bezdeka <florian.bezdeka@siemens.com> Tested-by: Florian Bezdeka <florian.bezdeka@siemens.com> Reviewed-by: Michael Kelley <mhklinux@outlook.com> Tested-by: Michael Kelley <mhklinux@outlook.com> Signed-off-by: Wei Liu <wei.liu@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 235d702 commit 0b88147

1 file changed

Lines changed: 65 additions & 1 deletion

File tree

drivers/hv/vmbus_drv.c

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/cpu.h>
2626
#include <linux/sched/isolation.h>
2727
#include <linux/sched/task_stack.h>
28+
#include <linux/smpboot.h>
2829

2930
#include <linux/delay.h>
3031
#include <linux/panic_notifier.h>
@@ -1350,7 +1351,7 @@ static void vmbus_message_sched(struct hv_per_cpu_context *hv_cpu, void *message
13501351
}
13511352
}
13521353

1353-
void vmbus_isr(void)
1354+
static void __vmbus_isr(void)
13541355
{
13551356
struct hv_per_cpu_context *hv_cpu
13561357
= this_cpu_ptr(hv_context.cpu_context);
@@ -1363,6 +1364,53 @@ void vmbus_isr(void)
13631364

13641365
add_interrupt_randomness(vmbus_interrupt);
13651366
}
1367+
1368+
static DEFINE_PER_CPU(bool, vmbus_irq_pending);
1369+
static DEFINE_PER_CPU(struct task_struct *, vmbus_irqd);
1370+
1371+
static void vmbus_irqd_wake(void)
1372+
{
1373+
struct task_struct *tsk = __this_cpu_read(vmbus_irqd);
1374+
1375+
__this_cpu_write(vmbus_irq_pending, true);
1376+
wake_up_process(tsk);
1377+
}
1378+
1379+
static void vmbus_irqd_setup(unsigned int cpu)
1380+
{
1381+
sched_set_fifo(current);
1382+
}
1383+
1384+
static int vmbus_irqd_should_run(unsigned int cpu)
1385+
{
1386+
return __this_cpu_read(vmbus_irq_pending);
1387+
}
1388+
1389+
static void run_vmbus_irqd(unsigned int cpu)
1390+
{
1391+
__this_cpu_write(vmbus_irq_pending, false);
1392+
__vmbus_isr();
1393+
}
1394+
1395+
static bool vmbus_irq_initialized;
1396+
1397+
static struct smp_hotplug_thread vmbus_irq_threads = {
1398+
.store = &vmbus_irqd,
1399+
.setup = vmbus_irqd_setup,
1400+
.thread_should_run = vmbus_irqd_should_run,
1401+
.thread_fn = run_vmbus_irqd,
1402+
.thread_comm = "vmbus_irq/%u",
1403+
};
1404+
1405+
void vmbus_isr(void)
1406+
{
1407+
if (IS_ENABLED(CONFIG_PREEMPT_RT)) {
1408+
vmbus_irqd_wake();
1409+
} else {
1410+
lockdep_hardirq_threaded();
1411+
__vmbus_isr();
1412+
}
1413+
}
13661414
EXPORT_SYMBOL_FOR_MODULES(vmbus_isr, "mshv_vtl");
13671415

13681416
static irqreturn_t vmbus_percpu_isr(int irq, void *dev_id)
@@ -1462,6 +1510,13 @@ static int vmbus_bus_init(void)
14621510
* the VMbus interrupt handler.
14631511
*/
14641512

1513+
if (IS_ENABLED(CONFIG_PREEMPT_RT) && !vmbus_irq_initialized) {
1514+
ret = smpboot_register_percpu_thread(&vmbus_irq_threads);
1515+
if (ret)
1516+
goto err_kthread;
1517+
vmbus_irq_initialized = true;
1518+
}
1519+
14651520
if (vmbus_irq == -1) {
14661521
hv_setup_vmbus_handler(vmbus_isr);
14671522
} else {
@@ -1507,6 +1562,11 @@ static int vmbus_bus_init(void)
15071562
free_percpu(vmbus_evt);
15081563
}
15091564
err_setup:
1565+
if (IS_ENABLED(CONFIG_PREEMPT_RT) && vmbus_irq_initialized) {
1566+
smpboot_unregister_percpu_thread(&vmbus_irq_threads);
1567+
vmbus_irq_initialized = false;
1568+
}
1569+
err_kthread:
15101570
bus_unregister(&hv_bus);
15111571
return ret;
15121572
}
@@ -2976,6 +3036,10 @@ static void __exit vmbus_exit(void)
29763036
free_percpu_irq(vmbus_irq, vmbus_evt);
29773037
free_percpu(vmbus_evt);
29783038
}
3039+
if (IS_ENABLED(CONFIG_PREEMPT_RT) && vmbus_irq_initialized) {
3040+
smpboot_unregister_percpu_thread(&vmbus_irq_threads);
3041+
vmbus_irq_initialized = false;
3042+
}
29793043
for_each_online_cpu(cpu) {
29803044
struct hv_per_cpu_context *hv_cpu
29813045
= per_cpu_ptr(hv_context.cpu_context, cpu);

0 commit comments

Comments
 (0)