From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2823EC43140 for ; Wed, 20 Jun 2018 19:57:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DD5C02083A for ; Wed, 20 Jun 2018 19:57:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DD5C02083A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=surriel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754992AbeFTT5Z (ORCPT ); Wed, 20 Jun 2018 15:57:25 -0400 Received: from shelob.surriel.com ([96.67.55.147]:52040 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754796AbeFTT5H (ORCPT ); Wed, 20 Jun 2018 15:57:07 -0400 Received: from imladris.surriel.com ([96.67.55.152]) by shelob.surriel.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1fVjDr-0002g7-Dv; Wed, 20 Jun 2018 15:56:55 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: 86@vger.kernel.org, luto@kernel.org, mingo@kernel.org, tglx@linutronix.de, dave.hansen@linux.intel.com, efault@gmx.de, songliubraving@fb.com, kernel-team@fb.com, Rik van Riel Subject: [PATCH 5/7] x86,tlb: only send page table free TLB flush to lazy TLB CPUs Date: Wed, 20 Jun 2018 15:56:50 -0400 Message-Id: <20180620195652.27251-6-riel@surriel.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180620195652.27251-1-riel@surriel.com> References: <20180620195652.27251-1-riel@surriel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org CPUs in TLBSTATE_OK 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. Signed-off-by: Rik van Riel Tested-by: Song Liu --- arch/x86/mm/tlb.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 4b27d8469848..40b00055c883 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -752,11 +752,31 @@ void tlb_flush_remove_tables_local(void *arg) void tlb_flush_remove_tables(struct mm_struct *mm) { int cpu = get_cpu(); + cpumask_var_t varmask; + + if (cpumask_any_but(mm_cpumask(mm), cpu) >= nr_cpu_ids) + return; + + if (!zalloc_cpumask_var(&varmask, GFP_ATOMIC)) { + /* Flush the TLB on all CPUs that have this mm loaded. */ + smp_call_function_many(mm_cpumask(mm), tlb_flush_remove_tables_local, (void *)mm, 1); + } + /* - * XXX: this really only needs to be called for CPUs in lazy TLB mode. + * CPUs in TLBSTATE_OK 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); + for_each_cpu(cpu, mm_cpumask(mm)) { + if (per_cpu(cpu_tlbstate.state, cpu) != TLBSTATE_OK) + cpumask_set_cpu(cpu, varmask); + } + + smp_call_function_many(varmask, tlb_flush_remove_tables_local, (void *)mm, 1); + free_cpumask_var(varmask); } static void do_flush_tlb_all(void *info) -- 2.14.4