[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250227144150.1667735-4-suzuki.poulose@arm.com>
Date: Thu, 27 Feb 2025 14:41:50 +0000
From: Suzuki K Poulose <suzuki.poulose@....com>
To: linux-kernel@...r.kernel.org
Cc: will@...nel.org,
catalin.marinas@....com,
maz@...nel.org,
steven.price@....com,
aneesh.kumar@...nel.org,
gshan@...hat.com,
robin.murphy@....com,
linux-arm-kernel@...ts.infradead.org,
Suzuki K Poulose <suzuki.poulose@....com>,
Jean-Philippe Brucker <jean-philippe@...aro.org>,
Christoph Hellwig <hch@....de>,
Marek Szyprowski <m.szyprowski@...sung.com>,
Tom Lendacky <thomas.lendacky@....com>
Subject: [PATCH v3 3/3] arm64: realm: Use aliased addresses for device DMA to shared buffers
When a device performs DMA to a shared buffer using physical addresses,
(without Stage1 translation), the device must use the "{I}PA address" with the
top bit set in Realm. This is to make sure that a trusted device will be able
to write to shared buffers as well as the protected buffers. Thus, a Realm must
always program the full address including the "protection" bit, like AMD SME
encryption bits.
Enable this by providing arm64 specific dma_addr_{encrypted, canonical}
helpers for Realms. Please note that the VMM needs to similarly make sure that
the SMMU Stage2 in the Non-secure world is setup accordingly to map IPA at the
unprotected alias.
Cc: Will Deacon <will@...nel.org>
Cc: Jean-Philippe Brucker <jean-philippe@...aro.org>
Cc: Catalin Marinas <catalin.marinas@....com>
Cc: Robin Murphy <robin.murphy@....com>
Cc: Steven Price <steven.price@....com>
Cc: Christoph Hellwig <hch@....de>
Cc: Marek Szyprowski <m.szyprowski@...sung.com>
Cc: Tom Lendacky <thomas.lendacky@....com>
Cc: Aneesh Kumar K.V <aneesh.kumar@...nel.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@....com>
---
Changes since v2:
- Drop dma_addr_encrypted() helper, which is a NOP for CCA ( Aneesh )
- Only mask the "top" IPA bit and not all the bits beyond top bit. ( Robin )
- Use PROT_NS_SHARED, now that we only set/clear top bit. (Gavin)
---
arch/arm64/include/asm/mem_encrypt.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/arch/arm64/include/asm/mem_encrypt.h b/arch/arm64/include/asm/mem_encrypt.h
index f8f78f622dd2..a2a1eeb36d4b 100644
--- a/arch/arm64/include/asm/mem_encrypt.h
+++ b/arch/arm64/include/asm/mem_encrypt.h
@@ -21,4 +21,15 @@ static inline bool force_dma_unencrypted(struct device *dev)
return is_realm_world();
}
+/*
+ * For Arm CCA guests, canonical addresses are "encrypted", so no changes
+ * required for dma_addr_encrypted().
+ * The unencrypted DMA buffers must be accessed via the unprotected IPA,
+ * "top IPA bit" set.
+ */
+#define dma_addr_unencrypted(x) ((x) | PROT_NS_SHARED)
+
+/* Clear the "top" IPA bit while converting back */
+#define dma_addr_canonical(x) ((x) & ~PROT_NS_SHARED)
+
#endif /* __ASM_MEM_ENCRYPT_H */
--
2.43.0
Powered by blists - more mailing lists