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: 814596 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CDEC714A0AE; Fri, 26 Jul 2024 22:59:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722034770; cv=none; b=QBkWpZCG3On1aAmT4vRCf1pQwnuzLcwn1vyjv3QLPZ12ZwDyIerExQzT0ZRqXm+AcHLpW8vdokWN0xPJyF0M26YEfK7GnWMXB8iuGW5wihFIANvyA0Vse4qSiYNU9fB4aq7fr3KjOQUNgSUOYpyhonRkjRg6xlA19DCzEC9Q69o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722034770; c=relaxed/simple; bh=HFBoWSD8uQoZuJWa7FvNTiQLxRg6hK3Qpe4FaW2NSH8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=J+GT5Df+RxE/0OBBScxluFOibS/dafxFliq5GkNDyjxnMwy6z3BWi86pSCS+6vwQHcxnShnfMwHO0BsEQalCDNlT7j+1YCfWtA6ACzn+D3BGuqiYPxNxAOjwDdarD1DRyoBrMsMVm2TdjImO1dDV8Nji9tlicVJ0Bzl4m8DnLnQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=ooH+d9b/; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="ooH+d9b/" 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> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 815067 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 309EF14E2E2; Fri, 26 Jul 2024 22:59:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722034770; cv=none; b=KhrdrkWqouWwi6qut7mjgJNkXVketPkhz1oPUOI3Dxff+LI2xQcMkvUo4sh5lU7sxDnZJZrMMBE4KiHjdmIMM3JVo8t5x2lnCsDI5aONBzQN59zVCN/ui5aXmO7jfwwpFjxz83l285mIpdVPOJ4qZ170y5tMvyXm0I/BOgZNA54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722034770; c=relaxed/simple; bh=7HgWJE4cfgE61Dl7QjSO8v9EH9VKJc6vrXkGm9O5TYY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=hM2TGWtSM1Z3Wqs/VbNkQfdv2NUgrSUpUenRKNocHRDu9OhdpcBmVRPibwb/5e7Chap6rbTrBfSUMdzYqXy9UsmWzstazk4xT/fMotIxICa70+n1EkC7K1akmLQaCZlE8E17cG5L4iYDCNpyQWxrp3vl6tQqXln/56TvrTkYLMc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=hwl/+ekN; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="hwl/+ekN" 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> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 814595 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6DFB614EC4E; Fri, 26 Jul 2024 22:59:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722034771; cv=none; b=LhZIVY464dxtTwbN/W1DDIXv5W4stjG9q7zPrjhB9lDI0TrI5VpAyXh5W0+uUKq8iiYq/G9OFsXpGq6sGuGIIyXv9oiHnKeT1r57tUYPhkDE/aJJifAjIaglL7iW7SUnYHAK8bkWb/4n9cKnfLaG6vn/2qFSix1766uhWNgPBoQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722034771; c=relaxed/simple; bh=Lssq5DYvn0UB3De1jCUCZOPpcxO9JEDZzy/E/cIrDls=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OSbAItAnTTUdIX8qP3W9SRUXhscvp0TUpWqqIE+kPlLzRscniJsvR+YgmkCnY3BBDlKXQ4tqcTXBDdPaezensJzpEIJNfW99fOmAAxyfzwVSBnX2pLkVmYnG9nQ0JyUck/UQtVQlYY7eG8Fjr/bjWQr9C5cjfQW7JwOplXbMorg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=Ay3ecAMl; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="Ay3ecAMl" 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> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 815066 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA1DC14EC5D; Fri, 26 Jul 2024 22:59:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722034771; cv=none; b=KCTETsts28xHshTZL8XD7FkH5xUNuZr/sVIZxcrZnU1ruxt/5P1ck4xxy/ekBCu3I+qNpRL5i7JPr2L+6v2AnT3mWDYx9X3kPLfQ1U17UmQjhx/Xd7x15tXfqNtU4QnGJkE29AcxT1BmRuVL+KlofZiDcB0cAfBs3qPgCGfnX7c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722034771; c=relaxed/simple; bh=rJcS3Jq98v2NWlttjuSO/XP10kOr038BA/9t0EitINY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hjlTfOdwnUNdbmrZGj1bk5eF7nVtZm2lAAyrCjnH5z9K7Y0tNiD1jOvHPvaIOFCt93DRcZAsMauo8Op/25RRxVpw6E6MiNqNr8EzHL8h20MlTOVG+rLWV26MnO2cDSxwsXuOh42dOzjymlJzeMYhtRWHGAWIyRCm3vDDLDRzATk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=HrFS4gQA; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="HrFS4gQA" 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> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 814594 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 605F51514F8; Fri, 26 Jul 2024 22:59:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722034771; cv=none; b=Vc3oJwaLkf6IQhZ7JQdm6JFfkNE1lOMwfBM0av6Ux6CDA2ccdflZMs0ThT+7cMOCFt4L6hw6ahct5iGWUG7w/qVAui5wIagIYkUsJaqheDqaRZY45OIRYLZvkdsmjDaLU0npw1mN94/dNP6qzyDTIYdV1VTbZ57wHgiyBwCQiI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722034771; c=relaxed/simple; bh=vk1//007f6efUv3tZXdBFYeje256Rq4JLZSViWp0k7Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z8rN+Jab31EWKNU7e5dmSdaBVk21920bKxp0kGtIwk/jzdJn/hbYSUVnZOpP3g5ganTBtl5H2tALBCrFpx7iGVdNJjbpbo7mWR71eRQLX4m3PbA7AovHzrr9zQG+pr5IX5OOnPRFFingJB+4QUS7U3lWs/JiO47/uwlcWAyzd1Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=J5prU8uA; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="J5prU8uA" 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> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 815065 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5F5311514F6; Fri, 26 Jul 2024 22:59:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722034772; cv=none; b=JThb0che4ULCJ7kU/RG/q6WR7W97biysEQtfx51t4crFVsJ1m17/tUu53xJJX1Qf5kHQnt/DrXn1cZkhGfumhQe3l6t0YAxORmmh9A6XtAwzO3e3Occ8pK/WDGcblnDFN/wOgRriFoOYxF5UApXP/fxONQYoUFl72ErGqYX62PM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722034772; c=relaxed/simple; bh=LmyxU2JFWdzIhr/7UyPWyDMHFIJ8AwEqBU+ndr0kTXY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SUx68xAfbmgVOWX2zOP2/857Np7JsfIkrw/xJmXKkc4go7Z2NvM0KOXokEAP6qXFx6tlDHqXXkio6dqg/aptrsNE7JzdTIk8CbDPq52uRn7X4boaisyt3WfOjjMSE9KEZc94GmoEsr2EMUqXUi6UXgtOBpKNJUuTc6nqJ/7CkoE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=Ifls2ATr; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="Ifls2ATr" 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> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: 814593 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8DCAF15350B; Fri, 26 Jul 2024 22:59:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722034772; cv=none; b=Nre5m5MGZuCfWVr9NLzPf8+C2NE0DK4lsjJg3Qj3WVq8+ErhJt+3i9P4E9TJNkGFbgDmNxbER+2f5vqNfUCZ/pq7UXUEqy0LH8LSp0PebeY+uRDFRJl9jv17qvHNgfaa5ZaWVXiMXbNrFPc+C/yK0yPywBQpS/pBdJ+iZgCzbsA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722034772; c=relaxed/simple; bh=DLUnroqMGGTesiv/VYVlyBGgrYzR5oprmLBsFYEDDqQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZGQ3tX4Ys899SEoFap3P14IHctNKxCdXbVubzplalkwuSFMgWm5xRPtVehbbHEtIIdtWRpRX1HCQXv2q34K8xDBNZ2CM/chKhXuEpXgAl9vJXGheF7brfazNxw/LC7mNj49yjJDYLkVoBu1Gs70hl2TBwHJKxiK3nmIOK7aARIw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=CTdOB9Bt; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="CTdOB9Bt" 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> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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;