Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2547750rwb; Thu, 17 Nov 2022 12:22:09 -0800 (PST) X-Google-Smtp-Source: AA0mqf4JwLxwnFL1z0uv1aVa8BUdPQC0rTV8dvl0GNb+3ZZrrwgJ5bkryXCgLYj8icMXA9fWBiSq X-Received: by 2002:a62:cd8f:0:b0:563:321a:9155 with SMTP id o137-20020a62cd8f000000b00563321a9155mr4560010pfg.46.1668716529063; Thu, 17 Nov 2022 12:22:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668716529; cv=none; d=google.com; s=arc-20160816; b=WkMEngU/R5xW77+U5F5FnUj2AM+E/lCaNWuUKEVnOqfuC33P6UwKAD5HuxzJu6qZks x/Lr2EST86H4+eqWtmR9cEcD1hkTF7E5GE7ftZ9Qmy8pRBs9JiABFk2JTik8dS+ZfEbm //Ns0WxvKhoq27tYaEzIo+TcHx3eyI69PVHNq8199LEBC7PQOHts+OG0+X9MAdFfuJkl p65/56sswR/Bpsv2pCPx9u6RU3CFpaJ/YJULKVyg3RoHSIxD3YXiJOtjnKA6WqGabwkX Famuuf8SsLXmy93XipHiMbs8Szgds8U94cvRoy5KsyMUmKLyaYUQ9TFJcBN6rw1w3N/C f1Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=wa9uP9wabMDKDkEi7yCMCeF3v/U9yuY0CAIcQrCpuoU=; b=L/e/tKuqC92gjeCKlXMZeWkbB45HauRV9liADAW4k22JfK8xY7YVCDZL6cf4p/pG+Q AJgoIP+Lq0px90NJvUv94NEdqAYPEbvMMWCUGPqG/MGALblyQH9qMzAbohZlDKHnvAEg G3qL6OL43jqEIAb2N0hhmw/paseoG/sKb44IrlAOyQBPfWfzi/8vNf8+hdJgUMug7KCd Kk7Zn+6wXrEN/tcYyV1/KpVCvNqkTT1OOSq2lllEzRA0gD28sUborJzd0FrcVET6mLik SIiqj7rzcoShfmR8PO57MDarCxvZn6G8BCObOmcWqtRl6Ig3U9aKTNL2RC8gvc/v1LyW SkRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Gu6zLkUq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 203-20020a6302d4000000b0046f3dfb9789si1895759pgc.477.2022.11.17.12.21.57; Thu, 17 Nov 2022 12:22:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Gu6zLkUq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235037AbiKQULs (ORCPT + 92 others); Thu, 17 Nov 2022 15:11:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232330AbiKQULq (ORCPT ); Thu, 17 Nov 2022 15:11:46 -0500 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BF0977DED9; Thu, 17 Nov 2022 12:11:45 -0800 (PST) Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 7798620B6C40; Thu, 17 Nov 2022 12:11:45 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7798620B6C40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1668715905; bh=wa9uP9wabMDKDkEi7yCMCeF3v/U9yuY0CAIcQrCpuoU=; h=From:To:Cc:Subject:Date:From; b=Gu6zLkUqn/uJuiye/UTwpFsFT0Gmrzz+J9+GgnY9QRxk4itMn63Ey1ubnmU5Xq5n0 BaD8ysJgRDVorR4U4xN5hCpRgDlbWIWTVUr1Upxaq8O3GLO6l82xzuiLF+3JdZ7ZvW AcjguNhb8JmwR8/FfTgQjtQxbl7JPLa+XYvVUq8k= From: Nuno Das Neves To: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev Cc: mikelley@microsoft.com, sunilmut@microsoft.com, wei.liu@kernel.org, kys@microsoft.com, Tianyu.Lan@microsoft.com, haiyangz@microsoft.com, decui@microsoft.com, dwmw2@infradead.org, joro@8bytes.org, will@kernel.org Subject: [PATCH v2] iommu/hyper-v: Allow hyperv irq remapping without x2apic Date: Thu, 17 Nov 2022 12:11:39 -0800 Message-Id: <1668715899-8971-1-git-send-email-nunodasneves@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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