Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp113650ybh; Tue, 14 Jul 2020 19:49:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHtqzsflKAkL2vWtgG7OIHJdC1Xlxx4M7WalhRTmUXyrljCZVqHkq6mqnsCd/sqy+6qXea X-Received: by 2002:a17:906:6b0c:: with SMTP id q12mr7651986ejr.525.1594781385734; Tue, 14 Jul 2020 19:49:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594781385; cv=none; d=google.com; s=arc-20160816; b=K/cqgzmJsE8RIolJWg3orIsw/5rSrHz1ceElCzAyLYdztBVs+wVCLfMda9yy1BOXWE N93vsldmxvfZHPKGB9FOADVi0ZHniT393Pu+r2JgNOhVz3Bw+phJMwXYjHeSa+bLO/6D RZLm0BJvlohFpqN2U3LJ93779oGXKIqEQIrzbDSrnVrkvdV/U63cAlK24zGiDlvEa7yx 8kVqp+rS18X0LeLdGt4XUTQPsqU0W+k1PgLt52s6QSTgUMpgYRJ0leiEQGPG4/Erq9a/ PXSQuFfXYmErrwxu0BfoHVosm9KrEaWeOG8QQyyR53d91vImbPP6rmKUkNvYJsFt6vwz nbgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:date:message-id :from:references:cc:to:dkim-signature:subject; bh=WJNUHBhdYWsOcHRE34jG+/1ZLtd4e1HQa9s2B7K+hYc=; b=SD8ODd6TKWLVl5Rbau6rrRXjBL26hTsalTIxhw1Ilng+Cc5jFGOQITVnrto2YJERtU nyvyjAPemtTuA22AOFcuWFAjFaLoQfXoigkP1QJoskkv/fJ0iapAZr48PwtBlTyZ4rWB uB7dTYpsFQh/kxlaY/5wLxJWBQrMRMKk0actRL+zdFn0ROKhz6CahTIX/phFxniBNTFZ 06tJAUoHvTxiRFFmaLJkMGiPFaBWIOo3NZZHV960MuJYfCKnlz0xkRdkp8WYBW1Iguas L27CT3gHfZlhrxnk2ehf8zDpdlg+JOChdEuS2I5OPJFW4cG/icTZnO/sK/dVMTho+Nfp TKew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synology.com header.s=123 header.b=Nfgl23aW; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=synology.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dg2si394653edb.326.2020.07.14.19.49.22; Tue, 14 Jul 2020 19:49:45 -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; dkim=pass header.i=@synology.com header.s=123 header.b=Nfgl23aW; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=synology.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728347AbgGOCpl (ORCPT + 99 others); Tue, 14 Jul 2020 22:45:41 -0400 Received: from mail.synology.com ([211.23.38.101]:40820 "EHLO synology.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727071AbgGOCpl (ORCPT ); Tue, 14 Jul 2020 22:45:41 -0400 Subject: Re: [PATCH] mm : fix pte _PAGE_DIRTY bit when fallback migrate page DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1594781139; bh=5fo2vbPQ7m0yDE7a+ouN9kyFBdQ4CHGkaiwDsK86hQk=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=Nfgl23aWE5cPGhbzZyBHoHpDRntBMrczkLPs8jSdjooB7SYTCWFOjF8xRl90nIgsP BTF44JCfl8U7+nDG/G3rY0jQawU3ZVk/MNbC363MoOJt3uW+Rmy/hCSDvvLbPDq7bu 9UnavLI1Faun19PsxcBq241LLszwx83kkXJaQuus= To: "Kirill A. Shutemov" , Vlastimil Babka Cc: linux-mm@kvack.org, 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> <433e26b0-5201-129a-4afe-4881e42781fa@suse.cz> <20200714101951.6osakxdgbhrnfrbd@box> From: Robbie Ko Message-ID: Date: Wed, 15 Jul 2020 10:45:39 +0800 MIME-Version: 1.0 In-Reply-To: <20200714101951.6osakxdgbhrnfrbd@box> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Synology-MCP-Status: no X-Synology-Spam-Flag: no X-Synology-Spam-Status: score=0, required 6, WHITELIST_FROM_ADDRESS 0 X-Synology-Virus-Status: no Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Kirill A. Shutemov 於 2020/7/14 下午6:19 寫道: > On Tue, Jul 14, 2020 at 11:46:12AM +0200, Vlastimil Babka wrote: >> 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. > I don't follow the scenario. > > When we establish migration entries with try_to_unmap(), it transfers > dirty bit from PTE to the page. Sorry, I mean is _PAGE_RW with pte_write When we establish migration entries with try_to_unmap(), we create a migration entry, and if pte_write we set it to SWP_MIGRATION_WRITE, which will replace the migration entry with the original pte. When migratepage, we go to fallback_migrate_page to execute a writeout if the migratepage is not supported. In the writeout, we call clear_page_dirty_for_io to clear the dirty bit of the page and use page_mkclean to clear pte _PAGE_RW with pte_wrprotect in page_mkclean_one. However, page_mkclean_one does not support migration entries, so the migration entry is still SWP_MIGRATION_WRITE. In writeout, then we call remove_migration_ptes to remove the migration entry, because it is still SWP_MIGRATION_WRITE so set _PAGE_RW to pte via pte_mkwrite. Therefore, subsequent mmap wirte will not trigger page_mkwrite to cause data loss.