From patchwork Fri Oct 6 22:35:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 9990627 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4FD9F6020F for ; Fri, 6 Oct 2017 22:42:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 413D828E4A for ; Fri, 6 Oct 2017 22:42:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3643C28E4B; Fri, 6 Oct 2017 22:42:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FD9328E45 for ; Fri, 6 Oct 2017 22:42:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752702AbdJFWl7 (ORCPT ); Fri, 6 Oct 2017 18:41:59 -0400 Received: from mga04.intel.com ([192.55.52.120]:8821 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752460AbdJFWl6 (ORCPT ); Fri, 6 Oct 2017 18:41:58 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Oct 2017 15:41:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,486,1500966000"; d="scan'208";a="1228003002" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.125]) by fmsmga002.fm.intel.com with ESMTP; 06 Oct 2017 15:41:57 -0700 Subject: [PATCH v7 03/12] fs: introduce i_mapdcount From: Dan Williams To: linux-nvdimm@lists.01.org Cc: linux-xfs@vger.kernel.org, Jan Kara , "Darrick J. Wong" , linux-rdma@vger.kernel.org, linux-api@vger.kernel.org, Dave Chinner , Christoph Hellwig , "J. Bruce Fields" , linux-mm@kvack.org, Jeff Moyer , linux-fsdevel@vger.kernel.org, Jeff Layton , Ross Zwisler Date: Fri, 06 Oct 2017 15:35:32 -0700 Message-ID: <150732933283.22363.570426117546397495.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <150732931273.22363.8436792888326501071.stgit@dwillia2-desk3.amr.corp.intel.com> References: <150732931273.22363.8436792888326501071.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-9-g687f MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When ->iomap_begin() sees this count being non-zero and determines that the block map of the file needs to be modified to satisfy the I/O request it will instead return an error. This is needed for MAP_DIRECT where, due to locking constraints, we can't rely on xfs_break_layouts() to protect against allocating write-faults either from the process that setup the MAP_DIRECT mapping nor other processes that have the file mapped. xfs_break_layouts() requires XFS_IOLOCK which is problematic to mix with the XFS_MMAPLOCK in the fault path. Cc: Jan Kara Cc: Jeff Moyer Cc: Christoph Hellwig Cc: Dave Chinner Cc: "Darrick J. Wong" Cc: Ross Zwisler Cc: Jeff Layton Cc: "J. Bruce Fields" Signed-off-by: Dan Williams --- fs/xfs/xfs_iomap.c | 9 +++++++++ include/linux/fs.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index a1909bc064e9..6816f8ebbdcf 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -1053,6 +1053,15 @@ xfs_file_iomap_begin( goto out_unlock; } /* + * If a file has MAP_DIRECT mappings disable block map + * updates. This should only effect mmap write faults as + * other paths are protected by an FL_LAYOUT lease. + */ + if (i_mapdcount_read(inode)) { + error = -ETXTBSY; + goto out_unlock; + } + /* * We cap the maximum length we map here to MAX_WRITEBACK_PAGES * pages to keep the chunks of work done where somewhat symmetric * with the work writeback does. This is a completely arbitrary diff --git a/include/linux/fs.h b/include/linux/fs.h index c2b9bf3dc4e9..f83871b188ff 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -642,6 +642,9 @@ struct inode { atomic_t i_count; atomic_t i_dio_count; atomic_t i_writecount; +#ifdef CONFIG_FS_DAX + atomic_t i_mapdcount; /* count of MAP_DIRECT vmas */ +#endif #ifdef CONFIG_IMA atomic_t i_readcount; /* struct files open RO */ #endif @@ -2784,6 +2787,34 @@ static inline void i_readcount_inc(struct inode *inode) return; } #endif + +#ifdef CONFIG_FS_DAX +static inline void i_mapdcount_dec(struct inode *inode) +{ + BUG_ON(!atomic_read(&inode->i_mapdcount)); + atomic_dec(&inode->i_mapdcount); +} +static inline void i_mapdcount_inc(struct inode *inode) +{ + atomic_inc(&inode->i_mapdcount); +} +static inline int i_mapdcount_read(struct inode *inode) +{ + return atomic_read(&inode->i_mapdcount); +} +#else +static inline void i_mapdcount_dec(struct inode *inode) +{ +} +static inline void i_mapdcount_inc(struct inode *inode) +{ +} +static inline int i_mapdcount_read(struct inode *inode) +{ + return 0; +} +#endif + extern int do_pipe_flags(int *, int); #define __kernel_read_file_id(id) \