Thread (23 messages) 23 messages, 3 authors, 2022-03-16

Re: [PATCH 12/15] swiotlb: provide swiotlb_init variants that remap the buffer

From: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Date: 2022-03-14 22:41:32
Also in: linux-arm-kernel, linux-hyperv, linux-iommu, linux-mips, linux-pci, linux-riscv, linux-s390, xen-devel

On 3/14/22 3:31 AM, Christoph Hellwig wrote:
quoted hunk ↗ jump to hunk
-void __init swiotlb_init(bool addressing_limit, unsigned int flags)
+void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
+		int (*remap)(void *tlb, unsigned long nslabs))
  {
-	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
+	unsigned long nslabs = default_nslabs;
+	size_t bytes;
  	void *tlb;
  
  	if (!addressing_limit && !swiotlb_force_bounce)
@@ -271,12 +273,24 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
  	 * allow to pick a location everywhere for hypervisors with guest
  	 * memory encryption.
  	 */
+retry:
+	bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
  	if (flags & SWIOTLB_ANY)
  		tlb = memblock_alloc(bytes, PAGE_SIZE);
  	else
  		tlb = memblock_alloc_low(bytes, PAGE_SIZE);
  	if (!tlb)
  		goto fail;
+	if (remap && remap(tlb, nslabs) < 0) {
+		memblock_free(tlb, PAGE_ALIGN(bytes));
+
+		/* Min is 2MB */
+		if (nslabs <= 1024)

This is IO_TLB_MIN_SLABS, isn't it? (Xen code didn't say so but that's what it meant to say I believe)

quoted hunk ↗ jump to hunk
+			panic("%s: Failed to remap %zu bytes\n",
+			      __func__, bytes);
+		nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
+		goto retry;
+	}
@@ -303,6 +323,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
  	if (swiotlb_force_disable)
  		return 0;
  
+retry:
  	order = get_order(nslabs << IO_TLB_SHIFT);
  	nslabs = SLABS_PER_PAGE << order;
  	bytes = nslabs << IO_TLB_SHIFT;
@@ -317,6 +338,17 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask)
  
  	if (!vstart)
  		return -ENOMEM;
+	if (remap)
+		rc = remap(vstart, nslabs);
+	if (rc) {
+		free_pages((unsigned long)vstart, order);
+
+		/* Min is 2MB */
+		if (nslabs <= 1024)

Same here.


-boris

+			return rc;
+		nslabs = max(1024UL, ALIGN(nslabs >> 1, IO_TLB_SEGSIZE));
+		goto retry;
+	}
  
  	if (order != get_order(bytes)) {
  		pr_warn("only able to allocate %ld MB\n",
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help