Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5497371ybl; Tue, 14 Jan 2020 09:54:56 -0800 (PST) X-Google-Smtp-Source: APXvYqzAjcG3bgNk+gMpqbABXWRKOQ7gm1eyVReQ7XRFq+e1NC+kTQdG2xQZtDz+zjrxgmtEwKHw X-Received: by 2002:a05:6830:121a:: with SMTP id r26mr17927789otp.225.1579024496689; Tue, 14 Jan 2020 09:54:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579024496; cv=none; d=google.com; s=arc-20160816; b=vBRLUe+I1iMd2ZpgLJxlMfr2St80xySsoPJxX98Rpg2urq1P1Ed85aIHKNaTOVnMNS 9MvMNQ/URz8KkFHLC+N75qx53spwoCivDGWdWy5+1Pl+Ik9k6gz2UeMg+7rbOYjUk8kW UIyFcjTcG6j1bN6JmhgDFYpD9jxepHcJqvwv1UoqU2JBAZm+bnnHh53nOq0RZagOYrZp F1oyYWsgKB8HCjZFrhMR6dLZ/vNhXbCW4QqsP3XlWhru1BXqPxHohoRKoUj87tGU3LYa GxlNzNFdcNgJ3IPKwngbfq/kaaeDcFCZxCnatefJaPFllSW5JfJ564cz94gcFW7cwba6 UQmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=DND74MbZisFyYx2ancRr3iINvNpdnL+g+9NT+mbaDQU=; b=cOmZNYJkcBQ9ZYp5MWV2FWYKcDuIWubzGi+GfFZl75gHsUuHSeysl09ix/If61vRkl nodTJvN6yIpRDmS/DV1mPMVKsxcpYh/B6gi6NfuOReAib5Usrt1hNBkPJSCXSOhlpmFT 33okSYCeQfR5zgtdt51WtPtH6A62ORvDfig8sZ521cx5NeuRuSuPiCRckRfy6FRsuQsV W0QRn5m9J4oDQmW15ynCOypWN9EJ3OdfSxQ8CKyANJmQJoRn9tielATUODjeUbtN5zLP IUKo9EK4li8JhVwtGmXYJbSL+Kb2Aj5TeKiJsr1Cn+zBu9WQmCUfiFEIGALvtWjttBOO 6jqg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s6si8518938otp.126.2020.01.14.09.54.45; Tue, 14 Jan 2020 09:54:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728753AbgANRxz (ORCPT + 99 others); Tue, 14 Jan 2020 12:53:55 -0500 Received: from mga12.intel.com ([192.55.52.136]:5109 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726450AbgANRxz (ORCPT ); Tue, 14 Jan 2020 12:53:55 -0500 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Jan 2020 09:53:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,319,1574150400"; d="scan'208";a="225622891" Received: from iweiny-desk2.sc.intel.com ([10.3.52.157]) by orsmga006.jf.intel.com with ESMTP; 14 Jan 2020 09:53:54 -0800 Date: Tue, 14 Jan 2020 09:53:54 -0800 From: Ira Weiny To: "Darrick J. Wong" Cc: linux-kernel@vger.kernel.org, Alexander Viro , Dan Williams , Dave Chinner , Christoph Hellwig , "Theodore Y. Ts'o" , Jan Kara , linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [RFC PATCH V2 09/12] fs: Prevent mode change if file is mmap'ed Message-ID: <20200114175353.GA7871@iweiny-DESK2.sc.intel.com> References: <20200110192942.25021-1-ira.weiny@intel.com> <20200110192942.25021-10-ira.weiny@intel.com> <20200113222212.GO8247@magnolia> <20200114004610.GD29860@iweiny-DESK2.sc.intel.com> <20200114013004.GU8247@magnolia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200114013004.GU8247@magnolia> User-Agent: Mutt/1.11.1 (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 13, 2020 at 05:30:04PM -0800, Darrick J. Wong wrote: > On Mon, Jan 13, 2020 at 04:46:10PM -0800, Ira Weiny wrote: > > On Mon, Jan 13, 2020 at 02:22:12PM -0800, Darrick J. Wong wrote: > > > On Fri, Jan 10, 2020 at 11:29:39AM -0800, ira.weiny@intel.com wrote: > > > > From: Ira Weiny > > > > > > > > [snip] > > > > > > > > > > diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c > > > > index bc3654fe3b5d..1ab0906c6c7f 100644 > > > > --- a/fs/xfs/xfs_ioctl.c > > > > +++ b/fs/xfs/xfs_ioctl.c > > > > @@ -1200,6 +1200,14 @@ xfs_ioctl_setattr_dax_invalidate( > > > > goto out_unlock; > > > > } > > > > > > > > + /* > > > > + * If there is a mapping in place we must remain in our current mode. > > > > + */ > > > > + if (atomic64_read(&inode->i_mapped)) { > > > > > > Urk, should we really be messing around with the address space > > > internals? > > > > I contemplated a function call instead of checking i_mapped directly? Is that > > what you mean? > > Yeah. Abstracting the details just enough that filesystems don't have > to know that i_mapped is atomic64 etc. Done. > > > > > > > > > > + error = -EBUSY; > > > > + goto out_unlock; > > > > + } > > > > + > > > > error = filemap_write_and_wait(inode->i_mapping); > > > > if (error) > > > > goto out_unlock; > > > > diff --git a/include/linux/fs.h b/include/linux/fs.h > > > > index 631f11d6246e..6e7dc626b657 100644 > > > > --- a/include/linux/fs.h > > > > +++ b/include/linux/fs.h > > > > @@ -740,6 +740,7 @@ struct inode { > > > > #endif > > > > > > > > void *i_private; /* fs or device private pointer */ > > > > + atomic64_t i_mapped; > > > > > > I would have expected to find this in struct address_space since the > > > mapping count is a function of the address space, right? > > > > I suppose but the only external call (above) would be passing an inode. So to > > me it seemed better here. > > But the number of memory mappings reflects the state of the address > space, not the inode. Or maybe put another way, if I were an mm > developer I would not expect to look in struct inode for mm state. This is a good point... > > static inline bool inode_has_mappings(struct inode *inode) > { > return atomic64_read(&inode->i_mapping->mapcount) > 0; > } > > OTOH if there exist other mm developers who /do/ find that storing the > mmap count in struct inode is more logical, please let me know. :) ... My thinking was that the number of mappings does not matters to the mm system... However, I'm starting to think you are correct... ;-) I've made a note of it and we will see what others think. Ira > > --D > > > Ira > > > > > > > > --D > > >