From patchwork Wed Sep 26 11:36:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 10615783 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 09B8314BD for ; Wed, 26 Sep 2018 11:54:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0F2B2A97C for ; Wed, 26 Sep 2018 11:54:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4DE82A98A; Wed, 26 Sep 2018 11:54:34 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham 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 204C32A97C for ; Wed, 26 Sep 2018 11:54:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C49B8E0007; Wed, 26 Sep 2018 07:54:28 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EF2208E0001; Wed, 26 Sep 2018 07:54:27 -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 CFB7D8E0007; Wed, 26 Sep 2018 07:54:27 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by kanga.kvack.org (Postfix) with ESMTP id 73AC08E0003 for ; Wed, 26 Sep 2018 07:54:27 -0400 (EDT) Received: by mail-pl1-f198.google.com with SMTP id 3-v6so10671036plq.6 for ; Wed, 26 Sep 2018 04:54:27 -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:message-id:user-agent:date:from :to:cc:subject:references:mime-version; bh=+tA8Q9MFdkLFV7zO6AF9h18nDDBKm/mt3m8i8F4mU94=; b=K+tM1KJ22qRsFk9Kne2hEpObBOfLdbjMmccKiG5Kc3RyhK1PthglzG/IyYybTz0gpS +MP5oJ47wCoyErrUhYZxAyrTR70trDvnbgAmhn6qnZoovfjZiig5+Y1nr00uXgoIKuKZ ThgFzm23+tJRg24hYoSQtb3chDMaB5ub3WJo4hetAnfQo+TDtvUw20azSrOKE/yusCiI rHJdJ3ljl5rabCIpGmQ0RGc+CNhe4/iqxJAg3IsN6n+xE7DY1F+gq0TAe2rPJribijbp viB22d7VErnwMsBB87QPTBsVPh8e17QVYwo68WmbnUyMo5jDHn/514iUCp4ROStovQT2 7+xg== X-Gm-Message-State: ABuFfojsdeLHUR+sEHp5c1GSdu+Xp4suO+RqaPz9/cIgt3wCpiYaKdtg 64GptMFb/kl8xX870l9UuiTFL+Rsfm7yehOc5l4x64bi/RHe0tBV7rkOZ2DgdLf29Eg9LnK8+s9 2V48AYbdBWnEVLUeYHFzLxfIC2i6nJw/dC/acGGqK0k7Rpo7X+2ZGjP3Js5Dp9bOlJA== X-Received: by 2002:a62:f610:: with SMTP id x16-v6mr5856007pfh.169.1537962867097; Wed, 26 Sep 2018 04:54:27 -0700 (PDT) X-Google-Smtp-Source: ACcGV60ZPoQf0lgGJ5tMKCy9HnWkj9l+6rv2FwsSt7iHHZSC5blCI/Muh01XJIjCIHgaPT7TncS/ X-Received: by 2002:a62:f610:: with SMTP id x16-v6mr5855950pfh.169.1537962866116; Wed, 26 Sep 2018 04:54:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537962866; cv=none; d=google.com; s=arc-20160816; b=mgyWc95rzqxU0P36pHs3mgINnaSVMUN13xz5gZcmZa5bpmNQjiWN5LXrWXuFV39Bgf NMnXCkKASh62B9qNuwxmw1kHfHsRFC0iUQzU1Jupsf1jNwN7S4pjlGbj5JVvS6kuz/XF EH2a9KJhfCstH6JEaO3f6t09C8Z3HgyK+9i6C6OcPi1NE2r4J/+WBpvjVx8y0KhptTmZ evpUHFzHS9VaWpEUB8a7TsDMD/mi1xMQlolURQS2ZYnLQHcGSgnmJRAkcMLklU7TisYL niJMuUFWwVSZn4Jw5TSpz0Regcd0tcKjvX5DXDlwi/y7HyzljAtpECyP0XjmAL+GFJbq va6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:references:subject:cc:to:from:date:user-agent :message-id:dkim-signature; bh=+tA8Q9MFdkLFV7zO6AF9h18nDDBKm/mt3m8i8F4mU94=; b=FIbWhplCKEO5LdYIujNGVj9gpfthlZEQ/BtIluud6efl4Ucrf0ErIZIN8bDe34vKtg E0s7VTQBz8WnCAslHassHwNXIFUwNjxzpJ0Rz8XngTa3HNHNk/i5PTGR3mg1pDHSFN6A r9EqN/UeZn5K9iLja4oCpsTkBJR5GJIOzzRE7HOYdsNl09VnECi0jRWQFaTO9p8PilJl pKP4sWIcxLwue0vtWAigGlvdJ+3BT4pR82JwkoZtzgRE6XkybGeQkPCYofgqBlxVcwHC BfbBBXD/cvu169B8R3enxJ31ATC9ZO2cEVNdf8QPR2z78GG9xQ6MGHDDVwFXCH09Eute TMLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=gPL6d7yS; spf=pass (google.com: best guess record for domain of peterz@infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=peterz@infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id o1-v6si4787055pfe.259.2018.09.26.04.54.25 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 26 Sep 2018 04:54:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of peterz@infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=gPL6d7yS; spf=pass (google.com: best guess record for domain of peterz@infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=peterz@infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=+tA8Q9MFdkLFV7zO6AF9h18nDDBKm/mt3m8i8F4mU94=; b=gPL6d7ySVlX1zkspubHdYLYPPz JHNxtySC9tV/OnbUzT6l4g+T3kBT2fitMK+ZiClHOw0emzwyjxzEDHSe2UH4uWMHoGP7qWHWMvAgD nFcN2lTgWPw6KID9r7/0OYTX7UZX+yU1CH95xdBrnNNXlPVr4ppS67PmWHJSj2Nu+FC2DBJenM0dT cVWSHt2hK6JcFCHnoluO349hwPyOBDYV1FtiuQ+elXrVjldiUoAynH6geYfjMIftHVAIP/SbWFK4A kvGmUJ1NKA13olh4n+56yj/aXI5D/y9jWCQlIzbOg+giilYTkIjOjbi0HgenjOcXFoQ3/zX9phbN2 vloLJK2A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1g58OM-0005vc-71; Wed, 26 Sep 2018 11:54:21 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 7577F206F1800; Wed, 26 Sep 2018 13:54:04 +0200 (CEST) Message-ID: <20180926114800.561468800@infradead.org> User-Agent: quilt/0.65 Date: Wed, 26 Sep 2018 13:36:24 +0200 From: Peter Zijlstra To: will.deacon@arm.com, aneesh.kumar@linux.vnet.ibm.com, akpm@linux-foundation.org, npiggin@gmail.com Cc: linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, peterz@infradead.org, linux@armlinux.org.uk, heiko.carstens@de.ibm.com, riel@surriel.com Subject: [PATCH 01/18] asm-generic/tlb: Provide a comment References: <20180926113623.863696043@infradead.org> MIME-Version: 1.0 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 Write a comment explaining some of this.. Cc: Nick Piggin Cc: Andrew Morton Cc: "Aneesh Kumar K.V" Cc: Will Deacon Signed-off-by: Peter Zijlstra (Intel) --- include/asm-generic/tlb.h | 119 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 116 insertions(+), 3 deletions(-) --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -22,6 +22,118 @@ #ifdef CONFIG_MMU +/* + * Generic MMU-gather implementation. + * + * The mmu_gather data structure is used by the mm code to implement the + * correct and efficient ordering of freeing pages and TLB invalidations. + * + * This correct ordering is: + * + * 1) unhook page + * 2) TLB invalidate page + * 3) free page + * + * That is, we must never free a page before we have ensured there are no live + * translations left to it. Otherwise it might be possible to observe (or + * worse, change) the page content after it has been reused. + * + * The mmu_gather API consists of: + * + * - tlb_gather_mmu() / tlb_finish_mmu(); start and finish a mmu_gather + * + * Finish in particular will issue a (final) TLB invalidate and free + * all (remaining) queued pages. + * + * - tlb_start_vma() / tlb_end_vma(); marks the start / end of a VMA + * + * Defaults to flushing at tlb_end_vma() to reset the range; helps when + * there's large holes between the VMAs. + * + * - tlb_remove_page() / __tlb_remove_page() + * - tlb_remove_page_size() / __tlb_remove_page_size() + * + * __tlb_remove_page_size() is the basic primitive that queues a page for + * freeing. __tlb_remove_page() assumes PAGE_SIZE. Both will return a + * boolean indicating if the queue is (now) full and a call to + * tlb_flush_mmu() is required. + * + * tlb_remove_page() and tlb_remove_page_size() imply the call to + * tlb_flush_mmu() when required and has no return value. + * + * - tlb_remove_check_page_size_change() + * + * call before __tlb_remove_page*() to set the current page-size; implies a + * possible tlb_flush_mmu() call. + * + * - tlb_flush_mmu() / tlb_flush_mmu_tlbonly() / tlb_flush_mmu_free() + * + * tlb_flush_mmu_tlbonly() - does the TLB invalidate (and resets + * related state, like the range) + * + * tlb_flush_mmu_free() - frees the queued pages; make absolutely + * sure no additional tlb_remove_page() + * calls happen between _tlbonly() and this. + * + * tlb_flush_mmu() - the above two calls. + * + * - mmu_gather::fullmm + * + * A flag set by tlb_gather_mmu() to indicate we're going to free + * the entire mm; this allows a number of optimizations. + * + * - We can ignore tlb_{start,end}_vma(); because we don't + * care about ranges. Everything will be shot down. + * + * - (RISC) architectures that use ASIDs can cycle to a new ASID + * and delay the invalidation until ASID space runs out. + * + * - mmu_gather::need_flush_all + * + * A flag that can be set by the arch code if it wants to force + * flush the entire TLB irrespective of the range. For instance + * x86-PAE needs this when changing top-level entries. + * + * And requires the architecture to provide and implement tlb_flush(). + * + * tlb_flush() may, in addition to the above mentioned mmu_gather fields, make + * use of: + * + * - mmu_gather::start / mmu_gather::end + * + * which provides the range that needs to be flushed to cover the pages to + * be freed. + * + * - mmu_gather::freed_tables + * + * set when we freed page table pages + * + * - tlb_get_unmap_shift() / tlb_get_unmap_size() + * + * returns the smallest TLB entry size unmapped in this range + * + * Additionally there are a few opt-in features: + * + * HAVE_RCU_TABLE_FREE + * + * This provides tlb_remove_table(), to be used instead of tlb_remove_page() + * for page directores (__p*_free_tlb()). This provides separate freeing of + * the page-table pages themselves in a semi-RCU fashion (see comment below). + * Useful if your architecture doesn't use IPIs for remote TLB invalidates + * and therefore doesn't naturally serialize with software page-table walkers. + * + * When used, an architecture is expected to provide __tlb_remove_table() + * which does the actual freeing of these pages. + * + * HAVE_RCU_TABLE_INVALIDATE + * + * This makes HAVE_RCU_TABLE_FREE call tlb_flush_mmu_tlbonly() before freeing + * the page-table pages. Required if you use HAVE_RCU_TABLE_FREE and your + * architecture uses the Linux page-tables natively. + * + */ +#define HAVE_GENERIC_MMU_GATHER + #ifdef CONFIG_HAVE_RCU_TABLE_FREE /* * Semi RCU freeing of the page directories. @@ -89,14 +201,17 @@ struct mmu_gather_batch { */ #define MAX_GATHER_BATCH_COUNT (10000UL/MAX_GATHER_BATCH) -/* struct mmu_gather is an opaque type used by the mm code for passing around +/* + * struct mmu_gather is an opaque type used by the mm code for passing around * any data needed by arch specific code for tlb_remove_page. */ struct mmu_gather { struct mm_struct *mm; + #ifdef CONFIG_HAVE_RCU_TABLE_FREE struct mmu_table_batch *batch; #endif + unsigned long start; unsigned long end; /* @@ -131,8 +246,6 @@ struct mmu_gather { int page_size; }; -#define HAVE_GENERIC_MMU_GATHER - void arch_tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned long start, unsigned long end); void tlb_flush_mmu(struct mmu_gather *tlb);