Skip to contentSkip to conversation

swiotlb: Fix debugfs reporting of reserved memory pools

PATCH Applied Michael Kelley 3 participants 3 messages Apr 13, 2023 – Apr 16, 2023 DMA mapping helpers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 swiotlb: Fix debugfs reporting of reserved memory pools

For io_tlb_nslabs, the debugfs code reports the correct value for a specific reserved memory pool. But for io_tlb_used, the value reported is always for the default pool, not the specific reserved pool. Fix this.

Fixes 5c850d31880e ("swiotlb: fix passing local variable to debugfs_create_ulong()")

---

I don't have a way to test this directly with OF reserved memory, but I cobbled together a hack to call rmem_swiotlb_device_init() multiple times for different size reserved pools. I verified that reserved pool debugfs entries are created as expected and that the value of io_tlb_used is *not* the value from the default pool.

 kernel/dma/swiotlb.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/dma/swiotlb.c +4 -2
index dac42a2..db43de82 100644
@@ -930,7 +930,9 @@ bool is_swiotlb_active(struct device *dev)
 
 static int io_tlb_used_get(void *data, u64 *val)
 {
-	*val = mem_used(&io_tlb_default_mem);
+	struct io_tlb_mem *mem = data;
+
+	*val = mem_used(mem);
 	return 0;
 }
 DEFINE_DEBUGFS_ATTRIBUTE(fops_io_tlb_used, io_tlb_used_get, NULL, "%llu\n");
@@ -943,7 +945,7 @@ static void swiotlb_create_debugfs_files(struct io_tlb_mem *mem,
 		return;
 
 	debugfs_create_ulong("io_tlb_nslabs", 0400, mem->debugfs, &mem->nslabs);
-	debugfs_create_file("io_tlb_used", 0400, mem->debugfs, NULL,
+	debugfs_create_file("io_tlb_used", 0400, mem->debugfs, mem,
 			&fops_io_tlb_used);
 }
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 6 lines · On Thu, 13 Apr 2023 08:37:30 -0700 Michael Kelley <[email protected]>…

For io_tlb_nslabs, the debugfs code reports the correct value for a specific reserved memory pool. But for io_tlb_used, the value reported is always for the default pool, not the specific reserved pool. Fix this.

Fixes 5c850d31880e ("swiotlb: fix passing local variable to debugfs_create_ulong()")
Quoted 7 lines

---

I don't have a way to test this directly with OF reserved memory, but I cobbled together a hack to call rmem_swiotlb_device_init() multiple times for different size reserved pools. I verified that reserved pool debugfs entries are created as expected and that the value of io_tlb_used is *not* the value from the default pool.

Yeah, the only in-tree user is Mediatek Asurada, and I don't have one either...

The patch looks good to me. But you know, I'm now well-known for breaking things because of insufficient testing. ;-)

Petr T

Quoted 28 lines
 kernel/dma/swiotlb.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/dma/swiotlb.c +3 -1
index dac42a2..db43de82 100644
@@ -930,7 +930,9 @@ bool is_swiotlb_active(struct device *dev)
 
 static int io_tlb_used_get(void *data, u64 *val)
 {
-	*val = mem_used(&io_tlb_default_mem);
+	struct io_tlb_mem *mem = data;
+
+	*val = mem_used(mem);
 	return 0;
 }
 DEFINE_DEBUGFS_ATTRIBUTE(fops_io_tlb_used, io_tlb_used_get, NULL,

"%llu\n"); @@ -943,7 +945,7 @@ static void swiotlb_create_debugfs_files(struct io_tlb_mem *mem, return;

debugfs_create_ulong("io_tlb_nslabs", 0400, mem->debugfs,
&mem->nslabs);

kernel/dma/swiotlb.c +1 -1
-	debugfs_create_file("io_tlb_used", 0400, mem->debugfs, NULL,
+	debugfs_create_file("io_tlb_used", 0400, mem->debugfs, mem,
 			&fops_io_tlb_used);
 }