]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
arm64: realm: ioremap: Allow mapping memory as encrypted
authorSuzuki K Poulose <suzuki.poulose@arm.com>
Thu, 18 Sep 2025 12:56:16 +0000 (13:56 +0100)
committerWill Deacon <will@kernel.org>
Fri, 19 Sep 2025 09:12:01 +0000 (10:12 +0100)
For ioremap(), so far we only checked if it was a device (RIPAS_DEV) to choose
an encrypted vs decrypted mapping. However, we may have firmware reserved memory
regions exposed to the OS (e.g., EFI Coco Secret Securityfs, ACPI CCEL).
We need to make sure that anything that is RIPAS_RAM (i.e., Guest
protected memory with RMM guarantees) are also mapped as encrypted.

Rephrasing the above, anything that is not RIPAS_EMPTY is guaranteed to be
protected by the RMM. Thus we choose encrypted mapping for anything that is not
RIPAS_EMPTY. While at it, rename the helper function

  __arm64_is_protected_mmio => arm64_rsi_is_protected

to clearly indicate that this not an arm64 generic helper, but something to do
with Realms.

Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
Cc: Steven Price <steven.price@arm.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Tested-by: Sami Mujawar <sami.mujawar@arm.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/include/asm/io.h
arch/arm64/include/asm/rsi.h
arch/arm64/kernel/rsi.c

index 9b96840fb979bf791cb9b2306ba7fb47464bb8af..82276282a3c725984643fec873c54afff39f33a5 100644 (file)
@@ -311,7 +311,7 @@ extern bool arch_memremap_can_ram_remap(resource_size_t offset, size_t size,
 static inline bool arm64_is_protected_mmio(phys_addr_t phys_addr, size_t size)
 {
        if (unlikely(is_realm_world()))
-               return __arm64_is_protected_mmio(phys_addr, size);
+               return arm64_rsi_is_protected(phys_addr, size);
        return false;
 }
 
index b42aeac05340edd7d41573789fb78b9d06ecc34c..88b50d660e85a059e64a9bd7148b7d111423b7d1 100644 (file)
@@ -16,7 +16,7 @@ DECLARE_STATIC_KEY_FALSE(rsi_present);
 
 void __init arm64_rsi_init(void);
 
-bool __arm64_is_protected_mmio(phys_addr_t base, size_t size);
+bool arm64_rsi_is_protected(phys_addr_t base, size_t size);
 
 static inline bool is_realm_world(void)
 {
index ce4778141ec7b8a05a49a28fdf4aa7f37bd915a7..c64a06f58c0bc0d1e9e95d5a489d9f65c0e037c7 100644 (file)
@@ -84,7 +84,25 @@ static void __init arm64_rsi_setup_memory(void)
        }
 }
 
-bool __arm64_is_protected_mmio(phys_addr_t base, size_t size)
+/*
+ * Check if a given PA range is Trusted (e.g., Protected memory, a Trusted Device
+ * mapping, or an MMIO emulated in the Realm world).
+ *
+ * We can rely on the RIPAS value of the region to detect if a given region is
+ * protected.
+ *
+ *  RIPAS_DEV - A trusted device memory or a trusted emulated MMIO (in the Realm
+ *             world
+ *  RIPAS_RAM - Memory (RAM), protected by the RMM guarantees. (e.g., Firmware
+ *             reserved regions for data sharing).
+ *
+ *  RIPAS_DESTROYED is a special case of one of the above, where the host did
+ *  something without our permission and as such we can't do anything about it.
+ *
+ * The only case where something is emulated by the untrusted hypervisor or is
+ * backed by shared memory is indicated by RSI_RIPAS_EMPTY.
+ */
+bool arm64_rsi_is_protected(phys_addr_t base, size_t size)
 {
        enum ripas ripas;
        phys_addr_t end, top;
@@ -101,18 +119,18 @@ bool __arm64_is_protected_mmio(phys_addr_t base, size_t size)
                        break;
                if (WARN_ON(top <= base))
                        break;
-               if (ripas != RSI_RIPAS_DEV)
+               if (ripas == RSI_RIPAS_EMPTY)
                        break;
                base = top;
        }
 
        return base >= end;
 }
-EXPORT_SYMBOL(__arm64_is_protected_mmio);
+EXPORT_SYMBOL(arm64_rsi_is_protected);
 
 static int realm_ioremap_hook(phys_addr_t phys, size_t size, pgprot_t *prot)
 {
-       if (__arm64_is_protected_mmio(phys, size))
+       if (arm64_rsi_is_protected(phys, size))
                *prot = pgprot_encrypted(*prot);
        else
                *prot = pgprot_decrypted(*prot);