linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/6] Nested virtualization fixes for root partition
@ 2025-07-03 22:44 Nuno Das Neves
  2025-07-03 22:44 ` [PATCH v2 1/6] PCI: hv: Don't load the driver for baremetal " Nuno Das Neves
                   ` (6 more replies)
  0 siblings, 7 replies; 19+ messages in thread
From: Nuno Das Neves @ 2025-07-03 22:44 UTC (permalink / raw)
  To: linux-hyperv, linux-arm-kernel, linux-kernel, linux-pci, mhklinux,
	tglx, bhelgaas, romank
  Cc: kys, haiyangz, wei.liu, decui, catalin.marinas, will, mingo, bp,
	dave.hansen, hpa, lpieralisi, kw, robh, jinankjain, skinsburskii,
	mrathor, x86, Nuno Das Neves

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(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH v2 1/6] PCI: hv: Don't load the driver for baremetal root partition
  2025-07-03 22:44 [PATCH v2 0/6] Nested virtualization fixes for root partition Nuno Das Neves
@ 2025-07-03 22:44 ` Nuno Das Neves
  2025-07-07  3:12   ` Michael Kelley
  2025-07-07 16:04   ` Bjorn Helgaas
  2025-07-03 22:44 ` [PATCH v2 2/6] Drivers: hv: Use nested hypercall for post message and signal event Nuno Das Neves
                   ` (5 subsequent siblings)
  6 siblings, 2 replies; 19+ messages in thread
From: Nuno Das Neves @ 2025-07-03 22:44 UTC (permalink / raw)
  To: linux-hyperv, linux-arm-kernel, linux-kernel, linux-pci, mhklinux,
	tglx, bhelgaas, romank
  Cc: kys, haiyangz, wei.liu, decui, catalin.marinas, will, mingo, bp,
	dave.hansen, hpa, lpieralisi, kw, robh, jinankjain, skinsburskii,
	mrathor, x86, Nuno Das Neves

From: Mukesh Rathor <mrathor@linux.microsoft.com>

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.

Signed-off-by: Mukesh Rathor <mrathor@linux.microsoft.com>
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Reviewed-by: Roman Kisel <romank@linux.microsoft.com>
---
 drivers/pci/controller/pci-hyperv.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
index b4f29ee75848..4d25754dfe2f 100644
--- a/drivers/pci/controller/pci-hyperv.c
+++ b/drivers/pci/controller/pci-hyperv.c
@@ -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;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 2/6] Drivers: hv: Use nested hypercall for post message and signal event
  2025-07-03 22:44 [PATCH v2 0/6] Nested virtualization fixes for root partition Nuno Das Neves
  2025-07-03 22:44 ` [PATCH v2 1/6] PCI: hv: Don't load the driver for baremetal " Nuno Das Neves
@ 2025-07-03 22:44 ` Nuno Das Neves
  2025-07-07  3:13   ` Michael Kelley
  2025-07-03 22:44 ` [PATCH v2 3/6] x86/hyperv: Fix usage of cpu_online_mask to get valid cpu Nuno Das Neves
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 19+ messages in thread
From: Nuno Das Neves @ 2025-07-03 22:44 UTC (permalink / raw)
  To: linux-hyperv, linux-arm-kernel, linux-kernel, linux-pci, mhklinux,
	tglx, bhelgaas, romank
  Cc: kys, haiyangz, wei.liu, decui, catalin.marinas, will, mingo, bp,
	dave.hansen, hpa, lpieralisi, kw, robh, jinankjain, skinsburskii,
	mrathor, x86, 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.

Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Reviewed-by: Roman Kisel <romank@linux.microsoft.com>
---
 arch/x86/include/asm/mshyperv.h | 20 --------------------
 drivers/hv/connection.c         |  7 +++++--
 drivers/hv/hv.c                 |  6 ++++--
 3 files changed, 9 insertions(+), 24 deletions(-)

diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index 5ec92e3e2e37..e00a8431ef8e 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -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)
diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
index be490c598785..47c93cee1ef6 100644
--- a/drivers/hv/connection.c
+++ b/drivers/hv/connection.c
@@ -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);
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index 308c8f279df8..b14c5f9e0ef2 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -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



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 3/6] x86/hyperv: Fix usage of cpu_online_mask to get valid cpu
  2025-07-03 22:44 [PATCH v2 0/6] Nested virtualization fixes for root partition Nuno Das Neves
  2025-07-03 22:44 ` [PATCH v2 1/6] PCI: hv: Don't load the driver for baremetal " Nuno Das Neves
  2025-07-03 22:44 ` [PATCH v2 2/6] Drivers: hv: Use nested hypercall for post message and signal event Nuno Das Neves
@ 2025-07-03 22:44 ` Nuno Das Neves
  2025-07-07  3:13   ` Michael Kelley
  2025-07-03 22:44 ` [PATCH v2 4/6] x86/hyperv: Clean up hv_map/unmap_interrupt() return values Nuno Das Neves
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 19+ messages in thread
From: Nuno Das Neves @ 2025-07-03 22:44 UTC (permalink / raw)
  To: linux-hyperv, linux-arm-kernel, linux-kernel, linux-pci, mhklinux,
	tglx, bhelgaas, romank
  Cc: kys, haiyangz, wei.liu, decui, catalin.marinas, will, mingo, bp,
	dave.hansen, hpa, lpieralisi, kw, robh, jinankjain, skinsburskii,
	mrathor, x86, 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.

Fixes: e39397d1fd68 ("x86/hyperv: implement an MSI domain for root partition")
Reported-by: Michael Kelley <mhklinux@outlook.com>
Closes: https://lore.kernel.org/linux-hyperv/SN6PR02MB4157639630F8AD2D8FD8F52FD475A@SN6PR02MB4157.namprd02.prod.outlook.com/
Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
---
 arch/x86/hyperv/irqdomain.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/x86/hyperv/irqdomain.c b/arch/x86/hyperv/irqdomain.c
index 31f0d29cbc5e..e28c317ac9e8 100644
--- a/arch/x86/hyperv/irqdomain.c
+++ b/arch/x86/hyperv/irqdomain.c
@@ -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) {
 		/*
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 4/6] x86/hyperv: Clean up hv_map/unmap_interrupt() return values
  2025-07-03 22:44 [PATCH v2 0/6] Nested virtualization fixes for root partition Nuno Das Neves
                   ` (2 preceding siblings ...)
  2025-07-03 22:44 ` [PATCH v2 3/6] x86/hyperv: Fix usage of cpu_online_mask to get valid cpu Nuno Das Neves
@ 2025-07-03 22:44 ` Nuno Das Neves
  2025-07-07  3:14   ` Michael Kelley
  2025-07-03 22:44 ` [PATCH v2 5/6] x86: hyperv: Expose hv_map_msi_interrupt function Nuno Das Neves
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 19+ messages in thread
From: Nuno Das Neves @ 2025-07-03 22:44 UTC (permalink / raw)
  To: linux-hyperv, linux-arm-kernel, linux-kernel, linux-pci, mhklinux,
	tglx, bhelgaas, romank
  Cc: kys, haiyangz, wei.liu, decui, catalin.marinas, will, mingo, bp,
	dave.hansen, hpa, lpieralisi, kw, robh, jinankjain, skinsburskii,
	mrathor, x86, 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".

Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
---
 arch/x86/hyperv/irqdomain.c  | 32 ++++++++++++++------------------
 drivers/iommu/hyperv-iommu.c | 33 ++++++++++++---------------------
 2 files changed, 26 insertions(+), 39 deletions(-)

diff --git a/arch/x86/hyperv/irqdomain.c b/arch/x86/hyperv/irqdomain.c
index e28c317ac9e8..75b25724b045 100644
--- a/arch/x86/hyperv/irqdomain.c
+++ b/arch/x86/hyperv/irqdomain.c
@@ -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,
diff --git a/drivers/iommu/hyperv-iommu.c b/drivers/iommu/hyperv-iommu.c
index 761ab647f372..0961ac805944 100644
--- a/drivers/iommu/hyperv-iommu.c
+++ b/drivers/iommu/hyperv-iommu.c
@@ -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);
 		}
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 5/6] x86: hyperv: Expose hv_map_msi_interrupt function
  2025-07-03 22:44 [PATCH v2 0/6] Nested virtualization fixes for root partition Nuno Das Neves
                   ` (3 preceding siblings ...)
  2025-07-03 22:44 ` [PATCH v2 4/6] x86/hyperv: Clean up hv_map/unmap_interrupt() return values Nuno Das Neves
@ 2025-07-03 22:44 ` Nuno Das Neves
  2025-07-07  3:14   ` Michael Kelley
  2025-07-03 22:44 ` [PATCH v2 6/6] PCI: hv: Use the correct hypercall for unmasking interrupts on nested Nuno Das Neves
  2025-07-09 23:51 ` [PATCH v2 0/6] Nested virtualization fixes for root partition Wei Liu
  6 siblings, 1 reply; 19+ messages in thread
From: Nuno Das Neves @ 2025-07-03 22:44 UTC (permalink / raw)
  To: linux-hyperv, linux-arm-kernel, linux-kernel, linux-pci, mhklinux,
	tglx, bhelgaas, romank
  Cc: kys, haiyangz, wei.liu, decui, catalin.marinas, will, mingo, bp,
	dave.hansen, hpa, lpieralisi, kw, robh, jinankjain, skinsburskii,
	mrathor, x86, Nuno Das Neves

From: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>

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.

Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Reviewed-by: Roman Kisel <romank@linux.microsoft.com>
---
 arch/x86/hyperv/irqdomain.c     | 38 +++++++++++++++++++++++----------
 arch/x86/include/asm/mshyperv.h |  2 ++
 2 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/arch/x86/hyperv/irqdomain.c b/arch/x86/hyperv/irqdomain.c
index 75b25724b045..eca015563420 100644
--- a/arch/x86/hyperv/irqdomain.c
+++ b/arch/x86/hyperv/irqdomain.c
@@ -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;
 }
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index e00a8431ef8e..42ea9c68f8c8 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -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



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH v2 6/6] PCI: hv: Use the correct hypercall for unmasking interrupts on nested
  2025-07-03 22:44 [PATCH v2 0/6] Nested virtualization fixes for root partition Nuno Das Neves
                   ` (4 preceding siblings ...)
  2025-07-03 22:44 ` [PATCH v2 5/6] x86: hyperv: Expose hv_map_msi_interrupt function Nuno Das Neves
@ 2025-07-03 22:44 ` Nuno Das Neves
  2025-07-07  3:15   ` Michael Kelley
  2025-07-07 16:05   ` Bjorn Helgaas
  2025-07-09 23:51 ` [PATCH v2 0/6] Nested virtualization fixes for root partition Wei Liu
  6 siblings, 2 replies; 19+ messages in thread
From: Nuno Das Neves @ 2025-07-03 22:44 UTC (permalink / raw)
  To: linux-hyperv, linux-arm-kernel, linux-kernel, linux-pci, mhklinux,
	tglx, bhelgaas, romank
  Cc: kys, haiyangz, wei.liu, decui, catalin.marinas, will, mingo, bp,
	dave.hansen, hpa, lpieralisi, kw, robh, jinankjain, skinsburskii,
	mrathor, x86, Nuno Das Neves

From: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>

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().

Co-developed-by: Jinank Jain <jinankjain@linux.microsoft.com>
Signed-off-by: Jinank Jain <jinankjain@linux.microsoft.com>
Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Reviewed-by: Roman Kisel <romank@linux.microsoft.com>
---
 drivers/pci/controller/pci-hyperv.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
index 4d25754dfe2f..9a8cba39ea6b 100644
--- a/drivers/pci/controller/pci-hyperv.c
+++ b/drivers/pci/controller/pci-hyperv.c
@@ -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
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* RE: [PATCH v2 1/6] PCI: hv: Don't load the driver for baremetal root partition
  2025-07-03 22:44 ` [PATCH v2 1/6] PCI: hv: Don't load the driver for baremetal " Nuno Das Neves
@ 2025-07-07  3:12   ` Michael Kelley
  2025-07-07 16:04   ` Bjorn Helgaas
  1 sibling, 0 replies; 19+ messages in thread
From: Michael Kelley @ 2025-07-07  3:12 UTC (permalink / raw)
  To: Nuno Das Neves, linux-hyperv@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	tglx@linutronix.de, bhelgaas@google.com,
	romank@linux.microsoft.com
  Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
	decui@microsoft.com, catalin.marinas@arm.com, will@kernel.org,
	mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
	hpa@zytor.com, lpieralisi@kernel.org, kw@linux.com,
	robh@kernel.org, jinankjain@linux.microsoft.com,
	skinsburskii@linux.microsoft.com, mrathor@linux.microsoft.com,
	x86@kernel.org

From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent: Thursday, July 3, 2025 3:45 PM
> 
> From: Mukesh Rathor <mrathor@linux.microsoft.com>
> 
> 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.
> 
> Signed-off-by: Mukesh Rathor <mrathor@linux.microsoft.com>
> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
> Reviewed-by: Roman Kisel <romank@linux.microsoft.com>
> ---
>  drivers/pci/controller/pci-hyperv.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
> index b4f29ee75848..4d25754dfe2f 100644
> --- a/drivers/pci/controller/pci-hyperv.c
> +++ b/drivers/pci/controller/pci-hyperv.c
> @@ -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;
> --
> 2.34.1

Reviewed-by: Michael Kelley <mhklinux@outlook.com>



^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: [PATCH v2 2/6] Drivers: hv: Use nested hypercall for post message and signal event
  2025-07-03 22:44 ` [PATCH v2 2/6] Drivers: hv: Use nested hypercall for post message and signal event Nuno Das Neves
@ 2025-07-07  3:13   ` Michael Kelley
  2025-07-07 18:19     ` Nuno Das Neves
  0 siblings, 1 reply; 19+ messages in thread
From: Michael Kelley @ 2025-07-07  3:13 UTC (permalink / raw)
  To: Nuno Das Neves, linux-hyperv@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	tglx@linutronix.de, bhelgaas@google.com,
	romank@linux.microsoft.com
  Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
	decui@microsoft.com, catalin.marinas@arm.com, will@kernel.org,
	mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
	hpa@zytor.com, lpieralisi@kernel.org, kw@linux.com,
	robh@kernel.org, jinankjain@linux.microsoft.com,
	skinsburskii@linux.microsoft.com, mrathor@linux.microsoft.com,
	x86@kernel.org

From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent: Thursday, July 3, 2025 3:45 PM
> 
> 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.
> 
> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
> Reviewed-by: Roman Kisel <romank@linux.microsoft.com>
> ---
>  arch/x86/include/asm/mshyperv.h | 20 --------------------
>  drivers/hv/connection.c         |  7 +++++--
>  drivers/hv/hv.c                 |  6 ++++--
>  3 files changed, 9 insertions(+), 24 deletions(-)
> 
> diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
> index 5ec92e3e2e37..e00a8431ef8e 100644
> --- a/arch/x86/include/asm/mshyperv.h
> +++ b/arch/x86/include/asm/mshyperv.h
> @@ -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)
> diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
> index be490c598785..47c93cee1ef6 100644
> --- a/drivers/hv/connection.c
> +++ b/drivers/hv/connection.c
> @@ -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

> +		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);
> diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
> index 308c8f279df8..b14c5f9e0ef2 100644
> --- a/drivers/hv/hv.c
> +++ b/drivers/hv/hv.c
> @@ -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



^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: [PATCH v2 3/6] x86/hyperv: Fix usage of cpu_online_mask to get valid cpu
  2025-07-03 22:44 ` [PATCH v2 3/6] x86/hyperv: Fix usage of cpu_online_mask to get valid cpu Nuno Das Neves
@ 2025-07-07  3:13   ` Michael Kelley
  0 siblings, 0 replies; 19+ messages in thread
From: Michael Kelley @ 2025-07-07  3:13 UTC (permalink / raw)
  To: Nuno Das Neves, linux-hyperv@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	tglx@linutronix.de, bhelgaas@google.com,
	romank@linux.microsoft.com
  Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
	decui@microsoft.com, catalin.marinas@arm.com, will@kernel.org,
	mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
	hpa@zytor.com, lpieralisi@kernel.org, kw@linux.com,
	robh@kernel.org, jinankjain@linux.microsoft.com,
	skinsburskii@linux.microsoft.com, mrathor@linux.microsoft.com,
	x86@kernel.org

From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent: Thursday, July 3, 2025 3:45 PM
> 
> 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.
> 
> Fixes: e39397d1fd68 ("x86/hyperv: implement an MSI domain for root partition")
> Reported-by: Michael Kelley <mhklinux@outlook.com>
> Closes: https://lore.kernel.org/linux-hyperv/SN6PR02MB4157639630F8AD2D8FD8F52FD475A@SN6PR02MB4157.namprd02.prod.outlook.com/
> Suggested-by: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
> ---
>  arch/x86/hyperv/irqdomain.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/arch/x86/hyperv/irqdomain.c b/arch/x86/hyperv/irqdomain.c
> index 31f0d29cbc5e..e28c317ac9e8 100644
> --- a/arch/x86/hyperv/irqdomain.c
> +++ b/arch/x86/hyperv/irqdomain.c
> @@ -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) {
>  		/*
> --
> 2.34.1

Reviewed-by: Michael Kelley <mhklinux@outlook.com>



^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: [PATCH v2 4/6] x86/hyperv: Clean up hv_map/unmap_interrupt() return values
  2025-07-03 22:44 ` [PATCH v2 4/6] x86/hyperv: Clean up hv_map/unmap_interrupt() return values Nuno Das Neves
@ 2025-07-07  3:14   ` Michael Kelley
  0 siblings, 0 replies; 19+ messages in thread
From: Michael Kelley @ 2025-07-07  3:14 UTC (permalink / raw)
  To: Nuno Das Neves, linux-hyperv@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	tglx@linutronix.de, bhelgaas@google.com,
	romank@linux.microsoft.com
  Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
	decui@microsoft.com, catalin.marinas@arm.com, will@kernel.org,
	mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
	hpa@zytor.com, lpieralisi@kernel.org, kw@linux.com,
	robh@kernel.org, jinankjain@linux.microsoft.com,
	skinsburskii@linux.microsoft.com, mrathor@linux.microsoft.com,
	x86@kernel.org

From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent: Thursday, July 3, 2025 3:45 PM
> 
> 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".
> 
> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
> ---
>  arch/x86/hyperv/irqdomain.c  | 32 ++++++++++++++------------------
>  drivers/iommu/hyperv-iommu.c | 33 ++++++++++++---------------------
>  2 files changed, 26 insertions(+), 39 deletions(-)

Reviewed-by: Michael Kelley <mhklinux@outlook.com>


^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: [PATCH v2 5/6] x86: hyperv: Expose hv_map_msi_interrupt function
  2025-07-03 22:44 ` [PATCH v2 5/6] x86: hyperv: Expose hv_map_msi_interrupt function Nuno Das Neves
@ 2025-07-07  3:14   ` Michael Kelley
  2025-07-07 18:23     ` Nuno Das Neves
  0 siblings, 1 reply; 19+ messages in thread
From: Michael Kelley @ 2025-07-07  3:14 UTC (permalink / raw)
  To: Nuno Das Neves, linux-hyperv@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	tglx@linutronix.de, bhelgaas@google.com,
	romank@linux.microsoft.com
  Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
	decui@microsoft.com, catalin.marinas@arm.com, will@kernel.org,
	mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
	hpa@zytor.com, lpieralisi@kernel.org, kw@linux.com,
	robh@kernel.org, jinankjain@linux.microsoft.com,
	skinsburskii@linux.microsoft.com, mrathor@linux.microsoft.com,
	x86@kernel.org

From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent: Thursday, July 3, 2025 3:45 PM
> 
> From: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
> 
> 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.

> 
> Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
> Reviewed-by: Roman Kisel <romank@linux.microsoft.com>
> ---
>  arch/x86/hyperv/irqdomain.c     | 38 +++++++++++++++++++++++----------
>  arch/x86/include/asm/mshyperv.h |  2 ++
>  2 files changed, 29 insertions(+), 11 deletions(-)
> 
> diff --git a/arch/x86/hyperv/irqdomain.c b/arch/x86/hyperv/irqdomain.c
> index 75b25724b045..eca015563420 100644
> --- a/arch/x86/hyperv/irqdomain.c
> +++ b/arch/x86/hyperv/irqdomain.c
> @@ -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.

> + *
> + * 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;
>  }
> diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
> index e00a8431ef8e..42ea9c68f8c8 100644
> --- a/arch/x86/include/asm/mshyperv.h
> +++ b/arch/x86/include/asm/mshyperv.h
> @@ -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


^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: [PATCH v2 6/6] PCI: hv: Use the correct hypercall for unmasking interrupts on nested
  2025-07-03 22:44 ` [PATCH v2 6/6] PCI: hv: Use the correct hypercall for unmasking interrupts on nested Nuno Das Neves
@ 2025-07-07  3:15   ` Michael Kelley
  2025-07-07 16:05   ` Bjorn Helgaas
  1 sibling, 0 replies; 19+ messages in thread
From: Michael Kelley @ 2025-07-07  3:15 UTC (permalink / raw)
  To: Nuno Das Neves, linux-hyperv@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	tglx@linutronix.de, bhelgaas@google.com,
	romank@linux.microsoft.com
  Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
	decui@microsoft.com, catalin.marinas@arm.com, will@kernel.org,
	mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
	hpa@zytor.com, lpieralisi@kernel.org, kw@linux.com,
	robh@kernel.org, jinankjain@linux.microsoft.com,
	skinsburskii@linux.microsoft.com, mrathor@linux.microsoft.com,
	x86@kernel.org

From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent: Thursday, July 3, 2025 3:45 PM
> 
> From: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
> 
> 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().
> 
> Co-developed-by: Jinank Jain <jinankjain@linux.microsoft.com>
> Signed-off-by: Jinank Jain <jinankjain@linux.microsoft.com>
> Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
> Reviewed-by: Roman Kisel <romank@linux.microsoft.com>
> ---
>  drivers/pci/controller/pci-hyperv.c | 18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
> index 4d25754dfe2f..9a8cba39ea6b 100644
> --- a/drivers/pci/controller/pci-hyperv.c
> +++ b/drivers/pci/controller/pci-hyperv.c
> @@ -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
> --
> 2.34.1

Reviewed-by: Michael Kelley <mhklinux@outlook.com>



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 1/6] PCI: hv: Don't load the driver for baremetal root partition
  2025-07-03 22:44 ` [PATCH v2 1/6] PCI: hv: Don't load the driver for baremetal " Nuno Das Neves
  2025-07-07  3:12   ` Michael Kelley
@ 2025-07-07 16:04   ` Bjorn Helgaas
  1 sibling, 0 replies; 19+ messages in thread
From: Bjorn Helgaas @ 2025-07-07 16:04 UTC (permalink / raw)
  To: Nuno Das Neves
  Cc: linux-hyperv, linux-arm-kernel, linux-kernel, linux-pci, mhklinux,
	tglx, bhelgaas, romank, kys, haiyangz, wei.liu, decui,
	catalin.marinas, will, mingo, bp, dave.hansen, hpa, lpieralisi,
	kw, robh, jinankjain, skinsburskii, mrathor, x86

On Thu, Jul 03, 2025 at 03:44:32PM -0700, Nuno Das Neves wrote:
> From: Mukesh Rathor <mrathor@linux.microsoft.com>
> 
> 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.
> 
> Signed-off-by: Mukesh Rathor <mrathor@linux.microsoft.com>
> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
> Reviewed-by: Roman Kisel <romank@linux.microsoft.com>

Acked-by: Bjorn Helgaas <bhelgaas@google.com>

I assume this series will be merged elsewhere.

> ---
>  drivers/pci/controller/pci-hyperv.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
> index b4f29ee75848..4d25754dfe2f 100644
> --- a/drivers/pci/controller/pci-hyperv.c
> +++ b/drivers/pci/controller/pci-hyperv.c
> @@ -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;
> -- 
> 2.34.1
> 


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 6/6] PCI: hv: Use the correct hypercall for unmasking interrupts on nested
  2025-07-03 22:44 ` [PATCH v2 6/6] PCI: hv: Use the correct hypercall for unmasking interrupts on nested Nuno Das Neves
  2025-07-07  3:15   ` Michael Kelley
@ 2025-07-07 16:05   ` Bjorn Helgaas
  1 sibling, 0 replies; 19+ messages in thread
From: Bjorn Helgaas @ 2025-07-07 16:05 UTC (permalink / raw)
  To: Nuno Das Neves
  Cc: linux-hyperv, linux-arm-kernel, linux-kernel, linux-pci, mhklinux,
	tglx, bhelgaas, romank, kys, haiyangz, wei.liu, decui,
	catalin.marinas, will, mingo, bp, dave.hansen, hpa, lpieralisi,
	kw, robh, jinankjain, skinsburskii, mrathor, x86

On Thu, Jul 03, 2025 at 03:44:37PM -0700, Nuno Das Neves wrote:
> From: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
> 
> 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().
> 
> Co-developed-by: Jinank Jain <jinankjain@linux.microsoft.com>
> Signed-off-by: Jinank Jain <jinankjain@linux.microsoft.com>
> Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
> Reviewed-by: Roman Kisel <romank@linux.microsoft.com>

Acked-by: Bjorn Helgaas <bhelgaas@google.com>

> ---
>  drivers/pci/controller/pci-hyperv.c | 18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
> index 4d25754dfe2f..9a8cba39ea6b 100644
> --- a/drivers/pci/controller/pci-hyperv.c
> +++ b/drivers/pci/controller/pci-hyperv.c
> @@ -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
> -- 
> 2.34.1
> 


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 2/6] Drivers: hv: Use nested hypercall for post message and signal event
  2025-07-07  3:13   ` Michael Kelley
@ 2025-07-07 18:19     ` Nuno Das Neves
  0 siblings, 0 replies; 19+ messages in thread
From: Nuno Das Neves @ 2025-07-07 18:19 UTC (permalink / raw)
  To: Michael Kelley, linux-hyperv@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	tglx@linutronix.de, bhelgaas@google.com,
	romank@linux.microsoft.com
  Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
	decui@microsoft.com, catalin.marinas@arm.com, will@kernel.org,
	mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
	hpa@zytor.com, lpieralisi@kernel.org, kw@linux.com,
	robh@kernel.org, jinankjain@linux.microsoft.com,
	skinsburskii@linux.microsoft.com, mrathor@linux.microsoft.com,
	x86@kernel.org

On 7/6/2025 8:13 PM, Michael Kelley wrote:
> From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent: Thursday, July 3, 2025 3:45 PM
>>
>> 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.
>>
>> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
>> Reviewed-by: Roman Kisel <romank@linux.microsoft.com>
>> ---
>>  arch/x86/include/asm/mshyperv.h | 20 --------------------
>>  drivers/hv/connection.c         |  7 +++++--
>>  drivers/hv/hv.c                 |  6 ++++--
>>  3 files changed, 9 insertions(+), 24 deletions(-)
>>
>> diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
>> index 5ec92e3e2e37..e00a8431ef8e 100644
>> --- a/arch/x86/include/asm/mshyperv.h
>> +++ b/arch/x86/include/asm/mshyperv.h
>> @@ -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)
>> diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
>> index be490c598785..47c93cee1ef6 100644
>> --- a/drivers/hv/connection.c
>> +++ b/drivers/hv/connection.c
>> @@ -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

> 
> Michael
> 
>> +		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);
>> diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
>> index 308c8f279df8..b14c5f9e0ef2 100644
>> --- a/drivers/hv/hv.c
>> +++ b/drivers/hv/hv.c
>> @@ -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



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 5/6] x86: hyperv: Expose hv_map_msi_interrupt function
  2025-07-07  3:14   ` Michael Kelley
@ 2025-07-07 18:23     ` Nuno Das Neves
  0 siblings, 0 replies; 19+ messages in thread
From: Nuno Das Neves @ 2025-07-07 18:23 UTC (permalink / raw)
  To: Michael Kelley, linux-hyperv@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	tglx@linutronix.de, bhelgaas@google.com,
	romank@linux.microsoft.com
  Cc: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
	decui@microsoft.com, catalin.marinas@arm.com, will@kernel.org,
	mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com,
	hpa@zytor.com, lpieralisi@kernel.org, kw@linux.com,
	robh@kernel.org, jinankjain@linux.microsoft.com,
	skinsburskii@linux.microsoft.com, mrathor@linux.microsoft.com,
	x86@kernel.org

On 7/6/2025 8:14 PM, Michael Kelley wrote:
> From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent: Thursday, July 3, 2025 3:45 PM
>>
>> From: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
>>
>> 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 :(

>>
>> Signed-off-by: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>
>> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
>> Reviewed-by: Roman Kisel <romank@linux.microsoft.com>
>> ---
>>  arch/x86/hyperv/irqdomain.c     | 38 +++++++++++++++++++++++----------
>>  arch/x86/include/asm/mshyperv.h |  2 ++
>>  2 files changed, 29 insertions(+), 11 deletions(-)
>>
>> diff --git a/arch/x86/hyperv/irqdomain.c b/arch/x86/hyperv/irqdomain.c
>> index 75b25724b045..eca015563420 100644
>> --- a/arch/x86/hyperv/irqdomain.c
>> +++ b/arch/x86/hyperv/irqdomain.c
>> @@ -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.
> 
>> + *
>> + * 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;
>>  }
>> diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
>> index e00a8431ef8e..42ea9c68f8c8 100644
>> --- a/arch/x86/include/asm/mshyperv.h
>> +++ b/arch/x86/include/asm/mshyperv.h
>> @@ -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


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 0/6] Nested virtualization fixes for root partition
  2025-07-03 22:44 [PATCH v2 0/6] Nested virtualization fixes for root partition Nuno Das Neves
                   ` (5 preceding siblings ...)
  2025-07-03 22:44 ` [PATCH v2 6/6] PCI: hv: Use the correct hypercall for unmasking interrupts on nested Nuno Das Neves
@ 2025-07-09 23:51 ` Wei Liu
  2025-07-10  0:33   ` Wei Liu
  6 siblings, 1 reply; 19+ messages in thread
From: Wei Liu @ 2025-07-09 23:51 UTC (permalink / raw)
  To: Nuno Das Neves
  Cc: linux-hyperv, linux-arm-kernel, linux-kernel, linux-pci, mhklinux,
	tglx, bhelgaas, romank, kys, haiyangz, wei.liu, decui,
	catalin.marinas, will, mingo, bp, dave.hansen, hpa, lpieralisi,
	kw, robh, jinankjain, skinsburskii, mrathor, x86

On Thu, Jul 03, 2025 at 03:44:31PM -0700, Nuno Das Neves wrote:
[...]
>   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.

>   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


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v2 0/6] Nested virtualization fixes for root partition
  2025-07-09 23:51 ` [PATCH v2 0/6] Nested virtualization fixes for root partition Wei Liu
@ 2025-07-10  0:33   ` Wei Liu
  0 siblings, 0 replies; 19+ messages in thread
From: Wei Liu @ 2025-07-10  0:33 UTC (permalink / raw)
  To: Nuno Das Neves
  Cc: linux-hyperv, linux-arm-kernel, linux-kernel, linux-pci, mhklinux,
	tglx, bhelgaas, romank, kys, haiyangz, wei.liu, decui,
	catalin.marinas, will, mingo, bp, dave.hansen, hpa, lpieralisi,
	kw, robh, jinankjain, skinsburskii, mrathor, x86

On Wed, Jul 09, 2025 at 11:51:19PM +0000, Wei Liu wrote:
> On Thu, Jul 03, 2025 at 03:44:31PM -0700, Nuno Das Neves wrote:
> [...]
> >   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.
> 
> >   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


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2025-07-10  1:06 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-03 22:44 [PATCH v2 0/6] Nested virtualization fixes for root partition Nuno Das Neves
2025-07-03 22:44 ` [PATCH v2 1/6] PCI: hv: Don't load the driver for baremetal " Nuno Das Neves
2025-07-07  3:12   ` Michael Kelley
2025-07-07 16:04   ` Bjorn Helgaas
2025-07-03 22:44 ` [PATCH v2 2/6] Drivers: hv: Use nested hypercall for post message and signal event Nuno Das Neves
2025-07-07  3:13   ` Michael Kelley
2025-07-07 18:19     ` Nuno Das Neves
2025-07-03 22:44 ` [PATCH v2 3/6] x86/hyperv: Fix usage of cpu_online_mask to get valid cpu Nuno Das Neves
2025-07-07  3:13   ` Michael Kelley
2025-07-03 22:44 ` [PATCH v2 4/6] x86/hyperv: Clean up hv_map/unmap_interrupt() return values Nuno Das Neves
2025-07-07  3:14   ` Michael Kelley
2025-07-03 22:44 ` [PATCH v2 5/6] x86: hyperv: Expose hv_map_msi_interrupt function Nuno Das Neves
2025-07-07  3:14   ` Michael Kelley
2025-07-07 18:23     ` Nuno Das Neves
2025-07-03 22:44 ` [PATCH v2 6/6] PCI: hv: Use the correct hypercall for unmasking interrupts on nested Nuno Das Neves
2025-07-07  3:15   ` Michael Kelley
2025-07-07 16:05   ` Bjorn Helgaas
2025-07-09 23:51 ` [PATCH v2 0/6] Nested virtualization fixes for root partition Wei Liu
2025-07-10  0:33   ` Wei Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).