From patchwork Tue Apr 7 08:43:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boaz Harrosh X-Patchwork-Id: 6167791 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3AA999F2EC for ; Tue, 7 Apr 2015 08:44:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 584432026D for ; Tue, 7 Apr 2015 08:43:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5309D20268 for ; Tue, 7 Apr 2015 08:43:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753128AbbDGIn4 (ORCPT ); Tue, 7 Apr 2015 04:43:56 -0400 Received: from mail-wg0-f52.google.com ([74.125.82.52]:32812 "EHLO mail-wg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753267AbbDGIny (ORCPT ); Tue, 7 Apr 2015 04:43:54 -0400 Received: by wgin8 with SMTP id n8so48454580wgi.0 for ; Tue, 07 Apr 2015 01:43:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=H8xy1sLcBU4yl54jPlJJPerfc5toLUJB+/m40E16Dbc=; b=Hmya+mqAb/c5lzD7nfwwIMvEFCHRaGDX3PbqQegTS5a0J+uup+Qee5ytaM+29NyIPt 0SpfJOhGkY6c3dNp7GHKU8kBzFFGJX1GVsRQg31/g3WGPfn5EBfzA2gCK3mROiV0gono L8Nk79u6sERXQhb6Y3sX3Ax6F3S6EBSkDA8nU8XFJwxGoEijKTruWuEDWCW/6oQbJwTa SZxig1UeFVqVQA9LI9DpyTl+q59b2spvTlHkAhzVjuQeW5VhfVe+nM1ee7sySA4+JsEG WBbdLNsNPK44MOHnS58ouWhD7fFO9Fl449SFTXNfgpkhMtSo94loKr2lofODB9uZ5f3x DqVg== X-Gm-Message-State: ALoCoQkuonUlHRnb0Y5/6od4aquIaIO2C9HEi7V1fOCa9YGQFMd+8Ay64Jq7XZrV1M3bYU1OsBV2 X-Received: by 10.194.109.70 with SMTP id hq6mr37078420wjb.77.1428396233307; Tue, 07 Apr 2015 01:43:53 -0700 (PDT) Received: from [10.0.0.5] ([207.232.55.62]) by mx.google.com with ESMTPSA id bp1sm9915069wjb.31.2015.04.07.01.43.51 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Apr 2015 01:43:52 -0700 (PDT) Message-ID: <552398C6.1010304@plexistor.com> Date: Tue, 07 Apr 2015 11:43:50 +0300 From: Boaz Harrosh User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Dave Chinner , Matthew Wilcox , Andrew Morton , "Kirill A. Shutemov" , Jan Kara , Hugh Dickins , Mel Gorman , linux-mm@kvack.org, linux-nvdimm , linux-fsdevel , Eryu Guan , Christoph Hellwig CC: Stable Tree Subject: [PATCH 2/3] dax: use pfn_mkwrite to update c/mtime + freeze protection References: <55239645.9000507@plexistor.com> In-Reply-To: <55239645.9000507@plexistor.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Yigal Korman [v1] Without this patch, c/mtime is not updated correctly when mmap'ed page is first read from and then written to. A new xfstest is submitted for testing this (generic/080) [v2] Jan Kara has pointed out that if we add the sb_start/end_pagefault pair in the new pfn_mkwrite we are then fixing another bug where: A user could start writing to the page while filesystem is frozen. CC: Jan Kara CC: Matthew Wilcox CC: Dave Chinner CC: Stable Tree Signed-off-by: Yigal Korman Signed-off-by: Boaz Harrosh Reviewed-by: Jan Kara --- fs/dax.c | 17 +++++++++++++++++ fs/ext2/file.c | 1 + fs/ext4/file.c | 1 + include/linux/fs.h | 1 + 4 files changed, 20 insertions(+) diff --git a/fs/dax.c b/fs/dax.c index ed1619e..d0bd1f4 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -464,6 +464,23 @@ int dax_fault(struct vm_area_struct *vma, struct vm_fault *vmf, EXPORT_SYMBOL_GPL(dax_fault); /** + * dax_pfn_mkwrite - handle first write to DAX page + * @vma: The virtual memory area where the fault occurred + * @vmf: The description of the fault + * + */ +int dax_pfn_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) +{ + struct super_block *sb = file_inode(vma->vm_file)->i_sb; + + sb_start_pagefault(sb); + file_update_time(vma->vm_file); + sb_end_pagefault(sb); + return VM_FAULT_NOPAGE; +} +EXPORT_SYMBOL_GPL(dax_pfn_mkwrite); + +/** * dax_zero_page_range - zero a range within a page of a DAX file * @inode: The file being truncated * @from: The file offset that is being truncated to diff --git a/fs/ext2/file.c b/fs/ext2/file.c index e317017..866a3ce 100644 --- a/fs/ext2/file.c +++ b/fs/ext2/file.c @@ -39,6 +39,7 @@ static int ext2_dax_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) static const struct vm_operations_struct ext2_dax_vm_ops = { .fault = ext2_dax_fault, .page_mkwrite = ext2_dax_mkwrite, + .pfn_mkwrite = dax_pfn_mkwrite, }; static int ext2_file_mmap(struct file *file, struct vm_area_struct *vma) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 598abbb..aa78c70 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -206,6 +206,7 @@ static int ext4_dax_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) static const struct vm_operations_struct ext4_dax_vm_ops = { .fault = ext4_dax_fault, .page_mkwrite = ext4_dax_mkwrite, + .pfn_mkwrite = dax_pfn_mkwrite, }; #else #define ext4_dax_vm_ops ext4_file_vm_ops diff --git a/include/linux/fs.h b/include/linux/fs.h index 368e349..394035f 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2628,6 +2628,7 @@ int dax_clear_blocks(struct inode *, sector_t block, long size); int dax_zero_page_range(struct inode *, loff_t from, unsigned len, get_block_t); int dax_truncate_page(struct inode *, loff_t from, get_block_t); int dax_fault(struct vm_area_struct *, struct vm_fault *, get_block_t); +int dax_pfn_mkwrite(struct vm_area_struct *, struct vm_fault *); #define dax_mkwrite(vma, vmf, gb) dax_fault(vma, vmf, gb) #ifdef CONFIG_BLOCK