Skip to content

Commit 7db1541

Browse files
hdellerakpm00
authored andcommitted
nios2: fix flush_dcache_page() for usage from irq context
Since at least kernel 6.1, flush_dcache_page() is called with IRQs disabled, e.g. from aio_complete(). But the current implementation for flush_dcache_page() on NIOS2 unintentionally re-enables IRQs, which may lead to deadlocks. Fix it by using xa_lock_irqsave() and xa_unlock_irqrestore() for the flush_dcache_mmap_*lock() macros instead. Link: https://lkml.kernel.org/r/ZOTF5WWURQNH9+iw@p100 Signed-off-by: Helge Deller <deller@gmx.de> Cc: Dinh Nguyen <dinguyen@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 8cfd014 commit 7db1541

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

arch/nios2/include/asm/cacheflush.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,9 @@ extern void invalidate_dcache_range(unsigned long start, unsigned long end);
5252

5353
#define flush_dcache_mmap_lock(mapping) xa_lock_irq(&mapping->i_pages)
5454
#define flush_dcache_mmap_unlock(mapping) xa_unlock_irq(&mapping->i_pages)
55+
#define flush_dcache_mmap_lock_irqsave(mapping, flags) \
56+
xa_lock_irqsave(&mapping->i_pages, flags)
57+
#define flush_dcache_mmap_unlock_irqrestore(mapping, flags) \
58+
xa_unlock_irqrestore(&mapping->i_pages, flags)
5559

5660
#endif /* _ASM_NIOS2_CACHEFLUSH_H */

arch/nios2/mm/cacheflush.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ static void flush_aliases(struct address_space *mapping, struct folio *folio)
7575
{
7676
struct mm_struct *mm = current->active_mm;
7777
struct vm_area_struct *vma;
78+
unsigned long flags;
7879
pgoff_t pgoff;
7980
unsigned long nr = folio_nr_pages(folio);
8081

8182
pgoff = folio->index;
8283

83-
flush_dcache_mmap_lock(mapping);
84+
flush_dcache_mmap_lock_irqsave(mapping, flags);
8485
vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff + nr - 1) {
8586
unsigned long start;
8687

@@ -92,7 +93,7 @@ static void flush_aliases(struct address_space *mapping, struct folio *folio)
9293
start = vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT);
9394
flush_cache_range(vma, start, start + nr * PAGE_SIZE);
9495
}
95-
flush_dcache_mmap_unlock(mapping);
96+
flush_dcache_mmap_unlock_irqrestore(mapping, flags);
9697
}
9798

9899
void flush_cache_all(void)

0 commit comments

Comments
 (0)