Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2522515rwb; Mon, 3 Oct 2022 01:53:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Fob838MWt1vFRqM1OM9cFXpoNEaR+DFPvR7T3AScDsNuDPbPXFe827rnzAVNnJwwUHDPH X-Received: by 2002:a63:f250:0:b0:44e:633b:23ae with SMTP id d16-20020a63f250000000b0044e633b23aemr3907913pgk.17.1664787234024; Mon, 03 Oct 2022 01:53:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664787234; cv=none; d=google.com; s=arc-20160816; b=f/6tIRJnMj8LU8csHzNNiEYp0vwpJm2iaq+9I9PHycNX/gvzHrBN/tD+44LvO9lS8Q ZkNi3ZsNhbvoDguC3MUS7PJOiLSIe3CLWH+1GZi9m1ZcsWyjXIisLF9k5x7oDLvn4rys EEyNY9zDtvmNjx7d5dpa0egjPcE0qu1QHh10cs6/CkFfbUMUoFzu+5tv/B+tQH7mRmhF AhcSOh8N3TsxPM6h2nFB3hG1CVcnoOYfhuT0rjT0S09L9KdApL9i5Dtxwrnavb/MFgiY r5Cpo67lFAcKn1P9YjOG9peLKAR0FcIg1ezhS1ClKkRFZMwwqP/Ikcq3QRtTPNy6djgT vzow== 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=T3w7RRjzCYjKCN09vsO/iitfzAQjqZafEuxXL0yaJ8E=; b=P8QW7u/IHEm3M5SvG2GBB4832C73HZMB8zII7Ll8duMR5f9zLsjlXrIvl9qybtf0wH HC8LQc7zt9796+rEigs5RvIWA+4/MsDEffbIO8Txvgi4o70MG1WDSGIOMyet0a1nDVgG jWyntQiVu/n9Hx40qgZUrHCzISgSAUMDgQdpNLzclo/oFo9P1OHrfDtlGgo69/i9Xa+F /NpupLGVlAJN1drB8NKtH1NLzKH0vAXaL2GMFMsYwW0dUrFgyFIxs5w1dAunIXdMJ4O7 3kgqPqEAvIEPfuaIW54LPiU9cjDMxGeM7X3ALmCKyxHDCzK7I+1jymQm2JV6I5zSYnAy CMwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Tg20w5kU; 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 b3-20020a056a000cc300b0053a8225dc47si10944572pfv.55.2022.10.03.01.53.43; Mon, 03 Oct 2022 01:53:53 -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=Tg20w5kU; 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 S231272AbiJCHbX (ORCPT + 99 others); Mon, 3 Oct 2022 03:31:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231237AbiJCH3i (ORCPT ); Mon, 3 Oct 2022 03:29:38 -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 D4F685F48; Mon, 3 Oct 2022 00:20: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 ams.source.kernel.org (Postfix) with ESMTPS id 6A445B80E80; Mon, 3 Oct 2022 07:19:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9118AC433C1; Mon, 3 Oct 2022 07:19:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664781548; bh=ZrxVxtXp/dUbfCF43tK79HuuLUoVMBvREU6yefQDcls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tg20w5kUAafDZfG3IHf1IKFuXlJyU1g1rsBPlgwb18w8HnOW05s7yztd48+hyC+qr 8aB73bL+b0git9cLwsDwOFImJASEvdJyQQ61og+q6HtDIcdTw9eCelgUIJQaUa4s4/ ZYR6WvW09hvX5v26gtqQy8ezud4Hl/RTEUH7pADY= 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.15 32/83] mm/migrate_device.c: flush TLB while holding PTL Date: Mon, 3 Oct 2022 09:10:57 +0200 Message-Id: <20221003070722.804229905@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003070721.971297651@linuxfoundation.org> References: <20221003070721.971297651@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 @@ -2422,13 +2422,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; }