From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 260E6C54EE9 for ; Fri, 16 Sep 2022 10:11:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230427AbiIPKLQ (ORCPT ); Fri, 16 Sep 2022 06:11:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231210AbiIPKKM (ORCPT ); Fri, 16 Sep 2022 06:10:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C673AB4E9; Fri, 16 Sep 2022 03:08:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B4CE3629E2; Fri, 16 Sep 2022 10:08:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C24A3C433C1; Fri, 16 Sep 2022 10:08:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663322934; bh=8INgkWtGw2iHL2E4EkyqZi3z6ZL6dVvdoW7k5Kw3w04=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=blm7I0R000Xs6kogsWnDD77S7/pOKxPOHGOrQtAwAVKE1la1n6YcDmcI3nsgBBIaS DdokItyYzDhnEZCBEIlChPNL07KqbNnN1FLvAyFEEq0gliB4pZHxDuW5JpI+TljfSw Tp0kT5Tml0y0qnf658hWOpAYvZoQvw1rvxS2smdw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn Subject: [PATCH 4.19 09/11] mm: Fix TLB flush for not-first PFNMAP mappings in unmap_region() Date: Fri, 16 Sep 2022 12:08:05 +0200 Message-Id: <20220916100443.118799924@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220916100442.662955946@linuxfoundation.org> References: <20220916100442.662955946@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jann Horn This is a stable-specific patch. I botched the stable-specific rewrite of commit b67fbebd4cf98 ("mmu_gather: Force tlb-flush VM_PFNMAP vmas"): As Hugh pointed out, unmap_region() actually operates on a list of VMAs, and the variable "vma" merely points to the first VMA in that list. So if we want to check whether any of the VMAs we're operating on is PFNMAP or MIXEDMAP, we have to iterate through the list and check each VMA. Signed-off-by: Jann Horn Signed-off-by: Greg Kroah-Hartman --- mm/mmap.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2567,6 +2567,7 @@ static void unmap_region(struct mm_struc { struct vm_area_struct *next = prev ? prev->vm_next : mm->mmap; struct mmu_gather tlb; + struct vm_area_struct *cur_vma; lru_add_drain(); tlb_gather_mmu(&tlb, mm, start, end); @@ -2581,8 +2582,12 @@ static void unmap_region(struct mm_struc * concurrent flush in this region has to be coming through the rmap, * and we synchronize against that using the rmap lock. */ - if ((vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)) != 0) - tlb_flush_mmu(&tlb); + for (cur_vma = vma; cur_vma; cur_vma = cur_vma->vm_next) { + if ((cur_vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)) != 0) { + tlb_flush_mmu(&tlb); + break; + } + } free_pgtables(&tlb, vma, prev ? prev->vm_end : FIRST_USER_ADDRESS, next ? next->vm_start : USER_PGTABLES_CEILING);