From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-bn3nam01on0117.outbound.protection.outlook.com ([104.47.33.117]:48111 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1031949AbeCAP0a (ORCPT ); Thu, 1 Mar 2018 10:26:30 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Andy Lutomirski , Ingo Molnar , Sasha Levin Subject: [added to the 4.1 stable tree] x86/mm: Make flush_tlb_mm_range() more predictable Date: Thu, 1 Mar 2018 15:23:16 +0000 Message-ID: <20180301152116.1486-78-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Andy Lutomirski This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit ce27374fabf553153c3f53efcaa9bfab9216bd8c ] I'm about to rewrite the function almost completely, but first I want to get a functional change out of the way. Currently, if flush_tlb_mm_range() does not flush the local TLB at all, it will never do individual page flushes on remote CPUs. This seems to be an accident, and preserving it will be awkward. Let's change it first so that any regressions in the rewrite will be easier to bisect and so that the rewrite can attempt to change no visible behavior at all. The fix is simple: we can simply avoid short-circuiting the calculation of base_pages_to_flush. As a side effect, this also eliminates a potential corner case: if tlb_single_page_flush_ceiling =3D=3D TLB_FLUSH_ALL, flush_tlb_mm_range() could have ended up flushing the entire address space one page at a time. Signed-off-by: Andy Lutomirski Acked-by: Dave Hansen Cc: Andrew Morton Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Michal Hocko Cc: Nadav Amit Cc: Peter Zijlstra Cc: Rik van Riel Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/4b29b771d9975aad7154c314534fec235618175a.149= 2844372.git.luto@kernel.org Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- arch/x86/mm/tlb.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index 3c59d5bdbd6a..cd6e3339b19e 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -175,6 +175,12 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned= long start, unsigned long base_pages_to_flush =3D TLB_FLUSH_ALL; =20 preempt_disable(); + + if ((end !=3D TLB_FLUSH_ALL) && !(vmflag & VM_HUGETLB)) + base_pages_to_flush =3D (end - start) >> PAGE_SHIFT; + if (base_pages_to_flush > tlb_single_page_flush_ceiling) + base_pages_to_flush =3D TLB_FLUSH_ALL; + if (current->active_mm !=3D mm) { /* Synchronize with switch_mm. */ smp_mb(); @@ -191,15 +197,11 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigne= d long start, goto out; } =20 - if ((end !=3D TLB_FLUSH_ALL) && !(vmflag & VM_HUGETLB)) - base_pages_to_flush =3D (end - start) >> PAGE_SHIFT; - /* * Both branches below are implicit full barriers (MOV to CR or * INVLPG) that synchronize with switch_mm. */ - if (base_pages_to_flush > tlb_single_page_flush_ceiling) { - base_pages_to_flush =3D TLB_FLUSH_ALL; + if (base_pages_to_flush =3D=3D TLB_FLUSH_ALL) { count_vm_tlb_event(NR_TLB_LOCAL_FLUSH_ALL); local_flush_tlb(); } else { --=20 2.14.1