xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* cleanup and fix swiotlb sizing
@ 2021-04-22  7:19 Christoph Hellwig
  2021-04-22  7:19 ` [PATCH 1/7] swiotlb: pass bytes instead of nslabs to swiotlb_init_with_tbl Christoph Hellwig
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: Christoph Hellwig @ 2021-04-22  7:19 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: Tom Lendacky, Thomas Bogendoerfer, Michael Ellerman,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, linux-mips,
	linuxppc-dev, xen-devel, iommu

Hi all,

based on a report from Tom that overriding the default sizing provided
by the x86 SEV code on the command line doesn't work anymore, this series
cleans up how we handle default and command line sizes for the swiotlb
buffer and then fixes the recently introduced bug in a straight-forward
way.

Diffstat:
 arch/mips/cavium-octeon/dma-octeon.c      |   16 +--------------
 arch/mips/include/asm/octeon/pci-octeon.h |    1 
 arch/mips/pci/pci-octeon.c                |    2 -
 arch/powerpc/platforms/pseries/svm.c      |   13 ++----------
 drivers/xen/swiotlb-xen.c                 |    2 -
 include/linux/swiotlb.h                   |    2 -
 kernel/dma/swiotlb.c                      |   32 +++++++++++++++---------------
 7 files changed, 25 insertions(+), 43 deletions(-)


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/7] swiotlb: pass bytes instead of nslabs to swiotlb_init_with_tbl
  2021-04-22  7:19 cleanup and fix swiotlb sizing Christoph Hellwig
@ 2021-04-22  7:19 ` Christoph Hellwig
  2021-04-22  7:19 ` [PATCH 2/7] swiotlb: use swiotlb_size_or_default in swiotlb_init Christoph Hellwig
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2021-04-22  7:19 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: Tom Lendacky, Thomas Bogendoerfer, Michael Ellerman,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, linux-mips,
	linuxppc-dev, xen-devel, iommu

Pass the actual allocation size to swiotlb_init_with_tbl, which
simplifies things quite a bit.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/mips/cavium-octeon/dma-octeon.c |  2 +-
 arch/powerpc/platforms/pseries/svm.c |  3 +--
 drivers/xen/swiotlb-xen.c            |  2 +-
 include/linux/swiotlb.h              |  2 +-
 kernel/dma/swiotlb.c                 | 10 +++++-----
 5 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index df70308db0e697..020b8ce5b8ff7c 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -245,6 +245,6 @@ void __init plat_swiotlb_setup(void)
 		panic("%s: Failed to allocate %zu bytes align=%lx\n",
 		      __func__, swiotlbsize, PAGE_SIZE);
 
-	if (swiotlb_init_with_tbl(octeon_swiotlb, swiotlb_nslabs, 1) == -ENOMEM)
+	if (swiotlb_init_with_tbl(octeon_swiotlb, swiotlbsize, 1) == -ENOMEM)
 		panic("Cannot allocate SWIOTLB buffer");
 }
diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
index 1d829e257996fb..4d281ff56ce96f 100644
--- a/arch/powerpc/platforms/pseries/svm.c
+++ b/arch/powerpc/platforms/pseries/svm.c
@@ -52,10 +52,9 @@ void __init svm_swiotlb_init(void)
 	bytes = io_tlb_nslabs << IO_TLB_SHIFT;
 
 	vstart = memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE);
-	if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, false))
+	if (vstart && !swiotlb_init_with_tbl(vstart, bytes, false))
 		return;
 
-
 	memblock_free_early(__pa(vstart),
 			    PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT));
 	panic("SVM: Cannot allocate SWIOTLB buffer");
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index 4c89afc0df6289..18d79f07b507ce 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -249,7 +249,7 @@ void __init xen_swiotlb_init_early(void)
 		panic("%s (rc:%d)", xen_swiotlb_error(XEN_SWIOTLB_EFIXUP), rc);
 	}
 
-	if (swiotlb_init_with_tbl(start, nslabs, false))
+	if (swiotlb_init_with_tbl(start, bytes, false))
 		panic("Cannot allocate SWIOTLB buffer");
 	swiotlb_set_max_segment(PAGE_SIZE);
 }
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index 216854a5e5134b..d1d40ca5014b54 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -36,7 +36,7 @@ enum swiotlb_force {
 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
 
 extern void swiotlb_init(int verbose);
-int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
+int swiotlb_init_with_tbl(char *tlb, size_t bytes, int verbose);
 unsigned long swiotlb_size_or_default(void);
 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
 extern int swiotlb_late_init_with_default_size(size_t default_size);
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 0a5b6f7e75bce6..c7b3dd86db7f56 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -166,9 +166,9 @@ void __init swiotlb_update_mem_attributes(void)
 	memset(vaddr, 0, bytes);
 }
 
-int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
+int __init swiotlb_init_with_tbl(char *tlb, size_t bytes, int verbose)
 {
-	unsigned long bytes = nslabs << IO_TLB_SHIFT, i;
+	unsigned long nslabs = bytes >> IO_TLB_SHIFT, i;
 	struct io_tlb_mem *mem;
 	size_t alloc_size;
 
@@ -209,17 +209,17 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 void  __init
 swiotlb_init(int verbose)
 {
-	size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
+	size_t bytes = default_nslabs << IO_TLB_SHIFT;
 	void *tlb;
 
 	if (swiotlb_force == SWIOTLB_NO_FORCE)
 		return;
 
 	/* Get IO TLB memory from the low pages */
-	tlb = memblock_alloc_low(bytes, PAGE_SIZE);
+	tlb = memblock_alloc_low(PAGE_ALIGN(bytes), PAGE_SIZE);
 	if (!tlb)
 		goto fail;
-	if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))
+	if (swiotlb_init_with_tbl(tlb, bytes, verbose))
 		goto fail_free_mem;
 	return;
 
-- 
2.30.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/7] swiotlb: use swiotlb_size_or_default in swiotlb_init
  2021-04-22  7:19 cleanup and fix swiotlb sizing Christoph Hellwig
  2021-04-22  7:19 ` [PATCH 1/7] swiotlb: pass bytes instead of nslabs to swiotlb_init_with_tbl Christoph Hellwig
@ 2021-04-22  7:19 ` Christoph Hellwig
  2021-04-22  7:19 ` [PATCH 3/7] swiotlb: use swiotlb_adjust_size in setup_io_tlb_npages Christoph Hellwig
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2021-04-22  7:19 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: Tom Lendacky, Thomas Bogendoerfer, Michael Ellerman,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, linux-mips,
	linuxppc-dev, xen-devel, iommu

Use swiotlb_size_or_default to calculate the buffer size insted of
open coding it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 kernel/dma/swiotlb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index c7b3dd86db7f56..27461fd63e0330 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -209,7 +209,7 @@ int __init swiotlb_init_with_tbl(char *tlb, size_t bytes, int verbose)
 void  __init
 swiotlb_init(int verbose)
 {
-	size_t bytes = default_nslabs << IO_TLB_SHIFT;
+	size_t bytes = swiotlb_size_or_default();
 	void *tlb;
 
 	if (swiotlb_force == SWIOTLB_NO_FORCE)
-- 
2.30.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/7] swiotlb: use swiotlb_adjust_size in setup_io_tlb_npages
  2021-04-22  7:19 cleanup and fix swiotlb sizing Christoph Hellwig
  2021-04-22  7:19 ` [PATCH 1/7] swiotlb: pass bytes instead of nslabs to swiotlb_init_with_tbl Christoph Hellwig
  2021-04-22  7:19 ` [PATCH 2/7] swiotlb: use swiotlb_size_or_default in swiotlb_init Christoph Hellwig
@ 2021-04-22  7:19 ` Christoph Hellwig
  2021-04-22  7:19 ` [PATCH 4/7] powerpc/pseries: simplify svm_swiotlb_init Christoph Hellwig
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2021-04-22  7:19 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: Tom Lendacky, Thomas Bogendoerfer, Michael Ellerman,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, linux-mips,
	linuxppc-dev, xen-devel, iommu

Use the proper helper to do the proper alignment of the buffer size
to the requirements of the swiotlb allocator instead of open coding
the logic.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 kernel/dma/swiotlb.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 27461fd63e0330..93737d0932fbf2 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -76,11 +76,9 @@ static unsigned long default_nslabs = IO_TLB_DEFAULT_SIZE >> IO_TLB_SHIFT;
 static int __init
 setup_io_tlb_npages(char *str)
 {
-	if (isdigit(*str)) {
-		/* avoid tail segment of size < IO_TLB_SEGSIZE */
-		default_nslabs =
-			ALIGN(simple_strtoul(str, &str, 0), IO_TLB_SEGSIZE);
-	}
+	if (isdigit(*str))
+		swiotlb_adjust_size(
+			simple_strtoul(str, &str, 0) << IO_TLB_SHIFT);
 	if (*str == ',')
 		++str;
 	if (!strcmp(str, "force"))
-- 
2.30.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 4/7] powerpc/pseries: simplify svm_swiotlb_init
  2021-04-22  7:19 cleanup and fix swiotlb sizing Christoph Hellwig
                   ` (2 preceding siblings ...)
  2021-04-22  7:19 ` [PATCH 3/7] swiotlb: use swiotlb_adjust_size in setup_io_tlb_npages Christoph Hellwig
@ 2021-04-22  7:19 ` Christoph Hellwig
  2021-04-22  7:19 ` [PATCH 5/7] MIPS/octeon: simplify swiotlb initialization Christoph Hellwig
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2021-04-22  7:19 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: Tom Lendacky, Thomas Bogendoerfer, Michael Ellerman,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, linux-mips,
	linuxppc-dev, xen-devel, iommu

The value returned by swiotlb_size_or_default is always properly
aligned now, so don't duplicate the work.

Signed-off-by: Christoph Hellwig <hch@lst.de>dddd
---
 arch/powerpc/platforms/pseries/svm.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/svm.c b/arch/powerpc/platforms/pseries/svm.c
index 4d281ff56ce96f..9187d2a1ed568d 100644
--- a/arch/powerpc/platforms/pseries/svm.c
+++ b/arch/powerpc/platforms/pseries/svm.c
@@ -43,20 +43,14 @@ machine_early_initcall(pseries, init_svm);
  */
 void __init svm_swiotlb_init(void)
 {
+	unsigned long bytes = swiotlb_size_or_default();
 	unsigned char *vstart;
-	unsigned long bytes, io_tlb_nslabs;
-
-	io_tlb_nslabs = (swiotlb_size_or_default() >> IO_TLB_SHIFT);
-	io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
-
-	bytes = io_tlb_nslabs << IO_TLB_SHIFT;
 
 	vstart = memblock_alloc(PAGE_ALIGN(bytes), PAGE_SIZE);
 	if (vstart && !swiotlb_init_with_tbl(vstart, bytes, false))
 		return;
 
-	memblock_free_early(__pa(vstart),
-			    PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT));
+	memblock_free_early(__pa(vstart), PAGE_ALIGN(bytes));
 	panic("SVM: Cannot allocate SWIOTLB buffer");
 }
 
-- 
2.30.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 5/7] MIPS/octeon: simplify swiotlb initialization
  2021-04-22  7:19 cleanup and fix swiotlb sizing Christoph Hellwig
                   ` (3 preceding siblings ...)
  2021-04-22  7:19 ` [PATCH 4/7] powerpc/pseries: simplify svm_swiotlb_init Christoph Hellwig
@ 2021-04-22  7:19 ` Christoph Hellwig
  2021-04-22  7:19 ` [PATCH 6/7] swiotlb: replace default_nslabs with a byte value Christoph Hellwig
  2021-04-22  7:19 ` [PATCH 7/7] swiotlb: don't override the command line in swiotlb_adjust_size Christoph Hellwig
  6 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2021-04-22  7:19 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: Tom Lendacky, Thomas Bogendoerfer, Michael Ellerman,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, linux-mips,
	linuxppc-dev, xen-devel, iommu

Just use swiotlb_adjust_size and swiotlb_init to initialize
swiotlb instead of doing a lot of manual work.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/mips/cavium-octeon/dma-octeon.c      | 16 ++--------------
 arch/mips/include/asm/octeon/pci-octeon.h |  1 -
 arch/mips/pci/pci-octeon.c                |  2 +-
 3 files changed, 3 insertions(+), 16 deletions(-)

diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
index 020b8ce5b8ff7c..6bc9ef5e3790ec 100644
--- a/arch/mips/cavium-octeon/dma-octeon.c
+++ b/arch/mips/cavium-octeon/dma-octeon.c
@@ -186,15 +186,12 @@ phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
 	return daddr;
 }
 
-char *octeon_swiotlb;
-
 void __init plat_swiotlb_setup(void)
 {
 	phys_addr_t start, end;
 	phys_addr_t max_addr;
 	phys_addr_t addr_size;
 	size_t swiotlbsize;
-	unsigned long swiotlb_nslabs;
 	u64 i;
 
 	max_addr = 0;
@@ -236,15 +233,6 @@ void __init plat_swiotlb_setup(void)
 	if (OCTEON_IS_OCTEON2() && max_addr >= 0x100000000ul)
 		swiotlbsize = 64 * (1<<20);
 #endif
-	swiotlb_nslabs = swiotlbsize >> IO_TLB_SHIFT;
-	swiotlb_nslabs = ALIGN(swiotlb_nslabs, IO_TLB_SEGSIZE);
-	swiotlbsize = swiotlb_nslabs << IO_TLB_SHIFT;
-
-	octeon_swiotlb = memblock_alloc_low(swiotlbsize, PAGE_SIZE);
-	if (!octeon_swiotlb)
-		panic("%s: Failed to allocate %zu bytes align=%lx\n",
-		      __func__, swiotlbsize, PAGE_SIZE);
-
-	if (swiotlb_init_with_tbl(octeon_swiotlb, swiotlbsize, 1) == -ENOMEM)
-		panic("Cannot allocate SWIOTLB buffer");
+	swiotlb_adjust_size(swiotlbsize);
+	swiotlb_init(false);
 }
diff --git a/arch/mips/include/asm/octeon/pci-octeon.h b/arch/mips/include/asm/octeon/pci-octeon.h
index b12d9a3fbfb6c0..a2f20a44fb6143 100644
--- a/arch/mips/include/asm/octeon/pci-octeon.h
+++ b/arch/mips/include/asm/octeon/pci-octeon.h
@@ -64,6 +64,5 @@ enum octeon_dma_bar_type {
 extern enum octeon_dma_bar_type octeon_dma_bar_type;
 
 void octeon_pci_dma_init(void);
-extern char *octeon_swiotlb;
 
 #endif
diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
index fc29b85cfa926d..ff26cd9dc083f6 100644
--- a/arch/mips/pci/pci-octeon.c
+++ b/arch/mips/pci/pci-octeon.c
@@ -664,7 +664,7 @@ static int __init octeon_pci_setup(void)
 
 		/* BAR1 movable regions contiguous to cover the swiotlb */
 		octeon_bar1_pci_phys =
-			virt_to_phys(octeon_swiotlb) & ~((1ull << 22) - 1);
+			io_tlb_default_mem->start & ~((1ull << 22) - 1);
 
 		for (index = 0; index < 32; index++) {
 			union cvmx_pci_bar1_indexx bar1_index;
-- 
2.30.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 6/7] swiotlb: replace default_nslabs with a byte value
  2021-04-22  7:19 cleanup and fix swiotlb sizing Christoph Hellwig
                   ` (4 preceding siblings ...)
  2021-04-22  7:19 ` [PATCH 5/7] MIPS/octeon: simplify swiotlb initialization Christoph Hellwig
@ 2021-04-22  7:19 ` Christoph Hellwig
  2021-04-22  7:19 ` [PATCH 7/7] swiotlb: don't override the command line in swiotlb_adjust_size Christoph Hellwig
  6 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2021-04-22  7:19 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: Tom Lendacky, Thomas Bogendoerfer, Michael Ellerman,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, linux-mips,
	linuxppc-dev, xen-devel, iommu

Replace the default_nslabs variable with one that stores the size in
bytes as that is what all the users actually expect.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 kernel/dma/swiotlb.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 93737d0932fbf2..87d06ddf4753f3 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -71,7 +71,7 @@ struct io_tlb_mem *io_tlb_default_mem;
  */
 static unsigned int max_segment;
 
-static unsigned long default_nslabs = IO_TLB_DEFAULT_SIZE >> IO_TLB_SHIFT;
+static unsigned long swiotlb_default_size = IO_TLB_DEFAULT_SIZE;
 
 static int __init
 setup_io_tlb_npages(char *str)
@@ -106,7 +106,7 @@ void swiotlb_set_max_segment(unsigned int val)
 
 unsigned long swiotlb_size_or_default(void)
 {
-	return default_nslabs << IO_TLB_SHIFT;
+	return swiotlb_default_size;
 }
 
 void __init swiotlb_adjust_size(unsigned long size)
@@ -116,9 +116,9 @@ void __init swiotlb_adjust_size(unsigned long size)
 	 * architectures such as those supporting memory encryption to
 	 * adjust/expand SWIOTLB size for their use.
 	 */
-	size = ALIGN(size, IO_TLB_SIZE);
-	default_nslabs = ALIGN(size >> IO_TLB_SHIFT, IO_TLB_SEGSIZE);
-	pr_info("SWIOTLB bounce buffer size adjusted to %luMB", size >> 20);
+	swiotlb_default_size = ALIGN(size, IO_TLB_SEGSIZE << IO_TLB_SHIFT);
+	pr_info("SWIOTLB bounce buffer size adjusted to %luMB",
+		swiotlb_default_size >> 20);
 }
 
 void swiotlb_print_info(void)
-- 
2.30.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 7/7] swiotlb: don't override the command line in swiotlb_adjust_size
  2021-04-22  7:19 cleanup and fix swiotlb sizing Christoph Hellwig
                   ` (5 preceding siblings ...)
  2021-04-22  7:19 ` [PATCH 6/7] swiotlb: replace default_nslabs with a byte value Christoph Hellwig
@ 2021-04-22  7:19 ` Christoph Hellwig
  2021-04-23  5:23   ` Tom Lendacky
  6 siblings, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2021-04-22  7:19 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: Tom Lendacky, Thomas Bogendoerfer, Michael Ellerman,
	Boris Ostrovsky, Juergen Gross, Stefano Stabellini, linux-mips,
	linuxppc-dev, xen-devel, iommu

When the user specified an explicit swiotlb size on the command line,
the achitecture code should not override it.

Fixes: 2cbc2776efe4 ("swiotlb: remove swiotlb_nr_tbl")
Reported-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 kernel/dma/swiotlb.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 87d06ddf4753f3..aef02a3825b494 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -106,7 +106,9 @@ void swiotlb_set_max_segment(unsigned int val)
 
 unsigned long swiotlb_size_or_default(void)
 {
-	return swiotlb_default_size;
+	if (swiotlb_default_size)
+		return swiotlb_default_size;
+	return IO_TLB_DEFAULT_SIZE;
 }
 
 void __init swiotlb_adjust_size(unsigned long size)
@@ -116,6 +118,8 @@ void __init swiotlb_adjust_size(unsigned long size)
 	 * architectures such as those supporting memory encryption to
 	 * adjust/expand SWIOTLB size for their use.
 	 */
+	if (swiotlb_default_size)
+		return;
 	swiotlb_default_size = ALIGN(size, IO_TLB_SEGSIZE << IO_TLB_SHIFT);
 	pr_info("SWIOTLB bounce buffer size adjusted to %luMB",
 		swiotlb_default_size >> 20);
-- 
2.30.1



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 7/7] swiotlb: don't override the command line in swiotlb_adjust_size
  2021-04-22  7:19 ` [PATCH 7/7] swiotlb: don't override the command line in swiotlb_adjust_size Christoph Hellwig
@ 2021-04-23  5:23   ` Tom Lendacky
  0 siblings, 0 replies; 9+ messages in thread
From: Tom Lendacky @ 2021-04-23  5:23 UTC (permalink / raw)
  To: Christoph Hellwig, Konrad Rzeszutek Wilk
  Cc: Thomas Bogendoerfer, Michael Ellerman, Boris Ostrovsky,
	Juergen Gross, Stefano Stabellini, linux-mips, linuxppc-dev,
	xen-devel, iommu

On 4/22/21 2:19 AM, Christoph Hellwig wrote:
> When the user specified an explicit swiotlb size on the command line,
> the achitecture code should not override it.
> 
> Fixes: 2cbc2776efe4 ("swiotlb: remove swiotlb_nr_tbl")
> Reported-by: Tom Lendacky <thomas.lendacky@amd.com>
> Signed-off-by: Christoph Hellwig <hch@lst.de>

I tested this patchset and I'm not able to get the override via the
command line or via the SEV adjustment function. Looking at the code,
swiotlb_default_size is initialized, so the call to swiotlb_adjust_size()
always returns without setting the new size.

Thanks,
Tom

> ---
>  kernel/dma/swiotlb.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 87d06ddf4753f3..aef02a3825b494 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -106,7 +106,9 @@ void swiotlb_set_max_segment(unsigned int val)
>  
>  unsigned long swiotlb_size_or_default(void)
>  {
> -	return swiotlb_default_size;
> +	if (swiotlb_default_size)
> +		return swiotlb_default_size;
> +	return IO_TLB_DEFAULT_SIZE;
>  }
>  
>  void __init swiotlb_adjust_size(unsigned long size)
> @@ -116,6 +118,8 @@ void __init swiotlb_adjust_size(unsigned long size)
>  	 * architectures such as those supporting memory encryption to
>  	 * adjust/expand SWIOTLB size for their use.
>  	 */
> +	if (swiotlb_default_size)
> +		return;
>  	swiotlb_default_size = ALIGN(size, IO_TLB_SEGSIZE << IO_TLB_SHIFT);
>  	pr_info("SWIOTLB bounce buffer size adjusted to %luMB",
>  		swiotlb_default_size >> 20);
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-04-23  5:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-22  7:19 cleanup and fix swiotlb sizing Christoph Hellwig
2021-04-22  7:19 ` [PATCH 1/7] swiotlb: pass bytes instead of nslabs to swiotlb_init_with_tbl Christoph Hellwig
2021-04-22  7:19 ` [PATCH 2/7] swiotlb: use swiotlb_size_or_default in swiotlb_init Christoph Hellwig
2021-04-22  7:19 ` [PATCH 3/7] swiotlb: use swiotlb_adjust_size in setup_io_tlb_npages Christoph Hellwig
2021-04-22  7:19 ` [PATCH 4/7] powerpc/pseries: simplify svm_swiotlb_init Christoph Hellwig
2021-04-22  7:19 ` [PATCH 5/7] MIPS/octeon: simplify swiotlb initialization Christoph Hellwig
2021-04-22  7:19 ` [PATCH 6/7] swiotlb: replace default_nslabs with a byte value Christoph Hellwig
2021-04-22  7:19 ` [PATCH 7/7] swiotlb: don't override the command line in swiotlb_adjust_size Christoph Hellwig
2021-04-23  5:23   ` Tom Lendacky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).