Skip to content

Commit b20266f

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 4949e32 commit b20266f

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>
@@ -1306,7 +1307,7 @@ static void vmbus_chan_sched(struct hv_per_cpu_context *hv_cpu)
13061307
}
13071308
}
13081309

1309-
static void vmbus_isr(void)
1310+
static void __vmbus_isr(void)
13101311
{
13111312
struct hv_per_cpu_context *hv_cpu
13121313
= this_cpu_ptr(hv_context.cpu_context);
@@ -1330,6 +1331,53 @@ static void vmbus_isr(void)
13301331
add_interrupt_randomness(vmbus_interrupt);
13311332
}
13321333

1334+
static DEFINE_PER_CPU(bool, vmbus_irq_pending);
1335+
static DEFINE_PER_CPU(struct task_struct *, vmbus_irqd);
1336+
1337+
static void vmbus_irqd_wake(void)
1338+
{
1339+
struct task_struct *tsk = __this_cpu_read(vmbus_irqd);
1340+
1341+
__this_cpu_write(vmbus_irq_pending, true);
1342+
wake_up_process(tsk);
1343+
}
1344+
1345+
static void vmbus_irqd_setup(unsigned int cpu)
1346+
{
1347+
sched_set_fifo(current);
1348+
}
1349+
1350+
static int vmbus_irqd_should_run(unsigned int cpu)
1351+
{
1352+
return __this_cpu_read(vmbus_irq_pending);
1353+
}
1354+
1355+
static void run_vmbus_irqd(unsigned int cpu)
1356+
{
1357+
__this_cpu_write(vmbus_irq_pending, false);
1358+
__vmbus_isr();
1359+
}
1360+
1361+
static bool vmbus_irq_initialized;
1362+
1363+
static struct smp_hotplug_thread vmbus_irq_threads = {
1364+
.store = &vmbus_irqd,
1365+
.setup = vmbus_irqd_setup,
1366+
.thread_should_run = vmbus_irqd_should_run,
1367+
.thread_fn = run_vmbus_irqd,
1368+
.thread_comm = "vmbus_irq/%u",
1369+
};
1370+
1371+
static void vmbus_isr(void)
1372+
{
1373+
if (IS_ENABLED(CONFIG_PREEMPT_RT)) {
1374+
vmbus_irqd_wake();
1375+
} else {
1376+
lockdep_hardirq_threaded();
1377+
__vmbus_isr();
1378+
}
1379+
}
1380+
13331381
static irqreturn_t vmbus_percpu_isr(int irq, void *dev_id)
13341382
{
13351383
vmbus_isr();
@@ -1375,6 +1423,13 @@ static int vmbus_bus_init(void)
13751423
* the VMbus interrupt handler.
13761424
*/
13771425

1426+
if (IS_ENABLED(CONFIG_PREEMPT_RT) && !vmbus_irq_initialized) {
1427+
ret = smpboot_register_percpu_thread(&vmbus_irq_threads);
1428+
if (ret)
1429+
goto err_kthread;
1430+
vmbus_irq_initialized = true;
1431+
}
1432+
13781433
if (vmbus_irq == -1) {
13791434
hv_setup_vmbus_handler(vmbus_isr);
13801435
} else {
@@ -1449,6 +1504,11 @@ static int vmbus_bus_init(void)
14491504
free_percpu(vmbus_evt);
14501505
}
14511506
err_setup:
1507+
if (IS_ENABLED(CONFIG_PREEMPT_RT) && vmbus_irq_initialized) {
1508+
smpboot_unregister_percpu_thread(&vmbus_irq_threads);
1509+
vmbus_irq_initialized = false;
1510+
}
1511+
err_kthread:
14521512
bus_unregister(&hv_bus);
14531513
return ret;
14541514
}
@@ -2914,6 +2974,10 @@ static void __exit vmbus_exit(void)
29142974
free_percpu_irq(vmbus_irq, vmbus_evt);
29152975
free_percpu(vmbus_evt);
29162976
}
2977+
if (IS_ENABLED(CONFIG_PREEMPT_RT) && vmbus_irq_initialized) {
2978+
smpboot_unregister_percpu_thread(&vmbus_irq_threads);
2979+
vmbus_irq_initialized = false;
2980+
}
29172981
for_each_online_cpu(cpu) {
29182982
struct hv_per_cpu_context *hv_cpu
29192983
= per_cpu_ptr(hv_context.cpu_context, cpu);

0 commit comments

Comments
 (0)