From patchwork Wed Jul 25 14:06:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 10544077 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 269AB9093 for ; Wed, 25 Jul 2018 14:13:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 130CF2A0A9 for ; Wed, 25 Jul 2018 14:13:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 069612A0B5; Wed, 25 Jul 2018 14:13:28 +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=-0.4 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,SUSPICIOUS_RECIPS autolearn=no version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 93C912A0AA for ; Wed, 25 Jul 2018 14:13:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=bSf7QPgWBhNorjlkpK7SvaRTche44kQTXXIR1rFhxlU=; b=VIUJzi50N2CHmf9f9u6Hrme8Em HEJM+icuu16Pmnf24Gno85a7GA1NSvGcZ1zEBeyFI+ZRdpbNF0ddAGjL3syAd61zRmsqTQbyujbql N9B8nJS7LbJGLPAyfboQ96vGaNYBnFXm0tk+WB80FXPhxkBi3B7H5rNc5g5ty1Fm19jUda/9g2qu9 MW1YJeBNQ/xrmFmVvauBCq8e71J6lGp2uL6hi0zvIs6X5z6NVppwRSOdz/BdO+5UZadel4DyZLmRx bRoVa7x4tWczOLSeb3RzM4BdxnlGpmbUU0SF3nEPGq7j0UMkn4ZYTcby1Ly9YHzU1SK0flufY2XQZ mPl0UPvw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fiKXa-00071l-49; Wed, 25 Jul 2018 14:13:22 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fiKXY-00071G-32 for linux-arm-kernel@bombadil.infradead.org; Wed, 25 Jul 2018 14:13:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=bEa2VC1PhTklj7TrxhDQMGrxkMdS1Gq+3HFfcqOkvaE=; b=yzXyb5IbukMpd1bXdec06lZ5B E5xJ9srLxOcfIGs+6ZoFQfRO7uWO08DP2W+WdeyqXaRkzK41RWS0z0kH+s3bnXBNx6Cd/0mekRqOO /CGqg61qPKAG7dHQgfSJmW/xLQI70smaHrQWuSE3WXRNMs2oqAwjzO3Iy1LVBm0KzXI8hSxkFDWn/ LcD8XeaoWFFEl9kvvCqs1C9wCFGdmO0QA1jrtJWy9BgFxnv5KgYKMYmmAlC979aLq1CiVUcIV/wMn fkkxcvjaoWAUD+yQ0t1wb8jTWluKjnutr46ZivCvdq5AvhwxJ0lLQNqqIEagDmroMJuifTuRTQh85 jyDcJBcqw==; Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fiKXU-0002ZP-Uz for linux-arm-kernel@lists.infradead.org; Wed, 25 Jul 2018 14:13:18 +0000 Received: by mail-pg1-x542.google.com with SMTP id e6-v6so5418998pgv.2 for ; Wed, 25 Jul 2018 07:13:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bEa2VC1PhTklj7TrxhDQMGrxkMdS1Gq+3HFfcqOkvaE=; b=s/oaPYvUXPdAEv1dgAf1aUK8hLBsA4DKGN5fR0/nvxAdQrOg3/KjjiNtDOA7QaQXWz NEzTiowWzU3LAgvm7OI0XcufZkXEoHCS6LVDtWDQvm18bpOnMwPHS52W4Qso3tHkoyi5 B8iSqrksRtRCUClCWEVLQGu7XgPhGCEREcWB8BIKl0cm4A2dJig9mDzc78FAgmxeSQ5c ic7WTfiRxTcuCnUU9DfhJxF/CiyT/PYxg80ATjMSUXRcnQdbkDn3u+352F83n3lZq342 /IGaDM9kJ27wVD5LcdiBh5wbGEtAdF1CVwRIiD1Hk89zzAJK9ARB+44ObGUaSgoxkWDZ aKgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bEa2VC1PhTklj7TrxhDQMGrxkMdS1Gq+3HFfcqOkvaE=; b=iHxinQlOqoZBbn5Z3lx/QNtMZUcvRu2wmTrZC+WK1Wzs/2ikSxNSpzLvbIy5bEwe4d Jet6wIFTh5sokm21zVGNM6CUeqi1OxZvE7yHBp/yuE+pOPntzbc9MbxUWpN3ZsWJEzci H4Lh5BcVtbGo8RIXJEuJ2MFu19g/fyA0vk5dbp5gQf50dcNANYM3LLJSPZQjaKShh1Ck Ym51oSo+IjFmdI/5oBYQprGqkPQOBF9O6slcbMpc2/2IVbv3Tm8pg2b04b0l2an3tWZa dl5ScVFAmNv8FpUy/MlX6Z3kFiFbsNiXruqDSLbLPUaa/KP3hZwlERHGwyPM5bujgXO3 0Z1g== X-Gm-Message-State: AOUpUlEiq1YCujf+B7S8d9J9a1bJ7pc24Ru6w9+rgXhUdCCYiE02zUb1 bQlHMevh0H21Bv95eMP8wUk= X-Google-Smtp-Source: AAOMgpcAXooHLfepiFNZvQ1EZXOE1oPa36WafIdHB3mJLvOw0mOJ8azm5i49n1gtoOVCew/36zGZlA== X-Received: by 2002:a65:660a:: with SMTP id w10-v6mr20323698pgv.366.1532527626243; Wed, 25 Jul 2018 07:07:06 -0700 (PDT) Received: from roar.au.ibm.com ([61.69.188.107]) by smtp.gmail.com with ESMTPSA id d132-v6sm20923421pga.10.2018.07.25.07.07.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Jul 2018 07:07:05 -0700 (PDT) From: Nicholas Piggin To: linux-mm@kvack.org Subject: [RFC PATCH 4/4] powerpc/64s/radix: optimise TLB flush with precise TLB ranges in mmu_gather Date: Thu, 26 Jul 2018 00:06:41 +1000 Message-Id: <20180725140641.30372-5-npiggin@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180725140641.30372-1-npiggin@gmail.com> References: <20180725140641.30372-1-npiggin@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180725_101317_105709_A51AE932 X-CRM114-Status: GOOD ( 20.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, Nicholas Piggin MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The mmu_gather APIs keep track of the invalidated address range, and the generic page table freeing accessors expand the invalidated range to cover the addresses corresponding to the page tables even if there are no ptes and therefore no TLB entries to invalidate. This is done for architectures that have paging structure caches that are invalidated with their TLB invalidate instructions (e.g., x86). powerpc/64s/radix does have a "page walk cache" (PWC), but it is invalidated with a specific instruction and tracked independently in the mmu_gather (using the need_flush_all flag to indicate PWC must be flushed). Therefore TLB invalidation does not have to be expanded to cover freed page tables. This patch defines p??_free_tlb functions for 64s, which do not expand the TLB flush range over page table pages. This brings the number of tlbiel instructions required by a kernel compile from 33M to 25M, most avoided from exec => shift_arg_pages(). Signed-off-by: Nicholas Piggin --- arch/powerpc/include/asm/tlb.h | 34 ++++++++++++++++++++++++++++++++++ arch/powerpc/mm/tlb-radix.c | 10 ++++++++++ include/asm-generic/tlb.h | 5 +++++ 3 files changed, 49 insertions(+) diff --git a/arch/powerpc/include/asm/tlb.h b/arch/powerpc/include/asm/tlb.h index 9138baccebb0..5d3107f2b014 100644 --- a/arch/powerpc/include/asm/tlb.h +++ b/arch/powerpc/include/asm/tlb.h @@ -30,6 +30,40 @@ #define __tlb_remove_tlb_entry __tlb_remove_tlb_entry #define tlb_remove_check_page_size_change tlb_remove_check_page_size_change +#ifdef CONFIG_PPC_BOOK3S_64 +/* + * powerpc book3s hash does not have page table structure caches, and + * radix requires explicit management with PWC invalidate tlb type, so + * there is no need to expand the mmu_gather range over invalidated page + * table pages like the generic code does. + */ + +#define pte_free_tlb(tlb, ptep, address) \ + do { \ + __pte_free_tlb(tlb, ptep, address); \ + } while (0) + +#define pmd_free_tlb(tlb, pmdp, address) \ + do { \ + __pmd_free_tlb(tlb, pmdp, address); \ + } while (0) + +#define pud_free_tlb(tlb, pudp, address) \ + do { \ + __pud_free_tlb(tlb, pudp, address); \ + } while (0) + +/* + * Radix sets need_flush_all when page table pages have been unmapped + * and the PWC needs flushing. Generic code must call our tlb_flush + * even on empty ranges in this case. + * + * This will always be false for hash. + */ +#define arch_tlb_mustflush(tlb) (tlb->need_flush_all) + +#endif + extern void tlb_flush(struct mmu_gather *tlb); /* Get the generic bits... */ diff --git a/arch/powerpc/mm/tlb-radix.c b/arch/powerpc/mm/tlb-radix.c index 1135b43a597c..238b20a513e7 100644 --- a/arch/powerpc/mm/tlb-radix.c +++ b/arch/powerpc/mm/tlb-radix.c @@ -862,6 +862,16 @@ void radix__tlb_flush(struct mmu_gather *tlb) unsigned long start = tlb->start; unsigned long end = tlb->end; + /* + * This can happen if need_flush_all is set due to a page table + * invalidate, but no ptes under it freed (see arch_tlb_mustflush). + * Set end = start to prevent any TLB flushing here (only PWC). + */ + if (!end) { + WARN_ON_ONCE(!tlb->need_flush_all); + end = start; + } + /* * if page size is not something we understand, do a full mm flush * diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index b320c0cc8996..a55ef1425f0d 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -285,6 +285,11 @@ static inline void tlb_remove_check_page_size_change(struct mmu_gather *tlb, * http://lkml.kernel.org/r/CA+55aFzBggoXtNXQeng5d_mRoDnaMBE5Y+URs+PHR67nUpMtaw@mail.gmail.com * * For now w.r.t page table cache, mark the range_size as PAGE_SIZE + * + * Update: powerpc (Book3S 64-bit, radix MMU) has an architected page table + * cache (called PWC), and invalidates it specifically. It sets the + * need_flush_all flag to indicate the PWC requires flushing, so it defines + * its own p??_free_tlb functions which do not expand the TLB range. */ #ifndef pte_free_tlb