Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1606678rwe; Fri, 2 Sep 2022 00:03:59 -0700 (PDT) X-Google-Smtp-Source: AA6agR73gBQspWpN7hdNUVfWjnoHP0b90GWTu1KhR4yXA3YT4m55u3twV++BdQuCV2G26PT80bjd X-Received: by 2002:a05:6402:31e7:b0:447:d664:83eb with SMTP id dy7-20020a05640231e700b00447d66483ebmr27872042edb.276.1662102239671; Fri, 02 Sep 2022 00:03:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662102239; cv=none; d=google.com; s=arc-20160816; b=PSmrFyP9UY8KoTCvc5hijvNX0Ppff+RPAyT/IJGex13/gc8VJ1Qgne3MbOoNxqoCjz tcvwOwD+tWXI5XzPCYX6hNYCQsfW4vNM4tqqJ54Ib78tMb3sq3vdciEmLl0qjuXJrKQ+ znjfRSrVn+X2KEbJ+E/n+ZEEPzYc34KRB7Bbh3+8hKcDc6waXS7je/Uwqg090MsV3ajW Wo5X7NBXEHIwR+K7vV8NVFayxtAxGhBrtW/8Zft6K3wbBhnH296F9A22Llj97c0d9N6H r7thjP7IUE4Whp3jsvZrrPXqW9voSvOLyqaBOUEDkBxG50e2W/u9vE8ouDTPr1eiFkL9 6fvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=K2hN84B8hnb1JPYdOSNGVn39QYSxDPmK/SyG1a0JjEM=; b=IKRfKrPcu4l7yxP7fO2zzwAKTucnmrQ9Ukpz9xFnbLQ5cQtCQR+oInD3fLFiwAuvGo n1MtyrCxklWxxydRjPX0z36slBg+qy/3cPAzjsYwdR38XInc1jzY8rxp4q70WoZaGcyE lPSI8VWyKzrYtacvCmBvhjMA38g1SER1IjU/qVuzCs3zgzmNAlUbzjHh/1gYBoXNzlv1 qLeEYo3Z6pzIBeuZqa+rUZZxlhRJIJYSm5QkQhofQ9YDH/0nvVZm+15dEIUjaX7K3FXl GHKVZA0YII8bgNvPSTJA+6JOJHHV6SbUr3OCbkDnNNAPt51GuROZC5KNwxnQbmvYeopa 0t6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=af5nbEbF; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r14-20020a1709062cce00b0073c1b04f592si982235ejr.245.2022.09.02.00.03.33; Fri, 02 Sep 2022 00:03:59 -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=@redhat.com header.s=mimecast20190719 header.b=af5nbEbF; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235373AbiIBGwD (ORCPT + 99 others); Fri, 2 Sep 2022 02:52:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235539AbiIBGwA (ORCPT ); Fri, 2 Sep 2022 02:52:00 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF216A570A for ; Thu, 1 Sep 2022 23:51:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662101518; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K2hN84B8hnb1JPYdOSNGVn39QYSxDPmK/SyG1a0JjEM=; b=af5nbEbFd58JmDviKm7JCDNAVh5X0Dro1lEemBE6JYT+OUBzRBa6grxi2KiOnItIoq6vtJ Csec8YMGiIFwmUgDPAEWJniaZ8e27RhxlnYlo+QGupcU1VmFSk4XWHiX3wfj6RIEaSGVWl KjOasXWMg48V0yrO/mFkP8DPIIKwWfQ= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-590-T5KXihPyOdaMZFvZmLCiag-1; Fri, 02 Sep 2022 02:51:56 -0400 X-MC-Unique: T5KXihPyOdaMZFvZmLCiag-1 Received: by mail-wm1-f72.google.com with SMTP id q16-20020a1cf310000000b003a626026ed1so284337wmq.4 for ; Thu, 01 Sep 2022 23:51:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date; bh=K2hN84B8hnb1JPYdOSNGVn39QYSxDPmK/SyG1a0JjEM=; b=c3L2+GTyZQzrC6QJiLyk+nbOcF0CEhnjftLpQSc+gEyz2QBC75H6mJzKM99uaIkHZ+ SWCZsMmrgQERrJPBi3ozSwo+XDKZJjH0Yh7BMNnFdInlZLQZ3vzrx0kvst/NI4Mefd1H ndgy6L9BMtiH3UALFPPIZHRSX/lV3swq/j4alvvTx/X6MnGiGuD7E+rst5/cze6Qrwb0 f7ZYmvv+euaZ5Roeza1ys5M67hkBnn0LVYacBAq49/ieN9o7tJpqJHhRDaKlm3oAAnNO 7WI05aqaeALWPBkJs+9BU15K0evfkx7cot8KNxkOjbuFC5VwW5I3i+xJMBjyOHUfaelb owzg== X-Gm-Message-State: ACgBeo3DQi1u2pvSAlGxlXfDHvE/BEtNQmBvhG9oxyh+xnVQdEkMchkU N/f/tZsJayZ8Ew8BgjkuGQ8Dtr6V1qV47Yq4bVOBjpOVz/Tg0csWXHI3GOvTDFI15gJEBo8rosg tFULsAmsFP8kGtmsmlW73q9N9 X-Received: by 2002:a05:600c:348d:b0:3a6:b4e:ff6d with SMTP id a13-20020a05600c348d00b003a60b4eff6dmr1565278wmq.95.1662101515469; Thu, 01 Sep 2022 23:51:55 -0700 (PDT) X-Received: by 2002:a05:600c:348d:b0:3a6:b4e:ff6d with SMTP id a13-20020a05600c348d00b003a60b4eff6dmr1565249wmq.95.1662101515193; Thu, 01 Sep 2022 23:51:55 -0700 (PDT) Received: from ?IPV6:2003:cb:c714:4800:2077:1bf6:40e7:2833? (p200300cbc714480020771bf640e72833.dip0.t-ipconnect.de. [2003:cb:c714:4800:2077:1bf6:40e7:2833]) by smtp.gmail.com with ESMTPSA id o5-20020a05600c510500b003a31fd05e0fsm16660267wms.2.2022.09.01.23.51.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 01 Sep 2022 23:51:54 -0700 (PDT) Message-ID: <65b9abb4-45f7-f8e0-5148-6059b2c2ae6a@redhat.com> Date: Fri, 2 Sep 2022 08:51:53 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH v4 1/4] mm/migrate_device.c: Flush TLB while holding PTL Content-Language: en-US To: Alistair Popple , linux-mm@kvack.org, akpm@linux-foundation.org Cc: Peter Xu , Nadav Amit , huang ying , LKML , "Sierra Guiza, Alejandro (Alex)" , Felix Kuehling , Jason Gunthorpe , John Hubbard , Ralph Campbell , Matthew Wilcox , Karol Herbst , Lyude Paul , Ben Skeggs , Logan Gunthorpe , paulus@ozlabs.org, linuxppc-dev@lists.ozlabs.org, "Huang, Ying" , stable@vger.kernel.org References: <9f801e9d8d830408f2ca27821f606e09aa856899.1662078528.git-series.apopple@nvidia.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <9f801e9d8d830408f2ca27821f606e09aa856899.1662078528.git-series.apopple@nvidia.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 On 02.09.22 02:35, Alistair Popple wrote: > 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. > > Signed-off-by: Alistair Popple > Reported-by: Nadav Amit > Reviewed-by: "Huang, Ying" > Fixes: 8c3328f1f36a ("mm/migrate: migrate_vma() unmap page from vma while collecting pages") > Cc: stable@vger.kernel.org > > --- > > Changes for v4: > > - Added Review-by > > Changes for v3: > > - New for v3 > --- > mm/migrate_device.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/mm/migrate_device.c b/mm/migrate_device.c > index 27fb37d..6a5ef9f 100644 > --- a/mm/migrate_device.c > +++ b/mm/migrate_device.c > @@ -254,13 +254,14 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, > 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; > } > > > base-commit: ffcf9c5700e49c0aee42dcba9a12ba21338e8136 Acked-by: David Hildenbrand -- Thanks, David / dhildenb