Will Deacon <[email protected]> writes:

> On Fri, Aug 07, 2026 at 02:56:12PM +0530, Aneesh Kumar K.V (Arm) wrote:
>> Realm guests and protected KVM guests may require swiotlb for device DMA
>> even when all system RAM is addressable by the DMA zones.
>> 
>> Do not reduce the SWIOTLB buffer to the kmalloc-bouncing size for these
>> guests, as the reduced number of slots can be exhausted during CCA guest
>> operation.
>> 
>> Fixes: 30c5e45ee2c5 ("dma-direct: make dma_direct_map_phys() honor 
>> DMA_ATTR_CC_SHARED")
>> Signed-off-by: Aneesh Kumar K.V (Arm) <[email protected]>
>> ---
>>  arch/arm64/mm/init.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>> 
>> diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
>> index e308a7cabd12..24caaf10e755 100644
>> --- a/arch/arm64/mm/init.c
>> +++ b/arch/arm64/mm/init.c
>> @@ -339,7 +339,8 @@ void __init arch_mm_preinit(void)
>>  {
>>      unsigned int flags = SWIOTLB_VERBOSE;
>>  
>> -    if (max_pfn <= PFN_DOWN(arm64_dma_phys_limit)) {
>> +    if (!cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT) &&
>> +        max_pfn <= PFN_DOWN(arm64_dma_phys_limit)) {
>
> Protected guests under pKVM rely on restricted DMA, so won't this just
> waste memory for them?
>

commit 30c5e45ee2c5 ("dma-direct: make dma_direct_map_phys() honor 
DMA_ATTR_CC_SHARED"),
which this patch fixes, has

--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -339,9 +339,7 @@ void __init arch_mm_preinit(void)
 {
        unsigned int flags = SWIOTLB_VERBOSE;
 
-       if (is_realm_world() || is_protected_kvm_guest()) {
-               flags |= SWIOTLB_FORCE;
-       } else if (max_pfn <= PFN_DOWN(arm64_dma_phys_limit)) {
+       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.

The is_protected_kvm_guest() part was added by the 
commit e62decaf98e7 ("arm64/coco: Add pKVM as a CC platform")

@@ -337,7 +339,7 @@ void __init arch_mm_preinit(void)
 {
        unsigned int flags = SWIOTLB_VERBOSE;
 
-       if (is_realm_world()) {
+       if (is_realm_world() || is_protected_kvm_guest()) {
                flags |= SWIOTLB_FORCE;
        } else if (max_pfn <= PFN_DOWN(arm64_dma_phys_limit)) {
                /*
@@ -412,6 +414,17 @@ void dump_mem_limit(void)
        }
 }

I was under the impression that there is a possibility of using swiotlb
instead of restricted-dma-pool with pKVM. If that is not the case, then
we could change:

!cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT) &&

to

!is_realm_world() &&

-aneesh

Reply via email to