Modify arm_smccc_hypervisor_has_uuid() to check is_realm_world() and use rsi_host_call() to query the hypervisor vendor UUID when inside a Realm. The realm path is factored into a helper, arm_smccc_realm_get_hypervisor_uuid(), that owns a file-static rsi_host_call buffer (uuid_hc) serialized by a spinlock.
The RSI-specific includes, file-static state and helper are guarded with CONFIG_ARM64 because <asm/rsi.h> does not exist on 32-bit ARM. For non-Realm environments, the existing arm_smccc_1_1_invoke() path is unchanged. Signed-off-by: Kameron Carr <[email protected]> --- drivers/firmware/smccc/smccc.c | 41 +++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/smccc/smccc.c b/drivers/firmware/smccc/smccc.c index bdee057db2fd3..6b465e65472b0 100644 --- a/drivers/firmware/smccc/smccc.c +++ b/drivers/firmware/smccc/smccc.c @@ -12,6 +12,12 @@ #include <linux/platform_device.h> #include <asm/archrandom.h> +#ifdef CONFIG_ARM64 +#include <linux/cleanup.h> +#include <linux/spinlock.h> +#include <asm/rsi.h> +#endif + static u32 smccc_version = ARM_SMCCC_VERSION_1_0; static enum arm_smccc_conduit smccc_conduit = SMCCC_CONDUIT_NONE; @@ -67,12 +73,45 @@ s32 arm_smccc_get_soc_id_revision(void) } EXPORT_SYMBOL_GPL(arm_smccc_get_soc_id_revision); +#ifdef CONFIG_ARM64 +static struct rsi_host_call uuid_hc; +static DEFINE_SPINLOCK(uuid_hc_lock); + +/* + * Helper function to get the hypervisor UUID via an RsiHostCall. + */ +static bool arm_smccc_realm_get_hypervisor_uuid(struct arm_smccc_res *res) +{ + guard(spinlock_irqsave)(&uuid_hc_lock); + + memset(&uuid_hc, 0, sizeof(uuid_hc)); + uuid_hc.gprs[0] = ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID; + + if (rsi_host_call(__pa_symbol(&uuid_hc)) != RSI_SUCCESS) + return false; + + res->a0 = uuid_hc.gprs[0]; + res->a1 = uuid_hc.gprs[1]; + res->a2 = uuid_hc.gprs[2]; + res->a3 = uuid_hc.gprs[3]; + return true; +} +#endif + bool arm_smccc_hypervisor_has_uuid(const uuid_t *hyp_uuid) { struct arm_smccc_res res = {}; uuid_t uuid; - arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID, &res); +#ifdef CONFIG_ARM64 + if (is_realm_world()) { + if (!arm_smccc_realm_get_hypervisor_uuid(&res)) + return false; + } else +#endif + arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID, + &res); + if (res.a0 == SMCCC_RET_NOT_SUPPORTED) return false; -- 2.45.4

