From patchwork Fri May 10 16:05:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kisel X-Patchwork-Id: 796566 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C14D7172761; Fri, 10 May 2024 16:06:26 +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=1715357189; cv=none; b=usjWAptHqWLFh01CmLYDAjxh0Ihyn1x7OyONIjEl5HudB+hhprxM8yCuL70aV4BSPMUpEQIq4bzOMhIMs1wLpTs4nAYB8ZzTuwr1+PLbPmZNMG0U3cfkhJMlYfTFp/s874eMjytMBS3gXDpbXabsxoNCcP0Z3fjxd+MncrtXf10= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715357189; c=relaxed/simple; bh=TEnUv8xcmqE696rwwBMkjSZIHNju2H3PsfeU3Tj8/Vg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KqFZ1wg9SvXIPEJeDFaLUbmJwiAaHF0BDAmY9tOmudlJDRVmwPQcFBntRJU8PY21S4EUGxkyyhQ0izZC0YWQvWjEMGq8odDeYGew1g12Gvq9t/0n9KHBCxqA7syTnNzg9lr7xqDpzvi4IPuCP6tk7TGm60UT4SV5sJYHv+SYOd4= 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=GBtFAzYW; 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="GBtFAzYW" Received: from xps-8930.corp.microsoft.com (unknown [131.107.160.48]) by linux.microsoft.com (Postfix) with ESMTPSA id 29FE1209122A; Fri, 10 May 2024 09:06:20 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 29FE1209122A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1715357180; bh=DbJI7sPFnvaKMs0+uBHHpBULjrM84eRWrgyYSqdRp8c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GBtFAzYWSJlPnqjxYwUJ14RUQoJ+AdzEttjClYL3yjLKPsxlMAdQ/rhJ3USI4ajfP mYu7wbfozgdR03UZtDU8CuIis0HWH1cnYWZr1GIZRlA+1BHwYyh8v/ezb5xGSfeWhv ChOVxto7ZFOAbFdclZGUCchGQZw+LFATVu3dGjQA= From: romank@linux.microsoft.com To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, linux-hyperv@vger.kernel.org, rafael@kernel.org, lenb@kernel.org, linux-acpi@vger.kernel.org Cc: ssengar@microsoft.com, sunilmut@microsoft.com Subject: [PATCH 1/6] arm64/hyperv: Support DeviceTree Date: Fri, 10 May 2024 09:05:00 -0700 Message-ID: <20240510160602.1311352-2-romank@linux.microsoft.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510160602.1311352-1-romank@linux.microsoft.com> References: <20240510160602.1311352-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 From: Roman Kisel Update the driver to support DeviceTree boot as well along with ACPI. This enables the Virtual Trust Level platforms boot up on ARM64. Signed-off-by: Roman Kisel --- arch/arm64/hyperv/mshyperv.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/arch/arm64/hyperv/mshyperv.c b/arch/arm64/hyperv/mshyperv.c index b1a4de4eee29..208a3bcb9686 100644 --- a/arch/arm64/hyperv/mshyperv.c +++ b/arch/arm64/hyperv/mshyperv.c @@ -15,6 +15,9 @@ #include #include #include +#include +#include +#include #include static bool hyperv_initialized; @@ -27,6 +30,29 @@ int hv_get_hypervisor_version(union hv_hypervisor_version_info *info) return 0; } +static bool hyperv_detect_fdt(void) +{ +#ifdef CONFIG_OF + const unsigned long hyp_node = of_get_flat_dt_subnode_by_name( + of_get_flat_dt_root(), "hypervisor"); + + return (hyp_node != -FDT_ERR_NOTFOUND) && + of_flat_dt_is_compatible(hyp_node, "microsoft,hyperv"); +#else + return false; +#endif +} + +static bool hyperv_detect_acpi(void) +{ +#ifdef CONFIG_ACPI + return !acpi_disabled && + !strncmp((char *)&acpi_gbl_FADT.hypervisor_id, "MsHyperV", 8); +#else + return false; +#endif +} + static int __init hyperv_init(void) { struct hv_get_vp_registers_output result; @@ -35,13 +61,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_fdt() && !hyperv_detect_acpi()) return 0; /* Setup the guest ID */ From patchwork Fri May 10 16:05:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kisel X-Patchwork-Id: 796045 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C143F171E7C; Fri, 10 May 2024 16:06:26 +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=1715357189; cv=none; b=S5+ZMg7E3jd6QYJyRkyNHEsbwWBTzXIprp6XJ2Zby+zxKK9kbdoho1uRHXZbocvEHvA0VeDng7hks5Vk9SOa6d8bZyBw/Benj4Gewlv6BiWvfLX/gGe+zl7C+YePGOzApieDdBfgRsp72iikhVV183IRfguWa6vsrro0YT8/pxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715357189; c=relaxed/simple; bh=ZFQEJj/HsfljCrFKMUE9UyYGfOEsgr1gbTXTWuK/an0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=abPeDmmK7/ju3QT+xEZQWpk9wIg64J/HBLm4ckKKF1hHnvUc83w0D6m35Iqpkbm8z0btkCbgcgMi4qkmnDWidN8maxmWXatTdqvMLMR99CWG0FAkHZ4YHHT18UJKG/Q+ngaiRMuutMLaejIFVYf374Tchc5D5dyqodSid4ofSgY= 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=QYSUuwbb; 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="QYSUuwbb" Received: from xps-8930.corp.microsoft.com (unknown [131.107.160.48]) by linux.microsoft.com (Postfix) with ESMTPSA id 58006209122D; Fri, 10 May 2024 09:06:20 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 58006209122D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1715357180; bh=i8sURU7VZy9XbERdslCO4zd0i0m4z48sr2ICI5U3xH4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QYSUuwbbm+sG3R23wRRulV8ZTIZtvLx2SWeK8z2C2YifG3+i/qjb0voiSNoCIJG38 ioliCBHp9FxLvEauXPZv+3CuV/gc1PE9lPm9eequqv61TFVIK5ywHYhs6Z2GVJFSuF qbuVS/9vwsKz5W6m/i6FKUHlW51AYulqHtFMCLgE= From: romank@linux.microsoft.com To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, linux-hyperv@vger.kernel.org, rafael@kernel.org, lenb@kernel.org, linux-acpi@vger.kernel.org Cc: ssengar@microsoft.com, sunilmut@microsoft.com Subject: [PATCH 2/6] drivers/hv: Enable VTL mode for arm64 Date: Fri, 10 May 2024 09:05:01 -0700 Message-ID: <20240510160602.1311352-3-romank@linux.microsoft.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510160602.1311352-1-romank@linux.microsoft.com> References: <20240510160602.1311352-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 From: Roman Kisel This change removes dependency on ACPI when buidling the hv drivers to allow Virtual Trust Level boot with DeviceTree. Signed-off-by: Roman Kisel --- 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 May 10 16:05:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kisel X-Patchwork-Id: 796046 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C1540172762; Fri, 10 May 2024 16:06:26 +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=1715357188; cv=none; b=F4L81Mw2OIIUdep6NqSrI41QEktd0andGE1E7FBsjz4kIZycxvU2+iFbFYOYAbOg02achxlIqXTGSqgzTda6IjzPk7kIWFVXydl8G7ggGwigNEn2qHDg6AnS8Wnd/LSvkknjYt5xNCiJ8Y04un61hIH+YQUt26s1s9jEOXVpP+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715357188; c=relaxed/simple; bh=+ARAvmTH0xEHhWGY2pzMrCPUMF/Y9G/VRo68y4+oy+M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A+Kmqqx1LowzBUyGKpQHpy9yGzYYByFMj1o8FZacW+tHRKB5CId1VrOX26k8+FHHxo1B3mUQoGmrXNi4KFUXkj1EJzfEKrTEa7+qQ0LgawzURoEdC3T1Ys4WNRESX3BQptxlQU+293+oehAyko+0dmoB4eQkx8YaAKgX2Tw+Ec8= 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=QYD/qgd2; 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="QYD/qgd2" Received: from xps-8930.corp.microsoft.com (unknown [131.107.160.48]) by linux.microsoft.com (Postfix) with ESMTPSA id 859BB209122F; Fri, 10 May 2024 09:06:20 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 859BB209122F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1715357180; bh=Wa4hWhC80XW07zlGS45CsHMVVvWPCo0ufeD5PixgqZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QYD/qgd2pBIMe1y+TbiB5ES/nFiLmdv0pMNkBv6PNqWvWiu462letgKIch1Gxtx+l H3I0Lv08bRqcT+aM2LzVBmecesHx7ze7isIfCBY+9ijatuxCX66z8EYZcfkoE/FNgq 1QNbx2BIiW8Cj1Kck9sNZBXVxtDsTsYByq2l34ik= From: romank@linux.microsoft.com To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, linux-hyperv@vger.kernel.org, rafael@kernel.org, lenb@kernel.org, linux-acpi@vger.kernel.org Cc: ssengar@microsoft.com, sunilmut@microsoft.com Subject: [PATCH 3/6] arm64/hyperv: Boot in a Virtual Trust Level Date: Fri, 10 May 2024 09:05:02 -0700 Message-ID: <20240510160602.1311352-4-romank@linux.microsoft.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510160602.1311352-1-romank@linux.microsoft.com> References: <20240510160602.1311352-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 From: Roman Kisel This change builds upon the previous ones to boot in a Virtual Trust Level and provide configuration for the drivers. Also print the VTL the code runs in the new and the existing code. Signed-off-by: Roman Kisel --- arch/arm64/hyperv/Makefile | 1 + arch/arm64/hyperv/hv_vtl.c | 19 +++++++++++++++++++ arch/arm64/hyperv/mshyperv.c | 6 ++++++ arch/arm64/include/asm/mshyperv.h | 8 ++++++++ arch/x86/hyperv/hv_vtl.c | 2 +- 5 files changed, 35 insertions(+), 1 deletion(-) 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..9b44cc49594c --- /dev/null +++ b/arch/arm64/hyperv/hv_vtl.c @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2023, Microsoft, Inc. + * + * Author : Roman Kisel + */ + +#include + +void __init hv_vtl_init_platform(void) +{ + pr_info("Linux runs in Hyper-V Virtual Trust Level %d\n", ms_hyperv.vtl); +} + +int __init hv_vtl_early_init(void) +{ + return 0; +} +early_initcall(hv_vtl_early_init); diff --git a/arch/arm64/hyperv/mshyperv.c b/arch/arm64/hyperv/mshyperv.c index 208a3bcb9686..cbde483b167a 100644 --- a/arch/arm64/hyperv/mshyperv.c +++ b/arch/arm64/hyperv/mshyperv.c @@ -96,6 +96,12 @@ static int __init hyperv_init(void) return ret; } + /* Find the VTL */ + ms_hyperv.vtl = get_vtl(); + if (ms_hyperv.vtl > 0) /* non default VTL */ + hv_vtl_early_init(); + + 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 a975e1a689dd..4a8ff6be389c 100644 --- a/arch/arm64/include/asm/mshyperv.h +++ b/arch/arm64/include/asm/mshyperv.h @@ -49,6 +49,14 @@ 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) {} +static inline int __init hv_vtl_early_init(void) { return 0; } +#endif + #include #endif diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c index 92bd5a55f093..ae3105375a12 100644 --- a/arch/x86/hyperv/hv_vtl.c +++ b/arch/x86/hyperv/hv_vtl.c @@ -19,7 +19,7 @@ static struct real_mode_header hv_vtl_real_mode_header; void __init hv_vtl_init_platform(void) { - pr_info("Linux runs in Hyper-V Virtual Trust Level\n"); + pr_info("Linux runs in Hyper-V Virtual Trust Level %d\n", ms_hyperv.vtl); x86_platform.realmode_reserve = x86_init_noop; x86_platform.realmode_init = x86_init_noop; From patchwork Fri May 10 16:05:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kisel X-Patchwork-Id: 796567 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C1485172760; Fri, 10 May 2024 16:06:26 +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=1715357188; cv=none; b=P/LXZoRVGtmmDNirzHa0CnsB8QIaxGu3s1tM4iBe2XpDAVKKrgUd9CBPvJqaBCAOMm1j4UkwOQHav0p3h7bvyiWO+Xcn/IH1GT7+FSAsj+vJsHBXeYTJjD9c0GTq+edNg1Tx7nnlFBkI78PzUpdJ9+J6nc2DhH44LVen8lHrA6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715357188; c=relaxed/simple; bh=ZvOkhTYeEJUhrZuTJhXQBbK3PBG0ruNlKJ4Scqql/xM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u7KXNYiniVq9o28RzZmru8Lsp1b9IEJ5N1E5fmrfCl+LwKBtWb2sLJe9HjEMNnCAmN0YyG+WnAwIccdb23kiuY4jRdSJPlUl0CvDwtcHrq7WAYvg4Zed3bgv24u71QzaqSeA2N+4H0ZPLl9X9sfBHpqhdA1XKcV3tK1dOWfb0lg= 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=Cp5/OUtA; 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="Cp5/OUtA" Received: from xps-8930.corp.microsoft.com (unknown [131.107.160.48]) by linux.microsoft.com (Postfix) with ESMTPSA id B3CAA2091232; Fri, 10 May 2024 09:06:20 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B3CAA2091232 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1715357180; bh=pc0a3SlDT85Dg313a1oZrrllyZZVotNtjF2PY6tBjF4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cp5/OUtAQ4b9a/4mwY7/n/JvwZN6EOyusSUrizKkAbaBI7auIdP/cgA3zoGL5e+zd RkufMtQMWEawsqPIvLou8anIWGXfJY2z6ncg9RaUH1fyuZKS8HWTLeFsMxkV23gKZr Zq42qYNbJdLTlqXg4//e0Fqhjvn49AxEreKAw9Io= From: romank@linux.microsoft.com To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, linux-hyperv@vger.kernel.org, rafael@kernel.org, lenb@kernel.org, linux-acpi@vger.kernel.org Cc: ssengar@microsoft.com, sunilmut@microsoft.com Subject: [PATCH 4/6] drivers/hv: arch-neutral implementation of get_vtl() Date: Fri, 10 May 2024 09:05:03 -0700 Message-ID: <20240510160602.1311352-5-romank@linux.microsoft.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510160602.1311352-1-romank@linux.microsoft.com> References: <20240510160602.1311352-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 From: Roman Kisel This change generalizes the x86-specific implementation of get_vtl() so that it can be used on arm64. 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 | 43 ++++++++++++++++++++++++++++++ include/asm-generic/hyperv-tlfs.h | 7 +++++ include/asm-generic/mshyperv.h | 6 +++++ 5 files changed, 56 insertions(+), 41 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 dde3f9b6871a..d4cf477a4d0c 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -660,3 +660,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 = (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_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 87e3d49a4e29..682bcda3124f 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 99935779682d..ea434186d765 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -301,4 +301,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 May 10 16:05: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: 796565 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5307D172795; Fri, 10 May 2024 16:06: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=1715357189; cv=none; b=bxkZNWBF6GXxSXel1R/4/vCY70hVrouQu0wDOiBrWYshYTyt5TJBC/7EvuUYwUA99HUINxwccIqB3eYHQ77O4HnffK7YNL+50yd4/1rmFn2MfXHTt98981tGgkNmQWtLxYdoP4+jrWseo50kbjmW4ykH83mIUTXdcSKKYZyD76U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715357189; c=relaxed/simple; bh=UsbnjB4gtW5blpakM91WS9EhR6bLL6Lpgeic4mxEgKc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tDs4oH7nfJhukY5iBtt28HpnqN/IOJn1TL3RoxV5IPlX3QzmxSqTuKZsTrKDAc5Fy7xYLwVMDGcqvDb3p4QWHqDTAiTLHAQh7WVnppovimTNnQ6ke9Sw5Y8NruehHbgsYQIajz699XrjtYQhoPeu++HecYKb+o0aSRDOxHXVDo8= 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=l+uYgJ8/; 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="l+uYgJ8/" Received: from xps-8930.corp.microsoft.com (unknown [131.107.160.48]) by linux.microsoft.com (Postfix) with ESMTPSA id E10C320B2C87; Fri, 10 May 2024 09:06:20 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E10C320B2C87 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1715357181; bh=SEb/v+0tEn4l473lcXeO/Vet6aCRc4eg0h0XcwR05H4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l+uYgJ8/vVfn6h1kO7xgjuIKnvBevf8xe3OhJc+gLZ+G7PPvh33xPIk8HsMt8fPCE VHYEP674UnmQV+8VvYXv8KDirpyOoWqiEsDI3wQSjZ1nMGUcfJQdA4mMbB3Brz96ub REuYI8So3Z+FUFR9yHOaaJw91gFOQBj4MybCrf8U= From: romank@linux.microsoft.com To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, linux-hyperv@vger.kernel.org, rafael@kernel.org, lenb@kernel.org, linux-acpi@vger.kernel.org Cc: ssengar@microsoft.com, sunilmut@microsoft.com Subject: [PATCH 5/6] drivers/hv/vmbus: Get the irq number from DeviceTree Date: Fri, 10 May 2024 09:05:04 -0700 Message-ID: <20240510160602.1311352-6-romank@linux.microsoft.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510160602.1311352-1-romank@linux.microsoft.com> References: <20240510160602.1311352-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 From: Roman Kisel When booting on arm64, one has to configure the irq using the data from the system configuration. There has already been support for ACPI, support DeviceTree as booting in a Virtual Trust Level relies on DT. Signed-off-by: Roman Kisel --- drivers/hv/vmbus_drv.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index e25223cee3ab..52f01bd1c947 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include "hyperv_vmbus.h" @@ -2316,6 +2317,34 @@ static int vmbus_acpi_add(struct platform_device *pdev) } #endif +static int __maybe_unused vmbus_of_set_irq(struct device_node *np) +{ + struct irq_desc *desc; + int irq; + + irq = of_irq_get(np, 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("VMBus interrupt description can't be found for 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; @@ -2324,12 +2353,20 @@ static int vmbus_device_add(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; int ret; + pr_debug("VMBus is present in DeviceTree\n"); + hv_dev = &pdev->dev; ret = of_range_parser_init(&parser, np); if (ret) return ret; +#ifndef HYPERVISOR_CALLBACK_VECTOR + ret = vmbus_of_set_irq(np); + if (ret) + return ret; +#endif + for_each_of_range(&parser, &range) { struct resource *res; From patchwork Fri May 10 16:05:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kisel X-Patchwork-Id: 796044 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 530C0172796; Fri, 10 May 2024 16:06: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=1715357189; cv=none; b=kMMj35b0wZ7hKtawtO6/9p/RYO3koCkjs6w2Pke37NsNEj/rdRz4h1xfec73qEWR2WJvHj76UwtnCejjOXKh9XJNh8k6ovTHIt6mt/nzMqs7BwZN1iw6Zm4HV1ZHBK9b2VmTyQqdTbmT5oSSPH5tnHq9gwwHDukN4R0pYzetnwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715357189; c=relaxed/simple; bh=GE5tLHN9OT+uWRNNqUExw+u/b0/lJKng9dDqqJYdNds=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nWR4WYsaFsGee4+XNDq1bhvgPN2wILGS6RKYpbuRt9TfHi0pUO/bR+2XpKGiXpNnfVR6nbbDr0gwpWFKqp1oUeuqvTxVcYXgI7EqWgO2ZBSfScCcqlTeJzWqi94qy8fzSOp/aa5g2Cz3DCfPCn827Ap/mP9Yg4CPfWc/MAD1fmo= 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=JEsp25bu; 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="JEsp25bu" Received: from xps-8930.corp.microsoft.com (unknown [131.107.160.48]) by linux.microsoft.com (Postfix) with ESMTPSA id 1B1FC20B2C89; Fri, 10 May 2024 09:06:21 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 1B1FC20B2C89 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1715357181; bh=LXs8J2ZnHM4aNGPgsOLCUM2M1nDXtO2ZATnKq4lTGJQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JEsp25buXL/eu6noVCZeqa+pgVEbi+bxNHCUVYCludbleCn/LBBAPI5/pookttIQZ 2Am6wmKVDXb+pCVNUtyLfSbVCuLI7qj3ytRsE4UxGxmE1laIh6AFbvdkpZsx6poyk4 E5wi5P4c/TM730HDuNsd7yFHGV9iVWv13tP6Ct54= From: romank@linux.microsoft.com To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, linux-hyperv@vger.kernel.org, rafael@kernel.org, lenb@kernel.org, linux-acpi@vger.kernel.org Cc: ssengar@microsoft.com, sunilmut@microsoft.com Subject: [PATCH 6/6] drivers/pci/hyperv/arm64: vPCI MSI IRQ domain from DT Date: Fri, 10 May 2024 09:05:05 -0700 Message-ID: <20240510160602.1311352-7-romank@linux.microsoft.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240510160602.1311352-1-romank@linux.microsoft.com> References: <20240510160602.1311352-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 From: Roman Kisel This change allows Hyper-V PCI to be enabled on arm64 via DT when booting in a Virtual Trust Level. Signed-off-by: Roman Kisel --- drivers/pci/controller/pci-hyperv.c | 13 ++++++++++--- include/linux/acpi.h | 10 ++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 1eaffff40b8d..ccc2b54206f4 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -906,9 +906,16 @@ static int hv_pci_irqchip_init(void) * way to ensure that all the corresponding devices are also gone and * no interrupts will be generated. */ - hv_msi_gic_irq_domain = acpi_irq_create_hierarchy(0, HV_PCI_MSI_SPI_NR, - fn, &hv_pci_domain_ops, - chip_data); + if (acpi_disabled) + hv_msi_gic_irq_domain = irq_domain_create_hierarchy( + irq_find_matching_fwnode(fn, DOMAIN_BUS_ANY), + 0, HV_PCI_MSI_SPI_NR, + fn, &hv_pci_domain_ops, + chip_data); + else + hv_msi_gic_irq_domain = acpi_irq_create_hierarchy(0, HV_PCI_MSI_SPI_NR, + fn, &hv_pci_domain_ops, + chip_data); if (!hv_msi_gic_irq_domain) { pr_err("Failed to create Hyper-V arm64 vPCI MSI IRQ domain\n"); diff --git a/include/linux/acpi.h b/include/linux/acpi.h index b7165e52b3c6..eb93d355bb6d 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -1077,6 +1077,16 @@ static inline bool acpi_sleep_state_supported(u8 sleep_state) return false; } + +static inline struct irq_domain *acpi_irq_create_hierarchy(unsigned int flags, + unsigned int size, + struct fwnode_handle *fwnode, + const struct irq_domain_ops *ops, + void *host_data) +{ + return NULL; +} + #endif /* !CONFIG_ACPI */ extern void arch_post_acpi_subsys_init(void);