Skip to contentSkip to conversation

openrisc: Fix pagewalk usage in arch_dma_{clear, set}_uncached

PATCH In review Jann Horn 2 participants 2 messages Oct 8, 2022 Openrisc architecture

lore
Share & tools
lore

Jann Horn

author
#0 lore raw

PATCH 1/1 openrisc: Fix pagewalk usage in arch_dma_{clear, set}_uncached

Since commit 8782fb61cc848 ("mm: pagewalk: Fix race between unmap and page walker"), walk_page_range() on kernel ranges won't work anymore, walk_page_range_novma() must be used instead.

Note: I don't have an openrisc development setup, so this is completely untested.

Fixes 8782fb61cc848 ("mm: pagewalk: Fix race between unmap and page walker")

---
Normally I would CC stable on a patch like this, but openrisc is mostly an in-development thing, so fixing stable kernels doesn't matter much, I assume?

 arch/openrisc/kernel/dma.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
arch/openrisc/kernel/dma.c +8 -8
index a82b2caaa560d..b3edbb33b621d 100644
@@ -74,10 +74,10 @@ void *arch_dma_set_uncached(void *cpu_addr, size_t size)
 	 * We need to iterate through the pages, clearing the dcache for
 	 * them and setting the cache-inhibit bit.
 	 */
-	mmap_read_lock(&init_mm);
-	error = walk_page_range(&init_mm, va, va + size, &set_nocache_walk_ops,
-			NULL);
-	mmap_read_unlock(&init_mm);
+	mmap_write_lock(&init_mm);
+	error = walk_page_range_novma(&init_mm, va, va + size,
+			&set_nocache_walk_ops, NULL, NULL);
+	mmap_write_unlock(&init_mm);
 
 	if (error)
 		return ERR_PTR(error);
@@ -88,11 +88,11 @@ void arch_dma_clear_uncached(void *cpu_addr, size_t size)
 {
 	unsigned long va = (unsigned long)cpu_addr;
 
-	mmap_read_lock(&init_mm);
+	mmap_write_lock(&init_mm);
 	/* walk_page_range shouldn't be able to fail here */
-	WARN_ON(walk_page_range(&init_mm, va, va + size,
-			&clear_nocache_walk_ops, NULL));
-	mmap_read_unlock(&init_mm);
+	WARN_ON(walk_page_range_novma(&init_mm, va, va + size,
+			&clear_nocache_walk_ops, NULL, NULL));
+	mmap_write_unlock(&init_mm);
 }
 
 void arch_sync_dma_for_device(phys_addr_t addr, size_t size,

base-commit: 7e6739b9336e61fe23ca4e2c8d1fda8f19f979bf

Signature · 1 line
2.38.0.rc1.362.ged0d419d3c-goog
maintainer
#1 lore raw

Re: [PATCH] openrisc: Fix pagewalk usage in arch_dma_{clear,set}_uncached

Quoted 9 lines · Jann Horn

Since commit 8782fb61cc848 ("mm: pagewalk: Fix race between unmap and page walker"), walk_page_range() on kernel ranges won't work anymore, walk_page_range_novma() must be used instead.

Note: I don't have an openrisc development setup, so this is completely untested.

Fixes 8782fb61cc848 ("mm: pagewalk: Fix race between unmap and page walker")

This looks good to me, I will queue it for 6.1 fixes.

Quoted 3 lines

---
Normally I would CC stable on a patch like this, but openrisc is mostly an in-development thing, so fixing stable kernels doesn't matter much, I assume?

In general we try to keep stable releases stable buy backporting OpenRISC patches as well. Just having the 'Fixes' tag should trigger to get this patched backported to stable. We should at least cc the LKML though.

-Stafford

Quoted 43 lines
 arch/openrisc/kernel/dma.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
arch/openrisc/kernel/dma.c +8 -8
index a82b2caaa560d..b3edbb33b621d 100644
@@ -74,10 +74,10 @@ void *arch_dma_set_uncached(void *cpu_addr, size_t size)
 	 * We need to iterate through the pages, clearing the dcache for
 	 * them and setting the cache-inhibit bit.
 	 */
-	mmap_read_lock(&init_mm);
-	error = walk_page_range(&init_mm, va, va + size, &set_nocache_walk_ops,
-			NULL);
-	mmap_read_unlock(&init_mm);
+	mmap_write_lock(&init_mm);
+	error = walk_page_range_novma(&init_mm, va, va + size,
+			&set_nocache_walk_ops, NULL, NULL);
+	mmap_write_unlock(&init_mm);
 
 	if (error)
 		return ERR_PTR(error);
@@ -88,11 +88,11 @@ void arch_dma_clear_uncached(void *cpu_addr, size_t size)
 {
 	unsigned long va = (unsigned long)cpu_addr;
 
-	mmap_read_lock(&init_mm);
+	mmap_write_lock(&init_mm);
 	/* walk_page_range shouldn't be able to fail here */
-	WARN_ON(walk_page_range(&init_mm, va, va + size,
-			&clear_nocache_walk_ops, NULL));
-	mmap_read_unlock(&init_mm);
+	WARN_ON(walk_page_range_novma(&init_mm, va, va + size,
+			&clear_nocache_walk_ops, NULL, NULL));
+	mmap_write_unlock(&init_mm);
 }
 
 void arch_sync_dma_for_device(phys_addr_t addr, size_t size,

base-commit: 7e6739b9336e61fe23ca4e2c8d1fda8f19f979bf

Signature · 1 line
2.38.0.rc1.362.ged0d419d3c-goog