Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1418578ybi; Sat, 25 May 2019 01:25:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqz0qXpiXe5PWuv80Bsvbz+tUx2p9Ld14AtWY9poedkzi7y6HE2gDxYd+6w1Jt3/jwO7cCQo X-Received: by 2002:a62:6444:: with SMTP id y65mr119225517pfb.148.1558772735846; Sat, 25 May 2019 01:25:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558772735; cv=none; d=google.com; s=arc-20160816; b=YGe+/h3mTZ2GtSmtpHOF6FUoWF03IbEdlfI0fCSHSTpTSpiIe4RSXdu2MYmZzjRiJY J0eHcq3qcmIawK4mVohAdlutWRTeV25BtaMP4XPrZDU+XCQPzYiWJIDt2dK4hoRxLr7y Gs509wlkge0A4mHSa5UZYiKtHzmbZ34HshteaNEGDNAwTPPgT4zcXkOrCh8D1GASaK5e lsd8cVd/AEV7sLobEyjWrWwQKRibL9avj0+UwyopfQpI8cN16eeoa7B7imu2IExUjCHq VshUFMWPZCXQyKnrr8S55BH5db//J1IN4Eq8PE4VcpIFPqWVmwOyure7JSGMbdTwGRmq iYpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Lw/xJ4sUfF0PL59NitOOD48j0ji7hMX9XqzlL67vWpw=; b=EGp66VYXkqrNifvYmaemKipDgdqkgOAvA4IlBaR8Quk/uYrBRflmfZOdV7j5WIIpc+ Gh47NDZMcSFv0qy6+4vGh1J8bkE7ZhFZFKPbxR3moBCtkcct6lOtuFoF5o3mDi8QrOdg rnD9e8A7DDT0WqjsXUez7ujNzH8rjNFrFygw3jCe2uL+TWnzreWSvpjC5VWBZg9IejhM LAN4p8ZSCezJBdmynety1vbe4HtOrNLWX6+h7o4/u0xHIcqeOZdicSzntGLYZSGOyxW5 3uZY6FW2gLLThJWy7/X9ajoSvfjpz2oGKBI+UKyiLIdrBthAhxAkf9phi9++Fr9PdeEl AGiA== 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; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t7si342847pgu.3.2019.05.25.01.25.20; Sat, 25 May 2019 01:25:35 -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; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726764AbfEYIW1 (ORCPT + 99 others); Sat, 25 May 2019 04:22:27 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:39634 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726582AbfEYIWO (ORCPT ); Sat, 25 May 2019 04:22:14 -0400 Received: by mail-pg1-f196.google.com with SMTP id w22so6315572pgi.6 for ; Sat, 25 May 2019 01:22:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Lw/xJ4sUfF0PL59NitOOD48j0ji7hMX9XqzlL67vWpw=; b=dcX1JF1FKOZ3q1jP7SG8Ulye9UVGJ/hXN0Y0/2Q+lCs28IN7DQqV3szmLuxKrjwksy /fJy95HzGD7+3nxE6Ab76GzH/feqr1JeZ6D70GspeG4IYX0awZ9HdSxLr/hVEnQ33yZi kDfP9/Q1/D3xTTRmZhIh363JgzEc6hUuab7B4a6IufF2vlyPPFz4lm+akpJUPJXXUH2B AQviHBIN2XLtIj/NM7faE6TaS2LagR7AvcOjjrhA4Y2jZwlEvnJJSC1hApPXOCfj/wic Siji/W0Ss9v3HAAL0g770iKuG4DWp/m96+16BvTDbWsmNer4BMmJ/izGJMlCd0bXsFq0 A50g== X-Gm-Message-State: APjAAAUJq/5yQLD/n0l7jGimU6vJuIRM8HW5Fc57uxmoRLMI6SEUJQVT zGnDT91SrqsyiQnF6tqega4= X-Received: by 2002:a63:cc4e:: with SMTP id q14mr107898610pgi.84.1558772532865; Sat, 25 May 2019 01:22:12 -0700 (PDT) Received: from htb-2n-eng-dhcp405.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id e4sm1438505pgi.80.2019.05.25.01.22.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 May 2019 01:22:11 -0700 (PDT) From: Nadav Amit To: Ingo Molnar , Peter Zijlstra , Andy Lutomirski Cc: Borislav Petkov , linux-kernel@vger.kernel.org, Nadav Amit , Dave Hansen , Thomas Gleixner , "H. Peter Anvin" , x86@kernel.org Subject: [RFC PATCH 4/6] x86/mm/tlb: Refactor common code into flush_tlb_on_cpus() Date: Sat, 25 May 2019 01:22:01 -0700 Message-Id: <20190525082203.6531-5-namit@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190525082203.6531-1-namit@vmware.com> References: <20190525082203.6531-1-namit@vmware.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org arch_tlbbatch_flush() and flush_tlb_mm_range() have very similar code, which is effectively the same. Extract the mutual code into a new function flush_tlb_on_cpus(). There is one functional change, which should not affect correctness: flush_tlb_mm_range compared loaded_mm and the mm to figure out if local flush is needed. Instead, the common code would look at the mm_cpumask() which should give the same result. Performance should not be affected, since this cpumask should not change in such a frequency that would introduce cache contention. Cc: Dave Hansen Cc: Andy Lutomirski Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: "H. Peter Anvin" Cc: x86@kernel.org Signed-off-by: Nadav Amit --- arch/x86/mm/tlb.c | 55 ++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 7f61431c75fb..afd2859a6966 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -733,7 +733,11 @@ static inline struct flush_tlb_info *get_flush_tlb_info(struct mm_struct *mm, unsigned int stride_shift, bool freed_tables, u64 new_tlb_gen) { - struct flush_tlb_info *info = this_cpu_ptr(&flush_tlb_info); + struct flush_tlb_info *info; + + preempt_disable(); + + info = this_cpu_ptr(&flush_tlb_info); #ifdef CONFIG_DEBUG_VM /* @@ -761,6 +765,23 @@ static inline void put_flush_tlb_info(void) barrier(); this_cpu_dec(flush_tlb_info_idx); #endif + preempt_enable(); +} + +static void flush_tlb_on_cpus(const cpumask_t *cpumask, + const struct flush_tlb_info *info) +{ + int this_cpu = smp_processor_id(); + + if (cpumask_test_cpu(this_cpu, cpumask)) { + lockdep_assert_irqs_enabled(); + local_irq_disable(); + flush_tlb_func_local(info, TLB_LOCAL_MM_SHOOTDOWN); + local_irq_enable(); + } + + if (cpumask_any_but(cpumask, this_cpu) < nr_cpu_ids) + flush_tlb_others(cpumask, info); } void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, @@ -769,9 +790,6 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, { struct flush_tlb_info *info; u64 new_tlb_gen; - int cpu; - - cpu = get_cpu(); /* Should we flush just the requested range? */ if ((end == TLB_FLUSH_ALL) || @@ -786,18 +804,9 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, info = get_flush_tlb_info(mm, start, end, stride_shift, freed_tables, new_tlb_gen); - if (mm == this_cpu_read(cpu_tlbstate.loaded_mm)) { - lockdep_assert_irqs_enabled(); - local_irq_disable(); - flush_tlb_func_local(info, TLB_LOCAL_MM_SHOOTDOWN); - local_irq_enable(); - } - - if (cpumask_any_but(mm_cpumask(mm), cpu) < nr_cpu_ids) - flush_tlb_others(mm_cpumask(mm), info); + flush_tlb_on_cpus(mm_cpumask(mm), info); put_flush_tlb_info(); - put_cpu(); } @@ -832,13 +841,11 @@ void flush_tlb_kernel_range(unsigned long start, unsigned long end) } else { struct flush_tlb_info *info; - preempt_disable(); info = get_flush_tlb_info(NULL, start, end, 0, false, 0); on_each_cpu(do_kernel_range_flush, info, 1); put_flush_tlb_info(); - preempt_enable(); } } @@ -856,21 +863,11 @@ static const struct flush_tlb_info full_flush_tlb_info = { void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch) { - int cpu = get_cpu(); - - if (cpumask_test_cpu(cpu, &batch->cpumask)) { - lockdep_assert_irqs_enabled(); - local_irq_disable(); - flush_tlb_func_local(&full_flush_tlb_info, TLB_LOCAL_SHOOTDOWN); - local_irq_enable(); - } - - if (cpumask_any_but(&batch->cpumask, cpu) < nr_cpu_ids) - flush_tlb_others(&batch->cpumask, &full_flush_tlb_info); + preempt_disable(); + flush_tlb_on_cpus(&batch->cpumask, &full_flush_tlb_info); + preempt_enable(); cpumask_clear(&batch->cpumask); - - put_cpu(); } static ssize_t tlbflush_read_file(struct file *file, char __user *user_buf, -- 2.20.1