Skip to contentSkip to conversation

arm64: hyperv: Support Virtual Trust Level Boot

PATCH Superseded Roman Kisel 8 participants 33 messages Mar 15, 2025 – Mar 26, 2025

Subsystems (11)
Device tree bindings x86 ACPI PCI +7 more subsystems

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v6 cover arm64: hyperv: Support Virtual Trust Level Boot

This patch set allows the Hyper-V code to boot on ARM64 inside a Virtual Trust Level. These levels are a part of the Virtual Secure Mode documented in the Top-Level Functional Specification available at
https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlfs/vsm.

The OpenHCL paravisor https://github.com/microsoft/openvmm/tree/main/openhcl
can serve as a practical application of these patches on ARM64.

For validation, I built kernels for the {x86_64, ARM64} x {VTL0, VTL2} set with a small initrd embedded into the kernel and booted VMs managed by Hyper-V and OpenVMM off of that.

Starting from V5, the patch series includes a non-functional change to KVM on arm64 which I tested as well.

[V6]
- Use more intuitive Kconfig update.
- Remove ifdef for getting IRQ number
** Thank you, Arnd! **

- Simplify code for finding the parent IRQ domain. ** Thank you, Bjorn! **

- Remove a superfluous check.
** Thank you, Dan! **

- Make the commit title and descrtiption legible.
- Don't set additionalProperties to true. ** Thank you, Krzysztof! **

- Fix spelling in the commit title and description.
- Trade-offs for options in Kconfig.
- Export the new symbol as hyperv-pci can be built as a module. ** Thank you, Michael! **

- Simplify code for getting IRQ number.
** Thank you, Rob! **

- Add comment to clarify when running in VTL mode is reported. ** Thank you, Wei! **

[V5]
https://lore.kernel.org/linux-hyperv/[email protected]/
- Provide and use a common SMCCC-based infra for the arm64 hypervisor guests to detect hypervisor presence.
** Thank you, Arnd! **

- Fix line wraps to follow the rest of the code.
- Open-code getting IRQ domain parent in the ACPI case to make the code better.
** Thank you, Bjorn! **

- Test the binding with the latest dtschema.
- Clean up the commit title and description.
- Use proper defines for known constants.
** Thank you, Krzysztof! **

- Extend comment on why ACPI v6 is checked for.
- Reorder patches to make sure that even with partial series application the compilation succeeds.
- Report VTL the kernel runs in.
- Use "X86_64" in Kconfig rather than "X86".
- Extract a non-functional change for hv_get_vmbus_root_device() into a separate patch.
** Thank you, Michael! **

[V4]
https://lore.kernel.org/linux-hyperv/[email protected]/
- Fixed wording to match acronyms defined in the "Terms and Abbreviations" section of the SMCCC specification throughout the patch series. **Thank you, Michael!**

- Replaced the hypervisor ID containing ASCII with an UUID as required by the specification.
**Thank you, Michael!**

- Added an explicit check for SMCCC_RET_NOT_SUPPORTED when discovering the hypervisor presence to make the backward compatibility obvious. **Thank you, Saurabh!**

- Split the fix for get_vtl(void) out to make it easier to backport.
- Refactored the configuration options as requested to eliminate the risk of building non-functional kernels with randomly selected options. **Thank you, Michael!**

- Refactored the changes not to introduce an additional file with a one-line function.
**Thank you, Wei!**

- Fixed change description for the VMBus DeviceTree changes, used scripts/get_maintainers.pl on the latest kernel to get the up-to-date list of maintainers as requested.
**Thank you, Krzysztof!**

- Removed the added (paranoidal+superfluous) checks for DMA coherence in the VMBus driver and instead relied on the DMA and the OF subsystem code. **Thank you, Arnd, Krzysztof, Michael!**

- Used another set of APIs for discovering the hardware interrupt number in the VMBus driver to be able to build the driver as a module. **Thank you, Michael, Saurabh!**

- Renamed the newly introduced get_vmbus_root_device(void) function to hv_get_vmbus_root_device(void) as requested.
**Thank you, Wei!**

- Applied the suggested small-scale refactoring to simplify changes to the Hyper-V PCI driver. Taking the offered liberty of doing the large scale refactoring in another patch series.
**Thank you, Michael!**

- Added a fix for the issue discovered internally where the CPU would not get the interrupt from a PCI device attached to VTL2 as the shared peripheral interrupt number (SPI) was not offset by 32 (the first valid SPI number). **Thank you, Brian!**

[V3]
https://lore.kernel.org/lkml/[email protected]/
- Employed the SMCCC function recently implemented in the Microsoft Hyper-V hypervisor to detect running on Hyper-V/arm64. No dependence on ACPI/DT is needed anymore although the source code still falls back to ACPI as the new hypervisor might be available only in the Windows Insiders channel just
yet.
- As a part of the above, refactored detecting the hypervisor via ACPI FADT.
- There was a suggestion to explore whether it is feasible or not to express
that ACPI must be absent for the VTL mode and present for the regular guests
in the Hyper-V Kconfig file.
My current conclusion is that this will require refactoring in many places. That becomes especially convoluted on x86_64 due to the MSI and APIC dependencies. I'd ask to let us tackle that in another patch series (or chalk up to nice-have's rather than fires to put out) to separate concerns and decrease chances of breakage.
- While refactoring get_vtl(void) and the related code, fixed the hypercall output address not to overlap with the input as the Hyper-V TLFS mandates:
"The input and output parameter lists cannot overlap or cross page boundaries." See https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlfs/hypercall-interface
for more.
Some might argue that should've been a topic for a separate patch series;
I'd counter that the change is well-contained (one line), has no dependencies, and makes the code legal.
- Made the VTL boot code (c)leaner as was suggested.
- Set DMA cache coherency for the VMBus.
- Updated DT bindings in the VMBus documentation (separated out into a new patch).
- Fixed vmbus_set_irq to use the API that works both for the ACPI and OF.
- Reworked setting up the vPCI MSI IRQ domain in the non-ACPI case. The logic looks a bit fiddly/ad-hoc as I couldn't find the API that would fit the bill. Added comments to explain myself.

[V2]
https://lore.kernel.org/all/[email protected]/
- Decreased number of #ifdef's
- Updated the wording in the commit messages to adhere to the guidlines
- Sending to the correct set of maintainers and mail lists

[V1]

    https://lore.kernel.org/all/[email protected]/

Roman Kisel (11):
arm64: kvm, smccc: Introduce and use API for detecting hypervisor
presence
arm64: hyperv: Use SMCCC to detect hypervisor presence
Drivers: hv: Enable VTL mode for arm64
Drivers: hv: Provide arch-neutral implementation of get_vtl()
arm64: hyperv: Initialize the Virtual Trust Level field arm64, x86: hyperv: Report the VTL the system boots in
dt-bindings: microsoft,vmbus: Add interrupt and DMA coherence
properties
Drivers: hv: vmbus: Get the IRQ number from DeviceTree
Drivers: hv: vmbus: Introduce hv_get_vmbus_root_device()
ACPI: irq: Introduce acpi_get_gsi_dispatcher()
PCI: hv: Get vPCI MSI IRQ domain from DeviceTree

 .../bindings/bus/microsoft,vmbus.yaml         | 17 ++++-
 arch/arm64/hyperv/mshyperv.c                  | 46 ++++++++++--
 arch/arm64/kvm/hypercalls.c                   |  5 +-
 arch/x86/hyperv/hv_init.c                     | 34 ---------
 arch/x86/hyperv/hv_vtl.c                      |  7 +-
 drivers/acpi/irq.c                            | 15 +++-
 drivers/firmware/smccc/kvm_guest.c            | 10 +--
 drivers/firmware/smccc/smccc.c                | 19 +++++
 drivers/hv/Kconfig                            |  6 +-
 drivers/hv/hv_common.c                        | 31 ++++++++
 drivers/hv/vmbus_drv.c                        | 53 ++++++++++++--
 drivers/pci/controller/pci-hyperv.c           | 73 +++++++++++++++++--
 include/asm-generic/mshyperv.h                |  6 ++
 include/hyperv/hvgdk_mini.h                   |  2 +-
 include/linux/acpi.h                          |  5 +-
 include/linux/arm-smccc.h                     | 55 +++++++++++++-
 include/linux/hyperv.h                        |  2 +
 17 files changed, 307 insertions(+), 79 deletions(-)

base-commit: d9608f6dc3e3229a40e1db1dab573d6882f38c2a

Signature · 1 line
2.43.0
#1 lore raw

PATCH v6 1/11 arm64: kvm, smccc: Introduce and use API for detecting hypervisor presence

The KVM/arm64 uses SMCCC to detect hypervisor presence. That code is private, and it follows the SMCCC specification. Other existing and emerging hypervisor guest implementations can and should use that standard approach as well.

Factor out a common infrastructure that the guests can use, update KVM to employ the new API. The central notion of the SMCCC method is the UUID of the hypervisor, and the API follows that.

No functional changes. Validated with a KVM/arm64 guest.

---
 arch/arm64/kvm/hypercalls.c        |  5 +--
 drivers/firmware/smccc/kvm_guest.c | 10 ++----
 drivers/firmware/smccc/smccc.c     | 19 +++++++++++
 include/linux/arm-smccc.h          | 55 +++++++++++++++++++++++++++---
 4 files changed, 73 insertions(+), 16 deletions(-)
arch/arm64/kvm/hypercalls.c +1 -4
index 27ce4cb44904..92b9bc1ea8e8 100644
@@ -353,10 +353,7 @@ int kvm_smccc_call_handler(struct kvm_vcpu *vcpu)
 			val[0] = gpa;
 		break;
 	case ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID:
-		val[0] = ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0;
-		val[1] = ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1;
-		val[2] = ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_2;
-		val[3] = ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3;
+		UUID_TO_SMCCC_RES(ARM_SMCCC_VENDOR_HYP_UID_KVM, val);
 		break;
 	case ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID:
 		val[0] = smccc_feat->vendor_hyp_bmap;
drivers/firmware/smccc/kvm_guest.c +2 -8
index f3319be20b36..b5084b309ea0 100644
@@ -14,17 +14,11 @@ static DECLARE_BITMAP(__kvm_arm_hyp_services, ARM_SMCCC_KVM_NUM_FUNCS) __ro_afte
 
 void __init kvm_init_hyp_services(void)
 {
+	uuid_t kvm_uuid = ARM_SMCCC_VENDOR_HYP_UID_KVM;
 	struct arm_smccc_res res;
 	u32 val[4];
 
-	if (arm_smccc_1_1_get_conduit() != SMCCC_CONDUIT_HVC)
-		return;
-
-	arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID, &res);
-	if (res.a0 != ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0 ||
-	    res.a1 != ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1 ||
-	    res.a2 != ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_2 ||
-	    res.a3 != ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3)
+	if (!arm_smccc_hyp_present(&kvm_uuid))
 		return;
 
 	memset(&res, 0, sizeof(res));
drivers/firmware/smccc/smccc.c +19 -0
index a74600d9f2d7..7399f27d58e5 100644
@@ -67,6 +67,25 @@ s32 arm_smccc_get_soc_id_revision(void)
 }
 EXPORT_SYMBOL_GPL(arm_smccc_get_soc_id_revision);
 
+bool arm_smccc_hyp_present(const uuid_t *hyp_uuid)
+{
+	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);
+	if (res.a0 == SMCCC_RET_NOT_SUPPORTED)
+		return false;
+
+	return ({
+		const uuid_t uuid = SMCCC_RES_TO_UUID(res.a0, res.a1, res.a2, res.a3);
+		const bool present = uuid_equal(&uuid, hyp_uuid);
+
+		present;
+	});
+}
+EXPORT_SYMBOL_GPL(arm_smccc_hyp_present);
+
 static int __init smccc_devices_init(void)
 {
 	struct platform_device *pdev;
include/linux/arm-smccc.h +51 -4

73 lines not on this page · raw message

Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH hyperv-next v6 01/11] arm64: kvm, smccc: Introduce and use API for detecting hypervisor presence

Quoted 5 lines · Roman Kisel

The KVM/arm64 uses SMCCC to detect hypervisor presence. That code is private, and it follows the SMCCC specification. Other existing and emerging hypervisor guest implementations can and should use that standard approach as well.

Quoted 8 lines

Factor out a common infrastructure that the guests can use, update KVM to employ the new API. The central notion of the SMCCC method is the UUID of the hypervisor, and the API follows that.

No functional changes. Validated with a KVM/arm64 guest.

While the change is Acked, here is the caveat maybe.

This patch produces warnings wtih sparse and CHECK_ENDING. That said, the kernel build produces a whole lot more other warnings from building with sparse by itself and/or with CHECK_ENDING.

I am not sure how to proceed with that, thinking I should not add warnings yet at the same time there are many others. Not certain if folks take these signals as fyi or blockers.

Decided to send V6 to trim the V5 discussion threads by implementing suggestions and fixes.

Quoted 157 lines
---
  arch/arm64/kvm/hypercalls.c        |  5 +--
  drivers/firmware/smccc/kvm_guest.c | 10 ++----
  drivers/firmware/smccc/smccc.c     | 19 +++++++++++
  include/linux/arm-smccc.h          | 55 +++++++++++++++++++++++++++---
  4 files changed, 73 insertions(+), 16 deletions(-)
arch/arm64/kvm/hypercalls.c +1 -4
index 27ce4cb44904..92b9bc1ea8e8 100644
@@ -353,10 +353,7 @@ int kvm_smccc_call_handler(struct kvm_vcpu *vcpu)
  			val[0] = gpa;
  		break;
  	case ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID:
-		val[0] = ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0;
-		val[1] = ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1;
-		val[2] = ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_2;
-		val[3] = ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3;
+		UUID_TO_SMCCC_RES(ARM_SMCCC_VENDOR_HYP_UID_KVM, val);
  		break;
  	case ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID:
  		val[0] = smccc_feat->vendor_hyp_bmap;
drivers/firmware/smccc/kvm_guest.c +2 -8
index f3319be20b36..b5084b309ea0 100644
@@ -14,17 +14,11 @@ static DECLARE_BITMAP(__kvm_arm_hyp_services, ARM_SMCCC_KVM_NUM_FUNCS) __ro_afte
 
  void __init kvm_init_hyp_services(void)
  {
+	uuid_t kvm_uuid = ARM_SMCCC_VENDOR_HYP_UID_KVM;
  	struct arm_smccc_res res;
  	u32 val[4];
 
-	if (arm_smccc_1_1_get_conduit() != SMCCC_CONDUIT_HVC)
-		return;
-
-	arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID, &res);
-	if (res.a0 != ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0 ||
-	    res.a1 != ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1 ||
-	    res.a2 != ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_2 ||
-	    res.a3 != ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3)
+	if (!arm_smccc_hyp_present(&kvm_uuid))
  		return;
 
  	memset(&res, 0, sizeof(res));
drivers/firmware/smccc/smccc.c +19 -0
index a74600d9f2d7..7399f27d58e5 100644
@@ -67,6 +67,25 @@ s32 arm_smccc_get_soc_id_revision(void)
  }
  EXPORT_SYMBOL_GPL(arm_smccc_get_soc_id_revision);
 
+bool arm_smccc_hyp_present(const uuid_t *hyp_uuid)
+{
+	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);
+	if (res.a0 == SMCCC_RET_NOT_SUPPORTED)
+		return false;
+
+	return ({
+		const uuid_t uuid = SMCCC_RES_TO_UUID(res.a0, res.a1, res.a2, res.a3);
+		const bool present = uuid_equal(&uuid, hyp_uuid);
+
+		present;
+	});
+}
+EXPORT_SYMBOL_GPL(arm_smccc_hyp_present);
+
  static int __init smccc_devices_init(void)
  {
  	struct platform_device *pdev;
include/linux/arm-smccc.h +51 -4
index 67f6fdf2e7cd..726f18221f1c 100644
@@ -7,6 +7,11 @@
 
  #include <linux/args.h>
  #include <linux/init.h>
+
+#ifndef __ASSEMBLER__
+#include <linux/uuid.h>
+#endif
+
  #include <uapi/linux/const.h>
 
  /*
@@ -107,10 +112,10 @@
  			   ARM_SMCCC_FUNC_QUERY_CALL_UID)
 
  /* KVM UID value: 28b46fb6-2ec5-11e9-a9ca-4b564d003a74 */
-#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0	0xb66fb428U
-#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1	0xe911c52eU
-#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_2	0x564bcaa9U
-#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3	0x743a004dU
+#define ARM_SMCCC_VENDOR_HYP_UID_KVM UUID_INIT(\
+	0xb66fb428, 0xc52e, 0xe911, \
+	0xa9, 0xca, 0x4b, 0x56, \
+	0x4d, 0x00, 0x3a, 0x74)
 
  /* KVM "vendor specific" services */
  #define ARM_SMCCC_KVM_FUNC_FEATURES		0
@@ -333,6 +338,48 @@ s32 arm_smccc_get_soc_id_version(void);
   */
  s32 arm_smccc_get_soc_id_revision(void);
 
+#ifndef __ASSEMBLER__
+
+/**
+ * arm_smccc_hyp_present(const uuid_t *hyp_uuid)
+ *
+ * Returns `true` if the hypervisor advertises its presence via SMCCC.
+ *
+ * When the function returns `false`, the caller shall not assume that
+ * there is no hypervisor running. Instead, the caller must fall back to
+ * other approaches if any are available.
+ */
+bool arm_smccc_hyp_present(const uuid_t *hyp_uuid);
+
+#define SMCCC_RES_TO_UUID(r0, r1, r2, r3) \
+	UUID_INIT( \
+		cpu_to_le32(lower_32_bits(r0)), \
+		cpu_to_le32(lower_32_bits(r1)) & 0xffff, \
+		cpu_to_le32(lower_32_bits(r1)) >> 16, \
+		cpu_to_le32(lower_32_bits(r2)) & 0xff, \
+		(cpu_to_le32(lower_32_bits(r2)) >> 8) & 0xff, \
+		(cpu_to_le32(lower_32_bits(r2)) >> 16) & 0xff, \
+		(cpu_to_le32(lower_32_bits(r2)) >> 24) & 0xff, \
+		cpu_to_le32(lower_32_bits(r3)) & 0xff, \
+		(cpu_to_le32(lower_32_bits(r3)) >> 8) & 0xff, \
+		(cpu_to_le32(lower_32_bits(r3)) >> 16) & 0xff, \
+		(cpu_to_le32(lower_32_bits(r3)) >> 24) & 0xff \
+	)
+
+#define UUID_TO_SMCCC_RES(uuid_init, regs) do { \
+		const uuid_t uuid = uuid_init; \
+		(regs)[0] = le32_to_cpu((u32)uuid.b[0] | (uuid.b[1] << 8) | \
+						((uuid.b[2]) << 16) | ((uuid.b[3]) << 24)); \
+		(regs)[1] = le32_to_cpu((u32)uuid.b[4] | (uuid.b[5] << 8) | \
+						((uuid.b[6]) << 16) | ((uuid.b[7]) << 24)); \
+		(regs)[2] = le32_to_cpu((u32)uuid.b[8] | (uuid.b[9] << 8) | \
+						((uuid.b[10]) << 16) | ((uuid.b[11]) << 24)); \
+		(regs)[3] = le32_to_cpu((u32)uuid.b[12] | (uuid.b[13] << 8) | \
+						((uuid.b[14]) << 16) | ((uuid.b[15]) << 24)); \
+	} while (0)
+
+#endif /* !__ASSEMBLER__ */
+
  /**
   * struct arm_smccc_res - Result from SMC/HVC call
   * @a0-a3 result values from registers 0 to 3
Signature · 2 lines
Thank you,
Roman
maintainer
#3 lore raw

Re: [PATCH hyperv-next v6 01/11] arm64: kvm, smccc: Introduce and use API for detecting hypervisor presence

Quoted 11 lines · Roman Kisel

On 3/14/2025 5:19 PM, Roman Kisel wrote:

While the change is Acked, here is the caveat maybe.

This patch produces warnings wtih sparse and CHECK_ENDING. That said, the kernel build produces a whole lot more other warnings from building with sparse by itself and/or with CHECK_ENDING.

I am not sure how to proceed with that, thinking I should not add warnings yet at the same time there are many others. Not certain if folks take these signals as fyi or blockers.

It would be best not to add warnigns. There is slow progress on fixing all the endianess warnings and I hope this can eventually complete, so even if there are many existing ones please try to keep new code clean.

Arnd

#4 lore raw

Re: [PATCH hyperv-next v6 01/11] arm64: kvm, smccc: Introduce and use API for detecting hypervisor presence

Quoted 9 lines · Arnd Bergmann
Quoted 8 lines · Roman Kisel

On 3/14/2025 5:19 PM, Roman Kisel wrote:

While the change is Acked, here is the caveat maybe.

This patch produces warnings wtih sparse and CHECK_ENDING. That said, the kernel build produces a whole lot more other warnings from building with sparse by itself and/or with CHECK_ENDING.

Quoted 9 lines
Quoted 3 lines

I am not sure how to proceed with that, thinking I should not add warnings yet at the same time there are many others. Not certain if folks take these signals as fyi or blockers.

It would be best not to add warnigns. There is slow progress on fixing all the endianess warnings and I hope this can eventually complete, so even if there are many existing ones please try to keep new code clean.

Will fix the warnings, appreciate providing the guidance!

Quoted 1 line

Arnd

Signature · 2 lines
Thank you,
Roman
maintainer
#5 lore raw

Re: [PATCH hyperv-next v6 01/11] arm64: kvm, smccc: Introduce and use API for detecting hypervisor presence

In reply to Roman Kisel
Quoted 75 lines · Roman Kisel

The KVM/arm64 uses SMCCC to detect hypervisor presence. That code is private, and it follows the SMCCC specification. Other existing and emerging hypervisor guest implementations can and should use that standard approach as well.

Factor out a common infrastructure that the guests can use, update KVM to employ the new API. The central notion of the SMCCC method is the UUID of the hypervisor, and the API follows that.

No functional changes. Validated with a KVM/arm64 guest.

---
 arch/arm64/kvm/hypercalls.c        |  5 +--
 drivers/firmware/smccc/kvm_guest.c | 10 ++----
 drivers/firmware/smccc/smccc.c     | 19 +++++++++++
 include/linux/arm-smccc.h          | 55 +++++++++++++++++++++++++++---
 4 files changed, 73 insertions(+), 16 deletions(-)
arch/arm64/kvm/hypercalls.c +1 -4
index 27ce4cb44904..92b9bc1ea8e8 100644
@@ -353,10 +353,7 @@ int kvm_smccc_call_handler(struct kvm_vcpu *vcpu)
 			val[0] = gpa;
 		break;
 	case ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID:
-		val[0] = ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0;
-		val[1] = ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1;
-		val[2] = ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_2;
-		val[3] = ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3;
+		UUID_TO_SMCCC_RES(ARM_SMCCC_VENDOR_HYP_UID_KVM, val);
 		break;
 	case ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID:
 		val[0] = smccc_feat->vendor_hyp_bmap;
drivers/firmware/smccc/kvm_guest.c +2 -8
index f3319be20b36..b5084b309ea0 100644
@@ -14,17 +14,11 @@ static DECLARE_BITMAP(__kvm_arm_hyp_services, ARM_SMCCC_KVM_NUM_FUNCS) __ro_afte
 
 void __init kvm_init_hyp_services(void)
 {
+	uuid_t kvm_uuid = ARM_SMCCC_VENDOR_HYP_UID_KVM;
 	struct arm_smccc_res res;
 	u32 val[4];
 
-	if (arm_smccc_1_1_get_conduit() != SMCCC_CONDUIT_HVC)
-		return;
-
-	arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID, &res);
-	if (res.a0 != ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0 ||
-	    res.a1 != ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1 ||
-	    res.a2 != ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_2 ||
-	    res.a3 != ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3)
+	if (!arm_smccc_hyp_present(&kvm_uuid))
 		return;
 
 	memset(&res, 0, sizeof(res));
drivers/firmware/smccc/smccc.c +7 -0
index a74600d9f2d7..7399f27d58e5 100644
@@ -67,6 +67,25 @@ s32 arm_smccc_get_soc_id_revision(void)
 }
 EXPORT_SYMBOL_GPL(arm_smccc_get_soc_id_revision);
 
+bool arm_smccc_hyp_present(const uuid_t *hyp_uuid)
+{
+	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);

drivers/firmware/smccc/smccc.c s32 arm_smccc_get_soc_id_revision(void) · line 86

Quoted 10 lines
drivers/firmware/smccc/smccc.c +10 -0
+	if (res.a0 == SMCCC_RET_NOT_SUPPORTED)
+		return false;
+
+	return ({
+		const uuid_t uuid = SMCCC_RES_TO_UUID(res.a0, res.a1, res.a2, res.a3);
+		const bool present = uuid_equal(&uuid, hyp_uuid);
+
+		present;
+	});
+}

This use of a statement expression is bizarre, and the function would be clearer without it, e.g.

| bool arm_smccc_hyp_present(const uuid_t *hyp_uuid)
| {
| 	struct arm_smccc_res res = {};
| 	uuid_t uuid;
| 
| 	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);
| 	if (res.a0 == SMCCC_RET_NOT_SUPPORTED)
| 		return false;
| 	
| 	uuid_t = SMCCC_RES_TO_UUID(res.a0, res.a1, res.a2, res.a3);
| 	return uuid_equal(&uuid, hyp_uuid);
| }

As noted below, I'd prefer if this were renamed to something like arm_smccc_hypervisor_has_uuid(), to more clearly indicate what is being checked.

[...]

drivers/firmware/smccc/smccc.c s32 arm_smccc_get_soc_id_revision(void)

Quoted 10 lines
drivers/firmware/smccc/smccc.c +10 -0
+/**
+ * arm_smccc_hyp_present(const uuid_t *hyp_uuid)
+ *
+ * Returns `true` if the hypervisor advertises its presence via SMCCC.
+ *
+ * When the function returns `false`, the caller shall not assume that
+ * there is no hypervisor running. Instead, the caller must fall back to
+ * other approaches if any are available.
+ */
+bool arm_smccc_hyp_present(const uuid_t *hyp_uuid);

I'd prefer if this were:

| /*
|  * Returns whether a specific hypervisor UUID is advertised for the
|  * Vendor Specific Hypervisor Service range.
|  */
| bool arm_smccc_hypervisor_has_uuid(const uuid_t *uuid);
Quoted 4 lines
drivers/firmware/smccc/smccc.c +4 -0
+#define SMCCC_RES_TO_UUID(r0, r1, r2, r3) \
+	UUID_INIT( \
+		cpu_to_le32(lower_32_bits(r0)), \
+		cpu_to_le32(lower_32_bits(r1)) & 0xffff, \

drivers/firmware/smccc/smccc.c

Quoted 10 lines
drivers/firmware/smccc/smccc.c +10 -0
+		cpu_to_le32(lower_32_bits(r1)) >> 16, \
+		cpu_to_le32(lower_32_bits(r2)) & 0xff, \
+		(cpu_to_le32(lower_32_bits(r2)) >> 8) & 0xff, \
+		(cpu_to_le32(lower_32_bits(r2)) >> 16) & 0xff, \
+		(cpu_to_le32(lower_32_bits(r2)) >> 24) & 0xff, \
+		cpu_to_le32(lower_32_bits(r3)) & 0xff, \
+		(cpu_to_le32(lower_32_bits(r3)) >> 8) & 0xff, \
+		(cpu_to_le32(lower_32_bits(r3)) >> 16) & 0xff, \
+		(cpu_to_le32(lower_32_bits(r3)) >> 24) & 0xff \
+	)

I think this'd be clearer if we did something similar to what we did for the SMCCC SOC_ID name:

https://lore.kernel.org/linux-arm-kernel/[email protected]/

... and pack/unpack the bytes explicitly, e.g.

| static inline uuid smccc_res_to_uuid(u32 r0, u32, r1, u32 r2, u32 r3)
| {
| 	uuid_t uuid = {
| 		.b = {
| 			[0]  = (r0 >> 0)  & 0xff,
| 			[1]  = (r0 >> 8)  & 0xff,
| 			[2]  = (r0 >> 16) & 0xff,
| 			[3]  = (r0 >> 24) & 0xff,
| 
| 			[4]  = (r1 >> 0)  & 0xff,
| 			[5]  = (r1 >> 8)  & 0xff,
| 			[6]  = (r1 >> 16) & 0xff,
| 			[7]  = (r1 >> 24) & 0xff,
| 
| 			[8]  = (r2 >> 0)  & 0xff,
| 			[9]  = (r2 >> 8)  & 0xff,
| 			[10] = (r2 >> 16) & 0xff,
| 			[11] = (r2 >> 24) & 0xff,
| 
| 			[12] = (r3 >> 0)  & 0xff,
| 			[13] = (r3 >> 8)  & 0xff,
| 			[14] = (r3 >> 16) & 0xff,
| 			[15] = (r3 >> 24) & 0xff,
| 		},
| 	};
| 
| 	return uuid;
| }

... which is a bit more verbose, but clearly aligns with what the SMCCC spec says w.r.t. packing/unpacking, and should avoid warnings about endianness conversions.

Quoted 4 lines
drivers/firmware/smccc/smccc.c +4 -0
+
+#define UUID_TO_SMCCC_RES(uuid_init, regs) do { \
+		const uuid_t uuid = uuid_init; \
+		(regs)[0] = le32_to_cpu((u32)uuid.b[0] | (uuid.b[1] << 8) | \

drivers/firmware/smccc/smccc.c

Quoted 10 lines
drivers/firmware/smccc/smccc.c +10 -0
+						((uuid.b[2]) << 16) | ((uuid.b[3]) << 24)); \
+		(regs)[1] = le32_to_cpu((u32)uuid.b[4] | (uuid.b[5] << 8) | \
+						((uuid.b[6]) << 16) | ((uuid.b[7]) << 24)); \
+		(regs)[2] = le32_to_cpu((u32)uuid.b[8] | (uuid.b[9] << 8) | \
+						((uuid.b[10]) << 16) | ((uuid.b[11]) << 24)); \
+		(regs)[3] = le32_to_cpu((u32)uuid.b[12] | (uuid.b[13] << 8) | \
+						((uuid.b[14]) << 16) | ((uuid.b[15]) << 24)); \
+	} while (0)
+
+#endif /* !__ASSEMBLER__ */

IMO it'd be clearer to initialise a uuid_t beforehand, and then allow the helper to unpack the bytes, e.g.

static inline u32 smccc_uuid_to_reg(const uuid_t uuid, int reg)

{
	u32 val = 0;

	val |= (u32)(uuid.b[4 * reg + 0] << 0)
	val |= (u32)(uuid.b[4 * reg + 1] << 8)
	val |= (u32)(uuid.b[4 * reg + 2] << 16)
	val |= (u32)(uuid.b[4 * reg + 3] << 24)

	return val:
}

#define UUID_TO_SMCCC_RES(uuid, regs) \

do {						\
	(regs)[0] = smccc_uuid_to_reg(uuid, 0); \
	(regs)[1] = smccc_uuid_to_reg(uuid, 1); \
	(regs)[2] = smccc_uuid_to_reg(uuid, 2); \
	(regs)[3] = smccc_uuid_to_reg(uuid, 3); \
} while (0)

... though arguably at that point you can get rid of the UUID_TO_SMCCC_RES() macro and just expand that directly at the callsite.

Mark.

#6 lore raw

Re: [PATCH hyperv-next v6 01/11] arm64: kvm, smccc: Introduce and use API for detecting hypervisor presence

Quoted 1 line · Mark Rutland

On Fri, Mar 14, 2025 at 05:19:21PM -0700, Roman Kisel wrote:

[...]

Quoted 4 lines
Quoted 1 line

+}

This use of a statement expression is bizarre, and the function would be clearer without it, e.g.

I'll change that to what you're suggesting, thanks for your help!

Quoted 17 lines
| bool arm_smccc_hyp_present(const uuid_t *hyp_uuid)
| {
| 	struct arm_smccc_res res = {};
| 	uuid_t uuid;
|
| 	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);
| 	if (res.a0 == SMCCC_RET_NOT_SUPPORTED)
| 		return false;
| 	
| 	uuid_t = SMCCC_RES_TO_UUID(res.a0, res.a1, res.a2, res.a3);
| 	return uuid_equal(&uuid, hyp_uuid);
| }
Quoted 5 lines

As noted below, I'd prefer if this were renamed to something like arm_smccc_hypervisor_has_uuid(), to more clearly indicate what is being checked.

[...]

Will update, thanks for your help!

Quoted 20 lines

include/linux/arm-smccc.h s32 arm_smccc_get_soc_id_version(void); · line 352

Quoted 11 lines
include/linux/arm-smccc.h +10 -0
+/**
+ * arm_smccc_hyp_present(const uuid_t *hyp_uuid)
+ *
+ * Returns `true` if the hypervisor advertises its presence via SMCCC.
+ *
+ * When the function returns `false`, the caller shall not assume that
+ * there is no hypervisor running. Instead, the caller must fall back to
+ * other approaches if any are available.
+ */
+bool arm_smccc_hyp_present(const uuid_t *hyp_uuid);

I'd prefer if this were:

| /*
|  * Returns whether a specific hypervisor UUID is advertised for the
|  * Vendor Specific Hypervisor Service range.
|  */
| bool arm_smccc_hypervisor_has_uuid(const uuid_t *uuid);

[...]

Quoted 7 lines

I think this'd be clearer if we did something similar to what we did for the SMCCC SOC_ID name:

   https://lore.kernel.org/linux-arm-kernel/[email protected]/

... and pack/unpack the bytes explicitly, e.g.

That looks great, thanks for the suggestion!

Quoted 30 lines
| static inline uuid smccc_res_to_uuid(u32 r0, u32, r1, u32 r2, u32 r3)
| {
| 	uuid_t uuid = {
| 		.b = {
| 			[0]  = (r0 >> 0)  & 0xff,
| 			[1]  = (r0 >> 8)  & 0xff,
| 			[2]  = (r0 >> 16) & 0xff,
| 			[3]  = (r0 >> 24) & 0xff,
|
| 			[4]  = (r1 >> 0)  & 0xff,
| 			[5]  = (r1 >> 8)  & 0xff,
| 			[6]  = (r1 >> 16) & 0xff,
| 			[7]  = (r1 >> 24) & 0xff,
|
| 			[8]  = (r2 >> 0)  & 0xff,
| 			[9]  = (r2 >> 8)  & 0xff,
| 			[10] = (r2 >> 16) & 0xff,
| 			[11] = (r2 >> 24) & 0xff,
|
| 			[12] = (r3 >> 0)  & 0xff,
| 			[13] = (r3 >> 8)  & 0xff,
| 			[14] = (r3 >> 16) & 0xff,
| 			[15] = (r3 >> 24) & 0xff,
| 		},
| 	};
|
| 	return uuid;
| }
Quoted 4 lines

... which is a bit more verbose, but clearly aligns with what the SMCCC spec says w.r.t. packing/unpacking, and should avoid warnings about endianness conversions.

I believe what you're proposing hits a better trade-off, thanks again!

Quoted 38 lines
Quoted 4 lines
include/linux/arm-smccc.h +4 -0
+
+#define UUID_TO_SMCCC_RES(uuid_init, regs) do { \
+		const uuid_t uuid = uuid_init; \
+		(regs)[0] = le32_to_cpu((u32)uuid.b[0] | (uuid.b[1] << 8) | \

include/linux/arm-smccc.h s32 arm_smccc_get_soc_id_version(void); · line 381

Quoted 10 lines
include/linux/arm-smccc.h +10 -0
+						((uuid.b[2]) << 16) | ((uuid.b[3]) << 24)); \
+		(regs)[1] = le32_to_cpu((u32)uuid.b[4] | (uuid.b[5] << 8) | \
+						((uuid.b[6]) << 16) | ((uuid.b[7]) << 24)); \
+		(regs)[2] = le32_to_cpu((u32)uuid.b[8] | (uuid.b[9] << 8) | \
+						((uuid.b[10]) << 16) | ((uuid.b[11]) << 24)); \
+		(regs)[3] = le32_to_cpu((u32)uuid.b[12] | (uuid.b[13] << 8) | \
+						((uuid.b[14]) << 16) | ((uuid.b[15]) << 24)); \
+	} while (0)
+
+#endif /* !__ASSEMBLER__ */

IMO it'd be clearer to initialise a uuid_t beforehand, and then allow the helper to unpack the bytes, e.g.

static inline u32 smccc_uuid_to_reg(const uuid_t uuid, int reg)

{
	u32 val = 0;

	val |= (u32)(uuid.b[4 * reg + 0] << 0)
	val |= (u32)(uuid.b[4 * reg + 1] << 8)
	val |= (u32)(uuid.b[4 * reg + 2] << 16)
	val |= (u32)(uuid.b[4 * reg + 3] << 24)

	return val:
}

#define UUID_TO_SMCCC_RES(uuid, regs) \

do {						\
	(regs)[0] = smccc_uuid_to_reg(uuid, 0); \
	(regs)[1] = smccc_uuid_to_reg(uuid, 1); \
	(regs)[2] = smccc_uuid_to_reg(uuid, 2); \
	(regs)[3] = smccc_uuid_to_reg(uuid, 3); \
} while (0)
Quoted 3 lines

... though arguably at that point you can get rid of the UUID_TO_SMCCC_RES() macro and just expand that directly at the callsite.

I'll work on that, thanks!!

Quoted 1 line

Mark.

Signature · 2 lines
Thank you,
Roman
#7 lore raw

Re: [PATCH hyperv-next v6 01/11] arm64: kvm, smccc: Introduce and use API for detecting hypervisor presence

In reply to Roman Kisel
kernel test robot noticed the following build warnings:

Hi Roman,

kernel test robot noticed the following build warnings:

[auto build test WARNING on d9608f6dc3e3229a40e1db1dab573d6882f38c2a]

url:    https://github.com/intel-lab-lkp/linux/commits/Roman-Kisel/arm64-kvm-smccc-Introduce-and-use-API-for-detecting-hypervisor-presence/20250315-082319
base:   d9608f6dc3e3229a40e1db1dab573d6882f38c2a
patch link:    https://lore.kernel.org/r/20250315001931.631210-2-romank%40linux.microsoft.com
patch subject: [PATCH hyperv-next v6 01/11] arm64: kvm, smccc: Introduce and use API for detecting hypervisor presence
config: arm64-randconfig-r122-20250317 (https://download.01.org/0day-ci/archive/20250317/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 14.2.0
reproduce: (https://download.01.org/0day-ci/archive/20250317/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)

>> arch/arm64/kvm/hypercalls.c:356:17: sparse: sparse: cast to restricted __le32
>> arch/arm64/kvm/hypercalls.c:356:17: sparse: sparse: cast to restricted __le32
>> arch/arm64/kvm/hypercalls.c:356:17: sparse: sparse: cast to restricted __le32
>> arch/arm64/kvm/hypercalls.c:356:17: sparse: sparse: cast to restricted __le32

vim +356 arch/arm64/kvm/hypercalls.c

262
263 int kvm_smccc_call_handler(struct kvm_vcpu *vcpu)
264 {
265 struct kvm_smccc_features *smccc_feat = &vcpu->kvm->arch.smccc_feat;
266 u32 func_id = smccc_get_function(vcpu);
267 u64 val[4] = {SMCCC_RET_NOT_SUPPORTED};
268 u32 feature;
269 u8 action;
270 gpa_t gpa;
271
272 action = kvm_smccc_get_action(vcpu, func_id);
273 switch (action) {
274 case KVM_SMCCC_FILTER_HANDLE:
275 break;
276 case KVM_SMCCC_FILTER_DENY:
277 goto out;
278 case KVM_SMCCC_FILTER_FWD_TO_USER:
279 kvm_prepare_hypercall_exit(vcpu, func_id);
280 return 0;
281 default:
282 WARN_RATELIMIT(1, "Unhandled SMCCC filter action: %d\n", action);
283 goto out;
284 }
285
286 switch (func_id) {
287 case ARM_SMCCC_VERSION_FUNC_ID:
288 val[0] = ARM_SMCCC_VERSION_1_1;
289 break;
290 case ARM_SMCCC_ARCH_FEATURES_FUNC_ID:
291 feature = smccc_get_arg1(vcpu);
292 switch (feature) {
293 case ARM_SMCCC_ARCH_WORKAROUND_1:
294 switch (arm64_get_spectre_v2_state()) {
295 case SPECTRE_VULNERABLE:
296 break;
297 case SPECTRE_MITIGATED:
298 val[0] = SMCCC_RET_SUCCESS;
299 break;
300 case SPECTRE_UNAFFECTED:
301 val[0] = SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED;
302 break;
303 }
304 break;
305 case ARM_SMCCC_ARCH_WORKAROUND_2:
306 switch (arm64_get_spectre_v4_state()) {
307 case SPECTRE_VULNERABLE:
308 break;
309 case SPECTRE_MITIGATED:
310 /*
311 * SSBS everywhere: Indicate no firmware
312 * support, as the SSBS support will be
313 * indicated to the guest and the default is
314 * safe.
315 *
316 * Otherwise, expose a permanent mitigation
317 * to the guest, and hide SSBS so that the
318 * guest stays protected.
319 */
320 if (kvm_has_feat(vcpu->kvm, ID_AA64PFR1_EL1, SSBS, IMP))
321 break;
322 fallthrough;
323 case SPECTRE_UNAFFECTED:
324 val[0] = SMCCC_RET_NOT_REQUIRED;
325 break;
326 }
327 break;
328 case ARM_SMCCC_ARCH_WORKAROUND_3:
329 switch (arm64_get_spectre_bhb_state()) {
330 case SPECTRE_VULNERABLE:
331 break;
332 case SPECTRE_MITIGATED:
333 val[0] = SMCCC_RET_SUCCESS;
334 break;
335 case SPECTRE_UNAFFECTED:
336 val[0] = SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED;
337 break;
338 }
339 break;
340 case ARM_SMCCC_HV_PV_TIME_FEATURES:
341 if (test_bit(KVM_REG_ARM_STD_HYP_BIT_PV_TIME,
342 &smccc_feat->std_hyp_bmap))
343 val[0] = SMCCC_RET_SUCCESS;
344 break;
345 }
346 break;
347 case ARM_SMCCC_HV_PV_TIME_FEATURES:
348 val[0] = kvm_hypercall_pv_features(vcpu);
349 break;
350 case ARM_SMCCC_HV_PV_TIME_ST:
351 gpa = kvm_init_stolen_time(vcpu);
352 if (gpa != INVALID_GPA)
353 val[0] = gpa;
354 break;
355 case ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID:

 > 356			UUID_TO_SMCCC_RES(ARM_SMCCC_VENDOR_HYP_UID_KVM, val);

357 break;
358 case ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID:
359 val[0] = smccc_feat->vendor_hyp_bmap;
360 break;
361 case ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID:
362 kvm_ptp_get_time(vcpu, val);
363 break;
364 case ARM_SMCCC_TRNG_VERSION:
365 case ARM_SMCCC_TRNG_FEATURES:
366 case ARM_SMCCC_TRNG_GET_UUID:
367 case ARM_SMCCC_TRNG_RND32:
368 case ARM_SMCCC_TRNG_RND64:
369 return kvm_trng_call(vcpu);
370 default:
371 return kvm_psci_call(vcpu);
372 }
373
374 out:
375 smccc_set_retval(vcpu, val[0], val[1], val[2], val[3]);
376 return 1;
377 }
378

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#8 lore raw

PATCH v6 2/11 arm64: hyperv: Use SMCCC to detect hypervisor presence

In reply to Roman Kisel

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. Then use the vendor-specific hypervisor service call (implemented recently in Hyper-V) via SMCCC in the non-ACPI case.

---
 arch/arm64/hyperv/mshyperv.c | 43 +++++++++++++++++++++++++++++++-----
 1 file changed, 38 insertions(+), 5 deletions(-)
arch/arm64/hyperv/mshyperv.c +38 -5
index 2265ea5ce5ad..c5b03d3af7c5 100644
@@ -27,6 +27,41 @@ int hv_get_hypervisor_version(union hv_hypervisor_version_info *info)
 	return 0;
 }
 
+static bool __init hyperv_detect_via_acpi(void)
+{
+	if (acpi_disabled)
+		return false;
+#if IS_ENABLED(CONFIG_ACPI)
+	/*
+	 * Hypervisor ID is only available in ACPI v6+, and the
+	 * structure layout was extended in v6 to accommodate that
+	 * new field.
+	 *
+	 * At the very minimum, this check makes sure not to read
+	 * past the FADT structure.
+	 *
+	 * It is also needed to catch running in some unknown
+	 * non-Hyper-V environment that has ACPI 5.x or less.
+	 * In such a case, it can't be Hyper-V.
+	 */
+	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 __init hyperv_detect_via_smccc(void)
+{
+	uuid_t hyperv_uuid = UUID_INIT(
+		0x4d32ba58, 0x4764, 0xcd24,
+		0x75, 0x6c, 0xef, 0x8e,
+		0x24, 0x70, 0x59, 0x16);
+
+	return arm_smccc_hyp_present(&hyperv_uuid);
+}
+
 static int __init hyperv_init(void)
 {
 	struct hv_get_vp_registers_output	result;
@@ -35,13 +70,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_smccc())
 		return 0;
 
 	/* Setup the guest ID */
Signature · 1 line
2.43.0
maintainer
#9 lore raw

Re: [PATCH hyperv-next v6 02/11] arm64: hyperv: Use SMCCC to detect hypervisor presence

Quoted 37 lines · Roman Kisel

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. Then use the vendor-specific hypervisor service call (implemented recently in Hyper-V) via SMCCC in the non-ACPI case.

---
 arch/arm64/hyperv/mshyperv.c | 43 +++++++++++++++++++++++++++++++-----
 1 file changed, 38 insertions(+), 5 deletions(-)
arch/arm64/hyperv/mshyperv.c +15 -0
index 2265ea5ce5ad..c5b03d3af7c5 100644
@@ -27,6 +27,41 @@ int hv_get_hypervisor_version(union hv_hypervisor_version_info *info)
 	return 0;
 }
 
+static bool __init hyperv_detect_via_acpi(void)
+{
+	if (acpi_disabled)
+		return false;
+#if IS_ENABLED(CONFIG_ACPI)
+	/*
+	 * Hypervisor ID is only available in ACPI v6+, and the
+	 * structure layout was extended in v6 to accommodate that
+	 * new field.
+	 *
+	 * At the very minimum, this check makes sure not to read
+	 * past the FADT structure.
+	 *
+	 * It is also needed to catch running in some unknown
+	 * non-Hyper-V environment that has ACPI 5.x or less.

arch/arm64/hyperv/mshyperv.c int hv_get_hypervisor_version(union hv_hypervisor_version_info *info) · line 54

Quoted 10 lines
arch/arm64/hyperv/mshyperv.c +10 -0
+	 * In such a case, it can't be Hyper-V.
+	 */
+	if (acpi_gbl_FADT.header.revision < 6)
+		return false;
+	return strncmp((char *)&acpi_gbl_FADT.hypervisor_id, "MsHyperV", 8) == 0;
+#else
+	return false;
+#endif
+}
+

The 'acpi_disabled' variable doesn't exist for !CONFIG_ACPI, so its use prior to the ifdeffery looks misplaced.

Usual codestyle is to avoid ifdeffery if possible, using IS_ENABLED(). Otherwise, use a stub, e.g.

| #ifdef CONFIG_ACPI
| static bool __init hyperv_detect_via_acpi(void)
| {
| 	if (acpi_disabled)
| 		return false;
| 	
| 	if (acpi_gbl_FADT.header.revision < 6)
| 		return false;
| 	
| 	return strncmp((char *)&acpi_gbl_FADT.hypervisor_id, "MsHyperV", 8) == 0;
| }
| #else
| static inline bool hyperv_detect_via_acpi(void) { return false; }
| #endif

Mark.

Quoted 33 lines
arch/arm64/hyperv/mshyperv.c +13 -5
+static bool __init hyperv_detect_via_smccc(void)
+{
+	uuid_t hyperv_uuid = UUID_INIT(
+		0x4d32ba58, 0x4764, 0xcd24,
+		0x75, 0x6c, 0xef, 0x8e,
+		0x24, 0x70, 0x59, 0x16);
+
+	return arm_smccc_hyp_present(&hyperv_uuid);
+}
+
 static int __init hyperv_init(void)
 {
 	struct hv_get_vp_registers_output	result;
@@ -35,13 +70,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_smccc())
 		return 0;
 
 	/* Setup the guest ID */
Signature · 1 line
2.43.0
#10 lore raw

Re: [PATCH hyperv-next v6 02/11] arm64: hyperv: Use SMCCC to detect hypervisor presence

Quoted 1 line · Mark Rutland

On Fri, Mar 14, 2025 at 05:19:22PM -0700, Roman Kisel wrote:

[...]

Quoted 6 lines

The 'acpi_disabled' variable doesn't exist for !CONFIG_ACPI, so its use prior to the ifdeffery looks misplaced.

Usual codestyle is to avoid ifdeffery if possible, using IS_ENABLED(). Otherwise, use a stub, e.g.

That looks much better, thanks for the review! Will implement in the next version.

Quoted 50 lines
| #ifdef CONFIG_ACPI
| static bool __init hyperv_detect_via_acpi(void)
| {
| 	if (acpi_disabled)
| 		return false;
| 	
| 	if (acpi_gbl_FADT.header.revision < 6)
| 		return false;
| 	
| 	return strncmp((char *)&acpi_gbl_FADT.hypervisor_id, "MsHyperV", 8) == 0;
| }
| #else
| static inline bool hyperv_detect_via_acpi(void) { return false; }
| #endif

Mark.

Quoted 33 lines
arch/arm64/hyperv/mshyperv.c +13 -5
+static bool __init hyperv_detect_via_smccc(void)
+{
+	uuid_t hyperv_uuid = UUID_INIT(
+		0x4d32ba58, 0x4764, 0xcd24,
+		0x75, 0x6c, 0xef, 0x8e,
+		0x24, 0x70, 0x59, 0x16);
+
+	return arm_smccc_hyp_present(&hyperv_uuid);
+}
+
  static int __init hyperv_init(void)
  {
  	struct hv_get_vp_registers_output	result;
@@ -35,13 +70,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_smccc())
  		return 0;
 
  	/* Setup the guest ID */
Signature · 1 line
2.43.0
Signature · 2 lines
Thank you,
Roman
#11 lore raw

RE: [PATCH hyperv-next v6 02/11] arm64: hyperv: Use SMCCC to detect hypervisor presence

In reply to Mark Rutland

From: Mark Rutland <[email protected]> Sent: Monday, March 17, 2025 4:38 AM

Quoted 45 lines · Roman Kisel

arch/arm64/hyperv/mshyperv.c int hv_get_hypervisor_version(union

Quoted 19 lines

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. Then use the vendor-specific hypervisor service call (implemented recently in Hyper-V) via SMCCC in the non-ACPI case.

---
 arch/arm64/hyperv/mshyperv.c | 43 +++++++++++++++++++++++++++++++-----
 1 file changed, 38 insertions(+), 5 deletions(-)
arch/arm64/hyperv/mshyperv.c +0 -0
index 2265ea5ce5ad..c5b03d3af7c5 100644
@@ -27,6 +27,41 @@ int hv_get_hypervisor_version(union

hv_hypervisor_version_info *info)

Quoted 23 lines
arch/arm64/hyperv/mshyperv.c +20 -0
 	return 0;
 }
 
+static bool __init hyperv_detect_via_acpi(void)
+{
+	if (acpi_disabled)
+		return false;
+#if IS_ENABLED(CONFIG_ACPI)
+	/*
+	 * Hypervisor ID is only available in ACPI v6+, and the
+	 * structure layout was extended in v6 to accommodate that
+	 * new field.
+	 *
+	 * At the very minimum, this check makes sure not to read
+	 * past the FADT structure.
+	 *
+	 * It is also needed to catch running in some unknown
+	 * non-Hyper-V environment that has ACPI 5.x or less.
+	 * In such a case, it can't be Hyper-V.
+	 */
+	if (acpi_gbl_FADT.header.revision < 6)
+		return false;
+	return strncmp((char *)&acpi_gbl_FADT.hypervisor_id, "MsHyperV", 8) == 0;
Quoted 8 lines

arch/arm64/hyperv/mshyperv.c int hv_get_hypervisor_version(union hv_hypervisor_version_info *info) · line 54

Quoted 5 lines
arch/arm64/hyperv/mshyperv.c +5 -0
+#else
+	return false;
+#endif
+}
+

The 'acpi_disabled' variable doesn't exist for !CONFIG_ACPI, so its use prior to the ifdeffery looks misplaced.

FWIW, include/linux/acpi.h has

#define acpi_disabled 1

when !CONFIG_ACPI. But I agree that using a stub is better.

Michael

Quoted 54 lines

Usual codestyle is to avoid ifdeffery if possible, using IS_ENABLED(). Otherwise, use a stub, e.g.

| #ifdef CONFIG_ACPI
| static bool __init hyperv_detect_via_acpi(void)
| {
| 	if (acpi_disabled)
| 		return false;
|
| 	if (acpi_gbl_FADT.header.revision < 6)
| 		return false;
|
| 	return strncmp((char *)&acpi_gbl_FADT.hypervisor_id, "MsHyperV", 8) == 0;
| }
| #else
| static inline bool hyperv_detect_via_acpi(void) { return false; }
| #endif

Mark.

Quoted 33 lines
arch/arm64/hyperv/mshyperv.c +13 -6
+static bool __init hyperv_detect_via_smccc(void)
+{
+	uuid_t hyperv_uuid = UUID_INIT(
+		0x4d32ba58, 0x4764, 0xcd24,
+		0x75, 0x6c, 0xef, 0x8e,
+		0x24, 0x70, 0x59, 0x16);
+
+	return arm_smccc_hyp_present(&hyperv_uuid);
+}
+
 static int __init hyperv_init(void)
 {
 	struct hv_get_vp_registers_output	result;
@@ -35,13 +70,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_smccc())
 		return 0;
 
 	/* Setup the guest ID */
--

2.43.0

#12 lore raw

Re: [PATCH hyperv-next v6 02/11] arm64: hyperv: Use SMCCC to detect hypervisor presence

Quoted 11 lines · Michael Kelley

From: Mark Rutland <[email protected]> Sent: Monday, March 17, 2025 4:38 AM

Quoted 3 lines

The 'acpi_disabled' variable doesn't exist for !CONFIG_ACPI, so its use prior to the ifdeffery looks misplaced.

FWIW, include/linux/acpi.h has

#define acpi_disabled 1

when !CONFIG_ACPI. But I agree that using a stub is better.

Thanks, Michael! I didn't "fact-checked" what was suggested indeed. Agreed that the stub makes the code look better.

Quoted 58 lines

Michael

Quoted 54 lines

Usual codestyle is to avoid ifdeffery if possible, using IS_ENABLED(). Otherwise, use a stub, e.g.

| #ifdef CONFIG_ACPI
| static bool __init hyperv_detect_via_acpi(void)
| {
| 	if (acpi_disabled)
| 		return false;
|
| 	if (acpi_gbl_FADT.header.revision < 6)
| 		return false;
|
| 	return strncmp((char *)&acpi_gbl_FADT.hypervisor_id, "MsHyperV", 8) == 0;
| }
| #else
| static inline bool hyperv_detect_via_acpi(void) { return false; }
| #endif

Mark.

Quoted 33 lines
arch/arm64/hyperv/mshyperv.c +13 -6
+static bool __init hyperv_detect_via_smccc(void)
+{
+	uuid_t hyperv_uuid = UUID_INIT(
+		0x4d32ba58, 0x4764, 0xcd24,
+		0x75, 0x6c, 0xef, 0x8e,
+		0x24, 0x70, 0x59, 0x16);
+
+	return arm_smccc_hyp_present(&hyperv_uuid);
+}
+
  static int __init hyperv_init(void)
  {
  	struct hv_get_vp_registers_output	result;
@@ -35,13 +70,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_smccc())
  		return 0;
 
  	/* Setup the guest ID */
--

2.43.0

Signature · 2 lines
Thank you,
Roman
#13 lore raw

PATCH v6 3/11 Drivers: hv: Enable VTL mode for arm64

In reply to Roman Kisel

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 unconditionally.

---
 drivers/hv/Kconfig | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/hv/Kconfig +3 -3
index 794e88e9dc6b..11b07a6d594a 100644
@@ -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.
Signature · 1 line
2.43.0
#14 lore raw

Re: [PATCH hyperv-next v6 03/11] Drivers: hv: Enable VTL mode for arm64

kernel test robot noticed the following build warnings:

Hi Roman,

kernel test robot noticed the following build warnings:

[auto build test WARNING on d9608f6dc3e3229a40e1db1dab573d6882f38c2a]

url:    https://github.com/intel-lab-lkp/linux/commits/Roman-Kisel/arm64-kvm-smccc-Introduce-and-use-API-for-detecting-hypervisor-presence/20250315-082319
base:   d9608f6dc3e3229a40e1db1dab573d6882f38c2a
patch link:    https://lore.kernel.org/r/20250315001931.631210-4-romank%40linux.microsoft.com
patch subject: [PATCH hyperv-next v6 03/11] Drivers: hv: Enable VTL mode for arm64
config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20250316/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250316/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

arch/x86/hyperv/hv_vtl.c: In function 'hv_vtl_system_desc_base':
arch/x86/hyperv/hv_vtl.c:84:28: error: 'struct ldttss_desc' has no member named 'base3'; did you mean 'base0'?

      84 |         return ((u64)desc->base3 << 32) | ((u64)desc->base2 << 24) |
         |                            ^~~~~
         |                            base0
   arch/x86/hyperv/hv_vtl.c: In function 'hv_vtl_ap_entry':
   arch/x86/hyperv/hv_vtl.c:96:35: error: 'secondary_startup_64' undeclared (first use in this function); did you mean 'secondary_startup_64_fn'?
      96 |         ((secondary_startup_64_fn)secondary_startup_64)(&boot_params, &boot_params);
         |                                   ^~~~~~~~~~~~~~~~~~~~
         |                                   secondary_startup_64_fn
   arch/x86/hyperv/hv_vtl.c:96:35: note: each undeclared identifier is reported only once for each function it appears in
   arch/x86/hyperv/hv_vtl.c: In function 'hv_vtl_bringup_vcpu':
>> arch/x86/hyperv/hv_vtl.c:116:19: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
     116 |         u64 rip = (u64)&hv_vtl_ap_entry;
         |                   ^
   arch/x86/hyperv/hv_vtl.c: In function 'hv_vtl_system_desc_base':
>> arch/x86/hyperv/hv_vtl.c:86:1: warning: control reaches end of non-void function [-Wreturn-type]
      86 | }
         | ^

vim +116 arch/x86/hyperv/hv_vtl.c

3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10   81  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10   82  static inline u64 hv_vtl_system_desc_base(struct ldttss_desc *desc)
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10   83  {
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10   84  	return ((u64)desc->base3 << 32) | ((u64)desc->base2 << 24) |
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10   85  		(desc->base1 << 16) | desc->base0;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  @86  }
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10   87  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10   88  static inline u32 hv_vtl_system_desc_limit(struct ldttss_desc *desc)
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10   89  {
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10   90  	return ((u32)desc->limit1 << 16) | (u32)desc->limit0;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10   91  }
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10   92  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10   93  typedef void (*secondary_startup_64_fn)(void*, void*);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10   94  static void hv_vtl_ap_entry(void)
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10   95  {
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10   96  	((secondary_startup_64_fn)secondary_startup_64)(&boot_params, &boot_params);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10   97  }
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10   98  
2b4b90e053a2905 Saurabh Sengar 2024-03-03   99  static int hv_vtl_bringup_vcpu(u32 target_vp_index, int cpu, u64 eip_ignored)
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  100  {
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  101  	u64 status;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  102  	int ret = 0;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  103  	struct hv_enable_vp_vtl *input;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  104  	unsigned long irq_flags;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  105  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  106  	struct desc_ptr gdt_ptr;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  107  	struct desc_ptr idt_ptr;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  108  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  109  	struct ldttss_desc *tss;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  110  	struct ldttss_desc *ldt;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  111  	struct desc_struct *gdt;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  112  
2b4b90e053a2905 Saurabh Sengar 2024-03-03  113  	struct task_struct *idle = idle_thread_get(cpu);
2b4b90e053a2905 Saurabh Sengar 2024-03-03  114  	u64 rsp = (unsigned long)idle->thread.sp;
2b4b90e053a2905 Saurabh Sengar 2024-03-03  115  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10 @116  	u64 rip = (u64)&hv_vtl_ap_entry;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  117  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  118  	native_store_gdt(&gdt_ptr);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  119  	store_idt(&idt_ptr);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  120  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  121  	gdt = (struct desc_struct *)((void *)(gdt_ptr.address));
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  122  	tss = (struct ldttss_desc *)(gdt + GDT_ENTRY_TSS);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  123  	ldt = (struct ldttss_desc *)(gdt + GDT_ENTRY_LDT);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  124  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  125  	local_irq_save(irq_flags);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  126  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  127  	input = *this_cpu_ptr(hyperv_pcpu_input_arg);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  128  	memset(input, 0, sizeof(*input));
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  129  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  130  	input->partition_id = HV_PARTITION_ID_SELF;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  131  	input->vp_index = target_vp_index;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  132  	input->target_vtl.target_vtl = HV_VTL_MGMT;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  133  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  134  	/*
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  135  	 * The x86_64 Linux kernel follows the 16-bit -> 32-bit -> 64-bit
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  136  	 * mode transition sequence after waking up an AP with SIPI whose
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  137  	 * vector points to the 16-bit AP startup trampoline code. Here in
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  138  	 * VTL2, we can't perform that sequence as the AP has to start in
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  139  	 * the 64-bit mode.
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  140  	 *
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  141  	 * To make this happen, we tell the hypervisor to load a valid 64-bit
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  142  	 * context (most of which is just magic numbers from the CPU manual)
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  143  	 * so that AP jumps right to the 64-bit entry of the kernel, and the
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  144  	 * control registers are loaded with values that let the AP fetch the
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  145  	 * code and data and carry on with work it gets assigned.
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  146  	 */
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  147  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  148  	input->vp_context.rip = rip;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  149  	input->vp_context.rsp = rsp;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  150  	input->vp_context.rflags = 0x0000000000000002;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  151  	input->vp_context.efer = __rdmsr(MSR_EFER);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  152  	input->vp_context.cr0 = native_read_cr0();
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  153  	input->vp_context.cr3 = __native_read_cr3();
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  154  	input->vp_context.cr4 = native_read_cr4();
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  155  	input->vp_context.msr_cr_pat = __rdmsr(MSR_IA32_CR_PAT);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  156  	input->vp_context.idtr.limit = idt_ptr.size;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  157  	input->vp_context.idtr.base = idt_ptr.address;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  158  	input->vp_context.gdtr.limit = gdt_ptr.size;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  159  	input->vp_context.gdtr.base = gdt_ptr.address;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  160  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  161  	/* Non-system desc (64bit), long, code, present */
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  162  	input->vp_context.cs.selector = __KERNEL_CS;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  163  	input->vp_context.cs.base = 0;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  164  	input->vp_context.cs.limit = 0xffffffff;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  165  	input->vp_context.cs.attributes = 0xa09b;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  166  	/* Non-system desc (64bit), data, present, granularity, default */
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  167  	input->vp_context.ss.selector = __KERNEL_DS;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  168  	input->vp_context.ss.base = 0;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  169  	input->vp_context.ss.limit = 0xffffffff;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  170  	input->vp_context.ss.attributes = 0xc093;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  171  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  172  	/* System desc (128bit), present, LDT */
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  173  	input->vp_context.ldtr.selector = GDT_ENTRY_LDT * 8;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  174  	input->vp_context.ldtr.base = hv_vtl_system_desc_base(ldt);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  175  	input->vp_context.ldtr.limit = hv_vtl_system_desc_limit(ldt);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  176  	input->vp_context.ldtr.attributes = 0x82;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  177  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  178  	/* System desc (128bit), present, TSS, 0x8b - busy, 0x89 -- default */
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  179  	input->vp_context.tr.selector = GDT_ENTRY_TSS * 8;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  180  	input->vp_context.tr.base = hv_vtl_system_desc_base(tss);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  181  	input->vp_context.tr.limit = hv_vtl_system_desc_limit(tss);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  182  	input->vp_context.tr.attributes = 0x8b;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  183  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  184  	status = hv_do_hypercall(HVCALL_ENABLE_VP_VTL, input, NULL);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  185  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  186  	if (!hv_result_success(status) &&
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  187  	    hv_result(status) != HV_STATUS_VTL_ALREADY_ENABLED) {
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  188  		pr_err("HVCALL_ENABLE_VP_VTL failed for VP : %d ! [Err: %#llx\n]",
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  189  		       target_vp_index, status);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  190  		ret = -EINVAL;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  191  		goto free_lock;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  192  	}
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  193  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  194  	status = hv_do_hypercall(HVCALL_START_VP, input, NULL);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  195  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  196  	if (!hv_result_success(status)) {
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  197  		pr_err("HVCALL_START_VP failed for VP : %d ! [Err: %#llx]\n",
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  198  		       target_vp_index, status);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  199  		ret = -EINVAL;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  200  	}
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  201  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  202  free_lock:
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  203  	local_irq_restore(irq_flags);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  204  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  205  	return ret;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  206  }
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  207  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#15 lore raw

Re: [PATCH hyperv-next v6 03/11] Drivers: hv: Enable VTL mode for arm64

In reply to Roman Kisel
kernel test robot noticed the following build errors:

Hi Roman,

kernel test robot noticed the following build errors:

[auto build test ERROR on d9608f6dc3e3229a40e1db1dab573d6882f38c2a]

url:    https://github.com/intel-lab-lkp/linux/commits/Roman-Kisel/arm64-kvm-smccc-Introduce-and-use-API-for-detecting-hypervisor-presence/20250315-082319
base:   d9608f6dc3e3229a40e1db1dab573d6882f38c2a
patch link:    https://lore.kernel.org/r/20250315001931.631210-4-romank%40linux.microsoft.com
patch subject: [PATCH hyperv-next v6 03/11] Drivers: hv: Enable VTL mode for arm64
config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20250316/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250316/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

arch/x86/hyperv/hv_vtl.c: In function 'hv_vtl_system_desc_base':

>> arch/x86/hyperv/hv_vtl.c:84:28: error: 'struct ldttss_desc' has no member named 'base3'; did you mean 'base0'?
      84 |         return ((u64)desc->base3 << 32) | ((u64)desc->base2 << 24) |
         |                            ^~~~~
         |                            base0
   arch/x86/hyperv/hv_vtl.c: In function 'hv_vtl_ap_entry':
>> arch/x86/hyperv/hv_vtl.c:96:35: error: 'secondary_startup_64' undeclared (first use in this function); did you mean 'secondary_startup_64_fn'?
      96 |         ((secondary_startup_64_fn)secondary_startup_64)(&boot_params, &boot_params);
         |                                   ^~~~~~~~~~~~~~~~~~~~
         |                                   secondary_startup_64_fn
   arch/x86/hyperv/hv_vtl.c:96:35: note: each undeclared identifier is reported only once for each function it appears in
   arch/x86/hyperv/hv_vtl.c: In function 'hv_vtl_bringup_vcpu':
   arch/x86/hyperv/hv_vtl.c:116:19: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
     116 |         u64 rip = (u64)&hv_vtl_ap_entry;
         |                   ^
   arch/x86/hyperv/hv_vtl.c: In function 'hv_vtl_system_desc_base':
   arch/x86/hyperv/hv_vtl.c:86:1: warning: control reaches end of non-void function [-Wreturn-type]
      86 | }
         | ^

vim +84 arch/x86/hyperv/hv_vtl.c

3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  81  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  82  static inline u64 hv_vtl_system_desc_base(struct ldttss_desc *desc)
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  83  {
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10 @84  	return ((u64)desc->base3 << 32) | ((u64)desc->base2 << 24) |
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  85  		(desc->base1 << 16) | desc->base0;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  86  }
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  87  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  88  static inline u32 hv_vtl_system_desc_limit(struct ldttss_desc *desc)
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  89  {
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  90  	return ((u32)desc->limit1 << 16) | (u32)desc->limit0;
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  91  }
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  92  
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  93  typedef void (*secondary_startup_64_fn)(void*, void*);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  94  static void hv_vtl_ap_entry(void)
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10  95  {

3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10 @96 ((secondary_startup_64_fn)secondary_startup_64)(&boot_params, &boot_params);
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10 97 }
3be1bc2fe9d2e4f Saurabh Sengar 2023-04-10 98

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#16 lore raw

PATCH v6 4/11 Drivers: hv: Provide arch-neutral implementation of get_vtl()

In reply to Roman Kisel

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.

---
 arch/x86/hyperv/hv_init.c      | 34 ----------------------------------
 drivers/hv/hv_common.c         | 31 +++++++++++++++++++++++++++++++
 include/asm-generic/mshyperv.h |  6 ++++++
 include/hyperv/hvgdk_mini.h    |  2 +-
 4 files changed, 38 insertions(+), 35 deletions(-)
arch/x86/hyperv/hv_init.c +0 -34
index ddeb40930bc8..3b569291dfed 100644
@@ -390,40 +390,6 @@ static void __init hv_stimer_setup_percpu_clockev(void)
 		old_setup_percpu_clockev();
 }
 
-#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_input_get_vp_registers *input;
-	struct hv_output_get_vp_registers *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, names, 1));
-	input->partition_id = HV_PARTITION_ID_SELF;
-	input->vp_index = HV_VP_INDEX_SELF;
-	input->input_vtl.as_uint8 = 0;
-	input->names[0] = HV_REGISTER_VSM_VP_STATUS;
-
-	ret = hv_do_hypercall(control, input, output);
-	if (hv_result_success(ret)) {
-		ret = output->values[0].reg8 & 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.
drivers/hv/hv_common.c +31 -0
index 9804adb4cc56..dce4b34e293b 100644
@@ -304,6 +304,37 @@ void __init hv_get_partition_id(void)
 		pr_err("Hyper-V: failed to get partition ID: %#x\n",
 		       hv_result(status));
 }
+#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_input_get_vp_registers *input;
+	struct hv_output_get_vp_registers *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, names, 1));
+	input->partition_id = HV_PARTITION_ID_SELF;
+	input->vp_index = HV_VP_INDEX_SELF;
+	input->input_vtl.as_uint8 = 0;
+	input->names[0] = HV_REGISTER_VSM_VP_STATUS;
+
+	ret = hv_do_hypercall(control, input, output);
+	if (hv_result_success(ret)) {
+		ret = output->values[0].reg8 & HV_VTL_MASK;
+	} else {
+		pr_err("Failed to get VTL(error: %lld) exiting...\n", ret);
+		BUG();
+	}
+
+	local_irq_restore(flags);
+	return ret;
+}
+#endif
 
 int __init hv_common_init(void)
 {
include/asm-generic/mshyperv.h +6 -0
index b13b0cda4ac8..c5150a2b12d6 100644
@@ -348,4 +348,10 @@ static inline int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u3
 }
 #endif /* CONFIG_MSHV_ROOT */
 
+#if IS_ENABLED(CONFIG_HYPERV_VTL_MODE)
+u8 __init get_vtl(void);
+#else
+static inline u8 get_vtl(void) { return 0; }
+#endif
+
 #endif
include/hyperv/hvgdk_mini.h +1 -1
index 58895883f636..98aa64e8844c 100644
@@ -1202,7 +1202,7 @@ struct hv_send_ipi {	 /* HV_INPUT_SEND_SYNTHETIC_CLUSTER_IPI */
 	u64 cpu_mask;
 } __packed;
 
-#define	HV_X64_VTL_MASK			GENMASK(3, 0)
+#define	HV_VTL_MASK			GENMASK(3, 0)
 
 /* Hyper-V memory host visibility */
 enum hv_mem_host_visibility {
Signature · 1 line
2.43.0
#17 lore raw

PATCH v6 5/11 arm64: hyperv: Initialize the Virtual Trust Level field

In reply to Roman Kisel

Various parts of the hyperv code need to know what VTL the kernel runs at, most notably VMBus needs that to establish communication with the host.

Initialize the Virtual Trust Level field to enable booting in the Virtual Trust Level.

---
 arch/arm64/hyperv/mshyperv.c | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/hyperv/mshyperv.c +1 -0
index c5b03d3af7c5..f251a08ada5b 100644
@@ -109,6 +109,7 @@ static int __init hyperv_init(void)
 
 	if (ms_hyperv.priv_high & HV_ACCESS_PARTITION_ID)
 		hv_get_partition_id();
+	ms_hyperv.vtl = get_vtl();
 
 	ms_hyperv_late_init();
 
Signature · 1 line
2.43.0
#18 lore raw

PATCH v6 6/11 arm64, x86: hyperv: Report the VTL the system boots in

In reply to Roman Kisel

The hyperv guest code might run in various Virtual Trust Levels.

Report the level when the kernel boots in the non-default (0) one.

---
 arch/arm64/hyperv/mshyperv.c | 2 ++
 arch/x86/hyperv/hv_vtl.c     | 7 ++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
arch/arm64/hyperv/mshyperv.c +2 -0
index f251a08ada5b..ecbd2f5c955e 100644
@@ -110,6 +110,8 @@ static int __init hyperv_init(void)
 	if (ms_hyperv.priv_high & HV_ACCESS_PARTITION_ID)
 		hv_get_partition_id();
 	ms_hyperv.vtl = get_vtl();
+	if (ms_hyperv.vtl > 0) /* non default VTL */
+		pr_info("Linux runs in Hyper-V Virtual Trust Level %d\n", ms_hyperv.vtl);
 
 	ms_hyperv_late_init();
 
arch/x86/hyperv/hv_vtl.c +6 -1
index 582fe820e29c..038c896fdd60 100644
@@ -55,7 +55,12 @@ static void  __noreturn hv_vtl_restart(char __maybe_unused *cmd)
 
 void __init hv_vtl_init_platform(void)
 {
-	pr_info("Linux runs in Hyper-V Virtual Trust Level\n");
+	/*
+	 * This function is a no-op if the VTL mode is not enabled.
+	 * If it is, this function runs if and only the kernel boots in
+	 * VTL2 which the x86 hv initialization path makes sure of.
+	 */
+	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;
Signature · 1 line
2.43.0
#19 lore raw

PATCH v6 7/11 dt-bindings: microsoft,vmbus: Add interrupt and DMA coherence properties

In reply to Roman Kisel

To boot in the VTL mode, VMBus on arm64 needs interrupt description which the binding documentation lacks. The transactions on the bus are DMA coherent which is not mentioned as well.

Add the interrupt property and the DMA coherence property to the VMBus binding. Update the example to match that. Fix typos.

---
 .../bindings/bus/microsoft,vmbus.yaml           | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/bus/microsoft,vmbus.yaml +15 -2
index a8d40c766dcd..ca288ea54b34 100644
@@ -10,8 +10,8 @@ maintainers:
   - Saurabh Sengar <[email protected]>
 
 description:
-  VMBus is a software bus that implement the protocols for communication
-  between the root or host OS and guest OSs (virtual machines).
+  VMBus is a software bus that implements the protocols for communication
+  between the root or host OS and guest OS'es (virtual machines).
 
 properties:
   compatible:
@@ -25,9 +25,17 @@ properties:
   '#size-cells':
     const: 1
 
+  dma-coherent: true
+
+  interrupts:
+    maxItems: 1
+    description: |
+      This interrupt is used to report a message from the host.
+
 required:
   - compatible
   - ranges
+  - interrupts
   - '#address-cells'
   - '#size-cells'
 
@@ -35,6 +43,8 @@ additionalProperties: false
 
 examples:
   - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
     soc {
         #address-cells = <2>;
         #size-cells = <1>;
@@ -49,6 +59,9 @@ examples:
                 #address-cells = <2>;
                 #size-cells = <1>;
                 ranges = <0x0f 0xf0000000 0x0f 0xf0000000 0x10000000>;
+                dma-coherent;
+                interrupt-parent = <&gic>;
+                interrupts = <GIC_PPI 2 IRQ_TYPE_EDGE_RISING>;
             };
         };
     };
Signature · 1 line
2.43.0
Reviewed-by on v6 7/11
#20 lore raw

Re: [PATCH hyperv-next v6 07/11] dt-bindings: microsoft,vmbus: Add interrupt and DMA coherence properties

Documentation/devicetree/bindings/bus/microsoft,vmbus.yaml properties:

Quoted 8 lines · Roman Kisel
Documentation/devicetree/bindings/bus/microsoft,vmbus.yaml +6 -0
+  dma-coherent: true
+
+  interrupts:
 
+    maxItems: 1
+    description: |
+      This interrupt is used to report a message from the host.

These could be just two lines:

items:
- description: Interrupt used to report a message from the host.

(and note that just like we do not use "This" in commit msg, there is really no benefit of using it in hardware descruption for simple statements)

Regardless:

Best regards,
Krzysztof

#21 lore raw

Re: [PATCH hyperv-next v6 07/11] dt-bindings: microsoft,vmbus: Add interrupt and DMA coherence properties

Quoted 10 lines · Krzysztof Kozlowski

Documentation/devicetree/bindings/bus/microsoft,vmbus.yaml properties:

Quoted 8 lines · Roman Kisel
Documentation/devicetree/bindings/bus/microsoft,vmbus.yaml +6 -0
+  dma-coherent: true
+
+  interrupts:
 
+    maxItems: 1
+    description: |
+      This interrupt is used to report a message from the host.
Quoted 9 lines

These could be just two lines:

items:
- description: Interrupt used to report a message from the host.

(and note that just like we do not use "This" in commit msg, there is really no benefit of using it in hardware descruption for simple statements)

Appreciate your help very much!! Will fix the formatting.

Quoted 7 lines

Regardless:

Best regards,
Krzysztof

Signature · 2 lines
Thank you,
Roman
#22 lore raw

PATCH v6 8/11 Drivers: hv: vmbus: Get the IRQ number from DeviceTree

In reply to Roman Kisel

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 from DT.

---
 drivers/hv/vmbus_drv.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
drivers/hv/vmbus_drv.c +30 -0
index 22afebfc28ff..e8f2c3e92d1f 100644
@@ -2345,6 +2345,31 @@ static int vmbus_acpi_add(struct platform_device *pdev)
 }
 #endif
 
+static int vmbus_set_irq(struct platform_device *pdev)
+{
+	struct irq_data *data;
+	int irq;
+	irq_hw_number_t hwirq;
+
+	irq = platform_get_irq(pdev, 0);
+	/* platform_get_irq() may not return 0. */
+	if (irq < 0)
+		return irq;
+
+	data = irq_get_irq_data(irq);
+	if (!data) {
+		pr_err("No interrupt data for VMBus virq %d\n", irq);
+		return -ENODEV;
+	}
+	hwirq = irqd_to_hwirq(data);
+
+	vmbus_irq = irq;
+	vmbus_interrupt = 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;
@@ -2359,6 +2384,11 @@ static int vmbus_device_add(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
+	if (!__is_defined(HYPERVISOR_CALLBACK_VECTOR))
+		ret = vmbus_set_irq(pdev);
+	if (ret)
+		return ret;
+
 	for_each_of_range(&parser, &range) {
 		struct resource *res;
 
Signature · 1 line
2.43.0
#23 lore raw

PATCH v6 9/11 Drivers: hv: vmbus: Introduce hv_get_vmbus_root_device()

In reply to Roman Kisel

The ARM64 PCI code for hyperv needs to know the VMBus root device, and it is private.

Provide a function that returns it. Rename it from "hv_dev" as "hv_dev" as a symbol is very overloaded. No functional changes.

---
 drivers/hv/vmbus_drv.c | 23 +++++++++++++++--------
 include/linux/hyperv.h |  2 ++
 2 files changed, 17 insertions(+), 8 deletions(-)
drivers/hv/vmbus_drv.c +15 -8
index e8f2c3e92d1f..df18b4070b01 100644
@@ -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 *hv_get_vmbus_root_device(void)
+{
+	return vmbus_root_device;
+}
+EXPORT_SYMBOL_GPL(hv_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;
 }
 
@@ -1930,7 +1937,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;
@@ -2292,7 +2299,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
@@ -2378,7 +2385,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)
@@ -2696,7 +2703,7 @@ static int __init hv_acpi_init(void)
 	if (ret)
 		return ret;
 
-	if (!hv_dev) {
+	if (!vmbus_root_device) {
 		ret = -ENODEV;
 		goto cleanup;
 	}
@@ -2727,7 +2734,7 @@ static int __init hv_acpi_init(void)
 
 cleanup:
 	platform_driver_unregister(&vmbus_platform_driver);
-	hv_dev = NULL;
+	vmbus_root_device = NULL;
 	return ret;
 }
 
include/linux/hyperv.h +2 -0
index 675959fb97ba..1f310fbbc4f9 100644
@@ -1277,6 +1277,8 @@ static inline void *hv_get_drvdata(struct hv_device *dev)
 	return dev_get_drvdata(&dev->device);
 }
 
+struct device *hv_get_vmbus_root_device(void);
+
 struct hv_ring_buffer_debug_info {
 	u32 current_interrupt_mask;
 	u32 current_read_index;
Signature · 1 line
2.43.0
#24 lore raw

PATCH v6 10/11 ACPI: irq: Introduce acpi_get_gsi_dispatcher()

In reply to Roman Kisel

Using acpi_irq_create_hierarchy() in the cases where the code also handles OF leads to code duplication as the ACPI subsystem doesn't provide means to compute the IRQ domain parent whereas the OF does.

Introduce acpi_get_gsi_dispatcher() so that the drivers relying on both ACPI and OF may use irq_domain_create_hierarchy() in the common code paths.

No functional changes.

---
 drivers/acpi/irq.c   | 15 +++++++++++++--
 include/linux/acpi.h |  5 ++++-
 2 files changed, 17 insertions(+), 3 deletions(-)
drivers/acpi/irq.c +13 -2
index 1687483ff319..8eb09e45e5c5 100644
@@ -12,7 +12,7 @@
 
 enum acpi_irq_model_id acpi_irq_model;
 
-static struct fwnode_handle *(*acpi_get_gsi_domain_id)(u32 gsi);
+static acpi_gsi_domain_disp_fn acpi_get_gsi_domain_id;
 static u32 (*acpi_gsi_to_irq_fallback)(u32 gsi);
 
 /**
@@ -307,12 +307,23 @@ EXPORT_SYMBOL_GPL(acpi_irq_get);
  *	for a given GSI
  */
 void __init acpi_set_irq_model(enum acpi_irq_model_id model,
-			       struct fwnode_handle *(*fn)(u32))
+	acpi_gsi_domain_disp_fn fn)
 {
 	acpi_irq_model = model;
 	acpi_get_gsi_domain_id = fn;
 }
 
+/**
+ * acpi_get_gsi_dispatcher - Returns dispatcher function that
+ *                           computes the domain fwnode for a
+ *                           given GSI.
+ */
+acpi_gsi_domain_disp_fn acpi_get_gsi_dispatcher(void)
+{
+	return acpi_get_gsi_domain_id;
+}
+EXPORT_SYMBOL_GPL(acpi_get_gsi_dispatcher);
+
 /**
  * acpi_set_gsi_to_irq_fallback - Register a GSI transfer
  * callback to fallback to arch specified implementation.
include/linux/acpi.h +4 -1
index 4e495b29c640..abc51288e867 100644
@@ -336,8 +336,11 @@ int acpi_register_gsi (struct device *dev, u32 gsi, int triggering, int polarity
 int acpi_gsi_to_irq (u32 gsi, unsigned int *irq);
 int acpi_isa_irq_to_gsi (unsigned isa_irq, u32 *gsi);
 
+typedef struct fwnode_handle *(*acpi_gsi_domain_disp_fn)(u32);
+
 void acpi_set_irq_model(enum acpi_irq_model_id model,
-			struct fwnode_handle *(*)(u32));
+	acpi_gsi_domain_disp_fn fn);
+acpi_gsi_domain_disp_fn acpi_get_gsi_dispatcher(void);
 void acpi_set_gsi_to_irq_fallback(u32 (*)(u32));
 
 struct irq_domain *acpi_irq_create_hierarchy(unsigned int flags,
Signature · 1 line
2.43.0
maintainer Acked-by on v6 10/11
#25 lore raw

Re: [PATCH hyperv-next v6 10/11] ACPI: irq: Introduce acpi_get_gsi_dispatcher()

Quoted 6 lines · Roman Kisel

Using acpi_irq_create_hierarchy() in the cases where the code also handles OF leads to code duplication as the ACPI subsystem doesn't provide means to compute the IRQ domain parent whereas the OF does.

Quoted 8 lines

Introduce acpi_get_gsi_dispatcher() so that the drivers relying on both ACPI and OF may use irq_domain_create_hierarchy() in the common code paths.

No functional changes.

This basically looks OK to me except for a couple of coding style related nits below.

Quoted 19 lines
---
 drivers/acpi/irq.c   | 15 +++++++++++++--
 include/linux/acpi.h |  5 ++++-
 2 files changed, 17 insertions(+), 3 deletions(-)
drivers/acpi/irq.c +1 -1
index 1687483ff319..8eb09e45e5c5 100644
@@ -12,7 +12,7 @@
 
 enum acpi_irq_model_id acpi_irq_model;
 
-static struct fwnode_handle *(*acpi_get_gsi_domain_id)(u32 gsi);
+static acpi_gsi_domain_disp_fn acpi_get_gsi_domain_id;
 static u32 (*acpi_gsi_to_irq_fallback)(u32 gsi);
 
 /**

drivers/acpi/irq.c EXPORT_SYMBOL_GPL(acpi_irq_get); · line 310

Quoted 4 lines
drivers/acpi/irq.c +0 -1
@@ -307,12 +307,23 @@ EXPORT_SYMBOL_GPL(acpi_irq_get);
  *     for a given GSI
  */
 void __init acpi_set_irq_model(enum acpi_irq_model_id model,
-                              struct fwnode_handle *(*fn)(u32))

Please retain the indentation here and analogously below.

drivers/acpi/irq.c EXPORT_SYMBOL_GPL(acpi_irq_get); · line 320

Quoted 11 lines
drivers/acpi/irq.c +6 -0
+       acpi_gsi_domain_disp_fn fn)
 {
        acpi_irq_model = model;
        acpi_get_gsi_domain_id = fn;
 }
 
+/**
+ * acpi_get_gsi_dispatcher - Returns dispatcher function that
+ *                           computes the domain fwnode for a
+ *                           given GSI.
+ */

I would format this kerneldoc comment a bit differently:

/*
* acpi_get_gsi_dispatcher() - Get the GSI dispatcher function *
* Return the dispatcher function that computes the domain fwnode for
a given GSI.
*/

Quoted 17 lines
drivers/acpi/irq.c +6 -0
+acpi_gsi_domain_disp_fn acpi_get_gsi_dispatcher(void)
+{
+       return acpi_get_gsi_domain_id;
+}
+EXPORT_SYMBOL_GPL(acpi_get_gsi_dispatcher);
+
 /**
  * acpi_set_gsi_to_irq_fallback - Register a GSI transfer
  * callback to fallback to arch specified implementation.
include/linux/acpi.h +0 -0
index 4e495b29c640..abc51288e867 100644
@@ -336,8 +336,11 @@ int acpi_register_gsi (struct device *dev, u32 gsi, int triggering, int polarity
 int acpi_gsi_to_irq (u32 gsi, unsigned int *irq);
 int acpi_isa_irq_to_gsi (unsigned isa_irq, u32 *gsi);
 

include/linux/acpi.h int acpi_register_gsi (struct device *dev, u32 gsi, int triggering, int polarity

Quoted 10 lines
include/linux/acpi.h +4 -2
+typedef struct fwnode_handle *(*acpi_gsi_domain_disp_fn)(u32);
+
 void acpi_set_irq_model(enum acpi_irq_model_id model,
-                       struct fwnode_handle *(*)(u32));
+       acpi_gsi_domain_disp_fn fn);
+acpi_gsi_domain_disp_fn acpi_get_gsi_dispatcher(void);
 void acpi_set_gsi_to_irq_fallback(u32 (*)(u32));
 
 struct irq_domain *acpi_irq_create_hierarchy(unsigned int flags,
--

With the above addressed, please feel free to add

to the patch and route it along with the rest of the series.

Thanks!

#26 lore raw

Re: [PATCH hyperv-next v6 10/11] ACPI: irq: Introduce acpi_get_gsi_dispatcher()

Quoted 1 line · Rafael J. Wysocki

On Sat, Mar 15, 2025 at 1:19 AM Roman Kisel <[email protected]> wrote:

[...]

Quoted 4 lines

This basically looks OK to me except for a couple of coding style related nits below.

Appreciate taking time to review this very much! Will squash the nits in the next version.

Quoted 72 lines
Quoted 19 lines
---
  drivers/acpi/irq.c   | 15 +++++++++++++--
  include/linux/acpi.h |  5 ++++-
  2 files changed, 17 insertions(+), 3 deletions(-)
drivers/acpi/irq.c +1 -1
index 1687483ff319..8eb09e45e5c5 100644
@@ -12,7 +12,7 @@
 
  enum acpi_irq_model_id acpi_irq_model;
 
-static struct fwnode_handle *(*acpi_get_gsi_domain_id)(u32 gsi);
+static acpi_gsi_domain_disp_fn acpi_get_gsi_domain_id;
  static u32 (*acpi_gsi_to_irq_fallback)(u32 gsi);
 
  /**

drivers/acpi/irq.c EXPORT_SYMBOL_GPL(acpi_irq_get); · line 310

Quoted 4 lines
drivers/acpi/irq.c +0 -1
@@ -307,12 +307,23 @@ EXPORT_SYMBOL_GPL(acpi_irq_get);
   *     for a given GSI
   */
  void __init acpi_set_irq_model(enum acpi_irq_model_id model,
-                              struct fwnode_handle *(*fn)(u32))

Please retain the indentation here and analogously below.

drivers/acpi/irq.c EXPORT_SYMBOL_GPL(acpi_irq_get); · line 320

Quoted 11 lines
drivers/acpi/irq.c +6 -0
+       acpi_gsi_domain_disp_fn fn)
  {
         acpi_irq_model = model;
         acpi_get_gsi_domain_id = fn;
  }
 
+/**
+ * acpi_get_gsi_dispatcher - Returns dispatcher function that
+ *                           computes the domain fwnode for a
+ *                           given GSI.
+ */

I would format this kerneldoc comment a bit differently:

/*
* acpi_get_gsi_dispatcher() - Get the GSI dispatcher function *
* Return the dispatcher function that computes the domain fwnode for
a given GSI.
*/

Quoted 25 lines
drivers/acpi/irq.c +6 -0
+acpi_gsi_domain_disp_fn acpi_get_gsi_dispatcher(void)
+{
+       return acpi_get_gsi_domain_id;
+}
+EXPORT_SYMBOL_GPL(acpi_get_gsi_dispatcher);
+
  /**
   * acpi_set_gsi_to_irq_fallback - Register a GSI transfer
   * callback to fallback to arch specified implementation.
include/linux/acpi.h +4 -1
index 4e495b29c640..abc51288e867 100644
@@ -336,8 +336,11 @@ int acpi_register_gsi (struct device *dev, u32 gsi, int triggering, int polarity
  int acpi_gsi_to_irq (u32 gsi, unsigned int *irq);
  int acpi_isa_irq_to_gsi (unsigned isa_irq, u32 *gsi);
 
+typedef struct fwnode_handle *(*acpi_gsi_domain_disp_fn)(u32);
+
  void acpi_set_irq_model(enum acpi_irq_model_id model,
-                       struct fwnode_handle *(*)(u32));
+       acpi_gsi_domain_disp_fn fn);
+acpi_gsi_domain_disp_fn acpi_get_gsi_dispatcher(void);
  void acpi_set_gsi_to_irq_fallback(u32 (*)(u32));
 
Quoted 9 lines

include/linux/acpi.h int acpi_register_gsi (struct device *dev, u32 gsi, int triggering, int polarity

Quoted 2 lines
include/linux/acpi.h +0 -1
  struct irq_domain *acpi_irq_create_hierarchy(unsigned int flags,
--

With the above addressed, please feel free to add

to the patch and route it along with the rest of the series.

Will do, thanks!

Quoted 1 line

Thanks!

Signature · 2 lines
Thank you,
Roman
#27 lore raw

PATCH v6 11/11 PCI: hv: Get vPCI MSI IRQ domain from DeviceTree

In reply to Roman Kisel

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.

---
 drivers/pci/controller/pci-hyperv.c | 73 ++++++++++++++++++++++++++---
 1 file changed, 67 insertions(+), 6 deletions(-)
drivers/pci/controller/pci-hyperv.c +67 -6
index 6084b38bdda1..cbff19e8a07c 100644
@@ -50,6 +50,7 @@
 #include <linux/irqdomain.h>
 #include <linux/acpi.h>
 #include <linux/sizes.h>
+#include <linux/of_irq.h>
 #include <asm/mshyperv.h>
 
 /*
@@ -817,9 +818,17 @@ static int hv_pci_vec_irq_gic_domain_alloc(struct irq_domain *domain,
 	int ret;
 
 	fwspec.fwnode = domain->parent->fwnode;
-	fwspec.param_count = 2;
-	fwspec.param[0] = hwirq;
-	fwspec.param[1] = IRQ_TYPE_EDGE_RISING;
+	if (is_of_node(fwspec.fwnode)) {
+		/* SPI lines for OF translations start at offset 32 */
+		fwspec.param_count = 3;
+		fwspec.param[0] = 0;
+		fwspec.param[1] = hwirq - 32;
+		fwspec.param[2] = IRQ_TYPE_EDGE_RISING;
+	} else {
+		fwspec.param_count = 2;
+		fwspec.param[0] = hwirq;
+		fwspec.param[1] = IRQ_TYPE_EDGE_RISING;
+	}
 
 	ret = irq_domain_alloc_irqs_parent(domain, virq, 1, &fwspec);
 	if (ret)
@@ -887,10 +896,47 @@ 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(hv_get_vmbus_root_device()->of_node);
+	if (!parent)
+		return NULL;
+	domain = irq_find_host(parent);
+	of_node_put(parent);
+
+	return domain;
+}
+
+#endif
+
+#ifdef CONFIG_ACPI
+
+static struct irq_domain *hv_pci_acpi_irq_domain_parent(void)
+{
+	struct irq_domain *domain;
+	acpi_gsi_domain_disp_fn gsi_domain_disp_fn;
+
+	if (acpi_irq_model != ACPI_IRQ_MODEL_GIC)
+		return NULL;
+	gsi_domain_disp_fn = acpi_get_gsi_dispatcher();
+	if (!gsi_domain_disp_fn)
+		return NULL;
+	return irq_find_matching_fwnode(gsi_domain_disp_fn(0),
+				     DOMAIN_BUS_ANY);
+}
+
+#endif
+
 static int hv_pci_irqchip_init(void)
 {
 	static struct hv_pci_chip_data *chip_data;
 	struct fwnode_handle *fn = NULL;
+	struct irq_domain *irq_domain_parent = NULL;
 	int ret = -ENOMEM;
 
 	chip_data = kzalloc(sizeof(*chip_data), GFP_KERNEL);
@@ -907,9 +953,24 @@ 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);
+#ifdef CONFIG_ACPI
+	if (!acpi_disabled)
+		irq_domain_parent = hv_pci_acpi_irq_domain_parent();
+#endif
+#if defined(CONFIG_OF)
+	if (!irq_domain_parent)
+		irq_domain_parent = hv_pci_of_irq_domain_parent();
+#endif
+	if (!irq_domain_parent) {
+		WARN_ONCE(1, "Invalid firmware configuration for VMBus interrupts\n");
+		ret = -EINVAL;
+		goto free_chip;
+	}
+
+	hv_msi_gic_irq_domain = irq_domain_create_hierarchy(
+		irq_domain_parent, 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");
Signature · 1 line
2.43.0
Acked-by on v6 11/11
#28 lore raw

Re: [PATCH hyperv-next v6 11/11] PCI: hv: Get vPCI MSI IRQ domain from DeviceTree

Quoted 8 lines · Roman Kisel

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.

Looks good to me; trivial whitespace comment below.

Quoted 100 lines
---
 drivers/pci/controller/pci-hyperv.c | 73 ++++++++++++++++++++++++++---
 1 file changed, 67 insertions(+), 6 deletions(-)
drivers/pci/controller/pci-hyperv.c +57 -6
index 6084b38bdda1..cbff19e8a07c 100644
@@ -50,6 +50,7 @@
 #include <linux/irqdomain.h>
 #include <linux/acpi.h>
 #include <linux/sizes.h>
+#include <linux/of_irq.h>
 #include <asm/mshyperv.h>
 
 /*
@@ -817,9 +818,17 @@ static int hv_pci_vec_irq_gic_domain_alloc(struct irq_domain *domain,
 	int ret;
 
 	fwspec.fwnode = domain->parent->fwnode;
-	fwspec.param_count = 2;
-	fwspec.param[0] = hwirq;
-	fwspec.param[1] = IRQ_TYPE_EDGE_RISING;
+	if (is_of_node(fwspec.fwnode)) {
+		/* SPI lines for OF translations start at offset 32 */
+		fwspec.param_count = 3;
+		fwspec.param[0] = 0;
+		fwspec.param[1] = hwirq - 32;
+		fwspec.param[2] = IRQ_TYPE_EDGE_RISING;
+	} else {
+		fwspec.param_count = 2;
+		fwspec.param[0] = hwirq;
+		fwspec.param[1] = IRQ_TYPE_EDGE_RISING;
+	}
 
 	ret = irq_domain_alloc_irqs_parent(domain, virq, 1, &fwspec);
 	if (ret)
@@ -887,10 +896,47 @@ 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(hv_get_vmbus_root_device()->of_node);
+	if (!parent)
+		return NULL;
+	domain = irq_find_host(parent);
+	of_node_put(parent);
+
+	return domain;
+}
+
+#endif
+
+#ifdef CONFIG_ACPI
+
+static struct irq_domain *hv_pci_acpi_irq_domain_parent(void)
+{
+	struct irq_domain *domain;
+	acpi_gsi_domain_disp_fn gsi_domain_disp_fn;
+
+	if (acpi_irq_model != ACPI_IRQ_MODEL_GIC)
+		return NULL;
+	gsi_domain_disp_fn = acpi_get_gsi_dispatcher();
+	if (!gsi_domain_disp_fn)
+		return NULL;
+	return irq_find_matching_fwnode(gsi_domain_disp_fn(0),
+				     DOMAIN_BUS_ANY);
+}
+
+#endif
+
 static int hv_pci_irqchip_init(void)
 {
 	static struct hv_pci_chip_data *chip_data;
 	struct fwnode_handle *fn = NULL;
+	struct irq_domain *irq_domain_parent = NULL;
 	int ret = -ENOMEM;
 
 	chip_data = kzalloc(sizeof(*chip_data), GFP_KERNEL);
@@ -907,9 +953,24 @@ 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);
+#ifdef CONFIG_ACPI
+	if (!acpi_disabled)
+		irq_domain_parent = hv_pci_acpi_irq_domain_parent();
+#endif
+#if defined(CONFIG_OF)
+	if (!irq_domain_parent)
+		irq_domain_parent = hv_pci_of_irq_domain_parent();
+#endif

drivers/pci/controller/pci-hyperv.c static int hv_pci_irqchip_init(void) · line 973

Quoted 10 lines
drivers/pci/controller/pci-hyperv.c +10 -0
+	if (!irq_domain_parent) {
+		WARN_ONCE(1, "Invalid firmware configuration for VMBus interrupts\n");
+		ret = -EINVAL;
+		goto free_chip;
+	}
+
+	hv_msi_gic_irq_domain = irq_domain_create_hierarchy(
+		irq_domain_parent, 0, HV_PCI_MSI_SPI_NR,
+		fn, &hv_pci_domain_ops,
+		chip_data);

This is a different style of indenting the parameters than other similar cases in this file, which line up parameters on subsequent lines under the open parenthesis.

Quoted 5 lines
drivers/pci/controller/pci-hyperv.c +0 -0
 	if (!hv_msi_gic_irq_domain) {
 		pr_err("Failed to create Hyper-V arm64 vPCI MSI IRQ domain\n");
Signature · 1 line
2.43.0
#29 lore raw

Re: [PATCH hyperv-next v6 11/11] PCI: hv: Get vPCI MSI IRQ domain from DeviceTree

Quoted 5 lines · Bjorn Helgaas
Quoted 4 lines · Roman Kisel

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.

Quoted 9 lines
Quoted 4 lines

Update the hyperv-pci driver to get vPCI MSI IRQ domain in the DeviceTree case, too.

Looks good to me; trivial whitespace comment below.

Thanks a bunch!! I'll fix that the whitespace (and remove the unused variable the robot noticed).

Quoted 120 lines
Quoted 100 lines
---
  drivers/pci/controller/pci-hyperv.c | 73 ++++++++++++++++++++++++++---
  1 file changed, 67 insertions(+), 6 deletions(-)
drivers/pci/controller/pci-hyperv.c +57 -6
index 6084b38bdda1..cbff19e8a07c 100644
@@ -50,6 +50,7 @@
  #include <linux/irqdomain.h>
  #include <linux/acpi.h>
  #include <linux/sizes.h>
+#include <linux/of_irq.h>
  #include <asm/mshyperv.h>
 
  /*
@@ -817,9 +818,17 @@ static int hv_pci_vec_irq_gic_domain_alloc(struct irq_domain *domain,
  	int ret;
 
  	fwspec.fwnode = domain->parent->fwnode;
-	fwspec.param_count = 2;
-	fwspec.param[0] = hwirq;
-	fwspec.param[1] = IRQ_TYPE_EDGE_RISING;
+	if (is_of_node(fwspec.fwnode)) {
+		/* SPI lines for OF translations start at offset 32 */
+		fwspec.param_count = 3;
+		fwspec.param[0] = 0;
+		fwspec.param[1] = hwirq - 32;
+		fwspec.param[2] = IRQ_TYPE_EDGE_RISING;
+	} else {
+		fwspec.param_count = 2;
+		fwspec.param[0] = hwirq;
+		fwspec.param[1] = IRQ_TYPE_EDGE_RISING;
+	}
 
  	ret = irq_domain_alloc_irqs_parent(domain, virq, 1, &fwspec);
  	if (ret)
@@ -887,10 +896,47 @@ 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(hv_get_vmbus_root_device()->of_node);
+	if (!parent)
+		return NULL;
+	domain = irq_find_host(parent);
+	of_node_put(parent);
+
+	return domain;
+}
+
+#endif
+
+#ifdef CONFIG_ACPI
+
+static struct irq_domain *hv_pci_acpi_irq_domain_parent(void)
+{
+	struct irq_domain *domain;
+	acpi_gsi_domain_disp_fn gsi_domain_disp_fn;
+
+	if (acpi_irq_model != ACPI_IRQ_MODEL_GIC)
+		return NULL;
+	gsi_domain_disp_fn = acpi_get_gsi_dispatcher();
+	if (!gsi_domain_disp_fn)
+		return NULL;
+	return irq_find_matching_fwnode(gsi_domain_disp_fn(0),
+				     DOMAIN_BUS_ANY);
+}
+
+#endif
+
  static int hv_pci_irqchip_init(void)
  {
  	static struct hv_pci_chip_data *chip_data;
  	struct fwnode_handle *fn = NULL;
+	struct irq_domain *irq_domain_parent = NULL;
  	int ret = -ENOMEM;
 
  	chip_data = kzalloc(sizeof(*chip_data), GFP_KERNEL);
@@ -907,9 +953,24 @@ 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);
+#ifdef CONFIG_ACPI
+	if (!acpi_disabled)
+		irq_domain_parent = hv_pci_acpi_irq_domain_parent();
+#endif
+#if defined(CONFIG_OF)
+	if (!irq_domain_parent)
+		irq_domain_parent = hv_pci_of_irq_domain_parent();
+#endif

drivers/pci/controller/pci-hyperv.c static int hv_pci_irqchip_init(void) · line 973

Quoted 10 lines
drivers/pci/controller/pci-hyperv.c +10 -0
+	if (!irq_domain_parent) {
+		WARN_ONCE(1, "Invalid firmware configuration for VMBus interrupts\n");
+		ret = -EINVAL;
+		goto free_chip;
+	}
+
+	hv_msi_gic_irq_domain = irq_domain_create_hierarchy(
+		irq_domain_parent, 0, HV_PCI_MSI_SPI_NR,
+		fn, &hv_pci_domain_ops,
+		chip_data);

This is a different style of indenting the parameters than other similar cases in this file, which line up parameters on subsequent lines under the open parenthesis.

Quoted 5 lines
drivers/pci/controller/pci-hyperv.c +0 -0
  	if (!hv_msi_gic_irq_domain) {
  		pr_err("Failed to create Hyper-V arm64 vPCI MSI IRQ domain\n");
Signature · 1 line
2.43.0
Signature · 2 lines
Thank you,
Roman
#30 lore raw

Re: [PATCH hyperv-next v6 11/11] PCI: hv: Get vPCI MSI IRQ domain from DeviceTree

In reply to Roman Kisel
kernel test robot noticed the following build warnings:

Hi Roman,

kernel test robot noticed the following build warnings:

[auto build test WARNING on d9608f6dc3e3229a40e1db1dab573d6882f38c2a]

url:    https://github.com/intel-lab-lkp/linux/commits/Roman-Kisel/arm64-kvm-smccc-Introduce-and-use-API-for-detecting-hypervisor-presence/20250315-082319
base:   d9608f6dc3e3229a40e1db1dab573d6882f38c2a
patch link:    https://lore.kernel.org/r/20250315001931.631210-12-romank%40linux.microsoft.com
patch subject: [PATCH hyperv-next v6 11/11] PCI: hv: Get vPCI MSI IRQ domain from DeviceTree
config: arm64-allmodconfig (https://download.01.org/0day-ci/archive/20250316/[email protected]/config)
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250316/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/pci/controller/pci-hyperv.c:921:21: warning: unused variable 'domain' [-Wunused-variable]
     921 |         struct irq_domain *domain;
         |                            ^~~~~~

1 warning generated.

vim +/domain +921 drivers/pci/controller/pci-hyperv.c

918
919 static struct irq_domain *hv_pci_acpi_irq_domain_parent(void)
920 {

 > 921		struct irq_domain *domain;

922 acpi_gsi_domain_disp_fn gsi_domain_disp_fn;
923
924 if (acpi_irq_model != ACPI_IRQ_MODEL_GIC)
925 return NULL;
926 gsi_domain_disp_fn = acpi_get_gsi_dispatcher();
927 if (!gsi_domain_disp_fn)
928 return NULL;
929 return irq_find_matching_fwnode(gsi_domain_disp_fn(0),
930 DOMAIN_BUS_ANY);
931 }
932

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#31 lore raw

Re: [PATCH hyperv-next v6 11/11] PCI: hv: Get vPCI MSI IRQ domain from DeviceTree

In reply to Roman Kisel
Quoted 96 lines · Roman Kisel

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.

---
 drivers/pci/controller/pci-hyperv.c | 73 ++++++++++++++++++++++++++---
 1 file changed, 67 insertions(+), 6 deletions(-)
drivers/pci/controller/pci-hyperv.c +49 -3
index 6084b38bdda1..cbff19e8a07c 100644
@@ -50,6 +50,7 @@
 #include <linux/irqdomain.h>
 #include <linux/acpi.h>
 #include <linux/sizes.h>
+#include <linux/of_irq.h>
 #include <asm/mshyperv.h>
 
 /*
@@ -817,9 +818,17 @@ static int hv_pci_vec_irq_gic_domain_alloc(struct irq_domain *domain,
        int ret;
 
        fwspec.fwnode = domain->parent->fwnode;
-       fwspec.param_count = 2;
-       fwspec.param[0] = hwirq;
-       fwspec.param[1] = IRQ_TYPE_EDGE_RISING;
+       if (is_of_node(fwspec.fwnode)) {
+               /* SPI lines for OF translations start at offset 32 */
+               fwspec.param_count = 3;
+               fwspec.param[0] = 0;
+               fwspec.param[1] = hwirq - 32;
+               fwspec.param[2] = IRQ_TYPE_EDGE_RISING;
+       } else {
+               fwspec.param_count = 2;
+               fwspec.param[0] = hwirq;
+               fwspec.param[1] = IRQ_TYPE_EDGE_RISING;
+       }
 
        ret = irq_domain_alloc_irqs_parent(domain, virq, 1, &fwspec);
        if (ret)
@@ -887,10 +896,47 @@ 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(hv_get_vmbus_root_device()->of_node);
+       if (!parent)
+               return NULL;
+       domain = irq_find_host(parent);
+       of_node_put(parent);
+
+       return domain;
+}
+
+#endif
+
+#ifdef CONFIG_ACPI
+
+static struct irq_domain *hv_pci_acpi_irq_domain_parent(void)
+{
+       struct irq_domain *domain;
+       acpi_gsi_domain_disp_fn gsi_domain_disp_fn;
+
+       if (acpi_irq_model != ACPI_IRQ_MODEL_GIC)
+               return NULL;
+       gsi_domain_disp_fn = acpi_get_gsi_dispatcher();
+       if (!gsi_domain_disp_fn)
+               return NULL;
+       return irq_find_matching_fwnode(gsi_domain_disp_fn(0),
+                                    DOMAIN_BUS_ANY);
+}
+
+#endif
+
 static int hv_pci_irqchip_init(void)
 {
        static struct hv_pci_chip_data *chip_data;
        struct fwnode_handle *fn = NULL;
+       struct irq_domain *irq_domain_parent = NULL;
        int ret = -ENOMEM;
 
        chip_data = kzalloc(sizeof(*chip_data), GFP_KERNEL);
@@ -907,9 +953,24 @@ static int hv_pci_irqchip_init(void)
         * way to ensure that all the corresponding devices are also gone and

drivers/pci/controller/pci-hyperv.c static int hv_pci_irqchip_init(void) · line 960

Quoted 10 lines
drivers/pci/controller/pci-hyperv.c +5 -3
         * 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);
+#ifdef CONFIG_ACPI
+       if (!acpi_disabled)
+               irq_domain_parent = hv_pci_acpi_irq_domain_parent();
+#endif
+#if defined(CONFIG_OF)

Why don't you do

#ifdef CONFIG_OF

here for consistency?

Quoted 17 lines
drivers/pci/controller/pci-hyperv.c +13 -1
+       if (!irq_domain_parent)
+               irq_domain_parent = hv_pci_of_irq_domain_parent();
+#endif
+       if (!irq_domain_parent) {
+               WARN_ONCE(1, "Invalid firmware configuration for VMBus interrupts\n");
+               ret = -EINVAL;
+               goto free_chip;
+       }
+
+       hv_msi_gic_irq_domain = irq_domain_create_hierarchy(
+               irq_domain_parent, 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");
--
#32 lore raw

Re: [PATCH hyperv-next v6 11/11] PCI: hv: Get vPCI MSI IRQ domain from DeviceTree

Quoted 1 line · Rafael J. Wysocki

On Sat, Mar 15, 2025 at 1:19 AM Roman Kisel <[email protected]> wrote:

[...]

Quoted 9 lines

drivers/pci/controller/pci-hyperv.c static int hv_pci_irqchip_init(void) · line 960

Quoted 6 lines
drivers/pci/controller/pci-hyperv.c +5 -1
-                                                         chip_data);
+#ifdef CONFIG_ACPI
+       if (!acpi_disabled)
+               irq_domain_parent = hv_pci_acpi_irq_domain_parent();
+#endif
+#if defined(CONFIG_OF)

Why don't you do

Quoted 4 lines

#ifdef CONFIG_OF

here for consistency?

Agree, that'd be easier on the eyes :) Will fix in the next version, thanks for the suggestion!

Quoted 17 lines
Quoted 17 lines
drivers/pci/controller/pci-hyperv.c +13 -1
+       if (!irq_domain_parent)
+               irq_domain_parent = hv_pci_of_irq_domain_parent();
+#endif
+       if (!irq_domain_parent) {
+               WARN_ONCE(1, "Invalid firmware configuration for VMBus interrupts\n");
+               ret = -EINVAL;
+               goto free_chip;
+       }
+
+       hv_msi_gic_irq_domain = irq_domain_create_hierarchy(
+               irq_domain_parent, 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");
--
Signature · 2 lines
Thank you,
Roman