Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1621115ybh; Tue, 14 Jul 2020 02:49:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7HAIHzCh5eGmGk61LGqjIFpV8+uYsxlfzHLA1WYTcA89H3In2wVfTHwJLuBEswxb8Xz3P X-Received: by 2002:a17:906:6499:: with SMTP id e25mr3705957ejm.352.1594720170387; Tue, 14 Jul 2020 02:49:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594720170; cv=none; d=google.com; s=arc-20160816; b=gaYsO6bYC/4gFLaftk3inTi/CDp3WWt62DnY+4he2wVO094lQzuTL5bDBjDO+TUeI2 uvua1KEn5k4nDI7TmE9JiCmzsHR9y8xng3vC8RsdYnsebb7pY/0SmVGr1/fRiTDrn+2k kMA/KnlmO7KZ+KW2fEZ0pYZWSng3/CiX6QGZkcEbAWlq2u1K3GQ2TZCN4QuHqsotY/uM pPq3jxjGZQyWZYLDHnUN9z5g4UJzJYaJCo6ZV5wnxARQ6CTz/L7htE7roGpAmSxf0HNT UtHrvl/yV0QUNZ8mRG3Ho/9UoWUGS7XxZXaLHqquU0w4Zr7PzhWyIit2tzuznBax3Gmv T52A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=PseKYyhFKYoQwEfPj7YCsB+bdT6/b87msxUmR7rEWKA=; b=STR90Ybg4f7IOpHXuHxalSh2+DJD/drrdJ2Db6c1QbdXCxy8EPiqAI+Pt2dN1DyLre unSoL55dea+vS9HLcP76QCw6UrbDpfdOBHslaEeD3gPNFiYudDyFTKgcPi+fC0a/STtN 1BjQw76Y8ayaUpFfeYGVFvT/rGXmpUbnLnSulqmE1sFH5Vlb7Fjo36/pz7icpV+gpz8B NmooOxaUN5jL4HCym9JiFL8kqL5OXTRfVlExctxTlbU8qmEKLSWO3rURgiysnDFUk98v OF6MaW1DEweHjx51Lz6TSWzjs28Bg/lo87efeDy4k1vo0V7OT0y1yNWqWD0c5/RhSia+ xbBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h21si10509532edw.233.2020.07.14.02.49.06; Tue, 14 Jul 2020 02:49:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726761AbgGNJqO (ORCPT + 99 others); Tue, 14 Jul 2020 05:46:14 -0400 Received: from mx2.suse.de ([195.135.220.15]:43068 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725952AbgGNJqO (ORCPT ); Tue, 14 Jul 2020 05:46:14 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 2AB4BABCE; Tue, 14 Jul 2020 09:46:15 +0000 (UTC) Subject: Re: [PATCH] mm : fix pte _PAGE_DIRTY bit when fallback migrate page To: Robbie Ko , linux-mm@kvack.org Cc: LKML , linux-btrfs@vger.kernel.org, Roman Gushchin , David Sterba , "Kirill A. Shutemov" References: <20200709024808.18466-1-robbieko@synology.com> <859c810e-376e-5e8b-e8a5-0da3f83315d1@suse.cz> <80b55fcf-def1-8a83-8f53-a22f2be56244@synology.com> From: Vlastimil Babka Message-ID: <433e26b0-5201-129a-4afe-4881e42781fa@suse.cz> Date: Tue, 14 Jul 2020 11:46:12 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <80b55fcf-def1-8a83-8f53-a22f2be56244@synology.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/13/20 3:57 AM, Robbie Ko wrote: > > Vlastimil Babka 於 2020/7/10 下午11:31 寫道: >> On 7/9/20 4:48 AM, robbieko wrote: >>> From: Robbie Ko >>> >>> When a migrate page occurs, we first create a migration entry >>> to replace the original pte, and then go to fallback_migrate_page >>> to execute a writeout if the migratepage is not supported. >>> >>> In the writeout, we will clear the dirty bit of the page and use >>> page_mkclean to clear the dirty bit along with the corresponding pte, >>> but page_mkclean does not support migration entry. >>> >>> The page ditry bit is cleared, but the dirty bit of the pte still exists, >>> so if mmap continues to write, it will result in data loss. >> Curious, did you observe this data loss? What filesystem? If yes, it seems >> serious enough to >> CC stable and determine a Fixes: tag? > > Yes, there is data loss. > I'm using a btrfs environment, but not the following patch And the kernel is otherwise upstream? Which version? Anyway we better let btrfs guys know (+CC) even if the fix is in MM code. > btrfs: implement migratepage callback for data pages > https://git.kernel.org/pub/scm/linux/kernel > /git/torvalds/linux.git/commit/?h=v5.8-rc5& > id=f8e6608180a31cc72a23b74969da428da236dbd1 That's a new commit, so if this is really affecting upstream btrfs pre-5.8 we should either backport that commit, or your fix (after review). >>> We fix the by first remove the migration entry and then clearing >>> the dirty bits of the page, which also clears the pte's dirty bits. >>> >>> Signed-off-by: Robbie Ko >>> --- >>> mm/migrate.c | 8 ++++---- >>> 1 file changed, 4 insertions(+), 4 deletions(-) >>> >>> diff --git a/mm/migrate.c b/mm/migrate.c >>> index f37729673558..5c407434b9ba 100644 >>> --- a/mm/migrate.c >>> +++ b/mm/migrate.c >>> @@ -875,10 +875,6 @@ static int writeout(struct address_space *mapping, struct page *page) >>> /* No write method for the address space */ >>> return -EINVAL; >>> >>> - if (!clear_page_dirty_for_io(page)) >>> - /* Someone else already triggered a write */ >>> - return -EAGAIN; >>> - >>> /* >>> * A dirty page may imply that the underlying filesystem has >>> * the page on some queue. So the page must be clean for >>> @@ -889,6 +885,10 @@ static int writeout(struct address_space *mapping, struct page *page) >>> */ >>> remove_migration_ptes(page, page, false); >>> >>> + if (!clear_page_dirty_for_io(page)) >>> + /* Someone else already triggered a write */ >>> + return -EAGAIN; >>> + >>> rc = mapping->a_ops->writepage(page, &wbc); >>> >>> if (rc != AOP_WRITEPAGE_ACTIVATE) >>> >> >