From patchwork Wed Aug 22 15:30:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 10573019 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 90385112E for ; Wed, 22 Aug 2018 15:46:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F7D92B783 for ; Wed, 22 Aug 2018 15:46:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7333B2B79C; Wed, 22 Aug 2018 15:46:09 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID 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 E51032B783 for ; Wed, 22 Aug 2018 15:46:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 733FA6B251A; Wed, 22 Aug 2018 11:46:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6BF606B251B; Wed, 22 Aug 2018 11:46:02 -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 498A76B251C; Wed, 22 Aug 2018 11:46:02 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) by kanga.kvack.org (Postfix) with ESMTP id F1CEF6B251A for ; Wed, 22 Aug 2018 11:46:01 -0400 (EDT) Received: by mail-pf1-f200.google.com with SMTP id j15-v6so1375542pfi.10 for ; Wed, 22 Aug 2018 08:46:01 -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=zUKxfxjpgWzZcjbYNf+Wl4oxw1QTfZ/a5hMhTBA6A2c=; b=pGDlnUD899YzcAY/ONAfg1BM+tJqMbe4UcOVjn2zWYHG/yK+Q9kzBKJaFreWE+xzO5 312doScnSZl5GTjfEYN0Z03ukY0n+92BQoJF4dGvU4jbyYnAj9GBL9vZXMWv0JhkpdNT qyFvTwejauaOnq29gC2F4nPxV1UFmAw/9Z7ocQ58OR7RBgo8Va79i7gIYTpMfDKBzLrl O3X5xqKFcLKkqAzpSY5rKuHUYtVmyaw8VnyKteBNvzW4hfzuorzd1jspziBO66O/K/+K uCSQkJw7ltCuah/msMkkTfed8P0qEWTqWmPXm1Wr63qwXtpNMcwMIcz1GiqckPBmwKs4 rQtA== X-Gm-Message-State: AOUpUlHXdjBaxX/UBVDOU4P7jib/qpRgUM8FtowpoWZaHacKzf7UFhXX +nHa5PihWBfb8B3wI81ELngFK7MYq3wdVYSbl/xG9g9wT9Qli7XEqbbPXXo05FQM7seZNNoiIaD Jp0fr0O/ZevvE/7AGG9wP0lLuifgM0shHDSdjwk4lDzgfjD6hph3K5T0SjphGU1egLA== X-Received: by 2002:a63:91:: with SMTP id 139-v6mr21042234pga.389.1534952761654; Wed, 22 Aug 2018 08:46:01 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyBHP4zPa9e64XNAfyqiYSZZchdA4cURrJP6E5FYaSJf4/5l93HWsi5yYAu9+ForLoeuEeB X-Received: by 2002:a63:91:: with SMTP id 139-v6mr21042185pga.389.1534952760841; Wed, 22 Aug 2018 08:46:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534952760; cv=none; d=google.com; s=arc-20160816; b=m6Pg7nUn2ynWddhEgqj4oCNS4Eq8HBiwGy9zS/yLjn5qLn2i0+oCkPRhmq3aNmDSbe hCyEJRvdO5ZbERhdQK+IkX5F3KqSl2LvFK8cOGF5GKMEerCNps58OrBVihMrL5BfxMjC 8N62WOZIkTE86+dTq1Ck41Ap1m8AE5no7Qrxtwz6cHoutUOC7wNYvWCrH3U3vxUKo6D9 3ZoFXrTBgOIRpt+5dLIHQ7EIkXqrCSnUFi7+gvE0RUCMSZxLiSI+4Pr34REIvA524DBW PsS8QYHOO1IRzXONhBtwFRF4vUpmZNiF3aS+ffQ9k08mGPSJFHokxzUwCTBH7q0BGs2U ATkA== 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:arc-authentication-results; bh=zUKxfxjpgWzZcjbYNf+Wl4oxw1QTfZ/a5hMhTBA6A2c=; b=BwSc04sy22Kg/pUOFnlUlFHA0J7MyApBTKlqLv+iFdRmdoQNLfimFsY1R1RQ3QyN42 a4XkX6qC4VkUROFQqvmTa6XDLETK/7HbiSE0cYmrySXuu/0JOt9a2bIzJS9Q0F5bX/Kw hS6B91MGWDn3xmG6d2JvFdgywS2OYjYQ57DvJY97FyhLtLeygDPZK0ng38y7dNb5GGuF AWVqNS+4kVeYcCO5mMV5TNk1joapDMdq8RBfI6b1jp+YxNRKKRN/547591qEo5/gbP7X +yWV4NFZ6lv8CxoxZ2NRg7JiWeQ0qIzrJ6aQQ5Fc/Jh0wrgiAd6hFEN2qBDkc+LF5hOx 1v3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=LihpBYe8; 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 w7-v6si1842346plq.198.2018.08.22.08.46.00 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 22 Aug 2018 08:46:00 -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=LihpBYe8; 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=zUKxfxjpgWzZcjbYNf+Wl4oxw1QTfZ/a5hMhTBA6A2c=; b=LihpBYe80MmgqB361ej9IoCREs /vL0G5e1PRqx3qNsuISx1zrXxTXiwALJu3yr//2iVpu6gFCuZk0FVc5JqI/LLGa0AnyCNUDhaLQT3 VkkNNdswlRc8kYqTusppEvH8gakOYOTvLrxneAyZVTu5X8U5hicLVNSp6ElFMGr6Mmtls06D+ybiy K2Fd6Y9uFC2CpTlckZzCAtAZUZXkodQz/hQLG3ZaJfvgpgP7QCaGi6ijjI9l9wj3Op5XZHFZVQ1/P S1k9FIfD/VLv6KZSJZ8bANA4+yQ3V4DYguO8M/Cv+kgBe5Xd0O5/v2CqEFbFcZnfX9QoVDAB28b+G fk0zJHHw==; 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 1fsVKM-0004RB-E1; Wed, 22 Aug 2018 15:45:46 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id C2A5C2024D725; Wed, 22 Aug 2018 17:45:44 +0200 (CEST) Message-ID: <20180822154046.823850812@infradead.org> User-Agent: quilt/0.65 Date: Wed, 22 Aug 2018 17:30:15 +0200 From: Peter Zijlstra To: torvalds@linux-foundation.org Cc: peterz@infradead.org, luto@kernel.org, x86@kernel.org, bp@alien8.de, will.deacon@arm.com, riel@surriel.com, jannh@google.com, ascannell@google.com, dave.hansen@intel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Nicholas Piggin , David Miller , Martin Schwidefsky , Michael Ellerman Subject: [PATCH 3/4] mm/tlb, x86/mm: Support invalidating TLB caches for RCU_TABLE_FREE References: <20180822153012.173508681@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 Jann reported that x86 was missing required TLB invalidates when he hit the !*batch slow path in tlb_remove_table(). This is indeed the case; RCU_TABLE_FREE does not provide TLB (cache) invalidates, the PowerPC-hash where this code originated and the Sparc-hash where this was subsequently used did not need that. ARM which later used this put an explicit TLB invalidate in their __p*_free_tlb() functions, and PowerPC-radix followed that example. But when we hooked up x86 we failed to consider this. Fix this by (optionally) hooking tlb_remove_table() into the TLB invalidate code. NOTE: s390 was also needing something like this and might now be able to use the generic code again. Cc: stable@kernel.org Cc: Nicholas Piggin Cc: David Miller Cc: Will Deacon Cc: Martin Schwidefsky Cc: Michael Ellerman Fixes: 9e52fc2b50de ("x86/mm: Enable RCU based page table freeing (CONFIG_HAVE_RCU_TABLE_FREE=y)") Reported-by: Jann Horn Signed-off-by: Peter Zijlstra (Intel) --- arch/Kconfig | 3 +++ arch/x86/Kconfig | 1 + mm/memory.c | 27 +++++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) --- a/arch/Kconfig +++ b/arch/Kconfig @@ -362,6 +362,9 @@ config HAVE_ARCH_JUMP_LABEL config HAVE_RCU_TABLE_FREE bool +config HAVE_RCU_TABLE_INVALIDATE + bool + config ARCH_HAVE_NMI_SAFE_CMPXCHG bool --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -180,6 +180,7 @@ config X86 select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP select HAVE_RCU_TABLE_FREE + select HAVE_RCU_TABLE_INVALIDATE if HAVE_RCU_TABLE_FREE select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RELIABLE_STACKTRACE if X86_64 && (UNWINDER_FRAME_POINTER || UNWINDER_ORC) && STACK_VALIDATION select HAVE_STACKPROTECTOR if CC_HAS_SANE_STACKPROTECTOR --- a/mm/memory.c +++ b/mm/memory.c @@ -238,17 +238,22 @@ void arch_tlb_gather_mmu(struct mmu_gath __tlb_reset_range(tlb); } -static void tlb_flush_mmu_tlbonly(struct mmu_gather *tlb) +static void __tlb_flush_mmu_tlbonly(struct mmu_gather *tlb) { if (!tlb->end) return; tlb_flush(tlb); mmu_notifier_invalidate_range(tlb->mm, tlb->start, tlb->end); + __tlb_reset_range(tlb); +} + +static void tlb_flush_mmu_tlbonly(struct mmu_gather *tlb) +{ + __tlb_flush_mmu_tlbonly(tlb); #ifdef CONFIG_HAVE_RCU_TABLE_FREE tlb_table_flush(tlb); #endif - __tlb_reset_range(tlb); } static void tlb_flush_mmu_free(struct mmu_gather *tlb) @@ -330,6 +335,21 @@ bool __tlb_remove_page_size(struct mmu_g * See the comment near struct mmu_table_batch. */ +/* + * If we want tlb_remove_table() to imply TLB invalidates. + */ +static inline void tlb_table_invalidate(struct mmu_gather *tlb) +{ +#ifdef CONFIG_HAVE_RCU_TABLE_INVALIDATE + /* + * Invalidate page-table caches used by hardware walkers. Then we still + * need to RCU-sched wait while freeing the pages because software + * walkers can still be in-flight. + */ + __tlb_flush_mmu_tlbonly(tlb); +#endif +} + static void tlb_remove_table_smp_sync(void *arg) { /* Simply deliver the interrupt */ @@ -366,6 +386,7 @@ void tlb_table_flush(struct mmu_gather * struct mmu_table_batch **batch = &tlb->batch; if (*batch) { + tlb_table_invalidate(tlb); call_rcu_sched(&(*batch)->rcu, tlb_remove_table_rcu); *batch = NULL; } @@ -378,11 +399,13 @@ void tlb_remove_table(struct mmu_gather if (*batch == NULL) { *batch = (struct mmu_table_batch *)__get_free_page(GFP_NOWAIT | __GFP_NOWARN); if (*batch == NULL) { + tlb_table_invalidate(tlb); tlb_remove_table_one(table); return; } (*batch)->nr = 0; } + (*batch)->tables[(*batch)->nr++] = table; if ((*batch)->nr == MAX_TABLE_BATCH) tlb_table_flush(tlb);