From patchwork Sat Dec 7 00:03:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898088 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 BB4512A8C1; Sat, 7 Dec 2024 00:03:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733529817; cv=none; b=VkhIBx8BnQIsXgJgG7gSFpPmJvUFe8RipdyMtGEVVYhRHDOVJcd+t9JmfcQ+Di1RZEuoeYAGEZgcr2Y0nGwIH+Ab6TK5Gq1a6gUE5eC2JFkfDwF8M8F7ViiIU8OosnZ1X8y9PlGgGzJl+f/9K5EQGfWsJ0XHhY3E/SsKL+zk63E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733529817; c=relaxed/simple; bh=Fy4iqRobx8evseMbf4CjhAQEVkhVopkrBmfUcRgRoOM=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RUiYG3OitrSVCyak6o5VaM6eHojjsUYRd3EeJcH0qMg0HeDPscQ/iinGzMreAZfirOPM526PQCgHXRhupYHNU9jkGLxG8oLtkYh6cAYmhOGOpJwnD1tmyTdfjFGxcuu059g1c9EFODVKoyXapxegshC60tyVwu2hirrbiFilOns= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s7PXeLEI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="s7PXeLEI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99254C4CED1; Sat, 7 Dec 2024 00:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733529817; bh=Fy4iqRobx8evseMbf4CjhAQEVkhVopkrBmfUcRgRoOM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=s7PXeLEIr5zR1aufhknuoHIJV66pfLzY0pmzD0gFsgQ+6Kdsp5tc17XZl/FSdCLKV hCuvnGBFiIGmQMmqjouZP1jVqIHlvpb4XjUTTpCp1KUjyDvuodL4ql4ri3zDnof7m1 DSyPHQxqhlnwx6Rc9ZcoZOMsXIaEjSglFe+6Hay5aC36stK2Ui/VuqHI3hnWMUo74a 1pj+X9iL383oQoGL5giCgU8fkBTzhDj/KXEqDiCsd1LzPJ66eFcJjPOWU6A7JYJBsu cilx5LoGJWGF6gZNYuT8beuCpkAhX3h4L9Suvp41G3wOL9Wr6/ksQ4oGrL6tH6ZHHW 7FspdgEaWnGEQ== Date: Fri, 06 Dec 2024 16:03:37 -0800 Subject: [PATCH 1/6] xfs: return a 64-bit block count from xfs_btree_count_blocks From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: stable@vger.kernel.org, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352751213.126106.11484272025980381078.stgit@frogsfrogsfrogs> In-Reply-To: <173352751190.126106.5258055486306925523.stgit@frogsfrogsfrogs> References: <173352751190.126106.5258055486306925523.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong With the nrext64 feature enabled, it's possible for a data fork to have 2^48 extent mappings. Even with a 64k fsblock size, that maps out to a bmbt containing more than 2^32 blocks. Therefore, this predicate must return a u64 count to avoid an integer wraparound that will cause scrub to do the wrong thing. It's unlikely that any such filesystem currently exists, because the incore bmbt would consume more than 64GB of kernel memory on its own, and so far nobody except me has driven a filesystem that far, judging from the lack of complaints. Cc: # v5.19 Fixes: df9ad5cc7a5240 ("xfs: Introduce macros to represent new maximum extent counts for data/attr forks") Signed-off-by: "Darrick J. Wong" --- libxfs/xfs_btree.c | 4 ++-- libxfs/xfs_btree.h | 2 +- libxfs/xfs_ialloc_btree.c | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c index 3d870f3f4a5165..5c293ccf623336 100644 --- a/libxfs/xfs_btree.c +++ b/libxfs/xfs_btree.c @@ -5142,7 +5142,7 @@ xfs_btree_count_blocks_helper( int level, void *data) { - xfs_extlen_t *blocks = data; + xfs_filblks_t *blocks = data; (*blocks)++; return 0; @@ -5152,7 +5152,7 @@ xfs_btree_count_blocks_helper( int xfs_btree_count_blocks( struct xfs_btree_cur *cur, - xfs_extlen_t *blocks) + xfs_filblks_t *blocks) { *blocks = 0; return xfs_btree_visit_blocks(cur, xfs_btree_count_blocks_helper, diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h index 3b739459ebb0f4..c5bff273cae255 100644 --- a/libxfs/xfs_btree.h +++ b/libxfs/xfs_btree.h @@ -484,7 +484,7 @@ typedef int (*xfs_btree_visit_blocks_fn)(struct xfs_btree_cur *cur, int level, int xfs_btree_visit_blocks(struct xfs_btree_cur *cur, xfs_btree_visit_blocks_fn fn, unsigned int flags, void *data); -int xfs_btree_count_blocks(struct xfs_btree_cur *cur, xfs_extlen_t *blocks); +int xfs_btree_count_blocks(struct xfs_btree_cur *cur, xfs_filblks_t *blocks); union xfs_btree_rec *xfs_btree_rec_addr(struct xfs_btree_cur *cur, int n, struct xfs_btree_block *block); diff --git a/libxfs/xfs_ialloc_btree.c b/libxfs/xfs_ialloc_btree.c index 19fca9fad62b1d..4cccac145dc775 100644 --- a/libxfs/xfs_ialloc_btree.c +++ b/libxfs/xfs_ialloc_btree.c @@ -743,6 +743,7 @@ xfs_finobt_count_blocks( { struct xfs_buf *agbp = NULL; struct xfs_btree_cur *cur; + xfs_filblks_t blocks; int error; error = xfs_ialloc_read_agi(pag, tp, 0, &agbp); @@ -750,9 +751,10 @@ xfs_finobt_count_blocks( return error; cur = xfs_finobt_init_cursor(pag, tp, agbp); - error = xfs_btree_count_blocks(cur, tree_blocks); + error = xfs_btree_count_blocks(cur, &blocks); xfs_btree_del_cursor(cur, error); xfs_trans_brelse(tp, agbp); + *tree_blocks = blocks; return error; } From patchwork Sat Dec 7 00:03:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898089 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5B039196 for ; Sat, 7 Dec 2024 00:03:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733529833; cv=none; b=FhEbgwE/ADYkTnxnfo0hZ4NsbIfB1k5A+v+XF0WP8lusDxYXpmnsZB7YapMw6cDH9QueE5+W5zrzLbxJPRWWJfUzyzlNdHAEKXZIXA06JUIpY6r6hjh8WtAEpzLI9ir+C5wmVTHezRdjsgZWpo/9ydvM0we4IsnsIsBSCDoGkUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733529833; c=relaxed/simple; bh=n6LwDZlESYIlO/JutBqcqmz2/VNgCaQ3r7l4pr5XZ2o=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VgE6vd2kOYvnPXqJ3gAd7EULx+bQq/S2SgvSDEs64KccaKM3BQvXCv9kXhxkj24noCVS42fo1KdaiCpIoUDnX12J06Mk97WVQ6pIXFVM0HlTldpAebrOtV2W5L30dSqz6I6AyfZ74oo7A7ew+H/yHXQ8dlu2PkttEx4e+HfaZoE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qDqTERLF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qDqTERLF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37EFAC4CED2; Sat, 7 Dec 2024 00:03:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733529833; bh=n6LwDZlESYIlO/JutBqcqmz2/VNgCaQ3r7l4pr5XZ2o=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=qDqTERLFo12MwOmxiS0P8IEwoaJ3IRhOgho73r3O1nMLecnmfj2aEQ5mKPl75Fy7P MytblSEv+gI1aY+aQG6UxoVIgiyCjBLi9A0P1G5U34Yqtp96lVTPQwlFsc/Z28kKVH jdX56uC1AZZkv4xe125Am/xbZjg0TVCwN3f7mIWZraHYPgzDpK7nhrK40CCr6A19d1 97slt1vWK8OTgt2uRJa32V+hET+8Ca9k6m1T38zvPSpx6TluPCPQJ4ARpiD3qJrmIk ViFy/iUidHqSAYtkwAbHBGptKs2T7l0pS8gJiFlKJCabG/o+5WjCRRy5wU08NwomQk YSx9bocP99tRA== Date: Fri, 06 Dec 2024 16:03:52 -0800 Subject: [PATCH 2/6] xfs: fix error bailout in xfs_rtginode_create From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: dan.carpenter@linaro.org, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352751229.126106.6830567491969634308.stgit@frogsfrogsfrogs> In-Reply-To: <173352751190.126106.5258055486306925523.stgit@frogsfrogsfrogs> References: <173352751190.126106.5258055486306925523.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong smatch reported that we screwed up the error cleanup in this function. Fix it. Fixes: ae897e0bed0f54 ("xfs: support creating per-RTG files in growfs") Reported-by: Dan Carpenter Signed-off-by: "Darrick J. Wong" --- libxfs/xfs_rtgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libxfs/xfs_rtgroup.c b/libxfs/xfs_rtgroup.c index 8189b83d0f184a..aaaec2a1cef9e5 100644 --- a/libxfs/xfs_rtgroup.c +++ b/libxfs/xfs_rtgroup.c @@ -493,7 +493,7 @@ xfs_rtginode_create( error = xfs_metadir_create(&upd, S_IFREG); if (error) - return error; + goto out_cancel; xfs_rtginode_lockdep_setup(upd.ip, rtg_rgno(rtg), type); From patchwork Sat Dec 7 00:04:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898090 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F2E4A139B; Sat, 7 Dec 2024 00:04:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733529849; cv=none; b=YccOfWxVbZRDZRLf77gJOZuZxSNHDSUeuDOCQ9kRHyB+s3h6C91QkSnAqptHV2wZ5a/SHs/KGMVfWDjKDFFELQ5NT3a/dTQDUldhv+pXRVT/hC/M6qy1NX6a3M4Eng+x0dkyBdiqmQAIF5B1sD2BNe30o5L5i99wHWmWrPxfLrg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733529849; c=relaxed/simple; bh=XcSmG1DDmIoBwBMa7DfIzTntQFdzableBCgb8sgrhc0=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=S/5rfXEG25O7kagrxhfWdCsXzYt1Ci83fbb6/m8T1DAKXwC8NRenLkXuXRk/drsOCotXecTV+x3z5/TbwTPl3shPeDr5XQ5aY+Q6rOgWlAr94uKeFbNwF7RCCvgA6Tg0fDvO2+9OJeDPE06L7JxF4vCJezpbb1GYMPo+oM27u7g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YnT+O1g4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YnT+O1g4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8516C4CED1; Sat, 7 Dec 2024 00:04:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733529848; bh=XcSmG1DDmIoBwBMa7DfIzTntQFdzableBCgb8sgrhc0=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=YnT+O1g4snN2boy/tQWXqEhrETMlGg1xdpBFpM6cdFETCkrn1h1niYYezSQWcMT2L Y5aO/SkvRI3KQ5xreo+mRegLsqgQ9BIFlPLYcNEF+DqUnRHFTctdY7GCeMg/URDBUL fLbRWKHbN73Ve8Ri12trwHVMp2/SsnNf6DIwvZW2lVFHx9eslGLFVXtFavfNOHdOyJ cVfxtlSAaPcMz9E0TfAiD6F6ctEhAfuY2e3e0KanHTZKfJ/3wLPrO/2ZAMNjqnmK9t QNKV8th3eWy4oK0IiQFzqm9xUA9fmMZbe3Livmt8LpfycX4P0vzDskhyZUnhfKFz04 Jnem5gs4fUiLw== Date: Fri, 06 Dec 2024 16:04:08 -0800 Subject: [PATCH 3/6] xfs: update btree keys correctly when _insrec splits an inode root block From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: stable@vger.kernel.org, hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352751244.126106.16426037647903930309.stgit@frogsfrogsfrogs> In-Reply-To: <173352751190.126106.5258055486306925523.stgit@frogsfrogsfrogs> References: <173352751190.126106.5258055486306925523.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong In commit 2c813ad66a72, I partially fixed a bug wherein xfs_btree_insrec would erroneously try to update the parent's key for a block that had been split if we decided to insert the new record into the new block. The solution was to detect this situation and update the in-core key value that we pass up to the caller so that the caller will (eventually) add the new block to the parent level of the tree with the correct key. However, I missed a subtlety about the way inode-rooted btrees work. If the full block was a maximally sized inode root block, we'll solve that fullness by moving the root block's records to a new block, resizing the root block, and updating the root to point to the new block. We don't pass a pointer to the new block to the caller because that work has already been done. The new record will /always/ land in the new block, so in this case we need to use xfs_btree_update_keys to update the keys. This bug can theoretically manifest itself in the very rare case that we split a bmbt root block and the new record lands in the very first slot of the new block, though I've never managed to trigger it in practice. However, it is very easy to reproduce by running generic/522 with the realtime rmapbt patchset if rtinherit=1. Cc: # v4.8 Fixes: 2c813ad66a7218 ("xfs: support btrees with overlapping intervals for keys") Signed-off-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- libxfs/xfs_btree.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c index 5c293ccf623336..f4c4db62e2069e 100644 --- a/libxfs/xfs_btree.c +++ b/libxfs/xfs_btree.c @@ -3555,14 +3555,31 @@ xfs_btree_insrec( xfs_btree_log_block(cur, bp, XFS_BB_NUMRECS); /* - * If we just inserted into a new tree block, we have to - * recalculate nkey here because nkey is out of date. + * Update btree keys to reflect the newly added record or keyptr. + * There are three cases here to be aware of. Normally, all we have to + * do is walk towards the root, updating keys as necessary. * - * Otherwise we're just updating an existing block (having shoved - * some records into the new tree block), so use the regular key - * update mechanism. + * If the caller had us target a full block for the insertion, we dealt + * with that by calling the _make_block_unfull function. If the + * "make unfull" function splits the block, it'll hand us back the key + * and pointer of the new block. We haven't yet added the new block to + * the next level up, so if we decide to add the new record to the new + * block (bp->b_bn != old_bn), we have to update the caller's pointer + * so that the caller adds the new block with the correct key. + * + * However, there is a third possibility-- if the selected block is the + * root block of an inode-rooted btree and cannot be expanded further, + * the "make unfull" function moves the root block contents to a new + * block and updates the root block to point to the new block. In this + * case, no block pointer is passed back because the block has already + * been added to the btree. In this case, we need to use the regular + * key update function, just like the first case. This is critical for + * overlapping btrees, because the high key must be updated to reflect + * the entire tree, not just the subtree accessible through the first + * child of the root (which is now two levels down from the root). */ - if (bp && xfs_buf_daddr(bp) != old_bn) { + if (!xfs_btree_ptr_is_null(cur, &nptr) && + bp && xfs_buf_daddr(bp) != old_bn) { xfs_btree_get_keys(cur, block, lkey); } else if (xfs_btree_needs_key_update(cur, optr)) { error = xfs_btree_update_keys(cur, level); From patchwork Sat Dec 7 00:04:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898091 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 E4644196 for ; Sat, 7 Dec 2024 00:04:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733529865; cv=none; b=fSNKYKPdtaj8EDVfvpZQzYNuEqBQMY/dXMqXEiiwP4uFMP9sw0kuBlTy+jb1TXzqv++2yvCDN6iw8W0Me+WIemhyJuaYWKnjkI6nZxlywEyHw0IX7DXl/bHy048Yhg7oQ13HBu6KsBjGf5Sk6okNKdAQ796U2BLWQCJFpzATEzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733529865; c=relaxed/simple; bh=/OraPJtyhNBbqUzkSPSuZA/HGBJEqT5hh7WVcU8sGYQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jL8gIGgkPRtyZGQyxF8pRRQWdOvPE67K/qHYPIeCfbFWv24Ta9yigQTRSJ/DIRQ7oODmmXc2CjmuGu+OlVbP0NJzn2GF3qDo4ih/+0DwcRqFVg8oj28QxrmGQdFgiaDGLT318bNbyNMRYEokDwTGtwZcXJaIZNEUs9hFR4IGjXs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CZY0gGAT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CZY0gGAT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67F50C4CED1; Sat, 7 Dec 2024 00:04:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733529864; bh=/OraPJtyhNBbqUzkSPSuZA/HGBJEqT5hh7WVcU8sGYQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=CZY0gGAT3ytMNA6Sc3c8CPQ4cnfrbu04gEnSoAS4hT+E74pHhsW36VI4ZA6L1D19a 8lo/uC+55wd6sdH6uVueW/hEc0j0dnvMWFl4hJKpghv4On7uGeH5mqNElOIopv1fTt x3F442aQJyzDYfIczwy+Ltu8N5dEf/jm1AZWtB2b2u4/35sQlVvVl1wyKTdO4326F1 RnRwQL7nKiXu1f1J3hvmWf5TeosILcOPQxwgr2ispWAhjAaQk8NRN5xgaCpGH9wugB CwR1BLLrGpTrp0k0BJoswT9EyPvJXFnV6Cr44AMO410BSnEASFf+O4h5Krla+ZitHi qHY+hl0oiC0Ng== Date: Fri, 06 Dec 2024 16:04:23 -0800 Subject: [PATCH 4/6] xfs: don't call xfs_bmap_same_rtgroup in xfs_bmap_add_extent_hole_delay From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352751260.126106.6805684880756196870.stgit@frogsfrogsfrogs> In-Reply-To: <173352751190.126106.5258055486306925523.stgit@frogsfrogsfrogs> References: <173352751190.126106.5258055486306925523.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Christoph Hellwig xfs_bmap_add_extent_hole_delay works entirely on delalloc extents, for which xfs_bmap_same_rtgroup doesn't make sense. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" Signed-off-by: "Darrick J. Wong" --- libxfs/xfs_bmap.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 552d292bf35412..16ee7403a75f3b 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -2614,8 +2614,7 @@ xfs_bmap_add_extent_hole_delay( */ if ((state & BMAP_LEFT_VALID) && (state & BMAP_LEFT_DELAY) && left.br_startoff + left.br_blockcount == new->br_startoff && - left.br_blockcount + new->br_blockcount <= XFS_MAX_BMBT_EXTLEN && - xfs_bmap_same_rtgroup(ip, whichfork, &left, new)) + left.br_blockcount + new->br_blockcount <= XFS_MAX_BMBT_EXTLEN) state |= BMAP_LEFT_CONTIG; if ((state & BMAP_RIGHT_VALID) && (state & BMAP_RIGHT_DELAY) && @@ -2623,8 +2622,7 @@ xfs_bmap_add_extent_hole_delay( new->br_blockcount + right.br_blockcount <= XFS_MAX_BMBT_EXTLEN && (!(state & BMAP_LEFT_CONTIG) || (left.br_blockcount + new->br_blockcount + - right.br_blockcount <= XFS_MAX_BMBT_EXTLEN)) && - xfs_bmap_same_rtgroup(ip, whichfork, new, &right)) + right.br_blockcount <= XFS_MAX_BMBT_EXTLEN))) state |= BMAP_RIGHT_CONTIG; /* From patchwork Sat Dec 7 00:04:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898092 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2E509139B for ; Sat, 7 Dec 2024 00:04:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733529880; cv=none; b=l1IlAwWVKYKsa1npHK2ZRX1eEooktp9EqxsNRzE6lQop6p3DZgbmllxYMApJDRuSIhFxMZXvgpClFNXwbeuVR7Btt8TbO/1hFbYGjQrtyn57U3l7F4fB0foz91JirH/Vk6MM2mons7b0PPykhcFJlvMmqmJY5Y8x9jEIlV4St6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733529880; c=relaxed/simple; bh=RUwpNSZPWzJTw/q9ytF6X/09sb0EQADhnmb3c37dtqI=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EaB/MVvFA7QFRR1gwtWBOOHQsjCB99hsRqIvSSHQdv3j/rwYlq84vjsu4Saxi9dGxYwthbIeyCwvWYm/jPU5HmYrV+vZGU/IhBgSiHoh1Pg6LD8S4o58yhsteFNMiDiKXPoCZGxnXxUCqfvWfZhQYG5ErMshwf4hxw2JHhHdMR4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tMIC6p1Z; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tMIC6p1Z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 030E5C4CED1; Sat, 7 Dec 2024 00:04:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733529880; bh=RUwpNSZPWzJTw/q9ytF6X/09sb0EQADhnmb3c37dtqI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=tMIC6p1ZVOvHMhgXfJfN1huiZBtYc10JQlVwtKcQDX2cDpvYBO/YxSRRXgWgIIdr/ JYkH6is/uwbCzUApRT0H09tzXAyw/fkfisWnTo3MKH1jd2u0ZuwTJhsisMP64ikQNJ H5DJ9tvi3dVf8yzRH0MKRDGmjbam6p2Jv4Oz2uudbf1d+kGu7/xEAjZ9f3ABR3Df8V 1ycw5nD5GGaY1c/MV8fAGY7FybbQoEERgYguo4alQy90LvdRlJNaGyvAF/pKqhDGaX +hWz/xu15CgwYB+CuzM1TjDn0QYbHq7ltLgrploUzVh2vU3o52uZFKM9Eccv1/P3Lm YO3/mjlicVhyw== Date: Fri, 06 Dec 2024 16:04:39 -0800 Subject: [PATCH 5/6] xfs: fix sb_spino_align checks for large fsblock sizes From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352751275.126106.4817221069844942594.stgit@frogsfrogsfrogs> In-Reply-To: <173352751190.126106.5258055486306925523.stgit@frogsfrogsfrogs> References: <173352751190.126106.5258055486306925523.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong For a sparse inodes filesystem, mkfs.xfs computes the values of sb_spino_align and sb_inoalignmt with the following code: int cluster_size = XFS_INODE_BIG_CLUSTER_SIZE; if (cfg->sb_feat.crcs_enabled) cluster_size *= cfg->inodesize / XFS_DINODE_MIN_SIZE; sbp->sb_spino_align = cluster_size >> cfg->blocklog; sbp->sb_inoalignmt = XFS_INODES_PER_CHUNK * cfg->inodesize >> cfg->blocklog; On a V5 filesystem with 64k fsblocks and 512 byte inodes, this results in cluster_size = 8192 * (512 / 256) = 16384. As a result, sb_spino_align and sb_inoalignmt are both set to zero. Unfortunately, this trips the new sb_spino_align check that was just added to xfs_validate_sb_common, and the mkfs fails: # mkfs.xfs -f -b size=64k, /dev/sda meta-data=/dev/sda isize=512 agcount=4, agsize=81136 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=1 = reflink=1 bigtime=1 inobtcount=1 nrext64=1 = exchange=0 metadir=0 data = bsize=65536 blocks=324544, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=65536 ascii-ci=0, ftype=1, parent=0 log =internal log bsize=65536 blocks=5006, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=65536 blocks=0, rtextents=0 = rgcount=0 rgsize=0 extents Discarding blocks...Sparse inode alignment (0) is invalid. Metadata corruption detected at 0x560ac5a80bbe, xfs_sb block 0x0/0x200 libxfs_bwrite: write verifier failed on xfs_sb bno 0x0/0x1 mkfs.xfs: Releasing dirty buffer to free list! found dirty buffer (bulk) on free list! Sparse inode alignment (0) is invalid. Metadata corruption detected at 0x560ac5a80bbe, xfs_sb block 0x0/0x200 libxfs_bwrite: write verifier failed on xfs_sb bno 0x0/0x1 mkfs.xfs: writing AG headers failed, err=22 Prior to commit 59e43f5479cce1 this all worked fine, even if "sparse" inodes are somewhat meaningless when everything fits in a single fsblock. Adjust the checks to handle existing filesystems. Fixes: 59e43f5479cce1 ("xfs: sb_spino_align is not verified") Signed-off-by: "Darrick J. Wong" --- libxfs/xfs_sb.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c index 87f740e6c75dce..ff23803a8065bf 100644 --- a/libxfs/xfs_sb.c +++ b/libxfs/xfs_sb.c @@ -491,12 +491,13 @@ xfs_validate_sb_common( return -EINVAL; } - if (!sbp->sb_spino_align || - sbp->sb_spino_align > sbp->sb_inoalignmt || - (sbp->sb_inoalignmt % sbp->sb_spino_align) != 0) { + if (sbp->sb_spino_align && + (sbp->sb_spino_align > sbp->sb_inoalignmt || + (sbp->sb_inoalignmt % sbp->sb_spino_align) != 0)) { xfs_warn(mp, - "Sparse inode alignment (%u) is invalid.", - sbp->sb_spino_align); +"Sparse inode alignment (%u) is invalid, must be integer factor of (%u).", + sbp->sb_spino_align, + sbp->sb_inoalignmt); return -EINVAL; } } else if (sbp->sb_spino_align) { From patchwork Sat Dec 7 00:04:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13898093 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 290D817E0; Sat, 7 Dec 2024 00:04:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733529896; cv=none; b=fE/dM1qo981Mnw9WmfETaEwNLWMSjxMtRaqcGYDCM9aWRp9Myx/cFZC/MTvL0IhBD4Xje5vkNsefB5Y9f6qzkorl57TnCIgc+OBw6Gev93A56aunNEXIJp5pmz1kZb2sFqF/QRwezmCffxxlTQtyjrOIJPLOfhmMSsusZ+t2/KY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733529896; c=relaxed/simple; bh=DpqGG4bMlII5yzVkc5pwB4B4TGfNhDaJexByzDs6FrQ=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=L++tC4s94c1s7PwuC3pim7aqaVzBXex8oE4FIOfs+5s+h7CCI6903NWGkvzKBgHxzA6czajRhIFLQy9KWkCtyw7zSt6JypU2mK6xAbNn2vKVJMHnoCnuG0Cme5t1kw0TMdvwleq3jjoXNU5eU2jL0UsOfzVbVvH7zve1ylcM5Zk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NyQ+T171; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NyQ+T171" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A926CC4CED1; Sat, 7 Dec 2024 00:04:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733529895; bh=DpqGG4bMlII5yzVkc5pwB4B4TGfNhDaJexByzDs6FrQ=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=NyQ+T1717nVzcT+LxnanA6RRWYpAjI/C1bSzkSBnSjUzgJi3XpPxDDeR1i9QRAyZT y2O1t1Zpsx8tNMa27OSDQuxn8M5wz1NrYRPwen1kogGQtyv9dl8yRD2UeZN9o1hjMj Fz5qpIFOCpz2RW4r4OLGHYNBuIgCAw7QTDpx5dep3+mnwoAMZ8ov9UcAWRHCaDO0Tl bYELBYbEHwi4O2WN5R3tlqTP9AK9QtZlTLM7k+jl6Jizjf1iMjeeS8FoZ8uC8LsUD+ uy9252r4Z7FvqXtDOFQbg+vw20So5cdKRQQGPJMeUvZ6pfb7TPVuUInuuuwNbeIfeE YyWlvdciSU7JA== Date: Fri, 06 Dec 2024 16:04:55 -0800 Subject: [PATCH 6/6] xfs: return from xfs_symlink_verify early on V4 filesystems From: "Darrick J. Wong" To: aalbersh@kernel.org, djwong@kernel.org Cc: stable@vger.kernel.org, hch@lst.de, linux-xfs@vger.kernel.org Message-ID: <173352751290.126106.1391306417071639286.stgit@frogsfrogsfrogs> In-Reply-To: <173352751190.126106.5258055486306925523.stgit@frogsfrogsfrogs> References: <173352751190.126106.5258055486306925523.stgit@frogsfrogsfrogs> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong V4 symlink blocks didn't have headers, so return early if this is a V4 filesystem. Cc: # v5.1 Fixes: 39708c20ab5133 ("xfs: miscellaneous verifier magic value fixups") Signed-off-by: "Darrick J. Wong" --- libxfs/xfs_symlink_remote.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_symlink_remote.c b/libxfs/xfs_symlink_remote.c index 2ad586f3926ad2..1c355f751e1cc7 100644 --- a/libxfs/xfs_symlink_remote.c +++ b/libxfs/xfs_symlink_remote.c @@ -89,8 +89,10 @@ xfs_symlink_verify( struct xfs_mount *mp = bp->b_mount; struct xfs_dsymlink_hdr *dsl = bp->b_addr; + /* no verification of non-crc buffers */ if (!xfs_has_crc(mp)) - return __this_address; + return NULL; + if (!xfs_verify_magic(bp, dsl->sl_magic)) return __this_address; if (!uuid_equal(&dsl->sl_uuid, &mp->m_sb.sb_meta_uuid))