Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2491747rwb; Mon, 3 Oct 2022 01:13:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM51HPhjP2VlPl/Nu3wThjwWXoAyn/dNhTjXozyV4X/0d2tQMN1lSTaJ7eppsTvT0+pl3wsT X-Received: by 2002:a17:902:7c97:b0:17f:5abf:9450 with SMTP id y23-20020a1709027c9700b0017f5abf9450mr4009002pll.19.1664784813792; Mon, 03 Oct 2022 01:13:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664784813; cv=none; d=google.com; s=arc-20160816; b=J5m40Q5Pi/1kgOhiNOxsc7caCOdE4xc6eiNAWK7EBof6KFM4dromQzG1CSCOwZNT1P 8qXT41LUFTE/VlIAIkg8dxcrUfSt6PqaERVOkrC9YDQ3tq8ZPlquTV5XxL46O6vQTktg Ajc+/0vgk7QcIhlEYyl5FFESeEzzRUTdXsaXHx+SAhT1EVabgBv1HGaCJdRNAiYTr+PT KakyOod2zFk69LDKbdj5W17pBWqqgThOu/lvF37yB0vLi58SNsl1rkRWY/gpLFyN8Dq5 TG1fQDhunGTfhzhLXhp9U3bpzzXrs9P0JTJOsOycriftcjCOcM2XO3VhFBcqRs7EGjWD m1qg== 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=sdHk7TDsiXPKUlnQERtJ1oLL7jJVvdtreBzACt4xMcM=; b=YgbgHZMK1bFyWt+rGmTRoeCmbYEkzVyWfs0BGDQ93Vh3UFzLLbXwPYeQ9BqOx6vdmB hQfEXgG8zwB6j5nknR5D4486XpCfUhK4/9Ai7im6N/03ldlyd5EGPHiJfC9392LRcabf qLs8GuPkOoRc9kRWZIvxihqxmhNimru65Q7Z7/87iEAf68rnK5rAwCsQpNTyvQrvnUTg AZEFhdnwEBi05lArlsagrEVJcS5OzliyUKYwn8cRu2Y0jACNYpzlF7EAekCtCGeLsm/g VRtI7rk426fFC3KkAx90IzdQYV5voQh+yROqqDT12SVGDZMEiZ05wjudEHEVKNV3cEdG ON+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CuRgBr5R; 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 m17-20020a635811000000b0043969d624dcsi9168289pgb.675.2022.10.03.01.13.20; Mon, 03 Oct 2022 01:13:33 -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=CuRgBr5R; 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 S231555AbiJCHfV (ORCPT + 99 others); Mon, 3 Oct 2022 03:35:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231637AbiJCHdz (ORCPT ); Mon, 3 Oct 2022 03:33:55 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F7D452816; Mon, 3 Oct 2022 00:21:39 -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 ams.source.kernel.org (Postfix) with ESMTPS id C455FB80E8A; Mon, 3 Oct 2022 07:21:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6141C43141; Mon, 3 Oct 2022 07:21:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664781683; bh=KaMSlhEnD8Oh2vtw1gsEwjhcYw/rYuCcKBM7s16lLE0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CuRgBr5RCNB6WFCm0zgcsccdvPDa3ZlpMZqE6SMAN/gzwZPLJjjd8vK8Qk8EDjGss I/7BON/ngJ85U8uQO4Ntn8aitJhMWqylUcoTC+j9lIsecyCAvgKCjizRmm3kTIR1mY AStqpUK3YRGYbJyHwHZXEtmdwCROmNQXoJ358Gbk= 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 5.10 25/52] mm/migrate_device.c: flush TLB while holding PTL Date: Mon, 3 Oct 2022 09:11:32 +0200 Message-Id: <20221003070719.479188014@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003070718.687440096@linuxfoundation.org> References: <20221003070718.687440096@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 @@ -2473,13 +2473,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; }