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: 10544069 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 C23E21805 for ; Wed, 25 Jul 2018 14:07:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0D7A2022C for ; Wed, 25 Jul 2018 14:07:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4A5C206E2; Wed, 25 Jul 2018 14:07: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=-0.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, SUSPICIOUS_RECIPS autolearn=no version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F57F2022C for ; Wed, 25 Jul 2018 14:07:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 543CD6B02BC; Wed, 25 Jul 2018 10:07:08 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4C6B66B02BE; Wed, 25 Jul 2018 10:07:08 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 366F26B02BF; Wed, 25 Jul 2018 10:07:08 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f72.google.com (mail-pl0-f72.google.com [209.85.160.72]) by kanga.kvack.org (Postfix) with ESMTP id E11A06B02BC for ; Wed, 25 Jul 2018 10:07:07 -0400 (EDT) Received: by mail-pl0-f72.google.com with SMTP id az8-v6so5486186plb.15 for ; Wed, 25 Jul 2018 07:07:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=bEa2VC1PhTklj7TrxhDQMGrxkMdS1Gq+3HFfcqOkvaE=; b=De/frg+PH1w/Sh/AkhH+g1cJvblm83byMpliKjw1zdw/a9qxNR6QrJClFCidlZtxmf Mpc/VdQkrJyHMCOyg403+lit+gG5dxqeAz9BQPRoMZ0JOdm1ACt/ZF922XvTlykswoRY piV+I8f3asdjflF/vifetuPXuD9dkSW9Hum3yMm4MJ4xPPQAWi2fzsgKu25D8y+B1+Lw MbEpnc4ci6lV+hQjc32WaFBxkpYA544GEOZrj2lIZvogmWvNQrENxkBhf88K4qfOPttj 34IIItMx2eI0X5yh3Kyj+BWNdvS88Yy/VEc9Wl/VxDIgGMD3AmcnVBpuSw4PXMyosOE/ LM7g== X-Gm-Message-State: AOUpUlH3Q4Bbz0xdh3iLpWHx6xkDjlNkNMWwDlYE622gKtqkOz0QhbDR ngpkXVGxKOOnUNAS212eIgUbOOuf2E8pyv8schc6KAT0W9qGctTV//5T5kEVYFCra64Zgsaz2NO TcjGLUDhDY/ugf2PAGIyLQWuvq0VxShpsAkRukQ2PUZjSOk/qwq5oPHqqnTQPuAjE6J99B5dS/m REkhY6B+U6PvoHqGCT6xwNuoQYTf2g1cbTe5cDG2aA0vlqXVKTnDNXJTfmOa3Nd//CqP0npYF32 hRb16JECpe5f9di1VQQIGPebbI04i+PZBKX9ITkFeHLN9JBVHZGhekl3vn+QQ3KP5k78XEbcw4B Q4W+mFahP3YqMBskEbPl+y0kCwybST5KZYwSP/KvGy9x5NyLCqG9Y20wjvZGaWGk+fjg7XJKT+Z i X-Received: by 2002:a62:5486:: with SMTP id i128-v6mr22066428pfb.166.1532527627601; Wed, 25 Jul 2018 07:07:07 -0700 (PDT) X-Received: by 2002:a62:5486:: with SMTP id i128-v6mr22066378pfb.166.1532527626725; Wed, 25 Jul 2018 07:07:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532527626; cv=none; d=google.com; s=arc-20160816; b=Laa/zHiZtgC5g/XqVghVzfeYbUexA26ab7M/T+yyUA9tD0niYKUx2X0dFujpjij0st C9J7UALhPOlUm3YDpOBhAG1nMnn3DGFm+up5Q4cH53JU0dvD53FVQTxcif6l4jpHPR2B vbQ8UGt+iZYmkpIfn//NfT/ZOLzM4fC3tEiUraDBCA7Af90GamezQtaryIQlgaNNYLz9 svVSozypNFW6OHPDbigbHbsySQkdy7ok6iKqSKjaId1qnKTSId99lyTCuqhiwG+8Xzbt dPcMHQ1Txx8HHSC7EBNbqdqwJYk9j5ZeWa+Inzkd84yQriV/vuAVCY5mOuNzTSi474m6 IfDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=bEa2VC1PhTklj7TrxhDQMGrxkMdS1Gq+3HFfcqOkvaE=; b=syZoU9F1FFrO0LJ35Cuf3nQOnuAHIgqRC0R+FVitvyj9szjzJwhv+rzx6FrsVIj2OH YDS/dDbVF73Mu+rlC2SnQrOiKwyiK++EDjRkS/5HC4Trshzj6sbl9lmySsoQuxYT/5JJ d9fE+JuoO1e8pkf+LXKrdLFjT/mnA4yh2fhjILf2TReuKNJKEentdE9kLwbiOIJA0Vh9 pE2W1m9e0nVWNuxLFPjGAzQfZZfnUrF30Ouoepw2uQIoBP/WH1OrfYOWO3gANgqCBvc9 YlTSgeb/eeSWPm3Yp7jkSH3XJfRKVhA4ztXhi4XemKz5VJnCWF95IpHNVAPIG4K8T0CF 8QGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="s/oaPYvU"; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id g14-v6sor4030662pgh.236.2018.07.25.07.07.06 for (Google Transport Security); Wed, 25 Jul 2018 07:07:06 -0700 (PDT) Received-SPF: pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="s/oaPYvU"; spf=pass (google.com: domain of npiggin@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=npiggin@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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-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 Cc: Nicholas Piggin , linuxppc-dev@lists.ozlabs.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.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-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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