Received: by 10.223.176.46 with SMTP id f43csp1077913wra; Fri, 19 Jan 2018 06:37:27 -0800 (PST) X-Google-Smtp-Source: ACJfBot86fbZb/fmJz4XZtEk378qwYkq7nRbV/iNk0toNy9zuonJk/6AhKtj9TObWudoIR6IKI6D X-Received: by 10.99.111.193 with SMTP id k184mr33913517pgc.378.1516372647790; Fri, 19 Jan 2018 06:37:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516372647; cv=none; d=google.com; s=arc-20160816; b=od8w3c0rJxESEQZbpWheOSdKOKMNKi3JoGjJ/Mb34cA3LzTCA5FTnBqOM+D1FdjR/c Vzd2m7qSNgqbf30dUcak6ltE/2Au1I0h8ZkKtDRDC8VOTtlaFK4Xr6T6H3YP5U0k9zXZ X/L/DL3rkc8/1mHlVMYvQhx5A6qsVbUg3+QO1VCPSBkwJI2dRYxr4zjGCsFenLmE5VGX 3bxY9tANX13NRwNi/D10o62mIzl+dZmBZo4qhfibrG0wQXFg60D9nR2q4d7eh8ro8IiV 8xqdj62MKFupSma+opPSw+m40ohbloLTERmahDonBLNynXdzNgVQU8eTGF1SC20XGPz4 PeiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :dmarc-filter:arc-authentication-results; bh=X/qaz8+EGzkb8ecsWmaRNl4wjbdx+1wZ3lElQjyz8lQ=; b=ZpGjEJv87NxK7Rrq/P6kb6ZkUIZ9WUfiiFHypQW6Eu89xUkI12dwZ9vcMpufrhiJ/v x42li9yaTQMjMCjol9AwyMq16wFiPb/PUKAWncbR8K8mydQwm0Sd6yrVqQ9nrP9nin4v mmn3aJyuZHdZ1XbPcORgXV7uLD9iqdmyj31WSbEyJr9gj0Os+VtiYty2OEdHsL6/OCBn 847v6FWgda444/JHLQvYORJUg+kqdTeS3rfgCA0Fdu9DHaNZB8U5oflZOdVtdKGCRyj0 Yj3p2kHA/sL4S4ad7iVG3EQ0k49G3coLM53ylMNZPcxsSVpvuN/IKDkBqppT6pxp0XsS hrnA== 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 z7si3198804pfa.360.2018.01.19.06.37.13; Fri, 19 Jan 2018 06:37:27 -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 S1755878AbeASOgq (ORCPT + 99 others); Fri, 19 Jan 2018 09:36:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:49332 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754809AbeASOgj (ORCPT ); Fri, 19 Jan 2018 09:36:39 -0500 Received: from tleilax.poochiereds.net (cpe-71-70-156-158.nc.res.rr.com [71.70.156.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 002CA20C0F; Fri, 19 Jan 2018 14:36:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 002CA20C0F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=jlayton@kernel.org Message-ID: <1516372594.3588.11.camel@kernel.org> Subject: Re: [PATCH v5 02/19] fs: don't take the i_lock in inode_inc_iversion From: Jeff Layton To: "J. Bruce Fields" 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 Date: Fri, 19 Jan 2018 09:36:34 -0500 In-Reply-To: <20180118214534.GB5299@fieldses.org> References: <20180109141059.25929-1-jlayton@kernel.org> <20180109141059.25929-3-jlayton@kernel.org> <20180118214534.GB5299@fieldses.org> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.3 (3.26.3-1.fc27) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2018-01-18 at 16:45 -0500, J. Bruce Fields wrote: > 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. > Shrug...we have that problem with the spinlock in place too. The bottom line is that reads of this value are not serialized with the increment at all. I'm not 100% thrilled with this patch, but I think it's probably better not to add the i_lock all over the place, even as an interim step in cleaning this stuff up. The good news here (as you mention) is that this nastiness gets cleaned up in the last patch when we convert the thing to an atomic64_t. > > > > 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 -- Jeff Layton