Skip to contentSkip to conversation

arm64: hyperv: Add Realm support for Hyper-V

PATCH Superseded Kameron Carr 6 participants 18 messages Oct 2 – Nov 2

Subsystems (5)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover arm64: hyperv: Add Realm support for Hyper-V

Realms (CoCo VMs on ARM) require host calls to be routed through the RMM (Realm Management Monitor) via the RSI (Realm Service Interface). This series implements most of the necessary changes to support Realms on Hyper-V.

One required change is not included in this series. The two buffers allocated via vzalloc() in netvsc_init_buf() cannot be decrypted in vmbus_establish_gpadl(). Currently only linearly mapped memory can be decrypted.

This patch series was tested by booting a Realm on Cobalt 200 running Windows. I tested 4KB and 64KB page size. I replaced vzalloc() in netvsc_init_buf() with alloc_pages_node() -> set_memory_decrypted() -> vmap() in my testing as a workaround for the issue mentioned above [1].

Changes since v1 [2]:
Patch 1: Add explicit padding to the RSI host call structure Patch 3: Change from a per-cpu pointer lazily allocated to an array
of host call structs indexed by cpu id
Patch 4: Align input_page + output_page allocation to PAGE_SIZE since
that is the smallest unit of memory that can be decrypted
~Remove KASAN tags before passing address to
set_memory_decrypted() since __is_lm_address() does pointer arithmetic.~ (reverted in v3)
Patch 5: Add a helper function to reduce repetition
Check for NULL before indexing into host call array

Changes since v2 [3]:
Patch 3: Remove hv_hostcall_free() and inline the logic for simplicity
Reorder edits to keep #include line at the end of the file
Patch 4: Remove kasan_reset_tag()

Changes since v3 [4]:
Rebased onto arm64 for-next/smccc-bus which includes moving RSI header files out of arch/arm64 [5]

Changes since v4 [6]:
Patch 1, 2, 4: Fix commit message to reflect the new header file names Patch 5: Remove extra blank line

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/[email protected]/
[5] https://lore.kernel.org/all/[email protected]/
[6] https://lore.kernel.org/all/[email protected]/

Kameron Carr (6):
arm64: rsi: Add RSI host call structure and helper function
firmware: smccc: Detect hypervisor via RSI host call in CCA Realms
arm64: hyperv: Add per-CPU RSI host call infrastructure for CCA Realms
Drivers: hv: Mark shared memory as decrypted for CCA Realms
arm64: hyperv: Route hypercalls through RSI host call in CCA Realms
arm64: hyperv: Implement hv_is_isolation_supported() for CCA Realms

 arch/arm64/hyperv/hv_core.c       | 155 +++++++++++++++++++++++-------
 arch/arm64/hyperv/mshyperv.c      |  38 +++++++-
 arch/arm64/include/asm/mshyperv.h |   4 +
 drivers/firmware/smccc/smccc.c    |  41 +++++++-
 drivers/hv/hv_common.c            |  17 +++-
 include/asm-generic/mshyperv.h    |   1 +
 include/linux/arm-rsi-cmds.h      |  22 +++++
 include/linux/arm-smccc-rsi.h     |   7 ++
 8 files changed, 244 insertions(+), 41 deletions(-)

base-commit: bce57945f5e7207960b2bd567a6e880f90258ffb

Signature · 1 line
2.45.4
#1 lore raw

PATCH v5 1/6 arm64: rsi: Add RSI host call structure and helper function

Add struct rsi_host_call to arm-smccc-rsi.h, which represents the host call data structure used by the Realm Management Monitor (RMM) for the RSI_HOST_CALL interface. The structure contains a 16-bit immediate field and 31 general-purpose register values, aligned to 256 bytes as required by the CCA RMM specification.

Add rsi_host_call() static inline wrapper in arm-rsi-cmds.h that invokes SMC_RSI_HOST_CALL with the physical address of the host call structure. This will be used by Hyper-V guest code to route hypercalls through the RSI interface when running inside an Arm CCA Realm.

---
 include/linux/arm-rsi-cmds.h  | 22 ++++++++++++++++++++++
 include/linux/arm-smccc-rsi.h |  7 +++++++
 2 files changed, 29 insertions(+)
include/linux/arm-rsi-cmds.h +22 -0
index 3f7a6a8..01d292e 100644
@@ -236,4 +236,26 @@ static inline unsigned long rsi_attestation_token_continue(phys_addr_t granule,
 	return res.a0;
 }
 
+/**
+ * rsi_host_call - Make a Host call.
+ * @host_call_struct: IPA of host call structure
+ *
+ * This call will fail if the IPA of the host call structure:
+ * * is not aligned to 256 bytes,
+ * * is not protected / encrypted,
+ * * is RIPAS_EMPTY
+ *
+ * Returns:
+ *  On success, returns RSI_SUCCESS.
+ *  Otherwise, returns an error code.
+ */
+static inline unsigned long rsi_host_call(phys_addr_t host_call_struct)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_smc(SMC_RSI_HOST_CALL, host_call_struct, 0, 0, 0, 0, 0, 0,
+		      &res);
+	return res.a0;
+}
+
 #endif /* __LINUX_ARM_RSI_CMDS_H_ */
include/linux/arm-smccc-rsi.h +7 -0
index fddb779..4c8530b 100644
@@ -142,6 +142,13 @@ struct realm_config {
 	 */
 } __aligned(0x1000);
 
+struct rsi_host_call {
+	u16 immediate;
+	u8 _padding[6];
+	u64 gprs[31];
+} __aligned(256);
+static_assert(sizeof(struct rsi_host_call) == 256);
+
 #endif /* __ASSEMBLER__ */
 
 /*
Signature · 1 line
2.45.4
#5 lore raw

PATCH v5 2/6 firmware: smccc: Detect hypervisor via RSI host call in CCA Realms

In reply to Kameron Carr

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 <linux/arm-rsi-cmds.h> does not build on 32-bit ARM.

For non-Realm environments, the existing arm_smccc_1_1_invoke() path is unchanged.

---
 drivers/firmware/smccc/smccc.c | 41 +++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)
drivers/firmware/smccc/smccc.c +40 -1
index afc2e4d..7e77170 100644
@@ -14,6 +14,12 @@
 
 #include <asm/archrandom.h>
 
+#ifdef CONFIG_ARM64
+#include <linux/arm-rsi-cmds.h>
+#include <linux/cleanup.h>
+#include <linux/spinlock.h>
+#endif
+
 static u32 smccc_version = ARM_SMCCC_VERSION_1_0;
 static enum arm_smccc_conduit smccc_conduit = SMCCC_CONDUIT_NONE;
 
@@ -69,12 +75,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 void 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) {
+		res->a0 = SMCCC_RET_NOT_SUPPORTED;
+		return;
+	}
+
+	res->a0 = uuid_hc.gprs[0];
+	res->a1 = uuid_hc.gprs[1];
+	res->a2 = uuid_hc.gprs[2];
+	res->a3 = uuid_hc.gprs[3];
+}
+#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())
+		arm_smccc_realm_get_hypervisor_uuid(&res);
+	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;
 
Signature · 1 line
2.45.4
#12 lore raw

PATCH v5 3/6 arm64: hyperv: Add per-CPU RSI host call infrastructure for CCA Realms

In reply to Kameron Carr

Arm CCA Realms cannot issue Hyper-V hypercalls via HVC; the guest must route them through the RSI_HOST_CALL interface, which takes the IPA of a per-CPU rsi_host_call structure as its argument.

Add hv_hostcall_array as a per-CPU struct array and allocate it during hyperv_init(). The allocation is gated on is_realm_world() so non-Realm arm64 Hyper-V guests pay no memory cost.

---
 arch/arm64/hyperv/mshyperv.c      | 28 ++++++++++++++++++++++++++--
 arch/arm64/include/asm/mshyperv.h |  4 ++++
 2 files changed, 30 insertions(+), 2 deletions(-)
arch/arm64/hyperv/mshyperv.c +26 -2
index 4fdc26a..b1657cf 100644
@@ -11,14 +11,19 @@
 
 #include <linux/types.h>
 #include <linux/acpi.h>
+#include <linux/arm-rsi-cmds.h>
 #include <linux/export.h>
 #include <linux/errno.h>
+#include <linux/slab.h>
 #include <linux/version.h>
 #include <linux/cpuhotplug.h>
 #include <asm/mshyperv.h>
 
 static bool hyperv_initialized;
 
+struct rsi_host_call *hv_hostcall_array;
+EXPORT_SYMBOL_GPL(hv_hostcall_array);
+
 int hv_get_hypervisor_version(union hv_hypervisor_version_info *info)
 {
 	hv_get_vpreg_128(HV_REGISTER_HYPERVISOR_VERSION,
@@ -85,6 +90,20 @@ static int __init hyperv_init(void)
 	if (!hyperv_detect_via_acpi() && !hyperv_detect_via_smccc())
 		return 0;
 
+	/*
+	 * The RSI host-call buffers are only ever used when
+	 * is_realm_world() is true. Skip the allocation on non-Realm
+	 * guests. A single contiguous array of nr_cpu_ids entries is
+	 * allocated; each CPU indexes into it by its processor ID.
+	 */
+	if (is_realm_world()) {
+		hv_hostcall_array = kcalloc(nr_cpu_ids,
+					    sizeof(struct rsi_host_call),
+					    GFP_KERNEL);
+		if (!hv_hostcall_array)
+			return -ENOMEM;
+	}
+
 	/* Setup the guest ID */
 	guest_id = hv_generate_guest_id(LINUX_VERSION_CODE);
 	hv_set_vpreg(HV_REGISTER_GUEST_OS_ID, guest_id);
@@ -106,13 +125,13 @@ static int __init hyperv_init(void)
 
 	ret = hv_common_init();
 	if (ret)
-		return ret;
+		goto free_hostcall_mem;
 
 	ret = cpuhp_setup_state(CPUHP_AP_HYPERV_ONLINE, "arm64/hyperv_init:online",
 				hv_common_cpu_init, hv_common_cpu_die);
 	if (ret < 0) {
 		hv_common_free();
-		return ret;
+		goto free_hostcall_mem;
 	}
 
 	if (ms_hyperv.priv_high & HV_ACCESS_PARTITION_ID)
@@ -125,6 +144,11 @@ static int __init hyperv_init(void)
 
 	hyperv_initialized = true;
 	return 0;
+
+free_hostcall_mem:
+	kfree(hv_hostcall_array);
+	hv_hostcall_array = NULL;
+	return ret;
 }
 
 early_initcall(hyperv_init);
arch/arm64/include/asm/mshyperv.h +4 -0
index b721d31..aed0aa5 100644
@@ -61,6 +61,10 @@ static inline u64 hv_get_non_nested_msr(unsigned int reg)
 				ARM_SMCCC_OWNER_VENDOR_HYP,	\
 				HV_SMCCC_FUNC_NUMBER)
 
+/* Per-CPU-indexed RSI host call structures for CCA Realms */
+struct rsi_host_call;
+extern struct rsi_host_call *hv_hostcall_array;
+
 #include <asm-generic/mshyperv.h>
 
 #endif
Signature · 1 line
2.45.4
#14 lore raw

PATCH v5 4/6 Drivers: hv: Mark shared memory as decrypted for CCA Realms

In reply to Kameron Carr

In hv_common_cpu_init(), the per-CPU hypercall input/output pages need to be marked as decrypted (shared) for confidential VM isolation types. This is already done for SNP and TDX isolation; extend the same handling to Arm CCA Realm guests so that the host hypervisor can access the shared hypercall buffers.

is_realm_world() is declared in include/linux/arm-rsi-cmds.h which only builds on arm64 (it includes <asm/memory.h>), so using it directly in the arch-neutral drivers/hv/hv_common.c would break the x86 build. Introduce a Hyper-V-specific helper following the established hv_isolation_type_snp() / hv_isolation_type_tdx() pattern.

On architectures other than arm64 the weak default keeps the existing behaviour.

---
 arch/arm64/hyperv/mshyperv.c   |  5 +++++
 drivers/hv/hv_common.c         | 17 +++++++++++++----
 include/asm-generic/mshyperv.h |  1 +
 3 files changed, 19 insertions(+), 4 deletions(-)
arch/arm64/hyperv/mshyperv.c +5 -0
index b1657cf..45ca8e2 100644
@@ -158,3 +158,8 @@ bool hv_is_hyperv_initialized(void)
 	return hyperv_initialized;
 }
 EXPORT_SYMBOL_GPL(hv_is_hyperv_initialized);
+
+bool hv_isolation_type_cca(void)
+{
+	return is_realm_world();
+}
drivers/hv/hv_common.c +13 -4
index 31256cb..a60c92c 100644
@@ -476,6 +476,7 @@ int hv_common_cpu_init(unsigned int cpu)
 	u64 msr_vp_index;
 	gfp_t flags;
 	const int pgcount = hv_output_page_exists() ? 2 : 1;
+	const size_t alloc_size = ALIGN((size_t)pgcount * HV_HYP_PAGE_SIZE, PAGE_SIZE);
 	void *mem;
 	int ret = 0;
 
@@ -489,7 +490,7 @@ int hv_common_cpu_init(unsigned int cpu)
 	 * online and then taken offline
 	 */
 	if (!*inputarg) {
-		mem = kmalloc_array(pgcount, HV_HYP_PAGE_SIZE, flags);
+		mem = kmalloc(alloc_size, flags);
 		if (!mem)
 			return -ENOMEM;
 
@@ -499,14 +500,16 @@ int hv_common_cpu_init(unsigned int cpu)
 		}
 
 		if (!ms_hyperv.paravisor_present &&
-		    (hv_isolation_type_snp() || hv_isolation_type_tdx())) {
-			ret = set_memory_decrypted((unsigned long)mem, pgcount);
+		    (hv_isolation_type_snp() || hv_isolation_type_tdx() ||
+		     hv_isolation_type_cca())) {
+			ret = set_memory_decrypted((unsigned long)mem,
+						   alloc_size >> PAGE_SHIFT);
 			if (ret) {
 				/* It may be unsafe to free 'mem' */
 				return ret;
 			}
 
-			memset(mem, 0x00, pgcount * HV_HYP_PAGE_SIZE);
+			memset(mem, 0x00, alloc_size);
 		}
 
 		/*
@@ -666,6 +669,12 @@ bool __weak hv_isolation_type_tdx(void)
 }
 EXPORT_SYMBOL_GPL(hv_isolation_type_tdx);
 
+bool __weak hv_isolation_type_cca(void)
+{
+	return false;
+}
+EXPORT_SYMBOL_GPL(hv_isolation_type_cca);
+
 void __weak hv_setup_vmbus_handler(void (*handler)(void))
 {
 }
include/asm-generic/mshyperv.h +1 -0
index bf601d6..1fa79ab 100644
@@ -79,6 +79,7 @@ u64 hv_do_fast_hypercall16(u16 control, u64 input1, u64 input2);
 
 bool hv_isolation_type_snp(void);
 bool hv_isolation_type_tdx(void);
+bool hv_isolation_type_cca(void);
 
 /*
  * On architectures where Hyper-V doesn't support AEOI (e.g., ARM64),
Signature · 1 line
2.45.4
#15 lore raw

PATCH v5 5/6 arm64: hyperv: Route hypercalls through RSI host call in CCA Realms

In reply to Kameron Carr

Modify the five hypercall wrapper functions to check is_realm_world() and use the per-CPU rsi_host_call structure when inside a Realm.

---
 arch/arm64/hyperv/hv_core.c | 155 ++++++++++++++++++++++++++++--------
 1 file changed, 121 insertions(+), 34 deletions(-)
arch/arm64/hyperv/hv_core.c +121 -34
index e33a9e3..2f6fc14 100644
@@ -12,11 +12,43 @@
 #include <linux/export.h>
 #include <linux/mm.h>
 #include <linux/arm-smccc.h>
+#include <linux/arm-rsi-cmds.h>
 #include <linux/module.h>
+#include <linux/smp.h>
 #include <asm-generic/bug.h>
 #include <hyperv/hvhdk.h>
 #include <asm/mshyperv.h>
 
+/*
+ * hv_do_rsi_hypercall - Helper function to invoke a hypercall from a
+ * Realm world using the RSI interface.
+ */
+static u64 hv_do_rsi_hypercall(u64 control, u64 input1, u64 input2)
+{
+	struct rsi_host_call *hostcall;
+	unsigned long flags;
+	u64 ret;
+
+	if (!hv_hostcall_array)
+		return HV_STATUS_INVALID_HYPERCALL_INPUT;
+
+	local_irq_save(flags);
+	hostcall = &hv_hostcall_array[smp_processor_id()];
+	memset(hostcall, 0, sizeof(*hostcall));
+	hostcall->gprs[0] = HV_FUNC_ID;
+	hostcall->gprs[1] = control;
+	hostcall->gprs[2] = input1;
+	hostcall->gprs[3] = input2;
+
+	if (rsi_host_call(virt_to_phys(hostcall)) == RSI_SUCCESS)
+		ret = hostcall->gprs[0];
+	else
+		ret = HV_STATUS_INVALID_HYPERCALL_INPUT;
+
+	local_irq_restore(flags);
+	return ret;
+}
+
 /*
  * hv_do_hypercall- Invoke the specified hypercall
  */
@@ -29,8 +61,11 @@ u64 hv_do_hypercall(u64 control, void *input, void *output)
 	input_address = input ? virt_to_phys(input) : 0;
 	output_address = output ? virt_to_phys(output) : 0;
 
-	arm_smccc_1_1_hvc(HV_FUNC_ID, control,
-			  input_address, output_address, &res);
+	if (is_realm_world())
+		return hv_do_rsi_hypercall(control, input_address, output_address);
+
+	arm_smccc_1_1_hvc(HV_FUNC_ID, control, input_address,
+			  output_address, &res);
 	return res.a0;
 }
 EXPORT_SYMBOL_GPL(hv_do_hypercall);
@@ -48,6 +83,9 @@ u64 hv_do_fast_hypercall8(u16 code, u64 input)
 
 	control = (u64)code | HV_HYPERCALL_FAST_BIT;
 
+	if (is_realm_world())
+		return hv_do_rsi_hypercall(control, input, 0);
+
 	arm_smccc_1_1_hvc(HV_FUNC_ID, control, input, &res);
 	return res.a0;
 }
@@ -65,6 +103,9 @@ u64 hv_do_fast_hypercall16(u16 code, u64 input1, u64 input2)
 
 	control = (u64)code | HV_HYPERCALL_FAST_BIT;
 
+	if (is_realm_world())
+		return hv_do_rsi_hypercall(control, input1, input2);
+
 	arm_smccc_1_1_hvc(HV_FUNC_ID, control, input1, input2, &res);
 	return res.a0;
 }
@@ -76,24 +117,44 @@ EXPORT_SYMBOL_GPL(hv_do_fast_hypercall16);
 void hv_set_vpreg(u32 msr, u64 value)
 {
 	struct arm_smccc_res res;
+	struct rsi_host_call *hostcall;
+	unsigned long flags;
+	u64 status;
 
-	arm_smccc_1_1_hvc(HV_FUNC_ID,
-		HVCALL_SET_VP_REGISTERS | HV_HYPERCALL_FAST_BIT |
-			HV_HYPERCALL_REP_COMP_1,
-		HV_PARTITION_ID_SELF,
-		HV_VP_INDEX_SELF,
-		msr,
-		0,
-		value,
-		0,
-		&res);
+	if (is_realm_world()) {
+		local_irq_save(flags);
+		hostcall = &hv_hostcall_array[smp_processor_id()];
+		memset(hostcall, 0, sizeof(*hostcall));
+		hostcall->gprs[0] = HV_FUNC_ID;
+		hostcall->gprs[1] = HVCALL_SET_VP_REGISTERS |
+				    HV_HYPERCALL_FAST_BIT |
+				    HV_HYPERCALL_REP_COMP_1;
+		hostcall->gprs[2] = HV_PARTITION_ID_SELF;
+		hostcall->gprs[3] = HV_VP_INDEX_SELF;
+		hostcall->gprs[4] = msr;
+		hostcall->gprs[6] = value;
+
+		if (rsi_host_call(virt_to_phys(hostcall)) == RSI_SUCCESS)
+			status = hostcall->gprs[0];
+		else
+			status = HV_STATUS_INVALID_HYPERCALL_INPUT;
+		local_irq_restore(flags);
+	} else {
+		arm_smccc_1_1_hvc(HV_FUNC_ID,
+				  HVCALL_SET_VP_REGISTERS |
+					  HV_HYPERCALL_FAST_BIT |
+					  HV_HYPERCALL_REP_COMP_1,
+				  HV_PARTITION_ID_SELF, HV_VP_INDEX_SELF, msr,
+				  0, value, 0, &res);
+		status = res.a0;
+	}
 
 	/*
-	 * Something is fundamentally broken in the hypervisor if
-	 * setting a VP register fails. There's really no way to
-	 * continue as a guest VM, so panic.
+	 * Something is fundamentally broken in the hypervisor (or, in a
+	 * Realm, the RMM denied the host call) if setting a VP register
+	 * fails. There's really no way to continue as a guest VM, so panic.
 	 */
-	BUG_ON(!hv_result_success(res.a0));
+	BUG_ON(!hv_result_success(status));
 }
 EXPORT_SYMBOL_GPL(hv_set_vpreg);
 
@@ -108,29 +169,55 @@ void hv_get_vpreg_128(u32 msr, struct hv_get_vp_registers_output *result)
 {
 	struct arm_smccc_1_2_regs args;
 	struct arm_smccc_1_2_regs res;
+	struct rsi_host_call *hostcall;
+	unsigned long flags;
+	u64 status;
 
-	args.a0 = HV_FUNC_ID;
-	args.a1 = HVCALL_GET_VP_REGISTERS | HV_HYPERCALL_FAST_BIT |
-			HV_HYPERCALL_REP_COMP_1;
-	args.a2 = HV_PARTITION_ID_SELF;
-	args.a3 = HV_VP_INDEX_SELF;
-	args.a4 = msr;
+	if (is_realm_world()) {
+		local_irq_save(flags);
+		hostcall = &hv_hostcall_array[smp_processor_id()];
+		memset(hostcall, 0, sizeof(*hostcall));
 
-	/*
-	 * Use the SMCCC 1.2 interface because the results are in registers
-	 * beyond X0-X3.
-	 */
-	arm_smccc_1_2_hvc(&args, &res);
+		hostcall->gprs[0] = HV_FUNC_ID;
+		hostcall->gprs[1] = HVCALL_GET_VP_REGISTERS |
+				    HV_HYPERCALL_FAST_BIT |
+				    HV_HYPERCALL_REP_COMP_1;
+		hostcall->gprs[2] = HV_PARTITION_ID_SELF;
+		hostcall->gprs[3] = HV_VP_INDEX_SELF;
+		hostcall->gprs[4] = msr;
+
+		if (rsi_host_call(virt_to_phys(hostcall)) == RSI_SUCCESS) {
+			status = hostcall->gprs[0];
+			result->as64.low = hostcall->gprs[6];
+			result->as64.high = hostcall->gprs[7];
+		} else {
+			status = HV_STATUS_INVALID_HYPERCALL_INPUT;
+		}
+		local_irq_restore(flags);
+	} else {
+		args.a0 = HV_FUNC_ID;
+		args.a1 = HVCALL_GET_VP_REGISTERS | HV_HYPERCALL_FAST_BIT |
+			  HV_HYPERCALL_REP_COMP_1;
+		args.a2 = HV_PARTITION_ID_SELF;
+		args.a3 = HV_VP_INDEX_SELF;
+		args.a4 = msr;
+
+		/*
+		 * Use the SMCCC 1.2 interface because the results are in
+		 * registers beyond X0-X3.
+		 */
+		arm_smccc_1_2_hvc(&args, &res);
+		status = res.a0;
+		result->as64.low = res.a6;
+		result->as64.high = res.a7;
+	}
 
 	/*
-	 * Something is fundamentally broken in the hypervisor if
-	 * getting a VP register fails. There's really no way to
-	 * continue as a guest VM, so panic.
+	 * Something is fundamentally broken in the hypervisor (or, in a
+	 * Realm, the RMM denied the host call) if getting a VP register
+	 * fails. There's really no way to continue as a guest VM, so panic.
 	 */
-	BUG_ON(!hv_result_success(res.a0));
-
-	result->as64.low = res.a6;
-	result->as64.high = res.a7;
+	BUG_ON(!hv_result_success(status));
 }
 EXPORT_SYMBOL_GPL(hv_get_vpreg_128);
 
Signature · 1 line
2.45.4
#17 lore raw

PATCH v5 6/6 arm64: hyperv: Implement hv_is_isolation_supported() for CCA Realms

In reply to Kameron Carr

Provide an arm64 implementation of hv_is_isolation_supported() that overrides the __weak default in drivers/hv/hv_common.c.

The implementation deliberately does not depend on hv_is_hyperv_initialized() because hv_common_init() consults hv_is_isolation_supported() before hyperv_initialized is set.

---
 arch/arm64/hyperv/mshyperv.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/arm64/hyperv/mshyperv.c +5 -0
index 45ca8e2..c41188a 100644
@@ -163,3 +163,8 @@ bool hv_isolation_type_cca(void)
 {
 	return is_realm_world();
 }
+
+bool hv_is_isolation_supported(void)
+{
+	return is_realm_world();
+}
Signature · 1 line
2.45.4
#13 lore raw

Re: [PATCH v5 3/6] arm64: hyperv: Add per-CPU RSI host call infrastructure for CCA Realms

In reply to Kameron Carr
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] arm64: hyperv: kcalloc() violates RSI host call 256-byte alignment --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] arm64: hyperv: kcalloc() violates RSI host call 256-byte alignment --

commit 15aadbf7702767ee71f473eab885a0900dbd0a76
Author: Kameron Carr <[email protected]>

arm64: hyperv: Add per-CPU RSI host call infrastructure for CCA Realms

This commit adds a dynamically allocated array of per-CPU struct rsi_host_call structures for ARM CCA Realms. The memory is allocated using kcalloc() during hyperv_init() to avoid paying the memory cost on non-Realm guests.

Quoted 4 lines
arch/arm64/hyperv/mshyperv.c +0 -0
index 4fdc26ade1d74..b1657cfabd7d1 100644

[ ... ]

Quoted 4 lines
arch/arm64/hyperv/mshyperv.c +0 -0
@@ -85,6 +90,20 @@ static int __init hyperv_init(void)
 	if (!hyperv_detect_via_acpi() && !hyperv_detect_via_smccc())
 		return 0;
 

arch/arm64/hyperv/mshyperv.c static int __init hyperv_init(void) · line 102

Quoted 10 lines
arch/arm64/hyperv/mshyperv.c +10 -0
+	/*
+	 * The RSI host-call buffers are only ever used when
+	 * is_realm_world() is true. Skip the allocation on non-Realm
+	 * guests. A single contiguous array of nr_cpu_ids entries is
+	 * allocated; each CPU indexes into it by its processor ID.
+	 */
+	if (is_realm_world()) {
+		hv_hostcall_array = kcalloc(nr_cpu_ids,
+					    sizeof(struct rsi_host_call),
+					    GFP_KERNEL);

[Severity: High]
Does kcalloc() satisfy the __aligned(256) requirement of struct rsi_host_call when SLUB debugging or KASAN is enabled?

The struct definition explicitly demands 256-byte alignment:

include/linux/arm-smccc-rsi.h:

struct rsi_host_call {
	u16 immediate;
	u8 _padding[6];
	u64 gprs[31];
} __aligned(256);

kcalloc() only receives the size of the structure, not the alignment constraint. When SLUB debugging is enabled, redzoning metadata is prepended to the object, shifting the base pointer off the 256-byte boundary. A misaligned Intermediate Physical Address (IPA) might lead to hardware rejection of the hypercall by the Realm Management Monitor (RMM).

Additionally, since this allocates a single contiguous array for all CPUs, does it bypass NUMA locality? Using alloc_percpu() would satisfy the alignment constraint natively and allocate memory on local nodes.

Quoted 4 lines
arch/arm64/hyperv/mshyperv.c +4 -0
+		if (!hv_hostcall_array)
+			return -ENOMEM;
+	}
+
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#16 lore raw

Re: [PATCH v5 5/6] arm64: hyperv: Route hypercalls through RSI host call in CCA Realms

In reply to Kameron Carr
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] arm64: hyperv: kcalloc fails to guarantee 256-byte alignment for rsi_host_call - [Medium] arm64…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] arm64: hyperv: kcalloc fails to guarantee 256-byte alignment for rsi_host_call
- [Medium] arm64: hyperv: missing NULL pointer guard on hv_hostcall_array causes recursive panic --

commit 2c893995afa956ce0fb20a1d090c6e04fba71575
Author: Kameron Carr <[email protected]>

arm64: hyperv: Route hypercalls through RSI host call in CCA Realms

This commit updates the Hyper-V hypercall wrappers to check if the kernel is running in a CCA Realm. If so, it routes the hypercalls through the RSI host call interface using the per-CPU hv_hostcall_array.

Quoted 5 lines
arch/arm64/hyperv/hv_core.c +0 -0
index e33a9e3c366a1..2f6fc1469c54f 100644
@@ -12,11 +12,43 @@

[ ... ]

Quoted 8 lines
arch/arm64/hyperv/hv_core.c +8 -0
+static u64 hv_do_rsi_hypercall(u64 control, u64 input1, u64 input2)
+{
+	struct rsi_host_call *hostcall;
+	unsigned long flags;
+	u64 ret;
+
+	if (!hv_hostcall_array)
+		return HV_STATUS_INVALID_HYPERCALL_INPUT;

arch/arm64/hyperv/hv_core.c line 43

Quoted 10 lines
arch/arm64/hyperv/hv_core.c +10 -0
+
+	local_irq_save(flags);
+	hostcall = &hv_hostcall_array[smp_processor_id()];
+	memset(hostcall, 0, sizeof(*hostcall));
+	hostcall->gprs[0] = HV_FUNC_ID;
+	hostcall->gprs[1] = control;
+	hostcall->gprs[2] = input1;
+	hostcall->gprs[3] = input2;
+
+	if (rsi_host_call(virt_to_phys(hostcall)) == RSI_SUCCESS)

[Severity: High]
Does this physical address satisfy the RMM's 256-byte alignment requirement?

If hv_hostcall_array was allocated with kcalloc() (e.g., in hyperv_init()), the allocation might not guarantee strict 256-byte alignment when SLUB debugging or KASAN is enabled due to redzone shifts. If the resulting address is misaligned, could the RMM reject the SMC host call and return an error that eventually triggers a BUG_ON() and kernel panic?

[ ... ]

Quoted 12 lines
arch/arm64/hyperv/hv_core.c +3 -4
@@ -76,24 +117,44 @@ EXPORT_SYMBOL_GPL(hv_do_fast_hypercall16);
 void hv_set_vpreg(u32 msr, u64 value)
 {
 	struct arm_smccc_res res;
+	struct rsi_host_call *hostcall;
+	unsigned long flags;
+	u64 status;
 
-	arm_smccc_1_1_hvc(HV_FUNC_ID,
-		HVCALL_SET_VP_REGISTERS | HV_HYPERCALL_FAST_BIT |
-			HV_HYPERCALL_REP_COMP_1,
-		HV_PARTITION_ID_SELF,

arch/arm64/hyperv/hv_core.c EXPORT_SYMBOL_GPL(hv_do_fast_hypercall16); · line 127

Quoted 10 lines
arch/arm64/hyperv/hv_core.c +4 -6
-		HV_VP_INDEX_SELF,
-		msr,
-		0,
-		value,
-		0,
-		&res);
+	if (is_realm_world()) {
+		local_irq_save(flags);
+		hostcall = &hv_hostcall_array[smp_processor_id()];
+		memset(hostcall, 0, sizeof(*hostcall));

[Severity: Medium]
Is it safe to access hv_hostcall_array here without a NULL check?

In hv_do_rsi_hypercall() above, there is a check for !hv_hostcall_array. If Hyper-V initialization fails and sets hv_hostcall_array to NULL, but the panic notifier remains registered, a later kernel panic could invoke hyperv_report_panic() which calls hv_set_vpreg(). Without a guard, this memset() could cause a recursive fault and break the crash handler.

[ ... ]

Quoted 8 lines
arch/arm64/hyperv/hv_core.c +3 -0
@@ -108,29 +169,55 @@ void hv_get_vpreg_128(u32 msr, struct hv_get_vp_registers_output *result)
 {
 	struct arm_smccc_1_2_regs args;
 	struct arm_smccc_1_2_regs res;
+	struct rsi_host_call *hostcall;
+	unsigned long flags;
+	u64 status;
 

arch/arm64/hyperv/hv_core.c void hv_get_vpreg_128(u32 msr, struct hv_get_vp_registers_output *result) · line 179

Quoted 10 lines
arch/arm64/hyperv/hv_core.c +4 -6
-	args.a0 = HV_FUNC_ID;
-	args.a1 = HVCALL_GET_VP_REGISTERS | HV_HYPERCALL_FAST_BIT |
-			HV_HYPERCALL_REP_COMP_1;
-	args.a2 = HV_PARTITION_ID_SELF;
-	args.a3 = HV_VP_INDEX_SELF;
-	args.a4 = msr;
+	if (is_realm_world()) {
+		local_irq_save(flags);
+		hostcall = &hv_hostcall_array[smp_processor_id()];
+		memset(hostcall, 0, sizeof(*hostcall));

[Severity: Medium]
Could this also cause a NULL pointer dereference if hv_hostcall_array was freed and set to NULL during an early boot failure?

[ ... ]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
maintainer
#2 lore raw

Re: [PATCH v5 1/6] arm64: rsi: Add RSI host call structure and helper function

In reply to Kameron Carr
Quoted 11 lines · Kameron Carr

Add struct rsi_host_call to arm-smccc-rsi.h, which represents the host call data structure used by the Realm Management Monitor (RMM) for the RSI_HOST_CALL interface. The structure contains a 16-bit immediate field and 31 general-purpose register values, aligned to 256 bytes as required by the CCA RMM specification.

Add rsi_host_call() static inline wrapper in arm-rsi-cmds.h that invokes SMC_RSI_HOST_CALL with the physical address of the host call structure. This will be used by Hyper-V guest code to route hypercalls through the RSI interface when running inside an Arm CCA Realm.

Quoted 5 lines
---
 include/linux/arm-rsi-cmds.h  | 22 ++++++++++++++++++++++
 include/linux/arm-smccc-rsi.h |  7 +++++++

ARM maintainers, I think this needs an ack from you?

Wei

Quoted 54 lines
 2 files changed, 29 insertions(+)
include/linux/arm-rsi-cmds.h +22 -0
index 3f7a6a8..01d292e 100644
@@ -236,4 +236,26 @@ static inline unsigned long rsi_attestation_token_continue(phys_addr_t granule,
 	return res.a0;
 }
 
+/**
+ * rsi_host_call - Make a Host call.
+ * @host_call_struct: IPA of host call structure
+ *
+ * This call will fail if the IPA of the host call structure:
+ * * is not aligned to 256 bytes,
+ * * is not protected / encrypted,
+ * * is RIPAS_EMPTY
+ *
+ * Returns:
+ *  On success, returns RSI_SUCCESS.
+ *  Otherwise, returns an error code.
+ */
+static inline unsigned long rsi_host_call(phys_addr_t host_call_struct)
+{
+	struct arm_smccc_res res;
+
+	arm_smccc_smc(SMC_RSI_HOST_CALL, host_call_struct, 0, 0, 0, 0, 0, 0,
+		      &res);
+	return res.a0;
+}
+
 #endif /* __LINUX_ARM_RSI_CMDS_H_ */
include/linux/arm-smccc-rsi.h +7 -0
index fddb779..4c8530b 100644
@@ -142,6 +142,13 @@ struct realm_config {
 	 */
 } __aligned(0x1000);
 
+struct rsi_host_call {
+	u16 immediate;
+	u8 _padding[6];
+	u64 gprs[31];
+} __aligned(256);
+static_assert(sizeof(struct rsi_host_call) == 256);
+
 #endif /* __ASSEMBLER__ */
 
 /*
Signature · 1 line
2.45.4
#3 lore raw

Re: [PATCH v5 1/6] arm64: rsi: Add RSI host call structure and helper function

Hello ARM maintainers,

Quoted 18 lines · Wei Liu
Quoted 11 lines · Kameron Carr

Add struct rsi_host_call to arm-smccc-rsi.h, which represents the host call data structure used by the Realm Management Monitor (RMM) for the RSI_HOST_CALL interface. The structure contains a 16-bit immediate field and 31 general-purpose register values, aligned to 256 bytes as required by the CCA RMM specification.

Add rsi_host_call() static inline wrapper in arm-rsi-cmds.h that invokes SMC_RSI_HOST_CALL with the physical address of the host call structure. This will be used by Hyper-V guest code to route hypercalls through the RSI interface when running inside an Arm CCA Realm.

Quoted 5 lines
---
 include/linux/arm-rsi-cmds.h  | 22 ++++++++++++++++++++++
 include/linux/arm-smccc-rsi.h |  7 +++++++
Quoted 3 lines

ARM maintainers, I think this needs an ack from you?

Wei

Do you have any issues with this patch?

Signature · 2 lines
Regards,
Kameron
maintainer
#6 lore raw

Re: [PATCH v5 2/6] firmware: smccc: Detect hypervisor via RSI host call in CCA Realms

In reply to Kameron Carr

+ Suzuki

Quoted 69 lines · Kameron Carr

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 <linux/arm-rsi-cmds.h> does not build on 32-bit ARM.

For non-Realm environments, the existing arm_smccc_1_1_invoke() path is unchanged.

---
 drivers/firmware/smccc/smccc.c | 41 +++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)
drivers/firmware/smccc/smccc.c +32 -0
index afc2e4d..7e77170 100644
@@ -14,6 +14,12 @@
 
 #include <asm/archrandom.h>
 
+#ifdef CONFIG_ARM64
+#include <linux/arm-rsi-cmds.h>
+#include <linux/cleanup.h>
+#include <linux/spinlock.h>
+#endif
+
 static u32 smccc_version = ARM_SMCCC_VERSION_1_0;
 static enum arm_smccc_conduit smccc_conduit = SMCCC_CONDUIT_NONE;
 
@@ -69,12 +75,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 void 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) {
+		res->a0 = SMCCC_RET_NOT_SUPPORTED;
+		return;
+	}
+
+	res->a0 = uuid_hc.gprs[0];
+	res->a1 = uuid_hc.gprs[1];
+	res->a2 = uuid_hc.gprs[2];
+	res->a3 = uuid_hc.gprs[3];
+}
+#endif
+
 bool arm_smccc_hypervisor_has_uuid(const uuid_t *hyp_uuid)
 {
 	struct arm_smccc_res res = {};

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

Quoted 10 lines
drivers/firmware/smccc/smccc.c +7 -1
 	uuid_t uuid;
 
-	arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID, &res);
+#ifdef CONFIG_ARM64
+	if (is_realm_world())
+		arm_smccc_realm_get_hypervisor_uuid(&res);
+	else
+#endif
+		arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID,
+				     &res);

Is this meant to be generic? I'm not sure the trick to pass ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID in gprs[0] and forward it to the host is a documented ABI. I think it even confuses other realm guests that don't expect this (e.g. kvm_init_hyp_services()).

I thought realms should stick to the RSI interface and not try to guess the host hypervisor. But if you do need this, a better fit would be in hyperv_detect_via_smccc() (if realms don't boot with ACPI).

I'll leave it to Sudeep or Suzuki to comment further.

Signature · 1 line
Catalin
maintainer Reviewed-by on v5 1/6
#4 lore raw

Re: [PATCH v5 1/6] arm64: rsi: Add RSI host call structure and helper function

In reply to Kameron Carr
Quoted 6 lines · Kameron Carr

Add struct rsi_host_call to arm-smccc-rsi.h, which represents the host call data structure used by the Realm Management Monitor (RMM) for the RSI_HOST_CALL interface. The structure contains a 16-bit immediate field and 31 general-purpose register values, aligned to 256 bytes as required by the CCA RMM specification.

Quoted 7 lines

Add rsi_host_call() static inline wrapper in arm-rsi-cmds.h that invokes SMC_RSI_HOST_CALL with the physical address of the host call structure. This will be used by Hyper-V guest code to route hypercalls through the RSI interface when running inside an Arm CCA Realm.

This looks fine.

#7 lore raw

Re: [PATCH v5 2/6] firmware: smccc: Detect hypervisor via RSI host call in CCA Realms

In reply to Catalin Marinas
Quoted 46 lines · Catalin Marinas
Quoted 29 lines · Kameron Carr
drivers/firmware/smccc/smccc.c +26 -0
+#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 void 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) {
+		res->a0 = SMCCC_RET_NOT_SUPPORTED;
+		return;
+	}
+
+	res->a0 = uuid_hc.gprs[0];
+	res->a1 = uuid_hc.gprs[1];
+	res->a2 = uuid_hc.gprs[2];
+	res->a3 = uuid_hc.gprs[3];
+}
+#endif
+
 bool arm_smccc_hypervisor_has_uuid(const uuid_t *hyp_uuid)
 {
 	struct arm_smccc_res res = {};

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

Quoted 10 lines
drivers/firmware/smccc/smccc.c +7 -1
 	uuid_t uuid;
 
-	arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID, &res);
+#ifdef CONFIG_ARM64
+	if (is_realm_world())
+		arm_smccc_realm_get_hypervisor_uuid(&res);
+	else
+#endif
+		arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID,
+				     &res);

Is this meant to be generic? I'm not sure the trick to pass ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID in gprs[0] and forward it to the host is a documented ABI. I think it even confuses other realm guests that don't expect this (e.g. kvm_init_hyp_services()).

Quoted 5 lines

I thought realms should stick to the RSI interface and not try to guess the host hypervisor. But if you do need this, a better fit would be in hyperv_detect_via_smccc() (if realms don't boot with ACPI).

I'll leave it to Sudeep or Suzuki to comment further.

I moved this code to a Hyper-V specific location as you suggested.

Let me know if you have any other concerns.

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

Signature · 2 lines
Regards,
Kameron
maintainer
#8 lore raw

RE: [EXTERNAL] Re: [PATCH v5 2/6] firmware: smccc: Detect hypervisor via RSI host call in CCA Realms

In reply to Catalin Marinas
Quoted 41 lines

From: Catalin Marinas <[email protected]>
Sent: Thursday, October 29, 2026 3:54 PM
...
+ Suzuki
...

Quoted 1 line

+static void arm_smccc_realm_get_hypervisor_uuid(struct arm_smccc_res

*res)

Quoted 14 lines
drivers/firmware/smccc/smccc.c +14 -0
+{
+	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) {
+		res->a0 = SMCCC_RET_NOT_SUPPORTED;
+		return;
+	}
+
+	res->a0 = uuid_hc.gprs[0];
+	res->a1 = uuid_hc.gprs[1];
+	res->a2 = uuid_hc.gprs[2];

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

Quoted 10 lines
drivers/firmware/smccc/smccc.c +4 -1
+	res->a3 = uuid_hc.gprs[3];
+}
+#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);

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

Quoted 6 lines
drivers/firmware/smccc/smccc.c +6 -0
+#ifdef CONFIG_ARM64
+	if (is_realm_world())
+		arm_smccc_realm_get_hypervisor_uuid(&res);
+	else
+#endif
+

arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC
_ID,

Quoted 6 lines

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

Quoted 1 line
drivers/firmware/smccc/smccc.c +1 -0
+				     &res);

Is this meant to be generic? I'm not sure the trick to pass ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID in gprs[0] and forward it to the host is a documented ABI. I think it even confuses other realm guests that don't expect this (e.g. kvm_init_hyp_services()).

Hi Catalin,
Regarding the concern about passing ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID In gprs and forwarding it to the host via an RSI Host Call: if I read the code correctly, this pattern actually aligns seamlessly with the current KVM host-side implementation for ARM CCA (e.g., in the v16 patchset [1]).

In arch/arm64/kvm/rmi-exit.c, when a Realm guest triggers an RMI_EXIT_HOST_CALL, KVM intercepts it and invokes rec_exit_hvc():

case RMI_EXIT_HOST_CALL:

	rec_exit_hvc(vcpu);
	kvm_make_request(KVM_REQ_RMI, vcpu);
	return ARM_EXCEPTION_TRAP;

Inside rec_exit_hvc(), KVM copies the GPRs from the rec run structure into the vCPU registers and explicitly emulates a standard HVC exception by populating esr_el2:

static void rec_exit_hvc(struct kvm_vcpu *vcpu)

{
        struct realm_rec *rec = &vcpu->arch.rec;
        int i;

        for (i = 0; i < REC_RUN_GPRS; i++)
                vcpu_set_reg(vcpu, i, rec->run->exit.gprs[i]);

        vcpu->arch.fault.esr_el2 = (ESR_ELx_EC_HVC64 << ESR_ELx_EC_SHIFT) |
                                     ESR_ELx_IL;
} 

After doing so, it returns ARM_EXCEPTION_TRAP, causing KVM's generic exception handling loop (kvm_arch_vcpu_ioctl_run() -> handle_exit()) to route it straight into the standard handle_hvc() -> kvm_smccc_call_handler() path.

Because KVM deliberately unpacks the RSI Host Call structure and pushes it down the traditional non-CVM HVC servicing pipeline, the guest passing standard SMCCC Function IDs inside the gprs array of an RSI Host Call is exactly how the host expects to handle hypervisor services. It shouldn't break or confuse other standard realm implementations since this exact emulation block translates the RSI exception back into a generic HVC abstraction for the hypervisor layer.

Quoted 8 lines

I thought realms should stick to the RSI interface and not try to guess the host hypervisor. But if you do need this, a better fit would be in hyperv_detect_via_smccc() (if realms don't boot with ACPI).

I'll leave it to Sudeep or Suzuki to comment further.

--
Catalin

As I described above, this patch from Kameron should work fine.

BTW, as Kameron mentioned in another reply, he better organized the code by moving the code in this patch into arch/arm64/hyperv/mshyperv.c: hyperv_detect_via_smccc(). (technically, IMO this change is unnecessary)

Thanks,
Dexuan

[1] https://gitlab.arm.com/linux-arm/linux-cca/-/tree/cca-host/v16
[2] https://lore.kernel.org/all/[email protected]/

#9 lore raw

Re: [EXTERNAL] Re: [PATCH v5 2/6] firmware: smccc: Detect hypervisor via RSI host call in CCA Realms

Hi

Quoted 41 lines · Dexuan Cui
Quoted 41 lines

From: Catalin Marinas <[email protected]>
Sent: Thursday, October 29, 2026 3:54 PM
...
+ Suzuki
...

Quoted 1 line

+static void arm_smccc_realm_get_hypervisor_uuid(struct arm_smccc_res

*res)

Quoted 14 lines
drivers/firmware/smccc/smccc.c +14 -0
+{
+	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) {
+		res->a0 = SMCCC_RET_NOT_SUPPORTED;
+		return;
+	}
+
+	res->a0 = uuid_hc.gprs[0];
+	res->a1 = uuid_hc.gprs[1];
+	res->a2 = uuid_hc.gprs[2];

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

Quoted 10 lines
drivers/firmware/smccc/smccc.c +4 -1
+	res->a3 = uuid_hc.gprs[3];
+}
+#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);

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

Quoted 6 lines
drivers/firmware/smccc/smccc.c +6 -0
+#ifdef CONFIG_ARM64
+	if (is_realm_world())
+		arm_smccc_realm_get_hypervisor_uuid(&res);
+	else
+#endif
+

arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC
_ID,

Quoted 6 lines
Quoted 6 lines

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

Quoted 1 line
drivers/firmware/smccc/smccc.c +1 -0
+				     &res);

Is this meant to be generic? I'm not sure the trick to pass ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID in gprs[0] and forward it to the host is a documented ABI. I think it even confuses other realm guests that don't expect this (e.g. kvm_init_hyp_services()).

Yes, this is how a Realm can talk to the Host hypervisor, i.e, RSI_HOST_CALL. In simpler terms, HVC is routed to Realm world for Realms (e.g., a Paravisor running in Realm world Plane-0).
A Realm must always use RSI_HOST_CALL to reach the non-secure
hypervisor. RSI_HOST_CALL expects the arguments to be passed
in a "memory" area to preserve forward compatibility with
the SMCCC standards to allow for using the full argument/result
list.

The RMM does the job of copying the arguments from the Realm memory to the rec_exit.gprs for consumption by the Host. The host can then return the results in rec_entr.gprs, which then gets copied over to the Realm memory area.

Quoted 50 lines

Hi Catalin,
Regarding the concern about passing ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID In gprs and forwarding it to the host via an RSI Host Call: if I read the code correctly, this pattern actually aligns seamlessly with the current KVM host-side implementation for ARM CCA (e.g., in the v16 patchset [1]).

In arch/arm64/kvm/rmi-exit.c, when a Realm guest triggers an RMI_EXIT_HOST_CALL, KVM intercepts it and invokes rec_exit_hvc():

case RMI_EXIT_HOST_CALL:

	rec_exit_hvc(vcpu);
	kvm_make_request(KVM_REQ_RMI, vcpu);
	return ARM_EXCEPTION_TRAP;

Inside rec_exit_hvc(), KVM copies the GPRs from the rec run structure into the vCPU registers and explicitly emulates a standard HVC exception by populating esr_el2:

static void rec_exit_hvc(struct kvm_vcpu *vcpu)

{
         struct realm_rec *rec = &vcpu->arch.rec;
         int i;

         for (i = 0; i < REC_RUN_GPRS; i++)
                 vcpu_set_reg(vcpu, i, rec->run->exit.gprs[i]);

         vcpu->arch.fault.esr_el2 = (ESR_ELx_EC_HVC64 << ESR_ELx_EC_SHIFT) |
                                      ESR_ELx_IL;
}

After doing so, it returns ARM_EXCEPTION_TRAP, causing KVM's generic exception handling loop (kvm_arch_vcpu_ioctl_run() -> handle_exit()) to route it straight into the standard handle_hvc() -> kvm_smccc_call_handler() path.

Because KVM deliberately unpacks the RSI Host Call structure and pushes it down the traditional non-CVM HVC servicing pipeline, the guest passing standard SMCCC Function IDs inside the gprs array of an RSI Host Call is exactly how the host expects to handle hypervisor services. It shouldn't break or confuse other standard realm implementations since this exact emulation block translates the RSI exception back into a generic HVC abstraction for the hypervisor layer.

Quoted 6 lines

I thought realms should stick to the RSI interface and not try to guess the host hypervisor. But if you do need this, a better fit would be in hyperv_detect_via_smccc() (if realms don't boot with ACPI).

I'll leave it to Sudeep or Suzuki to comment further.

Quoted 8 lines
Quoted 2 lines

--
Catalin

As I described above, this patch from Kameron should work fine.

BTW, as Kameron mentioned in another reply, he better organized the code by moving the code in this patch into arch/arm64/hyperv/mshyperv.c: hyperv_detect_via_smccc().

Any Realm specific stuff must be handled accordingly in the "enlightened" path, not in the common code like this patch.

Cheers
Suzuki

Quoted 7 lines

(technically, IMO this change is unnecessary)

Thanks,
Dexuan

[1] https://gitlab.arm.com/linux-arm/linux-cca/-/tree/cca-host/v16
[2] https://lore.kernel.org/all/[email protected]/

maintainer
#10 lore raw

Re: [EXTERNAL] Re: [PATCH v5 2/6] firmware: smccc: Detect hypervisor via RSI host call in CCA Realms

In reply to Dexuan Cui

Hi Dexuan,

Quoted 19 lines · Dexuan Cui
Quoted 14 lines

From: Catalin Marinas <[email protected]>
Sent: Thursday, October 29, 2026 3:54 PM

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

Quoted 7 lines
drivers/firmware/smccc/smccc.c +7 -0
+#ifdef CONFIG_ARM64
+	if (is_realm_world())
+		arm_smccc_realm_get_hypervisor_uuid(&res);
+	else
+#endif
+ 	arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID,
+				     &res);

Is this meant to be generic? I'm not sure the trick to pass ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID in gprs[0] and forward it to the host is a documented ABI. I think it even confuses other realm guests that don't expect this (e.g. kvm_init_hyp_services()).

Regarding the concern about passing ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID In gprs and forwarding it to the host via an RSI Host Call: if I read the code correctly, this pattern actually aligns seamlessly with the current KVM host-side implementation for ARM CCA (e.g., in the v16 patchset [1]).

[...]

Quoted 7 lines

Because KVM deliberately unpacks the RSI Host Call structure and pushes it down the traditional non-CVM HVC servicing pipeline, the guest passing standard SMCCC Function IDs inside the gprs array of an RSI Host Call is exactly how the host expects to handle hypervisor services. It shouldn't break or confuse other standard realm implementations since this exact emulation block translates the RSI exception back into a generic HVC abstraction for the hypervisor layer.

My point is not the RSI host call itself to query the UUID but what the Realm does afterwards. kvm_init_hyp_services() gets a positive answer for the KVM UUID and continues with an SMCCC 1.1 invocation to query the supported KVM features. The latter is not an RSI host call but an ordinary SMC call, to which the RMM responds with -1 in res.a0 (all lower 32 bits set). So we end up treating KVM hyp services as available in a Realm but their calls still use the SMC conduit and are rejected by the RMM.

Supporting such hyp services (e.g. KVM PTP) in a Realm would need a separate hypervisor-service conduit using RSI_HOST_CALL. Both discovery and subsequent calls would use the same transport without adding Realm-specific checks to each caller. Not sure how feasible this is.

Signature · 1 line
Catalin
maintainer
#11 lore raw

RE: [EXTERNAL] Re: [PATCH v5 2/6] firmware: smccc: Detect hypervisor via RSI host call in CCA Realms

Quoted 6 lines

From: Catalin Marinas <[email protected]>
Sent: Monday, November 2, 2026 3:58 AM
To: Dexuan Cui <[email protected]>
...
My point is not the RSI host call itself to query the UUID but what the Realm does afterwards. kvm_init_hyp_services() gets a positive answer

Quoted 8 lines

for the KVM UUID and continues with an SMCCC 1.1 invocation to query the supported KVM features. The latter is not an RSI host call but an ordinary SMC call, to which the RMM responds with -1 in res.a0 (all lower 32 bits set). So we end up treating KVM hyp services as available in a Realm but their calls still use the SMC conduit and are rejected by the RMM.
...
Catalin

Thanks for the clarification! Now I understood this patch is incorrect for a realm on KVM, and v6 is correct.

Thanks,
Dexuan