Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2338963imm; Sat, 28 Jul 2018 14:57:23 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe8qpV9fRDn5sIHK1/JERkfBMtBRRDGfTbkUSj3y0j8cEHFNUkyJgnRbEtKf3unos6Gr0FY X-Received: by 2002:a62:5543:: with SMTP id j64-v6mr11943937pfb.188.1532815043813; Sat, 28 Jul 2018 14:57:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532815043; cv=none; d=google.com; s=arc-20160816; b=bUA7Q7vT5HWjc3jsVSWjRROILBzUaQBn9lakf6/jPsSM6FPJ/UvGuetJjMSzweXQk2 cry9EH2kQ2ioZeoI+GUeu2iPgc0gDCE+ob1ycrq7nYqs02iKVQA7zaWiNqdqz2icXULz 3vWh17ehA4DjJpkWKsm4KiuTK5NWp7AQr4ZrjgTel23Ak0ZNNG0RHda4DOhvvcByW8nY iTimLFRzEug3QwHO/4SdI9II0HRUpSjkhhtz7/JsFOMaRCp7RfWypCaQqAHnKfgSUzFj gr7vqaRUcQE/GBg1uJIUU7mJTPluazWmlq5QpcTIL5hRTBHc/S6Qr0Wyda3dLJAnLLHR PP4A== 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=GujgfVMVZAkTIyU72CKX+PBV9ByX8IvYhRhoaJIVTuM=; b=O4DUr28ugcZtaRoAyzjG96KGk74H7TCLvxAfUsIp0jrLFpBxFz8wcVabmNwwdM1XYq v61bQjUWnGCvEOQxSQm6BTOoJY2r32vSAyGCpkgqbwP04GfNImsh50C79N12fHpRJljy yb/GQz9T4Qe4TS/2UVtQDv05XOzCXwcjZ1ZNXBzCoRqdUiKgD2JMLOQ4WEZFkDfcVL9d GofYVUWP7BtOyWfvfnsjj1hmeOo2LhdQMCK16mchdC1+l5UJMHFxMZ3wUKh4PeWS2QxV GYWm85MvoIoBWuMc4KxYMCy73SLzegOvjv1gi4z5yAV5wMqMDmd7D+uxc5DPSALYxdPi ZEWg== 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 5-v6si1763281plt.342.2018.07.28.14.56.33; Sat, 28 Jul 2018 14:57:23 -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 S1731528AbeG1XWh (ORCPT + 99 others); Sat, 28 Jul 2018 19:22:37 -0400 Received: from shelob.surriel.com ([96.67.55.147]:44166 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731425AbeG1XWW (ORCPT ); Sat, 28 Jul 2018 19:22:22 -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 1fjXA0-0000QZ-T0; Sat, 28 Jul 2018 17:54:00 -0400 From: Rik van Riel 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 Subject: [PATCH 09/10] mm,x86: shoot down lazy TLB references at exit_mmap time Date: Sat, 28 Jul 2018 17:53:56 -0400 Message-Id: <20180728215357.3249-10-riel@surriel.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180728215357.3249-1-riel@surriel.com> References: <20180728215357.3249-1-riel@surriel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Suggested-by: Andy Lutomirski Suggested-by: Peter Zijlstra --- 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