From: Nadav Amit <namit@vmware.com>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>,
linux-kernel@vger.kernel.org, Nadav Amit <namit@vmware.com>,
Dave Hansen <dave.hansen@linux.intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
"H. Peter Anvin" <hpa@zytor.com>,
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 [thread overview]
Message-ID: <20190525082203.6531-5-namit@vmware.com> (raw)
In-Reply-To: <20190525082203.6531-1-namit@vmware.com>
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 <dave.hansen@linux.intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Signed-off-by: Nadav Amit <namit@vmware.com>
---
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
next prev parent reply other threads:[~2019-05-25 8:22 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-25 8:21 [RFC PATCH 0/6] x86/mm: Flush remote and local TLBs concurrently Nadav Amit
2019-05-25 8:21 ` [RFC PATCH 1/6] smp: Remove smp_call_function() and on_each_cpu() return values Nadav Amit
2019-05-25 8:21 ` [RFC PATCH 2/6] cpumask: Purify cpumask_next() Nadav Amit
2019-05-25 8:32 ` Ingo Molnar
2019-05-27 8:30 ` Peter Zijlstra
2019-05-27 17:34 ` Nadav Amit
2019-05-25 8:22 ` [RFC PATCH 3/6] smp: Run functions concurrently in smp_call_function_many() Nadav Amit
2019-05-27 9:15 ` Peter Zijlstra
2019-05-27 17:39 ` Nadav Amit
2019-05-25 8:22 ` Nadav Amit [this message]
2019-05-27 9:24 ` [RFC PATCH 4/6] x86/mm/tlb: Refactor common code into flush_tlb_on_cpus() Peter Zijlstra
2019-05-27 18:59 ` Nadav Amit
2019-05-27 19:14 ` Peter Zijlstra
2019-05-25 8:22 ` [RFC PATCH 5/6] x86/mm/tlb: Flush remote and local TLBs concurrently Nadav Amit
2019-05-25 8:22 ` [Xen-devel] " Nadav Amit
2019-05-25 8:22 ` Nadav Amit via Virtualization
2019-05-25 8:38 ` Nadav Amit
2019-05-25 8:38 ` [Xen-devel] " Nadav Amit
2019-05-25 8:38 ` Nadav Amit via Virtualization
2019-05-25 8:38 ` Nadav Amit
2019-05-25 8:54 ` Juergen Gross
2019-05-25 8:54 ` [Xen-devel] " Juergen Gross
2019-05-27 9:47 ` Peter Zijlstra
2019-05-27 9:47 ` Peter Zijlstra
2019-05-27 9:47 ` [Xen-devel] " Peter Zijlstra
2019-05-27 10:21 ` Paolo Bonzini
2019-05-27 10:21 ` Paolo Bonzini
2019-05-27 10:21 ` [Xen-devel] " Paolo Bonzini
2019-05-27 12:32 ` Peter Zijlstra
2019-05-27 12:32 ` Peter Zijlstra
2019-05-27 12:32 ` [Xen-devel] " Peter Zijlstra
2019-05-27 12:32 ` Peter Zijlstra
2019-05-27 12:45 ` Paolo Bonzini
2019-05-27 12:45 ` [Xen-devel] " Paolo Bonzini
2019-05-27 12:45 ` Paolo Bonzini
2019-05-27 12:45 ` Paolo Bonzini
2019-05-27 10:21 ` Paolo Bonzini
2019-05-27 17:49 ` Nadav Amit via Virtualization
2019-05-27 17:49 ` Nadav Amit
2019-05-27 17:49 ` Nadav Amit
2019-05-27 17:49 ` [Xen-devel] " Nadav Amit
2019-05-27 9:47 ` Peter Zijlstra
2019-05-25 8:54 ` Juergen Gross
2019-05-25 8:54 ` Juergen Gross
2019-05-25 8:22 ` Nadav Amit
2019-05-25 8:22 ` [RFC PATCH 6/6] x86/mm/tlb: Optimize local TLB flushes Nadav Amit
2019-05-27 8:28 ` [RFC PATCH 0/6] x86/mm: Flush remote and local TLBs concurrently Peter Zijlstra
2019-05-27 9:59 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190525082203.6531-5-namit@vmware.com \
--to=namit@vmware.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.