Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1069384ybl; Fri, 10 Jan 2020 11:31:38 -0800 (PST) X-Google-Smtp-Source: APXvYqwqTSU5VrxXkxMiO2VWMy2h0ah1IlRUEQDc0vc0eJtMzfGHn8m645xL6pesg90L9QBfxOTj X-Received: by 2002:aca:b808:: with SMTP id i8mr3343258oif.66.1578684698167; Fri, 10 Jan 2020 11:31:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578684698; cv=none; d=google.com; s=arc-20160816; b=PJ3oN5vKpwNPHZvyLk2h0IX2FdIF/XdoSv3uaq4XDFFPxmaGUa47kUVBImQL0KGN0a 3UGpdTd/9iFSj+vNEHzCPk+C6GyxkCjFtFzF+VJPd/YWt2i/aPwXETGAIZgClEavFva1 X85LS8t6HASe0oFhUFbLdpciZqWuE3Rfrbz/m7ews7/iUAZ4G9ZP5fVpNDIPJxuK9JGN mcPJJWLet62ryWcq5WYMLbAd+F8wsDVqExqfZqIZb7rKoYw3IyrxXPE0VLOM6OAAv5gE 83iwTpL58CmcTj58YWrXFRoq895D2MZuGmaVyYB86JEYqlTpvvupcZV9JzU5FALyjyKZ f1IQ== 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=qI+IrB4IKau7xLvp6r2Ojg8OrfIogmb/s7R+yX89KKw=; b=GOrhL9jH2XE0ifmI3oXYsub+xuvkM3B/5vTpsmHKsUsplz+kFMH5yIHarwAHv8YknX H1tRw/5i3/0zzyuk3ZMKf53jvQyuPqHQUtseNdwDBRfYuT+mZ+o8AoPhaEx7JeIjtfc1 Df9YqJqvwvDhoiWHdgh8KOztVw+RXPvYcbsovD/Wfh5+j0vJ1BsAKYtOox99Qpwgh5z7 55N9JzVYU1/uWUMUNBb0C+dH/h/re2otsdoAWAQ3c0zKKywTLNkhh/YmuW2h4Riz6fZi F6gKUZPvKseCNX4Qx7Y5LSCLDDrSvdVIwIVq148WUe50k4K7R7Up/ss9i0k/C00sm44z zIQg== 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 x3si1518626oic.251.2020.01.10.11.31.26; Fri, 10 Jan 2020 11:31:38 -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 S1728939AbgAJTaH (ORCPT + 99 others); Fri, 10 Jan 2020 14:30:07 -0500 Received: from mga18.intel.com ([134.134.136.126]:33892 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728924AbgAJTaG (ORCPT ); Fri, 10 Jan 2020 14:30:06 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jan 2020 11:30:05 -0800 X-IronPort-AV: E=Sophos;i="5.69,418,1571727600"; d="scan'208";a="396531775" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.157]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jan 2020 11:30:04 -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: [RFC PATCH V2 06/12] fs/xfs: Check if the inode supports DAX under lock Date: Fri, 10 Jan 2020 11:29:36 -0800 Message-Id: <20200110192942.25021-7-ira.weiny@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200110192942.25021-1-ira.weiny@intel.com> References: <20200110192942.25021-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 mode change we could race with the file being reflinked and end up with a reflinked file being in DAX mode. 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 b5e00b67c297..bc3654fe3b5d 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -1180,10 +1180,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)) @@ -1197,6 +1193,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