Received: by 10.223.176.46 with SMTP id f43csp47807wra; Thu, 18 Jan 2018 13:46:21 -0800 (PST) X-Google-Smtp-Source: ACJfBoswVPxJBRKEnAeVlAssn5J/Qq+6YKDoU70zvnuD6aFYX4vWzWcYNNmaz9tCPd7wkuPTo4Ws X-Received: by 10.98.171.7 with SMTP id p7mr18105220pff.138.1516311981669; Thu, 18 Jan 2018 13:46:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516311981; cv=none; d=google.com; s=arc-20160816; b=CJxW7RMf1mX5u6G2k5ZR7LHws65XCRMopGPNEyo48Llh7jaUCIx20Tu1b9Y2pbXQbu +wtayUJpIU9xW0lwElyS3Ei5Wd7Sgf7f4GRriBEECvwfapaoX8PHz3rEJwBpIvyqqu6k B9XkmYiHgFaRNCJ67gDq96BhlpXr880YzkVrHjrRasJ55JFP6R8OuQW/CHDPrEY62Ny4 LTu25gwBDZq8N9nUCvHWJljKfoibLMDdOzk4Ni9CGtGk7VGnZSp2MZEV5wZlWSs8rY7E G0QUxoAGTOdM/p+YpjDXNAR2iWyDH2CDo4mjT6bHCkgf2kvdw47o3EkoobCYIlY7iJp8 w2Cg== 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:arc-authentication-results; bh=yERdy39P0ix37Xva9m54WLz4saAyZvmcage0CZa6D3Q=; b=b5Qqrpylh1gvrqVyvD3BFscZ5IYkvfLPOD/n9SzCYDV8pGSHjkfN0z9VRdK1WvTZg5 hqL80nS0lXBEbXwgJG8DepmGALMNzq4HbaKCfq1u3VcKkBhQZZK1H9FQeO+6dwFqrF52 RmeNbioDd9eYb2RPlIPUvrSSlSNyoc4tIti3pQPms70JOivXU5MrKqvWtjN1dj/CdI20 A5PutVTP3S1h2/aUY4N70YY7alJVK95vi2Ydl8RAeUR0EgObjFwKX7qCdvy8KScdUAcd Qoh5O9i+owJfHiVgJioNpEA3yBueZpz+L+f/Q4WUhRi66ACTjDhTzKdyjJ2wk0RjwfSA TreA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i90si7746192pfd.147.2018.01.18.13.46.06; Thu, 18 Jan 2018 13:46:21 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932191AbeARVpm (ORCPT + 99 others); Thu, 18 Jan 2018 16:45:42 -0500 Received: from fieldses.org ([173.255.197.46]:49846 "EHLO fieldses.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750718AbeARVpf (ORCPT ); Thu, 18 Jan 2018 16:45:35 -0500 Received: by fieldses.org (Postfix, from userid 2815) id BE3D92416; Thu, 18 Jan 2018 16:45:34 -0500 (EST) Date: Thu, 18 Jan 2018 16:45:34 -0500 From: "J. Bruce Fields" To: Jeff Layton Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, linux-nfs@vger.kernel.org, neilb@suse.de, jack@suse.de, linux-ext4@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, linux-xfs@vger.kernel.org, darrick.wong@oracle.com, david@fromorbit.com, linux-btrfs@vger.kernel.org, clm@fb.com, jbacik@fb.com, dsterba@suse.com, linux-integrity@vger.kernel.org, zohar@linux.vnet.ibm.com, dmitry.kasatkin@gmail.com, linux-afs@lists.infradead.org, dhowells@redhat.com, jaltman@auristor.com, krzk@kernel.org Subject: Re: [PATCH v5 02/19] fs: don't take the i_lock in inode_inc_iversion Message-ID: <20180118214534.GB5299@fieldses.org> References: <20180109141059.25929-1-jlayton@kernel.org> <20180109141059.25929-3-jlayton@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180109141059.25929-3-jlayton@kernel.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 09, 2018 at 09:10:42AM -0500, Jeff Layton wrote: > From: Jeff Layton > > The rationale for taking the i_lock when incrementing this value is > lost in antiquity. The readers of the field don't take it (at least > not universally), so my assumption is that it was only done here to > serialize incrementors. > > If that is indeed the case, then we can drop the i_lock from this > codepath and treat it as a atomic64_t for the purposes of > incrementing it. This allows us to use inode_inc_iversion without > any danger of lock inversion. > > Note that the read side is not fetched atomically with this change. > The assumption here is that that is not a critical issue since the > i_version is not fully synchronized with anything else anyway. So I guess it's theoretically possible that e.g. if you read while it's incrementing from 2^32-1 to 2^32 you could read 0, 1, or 2^32+1? If so then you could see an i_version value reused and incorrectly decide that a file hadn't changed. But it's such a tiny case, and I think you convert this to atomic64_t later anyway, so, whatever. --b. > > Signed-off-by: Jeff Layton > --- > include/linux/iversion.h | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/include/linux/iversion.h b/include/linux/iversion.h > index d09cc3a08740..5ad9eaa3a9b0 100644 > --- a/include/linux/iversion.h > +++ b/include/linux/iversion.h > @@ -104,12 +104,13 @@ inode_set_iversion_queried(struct inode *inode, u64 new) > static inline bool > inode_maybe_inc_iversion(struct inode *inode, bool force) > { > - spin_lock(&inode->i_lock); > - inode->i_version++; > - spin_unlock(&inode->i_lock); > + atomic64_t *ivp = (atomic64_t *)&inode->i_version; > + > + atomic64_inc(ivp); > return true; > } > > + > /** > * inode_inc_iversion - forcibly increment i_version > * @inode: inode that needs to be updated > -- > 2.14.3