Skip to content

Commit 2738d5a

Browse files
dcuiliuw
authored andcommitted
PCI: hv: Fix a race condition in hv_irq_unmask() that can cause panic
When the host tries to remove a PCI device, the host first sends a PCI_EJECT message to the guest, and the guest is supposed to gracefully remove the PCI device and send a PCI_EJECTION_COMPLETE message to the host; the host then sends a VMBus message CHANNELMSG_RESCIND_CHANNELOFFER to the guest (when the guest receives this message, the device is already unassigned from the guest) and the guest can do some final cleanup work; if the guest fails to respond to the PCI_EJECT message within one minute, the host sends the VMBus message CHANNELMSG_RESCIND_CHANNELOFFER and removes the PCI device forcibly. In the case of fast device addition/removal, it's possible that the PCI device driver is still configuring MSI-X interrupts when the guest receives the PCI_EJECT message; the channel callback calls hv_pci_eject_device(), which sets hpdev->state to hv_pcichild_ejecting, and schedules a work hv_eject_device_work(); if the PCI device driver is calling pci_alloc_irq_vectors() -> ... -> hv_compose_msi_msg(), we can break the while loop in hv_compose_msi_msg() due to the updated hpdev->state, and leave data->chip_data with its default value of NULL; later, when the PCI device driver calls request_irq() -> ... -> hv_irq_unmask(), the guest crashes in hv_arch_irq_unmask() due to data->chip_data being NULL. Fix the issue by not testing hpdev->state in the while loop: when the guest receives PCI_EJECT, the device is still assigned to the guest, and the guest has one minute to finish the device removal gracefully. We don't really need to (and we should not) test hpdev->state in the loop. Fixes: de0aa7b ("PCI: hv: Fix 2 hang issues in hv_compose_msi_msg()") Signed-off-by: Dexuan Cui <[email protected]> Reviewed-by: Michael Kelley <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Wei Liu <[email protected]>
1 parent 440b5e3 commit 2738d5a

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

drivers/pci/controller/pci-hyperv.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,11 @@ static void hv_arch_irq_unmask(struct irq_data *data)
635635
pbus = pdev->bus;
636636
hbus = container_of(pbus->sysdata, struct hv_pcibus_device, sysdata);
637637
int_desc = data->chip_data;
638+
if (!int_desc) {
639+
dev_warn(&hbus->hdev->device, "%s() can not unmask irq %u\n",
640+
__func__, data->irq);
641+
return;
642+
}
638643

639644
local_irq_save(flags);
640645

@@ -2004,12 +2009,6 @@ static void hv_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
20042009
hv_pci_onchannelcallback(hbus);
20052010
spin_unlock_irqrestore(&channel->sched_lock, flags);
20062011

2007-
if (hpdev->state == hv_pcichild_ejecting) {
2008-
dev_err_once(&hbus->hdev->device,
2009-
"the device is being ejected\n");
2010-
goto enable_tasklet;
2011-
}
2012-
20132012
udelay(100);
20142013
}
20152014

0 commit comments

Comments
 (0)