All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rik van Riel <riel@surriel.com>
To: linux-kernel@vger.kernel.org
Cc: kernel-team@fb.com, peterz@infradead.org, luto@kernel.org,
	x86@kernel.org, vkuznets@redhat.com, mingo@kernel.org,
	efault@gmx.de, dave.hansen@intel.com, will.daecon@arm.com,
	catalin.marinas@arm.com, benh@kernel.crashing.org,
	Rik van Riel <riel@surriel.com>
Subject: [PATCH 09/10] mm,x86: shoot down lazy TLB references at exit_mmap time
Date: Sat, 28 Jul 2018 17:53:56 -0400	[thread overview]
Message-ID: <20180728215357.3249-10-riel@surriel.com> (raw)
In-Reply-To: <20180728215357.3249-1-riel@surriel.com>

Shooting down lazy TLB references to an mm at exit_mmap time ensures
that no users of the mm_struct will be left anywhere in the system,
allowing it to be torn down and freed immediately.

Signed-off-by: Rik van Riel <riel@surriel.com>
Suggested-by: Andy Lutomirski <luto@kernel.org>
Suggested-by: Peter Zijlstra <peterz@infradead.org>
---
 arch/x86/Kconfig                   |  1 +
 arch/x86/include/asm/mmu_context.h |  1 +
 arch/x86/include/asm/tlbflush.h    |  2 ++
 arch/x86/mm/tlb.c                  | 15 +++++++++++++++
 4 files changed, 19 insertions(+)

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 6d4774f203d0..ecdfc6933203 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -75,6 +75,7 @@ config X86
 	select ARCH_MIGHT_HAVE_ACPI_PDC		if ACPI
 	select ARCH_MIGHT_HAVE_PC_PARPORT
 	select ARCH_MIGHT_HAVE_PC_SERIO
+	select ARCH_NO_ACTIVE_MM_REFCOUNTING
 	select ARCH_SUPPORTS_ATOMIC_RMW
 	select ARCH_SUPPORTS_NUMA_BALANCING	if X86_64
 	select ARCH_USE_BUILTIN_BSWAP
diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
index eeeb9289c764..529bf7bc5f75 100644
--- a/arch/x86/include/asm/mmu_context.h
+++ b/arch/x86/include/asm/mmu_context.h
@@ -238,6 +238,7 @@ static inline void arch_exit_mmap(struct mm_struct *mm)
 {
 	paravirt_arch_exit_mmap(mm);
 	ldt_arch_exit_mmap(mm);
+	lazy_tlb_exit_mmap(mm);
 }
 
 #ifdef CONFIG_X86_64
diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
index 511bf5fae8b8..3966a45367cd 100644
--- a/arch/x86/include/asm/tlbflush.h
+++ b/arch/x86/include/asm/tlbflush.h
@@ -538,6 +538,8 @@ extern void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch);
 	native_flush_tlb_others(mask, info)
 #endif
 
+extern void lazy_tlb_exit_mmap(struct mm_struct *mm);
+
 extern void tlb_flush_remove_tables(struct mm_struct *mm);
 extern void tlb_flush_remove_tables_local(void *arg);
 
diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
index ea4ef5ceaba2..7b1add904396 100644
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -713,6 +713,21 @@ void tlb_flush_remove_tables(struct mm_struct *mm)
 	put_cpu();
 }
 
+/*
+ * At exit or execve time, all other threads of a process have disappeared,
+ * but other CPUs could still be referencing this mm in lazy TLB mode.
+ * Get rid of those references before releasing the mm.
+ */
+void lazy_tlb_exit_mmap(struct mm_struct *mm)
+{
+	int cpu = get_cpu();
+
+	if (cpumask_any_but(mm_cpumask(mm), cpu) < nr_cpu_ids)
+		on_each_cpu_mask(mm_cpumask(mm), leave_mm, NULL, 1);
+
+	put_cpu();
+}
+
 static void do_flush_tlb_all(void *info)
 {
 	count_vm_tlb_event(NR_TLB_REMOTE_FLUSH_RECEIVED);
-- 
2.14.4


  parent reply	other threads:[~2018-07-28 21:54 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-28 21:53 [PATCH 0/10] x86,tlb,mm: more lazy TLB cleanups & optimizations Rik van Riel
2018-07-28 21:53 ` [PATCH 01/10] x86,tlb: clarify memory barrier in switch_mm_irqs_off Rik van Riel
2018-07-29  2:59   ` Andy Lutomirski
2018-07-28 21:53 ` [PATCH 02/10] smp: use __cpumask_set_cpu in on_each_cpu_cond Rik van Riel
2018-07-29  2:59   ` Andy Lutomirski
2018-07-28 21:53 ` [PATCH 03/10] smp,cpumask: introduce on_each_cpu_cond_mask Rik van Riel
2018-07-29  2:57   ` Andy Lutomirski
2018-07-29 12:00     ` Rik van Riel
     [not found]       ` <E710FBA5-CC5E-4941-ACBF-4AB3424F1F68@amacapital.net>
2018-07-29 17:39         ` Rik van Riel
2018-07-29 17:51         ` Rik van Riel
2018-07-29 18:55           ` Andy Lutomirski
2018-07-29 19:56             ` Linus Torvalds
2018-07-28 21:53 ` [PATCH 04/10] x86,mm: use on_each_cpu_cond for TLB flushes Rik van Riel
2018-07-29  2:58   ` Andy Lutomirski
2018-07-29 12:02     ` Rik van Riel
2018-07-28 21:53 ` [PATCH 05/10] mm,tlb: turn dummy defines into inline functions Rik van Riel
2018-07-28 21:53 ` [PATCH 06/10] mm,x86: skip cr4 and ldt reload when mm stays the same Rik van Riel
2018-07-29  4:21   ` Andy Lutomirski
2018-07-28 21:53 ` [PATCH 07/10] x86,mm: remove leave_mm cpu argument Rik van Riel
2018-07-28 21:53 ` [PATCH 08/10] arch,mm: add config variable to skip lazy TLB mm refcounting Rik van Riel
2018-07-28 21:53 ` Rik van Riel [this message]
2018-07-28 21:53 ` [PATCH 10/10] mm,sched: conditionally " Rik van Riel
2018-07-29  4:21   ` Andy Lutomirski
2018-07-29 12:11     ` Rik van Riel
2018-07-29 15:29       ` Andy Lutomirski
2018-07-29 16:55         ` Rik van Riel
2018-07-29 19:54     ` [PATCH v2 10/11] x86,tlb: really leave mm on shootdown Rik van Riel
2018-07-29 19:54     ` [PATCH v2 11/11] mm,sched: conditionally skip lazy TLB mm refcounting Rik van Riel
2018-07-30  9:55       ` Peter Zijlstra
2018-07-30 14:30         ` Rik van Riel
2018-07-30 16:26           ` Peter Zijlstra
2018-07-30 19:15             ` Rik van Riel
2018-07-30 19:30               ` Andy Lutomirski
2018-07-30 19:36                 ` Rik van Riel
2018-07-30 19:49                   ` Andy Lutomirski
2018-07-30 21:46                     ` Rik van Riel
2018-07-30 22:00                       ` Andy Lutomirski
2018-07-31  1:05             ` Rik van Riel
2018-07-31  9:12               ` Peter Zijlstra
2018-07-31 14:29                 ` Andy Lutomirski
2018-07-31 15:03                   ` Rik van Riel
2018-07-31 15:12                     ` Peter Zijlstra
2018-07-30 11:32 ` [PATCH 0/10] x86,tlb,mm: more lazy TLB cleanups & optimizations Ingo Molnar

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=20180728215357.3249-10-riel@surriel.com \
    --to=riel@surriel.com \
    --cc=benh@kernel.crashing.org \
    --cc=catalin.marinas@arm.com \
    --cc=dave.hansen@intel.com \
    --cc=efault@gmx.de \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=vkuznets@redhat.com \
    --cc=will.daecon@arm.com \
    --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.