Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2675491imm; Mon, 16 Jul 2018 12:05:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdzAZhfUwCQyjaHEupK/ypT6wYHbm1Wvj4wB3xN9oR0SYn9zffxvN52UJFzJW2w7dCMzQoI X-Received: by 2002:a65:5a8a:: with SMTP id c10-v6mr16045207pgt.389.1531767937084; Mon, 16 Jul 2018 12:05:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531767937; cv=none; d=google.com; s=arc-20160816; b=OpCZ93SJgmW/Ie+Vln/EEMsWlLGUVPOcl1TewLN3zti3GOj1CmOqoRN7DUsuBP0i1I jY178PbNL+fPXuF0qTdo71VFwyTssyaqk4w5EhYkmrOc08R47RGClXRid9msLT9bxU2c fW30lLQ1IcVEHMyVLb0JM82oQDJZA8psO9D7+DuJ3LpYMGs7uQGs9HAjmIIwfgmr8OFY WPGyZ9QyOnSV2urQml1jWBgL1956iL+ZDIBImigaPG9/9XN4ieF5pT8pYm6RaVI4DOWE lxhoEoZPJhQcOTnAqsTrCNxKCRu8rwPkjjYduVkKxJe/Hay/R2vuUFVeTuTylFtU5xsn /Ndg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=3m13tCU+zZCfvCt7k9db98QypejO2JwbyPKIsymN0MI=; b=e/9LGf5J8tybkyyQFCL2NpSdfDiRlT0oTy8x1uMeUiUnKFWqSCpEo1B/NZoP+cBl6S +hWSuG1e6/C2c51mJllSSoqcupAXKBnKlV3PD7tBqgPRhjST1/hFMSPePCCtb+MUjcFj ypIeq/LotHW3Qsh+Ufu4rZgq9E85f7Z/sxOmiURsnvMuWvkWWWQhBNFdYiWe2s8dQO2i d9pAIj4dBExzqQ5dnOMaJeABGz/lrKF9jD7W3/Nn1vvdo2v7MrfvrMbG57/0JGFCiyPf ak+ZukH8XdldNC7an1Y/jnhQzqPya/fxECjcGL+srXvbS8PHvogx15CJmO4hPzqY5CPu FFHw== 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 e14-v6si17794542pgg.345.2018.07.16.12.05.21; Mon, 16 Jul 2018 12:05:37 -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 S1730876AbeGPTc6 (ORCPT + 99 others); Mon, 16 Jul 2018 15:32:58 -0400 Received: from shelob.surriel.com ([96.67.55.147]:36136 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729952AbeGPTcg (ORCPT ); Mon, 16 Jul 2018 15:32:36 -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 1ff8ma-0003RH-JS; Mon, 16 Jul 2018 15:03:40 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, luto@kernel.org, efault@gmx.de, kernel-team@fb.com, mingo@kernel.org, dave.hansen@intel.com, Rik van Riel Subject: [PATCH 5/7] x86,tlb: only send page table free TLB flush to lazy TLB CPUs Date: Mon, 16 Jul 2018 15:03:35 -0400 Message-Id: <20180716190337.26133-6-riel@surriel.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180716190337.26133-1-riel@surriel.com> References: <20180716190337.26133-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 !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. Signed-off-by: Rik van Riel Acked-by: Dave Hansen Tested-by: Song Liu --- 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(); } -- 2.14.4