Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4560955ybv; Mon, 10 Feb 2020 22:32:02 -0800 (PST) X-Google-Smtp-Source: APXvYqztbXZJa0PnZlbzcozEsqQpIf10gpnap7++8wmI4zLVVUacEydlXM1+dwA32kYkcEuZK5H2 X-Received: by 2002:aca:d507:: with SMTP id m7mr1881556oig.48.1581402721663; Mon, 10 Feb 2020 22:32:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581402721; cv=none; d=google.com; s=arc-20160816; b=CGdVrgZ+qd21txeCOCev1PLr6Asluze9qv2bEZCLPd/i0u168BodWuwTu25OKkTUEC WfeAe+dGM1gmbcDIRC3dB3OkF1czPfH163+wHyzTVogMnnmv6Ci3DhA40L2DIFkL8Skv 7TiAi3bVP8w54jKv07w9Qfav+6jYGQTKheB+PJ7ohPm8TNMnE7bXzHXw2SVcCWyIL8Rl CtvxR0sugj5UB+g1J9TkL+DQC4sSfSVYN46Erl8mbJebpn0YSJSC52Tch8RVsu3tgBTD m/fmq1WDZn+qvyLbsriEn/96UZ4klsMLikvROkC88Jg6ikWzmYSg8J1p/8vVT6smSK0w z9cw== 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=mf5S9r6W54+0ztiHe9mtXql6Ci6wQnc1ADUKNmlinEM=; b=0xfbeHN6rHA3gZmeqndWocO7ApHkpqr3OrdbHdhOrMZl4na9pYqMyjX6/G564b63iD 2th5cDVyI+UVfSoCdbHS4hnSbkllBdO+8UE6JGKZ/6FbCn5u5O4/24RmhFer6MTZ1BEO EOaJ6+Ovd7fmJidpLFf3TuJcBfQ7Fv8N7efFRQAgaq/EKwE6qIYpo7itnFWjpd/wXwp3 KVfbXCB4lB3ft/ejyV7+bj7B94wkaCzync/GTk2wQ0akcHfqzG27yJjaoqVYjLwALvPh ztyU9zTEfSdKILZHD2G9kOFbhcFPKA9LRcBQGQd1+qYyuOaQozxBOpu8y/vmUf/3kb2k Yy6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-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 25si1326364oiz.230.2020.02.10.22.31.49; Mon, 10 Feb 2020 22:32:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-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-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727790AbgBKGQp (ORCPT + 99 others); Tue, 11 Feb 2020 01:16:45 -0500 Received: from mail104.syd.optusnet.com.au ([211.29.132.246]:34885 "EHLO mail104.syd.optusnet.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727430AbgBKGQp (ORCPT ); Tue, 11 Feb 2020 01:16:45 -0500 Received: from dread.disaster.area (pa49-179-138-28.pa.nsw.optusnet.com.au [49.179.138.28]) by mail104.syd.optusnet.com.au (Postfix) with ESMTPS id 75D9F820676; Tue, 11 Feb 2020 17:16:40 +1100 (AEDT) Received: from dave by dread.disaster.area with local (Exim 4.92.3) (envelope-from ) id 1j1Oqd-0006AU-2i; Tue, 11 Feb 2020 17:16:39 +1100 Date: Tue, 11 Feb 2020 17:16:39 +1100 From: Dave Chinner To: ira.weiny@intel.com Cc: linux-kernel@vger.kernel.org, Alexander Viro , "Darrick J. Wong" , Dan Williams , 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: [PATCH v3 06/12] fs/xfs: Check if the inode supports DAX under lock Message-ID: <20200211061639.GH10776@dread.disaster.area> References: <20200208193445.27421-1-ira.weiny@intel.com> <20200208193445.27421-7-ira.weiny@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200208193445.27421-7-ira.weiny@intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.3 cv=LYdCFQXi c=1 sm=1 tr=0 a=zAxSp4fFY/GQY8/esVNjqw==:117 a=zAxSp4fFY/GQY8/esVNjqw==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=kj9zAlcOel0A:10 a=l697ptgUJYAA:10 a=QyXUC8HyAAAA:8 a=7-415B0cAAAA:8 a=R3CSNY5uwQTHXUhv2_4A:9 a=CjuIK1q_8ugA:10 a=biEYGPWJfzWAr4FL6Ov7:22 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Sat, Feb 08, 2020 at 11:34:39AM -0800, ira.weiny@intel.com wrote: > From: Ira Weiny > > One of the checks for an inode supporting DAX is if the inode is > reflinked. During a non-DAX to DAX state change we could race with > the file being reflinked and end up with a reflinked file being in DAX > state. > > Prevent this race by checking for DAX support under the MMAP_LOCK. The on disk inode flags are protected by the XFS_ILOCK, not the MMAP_LOCK. i.e. the MMAPLOCK provides data access serialisation, not metadata modification serialisation. > > Signed-off-by: Ira Weiny > --- > fs/xfs/xfs_ioctl.c | 11 +++++++---- > 1 file changed, 7 insertions(+), 4 deletions(-) > > diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c > index da1eb2bdb386..4ff402fd6636 100644 > --- a/fs/xfs/xfs_ioctl.c > +++ b/fs/xfs/xfs_ioctl.c > @@ -1194,10 +1194,6 @@ xfs_ioctl_setattr_dax_invalidate( > > *join_flags = 0; > > - if ((fa->fsx_xflags & FS_XFLAG_DAX) == FS_XFLAG_DAX && > - !xfs_inode_supports_dax(ip)) > - return -EINVAL; > - > /* If the DAX state is not changing, we have nothing to do here. */ > if ((fa->fsx_xflags & FS_XFLAG_DAX) && > (ip->i_d.di_flags2 & XFS_DIFLAG2_DAX)) > @@ -1211,6 +1207,13 @@ xfs_ioctl_setattr_dax_invalidate( > > /* lock, flush and invalidate mapping in preparation for flag change */ > xfs_ilock(ip, XFS_MMAPLOCK_EXCL | XFS_IOLOCK_EXCL); > + > + if ((fa->fsx_xflags & FS_XFLAG_DAX) == FS_XFLAG_DAX && > + !xfs_inode_supports_dax(ip)) { > + error = -EINVAL; > + goto out_unlock; > + } Yes, you might be able to get away with reflink vs dax flag serialisation on the inode flag modification, but it is not correct and leaves a landmine for future inode flag modifications that are done without holding either the MMAP or IOLOCK. e.g. concurrent calls to xfs_ioctl_setattr() setting/clearing flags other than the on disk DAX flag are all serialised by the ILOCK_EXCL and will no be serialised against this DAX check. Hence if there are other flags that we add in future that affect the result of xfs_inode_supports_dax(), this code will not be correctly serialised. This raciness in checking the DAX flags is the reason that xfs_ioctl_setattr_xflags() redoes all the reflink vs dax checks once it's called under the XFS_ILOCK_EXCL during the actual change transaction.... Cheers, Dave. -- Dave Chinner david@fromorbit.com