Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2029794ybv; Sat, 8 Feb 2020 11:35:50 -0800 (PST) X-Google-Smtp-Source: APXvYqw6JgNBNN1YubjLWvo2CoPmq0eBGpaPBNw2hmBN2KsbBviDq/xagQzNF1gbBDVWbJ7m4Y8L X-Received: by 2002:aca:3805:: with SMTP id f5mr6185991oia.6.1581190550883; Sat, 08 Feb 2020 11:35:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581190550; cv=none; d=google.com; s=arc-20160816; b=RSoSWVvY2LVyuXKsYKEbAovKET58TrBZzieSNAeK29QMJbR1bNqvVh91UxyIVupfpo B9qXBgE/vCKDMZEvRoCjLS6xBghkub/SbSRsFB0ldnnkFI15R4THoivyyw4dcJpWqaSc GKEgrgCRogNEAVnAkd0WFp07lDZmO0Cy4HEAoRieV6z0Gj75b/hx9t8BFG4Z68S9a/Tj b8rGZhjXowf7mJOrlOMAmRt7R10S/o9ZQxBuSHMdgZsUYkcu722NxcRTUNmy+bFSANxE 8aCcwbRCskqLbKgNkJtIrSXa91xClT7xJ6dMmFksIFdcFToYjrk2zIvCwRtip3MRoGu4 8yeg== 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:message-id:date:subject:cc:to:from; bh=TNgfxDQJcL02eBek/sl3wBCMRxIhiGqEWm0CCAVEFUM=; b=qw6EcrANQjNKs2o7U8SATTzZ3CYwirtPWBKuRyENu4bqYBqwjJhqETJFfYJ5vCl+14 AND9KgiT+dFOBRy2CTcR05xzpMcPtlja2sDWfTC/YynJ4lqnINel+Vi3nZqAYOHk6qvP sO+NO20GQNzNLUzEkSFCue62FV/iviamVo1GJz6uKJgN9gpijnRKreBaOU+E5LBGDY7k GuiQEwYEkqpAOfwIKkjLByfpf33Ep+/n65UbJtK8Jx8M1g9Px9h4Kv3K44qUpH+3gbmI mbvUt7YpmR2eBXFJg7V4cchODBLR8TxoSy50mFO/rjOKbX38VA9qG8khTZu6boRYaJF6 Rwig== 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; 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 b10si5231582oiy.254.2020.02.08.11.35.40; Sat, 08 Feb 2020 11:35:50 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727768AbgBHTfQ (ORCPT + 99 others); Sat, 8 Feb 2020 14:35:16 -0500 Received: from mga11.intel.com ([192.55.52.93]:1353 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727586AbgBHTev (ORCPT ); Sat, 8 Feb 2020 14:34:51 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Feb 2020 11:34:50 -0800 X-IronPort-AV: E=Sophos;i="5.70,418,1574150400"; d="scan'208";a="431203209" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.157]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Feb 2020 11:34:50 -0800 From: ira.weiny@intel.com To: linux-kernel@vger.kernel.org Cc: Ira Weiny , Alexander Viro , "Darrick J. Wong" , 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: [PATCH v3 06/12] fs/xfs: Check if the inode supports DAX under lock Date: Sat, 8 Feb 2020 11:34:39 -0800 Message-Id: <20200208193445.27421-7-ira.weiny@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200208193445.27421-1-ira.weiny@intel.com> References: <20200208193445.27421-1-ira.weiny@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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. 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; + } + error = filemap_write_and_wait(inode->i_mapping); if (error) goto out_unlock; -- 2.21.0