From patchwork Mon Mar 23 12:54:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boaz Harrosh X-Patchwork-Id: 6073001 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 46D5F9F318 for ; Mon, 23 Mar 2015 12:54:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5E8E92024C for ; Mon, 23 Mar 2015 12:54:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 67ECC2024F for ; Mon, 23 Mar 2015 12:54:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752967AbbCWMyq (ORCPT ); Mon, 23 Mar 2015 08:54:46 -0400 Received: from mail-wi0-f172.google.com ([209.85.212.172]:35889 "EHLO mail-wi0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752485AbbCWMyo (ORCPT ); Mon, 23 Mar 2015 08:54:44 -0400 Received: by wibg7 with SMTP id g7so46495224wib.1 for ; Mon, 23 Mar 2015 05:54:42 -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 :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=+V9L5XrklUT3AR26amRVJy/XC7Xa31OtAuTBpmwLB+g=; b=RPzydrtoM4M/6LwI5nPaI5yIobzjTcODjmjVkCP1YNAq6h03qAiB3XO9aB6VwJM1Vn TlkBFDsb2eCRzp6OZWLbKlpm2T+iavZd5TNyzzfyvh4trs0P2hmKRU2cILPiw4PnQBgE 7ybSznWF33KUbL7PUMF99inIhHP2zZg4DObscGfbpGCFmnPLEIRs97ffWNlHlNXCLQbr yQDpItmYawYPzxryDuOijecsizjZ9s3IgyNVkec6PwGJqXv+NSulW0cyi7KS7KyXrGMg 1o+kdj5jQ/WdcgcwGrIiJ91KAy9oD3sDsbIuXiLosXUy6ot3G7S9vDUmpPlaKOLZh7ds Yunw== X-Gm-Message-State: ALoCoQnnzNk8lO9wHOWdMOpSNNFRsBtQnfuuG+ryPxOsQBDFXkJChBBYL9MSrFgPllCdfwI2QF3T X-Received: by 10.180.208.33 with SMTP id mb1mr19187170wic.69.1427115282757; Mon, 23 Mar 2015 05:54:42 -0700 (PDT) Received: from [10.0.0.5] ([207.232.55.62]) by mx.google.com with ESMTPSA id cn10sm11019343wib.15.2015.03.23.05.54.41 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Mar 2015 05:54:42 -0700 (PDT) Message-ID: <55100D10.6090902@plexistor.com> Date: Mon, 23 Mar 2015 14:54:40 +0200 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 Subject: [PATCH 3/3] RFC: dax: dax_prepare_freeze References: <55100B78.501@plexistor.com> In-Reply-To: <55100B78.501@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: Boaz Harrosh When freezing an FS, we must write protect all IS_DAX() inodes that have an mmap mapping on an inode. Otherwise application will be able to modify previously faulted-in file pages. I'm actually doing a full unmap_mapping_range because there is no readily available "mapping_write_protect" like functionality. I do not think it is worth it to define one just for here and just for some extra read-faults after an fs_freeze. How hot-path is fs_freeze at all? CC: Jan Kara CC: Matthew Wilcox CC: Andrew Morton Signed-off-by: Boaz Harrosh --- fs/dax.c | 30 ++++++++++++++++++++++++++++++ fs/super.c | 3 +++ include/linux/fs.h | 1 + 3 files changed, 34 insertions(+) diff --git a/fs/dax.c b/fs/dax.c index d0bd1f4..f3fc28b 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -549,3 +549,33 @@ int dax_truncate_page(struct inode *inode, loff_t from, get_block_t get_block) return dax_zero_page_range(inode, from, length, get_block); } EXPORT_SYMBOL_GPL(dax_truncate_page); + +/* This is meant to be called as part of freeze_super. otherwise we might + * Need some extra locking before calling here. + */ +void dax_prepare_freeze(struct super_block *sb) +{ + struct inode *inode; + + /* TODO: each DAX fs has some private mount option to enable DAX. If + * We made that option a generic MS_DAX_ENABLE super_block flag we could + * Avoid the 95% extra unneeded loop-on-all-inodes every freeze. + * if (!(sb->s_flags & MS_DAX_ENABLE)) + * return 0; + */ + + list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { + /* TODO: For freezing we can actually do with write-protecting + * the page. But I cannot find a ready made function that does + * that for a giving mapping (with all the proper locking). + * How performance sensitive is the all sb_freeze API? + * For now we can just unmap the all mapping, and pay extra + * on read faults. + */ + /* NOTE: Do not unmap private COW mapped pages it will not + * modify the FS. + */ + if (IS_DAX(inode)) + unmap_mapping_range(inode->i_mapping, 0, 0, 0); + } +} diff --git a/fs/super.c b/fs/super.c index 2b7dc90..9ef490c 100644 --- a/fs/super.c +++ b/fs/super.c @@ -1329,6 +1329,9 @@ int freeze_super(struct super_block *sb) /* All writers are done so after syncing there won't be dirty data */ sync_filesystem(sb); + /* Need to take care of DAX mmaped inodes */ + dax_prepare_freeze(sb); + /* Now wait for internal filesystem counter */ sb->s_writers.frozen = SB_FREEZE_FS; smp_wmb(); diff --git a/include/linux/fs.h b/include/linux/fs.h index 24af817..3b943d4 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2599,6 +2599,7 @@ 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) +void dax_prepare_freeze(struct super_block *sb); #ifdef CONFIG_BLOCK typedef void (dio_submit_t)(int rw, struct bio *bio, struct inode *inode,