Skip to contentSkip to conversation

swiotlb: add a SWIOTLB_ANY flag to lift restricted low memory for encryption

PATCH In review Jun Miao 2 participants 4 messages Apr 29, 2025 – Feb 12 x86

lore
Share & tools
lore

Jun Miao

author
#0 lore raw

PATCH 1/1 swiotlb: add a SWIOTLB_ANY flag to lift restricted low memory for encryption

TDX guest wants to allocate a swiotlb buffer that is not restricted to low memory for the trusted hypervisor scheme. So that allow to pick a location everywhere for hypervisors with guest memory encryption in swiotlb_memblock_alloc() interface by adding a new flag.

---
 arch/x86/kernel/pci-dma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/pci-dma.c +1 -1
index 6267363e0189..73b9320c4a7d 100644
@@ -61,7 +61,7 @@ static void __init pci_swiotlb_detect(void)
 	 */
 	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
 		x86_swiotlb_enable = true;
-		x86_swiotlb_flags |= SWIOTLB_FORCE;
+		x86_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;
 	}
 }
 #else
Signature · 1 line
2.43.0
author
#1 lore raw

Hi maintainers and Big shot,
I would like to further explain my original intention:
The purpose is to solve the problem found by customers when inserting 8 NVMe disks - There will be a swiotlb buffer full warning. When CONFIG_SWIOTLB_DYNAMIC is turned on, it is impossible to allocate more than 2G swiotlb buffer to meet the actual high throughput usage requirements.

Warm regards
Jun Miao

Quoted 26 lines

TDX guest wants to allocate a swiotlb buffer that is not restricted to low memory for the trusted hypervisor scheme. So that allow to pick a location everywhere for hypervisors with guest memory encryption in
swiotlb_memblock_alloc() interface by adding a new flag.

---
arch/x86/kernel/pci-dma.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/pci-dma.c index renamed from arch/x86/kernel/pci-dma.c +0 -0

6267363e0189..73b9320c4a7d 100644

arch/x86/kernel/pci-dma.c +1 -2
@@ -61,7 +61,7 @@ static void __init pci_swiotlb_detect(void)
 	 */
 	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
 		x86_swiotlb_enable = true;
-		x86_swiotlb_flags |= SWIOTLB_FORCE;
+		x86_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;
 	}
 }
 #else
--

2.43.0

Reviewed-by Tested-by on v1 1/1
#2 lore raw
In reply to Jun Miao

Hi Jun,

Quoted 15 lines · Jun Miao

TDX guest wants to allocate a swiotlb buffer that is not restricted to low memory for the trusted hypervisor scheme. So that allow to pick a location everywhere for hypervisors with guest memory encryption in swiotlb_memblock_alloc() interface by adding a new flag.

---
  arch/x86/kernel/pci-dma.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/pci-dma.c +0 -0
index 6267363e0189..73b9320c4a7d 100644

arch/x86/kernel/pci-dma.c static void __init pci_swiotlb_detect(void) · line 67

Quoted 8 lines
arch/x86/kernel/pci-dma.c +1 -1
@@ -61,7 +61,7 @@ static void __init pci_swiotlb_detect(void)
  	 */
  	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
  		x86_swiotlb_enable = true;
-		x86_swiotlb_flags |= SWIOTLB_FORCE;
+		x86_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;
  	}
  }
  #else

Thanks for working on this patch.

We ran into the same limitation where the SWIOTLB bounce buffer cannot be increased beyond 1GB without this change.

I reviewed the change and tested it on our setup. With this patch applied, we are able to successfully configure and use SWIOTLB bounce buffer size greater than 1GB, and the previous allocation failures are resolved.

Since, I wanted to bring more visibility to this patch.

Feel free to add

Thanks,
Aakarsh

author
#3 lore raw

Hi Aakarsh,

I’m glad to hear that this patch helps solve a real issue on your side, as this was also a problem I encountered. I appreciate your support and the Reviewed-by/Tested-by tags.

Hi Maintainers,
I am not sure whether I should send a v2 of the patch to add the Reviewed-by/Tested-by tags myself? or if the maintainer will add them when applying the patch ?

Also, if there are any incorrect or misleading descriptions in commit log? I would really appreciate your guidance and suggestions.

Thanks
Jun Miao

Quoted 37 lines

Hi Jun,

Quoted 15 lines · Jun Miao

TDX guest wants to allocate a swiotlb buffer that is not restricted to low memory for the trusted hypervisor scheme. So that allow to pick a location everywhere for hypervisors with guest memory encryption in swiotlb_memblock_alloc() interface by adding a new flag.

---
  arch/x86/kernel/pci-dma.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/pci-dma.c +0 -0
index 6267363e0189..73b9320c4a7d 100644

arch/x86/kernel/pci-dma.c static void __init pci_swiotlb_detect(void) · line 67

Quoted 8 lines
arch/x86/kernel/pci-dma.c +1 -1
@@ -61,7 +61,7 @@ static void __init pci_swiotlb_detect(void)
  	 */
  	if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) {
  		x86_swiotlb_enable = true;
-		x86_swiotlb_flags |= SWIOTLB_FORCE;
+		x86_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE;
  	}
  }
  #else

Thanks for working on this patch.

We ran into the same limitation where the SWIOTLB bounce buffer cannot be increased beyond 1GB without this change.

I reviewed the change and tested it on our setup. With this patch applied, we are able to successfully configure and use SWIOTLB bounce buffer size greater than 1GB, and the previous allocation failures are resolved.

Quoted 6 lines

Since, I wanted to bring more visibility to this patch.

Feel free to add

Hi Aakarsh,

I’m glad to hear that this patch helps solve a real issue on your side, as this was also a problem I encountered. I appreciate your support and the Reviewed-by/Tested-by tags.

Hi Maintainers,
I am not sure whether I should send a v2 of the patch to add the Reviewed-by/Tested-by tags myself? or if the maintainer will add them when applying the patch ?

Also, if there are any incorrect or misleading descriptions in commit log? I would really appreciate your guidance and suggestions.

Thanks
Jun Miao

Quoted 3 lines

Thanks,
Aakarsh