Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3337147rwb; Tue, 16 Aug 2022 00:35:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR7rLL5uJowTyyO76yJVJshHegjkHAwK77mHu5zQRJ9muqd3iBGR+cpF5mn/OIV0T4EbWW81 X-Received: by 2002:a17:907:7243:b0:733:2c:14cf with SMTP id ds3-20020a170907724300b00733002c14cfmr12446726ejc.485.1660635353025; Tue, 16 Aug 2022 00:35:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660635353; cv=none; d=google.com; s=arc-20160816; b=Q3UWb3JFumW5XsV3+JUE6fU8xFd0qhdG5fSwG2e63H/IEd3fDATWT3zq5hsosOfS+d e6IyfSZ2VqWYNX9cIjpYNgkkndxUuWOw7Fb1qYlXWLHLC+UAJuaTOClgIyomOIQfzJ8Y a+RzKiA9iE1lZna0SFvazQgEu02rxyjEe8BY+WK53cOQfLQJSmTUS/vzuOtZsvbX6DSj BZSuq5iQPtuRdcW+sy3cGRUrOVIeqcna97oWoFYntk4290WhJn5PcZuceM4xXOS8uUc8 kQIJ+yXwd/U1/4ogBgM59hxh0iWz5W84iEouM1GRoMBkfITIIBxXbfLOCDoCZBbQjNkN gvcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=cMuUlWGLbTpeu0ASefFqDvJ/DGPqzdWcKWwAAva0H64=; b=L40h6qBzruprlCY0FKY3qV1/g4IZvevQEpyHvRBlBDjy5/HSz6DEqHkrb1uSgpdauw 6GIjCRHdNKkkpK2fyATdY12G+G+DJIEta6TJs0HjO8YtM+x5b0w1+zYXghUUXTODWh7E 52sijI9qIhAWrNo1aqXNw3ag2mEA248wVcPhuVIK7QfoGu9QpYsg4awiSuZpXhippBnr 3TOzJK0wCGYeNQ1wuM1z6RevRk38Tzs9HJciryQD3YKpNJRqiTyCTigrgwR3XCfS7/n4 8poWVt/9bxksSCApQlujb31OSU3WhXTvvuriLwn7IKySn0K1poBBJ1lLIsAcAoNqRM7d 4K1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=WES+YnOZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nc30-20020a1709071c1e00b00730aa3e3843si11215359ejc.131.2022.08.16.00.35.27; Tue, 16 Aug 2022 00:35: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=@gmail.com header.s=20210112 header.b=WES+YnOZ; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229820AbiHPGoS (ORCPT + 99 others); Tue, 16 Aug 2022 02:44:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229619AbiHPGn7 (ORCPT ); Tue, 16 Aug 2022 02:43:59 -0400 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5CF9F5CD4 for ; Mon, 15 Aug 2022 18:39:42 -0700 (PDT) Received: by mail-pg1-x535.google.com with SMTP id 73so8007257pgb.9 for ; Mon, 15 Aug 2022 18:39:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=cMuUlWGLbTpeu0ASefFqDvJ/DGPqzdWcKWwAAva0H64=; b=WES+YnOZL2UjR4oBSqpkDqfy5lRMZ4Az94YlDnft7E80VXwd3QCegkIe80Y2DNmcRu exMTJsFtVAt7oqKqCDVqVwlCuuKBVkIi/cznTfu59wBPo3bUh+mt2ula0EENnUqsWqCP iOIr04Hn9JP5mUCDF8IoTZojIj/oDjxMK6VBkX9wIpu1QCZm+3dMUBq2i5bhU/b+GWpc fKkAQRnQTgBtX10tQEFcopknGrRl6Y3X9aCYwO+Qcl5QvrorZL0Y7lJYg1PKa6LW/1z9 pUhY+SX0gBQfjKk1jPI872E/x+guVVCnqOr3UsXNtruec/1Ypi6z/bPM+Vl0jbpQIcvx ONDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=cMuUlWGLbTpeu0ASefFqDvJ/DGPqzdWcKWwAAva0H64=; b=hVyKDMGaWmO3ltB9EeM/ii8X5aBcnPwq7mYI1SqhdHxpcVjcfDarJ+xTXbBym9FaZQ XxdhjJlAIz5nYhr5K6cNxWpnJ1krmFrCDYm9bh6m/R4j2pVKWr3ErCsHEwNaRDQEpuT7 JnrnFXG+dp36rlV3zoPO+q6KCKMyne+Sv1oJ/M1qXMMrXkzWUCfz5JIm6E6L5MJIhcXJ +Fg2eKds1cSue4/ukQqFloJEpE44TVmLx80ofrjVRxW9nTVqKMGZ5OzLGbigquqIOVA4 s/+uQgKXixDNK/XJ1/OdPsv5XEIrV0izVYzRV/vj9TDl/CZr9gZ2+dfrbOoypbaqxoDz SuBQ== X-Gm-Message-State: ACgBeo0eFM6kuOsFBoQbbvF+F+SYgfHT40BW8XcA+LmwHHiDEa2e51p+ FEpwZ3aSyr3BWF2Nqv856eGkQbbjakE+gdkEENG7iZUTUPs= X-Received: by 2002:a65:5b03:0:b0:41d:131c:4f39 with SMTP id y3-20020a655b03000000b0041d131c4f39mr15846558pgq.401.1660613982246; Mon, 15 Aug 2022 18:39:42 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: huang ying Date: Tue, 16 Aug 2022 09:39:24 +0800 Message-ID: Subject: Re: [PATCH 1/2] mm/migrate_device.c: Copy pte dirty bit to page To: Alistair Popple Cc: linux-mm@kvack.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, "Sierra Guiza, Alejandro (Alex)" , Felix Kuehling , Jason Gunthorpe , John Hubbard , David Hildenbrand , Ralph Campbell , Matthew Wilcox , Karol Herbst , Lyude Paul , Ben Skeggs , Logan Gunthorpe , linuxram@us.ibm.com, paulus@ozlabs.org, Peter Xu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 Hi, Alistair, On Fri, Aug 12, 2022 at 1:23 PM 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 > Reported-by: Peter Xu > --- > mm/migrate_device.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/mm/migrate_device.c b/mm/migrate_device.c > index 27fb37d..d38f8a6 100644 > --- a/mm/migrate_device.c > +++ b/mm/migrate_device.c > @@ -7,6 +7,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -211,6 +212,10 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, > > migrate->cpages++; > > + /* Set the dirty flag on the folio now the pte is gone. */ > + if (pte_dirty(pte)) > + folio_mark_dirty(page_folio(page)); > + I think that this isn't sufficient to fix all issues. Firstly, "pte" is assigned at the begin of the loop, before the PTE is cleared via ptep_clear_flush() or ptep_get_and_clear(). That is, the pte isn't changed atomically. Between "pte" assignment and PTE clear, the PTE may become dirty. That is, we need to update pte when we clear the PTE. And I don't know why we use ptep_get_and_clear() to clear PTE if (!anon_exclusive). Why don't we need to flush the TLB? Best Regards, Huang, Ying > /* Setup special migration page table entry */ > if (mpfn & MIGRATE_PFN_WRITE) > entry = make_writable_migration_entry( > > base-commit: ffcf9c5700e49c0aee42dcba9a12ba21338e8136 > -- > git-series 0.9.1 >