From patchwork Wed Jun 19 11:53:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13703744 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8978137747 for ; Wed, 19 Jun 2024 11:54:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718798074; cv=none; b=p5YAxH6NFelgkNXruaKrmIwtxgqwsM5QT+nFQPDsfkxcNAB3IXssxaN5RO2GcbzmTY6AGJG6l2vX4f05VMiYp4nKJp5u2CTsG3RdTJ81gwtJHXCFSmDEhC8hjt6vENzSOD47IJRbxNgoAlBxe+7v2nD4OkzbdrfQZLJTziWLQyk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718798074; c=relaxed/simple; bh=2ceETvIZVnivoxfrdlOMZunonIkde0gGypO+irm1a0c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tmupcvAeXd/bOtr0BTShfCQSF4PmFKUvCwBa1OmuiOF9oajJp8LBdfUu0/E8YR0WghFnOt09nB9ZQvJx6v2VYlhaU9hyD1LpLbGRgYtMINeRmobQK8jufNTJuu3hjedU1fmTmKqYAzngglVVtNBXLue76iuGNkYUYcRfKFt6vAg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=3H287grF; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="3H287grF" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=km9pqJBc15cNzjV8YL5dc4OVBT9Ut/+5PfqYsw27YX8=; b=3H287grFJEJSppT6718zGgEFSp cpbEAPS3AUUdWsUgr5YOWQniV63jaSw4W2V9yGbYpDSlZOYhTcF3I9CLVkmmvp305KcZ/AnwafDji WwdTD3jo//VAsM7t/uLMgs3p1P9rqltX3/5uE/zvEyL6ztiejKt60oqC+ZNy8Dq2LVzZTyxZ41ol/ FWiSbCyfuMSBCToAiky3Ac9A4HiIk2akd9YY/elIB+KS0f8vWpQICiRja5A6TkCe8eMZ8TukE23Hc 0+TH4townCp0efy8N4dGHxZ0ncBNasEAOhthMlagZEMTCHrB9RQMROCvY3yGsLuVHyEm9jyXp3dNI IpSKqWUw==; Received: from 2a02-8389-2341-5b80-3836-7e72-cede-2f46.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:3836:7e72:cede:2f46] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJttX-000000014O2-3Qzj; Wed, 19 Jun 2024 11:54:32 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , linux-xfs@vger.kernel.org Subject: [PATCH 1/6] xfs: move the dio write relocking out of xfs_ilock_for_iomap Date: Wed, 19 Jun 2024 13:53:51 +0200 Message-ID: <20240619115426.332708-2-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240619115426.332708-1-hch@lst.de> References: <20240619115426.332708-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html About half of xfs_ilock_for_iomap deals with a special case for direct I/O writes to COW files that need to take the ilock exclusively. Move this code into the one callers that cares and simplify xfs_ilock_for_iomap. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_iomap.c | 71 ++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 3783426739258c..b0085e5972393a 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -717,53 +717,30 @@ imap_needs_cow( return true; } +/* + * Extents not yet cached requires exclusive access, don't block for + * IOMAP_NOWAIT. + * + * This is basically an opencoded xfs_ilock_data_map_shared() call, but with + * support for IOMAP_NOWAIT. + */ static int xfs_ilock_for_iomap( struct xfs_inode *ip, unsigned flags, unsigned *lockmode) { - unsigned int mode = *lockmode; - bool is_write = flags & (IOMAP_WRITE | IOMAP_ZERO); - - /* - * COW writes may allocate delalloc space or convert unwritten COW - * extents, so we need to make sure to take the lock exclusively here. - */ - if (xfs_is_cow_inode(ip) && is_write) - mode = XFS_ILOCK_EXCL; - - /* - * Extents not yet cached requires exclusive access, don't block. This - * is an opencoded xfs_ilock_data_map_shared() call but with - * non-blocking behaviour. - */ - if (xfs_need_iread_extents(&ip->i_df)) { - if (flags & IOMAP_NOWAIT) - return -EAGAIN; - mode = XFS_ILOCK_EXCL; - } - -relock: if (flags & IOMAP_NOWAIT) { - if (!xfs_ilock_nowait(ip, mode)) + if (xfs_need_iread_extents(&ip->i_df)) + return -EAGAIN; + if (!xfs_ilock_nowait(ip, *lockmode)) return -EAGAIN; } else { - xfs_ilock(ip, mode); + if (xfs_need_iread_extents(&ip->i_df)) + *lockmode = XFS_ILOCK_EXCL; + xfs_ilock(ip, *lockmode); } - /* - * The reflink iflag could have changed since the earlier unlocked - * check, so if we got ILOCK_SHARED for a write and but we're now a - * reflink inode we have to switch to ILOCK_EXCL and relock. - */ - if (mode == XFS_ILOCK_SHARED && is_write && xfs_is_cow_inode(ip)) { - xfs_iunlock(ip, mode); - mode = XFS_ILOCK_EXCL; - goto relock; - } - - *lockmode = mode; return 0; } @@ -801,7 +778,7 @@ xfs_direct_write_iomap_begin( int nimaps = 1, error = 0; bool shared = false; u16 iomap_flags = 0; - unsigned int lockmode = XFS_ILOCK_SHARED; + unsigned int lockmode; u64 seq; ASSERT(flags & (IOMAP_WRITE | IOMAP_ZERO)); @@ -817,10 +794,30 @@ xfs_direct_write_iomap_begin( if (offset + length > i_size_read(inode)) iomap_flags |= IOMAP_F_DIRTY; + /* + * COW writes may allocate delalloc space or convert unwritten COW + * extents, so we need to make sure to take the lock exclusively here. + */ + if (xfs_is_cow_inode(ip)) + lockmode = XFS_ILOCK_EXCL; + else + lockmode = XFS_ILOCK_SHARED; + +relock: error = xfs_ilock_for_iomap(ip, flags, &lockmode); if (error) return error; + /* + * The reflink iflag could have changed since the earlier unlocked + * check, check if it again and relock if needed. + */ + if (xfs_is_cow_inode(ip) && lockmode == XFS_ILOCK_SHARED) { + xfs_iunlock(ip, lockmode); + lockmode = XFS_ILOCK_EXCL; + goto relock; + } + error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb, &imap, &nimaps, 0); if (error) From patchwork Wed Jun 19 11:53:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13703745 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A5CD824BB for ; Wed, 19 Jun 2024 11:54:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718798077; cv=none; b=HI4TEzJZf4waoeXhuykgTy/pyAj41ezNlxztai5qgByx9eQ1pGaiDOIAVv7rhTmc1lE7NR9OJj7NGCNGvQzyE3+e4hwOV+rxPACuDfDVwkTneFTopTYkqTJ2JZzM5MR5oiFmvT2tRonL/t4joDcP8CJmvQ4TQ9M7mvP2axcaD8c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718798077; c=relaxed/simple; bh=jPjG01ghYZdxqCrg2F/0tumct+naG0lC2sFeniAFdbU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sdWYu0/iLSJnhbTOBJr4L19qeulhGnqXubbZsda7qVj7fzeDWR6/arZrkjQpfmePGk46IUxuAPuwqc3md+zyzhh8HQvJIPDk/siC/t/F/BG+2z5VIWdvtaqOZy7+MeeQ+SLaOQI2Auv3zDmraJ0zbQ5J8GzhBIr9pwLILGrIEI8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=UVq99BCp; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="UVq99BCp" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=dzbJPBFeMrFU7Sh/Q2vx8nZdNm1RMn3h3JYJuqf7Tu4=; b=UVq99BCpDOJ1/5097r00IBEBkv a10hg5OPjPhd77zFDXQDwemXCL1kQGxwqzb4nhzwaOR+lqsPrEqfhZdaorkgljSdC+/pzzmxWgeYG RX0jtkOS0nJ9qKiKXxmlwDH3FEOGDUm/i9WXVMuGw+ytHknVVTI6/o2PRFhvn8/6g8ervDnIab7yr W9NsMqxVwGntHbqhuAOD2DjDMnHVewzfBpvbZDj35AfHNc5Y6xuMZJ/6pYYRtlZJW4qck1QaEnc9g RMkwzdDzGR+FQJgkz4SLu7Hi/OLxT5EHNo2krjhbhqmWYmxgwjv/v/aDH4RUNmSCk/Ktsmm6/ZsOY cLOckKXA==; Received: from 2a02-8389-2341-5b80-3836-7e72-cede-2f46.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:3836:7e72:cede:2f46] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJtta-000000014OI-1Sqs; Wed, 19 Jun 2024 11:54:34 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , linux-xfs@vger.kernel.org Subject: [PATCH 2/6] xfs: cleanup xfs_ilock_iocb_for_write Date: Wed, 19 Jun 2024 13:53:52 +0200 Message-ID: <20240619115426.332708-3-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240619115426.332708-1-hch@lst.de> References: <20240619115426.332708-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Move the relock path out of the straight line and add a comment explaining why it exists. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index b240ea5241dc9d..74c2c8d253e69b 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -213,14 +213,18 @@ xfs_ilock_iocb_for_write( if (ret) return ret; - if (*lock_mode == XFS_IOLOCK_EXCL) - return 0; - if (!xfs_iflags_test(ip, XFS_IREMAPPING)) - return 0; + /* + * If a reflink remap is in progress we always need to take the iolock + * exclusively to wait for it to finish. + */ + if (*lock_mode == XFS_IOLOCK_SHARED && + xfs_iflags_test(ip, XFS_IREMAPPING)) { + xfs_iunlock(ip, *lock_mode); + *lock_mode = XFS_IOLOCK_EXCL; + return xfs_ilock_iocb(iocb, *lock_mode); + } - xfs_iunlock(ip, *lock_mode); - *lock_mode = XFS_IOLOCK_EXCL; - return xfs_ilock_iocb(iocb, *lock_mode); + return 0; } static unsigned int From patchwork Wed Jun 19 11:53:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13703746 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D8C713DDC9 for ; Wed, 19 Jun 2024 11:54:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718798079; cv=none; b=ShjyoTjAMzZkUVdgXCP+xk8GYRRbzJ+0Uy7rtZ7WnhoBybBAsaaPMR5eKZs9M0kp8I+jmgQ25Xa98qtuSE/gNYLiUY0wPdJhPADO4oJg3JN084trLvEDqOvaLN/P4BYUH9tCJXWEs5Wk27LIvvVONH74Q2QHBQDsEoaVEOsgrqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718798079; c=relaxed/simple; bh=NYHsJkLr6lrnXFHQppGIN5fg9scICb4UfHikRC6hIt8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DE54kKoOOrYK6SYBM7dNVChzketFpIpUySeXt3xc6szLswuhAz1RgGedpqAGnJeHtLX/YnBZstvKoiDSb67gDS/BxO74xIKfDu25XBMxeXTp5repYaVzCYgDxfTpSmwGgnF7VauOHDl7/eMaY9ctaPA2AzvMHuV4cRvX8ku7kJQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=WSY+XOXz; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="WSY+XOXz" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=qhMM1eIVGZWmjqGRAM5clmHZ0fIZ7OEUKRktm3o0LJg=; b=WSY+XOXz+bMryp083JWwSRO5oY WRZprbTJb/s0rufpfcoV7MjusbM5Ut3DW7QEQGhauwhmDaL4/yo6IW5EUUufABqFO/4/7pBXLTJQY nyNMC/WL++GCH28mL/Z54/CyIlt2TzrKxgsXEfYXpCxIOWAROCDETAo7jE2RrvRqAjAU910wEe93c DO0RMK97DlygXFoABaVQT7XrHwy93tteeY/I587zWy8M5qpNAPQkr5wzCVt3oU9AzU11nF5bsQKuP ZSFJZFbwdePA9E6bJT/3QK/mLQSTHZyLwUbZmzexjenh7ROZDqNBdP4yne+QrWouE0f7P9UBr9zeC Zzu5ONFA==; Received: from 2a02-8389-2341-5b80-3836-7e72-cede-2f46.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:3836:7e72:cede:2f46] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJttc-000000014Ob-2jYq; Wed, 19 Jun 2024 11:54:37 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , linux-xfs@vger.kernel.org Subject: [PATCH 3/6] xfs: simplify xfs_dax_fault Date: Wed, 19 Jun 2024 13:53:53 +0200 Message-ID: <20240619115426.332708-4-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240619115426.332708-1-hch@lst.de> References: <20240619115426.332708-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Replace the separate stub with an IS_ENABLED check, and take the call to dax_finish_sync_fault into xfs_dax_fault instead of leaving it in the caller. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 74c2c8d253e69b..8aab2f66fe016f 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1251,31 +1251,27 @@ xfs_file_llseek( return vfs_setpos(file, offset, inode->i_sb->s_maxbytes); } -#ifdef CONFIG_FS_DAX static inline vm_fault_t xfs_dax_fault( struct vm_fault *vmf, unsigned int order, - bool write_fault, - pfn_t *pfn) + bool write_fault) { - return dax_iomap_fault(vmf, order, pfn, NULL, + vm_fault_t ret; + pfn_t pfn; + + if (!IS_ENABLED(CONFIG_FS_DAX)) { + ASSERT(0); + return VM_FAULT_SIGBUS; + } + ret = dax_iomap_fault(vmf, order, &pfn, NULL, (write_fault && !vmf->cow_page) ? &xfs_dax_write_iomap_ops : &xfs_read_iomap_ops); + if (ret & VM_FAULT_NEEDDSYNC) + ret = dax_finish_sync_fault(vmf, order, pfn); + return ret; } -#else -static inline vm_fault_t -xfs_dax_fault( - struct vm_fault *vmf, - unsigned int order, - bool write_fault, - pfn_t *pfn) -{ - ASSERT(0); - return VM_FAULT_SIGBUS; -} -#endif /* * Locking for serialisation of IO during page faults. This results in a lock @@ -1309,11 +1305,7 @@ __xfs_filemap_fault( lock_mode = xfs_ilock_for_write_fault(XFS_I(inode)); if (IS_DAX(inode)) { - pfn_t pfn; - - ret = xfs_dax_fault(vmf, order, write_fault, &pfn); - if (ret & VM_FAULT_NEEDDSYNC) - ret = dax_finish_sync_fault(vmf, order, pfn); + ret = xfs_dax_fault(vmf, order, write_fault); } else if (write_fault) { ret = iomap_page_mkwrite(vmf, &xfs_page_mkwrite_iomap_ops); } else { From patchwork Wed Jun 19 11:53:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13703747 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27FD5137747 for ; Wed, 19 Jun 2024 11:54:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718798081; cv=none; b=j1blDQjdk/fgPr2xWRfDvjYneqQwUr+pOALsTuuGGW746wRBiLJ/KJasp2yf6ohRdXIVb5lbMiLZV14iGy/dN19U1uAlKdFUyeKGCh5YYIHPQAzy/mkFW3n/e+PT3UUVIz5c60cYjaKqgwuzp7NLCtclnQD4SHiRegl+NQbjh+g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718798081; c=relaxed/simple; bh=rGnbf4TGRGvU69TcU2hVgTBuVEXASjouSSCHPPmQvJk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TKZjO8tT7OP08DFbavgGre3JqLSnwAOzg+dq/c7bVWbg69jRmEZ1cvUSigZCPcw60hrNk9UJ2PavDSwvoI+7XXDL5EVn8YSSL2jv5ROfAHV5/z8qnXb934QdsenAnuL2UGYI0umDCia0V9vjVT6yRyoG+ZjvwpkgWxPDT+asJhY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=rgfogS02; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="rgfogS02" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=7KWC4NC8EV1alccP+zfG8a3lNmKfjXNnX3UeU5O++hc=; b=rgfogS02S6xr39Muo54rez/UYf iB6G07f0QeQJvZIbLhyr1nw7RkEHa6PJKHocDaHQCTKR2XQfG21b+TY8dXH1czbl0ReW2r18jKlcI QQO8rOBHMaNFGBpTOJbt8QaN/ingaBxTV4798uVaXYE5xGtNPpdFAJHm7RY9yCA4uA0IOnKqaa2Wo Fn33wAUHWA/yXn+mgl3Ibowzp1KhIogxeqeawdm9t1aV+a05+6WhXJRzjfpJdj39lIIw0xi50a9YG dNpgWt4ejlmorC+bcN7vF7Q+JMlfSk0xUvH/xpHW8rATDLLZtVd3ykbfRrdRqeoWRKzyIJ+GohHse lFzHzKWg==; Received: from 2a02-8389-2341-5b80-3836-7e72-cede-2f46.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:3836:7e72:cede:2f46] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJttf-000000014Op-1ZFu; Wed, 19 Jun 2024 11:54:39 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , linux-xfs@vger.kernel.org Subject: [PATCH 4/6] xfs: refactor __xfs_filemap_fault Date: Wed, 19 Jun 2024 13:53:54 +0200 Message-ID: <20240619115426.332708-5-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240619115426.332708-1-hch@lst.de> References: <20240619115426.332708-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Split the write fault and DAX fault handling into separate helpers so that the main fault handler is easier to follow. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 71 ++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 8aab2f66fe016f..51e50afd935895 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1252,7 +1252,7 @@ xfs_file_llseek( } static inline vm_fault_t -xfs_dax_fault( +xfs_dax_fault_locked( struct vm_fault *vmf, unsigned int order, bool write_fault) @@ -1273,6 +1273,45 @@ xfs_dax_fault( return ret; } +static vm_fault_t +xfs_dax_fault( + struct vm_fault *vmf, + unsigned int order) +{ + struct xfs_inode *ip = XFS_I(file_inode(vmf->vma->vm_file)); + unsigned int lock_mode; + vm_fault_t ret; + + lock_mode = xfs_ilock_for_write_fault(ip); + ret = xfs_dax_fault_locked(vmf, order, false); + xfs_iunlock(ip, lock_mode); + + return ret; +} + +static vm_fault_t +xfs_write_fault( + struct vm_fault *vmf, + unsigned int order) +{ + struct inode *inode = file_inode(vmf->vma->vm_file); + unsigned int lock_mode; + vm_fault_t ret; + + sb_start_pagefault(inode->i_sb); + file_update_time(vmf->vma->vm_file); + + lock_mode = xfs_ilock_for_write_fault(XFS_I(inode)); + if (IS_DAX(inode)) + ret = xfs_dax_fault_locked(vmf, order, true); + else + ret = iomap_page_mkwrite(vmf, &xfs_page_mkwrite_iomap_ops); + xfs_iunlock(XFS_I(inode), lock_mode); + + sb_end_pagefault(inode->i_sb); + return ret; +} + /* * Locking for serialisation of IO during page faults. This results in a lock * ordering of: @@ -1290,34 +1329,14 @@ __xfs_filemap_fault( bool write_fault) { struct inode *inode = file_inode(vmf->vma->vm_file); - struct xfs_inode *ip = XFS_I(inode); - vm_fault_t ret; - unsigned int lock_mode = 0; - trace_xfs_filemap_fault(ip, order, write_fault); - - if (write_fault) { - sb_start_pagefault(inode->i_sb); - file_update_time(vmf->vma->vm_file); - } - - if (IS_DAX(inode) || write_fault) - lock_mode = xfs_ilock_for_write_fault(XFS_I(inode)); - - if (IS_DAX(inode)) { - ret = xfs_dax_fault(vmf, order, write_fault); - } else if (write_fault) { - ret = iomap_page_mkwrite(vmf, &xfs_page_mkwrite_iomap_ops); - } else { - ret = filemap_fault(vmf); - } - - if (lock_mode) - xfs_iunlock(XFS_I(inode), lock_mode); + trace_xfs_filemap_fault(XFS_I(inode), order, write_fault); if (write_fault) - sb_end_pagefault(inode->i_sb); - return ret; + return xfs_write_fault(vmf, order); + if (IS_DAX(inode)) + return xfs_dax_fault(vmf, order); + return filemap_fault(vmf); } static inline bool From patchwork Wed Jun 19 11:53:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13703749 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9181813DDC7 for ; Wed, 19 Jun 2024 11:54:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718798089; cv=none; b=nx2M173OR/nFVnDig8/1OLYETOjCPpRgMfnvpmVU7P+WZ39JgIfLH7pkItcGYr1GG6jEH94KM/XdzcgdFvsc7lQ23y5vH8gtm1Ad3/6eSPkNT9bqIuFaNLjGmKMgYjD0dXxYXSm+JIyZQDZiZekNRcTVtaQp2lN61+2Zke2zFQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718798089; c=relaxed/simple; bh=EGuhpdQFTZDqOPgi604OcaZHbtU3I7M8UHTzKbJJ2Ws=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QGv/scfcV9baAuoi1RDhhKw6YzNUMDkkw/5qKzlAmTpIwdm0+BUhNoKreRyqlbwPr7+qaDekYTxNqjACUC0yxC2n3HgJcCLobCSjmUAS8VDHwkFw552w1M34D47y7JsC1d/XFnyezyJCExKMflL3gcgMbTEHD2Gobisw6VTbhaA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=QEZRA5P4; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="QEZRA5P4" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=dVkcFIKTnQqpP50J0F+2aXWkddNXrZdnZb1hiar8ji4=; b=QEZRA5P41x1hCC26ZahmVK4weR GbyOCLRqsC7oR2Lqmi8jxwICDr9/FXSF/r+ZaKg1M9clX1kXkeB4FJDwFfapa7ODPknHaDb6kLwcX eJclFglPLYfKQ7/Sk+LedSM0II129Mg7+saCL7F5OG9AzSLzpmLy4Hqfb6olJ8+WDPICyyYqd6x0l OFXByalbSLHpUHVpEMQzCbcfhAA4hWWOP3hxZWiOwDQDKeBzRYbWt6fSMRuBBaieT/cGnW4xiKP7H 9hhgACnQ/nFzrvSUBhsJmMnF2XGXESYPN39vyWXIr1Vh83uzWgeLsgkTKj6ZzARxaZi0umjMefmbL N3Crpzxw==; Received: from 2a02-8389-2341-5b80-3836-7e72-cede-2f46.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:3836:7e72:cede:2f46] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJtth-000000014Pg-30F1; Wed, 19 Jun 2024 11:54:42 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , linux-xfs@vger.kernel.org Subject: [PATCH 5/6] xfs: always take XFS_MMAPLOCK shared in xfs_dax_fault Date: Wed, 19 Jun 2024 13:53:55 +0200 Message-ID: <20240619115426.332708-6-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240619115426.332708-1-hch@lst.de> References: <20240619115426.332708-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html After the previous refactoring, xfs_dax_fault is now never used for write faults, so don't bother with the xfs_ilock_for_write_fault logic to protect against writes when remapping is in progress. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 51e50afd935895..62a69ed796f2fd 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1279,12 +1279,11 @@ xfs_dax_fault( unsigned int order) { struct xfs_inode *ip = XFS_I(file_inode(vmf->vma->vm_file)); - unsigned int lock_mode; vm_fault_t ret; - lock_mode = xfs_ilock_for_write_fault(ip); + xfs_ilock(ip, XFS_MMAPLOCK_SHARED); ret = xfs_dax_fault_locked(vmf, order, false); - xfs_iunlock(ip, lock_mode); + xfs_iunlock(ip, XFS_MMAPLOCK_SHARED); return ret; } From patchwork Wed Jun 19 11:53:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13703748 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02899137747 for ; Wed, 19 Jun 2024 11:54:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718798086; cv=none; b=X4h/3GouHcvgGHKfpUW90QQTQq9+ROuap2rhW9QHd41KwjebjZna9XroX80HkL5wYlec6idM+Q+f+TeCTOwJqjkXns5cYlrxf9DNCAk9Tx6KUq2Rm0KSzRf8I7E44ljTG8Rb0Zxf045wpMvox99dYkQgchP0in04H5uM3g7IHc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718798086; c=relaxed/simple; bh=DdtYINDZM5wGmVXu51JHWF6Anl5VtYuMryRZQnrB2xw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HcfDpXGlD+SqBWs9JZJItG+tuju7inHGD6HL9SQdPD2nldZ+F4EIh0aBlFUn977Fdv0gJ3b+QpZt0EZEP7H22TGQOJYDQ1HJweQV0ppiUbcmRksx01CUVZOuDNBlCvbWnpMPod9SCEbHtF8eiijeq1L2dBuQ4b2b2fdrR1eEBH8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=XrXlPZxK; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="XrXlPZxK" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Suebk8GsbhsPBL6Nuhd26f4hiVv4BZ2QhO/e8BDsq+A=; b=XrXlPZxKGY/m/YKSjNnOHLObcd xWcSa4P6RkUaOPXnUPVKyD9Ydb7GmldlwEUFklfvvdQ0VyimOvuwAXkqNRtmwBsZe3zSds9PjH7sT Yf+rLN+D50zyvs+x7c2bfi0JXpFu/GmHCFNMWCNZsvpQoofjZ8bw5ayQIlpuHctgAl4PUJWNOE2Ze qtBuHvP1QxzbwJPbFut32ni/RJ35jbLg8PEoYUCAR0702x3kqZ1r/MDfVzmK3pdCBqfhQniKd/PdS srRWQ1vpg20fC+cXRcQA6YqOpOmn8PS32dNnmxM783Jk37Uw4F8sILHgJlxNzkUEXLxBXkdcWB0Xy OPLxDzew==; Received: from 2a02-8389-2341-5b80-3836-7e72-cede-2f46.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:3836:7e72:cede:2f46] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJttk-000000014Qr-1D3i; Wed, 19 Jun 2024 11:54:44 +0000 From: Christoph Hellwig To: Chandan Babu R Cc: "Darrick J. Wong" , linux-xfs@vger.kernel.org Subject: [PATCH 6/6] xfs: fold xfs_ilock_for_write_fault into xfs_write_fault Date: Wed, 19 Jun 2024 13:53:56 +0200 Message-ID: <20240619115426.332708-7-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240619115426.332708-1-hch@lst.de> References: <20240619115426.332708-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Now that the page fault handler has been refactored, the only caller of xfs_ilock_for_write_fault is simple enough and calls it unconditionally. Fold the logic and expand the comments explaining it. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_file.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 62a69ed796f2fd..05ea96661c475f 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -227,21 +227,6 @@ xfs_ilock_iocb_for_write( return 0; } -static unsigned int -xfs_ilock_for_write_fault( - struct xfs_inode *ip) -{ - /* get a shared lock if no remapping in progress */ - xfs_ilock(ip, XFS_MMAPLOCK_SHARED); - if (!xfs_iflags_test(ip, XFS_IREMAPPING)) - return XFS_MMAPLOCK_SHARED; - - /* wait for remapping to complete */ - xfs_iunlock(ip, XFS_MMAPLOCK_SHARED); - xfs_ilock(ip, XFS_MMAPLOCK_EXCL); - return XFS_MMAPLOCK_EXCL; -} - STATIC ssize_t xfs_file_dio_read( struct kiocb *iocb, @@ -1294,18 +1279,30 @@ xfs_write_fault( unsigned int order) { struct inode *inode = file_inode(vmf->vma->vm_file); - unsigned int lock_mode; + struct xfs_inode *ip = XFS_I(inode); + unsigned int lock_mode = XFS_MMAPLOCK_SHARED; vm_fault_t ret; sb_start_pagefault(inode->i_sb); file_update_time(vmf->vma->vm_file); - lock_mode = xfs_ilock_for_write_fault(XFS_I(inode)); + /* + * Normally we only need the shared mmaplock, but if a reflink remap is + * in progress we take the exclusive lock to wait for the remap to + * finish before taking a write fault. + */ + xfs_ilock(ip, XFS_MMAPLOCK_SHARED); + if (xfs_iflags_test(ip, XFS_IREMAPPING)) { + xfs_iunlock(ip, XFS_MMAPLOCK_SHARED); + xfs_ilock(ip, XFS_MMAPLOCK_EXCL); + lock_mode = XFS_MMAPLOCK_EXCL; + } + if (IS_DAX(inode)) ret = xfs_dax_fault_locked(vmf, order, true); else ret = iomap_page_mkwrite(vmf, &xfs_page_mkwrite_iomap_ops); - xfs_iunlock(XFS_I(inode), lock_mode); + xfs_iunlock(ip, lock_mode); sb_end_pagefault(inode->i_sb); return ret;