From patchwork Sun Jun 23 05:44:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13708504 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 40A019449 for ; Sun, 23 Jun 2024 05:45:08 +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=1719121509; cv=none; b=sD+zYsYaDpPG1qjQKXr2EYgIwuyScch6QFNmYjBngmBKkjLp6ztF7yh98HZGUPTUdJ0fSIJAVNACKakKYHqedcFuUAJUZMqN7p9AeZjS3pKcQxTsa/2sL5RWIv7MJYcpYP930tyX1cqjaFSNwmQAv/Cv3rAseDGVtO9EcQwXXY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719121509; c=relaxed/simple; bh=vaAA9XvyuWxF4knMeKVBbmEbZKOWphpksTCIyYXIzXg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d7W9uPbghsDO1Nibfdg0DW9x3wj9mj2Wp5agzg+o+7UaHHLMKfs0nRqo4HwunPNkozI0LmvkGSYQNZamzyxNk/gSyUMKd+HYg3Tsk5H1906monIYBr8qmmbXghTBADYx9VNOUbZgyb/euZqLJXX7kQ78MjRmIf5az4zyO/nVP2Y= 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=KSRdudax; 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="KSRdudax" 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=o/2QpST0cpNGMzSW3x8tyyn/8UmZN7hZdrDy13O3Bkc=; b=KSRdudax+ge3PWj1s3cfiCDoHl ppTq+Rl+ODlYwyXkien0StUqHpTmhV53XkLJxk0F0myue5kEblOtDKsVzPfTwM2kIFrlvA4AgRHFp RnRpzsAuVdhmHwzSSND8oAadhqA37aVOKlwPrc6a6kZCQHUtgYdWpHvbJUVr5K19P4rB3JydDTaQ3 DLOGiWU5MyRGDlg+a3flOz/yssXqI7ejokiyQLH2J6bH8hxi6UNIww7HhhsPlceZpcbZJ4vP+pB/8 msh5+KsCC9DejPfyzglFfdhA0aZ9ciI/bIYoGZInaLNv/NJVvRmUSMARQcwUtouM7mjAx5Cata98u 723MiXGg==; Received: from 2a02-8389-2341-5b80-9456-578d-194f-dacd.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:9456:578d:194f:dacd] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLG2F-0000000DPA9-11hQ; Sun, 23 Jun 2024 05:45:07 +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: Sun, 23 Jun 2024 07:44:26 +0200 Message-ID: <20240623054500.870845-2-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240623054500.870845-1-hch@lst.de> References: <20240623054500.870845-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 Sun Jun 23 05:44:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13708505 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 017402C95 for ; Sun, 23 Jun 2024 05:45:11 +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=1719121513; cv=none; b=BfnyRXH52fSFAjszJf3WboDW7KUOklfR3CJKynKnAzUsoZWubLVqM5bysoRAxj8Z247jpwm6G8iEbos47CMcX9OUjYxw/3wmyrBsRc9dyvQouFP4lOoA7+A7zsSmiGw3qnA0w3lmGwzrZAh6tHLsHcNX+NSSE3tMwDBWTKCLq/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719121513; c=relaxed/simple; bh=ssiZXCqjvR9877bUwiW7RYByfjxy34Pv6MKMmvlnfHE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f37EKx8QjU1ax5sExFhHcPI9chje/+/OWmxQHE4/jL0LyJp+K6gNDCFuHoAW3ZMH+C5LrLa3G+/tmnjL4+4Y8/11BEfn/CCZd1Xp+f5pPfyMrecTsRJRFUcDZwEuxGppf+4KUIOdw8YcMF+N+r50D3GpW8gJSG14U71NNg5F18g= 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=amElSbGk; 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="amElSbGk" 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=M+3l+uJ7AeC8KrjOJFtGhs/AjKRbHQh6XXjOJ6DOAk4=; b=amElSbGkEqIPnY8jXE21z0t/bm r8yJjhJt3CkHDURKv8OqSsiKFVGIvAmJeGyYOvQTMgvQtd4bW/X3auE6eKlKeKZz1lBpE4+Yl4pmy rWOFoNfoRe+MZZ4FP9h5nWCONKbeeE0ezc0Sevi97sak57pXfJwOjT7gCWGxPvFiGsIxi+6WPe6W3 s/Z2kxtOqaKKH0T9yd3m+UUj6511ACLl4t290+vIcrD6OXHmyeGSnoYSCguYpiPhht0Etmag83Ia5 SnpGk/ofRW3KP7qLgkwBPK/xARb4CFk9rkv0v+9rNtTMHnIvt7ZX2yfYKZH0fDtdX5q5jeZ8ROZoq yG3hvjOg==; Received: from 2a02-8389-2341-5b80-9456-578d-194f-dacd.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:9456:578d:194f:dacd] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLG2J-0000000DPAM-0W9i; Sun, 23 Jun 2024 05:45:11 +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: Sun, 23 Jun 2024 07:44:27 +0200 Message-ID: <20240623054500.870845-3-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240623054500.870845-1-hch@lst.de> References: <20240623054500.870845-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 Sun Jun 23 05:44:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13708506 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 456A9171BA for ; Sun, 23 Jun 2024 05:45:15 +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=1719121516; cv=none; b=E9EG1KRrC4wGN5HA6GOXAsxh4D2EsIhh20KW5d6vxDL2u9St0E7rrXoYQAuka6XYq4+u1j2ZQCovomQXvaHvt7zfvlGXFYoGipq19UUIZhYDiw6Qf944p+K+fu5IFylLTW1CBrZOhhLbu4n+Qy83gvuwP3eDi5pV+OvnCoWx2a8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719121516; c=relaxed/simple; bh=IfrfXNVlkHw3h6dPBlfVsysHBvPLyGnqHKwqPd3Rbuw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oQg7mBBzliENKKi5ZKL2xo0GO9FQgIaKQndmIWSunGAtiTiym/qM3ifLr6CuUwH2gsiSoR68V17FL8XRoLAKLJDnYnnqUwqLuHc09A1Ujqkk6Omkf6+pkljuGcfGV/Xy0cW+Ra+3b/smSOGQXmqBQesA89JzEcp45Tx992Lde7s= 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=JlxLP6bv; 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="JlxLP6bv" 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=UsFb63tZPxtvzIqQT+D+barxuGiCTisIO/VgusjO6vI=; b=JlxLP6bvNFv3YD23WGYzyfQtIl +57JxAxJ7Q/uQuAFXrHmXoXEOLBunr6T3hkzpinONRmq2mX8xq+heizJjb2xCoyV+Du1Qlhp3VuES w5bW8nEADpOfsGNCd9lWWbnXRQMybsXEcICmTuegu3Txp6oX5T7jEw/0wE491RigFLKZf8pFGoflU zzrUrlPq64Orq4DaoPBdEXcEo+JA+VhNaiJc1Q/acB8zPGv+2V8HKuNFmaNIFfJ0KDxDGiCFC7KAI uJbdMHjHYPfMs6yrFAiUmcqr1KF6CaUA6tf1fErF2wT9UOlpfzwnbmmGnATWu0tPpjV+s9Sw5uaLy fl4Ghd8A==; Received: from 2a02-8389-2341-5b80-9456-578d-194f-dacd.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:9456:578d:194f:dacd] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLG2M-0000000DPBK-12E4; Sun, 23 Jun 2024 05:45:14 +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: Sun, 23 Jun 2024 07:44:28 +0200 Message-ID: <20240623054500.870845-4-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240623054500.870845-1-hch@lst.de> References: <20240623054500.870845-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 Sun Jun 23 05:44:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13708507 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 CB308171BA for ; Sun, 23 Jun 2024 05:45:18 +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=1719121520; cv=none; b=P337y9r4oFaBIcg4dcIlKUiC0vjhCj1dZRwg+crESdD30lpuMV2QZSO5K8QWM57RR+h6Zj6uEuYJttBJXp97dVIVlICP0sCxHX/YnjYsqPujfzm8ZQDwQo8jqz3fp4Q+7jWP8US4Dv9ZLlt93ukBTEG1xp/WIlYxrARyS3fCKzk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719121520; c=relaxed/simple; bh=fiXOdvrAocMnKIbbJ10/yECMN3FsLrXYhmg3ZwPiGD8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gfFFqfuWLXzLpXm4CHC+yNjP9ig1Fv6zL2dpQnFnYqiyKc8JJwy48+xJofgQbKdQkuFrOuvuz66jJ4eYFILKEhn1Dgy/X0vhkvAS1s8S/JZKsVPBiEtfkHL8eUkzHUrAGMNCxprgC2ZWnws2j2Ie9UHQk+bqnCEnsJ/MobTyBG8= 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=WqPPsI3V; 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="WqPPsI3V" 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=FPR1zaHaaa+XSLa0TuT2+/UYYh1mDdxBGunH+sOMvOc=; b=WqPPsI3VCLO4n4dLBET53oR7yn exMoJaTwNNFMH8pEUa/JXNEZ+rJUQd7okvwUn/+sl0wnZ2wQdkvvO8duu9v1zox40CdLkFL4wAdOJ QziqXLmMXzCPnNYOxxk46ITw53Lq1ct5hWjhYNSOhBTFWQ/P8qUWmzt3Y+BzP+bhqOebGvn6NMg23 sK4i99ORujE6wPhJn8tTDZ0AUN6RVLo9KS8rkouJW5sF+5zdCfxgvtn/15Eee8M9MoFQWrqI5KB22 lCTxlJ+izgkAEkaUJ+ZnIIVYF2bdn1sPA5lLQ0KvNenzyZnRX3l/1Vs6tuG4EnP8w2V4j7PleNjH6 p8pPyPrg==; Received: from 2a02-8389-2341-5b80-9456-578d-194f-dacd.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:9456:578d:194f:dacd] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLG2P-0000000DPBl-3HYF; Sun, 23 Jun 2024 05:45:18 +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: Sun, 23 Jun 2024 07:44:29 +0200 Message-ID: <20240623054500.870845-5-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240623054500.870845-1-hch@lst.de> References: <20240623054500.870845-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..32a2cd6ec82e0c 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_read_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_read_fault(vmf, order); + return filemap_fault(vmf); } static inline bool From patchwork Sun Jun 23 05:44:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13708508 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 AF2EA7FD for ; Sun, 23 Jun 2024 05:45:22 +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=1719121523; cv=none; b=m7fyfwNm5/Strmzsllmd40TCgjM9PwcBERiEgfXFvaXu+CVY1UzS0rqnmD5s23k1T2KgRhfqd7m/2g+2u4wTyv3jUa+HFIA5N9DLKqe1oiicHSXgut6PcGyuA9MH1c56C8bKdck97tDDhc0/KFEKniVthdRKnDahsj30QpGrCxI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719121523; c=relaxed/simple; bh=78rOk0bTZ/+ajJlOV7k9gQgik1ItjXExgY28H3JXj8A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=geqiQyeriBWCBkVOZBZaG5hnN65zm5SwQ7J9pV/RqTI7DgPY9qjdseoxAuDm7wHhV6k1heOp9R1SXTzwYGa1cY4bVWqLuRkKpTXqbiyYubDnt8iGwhONCUTzEq025h9aw17nSTAMPW8R2gLGMarEINoj8oo7zYcSBGsodk1xln8= 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=ZDw0hTQc; 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="ZDw0hTQc" 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=+r6nVYMtFUMzJmp44iM5boDw4bE05fN7Vmvv1yNGPTc=; b=ZDw0hTQcZjYe1JQFr7V6WIZP1l blI0C6NgmFG8RY8Y11WLxbGwV1MDFvfUhq6xihBeRJ5y2lkr6OUDqBbETFrMrZrnpLKLyc1nVLNlZ ApyCQwL/CCnY+whti02oBWjlsQIczEMkSB1WIRYOZ5lUiWilS3UGaa0Y0z07IIQziJKWb4+7rNuWc ptQ4ixcoUdFXLXdbE75INlketdADyB+7XZRp+lp5Xwjz38NOgxm15kSKYaMfjLGkFWVx0rNG0FnpX YTQlzTyf4E1RrNoZCyGcYEkzjHqEeypiwY8k2Ck9M4WGfV2+e9/cGOWGLMbzg3+ECK6HdwkWLTC5h 1T7PGmcg==; Received: from 2a02-8389-2341-5b80-9456-578d-194f-dacd.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:9456:578d:194f:dacd] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLG2T-0000000DPC8-3FDU; Sun, 23 Jun 2024 05:45:22 +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_read_fault Date: Sun, 23 Jun 2024 07:44:30 +0200 Message-ID: <20240623054500.870845-6-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240623054500.870845-1-hch@lst.de> References: <20240623054500.870845-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 32a2cd6ec82e0c..904be41f3e5ec6 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c @@ -1279,12 +1279,11 @@ xfs_dax_read_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 Sun Jun 23 05:44:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13708509 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 DD3A71426F for ; Sun, 23 Jun 2024 05:45:26 +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=1719121528; cv=none; b=djeqZfnLsrS5mpuc97mQIO94rx5Rlrv68qp15Mw+iidk6A5nGCPpG0ppXFyZ9aPscBOSBkEf5YxNCmPkzW9OS+n/xZVgdUXF8u3PB4RX7oZYXi17GT/JfIKdLQksiI6OT63kTjojyAY5Z7GTB++dUMBn+nxTZwFWP9CbnKPoybs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719121528; c=relaxed/simple; bh=qI5IJEZpK7EDSaOEHypG9qihcPi/gmlPWYMN0pY8pcU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uf2M2KAxn4WQkCOPZs9wcsQZeAPuPROHOncieHt7IqlbcXKD2pxyU/5ea8+PD3PMfwdYZMteKVMByWUVEVrd/eYqN9nTrY49jmou/5DPa+BB0H1NH5kiHkes+0Wh+3HWXEMKgb3odOuwUbefxa17jLEFr5bIdB1MNNOmd8unWKU= 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=DaVJPTXe; 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="DaVJPTXe" 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=s99uInmJKiAfMUcHDZCZHnsJgTIBTtv0d9iH6mT+aW0=; b=DaVJPTXeV3A2b4gzlMNCMbJ6B9 JMsaKm871YN5hw0imhAIiBN2iwJqg4E69HvIiLhW/qAKqAXINz7DWl/fU/CnpvkwufP5G39+aVwvR Fw36hyFSogkChX92Zcn82MK6hJSWRSuLSNVfUEeW33DwK8so3FHp40R3Vf4SUVFiJ5bfhkLAOjKvl X7xQZreSW7guY4z1jqHI0WP8PP47yZhc9QqFqUqW0MCe2upR/w4xHD9632S8IxbTHe5UMLeC30JWs i2n6CKOg5usXXA0CqXIbiAWoKrhA/XC5XFqtuHtmSguvDLKSlKqrfP3mRJkEbwqshUrCvoxksJFwH 2EUMpzDw==; Received: from 2a02-8389-2341-5b80-9456-578d-194f-dacd.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:9456:578d:194f:dacd] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLG2X-0000000DPDP-44JJ; Sun, 23 Jun 2024 05:45:26 +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: Sun, 23 Jun 2024 07:44:31 +0200 Message-ID: <20240623054500.870845-7-hch@lst.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240623054500.870845-1-hch@lst.de> References: <20240623054500.870845-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 904be41f3e5ec6..4cdc54dc96862e 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;