From patchwork Mon Sep 25 23:14:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Zwisler X-Patchwork-Id: 9970657 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 7FDE560365 for ; Mon, 25 Sep 2017 23:16:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 714EA2847B for ; Mon, 25 Sep 2017 23:16:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FE5F28884; Mon, 25 Sep 2017 23:16:01 +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=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A3C1728D13 for ; Mon, 25 Sep 2017 23:14:33 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A4CD22095E53C; Mon, 25 Sep 2017 16:11:21 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: None (no SPF record) identity=mailfrom; client-ip=192.55.52.93; helo=mga11.intel.com; envelope-from=ross.zwisler@linux.intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B838D2095E513 for ; Mon, 25 Sep 2017 16:11:19 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Sep 2017 16:14:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,438,1500966000"; d="scan'208";a="139347309" Received: from theros.lm.intel.com ([10.232.112.77]) by orsmga002.jf.intel.com with ESMTP; 25 Sep 2017 16:14:29 -0700 From: Ross Zwisler To: Andrew Morton , linux-kernel@vger.kernel.org Subject: [PATCH 6/7] mm, fs: introduce file_operations->post_mmap() Date: Mon, 25 Sep 2017 17:14:03 -0600 Message-Id: <20170925231404.32723-7-ross.zwisler@linux.intel.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20170925231404.32723-1-ross.zwisler@linux.intel.com> References: <20170925231404.32723-1-ross.zwisler@linux.intel.com> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jeff Layton , Jan Kara , "Darrick J. Wong" , linux-nvdimm@lists.01.org, Dave Chinner , Christoph Hellwig , "J. Bruce Fields" , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP When mappings are created the vma->vm_flags that they use vary based on whether the inode being mapped is using DAX or not. This setup happens in XFS via mmap_region()=>call_mmap()=>xfs_file_mmap(). For us to be able to safely use the DAX per-inode flag we need to prevent S_DAX transitions when any mappings are present, and we will do that by looking at the address_space->i_mmap tree and returning -EBUSY if any mappings are present. Unfortunately at the time that the filesystem's file_operations->mmap() entry point is called the mapping has not yet been added to the address_space->i_mmap tree. This means that at that point in time we cannot determine whether or not the mapping will be set up to support DAX. Fix this by adding a new file_operations entry called post_mmap() which is called after the mapping has been added to the address_space->i_mmap tree. This post_mmap() op now happens at a time when we can be sure whether the mapping will use DAX or not, and we can set up the vma->vm_flags appropriately. Signed-off-by: Ross Zwisler --- fs/xfs/xfs_file.c | 15 ++++++++++++++- include/linux/fs.h | 1 + mm/mmap.c | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 2816858..9d66aaa 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1087,9 +1087,21 @@ xfs_file_mmap( { file_accessed(filp); vma->vm_ops = &xfs_file_vm_ops; + return 0; +} + +/* This call happens during mmap(), after the vma has been inserted into the + * inode->i_mapping->i_mmap tree. At this point the decision on whether or + * not to use DAX for this mapping has been set and will not change for the + * duration of the mapping. + */ +STATIC void +xfs_file_post_mmap( + struct file *filp, + struct vm_area_struct *vma) +{ if (IS_DAX(file_inode(filp))) vma->vm_flags |= VM_MIXEDMAP | VM_HUGEPAGE; - return 0; } const struct file_operations xfs_file_operations = { @@ -1103,6 +1115,7 @@ const struct file_operations xfs_file_operations = { .compat_ioctl = xfs_file_compat_ioctl, #endif .mmap = xfs_file_mmap, + .post_mmap = xfs_file_post_mmap, .open = xfs_file_open, .release = xfs_file_release, .fsync = xfs_file_fsync, diff --git a/include/linux/fs.h b/include/linux/fs.h index 339e737..7c06838 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1701,6 +1701,7 @@ struct file_operations { long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); long (*compat_ioctl) (struct file *, unsigned int, unsigned long); int (*mmap) (struct file *, struct vm_area_struct *); + void (*post_mmap) (struct file *, struct vm_area_struct *); int (*open) (struct inode *, struct file *); int (*flush) (struct file *, fl_owner_t id); int (*release) (struct inode *, struct file *); diff --git a/mm/mmap.c b/mm/mmap.c index 680506f..ee7458a 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1711,6 +1711,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma_link(mm, vma, prev, rb_link, rb_parent); /* Once vma denies write, undo our temporary denial count */ if (file) { + if (file->f_op->post_mmap) + file->f_op->post_mmap(file, vma); if (vm_flags & VM_SHARED) mapping_unmap_writable(file->f_mapping); if (vm_flags & VM_DENYWRITE)