[kvm-unit-tests PATCH 11/33] arm: realm: Set RIPAS state for RAM

Suzuki K Poulose suzuki.poulose at arm.com
Fri Apr 12 03:33:46 PDT 2024


A Realm must ensure that the "RAM" region is set to RIPAS_RAM, before any
access is made. This patch makes sure that all memory blocks are marked as
RIPAS_RAM. Also, before we relocate the "FDT" and "initrd", make sure the
target location is marked too. This happens before we parse the memory blocks.

It is OK to do this operation on a given IPA multiple times. So, we don't
exclude the inital image areas from the "target" list.

Also, this operation doesn't require the host to commit physical memory to back
the IPAs yet. It can be done on demand via fault handling.

Signed-off-by: Suzuki K Poulose <suzuki.poulose at arm.com>
---
 lib/arm/setup.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lib/arm/setup.c b/lib/arm/setup.c
index ebd6d058..d726c32a 100644
--- a/lib/arm/setup.c
+++ b/lib/arm/setup.c
@@ -184,6 +184,7 @@ static void mem_init(phys_addr_t freemem_start)
 	while (r && r->end != mem.end)
 		r = memregions_find(r->end);
 	assert(r);
+	arm_set_memory_protected_safe(r->start, r->end - r->start);
 
 	/* Ensure our selected freemem range is somewhere in our full range */
 	assert(freemem_start >= mem.start && freemem->end <= mem.end);
@@ -206,7 +207,14 @@ static void freemem_push_fdt(void **freemem, const void *fdt)
 	assert((unsigned long)fdt > (unsigned long)&stacktop);
 
 	fdt_size = fdt_totalsize(fdt);
+
+	/*
+	 * Before we touch the memory @freemem, make sure it
+	 * is set to protected for Realms.
+	 */
+	arm_set_memory_protected_safe((unsigned long)*freemem, fdt_size);
 	ret = fdt_move(fdt, *freemem, fdt_size);
+
 	assert(ret == 0);
 	ret = dt_init(*freemem);
 	assert(ret == 0);
@@ -222,6 +230,7 @@ static void freemem_push_dt_initrd(void **freemem)
 	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
 	if (ret == 0) {
 		initrd = *freemem;
+		arm_set_memory_protected_safe((unsigned long)initrd, initrd_size);
 		memmove(initrd, tmp, initrd_size);
 		*freemem += initrd_size;
 	}
-- 
2.34.1




More information about the linux-arm-kernel mailing list