Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3311080imm; Tue, 17 Jul 2018 02:37:29 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe8O299wzIXsCuca1k5D02Tf0P6Q8f6DpVwwn2w6ncOeBFu+zuezKtuMj2rEQf6qmJhGwCf X-Received: by 2002:a63:1015:: with SMTP id f21-v6mr892885pgl.354.1531820249011; Tue, 17 Jul 2018 02:37:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531820248; cv=none; d=google.com; s=arc-20160816; b=Gt+EfASuAS9g3B67TOdnJb/BnfBYq8OMtQRWesYhe81Tp9X8PDzmVqG81heHcB7RLm CiO2sHfIBJSQeZEzmOnohJYm0CshD/KkYs4NkECSzcBer5Xv0sz3A9nO5zxGQYp5owRD P/Wr4Ttaqwya99WCV78dW/yuaQtIaTR47XlV7SKPmvAlrcBKdd+WuLgMhNkJPyoOXap8 cXb2Tz1ArMkEL3/70OCmeJc91liEQUq4wo2zjskxpCb1t2HlKnVc1E99WuFicvem4XUe 0TtsplUNfYf2/kTGbCkrG2czr3pP+kJcSYvCOBeguih3Gb7fk18BELyAvBxQG2Twlq8l aofw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=BE3ZhQkQXm0WN12vIgWP0Z5cyyvmKXbvyyN6A0u7pYc=; b=Onf8wEAIlVtw0s8rq1t2KThEY3n8oRW+QLUUcVzhMnoxUgJmYCC4KYJba1lZD9XOfX +tYLVL4x+pfoWopAcWEYJyuvSKxFfTAkJnMHt2Apzc2D/M2Dpv0mCdx5MaKfujxqLu9f lfF9dLA7WxIxjtTV+3dm5ixwlWmPCf9Fu6+hvTGlDSNb0GW6wBItd+1cOtvX7J39KgsJ 0gIrl3+ufrzwhOR1Ji1b2hM0FbhErcnDJ9gow0YFZzfk6bmEpenmPEYBLA9C4Ul/92RM 5eTgtpoJLj/k/MP02liAPpQOKcdH/i9qhX7U6ODzBe4K6uXFuEbA63Vq+8kLvd4fAZb7 FqcQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r133-v6si486348pgr.17.2018.07.17.02.37.13; Tue, 17 Jul 2018 02:37:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730003AbeGQKHq (ORCPT + 99 others); Tue, 17 Jul 2018 06:07:46 -0400 Received: from terminus.zytor.com ([198.137.202.136]:44863 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728835AbeGQKHp (ORCPT ); Tue, 17 Jul 2018 06:07:45 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w6H9ZfHq1463459 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 17 Jul 2018 02:35:41 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w6H9Zf3x1463456; Tue, 17 Jul 2018 02:35:41 -0700 Date: Tue, 17 Jul 2018 02:35:41 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Rik van Riel Message-ID: Cc: riel@surriel.com, hpa@zytor.com, tglx@linutronix.de, peterz@infradead.org, torvalds@linux-foundation.org, songliubraving@fb.com, mingo@kernel.org, linux-kernel@vger.kernel.org, dave.hansen@intel.com Reply-To: dave.hansen@intel.com, linux-kernel@vger.kernel.org, mingo@kernel.org, songliubraving@fb.com, hpa@zytor.com, tglx@linutronix.de, peterz@infradead.org, torvalds@linux-foundation.org, riel@surriel.com In-Reply-To: <20180716190337.26133-6-riel@surriel.com> References: <20180716190337.26133-6-riel@surriel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/mm] x86/mm/tlb: Only send page table free TLB flush to lazy TLB CPUs Git-Commit-ID: 64482aafe55fc7e84d0741c356f8176ee7bde357 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 64482aafe55fc7e84d0741c356f8176ee7bde357 Gitweb: https://git.kernel.org/tip/64482aafe55fc7e84d0741c356f8176ee7bde357 Author: Rik van Riel AuthorDate: Mon, 16 Jul 2018 15:03:35 -0400 Committer: Ingo Molnar CommitDate: Tue, 17 Jul 2018 09:35:33 +0200 x86/mm/tlb: Only send page table free TLB flush to lazy TLB CPUs CPUs in !is_lazy have either received TLB flush IPIs earlier on during the munmap (when the user memory was unmapped), or have context switched and reloaded during that stage of the munmap. Page table free TLB flushes only need to be sent to CPUs in lazy TLB mode, which TLB contents might not yet be up to date yet. Tested-by: Song Liu Signed-off-by: Rik van Riel Acked-by: Dave Hansen Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: efault@gmx.de Cc: kernel-team@fb.com Cc: luto@kernel.org Link: http://lkml.kernel.org/r/20180716190337.26133-6-riel@surriel.com Signed-off-by: Ingo Molnar --- arch/x86/mm/tlb.c | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 26542cc17043..e4156e37aa71 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -712,15 +712,50 @@ void tlb_flush_remove_tables_local(void *arg) } } +static void mm_fill_lazy_tlb_cpu_mask(struct mm_struct *mm, + struct cpumask *lazy_cpus) +{ + int cpu; + + for_each_cpu(cpu, mm_cpumask(mm)) { + if (!per_cpu(cpu_tlbstate.is_lazy, cpu)) + cpumask_set_cpu(cpu, lazy_cpus); + } +} + void tlb_flush_remove_tables(struct mm_struct *mm) { int cpu = get_cpu(); + cpumask_var_t lazy_cpus; + + if (cpumask_any_but(mm_cpumask(mm), cpu) >= nr_cpu_ids) { + put_cpu(); + return; + } + + if (!zalloc_cpumask_var(&lazy_cpus, GFP_ATOMIC)) { + /* + * If the cpumask allocation fails, do a brute force flush + * on all the CPUs that have this mm loaded. + */ + smp_call_function_many(mm_cpumask(mm), + tlb_flush_remove_tables_local, (void *)mm, 1); + put_cpu(); + return; + } + /* - * XXX: this really only needs to be called for CPUs in lazy TLB mode. + * CPUs with !is_lazy either received a TLB flush IPI while the user + * pages in this address range were unmapped, or have context switched + * and reloaded %CR3 since then. + * + * Shootdown IPIs at page table freeing time only need to be sent to + * CPUs that may have out of date TLB contents. */ - if (cpumask_any_but(mm_cpumask(mm), cpu) < nr_cpu_ids) - smp_call_function_many(mm_cpumask(mm), tlb_flush_remove_tables_local, (void *)mm, 1); - + mm_fill_lazy_tlb_cpu_mask(mm, lazy_cpus); + smp_call_function_many(lazy_cpus, + tlb_flush_remove_tables_local, (void *)mm, 1); + free_cpumask_var(lazy_cpus); put_cpu(); }