[PATCH -v2] parisc: Handle case where flush_cache_range is called with no context

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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:

[549700.051761] NET: Registered protocol family 38
[552929.287236] systemd-logind[1672]: New session 11638 of user root.
[555698.899355] ------------[ cut here ]------------
[555698.955264] kernel BUG at /mnt/sdb6/linux/linux-4.15.4/arch/parisc/kernel/cache.c:587! [555699.051275] CPU: 1 PID: 3254 Comm: kworker/1:2 Tainted: G D          4.15.0-1-parisc64-smp #1 Debian 4.15.4-1+b1
[555699.179274] Workqueue: events free_ioctx

[555699.247243]      YZrvWESTHLNXBCVMcbcbcbcbOGFRQPDI
[555699.303248] PSW: 00001000000001001111111100001111 Tainted: G      D
[555699.391249] r00-03  000000ff0804ff0f 0000000040d22760 00000000404a6980 000000014a990b30 [555699.487249] r04-07  0000000040d01f60 00000000f40da000 00000000f40db000 00000041320c1ed8 [555699.583242] r08-11  000000014a9907e8 000000014a990728 000000014a990728 000000411617cd80 [555699.679256] r12-15  000000004107f150 0000000041080e48 0000000040d28760 0000000000000002 [555699.779246] r16-19  0000004133f50140 00000000f40da000 0000000066279900 00000000f40db000 [555699.875239] r20-23  00000000000044d5 fcfaa60000000000 000000014a990728 00000000f40db000 [555699.971239] r24-27  00000000f40db000 00000000f40da000 0000000008478800 0000000040d01f60 [555700.067237] r28-31  0000000007ac0000 000000014a990b00 000000014a990bd0 0000000000001000 [555700.167238] sr00-03  0000000007ac0000 0000000007ac0000 0000000007ac0000 0000000007ac0000 [555700.263236] sr04-07  0000000000000000 0000000000000000 0000000000000000 0000000000000000

[555700.379234] IASQ: 0000000000000000 0000000000000000 IAOQ: 000000004021c0b4 000000004021c0b8 [555700.483234]  IIR: 03ffe01f    ISR: 0000000000000000  IOR: 0000000000000000 [555700.567233]  CPU:        1   CR30: 000000014a990000 CR31: ffffffffffffffff
[555700.647233]  ORIG_R28: 0000000040d01f60
[555700.695237]  IAOQ[0]: flush_cache_range+0x164/0x168
[555700.755237]  IAOQ[1]: flush_cache_page+0x0/0x1c8
[555700.811240]  RP(r2): unmap_page_range+0xae8/0xb88
[555700.867231] Backtrace:
[555700.899249]  [<00000000404a6980>] unmap_page_range+0xae8/0xb88
[555700.971238]  [<00000000404a6ae0>] unmap_single_vma+0xc0/0x188
[555701.039238]  [<00000000404a6cdc>] zap_page_range_single+0x134/0x1f8
[555701.115240]  [<00000000404a702c>] unmap_mapping_range+0x1cc/0x208
[555701.191238]  [<0000000040461518>] truncate_pagecache+0x98/0x108
[555701.263239]  [<0000000040461624>] truncate_setsize+0x9c/0xb8
[555701.331263]  [<00000000405d7f30>] put_aio_ring_file+0x80/0x100
[555701.403238]  [<00000000405d803c>] aio_free_ring+0x8c/0x290
[555701.467236]  [<00000000405d82c0>] free_ioctx+0x80/0x180
[555701.531287]  [<0000000040284e6c>] process_one_work+0x21c/0x668
[555701.603237]  [<00000000402854c4>] worker_thread+0x20c/0x778
[555701.671235]  [<0000000040291d44>] kthread+0x2d4/0x2e0
[555701.735235]  [<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@xxxxxxxx>

diff --git a/arch/parisc/kernel/cache.c b/arch/parisc/kernel/cache.c
index 79089778725b..e3b45546d589 100644
--- a/arch/parisc/kernel/cache.c
+++ b/arch/parisc/kernel/cache.c
@@ -543,7 +543,8 @@ void flush_cache_mm(struct mm_struct *mm)
 	   rp3440, etc.  So, avoid it if the mm isn't too big.  */
 	if ((!IS_ENABLED(CONFIG_SMP) || !arch_irqs_disabled()) &&
 	    mm_total_size(mm) >= parisc_cache_flush_threshold) {
-		flush_tlb_all();
+		if (mm->context)
+			flush_tlb_all();
 		flush_cache_all();
 		return;
 	}
@@ -571,6 +572,8 @@ void flush_cache_mm(struct mm_struct *mm)
 			pfn = pte_pfn(*ptep);
 			if (!pfn_valid(pfn))
 				continue;
+			if (unlikely(mm->context))
+				flush_tlb_page(vma, addr);
 			__flush_cache_page(vma, addr, PFN_PHYS(pfn));
 		}
 	}
@@ -579,26 +582,46 @@ void flush_cache_mm(struct mm_struct *mm)
 void flush_cache_range(struct vm_area_struct *vma,
 		unsigned long start, unsigned long end)
 {
+	pgd_t *pgd;
+	unsigned long addr;
+
 	if ((!IS_ENABLED(CONFIG_SMP) || !arch_irqs_disabled()) &&
 	    end - start >= parisc_cache_flush_threshold) {
-		flush_tlb_range(vma, start, end);
+		if (vma->vm_mm->context)
+			flush_tlb_range(vma, start, end);
 		flush_cache_all();
 		return;
 	}
 
-	flush_user_dcache_range_asm(start, end);
-	if (vma->vm_flags & VM_EXEC)
-		flush_user_icache_range_asm(start, end);
-	flush_tlb_range(vma, start, end);
+	if (vma->vm_mm->context == mfsp(3)) {
+		flush_user_dcache_range_asm(start, end);
+		if (vma->vm_flags & VM_EXEC)
+			flush_user_icache_range_asm(start, end);
+		flush_tlb_range(vma, start, end);
+		return;
+	}
+
+	pgd = vma->vm_mm->pgd;
+	for (addr = vma->vm_start; addr < vma->vm_end; addr += PAGE_SIZE) {
+		unsigned long pfn;
+		pte_t *ptep = get_ptep(pgd, addr);
+		if (!ptep)
+			continue;
+		pfn = pte_pfn(*ptep);
+		if (pfn_valid(pfn)) {
+			if (unlikely(vma->vm_mm->context))
+				flush_tlb_page(vma, addr);
+			__flush_cache_page(vma, addr, PFN_PHYS(pfn));
+		}
+	}
 }
 
 void
 flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn)
 {
-	BUG_ON(!vma->vm_mm->context);
-
 	if (pfn_valid(pfn)) {
-		flush_tlb_page(vma, vmaddr);
+		if (likely(vma->vm_mm->context))
+			flush_tlb_page(vma, vmaddr);
 		__flush_cache_page(vma, vmaddr, PFN_PHYS(pfn));
 	}
 }

[Index of Archives]     [Linux SoC]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux