Skip to content

Commit a9cf8b6

Browse files
danglin44gregkh
authored andcommitted
parisc: Handle case where flush_cache_range is called with no context
commit 9ef0f88 upstream. Just when I had decided that flush_cache_range() was always called with a valid context, Helge reported two cases where the "BUG_ON(!vma->vm_mm->context);" was hit on the phantom buildd: kernel BUG at /mnt/sdb6/linux/linux-4.15.4/arch/parisc/kernel/cache.c:587! CPU: 1 PID: 3254 Comm: kworker/1:2 Tainted: G D 4.15.0-1-parisc64-smp #1 Debian 4.15.4-1+b1 Workqueue: events free_ioctx   IAOQ[0]: flush_cache_range+0x164/0x168   IAOQ[1]: flush_cache_page+0x0/0x1c8   RP(r2): unmap_page_range+0xae8/0xb88 Backtrace:   [<00000000404a6980>] unmap_page_range+0xae8/0xb88   [<00000000404a6ae0>] unmap_single_vma+0xc0/0x188   [<00000000404a6cdc>] zap_page_range_single+0x134/0x1f8   [<00000000404a702c>] unmap_mapping_range+0x1cc/0x208   [<0000000040461518>] truncate_pagecache+0x98/0x108   [<0000000040461624>] truncate_setsize+0x9c/0xb8   [<00000000405d7f30>] put_aio_ring_file+0x80/0x100   [<00000000405d803c>] aio_free_ring+0x8c/0x290   [<00000000405d82c0>] free_ioctx+0x80/0x180   [<0000000040284e6c>] process_one_work+0x21c/0x668   [<00000000402854c4>] worker_thread+0x20c/0x778   [<0000000040291d44>] kthread+0x2d4/0x2e0   [<0000000040204020>] end_fault_vector+0x20/0xc0 This indicates that we need to handle the no context case in flush_cache_range() as we do in flush_cache_mm(). In thinking about this, I realized that we don't need to flush the TLB when there is no context. So, I added context checks to the large flush cases in flush_cache_mm() and flush_cache_range(). The large flush case occurs frequently in flush_cache_mm() and the change should improve fork performance. The v2 version of this change removes the BUG_ON from flush_cache_page() by skipping the TLB flush when there is no context.  I also added code to flush the TLB in flush_cache_mm() and flush_cache_range() when we have a context that's not current.  Now all three routines handle TLB flushes in a similar manner. Signed-off-by: John David Anglin <dave.anglin@bell.net> Cc: stable@vger.kernel.org # 4.9+ Signed-off-by: Helge Deller <deller@gmx.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6fcb523 commit a9cf8b6

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

arch/parisc/kernel/cache.c

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,8 @@ void flush_cache_mm(struct mm_struct *mm)
543543
rp3440, etc. So, avoid it if the mm isn't too big. */
544544
if ((!IS_ENABLED(CONFIG_SMP) || !arch_irqs_disabled()) &&
545545
mm_total_size(mm) >= parisc_cache_flush_threshold) {
546-
flush_tlb_all();
546+
if (mm->context)
547+
flush_tlb_all();
547548
flush_cache_all();
548549
return;
549550
}
@@ -571,6 +572,8 @@ void flush_cache_mm(struct mm_struct *mm)
571572
pfn = pte_pfn(*ptep);
572573
if (!pfn_valid(pfn))
573574
continue;
575+
if (unlikely(mm->context))
576+
flush_tlb_page(vma, addr);
574577
__flush_cache_page(vma, addr, PFN_PHYS(pfn));
575578
}
576579
}
@@ -579,26 +582,46 @@ void flush_cache_mm(struct mm_struct *mm)
579582
void flush_cache_range(struct vm_area_struct *vma,
580583
unsigned long start, unsigned long end)
581584
{
585+
pgd_t *pgd;
586+
unsigned long addr;
587+
582588
if ((!IS_ENABLED(CONFIG_SMP) || !arch_irqs_disabled()) &&
583589
end - start >= parisc_cache_flush_threshold) {
584-
flush_tlb_range(vma, start, end);
590+
if (vma->vm_mm->context)
591+
flush_tlb_range(vma, start, end);
585592
flush_cache_all();
586593
return;
587594
}
588595

589-
flush_user_dcache_range_asm(start, end);
590-
if (vma->vm_flags & VM_EXEC)
591-
flush_user_icache_range_asm(start, end);
592-
flush_tlb_range(vma, start, end);
596+
if (vma->vm_mm->context == mfsp(3)) {
597+
flush_user_dcache_range_asm(start, end);
598+
if (vma->vm_flags & VM_EXEC)
599+
flush_user_icache_range_asm(start, end);
600+
flush_tlb_range(vma, start, end);
601+
return;
602+
}
603+
604+
pgd = vma->vm_mm->pgd;
605+
for (addr = vma->vm_start; addr < vma->vm_end; addr += PAGE_SIZE) {
606+
unsigned long pfn;
607+
pte_t *ptep = get_ptep(pgd, addr);
608+
if (!ptep)
609+
continue;
610+
pfn = pte_pfn(*ptep);
611+
if (pfn_valid(pfn)) {
612+
if (unlikely(vma->vm_mm->context))
613+
flush_tlb_page(vma, addr);
614+
__flush_cache_page(vma, addr, PFN_PHYS(pfn));
615+
}
616+
}
593617
}
594618

595619
void
596620
flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn)
597621
{
598-
BUG_ON(!vma->vm_mm->context);
599-
600622
if (pfn_valid(pfn)) {
601-
flush_tlb_page(vma, vmaddr);
623+
if (likely(vma->vm_mm->context))
624+
flush_tlb_page(vma, vmaddr);
602625
__flush_cache_page(vma, vmaddr, PFN_PHYS(pfn));
603626
}
604627
}

0 commit comments

Comments
 (0)