linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] iommu/hyper-v: Allow hyperv irq remapping without x2apic
@ 2022-11-17 20:11 Nuno Das Neves
  2022-11-18  2:41 ` Michael Kelley (LINUX)
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nuno Das Neves @ 2022-11-17 20:11 UTC (permalink / raw)
  To: linux-hyperv, linux-kernel, iommu
  Cc: mikelley, sunilmut, wei.liu, kys, Tianyu.Lan, haiyangz, decui,
	dwmw2, joro, will

If x2apic is not available, hyperv-iommu skips remapping
irqs. This breaks root partition which always needs irqs
remapped.

Fix this by allowing irq remapping regardless of x2apic,
and change hyperv_enable_irq_remapping() to return
IRQ_REMAP_XAPIC_MODE in case x2apic is missing.

Tested with root and non-root hyperv partitions.

Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
---
 arch/x86/kernel/cpu/mshyperv.c |  6 ++++++
 drivers/iommu/Kconfig          |  6 +++---
 drivers/iommu/hyperv-iommu.c   | 11 ++++++++---
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 831613959a92..46668e255421 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -475,6 +475,12 @@ static bool __init ms_hyperv_x2apic_available(void)
  * (logically) generates MSIs directly to the system APIC irq domain.
  * There is no HPET, and PCI MSI/MSI-X interrupts are remapped by the
  * pci-hyperv host bridge.
+ *
+ * Note: for a Hyper-V root partition, this will always return false.
+ * The hypervisor doesn't expose these HYPERV_CPUID_VIRT_STACK_* cpuids by
+ * default, they are implemented as intercepts by the Windows Hyper-V stack.
+ * Even a nested root partition (L2 root) will not get them because the
+ * nested (L1) hypervisor filters them out.
  */
 static bool __init ms_hyperv_msi_ext_dest_id(void)
 {
diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
index dc5f7a156ff5..cf7433652db0 100644
--- a/drivers/iommu/Kconfig
+++ b/drivers/iommu/Kconfig
@@ -474,13 +474,13 @@ config QCOM_IOMMU
 	  Support for IOMMU on certain Qualcomm SoCs.
 
 config HYPERV_IOMMU
-	bool "Hyper-V x2APIC IRQ Handling"
+	bool "Hyper-V IRQ Handling"
 	depends on HYPERV && X86
 	select IOMMU_API
 	default HYPERV
 	help
-	  Stub IOMMU driver to handle IRQs as to allow Hyper-V Linux
-	  guests to run with x2APIC mode enabled.
+	  Stub IOMMU driver to handle IRQs to support Hyper-V Linux
+	  guest and root partitions.
 
 config VIRTIO_IOMMU
 	tristate "Virtio IOMMU driver"
diff --git a/drivers/iommu/hyperv-iommu.c b/drivers/iommu/hyperv-iommu.c
index e190bb8c225c..8302db7f783e 100644
--- a/drivers/iommu/hyperv-iommu.c
+++ b/drivers/iommu/hyperv-iommu.c
@@ -122,9 +122,12 @@ static int __init hyperv_prepare_irq_remapping(void)
 	const char *name;
 	const struct irq_domain_ops *ops;
 
+	/*
+	 * For a Hyper-V root partition, ms_hyperv_msi_ext_dest_id()
+	 * will always return false.
+	 */
 	if (!hypervisor_is_type(X86_HYPER_MS_HYPERV) ||
-	    x86_init.hyper.msi_ext_dest_id() ||
-	    !x2apic_supported())
+	    x86_init.hyper.msi_ext_dest_id())
 		return -ENODEV;
 
 	if (hv_root_partition) {
@@ -170,7 +173,9 @@ static int __init hyperv_prepare_irq_remapping(void)
 
 static int __init hyperv_enable_irq_remapping(void)
 {
-	return IRQ_REMAP_X2APIC_MODE;
+	if (x2apic_supported())
+		return IRQ_REMAP_X2APIC_MODE;
+	return IRQ_REMAP_XAPIC_MODE;
 }
 
 struct irq_remap_ops hyperv_irq_remap_ops = {
-- 
2.25.1


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

* RE: [PATCH v2] iommu/hyper-v: Allow hyperv irq remapping without x2apic
  2022-11-17 20:11 [PATCH v2] iommu/hyper-v: Allow hyperv irq remapping without x2apic Nuno Das Neves
@ 2022-11-18  2:41 ` Michael Kelley (LINUX)
  2022-11-18  3:01 ` Tianyu Lan
  2022-11-18 14:34 ` Wei Liu
  2 siblings, 0 replies; 4+ messages in thread
From: Michael Kelley (LINUX) @ 2022-11-18  2:41 UTC (permalink / raw)
  To: Nuno Das Neves, linux-hyperv@vger.kernel.org,
	linux-kernel@vger.kernel.org, iommu@lists.linux.dev
  Cc: Sunil Muthuswamy, wei.liu@kernel.org, KY Srinivasan, Tianyu Lan,
	Haiyang Zhang, Dexuan Cui, dwmw2@infradead.org, joro@8bytes.org,
	will@kernel.org

From: Nuno Das Neves <nunodasneves@linux.microsoft.com> Sent: Thursday, November 17, 2022 12:12 PM
> 
> If x2apic is not available, hyperv-iommu skips remapping
> irqs. This breaks root partition which always needs irqs
> remapped.
> 
> Fix this by allowing irq remapping regardless of x2apic,
> and change hyperv_enable_irq_remapping() to return
> IRQ_REMAP_XAPIC_MODE in case x2apic is missing.
> 
> Tested with root and non-root hyperv partitions.
> 
> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
> ---
>  arch/x86/kernel/cpu/mshyperv.c |  6 ++++++
>  drivers/iommu/Kconfig          |  6 +++---
>  drivers/iommu/hyperv-iommu.c   | 11 ++++++++---
>  3 files changed, 17 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
> index 831613959a92..46668e255421 100644
> --- a/arch/x86/kernel/cpu/mshyperv.c
> +++ b/arch/x86/kernel/cpu/mshyperv.c
> @@ -475,6 +475,12 @@ static bool __init ms_hyperv_x2apic_available(void)
>   * (logically) generates MSIs directly to the system APIC irq domain.
>   * There is no HPET, and PCI MSI/MSI-X interrupts are remapped by the
>   * pci-hyperv host bridge.
> + *
> + * Note: for a Hyper-V root partition, this will always return false.
> + * The hypervisor doesn't expose these HYPERV_CPUID_VIRT_STACK_* cpuids by
> + * default, they are implemented as intercepts by the Windows Hyper-V stack.
> + * Even a nested root partition (L2 root) will not get them because the
> + * nested (L1) hypervisor filters them out.
>   */
>  static bool __init ms_hyperv_msi_ext_dest_id(void)
>  {
> diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
> index dc5f7a156ff5..cf7433652db0 100644
> --- a/drivers/iommu/Kconfig
> +++ b/drivers/iommu/Kconfig
> @@ -474,13 +474,13 @@ config QCOM_IOMMU
>  	  Support for IOMMU on certain Qualcomm SoCs.
> 
>  config HYPERV_IOMMU
> -	bool "Hyper-V x2APIC IRQ Handling"
> +	bool "Hyper-V IRQ Handling"
>  	depends on HYPERV && X86
>  	select IOMMU_API
>  	default HYPERV
>  	help
> -	  Stub IOMMU driver to handle IRQs as to allow Hyper-V Linux
> -	  guests to run with x2APIC mode enabled.
> +	  Stub IOMMU driver to handle IRQs to support Hyper-V Linux
> +	  guest and root partitions.
> 
>  config VIRTIO_IOMMU
>  	tristate "Virtio IOMMU driver"
> diff --git a/drivers/iommu/hyperv-iommu.c b/drivers/iommu/hyperv-iommu.c
> index e190bb8c225c..8302db7f783e 100644
> --- a/drivers/iommu/hyperv-iommu.c
> +++ b/drivers/iommu/hyperv-iommu.c
> @@ -122,9 +122,12 @@ static int __init hyperv_prepare_irq_remapping(void)
>  	const char *name;
>  	const struct irq_domain_ops *ops;
> 
> +	/*
> +	 * For a Hyper-V root partition, ms_hyperv_msi_ext_dest_id()
> +	 * will always return false.
> +	 */
>  	if (!hypervisor_is_type(X86_HYPER_MS_HYPERV) ||
> -	    x86_init.hyper.msi_ext_dest_id() ||
> -	    !x2apic_supported())
> +	    x86_init.hyper.msi_ext_dest_id())
>  		return -ENODEV;
> 
>  	if (hv_root_partition) {
> @@ -170,7 +173,9 @@ static int __init hyperv_prepare_irq_remapping(void)
> 
>  static int __init hyperv_enable_irq_remapping(void)
>  {
> -	return IRQ_REMAP_X2APIC_MODE;
> +	if (x2apic_supported())
> +		return IRQ_REMAP_X2APIC_MODE;
> +	return IRQ_REMAP_XAPIC_MODE;
>  }
> 
>  struct irq_remap_ops hyperv_irq_remap_ops = {
> --
> 2.25.1

Reviewed-by: Michael Kelley <mikelley@microsoft.com>

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

* Re: [PATCH v2] iommu/hyper-v: Allow hyperv irq remapping without x2apic
  2022-11-17 20:11 [PATCH v2] iommu/hyper-v: Allow hyperv irq remapping without x2apic Nuno Das Neves
  2022-11-18  2:41 ` Michael Kelley (LINUX)
@ 2022-11-18  3:01 ` Tianyu Lan
  2022-11-18 14:34 ` Wei Liu
  2 siblings, 0 replies; 4+ messages in thread
From: Tianyu Lan @ 2022-11-18  3:01 UTC (permalink / raw)
  To: Nuno Das Neves, linux-hyperv, linux-kernel, iommu
  Cc: mikelley, sunilmut, wei.liu, kys, Tianyu.Lan, haiyangz, decui,
	dwmw2, joro, will

On 11/18/2022 4:11 AM, Nuno Das Neves wrote:
> If x2apic is not available, hyperv-iommu skips remapping
> irqs. This breaks root partition which always needs irqs
> remapped.
> 
> Fix this by allowing irq remapping regardless of x2apic,
> and change hyperv_enable_irq_remapping() to return
> IRQ_REMAP_XAPIC_MODE in case x2apic is missing.
> 
> Tested with root and non-root hyperv partitions.
> 
> Signed-off-by: Nuno Das Neves<nunodasneves@linux.microsoft.com>
> ---
>   arch/x86/kernel/cpu/mshyperv.c |  6 ++++++
>   drivers/iommu/Kconfig          |  6 +++---
>   drivers/iommu/hyperv-iommu.c   | 11 ++++++++---
>   3 files changed, 17 insertions(+), 6 deletions(-)


Reviewed-by: Tianyu Lan <Tianyu.Lan@microsoft.com>

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

* Re: [PATCH v2] iommu/hyper-v: Allow hyperv irq remapping without x2apic
  2022-11-17 20:11 [PATCH v2] iommu/hyper-v: Allow hyperv irq remapping without x2apic Nuno Das Neves
  2022-11-18  2:41 ` Michael Kelley (LINUX)
  2022-11-18  3:01 ` Tianyu Lan
@ 2022-11-18 14:34 ` Wei Liu
  2 siblings, 0 replies; 4+ messages in thread
From: Wei Liu @ 2022-11-18 14:34 UTC (permalink / raw)
  To: Nuno Das Neves
  Cc: linux-hyperv, linux-kernel, iommu, mikelley, sunilmut, wei.liu,
	kys, Tianyu.Lan, haiyangz, decui, dwmw2, joro, will

On Thu, Nov 17, 2022 at 12:11:39PM -0800, Nuno Das Neves wrote:
> If x2apic is not available, hyperv-iommu skips remapping
> irqs. This breaks root partition which always needs irqs
> remapped.
> 
> Fix this by allowing irq remapping regardless of x2apic,
> and change hyperv_enable_irq_remapping() to return
> IRQ_REMAP_XAPIC_MODE in case x2apic is missing.
> 
> Tested with root and non-root hyperv partitions.
> 
> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>

Applied to hyperv-next. Thanks.

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

end of thread, other threads:[~2022-11-18 14:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-17 20:11 [PATCH v2] iommu/hyper-v: Allow hyperv irq remapping without x2apic Nuno Das Neves
2022-11-18  2:41 ` Michael Kelley (LINUX)
2022-11-18  3:01 ` Tianyu Lan
2022-11-18 14:34 ` 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).