Re: [PATCH v3 3/3] arm64: realm: Use aliased addresses for device DMA to shared buffers

From: Gavin Shan
Date: Thu Feb 27 2025 - 21:08:39 EST




On 2/28/25 12:41 AM, Suzuki K Poulose wrote:
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@xxxxxxxxxx>
Cc: Jean-Philippe Brucker <jean-philippe@xxxxxxxxxx>
Cc: Catalin Marinas <catalin.marinas@xxxxxxx>
Cc: Robin Murphy <robin.murphy@xxxxxxx>
Cc: Steven Price <steven.price@xxxxxxx>
Cc: Christoph Hellwig <hch@xxxxxx>
Cc: Marek Szyprowski <m.szyprowski@xxxxxxxxxxx>
Cc: Tom Lendacky <thomas.lendacky@xxxxxxx>
Cc: Aneesh Kumar K.V <aneesh.kumar@xxxxxxxxxx>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@xxxxxxx>
---
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(+)


Reviewed-by: Gavin Shan <gshan@xxxxxxxxxx>