Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1607772rwe; Fri, 2 Sep 2022 00:05:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR6lWXxXmFLCFNBKqILfHOaOA1wDlPXmZbAxkfHYizyKFmOWbyLmaAoDjia955dA3JWcOA+M X-Received: by 2002:a05:6402:551a:b0:446:1526:85ea with SMTP id fi26-20020a056402551a00b00446152685eamr31991585edb.188.1662102313497; Fri, 02 Sep 2022 00:05:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662102313; cv=none; d=google.com; s=arc-20160816; b=pI1ErPlIRHH6ROZe4T5wVHzzT8nDU1xw3RgT1RRWJfaLb4N6XxjSrzpAwGmhTJC+Eq nrYIE6Yygm7pHmpQd4Msp7DQ1Eja4Nso1wIzzV/sCLH0h7JEkFXCSocuZAQPSKdoLFl1 TfTXZMLJBfHJd96co+UVIcEQax1lPh/XeT2eoFQBo1eb+5CONdVuEm260DqwQPB9t3Pm NuK0s8RrILmCB+GqXjgTi1GStaT1ErccBKz/EKxmqqmtlVt/Gk6etT32j/CrwK4wvkBW 1fTFwNNoqBngtJeb5s8JhwIfCk7UflAWJ56exLxm+swEDcbn+/CIXIBiiSlgpj2uCvya nnDQ== 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=h+57PdWMxpBWbQjargyaqlxNH+Zcmno8dXbh3sZc6/c=; b=fG5sz8By1VI6cfb0oPo75zQhvYP4s7sK+hY9sZvv9k4FWziXcwZ9xf7jrxN9BKG5DE wvo7zDu37biJi2hYcx/3UQX/I92bwg8ZHhT9n2LAP/5y4pZsMfaiC7LD1Ci346XEPEzm w/cobv+f2JeLhefypkhsLEy9406FuNeLA5p4o0vG2RtQcZRh15RK7XPdX+0psdvk5hKf 8LCy4X6zbz3oUKOyGx2VUDqEFnT1UK3WPGU1ZbiRwDsNroufwaI6AwL/yEa8QmJppsIF 3r2cu8LkaHfTqYyP5QHzEMHNJF8gz3UWSub/xj5JHBkPDDDHTU2DwHZUSdSQ5gKbhtvi /iFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NSAJyKI1; 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 z17-20020a05640240d100b00447e9c56162si1334563edb.11.2022.09.02.00.04.42; Fri, 02 Sep 2022 00:05:13 -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=NSAJyKI1; 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 S235607AbiIBGx1 (ORCPT + 99 others); Fri, 2 Sep 2022 02:53:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235595AbiIBGxU (ORCPT ); Fri, 2 Sep 2022 02:53:20 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94528BC807 for ; Thu, 1 Sep 2022 23:53:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662101594; 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=h+57PdWMxpBWbQjargyaqlxNH+Zcmno8dXbh3sZc6/c=; b=NSAJyKI1OzMusRWmc9xm0T7junBLWZK0BQb5u1L5PilV5/iWSLXHSRIk4rGxbMCA89aFiY 1uObkmayh9HTYMYu457YqMOOaKnMltSEKQY+kDK5godGc8GaMw2nGMW6BGT8Q5KptkM87v QKsGWQl1S478qkp2kGPQPvTVMVor7Jg= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-625-kANBYT9oPZSWd9tQ4fvvTg-1; Fri, 02 Sep 2022 02:53:13 -0400 X-MC-Unique: kANBYT9oPZSWd9tQ4fvvTg-1 Received: by mail-wm1-f69.google.com with SMTP id v67-20020a1cac46000000b003a615c4893dso738715wme.3 for ; Thu, 01 Sep 2022 23:53:12 -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=h+57PdWMxpBWbQjargyaqlxNH+Zcmno8dXbh3sZc6/c=; b=RWAMhf751TEE91V9IIOG3WlgvvF+j5VBtqgIie890ixvUSch3QvS9DaNdhdBDfZUuN LFDra9EwZdn3tKNqm4rpgUkh4/C1CDe9Lm4+CKWEeLDmS12kXKsSu9gVV4oBzgiYp4iN gnGOLsxUsmgMb6FRECuBwoA5ZNvazbZnAOuf3XOaH4G/O12Yufo8GSr+080Ex2YGby8a K/NsM4wXjTtlXteGP8A4J3P2q2MTfjkeFWvfNklfJbrnujIYMSIb2ppKxaDUWSVRoMf0 tkk4NU+zuvEjhl8O5W3Bi/fzcf6MXk7MHvUSybhHTRjaPenvDpNrqEtnf4wVypbYdOQA yazg== X-Gm-Message-State: ACgBeo2FmldcNqjD9V4LJxyom/iY2UPNW8ljGpu2pDOFI1ehp4aOPz+A XFju8NZSiXTrma7tAfO5GGX4tPMi5FTI/wSZXSfktEFnMkwPnCGwy/ur/yZLCG7Ym0kN5WxzgAt 5zLWHO4odk6/YP2GgZEDuiONx X-Received: by 2002:adf:fb0e:0:b0:21a:34a2:5ca9 with SMTP id c14-20020adffb0e000000b0021a34a25ca9mr16886157wrr.472.1662101592037; Thu, 01 Sep 2022 23:53:12 -0700 (PDT) X-Received: by 2002:adf:fb0e:0:b0:21a:34a2:5ca9 with SMTP id c14-20020adffb0e000000b0021a34a25ca9mr16886135wrr.472.1662101591768; Thu, 01 Sep 2022 23:53:11 -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 z15-20020a5d654f000000b002211fc70174sm842621wrv.99.2022.09.01.23.53.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 01 Sep 2022 23:53:11 -0700 (PDT) Message-ID: <2fccd4c1-d12f-334c-3fab-24a84bcac007@redhat.com> Date: Fri, 2 Sep 2022 08:53:09 +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 3/4] mm/migrate_device.c: Copy pte dirty bit to page 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: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.8 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_LOW,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: > migrate_vma_setup() has a fast path in migrate_vma_collect_pmd() that > installs migration entries directly if it can lock the migrating page. > When removing a dirty pte the dirty bit is supposed to be carried over > to the underlying page to prevent it being lost. > > Currently migrate_vma_*() can only be used for private anonymous > mappings. That means loss of the dirty bit usually doesn't result in > data loss because these pages are typically not file-backed. However > pages may be backed by swap storage which can result in data loss if an > attempt is made to migrate a dirty page that doesn't yet have the > PageDirty flag set. > > In this case migration will fail due to unexpected references but the > dirty pte bit will be lost. If the page is subsequently reclaimed data > won't be written back to swap storage as it is considered uptodate, > resulting in data loss if the page is subsequently accessed. > > Prevent this by copying the dirty bit to the page when removing the pte > to match what try_to_migrate_one() does. > > Signed-off-by: Alistair Popple > Acked-by: Peter Xu > Reviewed-by: "Huang, Ying" > Reported-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 Reviewed-by > > Changes for v3: > > - Defer TLB flushing > - Split a TLB flushing fix into a separate change. > > Changes for v2: > > - Fixed up Reported-by tag. > - Added Peter's Acked-by. > - Atomically read and clear the pte to prevent the dirty bit getting > set after reading it. > - Added fixes tag > --- > mm/migrate_device.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/mm/migrate_device.c b/mm/migrate_device.c > index 4cc849c..dbf6c7a 100644 > --- a/mm/migrate_device.c > +++ b/mm/migrate_device.c > @@ -7,6 +7,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -196,7 +197,7 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, > flush_cache_page(vma, addr, pte_pfn(*ptep)); > anon_exclusive = PageAnon(page) && PageAnonExclusive(page); > if (anon_exclusive) { > - ptep_clear_flush(vma, addr, ptep); > + pte = ptep_clear_flush(vma, addr, ptep); > > if (page_try_share_anon_rmap(page)) { > set_pte_at(mm, addr, ptep, pte); > @@ -206,11 +207,15 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, > goto next; > } > } else { > - ptep_get_and_clear(mm, addr, ptep); > + pte = ptep_get_and_clear(mm, addr, ptep); > } > > migrate->cpages++; > > + /* Set the dirty flag on the folio now the pte is gone. */ > + if (pte_dirty(pte)) > + folio_mark_dirty(page_folio(page)); > + > /* Setup special migration page table entry */ > if (mpfn & MIGRATE_PFN_WRITE) > entry = make_writable_migration_entry( This matches what we do in try_to_unmap_one() Acked-by: David Hildenbrand -- Thanks, David / dhildenb