Skip to content

Commit fbf979a

Browse files
Steven Pricectmarinas
authored andcommitted
arm64: Enforce bounce buffers for realm DMA
Within a realm guest it's not possible for a device emulated by the VMM to access arbitrary guest memory. So force the use of bounce buffers to ensure that the memory the emulated devices are accessing is in memory which is explicitly shared with the host. This adds a call to swiotlb_update_mem_attributes() which calls set_memory_decrypted() to ensure the bounce buffer memory is shared with the host. For non-realm guests or hosts this is a no-op. Reviewed-by: Catalin Marinas <[email protected]> Reviewed-by: Gavin Shan <[email protected]> Co-developed-by: Suzuki K Poulose <[email protected]> Signed-off-by: Suzuki K Poulose <[email protected]> Signed-off-by: Steven Price <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 491db21 commit fbf979a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

arch/arm64/kernel/rsi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/jump_label.h>
77
#include <linux/memblock.h>
88
#include <linux/psci.h>
9+
#include <linux/swiotlb.h>
910

1011
#include <asm/io.h>
1112
#include <asm/rsi.h>

arch/arm64/mm/init.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <asm/kvm_host.h>
4242
#include <asm/memory.h>
4343
#include <asm/numa.h>
44+
#include <asm/rsi.h>
4445
#include <asm/sections.h>
4546
#include <asm/setup.h>
4647
#include <linux/sizes.h>
@@ -366,8 +367,14 @@ void __init bootmem_init(void)
366367
*/
367368
void __init mem_init(void)
368369
{
370+
unsigned int flags = SWIOTLB_VERBOSE;
369371
bool swiotlb = max_pfn > PFN_DOWN(arm64_dma_phys_limit);
370372

373+
if (is_realm_world()) {
374+
swiotlb = true;
375+
flags |= SWIOTLB_FORCE;
376+
}
377+
371378
if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) && !swiotlb) {
372379
/*
373380
* If no bouncing needed for ZONE_DMA, reduce the swiotlb
@@ -379,7 +386,8 @@ void __init mem_init(void)
379386
swiotlb = true;
380387
}
381388

382-
swiotlb_init(swiotlb, SWIOTLB_VERBOSE);
389+
swiotlb_init(swiotlb, flags);
390+
swiotlb_update_mem_attributes();
383391

384392
/* this will put all unused low memory onto the freelists */
385393
memblock_free_all();

0 commit comments

Comments
 (0)