[PATCH 2/2] PCI: hv: Deal with nested MSHV setup

From: Stanislav Kinsburskii
Date: Fri Apr 07 2023 - 16:58:25 EST


From: Stanislav Kinsburskii <stanislav.kinsburskii@xxxxxxxxx>

Running Microsoft hypervisor as nested (i.e., on top of another Microsoft
hypervisor) imposes a different requirement for the PCI-hyperv controller.

In this setup, the interrupt will first come to the nested (L1) hypervisor
from the hypervisor, running on bare metal (L0), and then the L1 hypervisor
will deliver the interrupt to the appropriate CPU of the nested root
partition.

Thus, instead of issuing the RETARGET hypercall to the L0 hypervisor,
MAP_DEVICE_INTERRUPT hypercall should be issued to the L1 hypervisor to
complete the interrupt setup.

Signed-off-by: Stanislav Kinsburskii <stanislav.kinsburskii@xxxxxxxxx>
CC: "K. Y. Srinivasan" <kys@xxxxxxxxxxxxx>
CC: Haiyang Zhang <haiyangz@xxxxxxxxxxxxx>
CC: Wei Liu <wei.liu@xxxxxxxxxx>
CC: Dexuan Cui <decui@xxxxxxxxxxxxx>
CC: Lorenzo Pieralisi <lpieralisi@xxxxxxxxxx>
CC: "Krzysztof Wilczyński" <kw@xxxxxxxxx>
CC: Rob Herring <robh@xxxxxxxxxx>
CC: Bjorn Helgaas <bhelgaas@xxxxxxxxxx>
CC: linux-hyperv@xxxxxxxxxxxxxxx
CC: linux-pci@xxxxxxxxxxxxxxx
CC: linux-kernel@xxxxxxxxxxxxxxx
---
drivers/pci/controller/pci-hyperv.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
index f33370b75628..61bee8babad4 100644
--- a/drivers/pci/controller/pci-hyperv.c
+++ b/drivers/pci/controller/pci-hyperv.c
@@ -1570,7 +1570,16 @@ static void hv_irq_mask(struct irq_data *data)

static void hv_irq_unmask(struct irq_data *data)
{
- hv_arch_irq_unmask(data);
+ if (hv_nested && hv_root_partition)
+ /*
+ * In case of the nested root partition, the nested hypervisor
+ * is taking care of interrupt remapping and thus the
+ * MAP_DEVICE_INTERRUPT hypercall is required instead of the
+ * RETARGET_INTERRUPT one.
+ */
+ (void)hv_map_msi_interrupt(data, NULL);
+ else
+ hv_arch_irq_unmask(data);

if (data->parent_data->chip->irq_unmask)
irq_chip_unmask_parent(data);