Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp773081pxp; Fri, 11 Mar 2022 14:45:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9QonhIstWPFsK7islmbiv6R8AeDg0E5+xLEAAJpUPFWhUA3dy5XOLEjWjfJXGsen5Qh9J X-Received: by 2002:a05:6a00:280c:b0:4f6:fc52:7b6a with SMTP id bl12-20020a056a00280c00b004f6fc527b6amr12139266pfb.39.1647038740898; Fri, 11 Mar 2022 14:45:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647038740; cv=none; d=google.com; s=arc-20160816; b=VM0xv+ZkfvWdRSVCVGCoaehiiDU0HIefnX90pT2Y2ya9JvdkxJglcDsoT5Uger3Hne pQhxKlySCe5JgNdJTyVCMU18K56ikKSHhQbtoWOssylf7hfepw0jO1u43xULCG4gCvhh tKwG9NOKjK+UoP0Q/wFfsjUK6RGAefPaczX06y7Ap/BlSTGdtKjoj4LOE/Z8TQvGAIQ6 XhBIy1W47+XAexeBIXSbz1mWDZcg1g7yN848Eun1zKlYLT8qlKXVT0BGmoSHDwtrHdFn 15ncLfSGlfIy8D5/zSSg3sFp6y3dS6w4Jp89iq0Ik6H0yDzsK9RuPbyL7ammBEp8hyuH FivQ== 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=m4uZHfd5TEknERkFPf+I/joPh8Butuy4Qgst4A1Cqjw=; b=SYnasud5BpjguZ3BfZFzav2rUbu/+zLOO3VZiTvkG16Ml4rdPsBnfFm/ZpRxcSSuHq KBpP0LY5exqjHmeQ3+y7zLl/WqELrzMIjQ9Scnvqr9jyxmRJr5uYU6LukuItqvChtQq8 2GGrZ0sNNSkJ/JqGdllwX/x6iEVbN0Q7RjwfTySCsDR32/y2C1NhqTJj3SA00fqOys3I BqNkQnoBfCWWXFow0muPNWsOb0OY7mcRrCAs0ee0Vjj02EuTAqI2NP1SbzSGphScH4Ww /RZZzRmDrDrKfm1kGxOEggtTuAkUeBrBSNlai+6EMTJ5/phvhWk9qEuMwTuIGcyPTA/o oCIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=pF6htef8; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id u35-20020a056a0009a300b004f6e7499f0bsi9409365pfg.29.2022.03.11.14.45.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 14:45:40 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=pF6htef8; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 63D8D2D59A5; Fri, 11 Mar 2022 13:58:44 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233602AbiCKJG6 (ORCPT + 99 others); Fri, 11 Mar 2022 04:06:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235346AbiCKJG4 (ORCPT ); Fri, 11 Mar 2022 04:06:56 -0500 Received: from mail-yb1-xb35.google.com (mail-yb1-xb35.google.com [IPv6:2607:f8b0:4864:20::b35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6338D1BB700 for ; Fri, 11 Mar 2022 01:05:53 -0800 (PST) Received: by mail-yb1-xb35.google.com with SMTP id v130so15901343ybe.13 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=xWHE81c6WGbRpgJfP4R/MNoBIsBIxfaG1R/261E+tnrBKBxFsqyxzdfL0uTG7hN25T efBWNKi+hp9fgGy8N8C7Ka4+O1DRnxWxmTVXDBoInDKSjWwyeCZq/JK3MAcpljP3GTFD vcK0i2q8qIcy08BfOjbee8b0935Ekqg4/Rqtrxay0ce2Dnv/TE2TDuOE0LGcPpg2J0ml UTfhD724BbbYG/TyThcvtDC/qdU/LSU2bk9eSHl+2rrcQWHHZtGXtr4IUiaga5yCY47L DwOScUNnYSTCRMOfStL4dco505RffgKck0VA9ihXwJ4IbWIHprIyc0mCTB0B0umXyHh/ ea5Q== X-Gm-Message-State: AOAM533KK40pGeMK3WnShsJMUqUL+3A1YWhfuq4fcxYVTrCPc0Dmi5AR Ksc9mF6O+9c/ZmR8W3ITeNMdlt1Hvxt+MDlWUo5VRg== 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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.