Skip to contentSkip to conversation

arm64: hyperv: Add Realm support for Hyper-V

PATCH Superseded Kameron Carr 3 participants 17 messages Jun 25 – Jul 23

Subsystems (5)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 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. See my RFC patch [1]. I will implement the accompanying netvsc changes based on the feedback I receive on that patch.

This patch series was tested by booting a Realm on Cobalt 200 running Windows. I decreased the buffer size and used kzalloc() in netvsc_init_buf() in my testing as a workaround for the issue mentioned above.

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 KSAN tags before passing address to set_memory_decrypted()
since __is_lm_address() does pointer arithmetic.
Patch 5: Add a helper function to reduce repetition
Check for NULL before indexing into host call array

[1] https://lore.kernel.org/all/[email protected]/
[2] 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      |  42 +++++++-
 arch/arm64/include/asm/mshyperv.h |   4 +
 arch/arm64/include/asm/rsi_cmds.h |  22 +++++
 arch/arm64/include/asm/rsi_smc.h  |   7 ++
 drivers/firmware/smccc/smccc.c    |  41 +++++++-
 drivers/hv/hv_common.c            |  17 +++-
 include/asm-generic/mshyperv.h    |   1 +
 8 files changed, 249 insertions(+), 40 deletions(-)

base-commit: a4ffc59238be84dd1c26bf1c001543e832674fc6

Signature · 1 line
2.45.4
#1 lore raw

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

Add struct rsi_host_call to rsi_smc.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 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.

---
 arch/arm64/include/asm/rsi_cmds.h | 22 ++++++++++++++++++++++
 arch/arm64/include/asm/rsi_smc.h  |  7 +++++++
 2 files changed, 29 insertions(+)
arch/arm64/include/asm/rsi_cmds.h +22 -0
index 2c8763876dfb7..9daf8008e5da2 100644
@@ -88,6 +88,28 @@ static inline long rsi_set_addr_range_state(phys_addr_t start,
 	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;
+}
+
 /**
  * rsi_attestation_token_init - Initialise the operation to retrieve an
  * attestation token.
arch/arm64/include/asm/rsi_smc.h +7 -0
index e19253f96c940..9cc57b5be0c02 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
#2 lore raw

PATCH v2 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 <asm/rsi.h> does not exist 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 bdee057db2fd3..a876b7aa2dc99 100644
@@ -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 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
#3 lore raw

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

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Initialization order bug causes `arm_smccc_hypervisor_has_uuid()` to incorrectly fall back to…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Initialization order bug causes arm_smccc_hypervisor_has_uuid() to incorrectly fall back to standard SMC during early boot in a CCA Realm. --

commit 8e27a5d40fac36e0edcb6814624362e892694ac4
Author: Kameron Carr <[email protected]>

firmware: smccc: Detect hypervisor via RSI host call in CCA Realms

This commit modifies arm_smccc_hypervisor_has_uuid() to check is_realm_world() and use an RSI host call to query the hypervisor UUID inside a Realm. It adds a file-static RSI host call buffer serialized by a spinlock for ARM64.

Quoted 4 lines
drivers/firmware/smccc/smccc.c +0 -0
index bdee057db2fd3..a876b7aa2dc99 100644

[ ... ]

Quoted 4 lines
drivers/firmware/smccc/smccc.c +0 -0
@@ -67,12 +73,45 @@ s32 arm_smccc_get_soc_id_revision(void)
 }
 EXPORT_SYMBOL_GPL(arm_smccc_get_soc_id_revision);
 

[ ... ]

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

Quoted 11 lines

bool arm_smccc_hypervisor_has_uuid(const uuid_t *hyp_uuid) {

drivers/firmware/smccc/smccc.c +5 -1
 	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

[Severity: Medium]
Will this check evaluate to false during early boot, causing the detection to incorrectly fall back to the standard SMC conduit?

Looking at setup_arch(), psci_dt_init() executes before arm64_rsi_init() is called to set up the rsi_present static key used by is_realm_world():

setup_arch() {
    ...
    if (acpi_disabled)
        psci_dt_init();
    else
        psci_acpi_init();

    arm64_rsi_init();
    ...
}

Because psci_dt_init() calls psci_probe(), which calls kvm_init_hyp_services(), this eventually reaches arm_smccc_hypervisor_has_uuid() before the static key is initialized.

Does this sequence cause a silent failure to detect the KVM hypervisor inside an Arm CCA Realm?

Quoted 5 lines
drivers/firmware/smccc/smccc.c +3 -0
+		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
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#4 lore raw

PATCH v2 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      | 32 ++++++++++++++++++++++++++++++-
 arch/arm64/include/asm/mshyperv.h |  4 ++++
 2 files changed, 35 insertions(+), 1 deletion(-)
arch/arm64/hyperv/mshyperv.c +31 -1
index 4fdc26ade1d74..7d536d7fb557e 100644
@@ -15,10 +15,15 @@
 #include <linux/errno.h>
 #include <linux/version.h>
 #include <linux/cpuhotplug.h>
+#include <linux/slab.h>
 #include <asm/mshyperv.h>
+#include <asm/rsi.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,
@@ -60,6 +65,12 @@ static bool __init hyperv_detect_via_acpi(void)
 
 #endif
 
+static void hv_hostcall_free(void)
+{
+	kfree(hv_hostcall_array);
+	hv_hostcall_array = NULL;
+}
+
 static bool __init hyperv_detect_via_smccc(void)
 {
 	uuid_t hyperv_uuid = UUID_INIT(
@@ -85,6 +96,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,12 +131,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();
+		hv_hostcall_free();
 		return ret;
 	}
 
@@ -125,6 +151,10 @@ static int __init hyperv_init(void)
 
 	hyperv_initialized = true;
 	return 0;
+
+free_hostcall_mem:
+	hv_hostcall_free();
+	return ret;
 }
 
 early_initcall(hyperv_init);
arch/arm64/include/asm/mshyperv.h +4 -0
index b721d3134ab66..c207a3f79b99b 100644
@@ -63,4 +63,8 @@ static inline u64 hv_get_non_nested_msr(unsigned int reg)
 
 #include <asm-generic/mshyperv.h>
 
+/* Per-CPU-indexed RSI host call structures for CCA Realms */
+struct rsi_host_call;
+extern struct rsi_host_call *hv_hostcall_array;
+
 #endif
Signature · 1 line
2.45.4
#5 lore raw

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

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] The `hv_hostcall_array` is allocated with `kcalloc()`, which does not guarantee the strict…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] The hv_hostcall_array is allocated with kcalloc(), which does not guarantee the strict 256-byte alignment required by the RMM for SMC_RSI_HOST_CALL.
- [High] If hyperv_init() fails, hv_hostcall_array is freed but panic notifiers are left registered, causing a fatal NULL pointer dereference during a subsequent panic.
- [Low] The early boot initialization function hyperv_init() contains unnecessary memory allocation failure handling and cleanup logic for hv_hostcall_array. --

commit 906cd2b30d2ff5884265fe39d28d07e982c9f874
Author: Kameron Carr <[email protected]>

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

This commit adds a per-CPU rsi_host_call array allocation for Arm CCA Realms. It routes Hyper-V hypercalls through the RSI_HOST_CALL interface instead of HVC.

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

[ ... ]

Quoted 4 lines
arch/arm64/hyperv/mshyperv.c +0 -0
@@ -85,6 +96,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 108

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]
The RMM requires the IPA of the host call structure to be strictly 256-byte aligned for SMC_RSI_HOST_CALL. Since standard slab allocators like kcalloc() do not guarantee alignment beyond ARCH_KMALLOC_MINALIGN, could this result in an unaligned physical address being passed to rsi_host_call() in hv_set_vpreg()?

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

Quoted 2 lines
arch/arm64/hyperv/mshyperv.c +2 -0
+		if (!hv_hostcall_array)
+			return -ENOMEM;

[Severity: Low]
This isn't a bug, but since hyperv_init() is an early_initcall executed early in the boot process, is it necessary to handle this allocation failure gracefully? Early boot memory allocations typically do not need complex failure paths, as a failure at this stage implies the system cannot boot.

Quoted 3 lines
arch/arm64/hyperv/mshyperv.c +2 -0
+	}
+
 	/* Setup the guest ID */

[ ... ]

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

Quoted 8 lines
arch/arm64/hyperv/mshyperv.c +4 -0
@@ -125,6 +151,10 @@ static int __init hyperv_init(void)
 
 	hyperv_initialized = true;
 	return 0;
+
+free_hostcall_mem:
+	hv_hostcall_free();
+	return ret;

[Severity: High]
If hyperv_init() fails here, hv_hostcall_array is freed and set to NULL. Since the panic notifiers registered earlier in hv_common_init() are not unregistered on this error path, will this cause a newly introduced NULL pointer dereference during a later panic?

When the leaked notifier invokes hyperv_report_panic(), it calls hv_set_vpreg(), which unconditionally accesses the array:

hv_set_vpreg() {
    ...
    hostcall = &hv_hostcall_array[smp_processor_id()];
    memset(hostcall, 0, sizeof(*hostcall));
    ...
}
Quoted 1 line
arch/arm64/hyperv/mshyperv.c +0 -0
 }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#6 lore raw

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

In reply to Kameron Carr

From: Kameron Carr <[email protected]> Sent: Thursday, June 25, 2026 10:35 AM

Quoted 80 lines

To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: [PATCH v2 3/6] arm64: hyperv: Add per-CPU RSI host call infrastructure for CCA Realms

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      | 32 ++++++++++++++++++++++++++++++-
 arch/arm64/include/asm/mshyperv.h |  4 ++++
 2 files changed, 35 insertions(+), 1 deletion(-)
arch/arm64/hyperv/mshyperv.c +25 -0
index 4fdc26ade1d74..7d536d7fb557e 100644
@@ -15,10 +15,15 @@
 #include <linux/errno.h>
 #include <linux/version.h>
 #include <linux/cpuhotplug.h>
+#include <linux/slab.h>
 #include <asm/mshyperv.h>
+#include <asm/rsi.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,
@@ -60,6 +65,12 @@ static bool __init hyperv_detect_via_acpi(void)
 
 #endif
 
+static void hv_hostcall_free(void)
+{
+	kfree(hv_hostcall_array);
+	hv_hostcall_array = NULL;
+}
+
 static bool __init hyperv_detect_via_smccc(void)
 {
 	uuid_t hyperv_uuid = UUID_INIT(
@@ -85,6 +96,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,12 +131,13 @@ static int __init hyperv_init(void)
 
 	ret = hv_common_init();

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

Quoted 10 lines
arch/arm64/hyperv/mshyperv.c +2 -1
 	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();
+		hv_hostcall_free();
 		return ret;

Let me suggest a small additional simplification. For this error path, call hv_common_free() as you have now, but then do "goto free_hostcall_mem". At the free_hostcall_mem label, do

	kfree(hv_hostcall_array);
	hv_hostcall_array = NULL;

directly inline, and eliminate the hv_hostcall_free() helper function. Saves about 5 lines of code overall and I think is a bit simpler.

Quoted 18 lines
arch/arm64/hyperv/mshyperv.c +4 -0
 	}
 
@@ -125,6 +151,10 @@ static int __init hyperv_init(void)
 
 	hyperv_initialized = true;
 	return 0;
+
+free_hostcall_mem:
+	hv_hostcall_free();
+	return ret;
 }
 
 early_initcall(hyperv_init);
arch/arm64/include/asm/mshyperv.h +0 -0
index b721d3134ab66..c207a3f79b99b 100644

arch/arm64/include/asm/mshyperv.h static inline u64 hv_get_non_nested_msr(unsigned int reg) · line 69

Quoted 7 lines
arch/arm64/include/asm/mshyperv.h +4 -0
@@ -63,4 +63,8 @@ static inline u64 hv_get_non_nested_msr(unsigned int reg)
 
 #include <asm-generic/mshyperv.h>
 
+/* Per-CPU-indexed RSI host call structures for CCA Realms */
+struct rsi_host_call;
+extern struct rsi_host_call *hv_hostcall_array;
+

The intent is that the #include of asm-generic/mshyperv.h should be last in the arch-specific version of mshyperv.h. If there's a need to go after the #include, that's a red flag to check if some restructuring of the definitions would be appropriate.

Unless I'm missing something, I think these new definitions can go above the #include.

Michael

Quoted 4 lines
arch/arm64/include/asm/mshyperv.h +0 -1
 #endif
--

2.45.4

#7 lore raw

PATCH v2 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.

We need to round up the memory allocated for the input/output pages to the nearest PAGE_SIZE, since set_memory_decrypted() requires the size to be a multiple of PAGE_SIZE. This only has an effect on ARM VMs that are using PAGE_SIZE larger than 4K.

is_realm_world() is only declared in arch/arm64/include/asm/rsi.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 7d536d7fb557e..8e8148b723d9c 100644
@@ -164,3 +164,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 6b67ac6167891..17048a0a18729 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)kasan_reset_tag(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 bf601d67cecb9..1fa79abce743c 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
#8 lore raw

Re: [PATCH v2 4/6] Drivers: hv: Mark shared memory as decrypted for CCA Realms

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Using kmalloc() to allocate hypercall input/output pages violates the strict page-alignment requirements of set_memory_decrypted(), causing silent failures on ARM64 and exposing slab metadata to the untrusted host on x86. --

commit 02dd1b4271844f489855c82e06efdec7e95897e3
Author: Kameron Carr <[email protected]>

Drivers: hv: Mark shared memory as decrypted for CCA Realms

This commit extends the confidential VM shared memory decryption handling for hypercall input/output pages to support Arm CCA Realm guests. It also updates the memory allocation to round up to the nearest page size to satisfy decryption requirements.

Quoted 4 lines
drivers/hv/hv_common.c +0 -0
index 6b67ac6167891..17048a0a18729 100644

[ ... ]

Quoted 10 lines
drivers/hv/hv_common.c +1 -1
@@ -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;
 

drivers/hv/hv_common.c int hv_common_cpu_init(unsigned int cpu) · line 506

Quoted 9 lines
drivers/hv/hv_common.c +4 -2
@@ -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)kasan_reset_tag(mem),
+				alloc_size >> PAGE_SHIFT);

[Severity: High]
This is a pre-existing issue, but does using kmalloc() here guarantee the required page alignment for set_memory_decrypted()?

When slub debugging (like redzoning) is enabled, kmalloc() can return an unaligned address due to prepended metadata.

On arm64, set_memory_decrypted() requires a page-aligned address. If given an unaligned address, it warns and returns 0 without decrypting. This leaves the hypercall pages encrypted, which breaks guest-hypervisor communication for CCA Realms.

On x86, set_memory_decrypted() masks the address to the page boundary. Because this memory is from a slab cache, decrypting the entire underlying physical page could expose other unrelated kernel slab objects on the same page to the untrusted hypervisor.

Quoted 8 lines
drivers/hv/hv_common.c +1 -1
 			if (ret) {
 				/* It may be unsafe to free 'mem' */
 				return ret;
 			}
 
-			memset(mem, 0x00, pgcount * HV_HYP_PAGE_SIZE);
+			memset(mem, 0x00, alloc_size);
 		}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#9 lore raw

RE: [PATCH v2 4/6] Drivers: hv: Mark shared memory as decrypted for CCA Realms

In reply to Kameron Carr

From: Kameron Carr <[email protected]> Sent: Thursday, June 25, 2026 10:35 AM

Quoted 11 lines

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.

We need to round up the memory allocated for the input/output pages to the nearest PAGE_SIZE, since set_memory_decrypted() requires the size to be a multiple of PAGE_SIZE. This only has an effect on ARM VMs that are using PAGE_SIZE larger than 4K.

I think this change resulted from a Sashiko comment. My understanding is that the ARM CCA architecture only supports CCA guests with 4 KiB page size. Is that still the case, or has that restriction been lifted in a later version of the architecture? I'm in favor of handling the larger page sizes, if only for future proofing. But I wondered whether your intent is to always support

Quoted 1 line

4 KiB page sizes even if CCA doesn't support them now. Another way to

put it: In reviewing code, should I flag issues related to page sizes > 4 KiB?

Quoted 51 lines

is_realm_world() is only declared in arch/arm64/include/asm/rsi.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 7d536d7fb557e..8e8148b723d9c 100644
@@ -164,3 +164,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 +2 -1
index 6b67ac6167891..17048a0a18729 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;
 

drivers/hv/hv_common.c int hv_common_cpu_init(unsigned int cpu) · line 506

Quoted 9 lines
drivers/hv/hv_common.c +4 -2
@@ -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)kasan_reset_tag(mem),
+				alloc_size >> PAGE_SHIFT);

I don't know enough about KASAN or the tag situation on ARM64 to comment on this change. But this same sequence of allocating memory and then decrypting it occurs in other places in Hyper-V code. It seems like those places would also need the same kasan_reset_tag() call.

Michael

Quoted 38 lines
drivers/hv/hv_common.c +7 -1
 			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 -1
index bf601d67cecb9..1fa79abce743c 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),
--

2.45.4

#10 lore raw

RE: [PATCH v2 4/6] Drivers: hv: Mark shared memory as decrypted for CCA Realms

Quoted 10 lines · Michael Kelley

From: Kameron Carr <[email protected]> Sent: Thursday, June 25, 2026 10:35 AM

Quoted 4 lines

We need to round up the memory allocated for the input/output pages to the nearest PAGE_SIZE, since set_memory_decrypted() requires the size to be a multiple of PAGE_SIZE. This only has an effect on ARM VMs that are using PAGE_SIZE larger than 4K.

I think this change resulted from a Sashiko comment. My understanding is that the ARM CCA architecture only supports CCA guests with 4 KiB page size. Is that still the case, or has that restriction been lifted in a

later version

Quoted 1 line

of the architecture? I'm in favor of handling the larger page sizes, if

only for

Quoted 3 lines

future proofing. But I wondered whether your intent is to always support

Quoted 1 line

4 KiB page sizes even if CCA doesn't support them now. Another way to

put it: In reviewing code, should I flag issues related to page sizes > 4

KiB?

I think you might be right. I'm looking at RMM spec 2.0 beta 2, and the RMI can have granule size 4KB, 16KB, 64KB, but the RSI is restricted to granule size
4KB.

I'm open to suggestion on best way to move forward.

Quoted 11 lines

drivers/hv/hv_common.c int hv_common_cpu_init(unsigned int cpu) · line 503

Quoted 6 lines
drivers/hv/hv_common.c +0 -2
@@ -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);

drivers/hv/hv_common.c int hv_common_cpu_init(unsigned int cpu)

Quoted 3 lines
drivers/hv/hv_common.c +3 -0
+		    (hv_isolation_type_snp() || hv_isolation_type_tdx() ||
+		     hv_isolation_type_cca())) {
+			ret = set_memory_decrypted((unsigned

long)kasan_reset_tag(mem),

Quoted 7 lines

drivers/hv/hv_common.c int hv_common_cpu_init(unsigned int cpu) · line 506

Quoted 1 line
drivers/hv/hv_common.c +1 -0
+				alloc_size >> PAGE_SHIFT);

I don't know enough about KASAN or the tag situation on ARM64 to comment on this change. But this same sequence of allocating memory and then decrypting it occurs in other places in Hyper-V code. It seems like those places would also need the same kasan_reset_tag() call.

I'm not sure of the exact behavior of PAGE_END when there are KASAN tags, but it looks like tags could mess with the address comparison.

I do see that __virt_to_phys_nodebug() and virt_addr_valid() in arch/arm64/include/asm/memory.h both reset tags before calling __is_lm_address().

If there are many calls that follow this pattern, it may be better to add the tag reset in __set_memory_enc_dec().

I can undo this change.

Regards,
Kameron

#11 lore raw

RE: [PATCH v2 4/6] Drivers: hv: Mark shared memory as decrypted for CCA Realms

From: Kameron Carr <[email protected]> Sent: Friday, June 26, 2026 4:09 AM

Quoted 14 lines · Michael Kelley
Quoted 12 lines

From: Kameron Carr <[email protected]> Sent: Thursday, June 25, 2026 10:35 AM

Quoted 4 lines

We need to round up the memory allocated for the input/output pages to the nearest PAGE_SIZE, since set_memory_decrypted() requires the size to be a multiple of PAGE_SIZE. This only has an effect on ARM VMs that are using PAGE_SIZE larger than 4K.

I think this change resulted from a Sashiko comment. My understanding is that the ARM CCA architecture only supports CCA guests with 4 KiB page size. Is that still the case, or has that restriction been lifted in a later version of the architecture? I'm in favor of handling the larger page sizes, if only for future proofing. But I wondered whether your intent is to always support

Quoted 8 lines
Quoted 2 lines
Quoted 1 line

4 KiB page sizes even if CCA doesn't support them now. Another way to

put it: In reviewing code, should I flag issues related to page sizes > 4 KiB?

I think you might be right. I'm looking at RMM spec 2.0 beta 2, and the RMI can have granule size 4KB, 16KB, 64KB, but the RSI is restricted to granule size 4KB.

I'm open to suggestion on best way to move forward.

The best approach probably depends on whether the 4 KiB restriction is likely to be lifted in a future version of the CCA architecture, and I don't have any insight into that.

If it is likely to be lifted, then doing the initial implementation to support larger page sizes probably makes sense (which is what you've done here). It's less work than going back and adding later. But the commit message and/or code comments should indicate that the larger page size support is future-proofing work, so that someone doesn't get the wrong idea that it should work with larger page sizes now.

The alternate approach is to not do any larger page size support now, and to explicitly state that the code is assuming the current restriction of 4 KiB page size only.

Whichever approach is chosen should be used consistently so there's not a mishmash.

Quoted 22 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0 -0
@@ -499,14 +500,16 @@ int hv_common_cpu_init(unsigned int cpu)
 		}
 
Quoted 13 lines

drivers/hv/hv_common.c int hv_common_cpu_init(unsigned int cpu) · line 506

Quoted 7 lines
drivers/hv/hv_common.c +4 -2
 		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)kasan_reset_tag(mem),
+				alloc_size >> PAGE_SHIFT);

I don't know enough about KASAN or the tag situation on ARM64 to comment on this change. But this same sequence of allocating memory and then decrypting it occurs in other places in Hyper-V code. It seems like those places would also need the same kasan_reset_tag() call.

I'm not sure of the exact behavior of PAGE_END when there are KASAN tags, but it looks like tags could mess with the address comparison.

Quoted 6 lines

I do see that __virt_to_phys_nodebug() and virt_addr_valid() in arch/arm64/include/asm/memory.h both reset tags before calling __is_lm_address().

If there are many calls that follow this pattern, it may be better to add the tag reset in __set_memory_enc_dec().

I had the same thought.

Quoted 3 lines

I can undo this change.

Unfortunately, I don't know whether undoing it is right or not. I haven't taken the time to go learn about the whole scheme and its implications.

Michael

#12 lore raw

RE: [PATCH v2 4/6] Drivers: hv: Mark shared memory as decrypted for CCA Realms

Quoted 9 lines · Michael Kelley

From: Kameron Carr <[email protected]> Sent: Friday, June 26, 2026 4:09 AM

Quoted 5 lines · Michael Kelley
Quoted 3 lines

From: Kameron Carr <[email protected]> Sent: Thursday, June 25, 2026 10:35 AM

Quoted 1 line

We need to round up the memory allocated for the input/output pages

to

Quoted 1 line
Quoted 1 line
Quoted 1 line

the nearest PAGE_SIZE, since set_memory_decrypted() requires the

size

Quoted 6 lines

to

Quoted 1 line
Quoted 1 line
Quoted 1 line

be a multiple of PAGE_SIZE. This only has an effect on ARM VMs that

are

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

using PAGE_SIZE larger than 4K.

I think this change resulted from a Sashiko comment. My understanding

is

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

that the ARM CCA architecture only supports CCA guests with 4 KiB page size. Is that still the case, or has that restriction been lifted in a

later

Quoted 2 lines

version

Quoted 1 line
Quoted 1 line

of the architecture? I'm in favor of handling the larger page sizes,

if only

Quoted 2 lines

for

Quoted 1 line
Quoted 1 line

future proofing. But I wondered whether your intent is to always

support

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

4 KiB page sizes even if CCA doesn't support them now. Another way

to

Quoted 4 lines
Quoted 1 line
Quoted 1 line

put it: In reviewing code, should I flag issues related to page sizes

4 KiB?

Quoted 2 lines

I think you might be right. I'm looking at RMM spec 2.0 beta 2, and the

RMI

Quoted 1 line
Quoted 1 line

can have granule size 4KB, 16KB, 64KB, but the RSI is restricted to

granule

Quoted 7 lines

size

Quoted 3 lines

4KB.

I'm open to suggestion on best way to move forward.

The best approach probably depends on whether the 4 KiB restriction is likely to be lifted in a future version of the CCA architecture, and I

don't have

Quoted 3 lines

any insight into that.

If it is likely to be lifted, then doing the initial implementation to

support

Quoted 6 lines

larger page sizes probably makes sense (which is what you've done here). It's less work than going back and adding later. But the commit message and/or code comments should indicate that the larger page size support is future-proofing work, so that someone doesn't get the wrong idea that it should work with larger page sizes now.

Quoted 6 lines

The alternate approach is to not do any larger page size support now, and to explicitly state that the code is assuming the current restriction of 4 KiB page size only.

Whichever approach is chosen should be used consistently so there's not a mishmash.

I talked with some people from ARM. My current understanding is that the 4KB granule size for the RSI does not mean the guest is restricted to 4KB page size. The granule size is just the alignment requirement and larger page sizes will always be 4KB aligned.

I tested 64KB page size on CCA Realm and it booted successfully.

I will be treating large page sizes as a valid scenario. Please flag any issues you spot related to page size > 4KB.

Regards,
Kameron

#13 lore raw

RE: [PATCH v2 4/6] Drivers: hv: Mark shared memory as decrypted for CCA Realms

From: Kameron Carr <[email protected]> Sent: Tuesday, July 21, 2026 11:44 AM

Quoted 49 lines · Michael Kelley
Quoted 35 lines

From: Kameron Carr <[email protected]> Sent: Friday, June 26, 2026 4:09 AM

Quoted 14 lines · Michael Kelley
Quoted 12 lines

From: Kameron Carr <[email protected]> Sent: Thursday, June 25, 2026 10:35 AM

Quoted 4 lines

We need to round up the memory allocated for the input/output pages to the nearest PAGE_SIZE, since set_memory_decrypted() requires the size to be a multiple of PAGE_SIZE. This only has an effect on ARM VMs that are using PAGE_SIZE larger than 4K.

I think this change resulted from a Sashiko comment. My understanding is that the ARM CCA architecture only supports CCA guests with 4 KiB page size. Is that still the case, or has that restriction been lifted in a later version of the architecture? I'm in favor of handling the larger page sizes, if only for future proofing. But I wondered whether your intent is to always support

Quoted 8 lines
Quoted 2 lines
Quoted 1 line

4 KiB page sizes even if CCA doesn't support them now. Another way to

put it: In reviewing code, should I flag issues related to page sizes 4 KiB?

I think you might be right. I'm looking at RMM spec 2.0 beta 2, and the RMI can have granule size 4KB, 16KB, 64KB, but the RSI is restricted to granule size 4KB.

I'm open to suggestion on best way to move forward.

The best approach probably depends on whether the 4 KiB restriction is likely to be lifted in a future version of the CCA architecture, and I don't have any insight into that.

If it is likely to be lifted, then doing the initial implementation to support larger page sizes probably makes sense (which is what you've done here). It's less work than going back and adding later. But the commit message and/or code comments should indicate that the larger page size support is future-proofing work, so that someone doesn't get the wrong idea that it should work with larger page sizes now.

Quoted 6 lines

The alternate approach is to not do any larger page size support now, and to explicitly state that the code is assuming the current restriction of 4 KiB page size only.

Whichever approach is chosen should be used consistently so there's not a mishmash.

I talked with some people from ARM. My current understanding is that the 4KB granule size for the RSI does not mean the guest is restricted to 4KB page size. The granule size is just the alignment requirement and larger page sizes will always be 4KB aligned.

Quoted 5 lines

I tested 64KB page size on CCA Realm and it booted successfully.

I will be treating large page sizes as a valid scenario. Please flag any issues you spot related to page size > 4KB.

OK, this is good information! So evidently the situation is just like with normal ARM64 VMs on Hyper-V today. The Hyper-V host must operate with a 4 KiB page size, but the guest can use a larger page size as long as it communicates with the host in 4 KiB chunks (which ARM64 guests on Hyper-V already do). As you point out, a guest page size of >= 4 KiB implicitly meets host 4 KiB size/alignment requirement.

But any changing of the private/shared state of memory assigned to the guest is necessarily done in units of, and aligned to, the guest page size. When running with 16 or 64 KiB page size, Hyper-V specific code in the guest must be careful that it is not unwittingly decrypting a larger chunk of memory than it intends. Doing so would probably still work, but would create a security hole by exposing guest data to the host that should be kept private to the guest. I've done a quick look through all the places where Hyper-V code calls set_memory_decrypted(), and the only case I see where the size might not match the guest page size is in hv_common_cpu_init(), and you are fixing that case in this patch. So all appears to be good.

Michael

#14 lore raw

PATCH v2 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 e33a9e3c366a1..77cba08fca132 100644
@@ -13,9 +13,41 @@
 #include <linux/mm.h>
 #include <linux/arm-smccc.h>
 #include <linux/module.h>
+#include <linux/smp.h>
 #include <asm-generic/bug.h>
 #include <hyperv/hvhdk.h>
 #include <asm/mshyperv.h>
+#include <asm/rsi.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
#15 lore raw

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

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Critical] Missing Unprotected IPA Translation - [High] Alignment Constraint Violation / Boot Failure…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] Missing Unprotected IPA Translation
- [High] Alignment Constraint Violation / Boot Failure
- [High] Missing NULL Pointer Check / NULL Dereference
--

commit a71c2edcad24708c7ea03f518e33fcef346f68d6
Author: Kameron Carr <[email protected]>

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

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

Quoted 5 lines
arch/arm64/hyperv/hv_core.c +0 -0
index e33a9e3c366a1..77cba08fca132 100644
@@ -13,9 +13,41 @@

[ ... ]

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 allocation guarantee the 256-byte alignment required by the Arm CCA RMM specification for the hostcall structure IPA?

If hv_hostcall_array is allocated with kcalloc(), which does not guarantee type alignment, SLUB debugging or KASAN redzones could shift the object offset.

Will calling rsi_host_call() with a misaligned pointer cause the RMM to reject the command with RSI_ERROR_INPUT, ultimately triggering a fatal BUG_ON(!hv_result_success(status)) in the wrapper?

Quoted 7 lines
arch/arm64/hyperv/hv_core.c +7 -0
+		ret = hostcall->gprs[0];
+	else
+		ret = HV_STATUS_INVALID_HYPERCALL_INPUT;
+
+	local_irq_restore(flags);
+	return ret;
+}

[ ... ]

arch/arm64/hyperv/hv_core.c u64 hv_do_hypercall(u64 control, void *input, void *output) · line 65

Quoted 8 lines
arch/arm64/hyperv/hv_core.c +2 -2
@@ -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);

[Severity: Critical]
Will this translate the virtual address into a protected IPA without applying the PROT_NS_SHARED bit required for host access?

In an Arm CCA Realm, memory shared with the host must be accessed via the unprotected IPA space. The virt_to_phys() call only calculates the canonical protected IPA.

When the untrusted host attempts to read or write the hypercall buffer using these protected IPAs, won't the RMM block the access and generate a stage-2 fault?

Quoted 5 lines
arch/arm64/hyperv/hv_core.c +3 -0
+
+	arm_smccc_1_1_hvc(HV_FUNC_ID, control, input_address,
+			  output_address, &res);
 	return res.a0;
 }

[ ... ]

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

Quoted 12 lines
arch/arm64/hyperv/hv_core.c +7 -0
@@ -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;
 
+	if (is_realm_world()) {
+		local_irq_save(flags);
+		hostcall = &hv_hostcall_array[smp_processor_id()];
+		memset(hostcall, 0, sizeof(*hostcall));

[Severity: High]
What happens if this is called early during a kernel panic before hv_hostcall_array is initialized?

If an early kernel panic occurs or allocation fails, the crash handler hyperv_report_panic() will invoke hv_set_vpreg(). Because this lacks the NULL check present in hv_do_rsi_hypercall(), calculating the offset from NULL and passing it to memset() might cause a double fault.

Could this prevent the panic from being reported to the hypervisor and hang the system?

Quoted 2 lines
arch/arm64/hyperv/hv_core.c +2 -0
+		hostcall->gprs[0] = HV_FUNC_ID;
+		hostcall->gprs[1] = HVCALL_SET_VP_REGISTERS |

[ ... ]

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

Quoted 12 lines
arch/arm64/hyperv/hv_core.c +7 -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;
 
+	if (is_realm_world()) {
+		local_irq_save(flags);
+		hostcall = &hv_hostcall_array[smp_processor_id()];
+		memset(hostcall, 0, sizeof(*hostcall));

[Severity: High]
Similar to hv_set_vpreg(), does this need a check for hv_hostcall_array being NULL to avoid a NULL pointer dereference if invoked before the array is properly allocated?

Quoted 8 lines
arch/arm64/hyperv/hv_core.c +2 -5
-	/*
-	 * 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 |
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#16 lore raw

PATCH v2 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 8e8148b723d9c..62995b6133f6f 100644
@@ -169,3 +169,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