From nobody Tue Apr 7 12:04:48 2026 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 A33DBECAAD8 for ; Fri, 16 Sep 2022 10:08:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229787AbiIPKIS (ORCPT ); Fri, 16 Sep 2022 06:08:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230453AbiIPKHy (ORCPT ); Fri, 16 Sep 2022 06:07:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A1FAAB427; Fri, 16 Sep 2022 03:07:48 -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 775CB629EF; Fri, 16 Sep 2022 10:07:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6701EC433D6; Fri, 16 Sep 2022 10:07:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663322866; bh=JwgEMcm8ImgwOu3IkVy+p4cHjDKBDufgt2Mp2DMsJS0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jph5Iz/RgFioBaiBuf6LK0GjOdyact1KseJ3PHPHHVepy1T9Y08BBKsEIywJL3AsY LFZ/OnY6UIhWetHZ6ezfsfFLw8S5BjniTR2FrgdSBGgJnaCeqHRjA6QlP+PB1PcgjX E3oE4BvuNZGO9k5RWmpKKdBFPgGxt7cgy6g9KM60= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn Subject: [PATCH 4.9 6/7] mm: Fix TLB flush for not-first PFNMAP mappings in unmap_region() Date: Fri, 16 Sep 2022 12:07:49 +0200 Message-Id: <20220916100441.352669614@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220916100440.995894282@linuxfoundation.org> References: <20220916100440.995894282@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 @@ -2524,6 +2524,7 @@ static void unmap_region(struct mm_struc { struct vm_area_struct *next =3D prev ? prev->vm_next : mm->mmap; struct mmu_gather tlb; + struct vm_area_struct *cur_vma; =20 lru_add_drain(); tlb_gather_mmu(&tlb, mm, start, end); @@ -2538,8 +2539,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)) !=3D 0) - tlb_flush_mmu(&tlb); + for (cur_vma =3D vma; cur_vma; cur_vma =3D cur_vma->vm_next) { + if ((cur_vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)) !=3D 0) { + tlb_flush_mmu(&tlb); + break; + } + } =20 free_pgtables(&tlb, vma, prev ? prev->vm_end : FIRST_USER_ADDRESS, next ? next->vm_start : USER_PGTABLES_CEILING);