Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3418434imm; Tue, 17 Jul 2018 04:40:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd8a1fPSkWxrHtUnc5rGNdjAYl2g+amqykQSc1rte3iX5863mN+2NwNhkhiLu4sulTBbToB X-Received: by 2002:a62:3d41:: with SMTP id k62-v6mr317061pfa.35.1531827604582; Tue, 17 Jul 2018 04:40:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531827604; cv=none; d=google.com; s=arc-20160816; b=hiTJ+YqzHbY9rWIW+6B9oAFfu52PKw0LXUklInVEhHym1JZDHm6Vmk3kiMahjNjNhn OHcnSHb1ljplmPaPT+vgsAyFpqAgxADNv+R5havFcYwMHKTmcPHGoDVB1NTbljiS/G1B n0nbn59WiW08kbSXNWG/NvsiGNbCG7oBfi8mYBTfK2E0fzZ0gCrQw2V0fQsPsl+XbHMO tLy2T3+IkijpgwGk10WbJK8+vNakgPX5uvQkSEv55tqGyXyDhb2lRgfoY5zHFkbmKf+9 jqBqcWCzBTWWHElOFZJH87pKkfnwLmr9BzmeNUZrNUNJSTtv0Km1g+RplVDaML4EMtb3 xbSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=uSl+pg/KU1ajAyGTPkJ3M3FKmuBXeJFv0lcSEru4HfA=; b=iIKTioN9u+y/0hSbO51HvGZkpmLCToy6PPgQTgc3vGKs/nveWYy97X1nz5lTExIdVE yt16BKn2rL2n6PQOy6YqqH0w2J2ppQGahi4YqQI7DFg4iR/Y+sz1Ir31qtUIdk2ISsAI wGR3AdQW1arI+B9hkb2mQehzgIlRpJIhoEMa9V1kHytfgnUCppm0WMd/Vn16T+8PAVn3 8/mQX+0Nw/k2F6/itNqv1zImQXwTiE4a0GKTFQamaMThdp6ZokyL6kw3uHAckL7XmE/V lc1iXgy+ucnzIJt4p2iNDu4YONM06VJT5rrLOd1XyZdmN9DZva6h4G0yZ8A8BMzPq8Vp alVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=TW4OVh5l; 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 p9-v6si702665pff.30.2018.07.17.04.39.48; Tue, 17 Jul 2018 04:40:04 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=TW4OVh5l; 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 S1731079AbeGQML2 (ORCPT + 99 others); Tue, 17 Jul 2018 08:11:28 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:50194 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730780AbeGQML2 (ORCPT ); Tue, 17 Jul 2018 08:11:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=uSl+pg/KU1ajAyGTPkJ3M3FKmuBXeJFv0lcSEru4HfA=; b=TW4OVh5l8vsZaIwDpJ6IH47mt 2a4TMh83GNBuvKeMljVecBTRJ9zzKdq7Ni1Ru6aQlXVQYGg/zkEsriUJg6RFIvr5knZZpyyTFVAXZ TDLlIyjiZH73Yfx5GOiJXcWpsMnrNvf32KblN2oXOen3jLr7HLMpU2r87htJM31rtCBjvNzVLxiqq am99yqOzN/M+bl5gDo+mz+PKQzsi5EJV92Z6A6Ze7fjuxN/GavjKWSe5OjBBlZ9cM4qhMZX64q6fH cPWaL0FySorH5y9vCyO9wF4mcwWdIkSFtcGw0Dh2RN9zEuZweCFH245UZd5a34nMEWZS9NsIeQ07z LRSdMVY6Q==; 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 1ffOJw-00029R-E3; Tue, 17 Jul 2018 11:39:08 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id BF6E920289332; Tue, 17 Jul 2018 13:39:06 +0200 (CEST) Date: Tue, 17 Jul 2018 13:39:06 +0200 From: Peter Zijlstra To: dave.hansen@intel.com, linux-kernel@vger.kernel.org, mingo@kernel.org, songliubraving@fb.com, hpa@zytor.com, tglx@linutronix.de, torvalds@linux-foundation.org, riel@surriel.com Cc: linux-tip-commits@vger.kernel.org Subject: Re: [tip:x86/mm] x86/mm/tlb: Only send page table free TLB flush to lazy TLB CPUs Message-ID: <20180717113906.GV2476@hirez.programming.kicks-ass.net> References: <20180716190337.26133-6-riel@surriel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 17, 2018 at 02:35:41AM -0700, tip-bot for Rik van Riel wrote: > 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); That really wants to be __cpumask_set_cpu(). Using LOCK prefix instructions to set local bits is kinda pointless and expensive. > + } > +} > + > 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(); > } Also, was there a reason to re-implement on_each_cpu_cond() ? (which btw also wants that __cpumask_set_bit fix).