Skip to contentSkip to conversation

Nested virtualization fixes for root partition

PATCH Superseded Nuno Das Neves 4 participants 19 messages Jul 3, 2025 – Jul 10, 2025

Subsystems (6)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Nested virtualization fixes for root partition

Fixes for running as nested root partition on the Microsoft Hypervisor.

Address issues with vmbus. The first patch prevents the Hyper-V PCI driver being registered on baremetal, since there's no vmbus.

The second patch changes vmbus to make hypercalls to the L0 hypervisor instead of the L1. This is needed because L0 hypervisor, not the L1, is the one hosting the Windows root partition with the VMM that provides vmbus.

The 3rd patch fixes a bug where cpu_online_mask is used unnecessarily in an interrupt chip callback.

The 4th patch fixes up error return values in hv_map/unmap_interrupt() and their callers, and cleans up style issues.

The 5th and 6th patches fix interrupt unmasking on nested. In this scenario, the L1 (nested) hypervisor does the interrupt mapping to root partition cores. The vectors just need to be mapped with MAP_DEVICE_INTERRUPT instead of affinitized with RETARGET_INTERRUPT.

Changes in v2:
- Reword commit messages for clarity (Michael Kelley, Bjorn Helgaas)
- Open-code nested hypercalls to reduce unnecessary code (Michael Kelley)
- Add patch (#3) to fix cpu_online_mask issue (Thomas Gleixner)
- Add patch (#4) to fix error return values (Michael Kelley)
- Remove several redundant error messages and checks (Michael Kelley)

Mukesh Rathor (1):
PCI: hv: Don't load the driver for baremetal root partition

Nuno Das Neves (3):
Drivers: hv: Use nested hypercall for post message and signal event x86/hyperv: Fix usage of cpu_online_mask to get valid cpu x86/hyperv: Clean up hv_map/unmap_interrupt() return values

Stanislav Kinsburskii (2):
x86: hyperv: Expose hv_map_msi_interrupt function
PCI: hv: Use the correct hypercall for unmasking interrupts on nested

 arch/x86/hyperv/irqdomain.c         | 66 +++++++++++++++++------------
 arch/x86/include/asm/mshyperv.h     | 22 +---------
 drivers/hv/connection.c             |  7 ++-
 drivers/hv/hv.c                     |  6 ++-
 drivers/iommu/hyperv-iommu.c        | 33 ++++++---------
 drivers/pci/controller/pci-hyperv.c | 21 ++++++++-
 6 files changed, 80 insertions(+), 75 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/6 PCI: hv: Don't load the driver for baremetal root partition

From: Mukesh Rathor <[email protected]>

The root partition only uses VMBus when running nested.

When running on baremetal the Hyper-V PCI driver is not needed, so do not initialize it.

---
 drivers/pci/controller/pci-hyperv.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pci/controller/pci-hyperv.c +3 -0
index b4f29ee75848..4d25754dfe2f 100644
@@ -4150,6 +4150,9 @@ static int __init init_hv_pci_drv(void)
 	if (!hv_is_hyperv_initialized())
 		return -ENODEV;
 
+	if (hv_root_partition() && !hv_nested)
+		return -ENODEV;
+
 	ret = hv_pci_irqchip_init();
 	if (ret)
 		return ret;
Signature · 1 line
2.34.1
Reviewed-by on v2 1/6
#2 lore raw

RE: [PATCH v2 1/6] PCI: hv: Don't load the driver for baremetal root partition

From: Nuno Das Neves <[email protected]> Sent: Thursday, July 3, 2025 3:45 PM

Quoted 30 lines

From: Mukesh Rathor <[email protected]>

The root partition only uses VMBus when running nested.

When running on baremetal the Hyper-V PCI driver is not needed, so do not initialize it.

---
 drivers/pci/controller/pci-hyperv.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pci/controller/pci-hyperv.c +3 -1
index b4f29ee75848..4d25754dfe2f 100644
@@ -4150,6 +4150,9 @@ static int __init init_hv_pci_drv(void)
 	if (!hv_is_hyperv_initialized())
 		return -ENODEV;
 
+	if (hv_root_partition() && !hv_nested)
+		return -ENODEV;
+
 	ret = hv_pci_irqchip_init();
 	if (ret)
 		return ret;
--
Quoted 1 line

2.34.1

Acked-by on v2 1/6
#3 lore raw

Re: [PATCH v2 1/6] PCI: hv: Don't load the driver for baremetal root partition

In reply to Nuno Das Neves
Quoted 10 lines · Nuno Das Neves

From: Mukesh Rathor <[email protected]>

The root partition only uses VMBus when running nested.

When running on baremetal the Hyper-V PCI driver is not needed, so do not initialize it.

I assume this series will be merged elsewhere.

Quoted 21 lines
---
 drivers/pci/controller/pci-hyperv.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pci/controller/pci-hyperv.c +3 -0
index b4f29ee75848..4d25754dfe2f 100644
@@ -4150,6 +4150,9 @@ static int __init init_hv_pci_drv(void)
 	if (!hv_is_hyperv_initialized())
 		return -ENODEV;
 
+	if (hv_root_partition() && !hv_nested)
+		return -ENODEV;
+
 	ret = hv_pci_irqchip_init();
 	if (ret)
 		return ret;
Signature · 1 line
2.34.1
#4 lore raw

PATCH v2 2/6 Drivers: hv: Use nested hypercall for post message and signal event

In reply to Nuno Das Neves

When running nested, these hypercalls must be sent to the L0 hypervisor or VMBus will fail.

Remove hv_do_nested_hypercall() and hv_do_fast_nested_hypercall8() altogether and open-code these cases, since there are only 2 and all they do is add the nested bit.

---
 arch/x86/include/asm/mshyperv.h | 20 --------------------
 drivers/hv/connection.c         |  7 +++++--
 drivers/hv/hv.c                 |  6 ++++--
 3 files changed, 9 insertions(+), 24 deletions(-)
arch/x86/include/asm/mshyperv.h +0 -20
index 5ec92e3e2e37..e00a8431ef8e 100644
@@ -111,12 +111,6 @@ static inline u64 hv_do_hypercall(u64 control, void *input, void *output)
 	return hv_status;
 }
 
-/* Hypercall to the L0 hypervisor */
-static inline u64 hv_do_nested_hypercall(u64 control, void *input, void *output)
-{
-	return hv_do_hypercall(control | HV_HYPERCALL_NESTED, input, output);
-}
-
 /* Fast hypercall with 8 bytes of input and no output */
 static inline u64 _hv_do_fast_hypercall8(u64 control, u64 input1)
 {
@@ -164,13 +158,6 @@ static inline u64 hv_do_fast_hypercall8(u16 code, u64 input1)
 	return _hv_do_fast_hypercall8(control, input1);
 }
 
-static inline u64 hv_do_fast_nested_hypercall8(u16 code, u64 input1)
-{
-	u64 control = (u64)code | HV_HYPERCALL_FAST_BIT | HV_HYPERCALL_NESTED;
-
-	return _hv_do_fast_hypercall8(control, input1);
-}
-
 /* Fast hypercall with 16 bytes of input */
 static inline u64 _hv_do_fast_hypercall16(u64 control, u64 input1, u64 input2)
 {
@@ -222,13 +209,6 @@ static inline u64 hv_do_fast_hypercall16(u16 code, u64 input1, u64 input2)
 	return _hv_do_fast_hypercall16(control, input1, input2);
 }
 
-static inline u64 hv_do_fast_nested_hypercall16(u16 code, u64 input1, u64 input2)
-{
-	u64 control = (u64)code | HV_HYPERCALL_FAST_BIT | HV_HYPERCALL_NESTED;
-
-	return _hv_do_fast_hypercall16(control, input1, input2);
-}
-
 extern struct hv_vp_assist_page **hv_vp_assist_page;
 
 static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu)
drivers/hv/connection.c +5 -2
index be490c598785..47c93cee1ef6 100644
@@ -518,8 +518,11 @@ void vmbus_set_event(struct vmbus_channel *channel)
 					 channel->sig_event, 0);
 		else
 			WARN_ON_ONCE(1);
-	} else {
-		hv_do_fast_hypercall8(HVCALL_SIGNAL_EVENT, channel->sig_event);
+	} else if (hv_nested) {
+		u64 control = HVCALL_SIGNAL_EVENT;
+
+		control |= hv_nested ? HV_HYPERCALL_NESTED : 0;
+		hv_do_fast_hypercall8(control, channel->sig_event);
 	}
 }
 EXPORT_SYMBOL_GPL(vmbus_set_event);
drivers/hv/hv.c +4 -2
index 308c8f279df8..b14c5f9e0ef2 100644
@@ -85,8 +85,10 @@ int hv_post_message(union hv_connection_id connection_id,
 		else
 			status = HV_STATUS_INVALID_PARAMETER;
 	} else {
-		status = hv_do_hypercall(HVCALL_POST_MESSAGE,
-					 aligned_msg, NULL);
+		u64 control = HVCALL_POST_MESSAGE;
+
+		control |= hv_nested ? HV_HYPERCALL_NESTED : 0;
+		status = hv_do_hypercall(control, aligned_msg, NULL);
 	}
 
 	local_irq_restore(flags);
Signature · 1 line
2.34.1
#5 lore raw

RE: [PATCH v2 2/6] Drivers: hv: Use nested hypercall for post message and signal event

From: Nuno Das Neves <[email protected]> Sent: Thursday, July 3, 2025 3:45 PM

Quoted 67 lines

When running nested, these hypercalls must be sent to the L0 hypervisor or VMBus will fail.

Remove hv_do_nested_hypercall() and hv_do_fast_nested_hypercall8() altogether and open-code these cases, since there are only 2 and all they do is add the nested bit.

---
 arch/x86/include/asm/mshyperv.h | 20 --------------------
 drivers/hv/connection.c         |  7 +++++--
 drivers/hv/hv.c                 |  6 ++++--
 3 files changed, 9 insertions(+), 24 deletions(-)
arch/x86/include/asm/mshyperv.h +0 -6
index 5ec92e3e2e37..e00a8431ef8e 100644
@@ -111,12 +111,6 @@ static inline u64 hv_do_hypercall(u64 control, void *input,
 void *output)
 	return hv_status;
 }
 
-/* Hypercall to the L0 hypervisor */
-static inline u64 hv_do_nested_hypercall(u64 control, void *input, void *output)
-{
-	return hv_do_hypercall(control | HV_HYPERCALL_NESTED, input, output);
-}
-
 /* Fast hypercall with 8 bytes of input and no output */
 static inline u64 _hv_do_fast_hypercall8(u64 control, u64 input1)

{

arch/x86/include/asm/mshyperv.h +0 -14
@@ -164,13 +158,6 @@ static inline u64 hv_do_fast_hypercall8(u16 code, u64 input1)
 	return _hv_do_fast_hypercall8(control, input1);
 }
 
-static inline u64 hv_do_fast_nested_hypercall8(u16 code, u64 input1)
-{
-	u64 control = (u64)code | HV_HYPERCALL_FAST_BIT | HV_HYPERCALL_NESTED;
-
-	return _hv_do_fast_hypercall8(control, input1);
-}
-
 /* Fast hypercall with 16 bytes of input */
 static inline u64 _hv_do_fast_hypercall16(u64 control, u64 input1, u64 input2)
 {
@@ -222,13 +209,6 @@ static inline u64 hv_do_fast_hypercall16(u16 code, u64 input1, u64 input2)
 	return _hv_do_fast_hypercall16(control, input1, input2);
 }
 
-static inline u64 hv_do_fast_nested_hypercall16(u16 code, u64 input1, u64 input2)
-{
-	u64 control = (u64)code | HV_HYPERCALL_FAST_BIT | HV_HYPERCALL_NESTED;
-
-	return _hv_do_fast_hypercall16(control, input1, input2);
-}
-
 extern struct hv_vp_assist_page **hv_vp_assist_page;
 
 static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu)
drivers/hv/connection.c +0 -0
index be490c598785..47c93cee1ef6 100644

drivers/hv/connection.c void vmbus_set_event(struct vmbus_channel *channel) · line 521

Quoted 6 lines
drivers/hv/connection.c +1 -2
@@ -518,8 +518,11 @@ void vmbus_set_event(struct vmbus_channel *channel)
 					 channel->sig_event, 0);
 		else
 			WARN_ON_ONCE(1);
-	} else {
-		hv_do_fast_hypercall8(HVCALL_SIGNAL_EVENT, channel->sig_event);
+	} else if (hv_nested) {

As coded, this won't make any hypercall for the non-nested case. The "else if (hv_nested)" should be just "else".

Michael

Quoted 26 lines
drivers/hv/connection.c +4 -0
+		u64 control = HVCALL_SIGNAL_EVENT;
+
+		control |= hv_nested ? HV_HYPERCALL_NESTED : 0;
+		hv_do_fast_hypercall8(control, channel->sig_event);
 	}
 }
 EXPORT_SYMBOL_GPL(vmbus_set_event);
drivers/hv/hv.c +4 -3
index 308c8f279df8..b14c5f9e0ef2 100644
@@ -85,8 +85,10 @@ int hv_post_message(union hv_connection_id connection_id,
 		else
 			status = HV_STATUS_INVALID_PARAMETER;
 	} else {
-		status = hv_do_hypercall(HVCALL_POST_MESSAGE,
-					 aligned_msg, NULL);
+		u64 control = HVCALL_POST_MESSAGE;
+
+		control |= hv_nested ? HV_HYPERCALL_NESTED : 0;
+		status = hv_do_hypercall(control, aligned_msg, NULL);
 	}
 
 	local_irq_restore(flags);
--

2.34.1

#6 lore raw

Re: [PATCH v2 2/6] Drivers: hv: Use nested hypercall for post message and signal event

Quoted 62 lines · Michael Kelley

From: Nuno Das Neves <[email protected]> Sent: Thursday, July 3, 2025 3:45 PM

Quoted 61 lines

When running nested, these hypercalls must be sent to the L0 hypervisor or VMBus will fail.

Remove hv_do_nested_hypercall() and hv_do_fast_nested_hypercall8() altogether and open-code these cases, since there are only 2 and all they do is add the nested bit.

---
 arch/x86/include/asm/mshyperv.h | 20 --------------------
 drivers/hv/connection.c         |  7 +++++--
 drivers/hv/hv.c                 |  6 ++++--
 3 files changed, 9 insertions(+), 24 deletions(-)
arch/x86/include/asm/mshyperv.h +0 -6
index 5ec92e3e2e37..e00a8431ef8e 100644
@@ -111,12 +111,6 @@ static inline u64 hv_do_hypercall(u64 control, void *input,
 void *output)
 	return hv_status;
 }
 
-/* Hypercall to the L0 hypervisor */
-static inline u64 hv_do_nested_hypercall(u64 control, void *input, void *output)
-{
-	return hv_do_hypercall(control | HV_HYPERCALL_NESTED, input, output);
-}
-
 /* Fast hypercall with 8 bytes of input and no output */
 static inline u64 _hv_do_fast_hypercall8(u64 control, u64 input1)

{

arch/x86/include/asm/mshyperv.h +0 -14
@@ -164,13 +158,6 @@ static inline u64 hv_do_fast_hypercall8(u16 code, u64 input1)
 	return _hv_do_fast_hypercall8(control, input1);
 }
 
-static inline u64 hv_do_fast_nested_hypercall8(u16 code, u64 input1)
-{
-	u64 control = (u64)code | HV_HYPERCALL_FAST_BIT | HV_HYPERCALL_NESTED;
-
-	return _hv_do_fast_hypercall8(control, input1);
-}
-
 /* Fast hypercall with 16 bytes of input */
 static inline u64 _hv_do_fast_hypercall16(u64 control, u64 input1, u64 input2)
 {
@@ -222,13 +209,6 @@ static inline u64 hv_do_fast_hypercall16(u16 code, u64 input1, u64 input2)
 	return _hv_do_fast_hypercall16(control, input1, input2);
 }
 
-static inline u64 hv_do_fast_nested_hypercall16(u16 code, u64 input1, u64 input2)
-{
-	u64 control = (u64)code | HV_HYPERCALL_FAST_BIT | HV_HYPERCALL_NESTED;
-
-	return _hv_do_fast_hypercall16(control, input1, input2);
-}
-
 extern struct hv_vp_assist_page **hv_vp_assist_page;
 
Quoted 15 lines

drivers/hv/connection.c void vmbus_set_event(struct vmbus_channel *channel) · line 521

Quoted 12 lines
arch/x86/include/asm/mshyperv.h +0 -0
 static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu)
drivers/hv/connection.c +1 -2
index be490c598785..47c93cee1ef6 100644
@@ -518,8 +518,11 @@ void vmbus_set_event(struct vmbus_channel *channel)
 					 channel->sig_event, 0);
 		else
 			WARN_ON_ONCE(1);
-	} else {
-		hv_do_fast_hypercall8(HVCALL_SIGNAL_EVENT, channel->sig_event);
+	} else if (hv_nested) {

As coded, this won't make any hypercall for the non-nested case. The "else if (hv_nested)" should be just "else".

Ah, forgot to change this line. Thank you for catching it

Nuno

Quoted 29 lines

Michael

Quoted 26 lines
drivers/hv/connection.c +4 -0
+		u64 control = HVCALL_SIGNAL_EVENT;
+
+		control |= hv_nested ? HV_HYPERCALL_NESTED : 0;
+		hv_do_fast_hypercall8(control, channel->sig_event);
 	}
 }
 EXPORT_SYMBOL_GPL(vmbus_set_event);
drivers/hv/hv.c +4 -3
index 308c8f279df8..b14c5f9e0ef2 100644
@@ -85,8 +85,10 @@ int hv_post_message(union hv_connection_id connection_id,
 		else
 			status = HV_STATUS_INVALID_PARAMETER;
 	} else {
-		status = hv_do_hypercall(HVCALL_POST_MESSAGE,
-					 aligned_msg, NULL);
+		u64 control = HVCALL_POST_MESSAGE;
+
+		control |= hv_nested ? HV_HYPERCALL_NESTED : 0;
+		status = hv_do_hypercall(control, aligned_msg, NULL);
 	}
 
 	local_irq_restore(flags);
--

2.34.1

#7 lore raw

PATCH v2 3/6 x86/hyperv: Fix usage of cpu_online_mask to get valid cpu

In reply to Nuno Das Neves

Accessing cpu_online_mask here is problematic because the cpus read lock is not held in this context.

However, cpu_online_mask isn't needed here since the effective affinity mask is guaranteed to be valid in this callback. So, just use cpumask_first() to get the cpu instead of ANDing it with cpus_online_mask unnecessarily.

---
 arch/x86/hyperv/irqdomain.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/x86/hyperv/irqdomain.c +1 -3
index 31f0d29cbc5e..e28c317ac9e8 100644
@@ -192,7 +192,6 @@ static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 	struct pci_dev *dev;
 	struct hv_interrupt_entry out_entry, *stored_entry;
 	struct irq_cfg *cfg = irqd_cfg(data);
-	const cpumask_t *affinity;
 	int cpu;
 	u64 status;
 
@@ -204,8 +203,7 @@ static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 		return;
 	}
 
-	affinity = irq_data_get_effective_affinity_mask(data);
-	cpu = cpumask_first_and(affinity, cpu_online_mask);
+	cpu = cpumask_first(irq_data_get_effective_affinity_mask(data));
 
 	if (data->chip_data) {
 		/*
Signature · 1 line
2.34.1
Reviewed-by on v2 3/6
#8 lore raw

RE: [PATCH v2 3/6] x86/hyperv: Fix usage of cpu_online_mask to get valid cpu

From: Nuno Das Neves <[email protected]> Sent: Thursday, July 3, 2025 3:45 PM

Quoted 41 lines

Accessing cpu_online_mask here is problematic because the cpus read lock is not held in this context.

However, cpu_online_mask isn't needed here since the effective affinity mask is guaranteed to be valid in this callback. So, just use cpumask_first() to get the cpu instead of ANDing it with cpus_online_mask unnecessarily.

---
 arch/x86/hyperv/irqdomain.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/x86/hyperv/irqdomain.c +1 -4
index 31f0d29cbc5e..e28c317ac9e8 100644
@@ -192,7 +192,6 @@ static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 	struct pci_dev *dev;
 	struct hv_interrupt_entry out_entry, *stored_entry;
 	struct irq_cfg *cfg = irqd_cfg(data);
-	const cpumask_t *affinity;
 	int cpu;
 	u64 status;
 
@@ -204,8 +203,7 @@ static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 		return;
 	}
 
-	affinity = irq_data_get_effective_affinity_mask(data);
-	cpu = cpumask_first_and(affinity, cpu_online_mask);
+	cpu = cpumask_first(irq_data_get_effective_affinity_mask(data));
 
 	if (data->chip_data) {
 		/*
--
Quoted 1 line

2.34.1

#9 lore raw

PATCH v2 4/6 x86/hyperv: Clean up hv_map/unmap_interrupt() return values

In reply to Nuno Das Neves

Fix the return values of these hypercall helpers so they return a negated errno either directly or via hv_result_to_errno().

Update the callers to check for errno instead of using hv_status_success(), and remove redundant error printing.

While at it, rearrange some variable declarations to adhere to style guidelines i.e. "reverse fir tree order".

---
 arch/x86/hyperv/irqdomain.c  | 32 ++++++++++++++------------------
 drivers/iommu/hyperv-iommu.c | 33 ++++++++++++---------------------
 2 files changed, 26 insertions(+), 39 deletions(-)
arch/x86/hyperv/irqdomain.c +14 -18
index e28c317ac9e8..75b25724b045 100644
@@ -46,7 +46,7 @@ static int hv_map_interrupt(union hv_device_id device_id, bool level,
 	if (nr_bank < 0) {
 		local_irq_restore(flags);
 		pr_err("%s: unable to generate VP set\n", __func__);
-		return EINVAL;
+		return -EINVAL;
 	}
 	intr_desc->target.flags = HV_DEVICE_INTERRUPT_TARGET_PROCESSOR_SET;
 
@@ -66,7 +66,7 @@ static int hv_map_interrupt(union hv_device_id device_id, bool level,
 	if (!hv_result_success(status))
 		hv_status_err(status, "\n");
 
-	return hv_result(status);
+	return hv_result_to_errno(status);
 }
 
 static int hv_unmap_interrupt(u64 id, struct hv_interrupt_entry *old_entry)
@@ -88,7 +88,10 @@ static int hv_unmap_interrupt(u64 id, struct hv_interrupt_entry *old_entry)
 	status = hv_do_hypercall(HVCALL_UNMAP_DEVICE_INTERRUPT, input, NULL);
 	local_irq_restore(flags);
 
-	return hv_result(status);
+	if (!hv_result_success(status))
+		hv_status_err(status, "\n");
+
+	return hv_result_to_errno(status);
 }
 
 #ifdef CONFIG_PCI_MSI
@@ -188,12 +191,11 @@ static inline void entry_to_msi_msg(struct hv_interrupt_entry *entry, struct msi
 static int hv_unmap_msi_interrupt(struct pci_dev *dev, struct hv_interrupt_entry *old_entry);
 static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 {
-	struct msi_desc *msidesc;
-	struct pci_dev *dev;
 	struct hv_interrupt_entry out_entry, *stored_entry;
 	struct irq_cfg *cfg = irqd_cfg(data);
-	int cpu;
-	u64 status;
+	struct msi_desc *msidesc;
+	struct pci_dev *dev;
+	int cpu, ret;
 
 	msidesc = irq_data_get_msi_desc(data);
 	dev = msi_desc_to_pci_dev(msidesc);
@@ -217,14 +219,12 @@ static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 		stored_entry = data->chip_data;
 		data->chip_data = NULL;
 
-		status = hv_unmap_msi_interrupt(dev, stored_entry);
+		ret = hv_unmap_msi_interrupt(dev, stored_entry);
 
 		kfree(stored_entry);
 
-		if (status != HV_STATUS_SUCCESS) {
-			hv_status_debug(status, "failed to unmap\n");
+		if (ret)
 			return;
-		}
 	}
 
 	stored_entry = kzalloc(sizeof(*stored_entry), GFP_ATOMIC);
@@ -233,8 +233,8 @@ static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 		return;
 	}
 
-	status = hv_map_msi_interrupt(dev, cpu, cfg->vector, &out_entry);
-	if (status != HV_STATUS_SUCCESS) {
+	ret = hv_map_msi_interrupt(dev, cpu, cfg->vector, &out_entry);
+	if (ret) {
 		kfree(stored_entry);
 		return;
 	}
@@ -255,7 +255,6 @@ static void hv_teardown_msi_irq(struct pci_dev *dev, struct irq_data *irqd)
 {
 	struct hv_interrupt_entry old_entry;
 	struct msi_msg msg;
-	u64 status;
 
 	if (!irqd->chip_data) {
 		pr_debug("%s: no chip data\n!", __func__);
@@ -268,10 +267,7 @@ static void hv_teardown_msi_irq(struct pci_dev *dev, struct irq_data *irqd)
 	kfree(irqd->chip_data);
 	irqd->chip_data = NULL;
 
-	status = hv_unmap_msi_interrupt(dev, &old_entry);
-
-	if (status != HV_STATUS_SUCCESS)
-		hv_status_err(status, "\n");
+	(void)hv_unmap_msi_interrupt(dev, &old_entry);
 }
 
 static void hv_msi_free_irq(struct irq_domain *domain,
drivers/iommu/hyperv-iommu.c +12 -21
index 761ab647f372..0961ac805944 100644
@@ -193,15 +193,13 @@ struct hyperv_root_ir_data {
 static void
 hyperv_root_ir_compose_msi_msg(struct irq_data *irq_data, struct msi_msg *msg)
 {
-	u64 status;
-	u32 vector;
-	struct irq_cfg *cfg;
-	int ioapic_id;
-	const struct cpumask *affinity;
-	int cpu;
-	struct hv_interrupt_entry entry;
 	struct hyperv_root_ir_data *data = irq_data->chip_data;
+	struct hv_interrupt_entry entry;
+	const struct cpumask *affinity;
 	struct IO_APIC_route_entry e;
+	struct irq_cfg *cfg;
+	int cpu, ioapic_id;
+	u32 vector;
 
 	cfg = irqd_cfg(irq_data);
 	affinity = irq_data_get_effective_affinity_mask(irq_data);
@@ -214,23 +212,16 @@ hyperv_root_ir_compose_msi_msg(struct irq_data *irq_data, struct msi_msg *msg)
 	    && data->entry.ioapic_rte.as_uint64) {
 		entry = data->entry;
 
-		status = hv_unmap_ioapic_interrupt(ioapic_id, &entry);
-
-		if (status != HV_STATUS_SUCCESS)
-			hv_status_debug(status, "failed to unmap\n");
+		(void)hv_unmap_ioapic_interrupt(ioapic_id, &entry);
 
 		data->entry.ioapic_rte.as_uint64 = 0;
 		data->entry.source = 0; /* Invalid source */
 	}
 
 
-	status = hv_map_ioapic_interrupt(ioapic_id, data->is_level, cpu,
-					vector, &entry);
-
-	if (status != HV_STATUS_SUCCESS) {
-		hv_status_err(status, "map failed\n");
+	if (hv_map_ioapic_interrupt(ioapic_id, data->is_level, cpu,
+				    vector, &entry))
 		return;
-	}
 
 	data->entry = entry;
 
@@ -322,10 +313,10 @@ static void hyperv_root_irq_remapping_free(struct irq_domain *domain,
 			data = irq_data->chip_data;
 			e = &data->entry;
 
-			if (e->source == HV_DEVICE_TYPE_IOAPIC
-			      && e->ioapic_rte.as_uint64)
-				hv_unmap_ioapic_interrupt(data->ioapic_id,
-							&data->entry);
+			if (e->source == HV_DEVICE_TYPE_IOAPIC &&
+			    e->ioapic_rte.as_uint64)
+				(void)hv_unmap_ioapic_interrupt(data->ioapic_id,
+								&data->entry);
 
 			kfree(data);
 		}
Signature · 1 line
2.34.1
Reviewed-by on v2 4/6
#10 lore raw

RE: [PATCH v2 4/6] x86/hyperv: Clean up hv_map/unmap_interrupt() return values

From: Nuno Das Neves <[email protected]> Sent: Thursday, July 3, 2025 3:45 PM

Quoted 7 lines

Fix the return values of these hypercall helpers so they return a negated errno either directly or via hv_result_to_errno().

Update the callers to check for errno instead of using hv_status_success(), and remove redundant error printing.

Quoted 8 lines

While at it, rearrange some variable declarations to adhere to style guidelines i.e. "reverse fir tree order".

---
 arch/x86/hyperv/irqdomain.c  | 32 ++++++++++++++------------------
 drivers/iommu/hyperv-iommu.c | 33 ++++++++++++---------------------
 2 files changed, 26 insertions(+), 39 deletions(-)
#11 lore raw

PATCH v2 5/6 x86: hyperv: Expose hv_map_msi_interrupt function

In reply to Nuno Das Neves

From: Stanislav Kinsburskii <[email protected]>

This patch moves a part of currently internal logic into the hv_map_msi_interrupt function and makes it globally available helper function, which will be used to map PCI interrupts in case of root partition.

---
 arch/x86/hyperv/irqdomain.c     | 38 +++++++++++++++++++++++----------
 arch/x86/include/asm/mshyperv.h |  2 ++
 2 files changed, 29 insertions(+), 11 deletions(-)
arch/x86/hyperv/irqdomain.c +27 -11
index 75b25724b045..eca015563420 100644
@@ -172,13 +172,32 @@ static union hv_device_id hv_build_pci_dev_id(struct pci_dev *dev)
 	return dev_id;
 }
 
-static int hv_map_msi_interrupt(struct pci_dev *dev, int cpu, int vector,
-				struct hv_interrupt_entry *entry)
+/**
+ * hv_map_msi_interrupt() - "Map" the MSI IRQ in the hypervisor.
+ * @data:      Describes the IRQ
+ * @out_entry: Hypervisor (MSI) interrupt entry (can be NULL)
+ *
+ * Map the IRQ in the hypervisor by issuing a MAP_DEVICE_INTERRUPT hypercall.
+ */
+int hv_map_msi_interrupt(struct irq_data *data,
+			 struct hv_interrupt_entry *out_entry)
 {
-	union hv_device_id device_id = hv_build_pci_dev_id(dev);
+	struct irq_cfg *cfg = irqd_cfg(data);
+	struct hv_interrupt_entry dummy;
+	union hv_device_id device_id;
+	struct msi_desc *msidesc;
+	struct pci_dev *dev;
+	int cpu;
 
-	return hv_map_interrupt(device_id, false, cpu, vector, entry);
+	msidesc = irq_data_get_msi_desc(data);
+	dev = msi_desc_to_pci_dev(msidesc);
+	device_id = hv_build_pci_dev_id(dev);
+	cpu = cpumask_first(irq_data_get_effective_affinity_mask(data));
+
+	return hv_map_interrupt(device_id, false, cpu, cfg->vector,
+				out_entry ? out_entry : &dummy);
 }
+EXPORT_SYMBOL_GPL(hv_map_msi_interrupt);
 
 static inline void entry_to_msi_msg(struct hv_interrupt_entry *entry, struct msi_msg *msg)
 {
@@ -191,11 +210,11 @@ static inline void entry_to_msi_msg(struct hv_interrupt_entry *entry, struct msi
 static int hv_unmap_msi_interrupt(struct pci_dev *dev, struct hv_interrupt_entry *old_entry);
 static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 {
-	struct hv_interrupt_entry out_entry, *stored_entry;
+	struct hv_interrupt_entry *stored_entry;
 	struct irq_cfg *cfg = irqd_cfg(data);
 	struct msi_desc *msidesc;
 	struct pci_dev *dev;
-	int cpu, ret;
+	int ret;
 
 	msidesc = irq_data_get_msi_desc(data);
 	dev = msi_desc_to_pci_dev(msidesc);
@@ -205,8 +224,6 @@ static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 		return;
 	}
 
-	cpu = cpumask_first(irq_data_get_effective_affinity_mask(data));
-
 	if (data->chip_data) {
 		/*
 		 * This interrupt is already mapped. Let's unmap first.
@@ -233,15 +250,14 @@ static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 		return;
 	}
 
-	ret = hv_map_msi_interrupt(dev, cpu, cfg->vector, &out_entry);
+	ret = hv_map_msi_interrupt(data, stored_entry);
 	if (ret) {
 		kfree(stored_entry);
 		return;
 	}
 
-	*stored_entry = out_entry;
 	data->chip_data = stored_entry;
-	entry_to_msi_msg(&out_entry, msg);
+	entry_to_msi_msg(data->chip_data, msg);
 
 	return;
 }
arch/x86/include/asm/mshyperv.h +2 -0
index e00a8431ef8e..42ea9c68f8c8 100644
@@ -241,6 +241,8 @@ static inline void hv_apic_init(void) {}
 
 struct irq_domain *hv_create_pci_msi_domain(void);
 
+int hv_map_msi_interrupt(struct irq_data *data,
+			 struct hv_interrupt_entry *out_entry);
 int hv_map_ioapic_interrupt(int ioapic_id, bool level, int vcpu, int vector,
 		struct hv_interrupt_entry *entry);
 int hv_unmap_ioapic_interrupt(int ioapic_id, struct hv_interrupt_entry *entry);
Signature · 1 line
2.34.1
#12 lore raw

RE: [PATCH v2 5/6] x86: hyperv: Expose hv_map_msi_interrupt function

From: Nuno Das Neves <[email protected]> Sent: Thursday, July 3, 2025 3:45 PM

Quoted 7 lines

From: Stanislav Kinsburskii <[email protected]>

This patch moves a part of currently internal logic into the hv_map_msi_interrupt function and makes it globally available helper function, which will be used to map PCI interrupts in case of root partition.

Commit message still has "this patch". See suggested wording in my comment on v1 of this patch.

Quoted 14 lines
---
 arch/x86/hyperv/irqdomain.c     | 38 +++++++++++++++++++++++----------
 arch/x86/include/asm/mshyperv.h |  2 ++
 2 files changed, 29 insertions(+), 11 deletions(-)
arch/x86/hyperv/irqdomain.c +0 -0
index 75b25724b045..eca015563420 100644

arch/x86/hyperv/irqdomain.c static union hv_device_id hv_build_pci_dev_id(struct pci_dev *dev) · line 178

Quoted 9 lines
arch/x86/hyperv/irqdomain.c +4 -2
@@ -172,13 +172,32 @@ static union hv_device_id hv_build_pci_dev_id(struct pci_dev *dev)
 	return dev_id;
 }
 
-static int hv_map_msi_interrupt(struct pci_dev *dev, int cpu, int vector,
-				struct hv_interrupt_entry *entry)
+/**
+ * hv_map_msi_interrupt() - "Map" the MSI IRQ in the hypervisor.
+ * @data:      Describes the IRQ
+ * @out_entry: Hypervisor (MSI) interrupt entry (can be NULL)

Also document the return value? At least to say that success returns 0, while a failure returns a negative errno.

Quoted 83 lines
arch/x86/hyperv/irqdomain.c +23 -9
+ *
+ * Map the IRQ in the hypervisor by issuing a MAP_DEVICE_INTERRUPT hypercall.
+ */
+int hv_map_msi_interrupt(struct irq_data *data,
+			 struct hv_interrupt_entry *out_entry)
 {
-	union hv_device_id device_id = hv_build_pci_dev_id(dev);
+	struct irq_cfg *cfg = irqd_cfg(data);
+	struct hv_interrupt_entry dummy;
+	union hv_device_id device_id;
+	struct msi_desc *msidesc;
+	struct pci_dev *dev;
+	int cpu;
 
-	return hv_map_interrupt(device_id, false, cpu, vector, entry);
+	msidesc = irq_data_get_msi_desc(data);
+	dev = msi_desc_to_pci_dev(msidesc);
+	device_id = hv_build_pci_dev_id(dev);
+	cpu = cpumask_first(irq_data_get_effective_affinity_mask(data));
+
+	return hv_map_interrupt(device_id, false, cpu, cfg->vector,
+				out_entry ? out_entry : &dummy);
 }
+EXPORT_SYMBOL_GPL(hv_map_msi_interrupt);
 
 static inline void entry_to_msi_msg(struct hv_interrupt_entry *entry, struct msi_msg *msg)
 {
@@ -191,11 +210,11 @@ static inline void entry_to_msi_msg(struct hv_interrupt_entry *entry, struct msi
 static int hv_unmap_msi_interrupt(struct pci_dev *dev, struct hv_interrupt_entry *old_entry);
 static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 {
-	struct hv_interrupt_entry out_entry, *stored_entry;
+	struct hv_interrupt_entry *stored_entry;
 	struct irq_cfg *cfg = irqd_cfg(data);
 	struct msi_desc *msidesc;
 	struct pci_dev *dev;
-	int cpu, ret;
+	int ret;
 
 	msidesc = irq_data_get_msi_desc(data);
 	dev = msi_desc_to_pci_dev(msidesc);
@@ -205,8 +224,6 @@ static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 		return;
 	}
 
-	cpu = cpumask_first(irq_data_get_effective_affinity_mask(data));
-
 	if (data->chip_data) {
 		/*
 		 * This interrupt is already mapped. Let's unmap first.
@@ -233,15 +250,14 @@ static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 		return;
 	}
 
-	ret = hv_map_msi_interrupt(dev, cpu, cfg->vector, &out_entry);
+	ret = hv_map_msi_interrupt(data, stored_entry);
 	if (ret) {
 		kfree(stored_entry);
 		return;
 	}
 
-	*stored_entry = out_entry;
 	data->chip_data = stored_entry;
-	entry_to_msi_msg(&out_entry, msg);
+	entry_to_msi_msg(data->chip_data, msg);
 
 	return;
 }
arch/x86/include/asm/mshyperv.h +2 -1
index e00a8431ef8e..42ea9c68f8c8 100644
@@ -241,6 +241,8 @@ static inline void hv_apic_init(void) {}
 
 struct irq_domain *hv_create_pci_msi_domain(void);
 
+int hv_map_msi_interrupt(struct irq_data *data,
+			 struct hv_interrupt_entry *out_entry);
 int hv_map_ioapic_interrupt(int ioapic_id, bool level, int vcpu, int vector,
 		struct hv_interrupt_entry *entry);
 int hv_unmap_ioapic_interrupt(int ioapic_id, struct hv_interrupt_entry *entry);
--

2.34.1

#13 lore raw

Re: [PATCH v2 5/6] x86: hyperv: Expose hv_map_msi_interrupt function

Quoted 4 lines · Michael Kelley

From: Nuno Das Neves <[email protected]> Sent: Thursday, July 3, 2025 3:45 PM

Quoted 3 lines

From: Stanislav Kinsburskii <[email protected]>

Quoted 8 lines
Quoted 4 lines

This patch moves a part of currently internal logic into the hv_map_msi_interrupt function and makes it globally available helper function, which will be used to map PCI interrupts in case of root partition.

Commit message still has "this patch". See suggested wording in my comment on v1 of this patch.

Ah, indeed, I missed the change somehow :(

Quoted 110 lines
Quoted 14 lines
---
 arch/x86/hyperv/irqdomain.c     | 38 +++++++++++++++++++++++----------
 arch/x86/include/asm/mshyperv.h |  2 ++
 2 files changed, 29 insertions(+), 11 deletions(-)
arch/x86/hyperv/irqdomain.c +0 -0
index 75b25724b045..eca015563420 100644

arch/x86/hyperv/irqdomain.c static union hv_device_id hv_build_pci_dev_id(struct pci_dev *dev) · line 178

Quoted 9 lines
arch/x86/hyperv/irqdomain.c +4 -2
@@ -172,13 +172,32 @@ static union hv_device_id hv_build_pci_dev_id(struct pci_dev *dev)
 	return dev_id;
 }
 
-static int hv_map_msi_interrupt(struct pci_dev *dev, int cpu, int vector,
-				struct hv_interrupt_entry *entry)
+/**
+ * hv_map_msi_interrupt() - "Map" the MSI IRQ in the hypervisor.
+ * @data:      Describes the IRQ
+ * @out_entry: Hypervisor (MSI) interrupt entry (can be NULL)

Also document the return value? At least to say that success returns 0, while a failure returns a negative errno.

Quoted 83 lines
arch/x86/hyperv/irqdomain.c +23 -9
+ *
+ * Map the IRQ in the hypervisor by issuing a MAP_DEVICE_INTERRUPT hypercall.
+ */
+int hv_map_msi_interrupt(struct irq_data *data,
+			 struct hv_interrupt_entry *out_entry)
 {
-	union hv_device_id device_id = hv_build_pci_dev_id(dev);
+	struct irq_cfg *cfg = irqd_cfg(data);
+	struct hv_interrupt_entry dummy;
+	union hv_device_id device_id;
+	struct msi_desc *msidesc;
+	struct pci_dev *dev;
+	int cpu;
 
-	return hv_map_interrupt(device_id, false, cpu, vector, entry);
+	msidesc = irq_data_get_msi_desc(data);
+	dev = msi_desc_to_pci_dev(msidesc);
+	device_id = hv_build_pci_dev_id(dev);
+	cpu = cpumask_first(irq_data_get_effective_affinity_mask(data));
+
+	return hv_map_interrupt(device_id, false, cpu, cfg->vector,
+				out_entry ? out_entry : &dummy);
 }
+EXPORT_SYMBOL_GPL(hv_map_msi_interrupt);
 
 static inline void entry_to_msi_msg(struct hv_interrupt_entry *entry, struct msi_msg *msg)
 {
@@ -191,11 +210,11 @@ static inline void entry_to_msi_msg(struct hv_interrupt_entry *entry, struct msi
 static int hv_unmap_msi_interrupt(struct pci_dev *dev, struct hv_interrupt_entry *old_entry);
 static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 {
-	struct hv_interrupt_entry out_entry, *stored_entry;
+	struct hv_interrupt_entry *stored_entry;
 	struct irq_cfg *cfg = irqd_cfg(data);
 	struct msi_desc *msidesc;
 	struct pci_dev *dev;
-	int cpu, ret;
+	int ret;
 
 	msidesc = irq_data_get_msi_desc(data);
 	dev = msi_desc_to_pci_dev(msidesc);
@@ -205,8 +224,6 @@ static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 		return;
 	}
 
-	cpu = cpumask_first(irq_data_get_effective_affinity_mask(data));
-
 	if (data->chip_data) {
 		/*
 		 * This interrupt is already mapped. Let's unmap first.
@@ -233,15 +250,14 @@ static void hv_irq_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 		return;
 	}
 
-	ret = hv_map_msi_interrupt(dev, cpu, cfg->vector, &out_entry);
+	ret = hv_map_msi_interrupt(data, stored_entry);
 	if (ret) {
 		kfree(stored_entry);
 		return;
 	}
 
-	*stored_entry = out_entry;
 	data->chip_data = stored_entry;
-	entry_to_msi_msg(&out_entry, msg);
+	entry_to_msi_msg(data->chip_data, msg);
 
 	return;
 }
arch/x86/include/asm/mshyperv.h +2 -1
index e00a8431ef8e..42ea9c68f8c8 100644
@@ -241,6 +241,8 @@ static inline void hv_apic_init(void) {}
 
 struct irq_domain *hv_create_pci_msi_domain(void);
 
+int hv_map_msi_interrupt(struct irq_data *data,
+			 struct hv_interrupt_entry *out_entry);
 int hv_map_ioapic_interrupt(int ioapic_id, bool level, int vcpu, int vector,
 		struct hv_interrupt_entry *entry);
 int hv_unmap_ioapic_interrupt(int ioapic_id, struct hv_interrupt_entry *entry);
--

2.34.1

#14 lore raw

PATCH v2 6/6 PCI: hv: Use the correct hypercall for unmasking interrupts on nested

In reply to Nuno Das Neves

From: Stanislav Kinsburskii <[email protected]>

Running as nested root on MSHV imposes a different requirement for the pci-hyperv controller.

In this setup, the interrupt will first come to the L1 (nested) hypervisor, which will deliver it to the appropriate root CPU. Instead of issuing the RETARGET hypercall, issue the MAP_DEVICE_INTERRUPT hypercall to L1 to complete the setup.

Rename hv_arch_irq_unmask() to hv_irq_retarget_interrupt().

---
 drivers/pci/controller/pci-hyperv.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/pci/controller/pci-hyperv.c +16 -2
index 4d25754dfe2f..9a8cba39ea6b 100644
@@ -600,7 +600,7 @@ static unsigned int hv_msi_get_int_vector(struct irq_data *data)
 #define hv_msi_prepare		pci_msi_prepare
 
 /**
- * hv_arch_irq_unmask() - "Unmask" the IRQ by setting its current
+ * hv_irq_retarget_interrupt() - "Unmask" the IRQ by setting its current
  * affinity.
  * @data:	Describes the IRQ
  *
@@ -609,7 +609,7 @@ static unsigned int hv_msi_get_int_vector(struct irq_data *data)
  * is built out of this PCI bus's instance GUID and the function
  * number of the device.
  */
-static void hv_arch_irq_unmask(struct irq_data *data)
+static void hv_irq_retarget_interrupt(struct irq_data *data)
 {
 	struct msi_desc *msi_desc = irq_data_get_msi_desc(data);
 	struct hv_retarget_device_interrupt *params;
@@ -714,6 +714,20 @@ static void hv_arch_irq_unmask(struct irq_data *data)
 		dev_err(&hbus->hdev->device,
 			"%s() failed: %#llx", __func__, res);
 }
+
+static void hv_arch_irq_unmask(struct irq_data *data)
+{
+	if (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
+		 * RETARGET_INTERRUPT.
+		 */
+		(void)hv_map_msi_interrupt(data, NULL);
+	else
+		hv_irq_retarget_interrupt(data);
+}
 #elif defined(CONFIG_ARM64)
 /*
  * SPI vectors to use for vPCI; arch SPIs range is [32, 1019], but leaving a bit
Signature · 1 line
2.34.1
Reviewed-by on v2 6/6
#15 lore raw

RE: [PATCH v2 6/6] PCI: hv: Use the correct hypercall for unmasking interrupts on nested

From: Nuno Das Neves <[email protected]> Sent: Thursday, July 3, 2025 3:45 PM

Quoted 68 lines

From: Stanislav Kinsburskii <[email protected]>

Running as nested root on MSHV imposes a different requirement for the pci-hyperv controller.

In this setup, the interrupt will first come to the L1 (nested) hypervisor, which will deliver it to the appropriate root CPU. Instead of issuing the RETARGET hypercall, issue the MAP_DEVICE_INTERRUPT hypercall to L1 to complete the setup.

Rename hv_arch_irq_unmask() to hv_irq_retarget_interrupt().

---
 drivers/pci/controller/pci-hyperv.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/pci/controller/pci-hyperv.c +1 -1
index 4d25754dfe2f..9a8cba39ea6b 100644
@@ -600,7 +600,7 @@ static unsigned int hv_msi_get_int_vector(struct irq_data
 *data)
 #define hv_msi_prepare		pci_msi_prepare
 
 /**
- * hv_arch_irq_unmask() - "Unmask" the IRQ by setting its current
+ * hv_irq_retarget_interrupt() - "Unmask" the IRQ by setting its current
  * affinity.
  * @data:	Describes the IRQ

*

drivers/pci/controller/pci-hyperv.c +1 -1
@@ -609,7 +609,7 @@ static unsigned int hv_msi_get_int_vector(struct irq_data
 *data)
  * is built out of this PCI bus's instance GUID and the function
  * number of the device.
  */
-static void hv_arch_irq_unmask(struct irq_data *data)
+static void hv_irq_retarget_interrupt(struct irq_data *data)
 {
 	struct msi_desc *msi_desc = irq_data_get_msi_desc(data);
drivers/pci/controller/pci-hyperv.c +14 -1
 	struct hv_retarget_device_interrupt *params;
@@ -714,6 +714,20 @@ static void hv_arch_irq_unmask(struct irq_data *data)
 		dev_err(&hbus->hdev->device,
 			"%s() failed: %#llx", __func__, res);
 }
+
+static void hv_arch_irq_unmask(struct irq_data *data)
+{
+	if (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
+		 * RETARGET_INTERRUPT.
+		 */
+		(void)hv_map_msi_interrupt(data, NULL);
+	else
+		hv_irq_retarget_interrupt(data);
+}
 #elif defined(CONFIG_ARM64)
 /*
  * SPI vectors to use for vPCI; arch SPIs range is [32, 1019], but leaving a bit
--
Quoted 1 line

2.34.1

Acked-by on v2 6/6
#16 lore raw

Re: [PATCH v2 6/6] PCI: hv: Use the correct hypercall for unmasking interrupts on nested

In reply to Nuno Das Neves
Quoted 10 lines · Nuno Das Neves

From: Stanislav Kinsburskii <[email protected]>

Running as nested root on MSHV imposes a different requirement for the pci-hyperv controller.

In this setup, the interrupt will first come to the L1 (nested) hypervisor, which will deliver it to the appropriate root CPU. Instead of issuing the RETARGET hypercall, issue the MAP_DEVICE_INTERRUPT hypercall to L1 to complete the setup.

Quoted 7 lines

Rename hv_arch_irq_unmask() to hv_irq_retarget_interrupt().

Quoted 50 lines
---
 drivers/pci/controller/pci-hyperv.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/pci/controller/pci-hyperv.c +16 -2
index 4d25754dfe2f..9a8cba39ea6b 100644
@@ -600,7 +600,7 @@ static unsigned int hv_msi_get_int_vector(struct irq_data *data)
 #define hv_msi_prepare		pci_msi_prepare
 
 /**
- * hv_arch_irq_unmask() - "Unmask" the IRQ by setting its current
+ * hv_irq_retarget_interrupt() - "Unmask" the IRQ by setting its current
  * affinity.
  * @data:	Describes the IRQ
  *
@@ -609,7 +609,7 @@ static unsigned int hv_msi_get_int_vector(struct irq_data *data)
  * is built out of this PCI bus's instance GUID and the function
  * number of the device.
  */
-static void hv_arch_irq_unmask(struct irq_data *data)
+static void hv_irq_retarget_interrupt(struct irq_data *data)
 {
 	struct msi_desc *msi_desc = irq_data_get_msi_desc(data);
 	struct hv_retarget_device_interrupt *params;
@@ -714,6 +714,20 @@ static void hv_arch_irq_unmask(struct irq_data *data)
 		dev_err(&hbus->hdev->device,
 			"%s() failed: %#llx", __func__, res);
 }
+
+static void hv_arch_irq_unmask(struct irq_data *data)
+{
+	if (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
+		 * RETARGET_INTERRUPT.
+		 */
+		(void)hv_map_msi_interrupt(data, NULL);
+	else
+		hv_irq_retarget_interrupt(data);
+}
 #elif defined(CONFIG_ARM64)
 /*
  * SPI vectors to use for vPCI; arch SPIs range is [32, 1019], but leaving a bit
Signature · 1 line
2.34.1
maintainer
#17 lore raw
In reply to Nuno Das Neves

On Thu, Jul 03, 2025 at 03:44:31PM -0700, Nuno Das Neves wrote:
[...]

Quoted 5 lines

PCI: hv: Don't load the driver for baremetal root partition x86/hyperv: Fix usage of cpu_online_mask to get valid cpu x86/hyperv: Clean up hv_map/unmap_interrupt() return values
PCI: hv: Use the correct hypercall for unmasking interrupts on nested

These are applied to hyperv-fixes.

Quoted 2 lines

Drivers: hv: Use nested hypercall for post message and signal event
x86: hyperv: Expose hv_map_msi_interrupt function

These have pending comments so they are not yet applied.

Wei

maintainer
#18 lore raw
Quoted 8 lines · Wei Liu

On Thu, Jul 03, 2025 at 03:44:31PM -0700, Nuno Das Neves wrote:
[...]

Quoted 5 lines

PCI: hv: Don't load the driver for baremetal root partition x86/hyperv: Fix usage of cpu_online_mask to get valid cpu x86/hyperv: Clean up hv_map/unmap_interrupt() return values
PCI: hv: Use the correct hypercall for unmasking interrupts on nested

Quoted 6 lines

These are applied to hyperv-fixes.

Quoted 2 lines

Drivers: hv: Use nested hypercall for post message and signal event
x86: hyperv: Expose hv_map_msi_interrupt function

These have pending comments so they are not yet applied.

PCI: hv: Use the correct hypercall for unmasking interrupts on nested

This has a dependency on the second dropped patch, so this is also dropped.

Wei