Skip to content

Commit

Permalink
arm64: Enforce bounce buffers for realm DMA
Browse files Browse the repository at this point in the history
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 <catalin.marinas@arm.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Co-developed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Steven Price <steven.price@arm.com>
Link: https://lore.kernel.org/r/20241017131434.40935-8-steven.price@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
  • Loading branch information
Steven Price authored and Catalin Marinas committed Oct 23, 2024
1 parent 491db21 commit fbf979a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions arch/arm64/kernel/rsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <linux/jump_label.h>
#include <linux/memblock.h>
#include <linux/psci.h>
#include <linux/swiotlb.h>

#include <asm/io.h>
#include <asm/rsi.h>
Expand Down
10 changes: 9 additions & 1 deletion arch/arm64/mm/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <asm/kvm_host.h>
#include <asm/memory.h>
#include <asm/numa.h>
#include <asm/rsi.h>
#include <asm/sections.h>
#include <asm/setup.h>
#include <linux/sizes.h>
Expand Down Expand Up @@ -366,8 +367,14 @@ void __init bootmem_init(void)
*/
void __init mem_init(void)
{
unsigned int flags = SWIOTLB_VERBOSE;
bool swiotlb = max_pfn > PFN_DOWN(arm64_dma_phys_limit);

if (is_realm_world()) {
swiotlb = true;
flags |= SWIOTLB_FORCE;
}

if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) && !swiotlb) {
/*
* If no bouncing needed for ZONE_DMA, reduce the swiotlb
Expand All @@ -379,7 +386,8 @@ void __init mem_init(void)
swiotlb = true;
}

swiotlb_init(swiotlb, SWIOTLB_VERBOSE);
swiotlb_init(swiotlb, flags);
swiotlb_update_mem_attributes();

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

0 comments on commit fbf979a

Please sign in to comment.