From patchwork Wed Mar 7 13:18:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John David Anglin X-Patchwork-Id: 10264003 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B1983602C8 for ; Wed, 7 Mar 2018 13:18:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A000129502 for ; Wed, 7 Mar 2018 13:18:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9494B2950B; Wed, 7 Mar 2018 13:18:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_TVD_MIME_EPI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76F2B29502 for ; Wed, 7 Mar 2018 13:18:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754465AbeCGNSI (ORCPT ); Wed, 7 Mar 2018 08:18:08 -0500 Received: from belmont79srvr.owm.bell.net ([184.150.200.79]:49602 "EHLO mtlfep01.bell.net" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751241AbeCGNSH (ORCPT ); Wed, 7 Mar 2018 08:18:07 -0500 Received: from bell.net mtlfep01 184.150.200.30 by mtlfep01.bell.net with ESMTP id <20180307131806.SKXZ19887.mtlfep01.bell.net@mtlspm02.bell.net> for ; Wed, 7 Mar 2018 08:18:06 -0500 Received: from [192.168.2.49] (really [70.31.74.127]) by mtlspm02.bell.net with ESMTP id <20180307131806.ERKE6415.mtlspm02.bell.net@[192.168.2.49]>; Wed, 7 Mar 2018 08:18:06 -0500 To: linux-parisc@vger.kernel.org Cc: Helge Deller , James Bottomley From: John David Anglin Subject: [PATCH -v2] parisc: Handle case where flush_cache_range is called with no context Message-ID: Date: Wed, 7 Mar 2018 08:18:05 -0500 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 Content-Language: en-US X-Cloudmark-Analysis: v=2.2 cv=IaFoYSia c=1 sm=0 tr=0 a=exAxv0+L8MI61oIUChyxXA==:17 a=v2DPQv5-lfwA:10 a=r77TgQKjGQsHNAKrUKIA:9 a=FBHGMhGWAAAA:8 a=pAuehaiAPX9peDNzX_EA:9 a=QEXdDO2ut3YA:10 a=6men1qdiKKD22uL7hOAA:9 a=ichUEFZdvV4A:10 a=9gvnlMMaQFpL9xblJ6ne:22 Sender: linux-parisc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-parisc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 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)); } }