From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70FF2ECAAA1 for ; Fri, 2 Sep 2022 06:52:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 10BB1800C6; Fri, 2 Sep 2022 02:52:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 092CF8008D; Fri, 2 Sep 2022 02:52:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E763B800C6; Fri, 2 Sep 2022 02:52:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D77EE8008D for ; Fri, 2 Sep 2022 02:52:07 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B0BD21C6236 for ; Fri, 2 Sep 2022 06:52:07 +0000 (UTC) X-FDA: 79866225894.10.07620DB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 5673140047 for ; Fri, 2 Sep 2022 06:52:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662101526; 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=SB5oXvFnOA+/HxHuxJNyRCTc+DXyJaNpv+b7tPwXJarR94osENb7jeSKncukqAkXUxEU8n TJDp51jzw2F92KVYFPGehHNZ02dhUULsqrp1SNvPQKkpwoVp8UeKuk4BMsOFYqatP4exoy x4MNqguzGAavwa4R+r9hNAExUYT7bWw= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-610-Ra2gBRXFNIKtWDdh5AUxzw-1; Fri, 02 Sep 2022 02:51:56 -0400 X-MC-Unique: Ra2gBRXFNIKtWDdh5AUxzw-1 Received: by mail-wm1-f71.google.com with SMTP id c64-20020a1c3543000000b003a61987ffb3so726405wma.6 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=pCnFiwpLvuNJRVvl3UqH5cGpwj78xJ8Uizyoq7HhU/NMjoAZ3pFqxzMxYMqILaXe2K ly5Zp2Cke11O7yGlSrlg5fLdnzjVXmlPyhsvqr6gTIarpCKVR/FJkLanM+4hKP1e2wIt YttdHXdSAc9dB5AH3y22a6/5uZAo3aYUW/Kxd7zUbDHjAa9zdrnmodjk+bRxD3SEIVj2 W6h+UNiHS3wvnGjKQg9owSrw5cNiscSGfYXAdGROmpPibTMATJbmv+QF6BbIKvWCXTrS cRH81khUabsHJ224uJHWYrN4C6seBXJ5LC6FUvwmWa8UhFoQEYXm0m4HkSKWSuxPUJve 33mQ== X-Gm-Message-State: ACgBeo35VsHBfXk5SEpzJUH2kojuCVtL3h0XEJhmq1LX3eKlKmDC5JyX q5JVSNLTcn7Kiqwb93Sm9UztD+4l2VVIQYrFwCrb5QK3zVYXoFkQWnl0/3Sqkt53+ONaJtdfI+Q Ou32X2lbmpTQ= X-Received: by 2002:a05:600c:348d:b0:3a6:b4e:ff6d with SMTP id a13-20020a05600c348d00b003a60b4eff6dmr1565276wmq.95.1662101515468; Thu, 01 Sep 2022 23:51:55 -0700 (PDT) X-Google-Smtp-Source: AA6agR46CGLtC2fDdfzM/QpJfx4qdEeswbHmK0RWHhlnHIk5iORrxdcergyRIzSqDQ7HjT8Z5PbhQw== 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 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> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662101527; a=rsa-sha256; cv=none; b=VqKRqWmFhqtkSl3ckBMCFCaHoAuBvI1XeLhah8/Ibcs5yCaorov9Qr7FFshgGWObx2vPoy dfJjONk7HRbEld0OUXDNTIJwhRmWz4KbW/UQGRo1ksqxtEryyoXwDxz3O2e5mZIyuZC7kZ zCBBqFq0NvqPiJEWFSt4Ph27C9sAI3Y= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SB5oXvFn; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662101527; h=from:from:sender: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:dkim-signature; bh=K2hN84B8hnb1JPYdOSNGVn39QYSxDPmK/SyG1a0JjEM=; b=bejo0uH8B1aPxqG01hanJCtJZ4yNVpCO2+Mikqt6CwAegcp8Ox3IfoDgwO3qtQpCUryY0U FGb3CGKuJ+QO6tZt8BSlK5YGxmMRJ2lPjknZPif3pcXKdKgmHCx4oBSKdYysg4VpEyRob1 ZmaYAXzw8vQyU8YIgpdE8FoiESRpJSM= X-Stat-Signature: cxb6mketk9jiy8re99iygoqd6xbikqcw X-Rspamd-Queue-Id: 5673140047 X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SB5oXvFn; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com X-Rspamd-Server: rspam08 X-HE-Tag: 1662101527-630566 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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