From patchwork Fri Jul 26 22:59:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kisel X-Patchwork-Id: 13743241 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 568C3C3DA4A for ; Fri, 26 Jul 2024 23:00:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=WFxhd+9RO4zGcRAHUQgDgONPVosLPQEEwR7xsvUdJIE=; b=PoYVqhr7jIUBH9WhhLr4PAQMqq Uk187DhoywKOdLiUQm7q7y4s9Cf5xa6ZIY4od/KK7pb+4PUcyt+By/PoQQ+dtHKxr8JXxFNI4A7Kl APQb8F8GPPFghtcvA2h4b0lGGPPyR01/YOjINQ25uJT9tpO31mIXiaJ0PPF2LUpcG7Lf4jwKs/9Mr DNwrkYUlWgl8VvWSw3EgPbzq3FXetQPHUniS3q5NGCTA6DI+w7/MJA/CkIYSoyX/oNQXaE08A3Jyr GD6QQ5qzizAwETMMgcLx6mtA6uq3XsjRv5CNSzP6vePiTC6n58cwowH8a1ytHC4BUkEkygPUlmi1w YUtQW8HQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXTuo-00000005HU5-34OH; Fri, 26 Jul 2024 22:59:58 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXTuN-00000005HGm-0ioe for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 22:59:32 +0000 Received: from romank-3650.corp.microsoft.com (unknown [131.107.159.62]) by linux.microsoft.com (Postfix) with ESMTPSA id 2ABEC20B7177; Fri, 26 Jul 2024 15:59:28 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2ABEC20B7177 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1722034768; bh=WFxhd+9RO4zGcRAHUQgDgONPVosLPQEEwR7xsvUdJIE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ooH+d9b/veU9GXEUGc1iFPvDL8E0ekXCc57TFGFw0fK31DgQKrUK1o7HmfnsmfYR7 kP//lNqDHHiUgdttFp2PWPsdhVSKaByiDO7b54XFkwFXZZ2x5SJFhHNcZALkVH1efF C4z1JtgXGDyzfqEeQzxZOv+39xhSCGNZ6RsZxvK8= From: Roman Kisel To: arnd@arndb.de, bhelgaas@google.com, bp@alien8.de, catalin.marinas@arm.com, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kw@linux.com, kys@microsoft.com, lenb@kernel.org, lpieralisi@kernel.org, mingo@redhat.com, rafael@kernel.org, robh@kernel.org, tglx@linutronix.de, wei.liu@kernel.org, will@kernel.org, linux-acpi@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, ssengar@microsoft.com, sunilmut@microsoft.com, vdso@hexbites.dev Subject: [PATCH v3 1/7] arm64: hyperv: Use SMC to detect hypervisor presence Date: Fri, 26 Jul 2024 15:59:04 -0700 Message-Id: <20240726225910.1912537-2-romank@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240726225910.1912537-1-romank@linux.microsoft.com> References: <20240726225910.1912537-1-romank@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240726_155931_401744_8E182490 X-CRM114-Status: GOOD ( 15.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The arm64 Hyper-V startup path relies on ACPI to detect running under a Hyper-V compatible hypervisor. That doesn't work on non-ACPI systems. Hoist the ACPI detection logic into a separate function, use the new SMC added recently to Hyper-V to use in the non-ACPI case. Signed-off-by: Roman Kisel Acked-by: Wei Liu --- arch/arm64/hyperv/mshyperv.c | 36 ++++++++++++++++++++++++++----- arch/arm64/include/asm/mshyperv.h | 5 +++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/arch/arm64/hyperv/mshyperv.c b/arch/arm64/hyperv/mshyperv.c index b1a4de4eee29..341f98312667 100644 --- a/arch/arm64/hyperv/mshyperv.c +++ b/arch/arm64/hyperv/mshyperv.c @@ -27,6 +27,34 @@ int hv_get_hypervisor_version(union hv_hypervisor_version_info *info) return 0; } +static bool hyperv_detect_via_acpi(void) +{ + if (acpi_disabled) + return false; +#if IS_ENABLED(CONFIG_ACPI) + /* Hypervisor ID is only available in ACPI v6+. */ + if (acpi_gbl_FADT.header.revision < 6) + return false; + return strncmp((char *)&acpi_gbl_FADT.hypervisor_id, "MsHyperV", 8) == 0; +#else + return false; +#endif +} + +static bool hyperv_detect_via_smc(void) +{ + struct arm_smccc_res res = {}; + + if (arm_smccc_1_1_get_conduit() != SMCCC_CONDUIT_HVC) + return false; + arm_smccc_1_1_hvc(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID, &res); + + return res.a0 == ARM_SMCCC_VENDOR_HYP_UID_HYPERV_REG_0 && + res.a1 == ARM_SMCCC_VENDOR_HYP_UID_HYPERV_REG_1 && + res.a2 == ARM_SMCCC_VENDOR_HYP_UID_HYPERV_REG_2 && + res.a3 == ARM_SMCCC_VENDOR_HYP_UID_HYPERV_REG_3; +} + static int __init hyperv_init(void) { struct hv_get_vp_registers_output result; @@ -35,13 +63,11 @@ static int __init hyperv_init(void) /* * Allow for a kernel built with CONFIG_HYPERV to be running in - * a non-Hyper-V environment, including on DT instead of ACPI. + * a non-Hyper-V environment. + * * In such cases, do nothing and return success. */ - if (acpi_disabled) - return 0; - - if (strncmp((char *)&acpi_gbl_FADT.hypervisor_id, "MsHyperV", 8)) + if (!hyperv_detect_via_acpi() && !hyperv_detect_via_smc()) return 0; /* Setup the guest ID */ diff --git a/arch/arm64/include/asm/mshyperv.h b/arch/arm64/include/asm/mshyperv.h index a975e1a689dd..a7a3586f7cb1 100644 --- a/arch/arm64/include/asm/mshyperv.h +++ b/arch/arm64/include/asm/mshyperv.h @@ -51,4 +51,9 @@ static inline u64 hv_get_msr(unsigned int reg) #include +#define ARM_SMCCC_VENDOR_HYP_UID_HYPERV_REG_0 0x7948734d +#define ARM_SMCCC_VENDOR_HYP_UID_HYPERV_REG_1 0x56726570 +#define ARM_SMCCC_VENDOR_HYP_UID_HYPERV_REG_2 0 +#define ARM_SMCCC_VENDOR_HYP_UID_HYPERV_REG_3 0 + #endif From patchwork Fri Jul 26 22:59:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roman Kisel X-Patchwork-Id: 13743243 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A49C1C3DA4A for ; Fri, 26 Jul 2024 23:01:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6VdNUotlmWFHm4fWqPlZRqwFWjZIXEM8OUM2hq4wFV8=; b=mt4sJewLlqnWoGcluDkEPCmBaL R73vP1n7cGfM6wkUdSR3pAhuv3IAKP+zZIFnt8qMlZEa8czuHMgNKlbPCQIOxCeYWLumdZ2nxqSWX OD4czZE93yEabQl17nJWSHFvODzST9xQhWWmO3BFUEWObD4c5rLRaiVsvCqfN7FkGucbEwzzl8pnp uvKKfOZMAZO1Wx+5OpywDmmuTawYZatWOI9LW4qgosAOGdbrLQOQ+aB57bSEo0FHLqvocle7AA92g l4zkesyzh4K9GNUSQu/sfSBL2ooNtksenh4m/HvbT0V8h8enC7q5HHjEt6e07UTPoJ0Qwrtw1QfKV emFzc4Ag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXTvc-00000005Ht5-1ANu; Fri, 26 Jul 2024 23:00:48 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXTuN-00000005HGn-1eXJ for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 22:59:34 +0000 Received: from romank-3650.corp.microsoft.com (unknown [131.107.159.62]) by linux.microsoft.com (Postfix) with ESMTPSA id 7F9F520B7123; Fri, 26 Jul 2024 15:59:28 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7F9F520B7123 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1722034768; bh=6VdNUotlmWFHm4fWqPlZRqwFWjZIXEM8OUM2hq4wFV8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hwl/+ekNAzQ4Kdaq4mMERTDDqlqxl0CigI9TQpm1Icz7P+UdZ2vWwaHcnLaW10xO/ RP1S4wMYsfZxiLGqP2P/SLt7Bor6CQcy85IpJnVgcsGhnFXMLau7H2DoJv2MglLSa2 EiGuLV8sjO9gG8eRpncI47xmIFVSLitwz53M+xAk= From: Roman Kisel To: arnd@arndb.de, bhelgaas@google.com, bp@alien8.de, catalin.marinas@arm.com, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kw@linux.com, kys@microsoft.com, lenb@kernel.org, lpieralisi@kernel.org, mingo@redhat.com, rafael@kernel.org, robh@kernel.org, tglx@linutronix.de, wei.liu@kernel.org, will@kernel.org, linux-acpi@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, ssengar@microsoft.com, sunilmut@microsoft.com, vdso@hexbites.dev Subject: [PATCH v3 2/7] Drivers: hv: Enable VTL mode for arm64 Date: Fri, 26 Jul 2024 15:59:05 -0700 Message-Id: <20240726225910.1912537-3-romank@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240726225910.1912537-1-romank@linux.microsoft.com> References: <20240726225910.1912537-1-romank@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240726_155931_563988_E3075475 X-CRM114-Status: GOOD ( 14.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Kconfig dependencies for arm64 guests on Hyper-V require that be ACPI enabled, and limit VTL mode to x86/x64. To enable VTL mode on arm64 as well, update the dependencies. Since VTL mode requires DeviceTree instead of ACPI, don’t require arm64 guests on Hyper-V to have ACPI. Signed-off-by: Roman Kisel Acked-by: Wei Liu --- drivers/hv/Kconfig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/hv/Kconfig b/drivers/hv/Kconfig index 862c47b191af..a5cd1365e248 100644 --- a/drivers/hv/Kconfig +++ b/drivers/hv/Kconfig @@ -5,7 +5,7 @@ menu "Microsoft Hyper-V guest support" config HYPERV tristate "Microsoft Hyper-V client drivers" depends on (X86 && X86_LOCAL_APIC && HYPERVISOR_GUEST) \ - || (ACPI && ARM64 && !CPU_BIG_ENDIAN) + || (ARM64 && !CPU_BIG_ENDIAN) select PARAVIRT select X86_HV_CALLBACK_VECTOR if X86 select OF_EARLY_FLATTREE if OF @@ -15,7 +15,7 @@ config HYPERV config HYPERV_VTL_MODE bool "Enable Linux to boot in VTL context" - depends on X86_64 && HYPERV + depends on HYPERV depends on SMP default n help @@ -31,7 +31,7 @@ config HYPERV_VTL_MODE Select this option to build a Linux kernel to run at a VTL other than the normal VTL0, which currently is only VTL2. This option - initializes the x86 platform for VTL2, and adds the ability to boot + initializes the kernel to run in VTL2, and adds the ability to boot secondary CPUs directly into 64-bit context as required for VTLs other than 0. A kernel built with this option must run at VTL2, and will not run as a normal guest. From patchwork Fri Jul 26 22:59:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kisel X-Patchwork-Id: 13743246 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0C163C3DA4A for ; Fri, 26 Jul 2024 23:02:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=aGtuuS44L1FWxWnw8aopWoYtUuyOCwVC3o0rFEImRa4=; b=HxO7sc13jVdxTkYJ8kCyPt4KYM xaYMgTtbn9hXwrPbLJmNmSdughpLllzMLIOM/g+wB/6v4wI2M8C1fvYYsCWNagefsaPlnpWc0ctdW KsVkYQtlPXyiOIH8fdysBzneqQw5E/Ihdc6GDxtLFlbqm7iH3Ml/JJBXiCOPE3yfTQrkMrSSTXQt+ /dsY54tH/Riarfcvm63RkOBSj1/lxoqqox0xFqkpA7BOXyBCXqhOwgmQZFrN0si7AQWghlGsRpVSh 7/yDPTE0vl6pMa6Wpu7xMfqZ8o6Psk8ysgAYHHOb82HhK4gv0TCp+BLRMpp8Ngt/9uJdxcodPAaBY MGbQfGnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXTwm-00000005INm-0icH; Fri, 26 Jul 2024 23:02:00 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXTuN-00000005HGo-1PkQ for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 22:59:35 +0000 Received: from romank-3650.corp.microsoft.com (unknown [131.107.159.62]) by linux.microsoft.com (Postfix) with ESMTPSA id CEE3D20B7127; Fri, 26 Jul 2024 15:59:28 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com CEE3D20B7127 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1722034769; bh=aGtuuS44L1FWxWnw8aopWoYtUuyOCwVC3o0rFEImRa4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ay3ecAMlZzDzgdbwBOPeo/Jmf+KSFKuylv/Gf8gJBwUBwig9q2NhLAemzcG8ltPRV riKWHkp6130fkaOD9K/juYHtqmScjVjRoViUv5axRYPSEg0VFSVX6skSaUTMvxBk2Q Ct6fnu6En2IfZdKnhQbhNCdtbi3flTO7AuplpWoQ= From: Roman Kisel To: arnd@arndb.de, bhelgaas@google.com, bp@alien8.de, catalin.marinas@arm.com, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kw@linux.com, kys@microsoft.com, lenb@kernel.org, lpieralisi@kernel.org, mingo@redhat.com, rafael@kernel.org, robh@kernel.org, tglx@linutronix.de, wei.liu@kernel.org, will@kernel.org, linux-acpi@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, ssengar@microsoft.com, sunilmut@microsoft.com, vdso@hexbites.dev Subject: [PATCH v3 3/7] Drivers: hv: Provide arch-neutral implementation of get_vtl() Date: Fri, 26 Jul 2024 15:59:06 -0700 Message-Id: <20240726225910.1912537-4-romank@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240726225910.1912537-1-romank@linux.microsoft.com> References: <20240726225910.1912537-1-romank@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240726_155931_586868_49B04CBC X-CRM114-Status: GOOD ( 23.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org To run in the VTL mode, Hyper-V drivers have to know what VTL the system boots in, and the arm64/hyperv code does not have the means to compute that. Refactor the code to hoist the function that detects VTL, make it arch-neutral to be able to employ it to get the VTL on arm64. Fix the hypercall output address in `get_vtl(void)` not to overlap with the hypercall input area to adhere to the Hyper-V TLFS. Signed-off-by: Roman Kisel --- arch/x86/hyperv/hv_init.c | 34 --------------------- arch/x86/include/asm/hyperv-tlfs.h | 7 ----- drivers/hv/hv_common.c | 47 ++++++++++++++++++++++++++++-- include/asm-generic/hyperv-tlfs.h | 7 +++++ include/asm-generic/mshyperv.h | 6 ++++ 5 files changed, 58 insertions(+), 43 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 17a71e92a343..c350fa05ee59 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -413,40 +413,6 @@ static void __init hv_get_partition_id(void) local_irq_restore(flags); } -#if IS_ENABLED(CONFIG_HYPERV_VTL_MODE) -static u8 __init get_vtl(void) -{ - u64 control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_REGISTERS; - struct hv_get_vp_registers_input *input; - struct hv_get_vp_registers_output *output; - unsigned long flags; - u64 ret; - - local_irq_save(flags); - input = *this_cpu_ptr(hyperv_pcpu_input_arg); - output = (struct hv_get_vp_registers_output *)input; - - memset(input, 0, struct_size(input, element, 1)); - input->header.partitionid = HV_PARTITION_ID_SELF; - input->header.vpindex = HV_VP_INDEX_SELF; - input->header.inputvtl = 0; - input->element[0].name0 = HV_X64_REGISTER_VSM_VP_STATUS; - - ret = hv_do_hypercall(control, input, output); - if (hv_result_success(ret)) { - ret = output->as64.low & HV_X64_VTL_MASK; - } else { - pr_err("Failed to get VTL(error: %lld) exiting...\n", ret); - BUG(); - } - - local_irq_restore(flags); - return ret; -} -#else -static inline u8 get_vtl(void) { return 0; } -#endif - /* * This function is to be invoked early in the boot sequence after the * hypervisor has been detected. diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index 3787d26810c1..9ee68eb8e6ff 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -309,13 +309,6 @@ enum hv_isolation_type { #define HV_MSR_STIMER0_CONFIG (HV_X64_MSR_STIMER0_CONFIG) #define HV_MSR_STIMER0_COUNT (HV_X64_MSR_STIMER0_COUNT) -/* - * Registers are only accessible via HVCALL_GET_VP_REGISTERS hvcall and - * there is not associated MSR address. - */ -#define HV_X64_REGISTER_VSM_VP_STATUS 0x000D0003 -#define HV_X64_VTL_MASK GENMASK(3, 0) - /* Hyper-V memory host visibility */ enum hv_mem_host_visibility { VMBUS_PAGE_NOT_VISIBLE = 0, diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c index 9c452bfbd571..7d6c1523b0b5 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -339,8 +339,8 @@ int __init hv_common_init(void) hyperv_pcpu_input_arg = alloc_percpu(void *); BUG_ON(!hyperv_pcpu_input_arg); - /* Allocate the per-CPU state for output arg for root */ - if (hv_root_partition) { + /* Allocate the per-CPU state for output arg for root or a VTL */ + if (hv_root_partition || IS_ENABLED(CONFIG_HYPERV_VTL_MODE)) { hyperv_pcpu_output_arg = alloc_percpu(void *); BUG_ON(!hyperv_pcpu_output_arg); } @@ -656,3 +656,46 @@ u64 __weak hv_tdx_hypercall(u64 control, u64 param1, u64 param2) return HV_STATUS_INVALID_PARAMETER; } EXPORT_SYMBOL_GPL(hv_tdx_hypercall); + +#if IS_ENABLED(CONFIG_HYPERV_VTL_MODE) +u8 __init get_vtl(void) +{ + u64 control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_REGISTERS; + struct hv_get_vp_registers_input *input; + struct hv_get_vp_registers_output *output; + unsigned long flags; + u64 ret; + + local_irq_save(flags); + input = *this_cpu_ptr(hyperv_pcpu_input_arg); + output = *this_cpu_ptr(hyperv_pcpu_output_arg); + + memset(input, 0, struct_size(input, element, 1)); + input->header.partitionid = HV_PARTITION_ID_SELF; + input->header.vpindex = HV_VP_INDEX_SELF; + input->header.inputvtl = 0; + input->element[0].name0 = HV_REGISTER_VSM_VP_STATUS; + + ret = hv_do_hypercall(control, input, output); + if (hv_result_success(ret)) { + ret = output->as64.low & HV_VTL_MASK; + } else { + pr_err("Failed to get VTL(error: %lld) exiting...\n", ret); + + /* + * This is a dead end, something fundamental is broken. + * + * There is no sensible way of continuing as the Hyper-V drivers + * transitively depend via the vmbus driver on knowing which VTL + * they run in to establish communication with the host. The kernel + * is going to be worse off if continued booting than a panicked one, + * just hung and stuck, producing second-order failures, with neither + * a way to recover nor to provide expected services. + */ + BUG(); + } + + local_irq_restore(flags); + return ret; +} +#endif diff --git a/include/asm-generic/hyperv-tlfs.h b/include/asm-generic/hyperv-tlfs.h index 814207e7c37f..271c365973d6 100644 --- a/include/asm-generic/hyperv-tlfs.h +++ b/include/asm-generic/hyperv-tlfs.h @@ -75,6 +75,13 @@ /* AccessTscInvariantControls privilege */ #define HV_ACCESS_TSC_INVARIANT BIT(15) +/* + * This synthetic register is only accessible via the HVCALL_GET_VP_REGISTERS + * hvcall, and there is no an associated MSR on x86. + */ +#define HV_REGISTER_VSM_VP_STATUS 0x000D0003 +#define HV_VTL_MASK GENMASK(3, 0) + /* * Group B features. */ diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index 8fe7aaab2599..85a5b8cb1702 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -315,4 +315,10 @@ static inline enum hv_isolation_type hv_get_isolation_type(void) } #endif /* CONFIG_HYPERV */ +#if IS_ENABLED(CONFIG_HYPERV_VTL_MODE) +u8 __init get_vtl(void); +#else +static inline u8 get_vtl(void) { return 0; } +#endif + #endif From patchwork Fri Jul 26 22:59:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kisel X-Patchwork-Id: 13743244 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 922FEC3DA4A for ; Fri, 26 Jul 2024 23:01:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=tmxjj8vso9v/ojCxB2Cygc/rP9hc2qP1BIOw38tT1zE=; b=b0KFKhixw+btHROOvVPdA/9ffx 9lbk3V+HxlJZeMIHZJex5QX3nlqUT6RwRf3e5QK8+Q7OBc5Q0BUUU4fPSFIrUmKW3y8QJFt4hqNzf DmU0zj55BGXFnRJrySAQVA+KxkAKb8GOWl2MshxzIF8Cu0M9EgKyQ1DxK6SLrWXtSG94MYddz/NXa 8aciqvt9hc44Fon2weC8LChzdhDR9z0rdtLOHqkCmLpQSYjYZW1pCZUiTn0JQZ0UDY6QODg373oLH uFaNup9/sW3xuwLSxs8MxIfh0ulX/B2yNB4HtigBN7ubwvZWfHioOQKDYPfrFq5yyf47KQ9qTGrMP kz73sSaA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXTvz-00000005I1K-4B6J; Fri, 26 Jul 2024 23:01:12 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXTuN-00000005HGt-27Bm for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 22:59:34 +0000 Received: from romank-3650.corp.microsoft.com (unknown [131.107.159.62]) by linux.microsoft.com (Postfix) with ESMTPSA id 2BD6420B712C; Fri, 26 Jul 2024 15:59:29 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2BD6420B712C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1722034769; bh=tmxjj8vso9v/ojCxB2Cygc/rP9hc2qP1BIOw38tT1zE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HrFS4gQA63f9ZtXluPQS6xKLvJ9iGcheKqe8qXFGmxALOaJxtC3mt7lByp/kfPsWG CorAVbwGjB2BghmnQvGHqY48CpEoYMi2x1oIf9LwIn3qH8lFQpxWB1QsjcsCDHwm89 wjRy4XLGbPrRbKVDtla62/DUxosA9UgmY8vwKAxE= From: Roman Kisel To: arnd@arndb.de, bhelgaas@google.com, bp@alien8.de, catalin.marinas@arm.com, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kw@linux.com, kys@microsoft.com, lenb@kernel.org, lpieralisi@kernel.org, mingo@redhat.com, rafael@kernel.org, robh@kernel.org, tglx@linutronix.de, wei.liu@kernel.org, will@kernel.org, linux-acpi@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, ssengar@microsoft.com, sunilmut@microsoft.com, vdso@hexbites.dev Subject: [PATCH v3 4/7] arm64: hyperv: Boot in a Virtual Trust Level Date: Fri, 26 Jul 2024 15:59:07 -0700 Message-Id: <20240726225910.1912537-5-romank@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240726225910.1912537-1-romank@linux.microsoft.com> References: <20240726225910.1912537-1-romank@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240726_155931_728584_7CB76117 X-CRM114-Status: GOOD ( 17.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org To run in the VTL mode, Hyper-V drivers have to know what VTL the system boots in, and the arm64/hyperv code does not update the variable that stores the value. Update the variable to enable the Hyper-V drivers to boot in the VTL mode and print the VTL the code runs in. Signed-off-by: Roman Kisel --- arch/arm64/hyperv/Makefile | 1 + arch/arm64/hyperv/hv_vtl.c | 13 +++++++++++++ arch/arm64/hyperv/mshyperv.c | 4 ++++ arch/arm64/include/asm/mshyperv.h | 7 +++++++ 4 files changed, 25 insertions(+) create mode 100644 arch/arm64/hyperv/hv_vtl.c diff --git a/arch/arm64/hyperv/Makefile b/arch/arm64/hyperv/Makefile index 87c31c001da9..9701a837a6e1 100644 --- a/arch/arm64/hyperv/Makefile +++ b/arch/arm64/hyperv/Makefile @@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0 obj-y := hv_core.o mshyperv.o +obj-$(CONFIG_HYPERV_VTL_MODE) += hv_vtl.o diff --git a/arch/arm64/hyperv/hv_vtl.c b/arch/arm64/hyperv/hv_vtl.c new file mode 100644 index 000000000000..38642b7b6be0 --- /dev/null +++ b/arch/arm64/hyperv/hv_vtl.c @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2024, Microsoft, Inc. + * + * Author : Roman Kisel + */ + +#include + +void __init hv_vtl_init_platform(void) +{ + pr_info("Linux runs in Hyper-V Virtual Trust Level\n"); +} diff --git a/arch/arm64/hyperv/mshyperv.c b/arch/arm64/hyperv/mshyperv.c index 341f98312667..8fd04d6e4800 100644 --- a/arch/arm64/hyperv/mshyperv.c +++ b/arch/arm64/hyperv/mshyperv.c @@ -98,6 +98,10 @@ static int __init hyperv_init(void) return ret; } + /* Find the VTL */ + ms_hyperv.vtl = get_vtl(); + hv_vtl_init_platform(); + ms_hyperv_late_init(); hyperv_initialized = true; diff --git a/arch/arm64/include/asm/mshyperv.h b/arch/arm64/include/asm/mshyperv.h index a7a3586f7cb1..63d6bb6998fc 100644 --- a/arch/arm64/include/asm/mshyperv.h +++ b/arch/arm64/include/asm/mshyperv.h @@ -49,6 +49,13 @@ static inline u64 hv_get_msr(unsigned int reg) ARM_SMCCC_OWNER_VENDOR_HYP, \ HV_SMCCC_FUNC_NUMBER) +#ifdef CONFIG_HYPERV_VTL_MODE +void __init hv_vtl_init_platform(void); +int __init hv_vtl_early_init(void); +#else +static inline void __init hv_vtl_init_platform(void) {} +#endif + #include #define ARM_SMCCC_VENDOR_HYP_UID_HYPERV_REG_0 0x7948734d From patchwork Fri Jul 26 22:59:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kisel X-Patchwork-Id: 13743247 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 661DAC3DA4A for ; Fri, 26 Jul 2024 23:02:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=3Zon5hZ0mew9TRjycUlDXro0yNveA6eiZCkGV3Hxyd0=; b=AnhH7D4PVAxV7qwUdjTi64hCFx 1uq05Zua5cX80a9bdxGfjqaQf2iLWJ/sNJkvvKo3ztf44ZBU7V8z7I4P4oD3c253RdHiPXY/QfIsI tCaRmCCWt71xQ7zwA/Ppn7bR9Jl9Tcfc9hGEzHBaseXTnTJ/JjdhwqTa9Q3Tt/wXsIlNp5+UGcb5r QZkv1BbZjIx77ZkseNzTW74d9DDzFb1dPGMmY5kBR6hoaCw4WUCH8NjbeCpe7BM0/0P0lgqQIyaBE oqRLzLHbe4ewwPZNgHI2JeGWS6m0JMR6eA5Dv0DwZX+byFIK1GA6jidqqPWW+7nN1J5C+bUzt9CvZ AcMPQ6Zw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXTx9-00000005IXh-25rL; Fri, 26 Jul 2024 23:02:23 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXTuP-00000005HIg-3Jtp for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 22:59:35 +0000 Received: from romank-3650.corp.microsoft.com (unknown [131.107.159.62]) by linux.microsoft.com (Postfix) with ESMTPSA id 7DBB320B712E; Fri, 26 Jul 2024 15:59:29 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7DBB320B712E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1722034769; bh=3Zon5hZ0mew9TRjycUlDXro0yNveA6eiZCkGV3Hxyd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J5prU8uA8W9Fh/XGljE+RdoZ2/4cUP5LuHI94mtaUlgcOIIdnAiocnovfe1FK5uU6 mNe/0gXVIoDEDdG2dgwK3xyct8+ItfE8fOU4DJwm0E4fZoGFQcChlz9TtXW3OSZGaH yEonssCXnQ2peGTMzD4I3nK5oegU73q1kLATcB3U= From: Roman Kisel To: arnd@arndb.de, bhelgaas@google.com, bp@alien8.de, catalin.marinas@arm.com, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kw@linux.com, kys@microsoft.com, lenb@kernel.org, lpieralisi@kernel.org, mingo@redhat.com, rafael@kernel.org, robh@kernel.org, tglx@linutronix.de, wei.liu@kernel.org, will@kernel.org, linux-acpi@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, ssengar@microsoft.com, sunilmut@microsoft.com, vdso@hexbites.dev Subject: [PATCH v3 5/7] dt-bindings: bus: Add Hyper-V VMBus cache coherency and IRQs Date: Fri, 26 Jul 2024 15:59:08 -0700 Message-Id: <20240726225910.1912537-6-romank@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240726225910.1912537-1-romank@linux.microsoft.com> References: <20240726225910.1912537-1-romank@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240726_155933_951356_4A0C3426 X-CRM114-Status: UNSURE ( 7.81 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add dt-bindings for the Hyper-V VMBus DMA cache coherency and interrupt specification. Signed-off-by: Roman Kisel --- .../devicetree/bindings/bus/microsoft,vmbus.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/devicetree/bindings/bus/microsoft,vmbus.yaml b/Documentation/devicetree/bindings/bus/microsoft,vmbus.yaml index a8d40c766dcd..5ec69226ab85 100644 --- a/Documentation/devicetree/bindings/bus/microsoft,vmbus.yaml +++ b/Documentation/devicetree/bindings/bus/microsoft,vmbus.yaml @@ -44,11 +44,22 @@ examples: #size-cells = <1>; ranges; + gic: intc@fe200000 { + compatible = "arm,gic-v3"; + reg = <0x0 0xfe200000 0x0 0x10000>, /* GIC Dist */ + <0x0 0xfe280000 0x0 0x200000>; /* GICR */ + interrupt-controller; + #interrupt-cells = <3>; + } + vmbus@ff0000000 { compatible = "microsoft,vmbus"; #address-cells = <2>; #size-cells = <1>; ranges = <0x0f 0xf0000000 0x0f 0xf0000000 0x10000000>; + dma-coherent; + interrupt-parent = <&gic>; + interrupts = <1 2 1>; }; }; }; From patchwork Fri Jul 26 22:59:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kisel X-Patchwork-Id: 13743245 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 14BDAC3DA49 for ; Fri, 26 Jul 2024 23:01:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=4vaIu2cEtSVp+bjNc+RfZaBe8pNFl4ohmrBuqhrOtgc=; b=v3Cge4uw/DfX0/1z6Ra/IRkX6u LmT0WtgeczAi67828AnGJUFLbACJmZ7ZKzymYEwWPRDqIhrIi8KDiV9HJ/Njazm5hM1TIkp5p9oPv tfwaqEtvW7Nb0WcNfanlqoobtNBajy2bBqeMBFbDJXmvKQAeO7bykOyZ7rPE9CaAyBq8pwqa8U004 LFMUHLliP8xlTKdxzv26pPDIEEuqPMIEclyk5h+e7VgTH0JyeZTxU+qVpDXIQEWMlzaMHRIwHUnmV hJTFZ9aRg9KfE+MuzQ3fZ3Es18s/ak2Htmm/e07ZQkCGKVJQTJkjenffCVBn5vxIfdSG/wLFAMMlb J7qbhJVg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXTwN-00000005IDD-336l; Fri, 26 Jul 2024 23:01:35 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXTuP-00000005HIa-22gX for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 22:59:34 +0000 Received: from romank-3650.corp.microsoft.com (unknown [131.107.159.62]) by linux.microsoft.com (Postfix) with ESMTPSA id CBF7D20B7131; Fri, 26 Jul 2024 15:59:29 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com CBF7D20B7131 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1722034770; bh=4vaIu2cEtSVp+bjNc+RfZaBe8pNFl4ohmrBuqhrOtgc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ifls2ATr8KECM4bvDJ5IAeXj1JMZS5t3yp814sYi/dAkxL35MPfq6JG2HfH7Q/XkJ uX0zS1bBgTDoeA3MrkbFjwyhF5BvqDZY24fonP8+uxqueoEHNx/dd9O85VfP7K9jzA /9lBCoUC18fqOQrPZctyv6Q5OlKj/Uuqfd90xvkE= From: Roman Kisel To: arnd@arndb.de, bhelgaas@google.com, bp@alien8.de, catalin.marinas@arm.com, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kw@linux.com, kys@microsoft.com, lenb@kernel.org, lpieralisi@kernel.org, mingo@redhat.com, rafael@kernel.org, robh@kernel.org, tglx@linutronix.de, wei.liu@kernel.org, will@kernel.org, linux-acpi@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, ssengar@microsoft.com, sunilmut@microsoft.com, vdso@hexbites.dev Subject: [PATCH v3 6/7] Drivers: hv: vmbus: Get the IRQ number from DT Date: Fri, 26 Jul 2024 15:59:09 -0700 Message-Id: <20240726225910.1912537-7-romank@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240726225910.1912537-1-romank@linux.microsoft.com> References: <20240726225910.1912537-1-romank@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240726_155933_769116_411738BC X-CRM114-Status: GOOD ( 15.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The VMBus driver uses ACPI for interrupt assignment on arm64 hence it won't function in the VTL mode where only DeviceTree can be used. Update the VMBus driver to discover interrupt configuration via DeviceTree and indicate DMA cache coherency. Signed-off-by: Roman Kisel --- drivers/hv/vmbus_drv.c | 49 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 12a707ab73f8..7eee7caff5f6 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -2306,6 +2306,34 @@ static int vmbus_acpi_add(struct platform_device *pdev) } #endif +static int __maybe_unused vmbus_set_irq(struct platform_device *pdev) +{ + struct irq_desc *desc; + int irq; + + irq = platform_get_irq(pdev, 0); + if (irq == 0) { + pr_err("VMBus interrupt mapping failure\n"); + return -EINVAL; + } + if (irq < 0) { + pr_err("VMBus interrupt data can't be read from DeviceTree, error %d\n", irq); + return irq; + } + + desc = irq_to_desc(irq); + if (!desc) { + pr_err("No interrupt descriptor for VMBus virq %d\n", irq); + return -ENODEV; + } + + vmbus_irq = irq; + vmbus_interrupt = desc->irq_data.hwirq; + pr_debug("VMBus virq %d, hwirq %d\n", vmbus_irq, vmbus_interrupt); + + return 0; +} + static int vmbus_device_add(struct platform_device *pdev) { struct resource **cur_res = &hyperv_mmio; @@ -2320,6 +2348,12 @@ static int vmbus_device_add(struct platform_device *pdev) if (ret) return ret; +#ifndef HYPERVISOR_CALLBACK_VECTOR + ret = vmbus_set_irq(pdev); + if (ret) + return ret; +#endif + for_each_of_range(&parser, &range) { struct resource *res; @@ -2338,6 +2372,21 @@ static int vmbus_device_add(struct platform_device *pdev) cur_res = &res->sibling; } + /* + * Hyper-V always assumes DMA cache coherency, and the DMA subsystem + * might default to 'not coherent' on some architectures. + * Avoid high-cost cache coherency maintenance done by the CPU. + */ +#if defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_DEVICE) || \ + defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU) || \ + defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL) + + if (!of_property_read_bool(np, "dma-coherent")) + pr_warn("Assuming cache coherent DMA transactions, no 'dma-coherent' node supplied\n"); + pdev->dev.dma_coherent = true; + +#endif + return ret; } From patchwork Fri Jul 26 22:59:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kisel X-Patchwork-Id: 13743248 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A60A7C3DA4A for ; Fri, 26 Jul 2024 23:02:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=HO3yRXjuxdLjBhwnppBtgMAHdHUWQFnMBR0lzUnYMd4=; b=e7TashhvkpGVyW88IGzPZVt5+n Y346c4ToyM1jMTYSufDSYbJrOX/EAzEGDlCAMR/UBiwW9j7YRfiKMJpe3yd8g6z7zEBmPDL0vz2aU ElZksbp94DqCjiZErqegoMCkHGNk4Sd08lqmX2LcFdTzRHrxqVX28e3zUOp6xhSjATiLdPdWjnx8+ 1dSEjmEJpbhKIo90362NYp0FDC52CMEeKahKfojpkV9Yw8cLBXCBcZa+N2bEKKUZrgUeJ7KPAYwIK 92FHfMDw1eU7gl096CNdMcknvyxUgTZZdWS8FkCiOBQxlx0wElMCGkxhysqBM2klLfkdONMRh04Px KERv2C/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXTxW-00000005Idr-09cP; Fri, 26 Jul 2024 23:02:46 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXTuP-00000005HIf-3FCy for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 22:59:36 +0000 Received: from romank-3650.corp.microsoft.com (unknown [131.107.159.62]) by linux.microsoft.com (Postfix) with ESMTPSA id 262EB20B7139; Fri, 26 Jul 2024 15:59:30 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 262EB20B7139 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1722034770; bh=HO3yRXjuxdLjBhwnppBtgMAHdHUWQFnMBR0lzUnYMd4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CTdOB9BtLQmksCAEH7nr1aJW0bLAE0rIU2bYhoG+rAer6pFBGUyYbWzRaJPvLHOQg hMNfTiuq7Q5Rkp5jRz875m5oA9Y7q4xceyViPsWreqV4KQPX14TOp15njTYyTtUBcq 0zEwjKEOQOaO/ndF5oPyEX4dc6FmkQM0vPTR838w= From: Roman Kisel To: arnd@arndb.de, bhelgaas@google.com, bp@alien8.de, catalin.marinas@arm.com, dave.hansen@linux.intel.com, decui@microsoft.com, haiyangz@microsoft.com, hpa@zytor.com, kw@linux.com, kys@microsoft.com, lenb@kernel.org, lpieralisi@kernel.org, mingo@redhat.com, rafael@kernel.org, robh@kernel.org, tglx@linutronix.de, wei.liu@kernel.org, will@kernel.org, linux-acpi@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, x86@kernel.org Cc: apais@microsoft.com, benhill@microsoft.com, ssengar@microsoft.com, sunilmut@microsoft.com, vdso@hexbites.dev Subject: [PATCH v3 7/7] PCI: hv: Get vPCI MSI IRQ domain from DT Date: Fri, 26 Jul 2024 15:59:10 -0700 Message-Id: <20240726225910.1912537-8-romank@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240726225910.1912537-1-romank@linux.microsoft.com> References: <20240726225910.1912537-1-romank@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240726_155934_038693_B5429CA7 X-CRM114-Status: GOOD ( 25.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The hyperv-pci driver uses ACPI for MSI IRQ domain configuration on arm64. It won't be able to do that in the VTL mode where only DeviceTree can be used. Update the hyperv-pci driver to get vPCI MSI IRQ domain in the DeviceTree case, too. Signed-off-by: Roman Kisel --- drivers/hv/vmbus_drv.c | 23 +++++++----- drivers/pci/controller/pci-hyperv.c | 55 +++++++++++++++++++++++++++-- include/linux/hyperv.h | 2 ++ 3 files changed, 69 insertions(+), 11 deletions(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 7eee7caff5f6..038bd9be64b7 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -45,7 +45,8 @@ struct vmbus_dynid { struct hv_vmbus_device_id id; }; -static struct device *hv_dev; +/* VMBus Root Device */ +static struct device *vmbus_root_device; static int hyperv_cpuhp_online; @@ -80,9 +81,15 @@ static struct resource *fb_mmio; static struct resource *hyperv_mmio; static DEFINE_MUTEX(hyperv_mmio_lock); +struct device *get_vmbus_root_device(void) +{ + return vmbus_root_device; +} +EXPORT_SYMBOL_GPL(get_vmbus_root_device); + static int vmbus_exists(void) { - if (hv_dev == NULL) + if (vmbus_root_device == NULL) return -ENODEV; return 0; @@ -861,7 +868,7 @@ static int vmbus_dma_configure(struct device *child_device) * On x86/x64 coherence is assumed and these calls have no effect. */ hv_setup_dma_ops(child_device, - device_get_dma_attr(hv_dev) == DEV_DMA_COHERENT); + device_get_dma_attr(vmbus_root_device) == DEV_DMA_COHERENT); return 0; } @@ -1892,7 +1899,7 @@ int vmbus_device_register(struct hv_device *child_device_obj) &child_device_obj->channel->offermsg.offer.if_instance); child_device_obj->device.bus = &hv_bus; - child_device_obj->device.parent = hv_dev; + child_device_obj->device.parent = vmbus_root_device; child_device_obj->device.release = vmbus_device_release; child_device_obj->device.dma_parms = &child_device_obj->dma_parms; @@ -2253,7 +2260,7 @@ static int vmbus_acpi_add(struct platform_device *pdev) struct acpi_device *ancestor; struct acpi_device *device = ACPI_COMPANION(&pdev->dev); - hv_dev = &device->dev; + vmbus_root_device = &device->dev; /* * Older versions of Hyper-V for ARM64 fail to include the _CCA @@ -2342,7 +2349,7 @@ static int vmbus_device_add(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; int ret; - hv_dev = &pdev->dev; + vmbus_root_device = &pdev->dev; ret = of_range_parser_init(&parser, np); if (ret) @@ -2675,7 +2682,7 @@ static int __init hv_acpi_init(void) if (ret) return ret; - if (!hv_dev) { + if (!vmbus_root_device) { ret = -ENODEV; goto cleanup; } @@ -2706,7 +2713,7 @@ static int __init hv_acpi_init(void) cleanup: platform_driver_unregister(&vmbus_platform_driver); - hv_dev = NULL; + vmbus_root_device = NULL; return ret; } diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 5992280e8110..cdecefd1f9bd 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -50,6 +50,7 @@ #include #include #include +#include #include /* @@ -887,6 +888,35 @@ static const struct irq_domain_ops hv_pci_domain_ops = { .activate = hv_pci_vec_irq_domain_activate, }; +#ifdef CONFIG_OF + +static struct irq_domain *hv_pci_of_irq_domain_parent(void) +{ + struct device_node *parent; + struct irq_domain *domain; + + parent = of_irq_find_parent(to_platform_device(get_vmbus_root_device())->dev.of_node); + domain = NULL; + if (parent) { + domain = irq_find_host(parent); + of_node_put(parent); + } + + /* + * `domain == NULL` shouldn't happen. + * + * If somehow the code does end up in that state, treat this as a configuration + * issue rather than a hard error, emit a warning, and let the code proceed. + * The NULL parent domain is an acceptable option for the `irq_domain_create_hierarchy` + * function called later. + */ + if (!domain) + WARN_ONCE(1, "No interrupt-parent found, check the DeviceTree data.\n"); + return domain; +} + +#endif + static int hv_pci_irqchip_init(void) { static struct hv_pci_chip_data *chip_data; @@ -906,10 +936,29 @@ static int hv_pci_irqchip_init(void) * IRQ domain once enabled, should not be removed since there is no * way to ensure that all the corresponding devices are also gone and * no interrupts will be generated. + * + * In the ACPI case, the parent IRQ domain is supplied by the ACPI + * subsystem, and it is the default GSI domain pointing to the GIC. + * Neither is available outside of the ACPI subsystem, cannot avoid + * the messy ifdef below. + * There is apparently no such default in the OF subsystem, and + * `hv_pci_of_irq_domain_parent` finds the parent IRQ domain that + * points to the GIC as well. + * None of these two cases reaches for the MSI parent domain. */ - hv_msi_gic_irq_domain = acpi_irq_create_hierarchy(0, HV_PCI_MSI_SPI_NR, - fn, &hv_pci_domain_ops, - chip_data); +#ifdef CONFIG_ACPI + if (!acpi_disabled) + hv_msi_gic_irq_domain = acpi_irq_create_hierarchy(0, HV_PCI_MSI_SPI_NR, + fn, &hv_pci_domain_ops, + chip_data); +#endif +#if defined(CONFIG_OF) + if (!hv_msi_gic_irq_domain) + hv_msi_gic_irq_domain = irq_domain_create_hierarchy( + hv_pci_of_irq_domain_parent(), 0, HV_PCI_MSI_SPI_NR, + fn, &hv_pci_domain_ops, + chip_data); +#endif if (!hv_msi_gic_irq_domain) { pr_err("Failed to create Hyper-V arm64 vPCI MSI IRQ domain\n"); diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index 5e39baa7f6cb..b4aa1f579a97 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -1346,6 +1346,8 @@ static inline void *hv_get_drvdata(struct hv_device *dev) return dev_get_drvdata(&dev->device); } +struct device *get_vmbus_root_device(void); + struct hv_ring_buffer_debug_info { u32 current_interrupt_mask; u32 current_read_index;