Skip to content

Commit 36ebd32

Browse files
romank-msftliuw
authored andcommitted
arm64: hyperv: Use SMCCC to detect hypervisor presence
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. Signed-off-by: Roman Kisel <[email protected]> Reviewed-by: Michael Kelley <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Wei Liu <[email protected]> Message-ID: <[email protected]>
1 parent 1342306 commit 36ebd32

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

arch/arm64/hyperv/mshyperv.c

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,48 @@ int hv_get_hypervisor_version(union hv_hypervisor_version_info *info)
2828
}
2929
EXPORT_SYMBOL_GPL(hv_get_hypervisor_version);
3030

31+
#ifdef CONFIG_ACPI
32+
33+
static bool __init hyperv_detect_via_acpi(void)
34+
{
35+
if (acpi_disabled)
36+
return false;
37+
/*
38+
* Hypervisor ID is only available in ACPI v6+, and the
39+
* structure layout was extended in v6 to accommodate that
40+
* new field.
41+
*
42+
* At the very minimum, this check makes sure not to read
43+
* past the FADT structure.
44+
*
45+
* It is also needed to catch running in some unknown
46+
* non-Hyper-V environment that has ACPI 5.x or less.
47+
* In such a case, it can't be Hyper-V.
48+
*/
49+
if (acpi_gbl_FADT.header.revision < 6)
50+
return false;
51+
return strncmp((char *)&acpi_gbl_FADT.hypervisor_id, "MsHyperV", 8) == 0;
52+
}
53+
54+
#else
55+
56+
static bool __init hyperv_detect_via_acpi(void)
57+
{
58+
return false;
59+
}
60+
61+
#endif
62+
63+
static bool __init hyperv_detect_via_smccc(void)
64+
{
65+
uuid_t hyperv_uuid = UUID_INIT(
66+
0x58ba324d, 0x6447, 0x24cd,
67+
0x75, 0x6c, 0xef, 0x8e,
68+
0x24, 0x70, 0x59, 0x16);
69+
70+
return arm_smccc_hypervisor_has_uuid(&hyperv_uuid);
71+
}
72+
3173
static int __init hyperv_init(void)
3274
{
3375
struct hv_get_vp_registers_output result;
@@ -36,13 +78,11 @@ static int __init hyperv_init(void)
3678

3779
/*
3880
* Allow for a kernel built with CONFIG_HYPERV to be running in
39-
* a non-Hyper-V environment, including on DT instead of ACPI.
81+
* a non-Hyper-V environment.
82+
*
4083
* In such cases, do nothing and return success.
4184
*/
42-
if (acpi_disabled)
43-
return 0;
44-
45-
if (strncmp((char *)&acpi_gbl_FADT.hypervisor_id, "MsHyperV", 8))
85+
if (!hyperv_detect_via_acpi() && !hyperv_detect_via_smccc())
4686
return 0;
4787

4888
/* Setup the guest ID */

0 commit comments

Comments
 (0)