dma: swiotlb: Size shared default pools for memory encryption
RFC PATCH 1/1 dma: swiotlb: Size shared default pools for memory encryption
Systems with memory encryption use swiotlb to provide shared or unencrypted buffers for device DMA. Confidential guests may route all DMA through these buffers, while SME hosts use them for devices that cannot address encrypted memory. The default swiotlb pool can therefore be exhausted under I/O-intensive workloads.
Let architectures mark the default swiotlb pool as shared before swiotlb_init(). Move the existing x86 sizing policy into generic swiotlb code and add early pool marking for arm64 Realm guests, powerpc secure guests, s390 protected-virtualization guests, and x86 memory-encryption platforms. Use CC_ATTR_MEM_ENCRYPT on x86 to include host SME, whose swiotlb pool must also be decrypted for devices that cannot address encrypted memory.
Move the powerpc secure-guest swiotlb enablement before initialization so that the shared pool is allocated with the required flags. pKVM guests continue to use a restricted DMA pool instead of the default swiotlb pool.
--- arch/arm64/mm/init.c | 6 ++- arch/powerpc/mm/mem.c | 7 +++ arch/powerpc/platforms/pseries/svm.c | 10 ---- arch/s390/mm/init.c | 2 + arch/x86/mm/mem_encrypt.c | 27 ++-------- include/linux/swiotlb.h | 7 ++- kernel/dma/swiotlb.c | 73 ++++++++++++++++++++++------ 7 files changed, 82 insertions(+), 50 deletions(-)
arch/arm64/mm/init.c +5 -1
@@ -338,8 +338,12 @@ void __init arch_setup_zero_pages(void)void __init arch_mm_preinit (void ) {unsigned int flags =SWIOTLB_VERBOSE ; +/* pKVM uses restricted-dma-pool */ +bool cc_guest =is_realm_world (); -if (max_pfn <=PFN_DOWN (arm64_dma_phys_limit)) { +if (cc_guest) { +swiotlb_mark_default_cc_shared (); + }else if (max_pfn <=PFN_DOWN (arm64_dma_phys_limit)) {/* * If no bouncing needed for ZONE_DMA, reduce the swiotlb * buffer for kmalloc() bouncing to 1MB per 1GB of RAM.
arch/powerpc/mm/mem.c +7 -0
@@ -287,6 +287,13 @@ void __init arch_mm_preinit(void)BUILD_BUG_ON (MMU_PAGE_COUNT >16 );#ifdef CONFIG_SWIOTLB +if (is_secure_guest ()) { +/* The host can access DMA buffers only through the SWIOTLB. */ +swiotlb_mark_default_cc_shared (); + ppc_swiotlb_enable =1 ; + ppc_swiotlb_flags |=SWIOTLB_ANY ; + } +/* * Some platforms (e.g. 85xx) limit DMA-able memory way below * 4G. We force memblock to bottom-up mode to ensure that the
arch/powerpc/platforms/pseries/svm.c +0 -10
@@ -21,16 +21,6 @@ static int __init init_svm(void)if (!is_secure_guest ())return 0 ; -/* Don't release the SWIOTLB buffer. */ - ppc_swiotlb_enable =1 ; - -/* -* Since the guest memory is inaccessible to the host, devices always -* need to use the SWIOTLB buffer for DMA even if dma_capable() says -* otherwise. -*/ - ppc_swiotlb_flags |=SWIOTLB_ANY ; -/* Share the SWIOTLB buffer with the host. */ swiotlb_update_mem_attributes ();
arch/s390/mm/init.c +2 -0
@@ -163,6 +163,8 @@ static void __init pv_init(void)if (!is_prot_virt_guest ())return ; +swiotlb_mark_default_cc_shared (); +virtio_set_mem_acc_cb (virtio_require_restricted_mem_acc);/* make sure bounce buffers are shared */
arch/x86/mm/mem_encrypt.c +3 -24
@@ -101,9 +101,6 @@ void __init mem_encrypt_init(void)void __init mem_encrypt_setup_arch (void ) { -phys_addr_t total_mem =memblock_phys_mem_size (); -unsigned long size; -/* * Do RMP table fixups after the e820 tables have been setup by * e820__memory_setup().
@@ -111,30 +108,12 @@ void __init mem_encrypt_setup_arch(void)if (cc_platform_has (CC_ATTR_HOST_SEV_SNP ))snp_fixup_e820_tables (); +if (cc_platform_has (CC_ATTR_MEM_ENCRYPT )) +swiotlb_mark_default_cc_shared (); +if (!cc_platform_has (CC_ATTR_GUEST_MEM_ENCRYPT ))return ; -/* -* For SEV and TDX, all DMA has to occur via shared/unencrypted pages. -* Kernel uses SWIOTLB to make this happen without changing device -* drivers. However, depending on the workload being run, the -* default 64MB of SWIOTLB may not be enough and SWIOTLB may -* run out of buffers for DMA, resulting in I/O errors and/or -* performance degradation especially with high I/O workloads. -* -* Adjust the default size of SWIOTLB using a percentage of guest -* memory for SWIOTLB buffers. Also, as the SWIOTLB bounce buffer -* memory is allocated from low memory, ensure that the adjusted size -* is within the limits of low available memory. -* -* The percentage of guest memory used here for SWIOTLB buffers -* is more of an approximation of the static adjustment which -* 64MB for <1G, and ~128M to 256M for 1G-to-4G, i.e., the 6% -*/ - size = total_mem *6 /100 ; - size =clamp_val (size,IO_TLB_DEFAULT_SIZE ,SZ_1G ); -swiotlb_adjust_size (size); -/* Set restricted memory access for virtio. */ virtio_set_mem_acc_cb (virtio_require_restricted_mem_acc); }
include/linux/swiotlb.h +6 -1
@@ -189,7 +189,8 @@ void swiotlb_dev_init(struct device *dev);size_t swiotlb_max_mapping_size (struct device *dev);bool is_swiotlb_allocated (void );bool is_swiotlb_active (struct device *dev); -void __init swiotlb_adjust_size (unsigned long size); +void __init swiotlb_mark_default_cc_shared (void ); +void swiotlb_adjust_size (unsigned long size);phys_addr_t default_swiotlb_base (void );phys_addr_t default_swiotlb_limit (void );#else
@@ -228,6 +229,10 @@ static inline bool is_swiotlb_active(struct device *dev)return false; } +static inline void swiotlb_mark_default_cc_shared (void ) +{ +} +static inline void swiotlb_adjust_size (unsigned long size) { }
kernel/dma/swiotlb.c +59 -14
123 lines not on this page · raw message
Signature · 1 line
2.43.0
Catalin Marinas
maintainerQuoted 8 lines · Aneesh Kumar K.V (Arm)
Systems with memory encryption use swiotlb to provide shared or unencrypted buffers for device DMA. Confidential guests may route all DMA through these buffers, while SME hosts use them for devices that cannot address encrypted memory. The default swiotlb pool can therefore be exhausted under I/O-intensive workloads.
Let architectures mark the default swiotlb pool as shared before
swiotlb_init().
I thought we wanted even this decision to be moved out of the arch code.
Quoted 6 lines
Move the existing x86 sizing policy into generic swiotlb code and add early pool marking for arm64 Realm guests, powerpc secure guests, s390 protected-virtualization guests, and x86 memory-encryption platforms. Use
CC_ATTR_MEM_ENCRYPTon x86 to include host SME, whose swiotlb pool must also be decrypted for devices that cannot address encrypted memory.
That's a functional change for x86. For now, I'd keep it to CC_ATTR_GUEST_MEM_ENCRYPT.
BTW, why does arm64 report CC_ATTR_MEM_ENCRYPT instead of the GUEST option in realms?
Quoted 24 lines
Move the powerpc secure-guest swiotlb enablement before initialization so that the shared pool is allocated with the required flags. pKVM guests continue to use a restricted DMA pool instead of the default swiotlb pool.
Signed-off-by Aneesh Kumar K.V (Arm) <[email protected]>--- arch/arm64/mm/init.c | 6 ++- arch/powerpc/mm/mem.c | 7 +++ arch/powerpc/platforms/pseries/svm.c | 10 ---- arch/s390/mm/init.c | 2 + arch/x86/mm/mem_encrypt.c | 27 ++-------- include/linux/swiotlb.h | 7 ++- kernel/dma/swiotlb.c | 73 ++++++++++++++++++++++------ 7 files changed, 82 insertions(+), 50 deletions(-)arch/arm64/mm/init.c +0
-0@@ -338,8 +338,12 @@ void __init arch_setup_zero_pages(void)void __init arch_mm_preinit (void ) {unsigned int flags =SWIOTLB_VERBOSE ;
arch/arm64/mm/init.c void __init arch_setup_zero_pages(void) · line 349
Quoted 10 lines
arch/arm64/mm/init.c +5
-1+/* pKVM uses restricted-dma-pool */ +bool cc_guest =is_realm_world (); -if (max_pfn <=PFN_DOWN (arm64_dma_phys_limit)) { +if (cc_guest) { +swiotlb_mark_default_cc_shared (); + }else if (max_pfn <=PFN_DOWN (arm64_dma_phys_limit)) {/* * If no bouncing needed for ZONE_DMA, reduce the swiotlb * buffer for kmalloc() bouncing to 1MB per 1GB of RAM.
With your other reworking, doesn't the core code know the swiotlb will be shared? Can it not make the decision to resize at that point based solely on CC_ATTR_GUEST_MEM_ENCRYPT?
I also wonder whether we could address Will's pKVM request not to allocate a bounce buffer once pKVM guests will start reporting CC_ATTR_GUEST_MEM_ENCRYPT. Some simple heuristic: if a restricted-dma-pool is advertised in DT (it will end up in rmem_swiotlb_setup()), skip resizing the default swiotlb. It's not perfect but the bounce buffer can be overridden on the command line.
Signature · 1 line
Catalin
Quoted 7 lines · Catalin Marinas
Quoted 6 lines · Aneesh Kumar K.V (Arm)
Systems with memory encryption use swiotlb to provide shared or unencrypted buffers for device DMA. Confidential guests may route all DMA through these buffers, while SME hosts use them for devices that cannot address encrypted memory. The default swiotlb pool can therefore be exhausted under I/O-intensive workloads.
Quoted 5 lines
Quoted 2 lines
Let architectures mark the default swiotlb pool as shared before
swiotlb_init().I thought we wanted even this decision to be moved out of the arch code.
Architectures may want to use an unencrypted swiotlb pool for different reasons, one of them being CC_ATTR_GUEST_MEM_ENCRYPT. x86 hosts also require unencrypted pool to support SME. We can cover both cases using CC_ATTR_MEM_ENCRYPT. However, pKVM does not want an unencrypted SWIOTLB pool. So I was thinking it would be much cleaner to let the architecture code drive that decision.
Quoted 53 lines
Quoted 7 lines
Move the existing x86 sizing policy into generic swiotlb code and add early pool marking for arm64 Realm guests, powerpc secure guests, s390 protected-virtualization guests, and x86 memory-encryption platforms. Use
CC_ATTR_MEM_ENCRYPTon x86 to include host SME, whose swiotlb pool must also be decrypted for devices that cannot address encrypted memory.That's a functional change for x86. For now, I'd keep it to
CC_ATTR_GUEST_MEM_ENCRYPT.BTW, why does arm64 report
CC_ATTR_MEM_ENCRYPTinstead of the GUEST option in realms?Quoted 24 lines
Move the powerpc secure-guest swiotlb enablement before initialization so that the shared pool is allocated with the required flags. pKVM guests continue to use a restricted DMA pool instead of the default swiotlb pool.
Signed-off-by Aneesh Kumar K.V (Arm) <[email protected]>--- arch/arm64/mm/init.c | 6 ++- arch/powerpc/mm/mem.c | 7 +++ arch/powerpc/platforms/pseries/svm.c | 10 ---- arch/s390/mm/init.c | 2 + arch/x86/mm/mem_encrypt.c | 27 ++-------- include/linux/swiotlb.h | 7 ++- kernel/dma/swiotlb.c | 73 ++++++++++++++++++++++------ 7 files changed, 82 insertions(+), 50 deletions(-)arch/arm64/mm/init.c +0
-0@@ -338,8 +338,12 @@ void __init arch_setup_zero_pages(void)void __init arch_mm_preinit (void ) {unsigned int flags =SWIOTLB_VERBOSE ;arch/arm64/mm/init.c void __init arch_setup_zero_pages(void) · line 349
Quoted 10 lines
arch/arm64/mm/init.c +5
-1+/* pKVM uses restricted-dma-pool */ +bool cc_guest =is_realm_world (); -if (max_pfn <=PFN_DOWN (arm64_dma_phys_limit)) { +if (cc_guest) { +swiotlb_mark_default_cc_shared (); + }else if (max_pfn <=PFN_DOWN (arm64_dma_phys_limit)) {/* * If no bouncing needed for ZONE_DMA, reduce the swiotlb * buffer for kmalloc() bouncing to 1MB per 1GB of RAM. With your other reworking, doesn't the core code know the swiotlb will be shared? Can it not make the decision to resize at that point based solely on
CC_ATTR_GUEST_MEM_ENCRYPT?
Quoted 7 lines
I also wonder whether we could address Will's pKVM request not to allocate a bounce buffer once pKVM guests will start reporting
CC_ATTR_GUEST_MEM_ENCRYPT. Some simple heuristic: if a restricted-dma-pool is advertised in DT (it will end up inrmem_swiotlb_setup()), skip resizing the default swiotlb. It's not perfect but the bounce buffer can be overridden on the command line.
For the same reason I mentioned above, architectures may have different reasons for setting cc_shared = true. IMHO, it is cleaner to let the architecture code make that decision before swiotlb_init().
-aneesh
Quoted 7 lines · Catalin Marinas
I also wonder whether we could address Will's pKVM request not to allocate a bounce buffer once pKVM guests will start reporting
CC_ATTR_GUEST_MEM_ENCRYPT. Some simple heuristic: if a restricted-dma-pool is advertised in DT (it will end up inrmem_swiotlb_setup()), skip resizing the default swiotlb. It's not perfect but the bounce buffer can be overridden on the command line.
I have a follow-up cleanup patch where I switch the swiotlb initialization reason to a flag value. With that, we now have SWIOTLB_INIT_CC_SHARED.
The challenge is that it is still not clear when pKVM would want to use an unencrypted swiotlb pool for DMA bouncing. I would expect pKVM to have some additional condition based on which it chooses either the restricted-dma-pool or the default swiotlb pool.
Using the presence of a restricted-dma-pool to decide whether the default swiotlb pool should be unencrypted is one option, but I am not sure that is the right abstraction.
modified arch/arm64/mm/init.c
@@ -342,7 +342,7 @@ void __init arch_mm_preinit(void)
bool cc_guest = is_realm_world();
if (cc_guest)
- swiotlb_mark_default_cc_shared();
+ flags |= SWIOTLB_INIT_CC_SHARED;
else if (max_pfn > PFN_DOWN(arm64_dma_phys_limit))
flags |= SWIOTLB_INIT_ADDRESSING_LIMIT;
modified arch/powerpc/mm/mem.c
@@ -289,9 +289,8 @@ void __init arch_mm_preinit(void)
#ifdef CONFIG_SWIOTLB
if (is_secure_guest()) {
/* The host can access DMA buffers only through the SWIOTLB. */
- swiotlb_mark_default_cc_shared();
ppc_swiotlb_enable = 1;
- ppc_swiotlb_flags |= SWIOTLB_ANY;
+ ppc_swiotlb_flags |= SWIOTLB_INIT_CC_SHARED | SWIOTLB_ANY;
}
/*
modified arch/s390/mm/init.c
@@ -163,12 +163,10 @@ static void __init pv_init(void)
if (!is_prot_virt_guest())
return;
- swiotlb_mark_default_cc_shared();
-
virtio_set_mem_acc_cb(virtio_require_restricted_mem_acc);
/* make sure bounce buffers are shared */
- swiotlb_init(SWIOTLB_VERBOSE);
+ swiotlb_init(SWIOTLB_VERBOSE | SWIOTLB_INIT_CC_SHARED);
swiotlb_update_mem_attributes();
}
modified arch/x86/mm/mem_encrypt.c
@@ -14,6 +14,7 @@
#include <linux/mem_encrypt.h>
#include <linux/virtio_anchor.h>
+#include <asm/iommu.h>
#include <asm/sev.h>
/* Override for DMA direct allocation check - ARCH_HAS_FORCE_DMA_UNENCRYPTED */
@@ -109,7 +110,7 @@ void __init mem_encrypt_setup_arch(void)
snp_fixup_e820_tables();
if (cc_platform_has(CC_ATTR_MEM_ENCRYPT))
- swiotlb_mark_default_cc_shared();
+ x86_swiotlb_flags |= SWIOTLB_INIT_CC_SHARED;
if (!cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
return;
modified include/linux/swiotlb.h
@@ -18,6 +18,8 @@ struct scatterlist;
#define SWIOTLB_ANY (1 << 1) /* allow any memory for the buffer */
/* Initialize a default-sized pool for devices with limited DMA addressing. */
#define SWIOTLB_INIT_ADDRESSING_LIMIT (1 << 2)
+/* Initialize a shared default pool for confidential-computing systems. */
+#define SWIOTLB_INIT_CC_SHARED (1 << 3)
/*
* Maximum allowable number of contiguous slabs to map,
@@ -191,7 +193,6 @@ void swiotlb_dev_init(struct device *dev);
size_t swiotlb_max_mapping_size(struct device *dev);
bool is_swiotlb_allocated(void);
bool is_swiotlb_active(struct device *dev);
-void __init swiotlb_mark_default_cc_shared(void);
void __init swiotlb_adjust_size(unsigned long size);
phys_addr_t default_swiotlb_base(void);
phys_addr_t default_swiotlb_limit(void);
@@ -231,10 +232,6 @@ static inline bool is_swiotlb_active(struct device *dev)
return false;
}
-static inline void swiotlb_mark_default_cc_shared(void)
-{
-}
-
static inline void swiotlb_adjust_size(unsigned long size)
{
}
modified kernel/dma/swiotlb.c
@@ -373,11 +373,6 @@ static void __init *swiotlb_memblock_alloc(unsigned long nslabs,
return tlb;
}
-void __init swiotlb_mark_default_cc_shared(void)
-{
- io_tlb_default_mem.cc_shared = true;
-}
-
static void __init swiotlb_adjust_cc_attributes(void)
{
unsigned long size;
@@ -429,7 +424,7 @@ static bool __init swiotlb_should_init(unsigned int flags)
if (swiotlb_force_bounce)
return true;
- if (io_tlb_default_mem.cc_shared)
+ if (flags & SWIOTLB_INIT_CC_SHARED)
return true;
return false;
@@ -451,6 +446,9 @@ void __init swiotlb_init_remap(unsigned int flags,
if (!swiotlb_should_init(flags))
return;
+ if (flags & SWIOTLB_INIT_CC_SHARED)
+ io_tlb_default_mem.cc_shared = true;
+
io_tlb_default_mem.force_bounce = swiotlb_force_bounce;
#ifdef CONFIG_SWIOTLB_DYNAMIC
Catalin Marinas
maintainerQuoted 11 lines · Aneesh Kumar K.V
Quoted 10 lines · Catalin Marinas
Quoted 8 lines · Aneesh Kumar K.V (Arm)
Systems with memory encryption use swiotlb to provide shared or unencrypted buffers for device DMA. Confidential guests may route all DMA through these buffers, while SME hosts use them for devices that cannot address encrypted memory. The default swiotlb pool can therefore be exhausted under I/O-intensive workloads.
Let architectures mark the default swiotlb pool as shared before
swiotlb_init().
Quoted 6 lines
Quoted 1 line
I thought we wanted even this decision to be moved out of the arch code.
Architectures may want to use an unencrypted swiotlb pool for different reasons, one of them being
CC_ATTR_GUEST_MEM_ENCRYPT. x86 hosts also require unencrypted pool to support SME. We can cover both cases usingCC_ATTR_MEM_ENCRYPT.
Yes but in one case it did not do resizing. With your proposal, it now does swiotlb resizing even for SME.
Quoted 3 lines
However, pKVM does not want an unencrypted SWIOTLB
pool. So I was thinking it would be much cleaner to let the architecture code drive that decision.
Let's not single out pKVM but rather the reason it does not want one - it relies heavily on restricted mem. If you started a pKVM guest without rmem in DT, I assume it will need swiotlb to function properly. It's not a great heuristic (devices may not use rmem) but it preserves the current behaviour and can be overridden on the command line.
Quoted 2 lines
Quoted 2 lines
BTW, why does arm64 report
CC_ATTR_MEM_ENCRYPTinstead of the GUEST option in realms?
It's still not clear to me why we went for CC_ATTR_MEM_ENCRYPT instead of CC_ATTR_GUEST_MEM_ENCRYPT.
Quoted 3 lines
For the same reason I mentioned above, architectures may have different reasons for setting
cc_shared= true. IMHO, it is cleaner to let the architecture code make that decision beforeswiotlb_init().
The arch code already reports cc_platform_has(), can we not rely on this in the core code instead of specific is_realm_world() and a new SWIOTLB_INIT_CC_SHARED flag or function call?
We have three different decisions that shouldn't be driven by a single flag from the arch code:
1. allocate default pool
2. make default pool shared
3. resize default pool
(1) is traditionally driven by arch code and that's fine. For (2), the core code has the information via CC_ATTR_*. For (3), we can enlarge it based on CC_ATTR_GUEST_MEM_ENCRYPT in combination with rmem (but not CC_ATTR_MEM_ENCRYPT to keep the current x86 behaviour).
I think we should also move the reduction based on CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC into the core code. Riscv copied the same heuristic as arm64, so there's precedent for sharing.
Signature · 1 line
Catalin
Quoted 5 lines · Catalin Marinas
Quoted 2 lines
Quoted 2 lines
BTW, why does arm64 report
CC_ATTR_MEM_ENCRYPTinstead of the GUEST option in realms?It's still not clear to me why we went for
CC_ATTR_MEM_ENCRYPTinstead ofCC_ATTR_GUEST_MEM_ENCRYPT.
Yeah, this tune should be only for CC guests that have the shared/private issue.
The AMD SME issue with the address width on bare metal is an entirely different problem that would need a different kind of tuning.
Jason
Quoted 14 lines · Catalin Marinas
Quoted 13 lines · Aneesh Kumar K.V
Quoted 11 lines · Catalin Marinas
Quoted 8 lines · Aneesh Kumar K.V (Arm)
Systems with memory encryption use swiotlb to provide shared or unencrypted buffers for device DMA. Confidential guests may route all DMA through these buffers, while SME hosts use them for devices that cannot address encrypted memory. The default swiotlb pool can therefore be exhausted under I/O-intensive workloads.
Let architectures mark the default swiotlb pool as shared before
swiotlb_init().I thought we wanted even this decision to be moved out of the arch code.
Quoted 8 lines
Quoted 4 lines
Architectures may want to use an unencrypted swiotlb pool for different reasons, one of them being
CC_ATTR_GUEST_MEM_ENCRYPT. x86 hosts also require unencrypted pool to support SME. We can cover both cases usingCC_ATTR_MEM_ENCRYPT.Yes but in one case it did not do resizing. With your proposal, it now does swiotlb resizing even for SME.
Isn't that a bug with x86 SME? I would expect both SME and SEV to require that swiotlb resize.
Quoted 5 lines
Quoted 4 lines
However, pKVM does not want an unencrypted SWIOTLB
pool. So I was thinking it would be much cleaner to let the architecture code drive that decision.
Quoted 8 lines
Let's not single out pKVM but rather the reason it does not want one - it relies heavily on restricted mem. If you started a pKVM guest without rmem in DT, I assume it will need swiotlb to function properly. It's not a great heuristic (devices may not use rmem) but it preserves the current behaviour and can be overridden on the command line.
Quoted 2 lines
Quoted 2 lines
BTW, why does arm64 report
CC_ATTR_MEM_ENCRYPTinstead of the GUEST option in realms?
This is getting fixed in
https://lore.kernel.org/all/[email protected]/
Quoted 4 lines
It's still not clear to me why we went for
CC_ATTR_MEM_ENCRYPTinstead ofCC_ATTR_GUEST_MEM_ENCRYPT.
This is done for x86 to handle SME. SME also requires an unencrypted swiotlb pool
Quoted 12 lines
Quoted 4 lines
For the same reason I mentioned above, architectures may have different reasons for setting
cc_shared= true. IMHO, it is cleaner to let the architecture code make that decision beforeswiotlb_init().The arch code already reports
cc_platform_has(), can we not rely on this in the core code instead of specificis_realm_world()and a newSWIOTLB_INIT_CC_SHAREDflag or function call?We have three different decisions that shouldn't be driven by a single flag from the arch code:
Quoted 9 lines
1. allocate default pool
2. make default pool shared
3. resize default pool(1) is traditionally driven by arch code and that's fine. For (2), the core code has the information via CC_ATTR_*. For (3), we can enlarge it based on
CC_ATTR_GUEST_MEM_ENCRYPTin combination with rmem (but notCC_ATTR_MEM_ENCRYPTto keep the current x86 behaviour).
Okay, if the presence of restricted-dma-pool is taken as a hint, we can definitely move that to generic code.
I still think not resizing the swiotlb pool on the host for SME is an x86 bug. However, I'll keep it compatible with the current behavior and use CC_ATTR_GUEST_MEM_ENCRYPT for now. We can handle host SME in a separate patch if needed.
Quoted 4 lines
I think we should also move the reduction based on
CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOCinto the core code. Riscv copied the same heuristic as arm64, so there's precedent for sharing.
I already have a patch doing that.
-aneesh
Catalin Marinas
maintainerQuoted 20 lines · Aneesh Kumar K.V
Quoted 19 lines · Catalin Marinas
Quoted 17 lines · Aneesh Kumar K.V
Quoted 11 lines · Catalin Marinas
Quoted 8 lines · Aneesh Kumar K.V (Arm)
Systems with memory encryption use swiotlb to provide shared or unencrypted buffers for device DMA. Confidential guests may route all DMA through these buffers, while SME hosts use them for devices that cannot address encrypted memory. The default swiotlb pool can therefore be exhausted under I/O-intensive workloads.
Let architectures mark the default swiotlb pool as shared before
swiotlb_init().I thought we wanted even this decision to be moved out of the arch code.
Architectures may want to use an unencrypted swiotlb pool for different reasons, one of them being
CC_ATTR_GUEST_MEM_ENCRYPT. x86 hosts also require unencrypted pool to support SME. We can cover both cases usingCC_ATTR_MEM_ENCRYPT.
Quoted 5 lines
Quoted 2 lines
Yes but in one case it did not do resizing. With your proposal, it now does swiotlb resizing even for SME.
Isn't that a bug with x86 SME? I would expect both SME and SEV to require that swiotlb resize.
Maybe, but that's for a different discussion (and we may want different sizing). Better to keep the semantics unchanged for now.
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
BTW, why does arm64 report
CC_ATTR_MEM_ENCRYPTinstead of the GUEST option in realms?This is getting fixed in
https://lore.kernel.org/all/[email protected]/
You might want to bring this early together with the swiotlb adjustment here.
Quoted 20 lines
Quoted 11 lines
Quoted 3 lines
For the same reason I mentioned above, architectures may have different reasons for setting
cc_shared= true. IMHO, it is cleaner to let the architecture code make that decision beforeswiotlb_init().The arch code already reports
cc_platform_has(), can we not rely on this in the core code instead of specificis_realm_world()and a newSWIOTLB_INIT_CC_SHAREDflag or function call?We have three different decisions that shouldn't be driven by a single flag from the arch code:
Quoted 8 lines
1. allocate default pool
2. make default pool shared
3. resize default pool(1) is traditionally driven by arch code and that's fine. For (2), the core code has the information via CC_ATTR_*. For (3), we can enlarge it based on
CC_ATTR_GUEST_MEM_ENCRYPTin combination with rmem (but notCC_ATTR_MEM_ENCRYPTto keep the current x86 behaviour).
Quoted 7 lines
Okay, if the presence of restricted-dma-pool is taken as a hint, we can definitely move that to generic code.
I still think not resizing the swiotlb pool on the host for SME is an x86 bug. However, I'll keep it compatible with the current behavior and use
CC_ATTR_GUEST_MEM_ENCRYPTfor now. We can handle host SME in a separate patch if needed.
Sound good.
Quoted 5 lines
Quoted 3 lines
I think we should also move the reduction based on
CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOCinto the core code. Riscv copied the same heuristic as arm64, so there's precedent for sharing.I already have a patch doing that.
Great. Now you have a 3-patch series for the generic swiotlb sizing ;)
Signature · 1 line
Catalin
Quoted 9 lines · Catalin Marinas
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
BTW, why does arm64 report
CC_ATTR_MEM_ENCRYPTinstead of the GUEST option in realms?This is getting fixed in
https://lore.kernel.org/all/[email protected]/You might want to bring this early together with the swiotlb adjustment here.
That is already part of dma -next tree.
-aneesh