Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2534518rwb; Mon, 3 Oct 2022 02:07:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5BjaSHCrAowcYtCTy2Tk1kV14s1fGpxpmOgMEVk1y2NhQIeH0fAd1C+xidzweQMshoXQvM X-Received: by 2002:a17:90b:692:b0:203:6c21:b4aa with SMTP id m18-20020a17090b069200b002036c21b4aamr10856757pjz.227.1664788041725; Mon, 03 Oct 2022 02:07:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664788041; cv=none; d=google.com; s=arc-20160816; b=0iAEPPNMebjFnGPxqKezywY9yNvvimpRqwb/AIhULlg1POOnhx6VbwipjdZHhUnacB soZm89FZ0BWHLgugYgYklgvWVch9qCAItj5Dz2kZeSFPkMx8vUjzDbd3Yz+fEzHfLhoo itSx119rSpKYt2QsT7sakwHX0tftUrHLD7FrUr7uN3Qqw5QGsFaidlror7daJJkYxPiD EccSORLNL05TimWdxWPpxfXXbwevfejg40vIIYd9zB4BrE3oPY/Xz95tKEENC6CbFRjH v//rzf9mVXzyOvuOSpN6tFhDPo0HHNWWwemPRjo+3OosbyTTrZ2zWxEppi5Jec/9Aws2 Q90A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=K5SNE2I9YkNsN41mubSKdZUweOQQLZU7GKx0824l/10=; b=QHQx7OSebeeNgjQQGmzvPGKVWXZVrQinxgAq4imNytgpzTgI2m3Rtdg0gFpGWs0R7F FSrmEiTxabpv4eexamFCWLwpjvVpjpJPYdu6iL2qSyYK7rOtGq3TWUugqJ9R2CAlvYGT Ohmb8LVV9pHOwkIFaCrR7Q/DfTXIa4HsRB3vl/274PMDFtuNTYvRkDgrNTIDP3sI6cN1 JauJFNqtg75E3P6CUrFrZvQ0dEy9abTnh+ljj14g+3KfppFvD8k6l6VfaHAbLNrs5a3t TOqS2jootk525L8QUWl45T2thvD8w1RsOrn9NccZwrWFjWsHYuNHNYAGX73VbJK5ECwB 0hhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pFFCeKEt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s4-20020a634504000000b0043dc7961525si9966547pga.470.2022.10.03.02.07.07; Mon, 03 Oct 2022 02:07:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pFFCeKEt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230139AbiJCIoc (ORCPT + 99 others); Mon, 3 Oct 2022 04:44:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230157AbiJCIoE (ORCPT ); Mon, 3 Oct 2022 04:44:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 202B9255B1; Mon, 3 Oct 2022 01:22:12 -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 4C33060FCE; Mon, 3 Oct 2022 07:24:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BB3CC433C1; Mon, 3 Oct 2022 07:24:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664781871; bh=4EQt3gJL7vdLpZkM2VX2fkNa6c6Mdv3DxSB71+wkw9Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pFFCeKEtQaktZ0Rbv9CHS19i6ZDmL9IbBNogZR2e9UcIySBgwYBoCVdtN43E+2h42 /UWjtz2F/XBLU9RDBi+6CMZBWNOgwvihkHZx7SlSF9fOSIJGfDeAzPP0BayAcnTJxn vT9IputnkTstoieFJ2oE75a6sTW1SVoF+5zOeA3Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alistair Popple , Nadav Amit , "Huang, Ying" , David Hildenbrand , Peter Xu , Alex Sierra , Ben Skeggs , Felix Kuehling , huang ying , Jason Gunthorpe , John Hubbard , Karol Herbst , Logan Gunthorpe , Lyude Paul , Matthew Wilcox , Paul Mackerras , Ralph Campbell , Andrew Morton Subject: [PATCH 4.19 11/25] mm/migrate_device.c: flush TLB while holding PTL Date: Mon, 3 Oct 2022 09:12:14 +0200 Message-Id: <20221003070715.743561818@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003070715.406550966@linuxfoundation.org> References: <20221003070715.406550966@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alistair Popple commit 60bae73708963de4a17231077285bd9ff2f41c44 upstream. When clearing a PTE the TLB should be flushed whilst still holding the PTL to avoid a potential race with madvise/munmap/etc. For example consider the following sequence: CPU0 CPU1 ---- ---- migrate_vma_collect_pmd() pte_unmap_unlock() madvise(MADV_DONTNEED) -> zap_pte_range() pte_offset_map_lock() [ PTE not present, TLB not flushed ] pte_unmap_unlock() [ page is still accessible via stale TLB ] flush_tlb_range() In this case the page may still be accessed via the stale TLB entry after madvise returns. Fix this by flushing the TLB while holding the PTL. Fixes: 8c3328f1f36a ("mm/migrate: migrate_vma() unmap page from vma while collecting pages") Link: https://lkml.kernel.org/r/9f801e9d8d830408f2ca27821f606e09aa856899.1662078528.git-series.apopple@nvidia.com Signed-off-by: Alistair Popple Reported-by: Nadav Amit Reviewed-by: "Huang, Ying" Acked-by: David Hildenbrand Acked-by: Peter Xu Cc: Alex Sierra Cc: Ben Skeggs Cc: Felix Kuehling Cc: huang ying Cc: Jason Gunthorpe Cc: John Hubbard Cc: Karol Herbst Cc: Logan Gunthorpe Cc: Lyude Paul Cc: Matthew Wilcox Cc: Paul Mackerras Cc: Ralph Campbell Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/migrate.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2359,13 +2359,14 @@ next: migrate->dst[migrate->npages] = 0; migrate->src[migrate->npages++] = mpfn; } - arch_leave_lazy_mmu_mode(); - pte_unmap_unlock(ptep - 1, ptl); /* Only flush the TLB if we actually modified any entries */ if (unmapped) flush_tlb_range(walk->vma, start, end); + arch_leave_lazy_mmu_mode(); + pte_unmap_unlock(ptep - 1, ptl); + return 0; }