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 BB0A4C433F5 for ; Fri, 11 Mar 2022 09:05:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 277098D0002; Fri, 11 Mar 2022 04:05:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 226D38D0001; Fri, 11 Mar 2022 04:05:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 116808D0002; Fri, 11 Mar 2022 04:05:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 022278D0001 for ; Fri, 11 Mar 2022 04:05:54 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BD30D2FF for ; Fri, 11 Mar 2022 09:05:54 +0000 (UTC) X-FDA: 79231523028.11.6A27659 Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) by imf20.hostedemail.com (Postfix) with ESMTP id 987001C0018 for ; Fri, 11 Mar 2022 09:05:53 +0000 (UTC) Received: by mail-yb1-f175.google.com with SMTP id g26so15907341ybj.10 for ; Fri, 11 Mar 2022 01:05:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=m4uZHfd5TEknERkFPf+I/joPh8Butuy4Qgst4A1Cqjw=; b=pF6htef8BElDLh5mKnFuCbURvy+T/DgtLXd1OrtoV5iZB/kuFmt74asVUCwjaEiP1W VvVb0/uyuvzAHsaOwfvAPUbNjLLi/4O+SisK77Z/w6dLGflRJWAcnwFg8SMYxuEzUtm9 Kn0yMKbWtwRnmtRjIb/fgaiA5s9Zib6MbM6LijkloeJGFeDoxalPAyalbbC5Vvm4edYz fKO5lHEqYrZVhfKCrzgSemS8X69xLKp4tDnuTSv1x4AULBBK4IQkDR+YI9t12YnNKIli OXfoMRM7zpWFlX+2+hnO36gI1Xv1n89u0KcNlYLC4ioZEqwTkHNfcCLxhOk5rKKtlYoP icDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=m4uZHfd5TEknERkFPf+I/joPh8Butuy4Qgst4A1Cqjw=; b=3hyelfUhu0bqQ8dFoJk8UvAF2wnba8JAiS45KQ4ObV/CccoPblNst4ly/0bwrSLEyx HgwBsj3iEugPYJ0H6idyhALhbL685mL/39P+8qJSxONzvCWgsUwz9bHe7DmTbGZ537BF bCgG6dXVaWVy79HGfWDvFwr6+iPPiR2SfSFqZKLxNlyyvufRAFaOePNqOE03i4Mnz/+y r4e3+cnlrbnXbVhKa69TUul/umA2Jv5vroggZTCbLPYf/3bafi5JdWY2Ei/ASVCWXH9A aywJhLgjMGNzJuIh2rrcbuRoQtAmgon/VGIuFSNMXOqCXJtN1j85N9ijkB3XUyy0y2Jl n3hg== X-Gm-Message-State: AOAM531CiKnJ6MLiYRP9J5bAD1bkE9QEj0a/up5frx4NdBT9NvMLwXh4 gc9F5KGT3VqB9Z5Qku9MlndYeYXUF2QweaY60lu9Vg== X-Google-Smtp-Source: ABdhPJw9qo6/6qA17qt3SommKl5Kt2eGwf1GjUaS4QRzcq/DenqfvaHGIbgh5aqK7drz/IJ4KLgY2d7lQMruWIN46Do= X-Received: by 2002:a25:d188:0:b0:628:ba86:ee68 with SMTP id i130-20020a25d188000000b00628ba86ee68mr7040760ybg.427.1646989552644; Fri, 11 Mar 2022 01:05:52 -0800 (PST) MIME-Version: 1.0 References: <20220302082718.32268-1-songmuchun@bytedance.com> <20220302082718.32268-6-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Fri, 11 Mar 2022 17:04:06 +0800 Message-ID: Subject: Re: [PATCH v4 5/6] dax: fix missing writeprotect the pte entry To: Dan Williams Cc: Matthew Wilcox , Jan Kara , Al Viro , Andrew Morton , Alistair Popple , Yang Shi , Ralph Campbell , Hugh Dickins , Xiyu Yang , "Kirill A. Shutemov" , Ross Zwisler , Christoph Hellwig , linux-fsdevel , Linux NVDIMM , Linux Kernel Mailing List , Linux MM , Xiongchun duan , Muchun Song Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 987001C0018 X-Stat-Signature: jwxzx694op5oyuagbfw5fi9j493jimcs Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=pF6htef8; spf=pass (imf20.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.219.175 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-HE-Tag: 1646989553-467835 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 Thu, Mar 10, 2022 at 8:59 AM Dan Williams wrote: > > On Wed, Mar 2, 2022 at 12:30 AM Muchun Song wrote: > > > > Currently dax_mapping_entry_mkclean() fails to clean and write protect > > the pte entry within a DAX PMD entry during an *sync operation. This > > can result in data loss in the following sequence: > > > > 1) process A mmap write to DAX PMD, dirtying PMD radix tree entry and > > making the pmd entry dirty and writeable. > > 2) process B mmap with the @offset (e.g. 4K) and @length (e.g. 4K) > > write to the same file, dirtying PMD radix tree entry (already > > done in 1)) and making the pte entry dirty and writeable. > > 3) fsync, flushing out PMD data and cleaning the radix tree entry. We > > currently fail to mark the pte entry as clean and write protected > > since the vma of process B is not covered in dax_entry_mkclean(). > > 4) process B writes to the pte. These don't cause any page faults since > > the pte entry is dirty and writeable. The radix tree entry remains > > clean. > > 5) fsync, which fails to flush the dirty PMD data because the radix tree > > entry was clean. > > 6) crash - dirty data that should have been fsync'd as part of 5) could > > still have been in the processor cache, and is lost. > > Excellent description. > > > > > Just to use pfn_mkclean_range() to clean the pfns to fix this issue. > > So the original motivation for CONFIG_FS_DAX_LIMITED was for archs > that do not have spare PTE bits to indicate pmd_devmap(). So this fix > can only work in the CONFIG_FS_DAX_LIMITED=n case and in that case it > seems you can use the current page_mkclean_one(), right? I don't know the history of CONFIG_FS_DAX_LIMITED. page_mkclean_one() need a struct page associated with the pfn, do the struct pages exist when CONFIG_FS_DAX_LIMITED and ! FS_DAX_PMD? If yes, I think you are right. But I don't see this guarantee. I am not familiar with DAX code, so what am I missing here? Thanks.