From patchwork Wed Nov 9 02:05:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037053 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 143ABC433FE for ; Wed, 9 Nov 2022 02:05:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229552AbiKICFv (ORCPT ); Tue, 8 Nov 2022 21:05:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229546AbiKICFu (ORCPT ); Tue, 8 Nov 2022 21:05:50 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A77C154B21 for ; Tue, 8 Nov 2022 18:05:49 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 41715617E1 for ; Wed, 9 Nov 2022 02:05:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A32F6C433C1; Wed, 9 Nov 2022 02:05:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959548; bh=GRXFldNWnhEE8HHb7Flp4X6cHg63k82xl0dYoBjuFZc=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=MffFeACVlc48SOy7J0t6W245BZa9VM2sDWljA0ytCHwHEqvnpGDlkjOgHHGrtfhyy s0oJqlsoMqaq9Rk7Wb5WbkQ5I57MugCGx27A/ERH44/7XFTyEgS5xgPRCRNmhVudB6 QDUEpyqRU5WRM7sTa/mzAd4idu9Qyg1yTG+bBN/VYSentHbtnbzK0C4teUl73JOgLm fmLw0uhAnKJbvPmI5fW4C5KGG7jN6vAdzANrun9HEdv4qGaQlfiAuQnjHoZS3psnUl mbR0ahy4xOnW2G23T96nBpOr+rNhpKH3Oi62jxhzKP6AGnXjoeJpoRNL6eYN5hkziG VYgVJQmmy79lA== Subject: [PATCH 01/24] xfs: clean up "%Ld/%Lu" which doesn't meet C standard From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Zeng Heng , Dave Chinner , Dave Chinner , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:05:48 -0800 Message-ID: <166795954825.3761583.9121404007612201905.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Zeng Heng Source kernel commit: 78b0f58bdfef45aa9f3c7fbbd9b4d41abad6d85f The "%Ld" specifier, which represents long long unsigned, doesn't meet C language standard, and even more, it makes people easily mistake with "%ld", which represent long unsigned. So replace "%Ld" with "lld". Do the same with "%Lu". Signed-off-by: Zeng Heng Reviewed-by: Darrick J. Wong Reviewed-by: Dave Chinner Signed-off-by: Dave Chinner --- libxfs/xfs_bmap.c | 2 +- libxfs/xfs_inode_fork.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 123255b646..6d6f9e7dd6 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -287,7 +287,7 @@ xfs_check_block( else thispa = XFS_BMBT_PTR_ADDR(mp, block, j, dmxr); if (*thispa == *pp) { - xfs_warn(mp, "%s: thispa(%d) == pp(%d) %Ld", + xfs_warn(mp, "%s: thispa(%d) == pp(%d) %lld", __func__, j, i, (unsigned long long)be64_to_cpu(*thispa)); xfs_err(mp, "%s: ptrs are equal in node\n", diff --git a/libxfs/xfs_inode_fork.c b/libxfs/xfs_inode_fork.c index bed0c1b08a..f16b8ccc05 100644 --- a/libxfs/xfs_inode_fork.c +++ b/libxfs/xfs_inode_fork.c @@ -76,7 +76,7 @@ xfs_iformat_local( */ if (unlikely(size > XFS_DFORK_SIZE(dip, ip->i_mount, whichfork))) { xfs_warn(ip->i_mount, - "corrupt inode %Lu (bad size %d for local fork, size = %zd).", + "corrupt inode %llu (bad size %d for local fork, size = %zd).", (unsigned long long) ip->i_ino, size, XFS_DFORK_SIZE(dip, ip->i_mount, whichfork)); xfs_inode_verifier_error(ip, -EFSCORRUPTED, @@ -190,7 +190,7 @@ xfs_iformat_btree( XFS_DFORK_SIZE(dip, mp, whichfork) || ifp->if_nextents > ip->i_nblocks) || level == 0 || level > XFS_BM_MAXLEVELS(mp, whichfork)) { - xfs_warn(mp, "corrupt inode %Lu (btree).", + xfs_warn(mp, "corrupt inode %llu (btree).", (unsigned long long) ip->i_ino); xfs_inode_verifier_error(ip, -EFSCORRUPTED, "xfs_iformat_btree", dfp, size, From patchwork Wed Nov 9 02:05:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037054 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4CD0C433FE for ; Wed, 9 Nov 2022 02:05:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229526AbiKICF6 (ORCPT ); Tue, 8 Nov 2022 21:05:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbiKICF5 (ORCPT ); Tue, 8 Nov 2022 21:05:57 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC65560E88 for ; Tue, 8 Nov 2022 18:05:56 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8CBC9B81CC4 for ; Wed, 9 Nov 2022 02:05:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D3EFC433C1; Wed, 9 Nov 2022 02:05:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959554; bh=Uq7zC3UduKSRYqGXbxTf7gG5CUJuPcBgxOlZ9VTpWK4=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=jhPBaZloAVOllxidVvu/t6jXvXxrbetOTkN3Iyl9Bm0X1FN4CtErJdBdDbDg57PJQ 3Viu9+V7jcs2e9IS02p6BDVXxBWeO/mSzCeCGJ1dpzVC7n6sIiDvubeZUW2z+XY7ET jPr7ZmUNKZfyXCgzEshus0Ty+1559edCC3gL0RHe5P087NYgmnCgxLcVwG6p/1vLxV mD0/U7wcyv9v50SlGcsbsbELaW17CUG3HX6HafuSooSIhUXeTvmxUFuVnBkPVx+nY7 bVygKFOwnjiXOF5n2i65cXhFidHRw86VBGXSXgnexVFErLYAfyGE//3BHLHrJkzC7A nc4y1h36CZOOw== Subject: [PATCH 02/24] xfs: Remove the unneeded result variable From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Zeal Robot , ye xingchen , Dave Chinner , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:05:53 -0800 Message-ID: <166795955382.3761583.1638017452653008682.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: ye xingchen Source kernel commit: abda5271f8ec6e9a84ae8129ddc59226c89def7a Return the value xfs_dir_cilookup_result() directly instead of storing it in another redundant variable. Reported-by: Zeal Robot Signed-off-by: ye xingchen Reviewed-by: Darrick J. Wong Signed-off-by: Dave Chinner --- libxfs/xfs_dir2_sf.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libxfs/xfs_dir2_sf.c b/libxfs/xfs_dir2_sf.c index e97799b96f..08b36c95ce 100644 --- a/libxfs/xfs_dir2_sf.c +++ b/libxfs/xfs_dir2_sf.c @@ -865,7 +865,6 @@ xfs_dir2_sf_lookup( struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; int i; /* entry index */ - int error; xfs_dir2_sf_entry_t *sfep; /* shortform directory entry */ xfs_dir2_sf_hdr_t *sfp; /* shortform structure */ enum xfs_dacmp cmp; /* comparison result */ @@ -929,8 +928,7 @@ xfs_dir2_sf_lookup( if (!ci_sfep) return -ENOENT; /* otherwise process the CI match as required by the caller */ - error = xfs_dir_cilookup_result(args, ci_sfep->name, ci_sfep->namelen); - return error; + return xfs_dir_cilookup_result(args, ci_sfep->name, ci_sfep->namelen); } /* From patchwork Wed Nov 9 02:05:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037055 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23E8EC433FE for ; Wed, 9 Nov 2022 02:06:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229537AbiKICGC (ORCPT ); Tue, 8 Nov 2022 21:06:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbiKICGB (ORCPT ); Tue, 8 Nov 2022 21:06:01 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E885860E88 for ; Tue, 8 Nov 2022 18:06:00 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 705316187F for ; Wed, 9 Nov 2022 02:06:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBBFCC433D6; Wed, 9 Nov 2022 02:05:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959559; bh=dfdgpTDWgLucjj3sFy6zjfMm8FODrAHQ0xekjesk/6o=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=H0ByaixnbUGGlhIa5YBvGAM/jLp6XYAEwRbHhhh3wWeLm7LvgcxS3gw4GuLcg3m6z pg2UG54u6rzJ6/K1RrA3sxXRlOsn17BPBjJGXo9w+H8NeaBjoGhbFdMrzEn2V03h7Z xpYss0U+9+DIqaBmQwx4d+Gk5xP9WiwrazQPZ4bIXThiYw5zSWydsLhuLceKioXegG nCj4/l0RQgei+pkO2QjfElAeMouPcWBinJsZLSh9Jy0/tRwy3lsEmBvvYC9peJ19Ry Lg78qDRX9jTeBZF02rAxTFdioKw4K1GmwS773REequfwPsdAsp7KNH3eGnjOw6b2ks rSmUKCr0DL5Gg== Subject: [PATCH 03/24] xfs: trim the mapp array accordingly in xfs_da_grow_inode_int From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Shida Zhang , Dave Chinner , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:05:59 -0800 Message-ID: <166795955941.3761583.17493578275711914726.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Shida Zhang Source kernel commit: 44159659df8ca381b84261e11058b2176fa03ba0 Take a look at the for-loop in xfs_da_grow_inode_int: ====== for(){ nmap = min(XFS_BMAP_MAX_NMAP, count); ... error = xfs_bmapi_write(...,&mapp[mapi], &nmap);//(..., $1, $2) ... mapi += nmap; } ===== where $1 stands for the start address of the array, while $2 is used to indicate the size of the array. The array $1 will advance by $nmap in each iteration after the allocation of extents. But the size $2 still remains unchanged, which is determined by min(XFS_BMAP_MAX_NMAP, count). It seems that it has forgotten to trim the mapp array after each iteration, so change it. Signed-off-by: Shida Zhang Reviewed-by: Darrick J. Wong Signed-off-by: Dave Chinner --- libxfs/xfs_da_btree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libxfs/xfs_da_btree.c b/libxfs/xfs_da_btree.c index 9dc22f2ff1..a068a01643 100644 --- a/libxfs/xfs_da_btree.c +++ b/libxfs/xfs_da_btree.c @@ -2188,8 +2188,8 @@ xfs_da_grow_inode_int( */ mapp = kmem_alloc(sizeof(*mapp) * count, 0); for (b = *bno, mapi = 0; b < *bno + count; ) { - nmap = min(XFS_BMAP_MAX_NMAP, count); c = (int)(*bno + count - b); + nmap = min(XFS_BMAP_MAX_NMAP, c); error = xfs_bmapi_write(tp, dp, b, c, xfs_bmapi_aflag(w)|XFS_BMAPI_METADATA, args->total, &mapp[mapi], &nmap); From patchwork Wed Nov 9 02:06:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037056 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACB25C433FE for ; Wed, 9 Nov 2022 02:06:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229546AbiKICGK (ORCPT ); Tue, 8 Nov 2022 21:06:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbiKICGK (ORCPT ); Tue, 8 Nov 2022 21:06:10 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1ACE0663D8 for ; Tue, 8 Nov 2022 18:06:08 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CBF12B81CC4 for ; Wed, 9 Nov 2022 02:06:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73F20C433C1; Wed, 9 Nov 2022 02:06:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959565; bh=2nNqxIlR0BfBKCWmaciTLxX2lwhjOywxBms7atRMe3s=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=tnOnc0z+qNh8bvuz6cROCkRvE9xlNzimxtVopsOCPPhV1MvjvFuEhOIvXqoDp4Ulc CK6reqe/xlK8fK1Golth903K5KbE1UJPmC2yNz+kD0JtLRuystqHsqkRGXkEPPokPo kbhGZ0iNnHIcbw5afUrOZ5kSjD4rc9oUVw74Xbye2Ev1gh82uz34mwdn9PeZsVsf9j ISJplpQY00jrG+M2akcyG2bmZ0CqFERCOggdP+O3RRA6RKcKwplGeI1kGiqX6Ihoe0 BIIRk0UHoV+62WETwt9sDjWsGsUpElETl47eHWo7lMu1bWh7K6b5PXaaxTHWB/GXIq ku6X6RyG4lCcA== Subject: [PATCH 04/24] xfs: rearrange the logic and remove the broken comment for xfs_dir2_isxx From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Shida Zhang , Dave Chinner , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:06:05 -0800 Message-ID: <166795956500.3761583.4853170066354811352.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Shida Zhang Source kernel commit: c098576f5f63bc0ee2424bba50892514a71d54e8 xfs_dir2_isleaf is used to see if the directory is a single-leaf form directory instead, as commented right above the function. Besides getting rid of the broken comment, we rearrange the logic by converting everything over to standard formatting and conventions, at the same time, to make it easier to understand and self documenting. Signed-off-by: Shida Zhang Reviewed-by: Darrick J. Wong Signed-off-by: Dave Chinner --- db/namei.c | 2 +- libxfs/xfs_dir2.c | 50 ++++++++++++++++++++++++++++++-------------------- libxfs/xfs_dir2.h | 4 ++-- repair/phase6.c | 4 ++-- 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/db/namei.c b/db/namei.c index 6c57cc624e..7a5d749a77 100644 --- a/db/namei.c +++ b/db/namei.c @@ -449,8 +449,8 @@ listdir( .dp = dp, .geo = dp->i_mount->m_dir_geo, }; + bool isblock; int error; - int isblock; if (dp->i_df.if_format == XFS_DINODE_FMT_LOCAL) return list_sfdir(&args); diff --git a/libxfs/xfs_dir2.c b/libxfs/xfs_dir2.c index fac072fcb1..d6a192963f 100644 --- a/libxfs/xfs_dir2.c +++ b/libxfs/xfs_dir2.c @@ -260,7 +260,7 @@ xfs_dir_createname( { struct xfs_da_args *args; int rval; - int v; /* type-checking value */ + bool v; ASSERT(S_ISDIR(VFS_I(dp)->i_mode)); @@ -356,7 +356,7 @@ xfs_dir_lookup( { struct xfs_da_args *args; int rval; - int v; /* type-checking value */ + bool v; int lock_mode; ASSERT(S_ISDIR(VFS_I(dp)->i_mode)); @@ -434,7 +434,7 @@ xfs_dir_removename( { struct xfs_da_args *args; int rval; - int v; /* type-checking value */ + bool v; ASSERT(S_ISDIR(VFS_I(dp)->i_mode)); XFS_STATS_INC(dp->i_mount, xs_dir_remove); @@ -492,7 +492,7 @@ xfs_dir_replace( { struct xfs_da_args *args; int rval; - int v; /* type-checking value */ + bool v; ASSERT(S_ISDIR(VFS_I(dp)->i_mode)); @@ -609,19 +609,23 @@ xfs_dir2_grow_inode( int xfs_dir2_isblock( struct xfs_da_args *args, - int *vp) /* out: 1 is block, 0 is not block */ + bool *isblock) { - xfs_fileoff_t last; /* last file offset */ - int rval; + struct xfs_mount *mp = args->dp->i_mount; + xfs_fileoff_t eof; + int error; - if ((rval = xfs_bmap_last_offset(args->dp, &last, XFS_DATA_FORK))) - return rval; - rval = XFS_FSB_TO_B(args->dp->i_mount, last) == args->geo->blksize; - if (XFS_IS_CORRUPT(args->dp->i_mount, - rval != 0 && - args->dp->i_disk_size != args->geo->blksize)) + error = xfs_bmap_last_offset(args->dp, &eof, XFS_DATA_FORK); + if (error) + return error; + + *isblock = false; + if (XFS_FSB_TO_B(mp, eof) != args->geo->blksize) + return 0; + + *isblock = true; + if (XFS_IS_CORRUPT(mp, args->dp->i_disk_size != args->geo->blksize)) return -EFSCORRUPTED; - *vp = rval; return 0; } @@ -631,14 +635,20 @@ xfs_dir2_isblock( int xfs_dir2_isleaf( struct xfs_da_args *args, - int *vp) /* out: 1 is block, 0 is not block */ + bool *isleaf) { - xfs_fileoff_t last; /* last file offset */ - int rval; + xfs_fileoff_t eof; + int error; - if ((rval = xfs_bmap_last_offset(args->dp, &last, XFS_DATA_FORK))) - return rval; - *vp = last == args->geo->leafblk + args->geo->fsbcount; + error = xfs_bmap_last_offset(args->dp, &eof, XFS_DATA_FORK); + if (error) + return error; + + *isleaf = false; + if (eof != args->geo->leafblk + args->geo->fsbcount) + return 0; + + *isleaf = true; return 0; } diff --git a/libxfs/xfs_dir2.h b/libxfs/xfs_dir2.h index b6df3c34b2..dd39f17dd9 100644 --- a/libxfs/xfs_dir2.h +++ b/libxfs/xfs_dir2.h @@ -61,8 +61,8 @@ extern int xfs_dir2_sf_to_block(struct xfs_da_args *args); /* * Interface routines used by userspace utilities */ -extern int xfs_dir2_isblock(struct xfs_da_args *args, int *r); -extern int xfs_dir2_isleaf(struct xfs_da_args *args, int *r); +extern int xfs_dir2_isblock(struct xfs_da_args *args, bool *isblock); +extern int xfs_dir2_isleaf(struct xfs_da_args *args, bool *isleaf); extern int xfs_dir2_shrink_inode(struct xfs_da_args *args, xfs_dir2_db_t db, struct xfs_buf *bp); diff --git a/repair/phase6.c b/repair/phase6.c index fefb9755f5..81fccff9d4 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -2250,8 +2250,8 @@ longform_dir2_entry_check( xfs_dablk_t da_bno; freetab_t *freetab; int i; - int isblock; - int isleaf; + bool isblock; + bool isleaf; xfs_fileoff_t next_da_bno; int seeval; int fixit = 0; From patchwork Wed Nov 9 02:06:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037057 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63E1DC43219 for ; Wed, 9 Nov 2022 02:06:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229612AbiKICGQ (ORCPT ); Tue, 8 Nov 2022 21:06:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229602AbiKICGO (ORCPT ); Tue, 8 Nov 2022 21:06:14 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C7AF67F43 for ; Tue, 8 Nov 2022 18:06:13 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5A734B81CD7 for ; Wed, 9 Nov 2022 02:06:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02A4FC433C1; Wed, 9 Nov 2022 02:06:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959571; bh=fZ73h36H4v2wozkAxjWHI56L2pG6glQNaBVXoAieXOA=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=rs0T5bmqnZ9lMg04sB9qRX5DhhzpiBL8dSSnCqvWFoSJ6SN4qjzWNaavyiysC2uxu B4pKWFbEZmvGfsMeL8TGlxmrsoJOaHJmAW1NCy6K6bLdvr6zpdib6tWvgH+HO5fp5b xu2iXWKWwIoXaOCiDkHbe0E9BAC94X3k7HUNR/I8VuyU3bWZXkaC7Km09+pAd6avZf iWTeVbA8I7EhTzr8OGJ5x5oJVbAF4h0PoLl4/1xNewHZ5P2X0HUSqViwk218lI66Jl lFo8dENPJfNO5gcfRFSl6eYQU7ia3OUGf4Fu8mQ1JVHxuMq03gkVuAifO/8J3uTY69 kIlR0/T/QKn0Q== Subject: [PATCH 05/24] treewide: use prandom_u32_max() when possible, part 1 From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Greg Kroah-Hartman , Kees Cook , Yury Norov , KP Singh , Jan Kara , =?utf-8?q?Christoph?= =?utf-8?q?_B=C3=B6hmwalder?= , Jakub Kicinski , Heiko Carstens , Ulf Hansson , "Jason A. Donenfeld" , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:06:10 -0800 Message-ID: <166795957064.3761583.12187898025422805623.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Jason A. Donenfeld Source kernel commit: 81895a65ec63ee1daec3255dc1a06675d2fbe915 Rather than incurring a division or requesting too many random bytes for the given range, use the prandom_u32_max() function, which only takes the minimum required bytes from the RNG and avoids divisions. This was done mechanically with this coccinelle script: @basic@ expression E; type T; identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32"; typedef u64; @@ ( - ((T)get_random_u32() % (E)) + prandom_u32_max(E) | - ((T)get_random_u32() & ((E) - 1)) + prandom_u32_max(E * XXX_MAKE_SURE_E_IS_POW2) | - ((u64)(E) * get_random_u32() >> 32) + prandom_u32_max(E) | - ((T)get_random_u32() & ~PAGE_MASK) + prandom_u32_max(PAGE_SIZE) ) @multi_line@ identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32"; identifier RAND; expression E; @@ - RAND = get_random_u32(); ... when != RAND - RAND %= (E); + RAND = prandom_u32_max(E); // Find a potential literal @literal_mask@ expression LITERAL; type T; identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32"; position p; @@ ((T)get_random_u32()@p & (LITERAL)) // Add one to the literal. @script:python add_one@ literal << literal_mask.LITERAL; RESULT; @@ value = None if literal.startswith('0x'): value = int(literal, 16) elif literal[0] in '123456789': value = int(literal, 10) if value is None: print("I don't know how to handle %s" % (literal)) cocci.include_match(False) elif value == 2**32 - 1 or value == 2**31 - 1 or value == 2**24 - 1 or value == 2**16 - 1 or value == 2**8 - 1: print("Skipping 0x%x for cleanup elsewhere" % (value)) cocci.include_match(False) elif value & (value + 1) != 0: print("Skipping 0x%x because it's not a power of two minus one" % (value)) cocci.include_match(False) elif literal.startswith('0x'): coccinelle.RESULT = cocci.make_expr("0x%x" % (value + 1)) else: coccinelle.RESULT = cocci.make_expr("%d" % (value + 1)) // Replace the literal mask with the calculated result. @plus_one@ expression literal_mask.LITERAL; position literal_mask.p; expression add_one.RESULT; identifier FUNC; @@ - (FUNC()@p & (LITERAL)) + prandom_u32_max(RESULT) @collapse_ret@ type T; identifier VAR; expression E; @@ { - T VAR; - VAR = (E); - return VAR; + return E; } @drop_var@ type T; identifier VAR; @@ { - T VAR; ... when != VAR } Reviewed-by: Greg Kroah-Hartman Reviewed-by: Kees Cook Reviewed-by: Yury Norov Reviewed-by: KP Singh Reviewed-by: Jan Kara Reviewed-by: Christoph Böhmwalder Acked-by: Jakub Kicinski Acked-by: Heiko Carstens Acked-by: Ulf Hansson Acked-by: Darrick J. Wong Signed-off-by: Jason A. Donenfeld --- libxfs/xfs_alloc.c | 2 +- libxfs/xfs_ialloc.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index 271c48dd83..3e310ce3e5 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -1516,7 +1516,7 @@ xfs_alloc_ag_vextent_lastblock( #ifdef DEBUG /* Randomly don't execute the first algorithm. */ - if (prandom_u32() & 1) + if (prandom_u32_max(2)) return 0; #endif diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c index f27de1fdd0..18f3dea5f5 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -631,7 +631,7 @@ xfs_ialloc_ag_alloc( /* randomly do sparse inode allocations */ if (xfs_has_sparseinodes(tp->t_mountp) && igeo->ialloc_min_blks < igeo->ialloc_blks) - do_sparse = prandom_u32() & 1; + do_sparse = prandom_u32_max(2); #endif /* From patchwork Wed Nov 9 02:06:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037058 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3065FC433FE for ; Wed, 9 Nov 2022 02:06:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229605AbiKICGU (ORCPT ); Tue, 8 Nov 2022 21:06:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229610AbiKICGU (ORCPT ); Tue, 8 Nov 2022 21:06:20 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AF5C67F40 for ; Tue, 8 Nov 2022 18:06:19 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DF028B81619 for ; Wed, 9 Nov 2022 02:06:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90034C433C1; Wed, 9 Nov 2022 02:06:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959576; bh=m93GOKQbivFlnvGYZtADaqfmx9hB2rKPdcgU9Qv+Aww=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=e077x4Runu4gw7pSc8RLLq7E+o32KJe0NlaEtOBHi8K8aGFkB71XhEdf1BhVhIAUJ NpW1K4u4zcdFqA0vRVjYvfm7t/7pyZ5Hm2OayzGtBvqtWT3H9KlbGCqtJMpob2Io0X zor4aHDE+QLgk4j0jCBMVCzCe2r89cl39yYysPKKgGqHS231T6194HOSODAByZWChc QJOyMFw2RLNUdDv2NIw/c1HaWpdu+wBGWjRAd7B+lWP7MxVZhpEnex7rV0f6VfjBwY wL+s3tTGV5nlryoflME+FHnvD8NCk/waQsQlauTOtg8S2eIItfQeUDn3pCye1zypNP tu/bulqSN9npQ== Subject: [PATCH 06/24] treewide: use get_random_u32() when possible From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Greg Kroah-Hartman , Kees Cook , Yury Norov , Jan Kara , =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , Chuck Lever , Jakub Kicinski , Mika Westerberg , Helge Deller , Heiko Carstens , "Jason A. Donenfeld" , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:06:16 -0800 Message-ID: <166795957617.3761583.14978349837941360702.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Jason A. Donenfeld Source kernel commit: a251c17aa558d8e3128a528af5cf8b9d7caae4fd The prandom_u32() function has been a deprecated inline wrapper around get_random_u32() for several releases now, and compiles down to the exact same code. Replace the deprecated wrapper with a direct call to the real function. The same also applies to get_random_int(), which is just a wrapper around get_random_u32(). This was done as a basic find and replace. Reviewed-by: Greg Kroah-Hartman Reviewed-by: Kees Cook Reviewed-by: Yury Norov Reviewed-by: Jan Kara Acked-by: Toke Høiland-Jørgensen Acked-by: Chuck Lever Acked-by: Jakub Kicinski Acked-by: Mika Westerberg Acked-by: Darrick J. Wong Acked-by: Helge Deller Acked-by: Heiko Carstens Signed-off-by: Jason A. Donenfeld --- libxfs/libxfs_priv.h | 6 +++--- libxfs/xfs_ialloc.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h index b2c3f694b0..ad4b947583 100644 --- a/libxfs/libxfs_priv.h +++ b/libxfs/libxfs_priv.h @@ -225,10 +225,10 @@ static inline bool WARN_ON(bool expr) { #define WRITE_ONCE(x, val) ((x) = (val)) /* - * prandom_u32 is used for di_gen inode allocation, it must be zero for libxfs - * or all sorts of badness can occur! + * get_random_u32 is used for di_gen inode allocation, it must be zero for + * libxfs or all sorts of badness can occur! */ -#define prandom_u32() 0 +#define get_random_u32() (0) #define PAGE_SIZE getpagesize() diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c index 18f3dea5f5..e05aa0c11b 100644 --- a/libxfs/xfs_ialloc.c +++ b/libxfs/xfs_ialloc.c @@ -800,7 +800,7 @@ xfs_ialloc_ag_alloc( * number from being easily guessable. */ error = xfs_ialloc_inode_init(args.mp, tp, NULL, newlen, pag->pag_agno, - args.agbno, args.len, prandom_u32()); + args.agbno, args.len, get_random_u32()); if (error) return error; From patchwork Wed Nov 9 02:06:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037059 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97B39C433FE for ; Wed, 9 Nov 2022 02:06:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229517AbiKICG0 (ORCPT ); Tue, 8 Nov 2022 21:06:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229602AbiKICG0 (ORCPT ); Tue, 8 Nov 2022 21:06:26 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6A88663E1 for ; Tue, 8 Nov 2022 18:06:24 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 722C3B81619 for ; Wed, 9 Nov 2022 02:06:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 206D9C433D6; Wed, 9 Nov 2022 02:06:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959582; bh=6dvSY4PFc5h4MgbCwlc8+JGMaNB7m6hJcI6ZZpacklE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=FdlVOoyQ4WuLPaBQ8HITnS/+iwo5ADM8BtC+WDfrja/ZIqYKptMAlusgQLTMAKsth EPB/5c04rohDREoMqq1maLIUsq+mooKfwuE/4TEBdyASav0R9otLJgVfstP/CBwaix Pf3X9keG7DXljjY05vxJsh5A7LRiK7sDEpHpxTBK14SfgUgimp2BTNMd3mJOokRrRZ IRzfP55QK45mV5Cf96rGEmOJ9wfJT5yNaA9NfSsmo/+m8x9PRdgu5ITHRe8lTcf9do S/kNTp9gbn9WkF33GzkswQAx3MvDD6Tm/AETE0tNZy2Y3LgKFirfo4MObuPuzNXnln TQWHCTJrW1/tw== Subject: [PATCH 07/24] xfs: fix exception caused by unexpected illegal bestcount in leaf dir From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Hou Tao , Guo Xuenan , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:06:21 -0800 Message-ID: <166795958175.3761583.2285127671315785716.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Guo Xuenan Source kernel commit: 0cb227895e6f8369c1a2b9110e291a35223b8de1 For leaf dir, In most cases, there should be as many bestfree slots as the dir data blocks that can fit under i_size (except for [1]). Root cause is we don't examin the number bestfree slots, when the slots number less than dir data blocks, if we need to allocate new dir data block and update the bestfree array, we will use the dir block number as index to assign bestfree array, while we did not check the leaf buf boundary which may cause UAF or other memory access problem. This issue can also triggered with test cases xfs/473 from fstests. According to Dave Chinner & Darrick's suggestion, adding buffer verifier to detect this abnormal situation in time. Simplify the testcase for fstest xfs/554 [1] The error log is shown as follows: ================================================================== BUG: KASAN: use-after-free in xfs_dir2_leaf_addname+0x1995/0x1ac0 Write of size 2 at addr ffff88810168b000 by task touch/1552 CPU: 5 PID: 1552 Comm: touch Not tainted 6.0.0-rc3+ #101 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 Call Trace: dump_stack_lvl+0x4d/0x66 print_report.cold+0xf6/0x691 kasan_report+0xa8/0x120 xfs_dir2_leaf_addname+0x1995/0x1ac0 xfs_dir_createname+0x58c/0x7f0 xfs_create+0x7af/0x1010 xfs_generic_create+0x270/0x5e0 path_openat+0x270b/0x3450 do_filp_open+0x1cf/0x2b0 do_sys_openat2+0x46b/0x7a0 do_sys_open+0xb7/0x130 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcd RIP: 0033:0x7fe4d9e9312b Code: 25 00 00 41 00 3d 00 00 41 00 74 4b 64 8b 04 25 18 00 00 00 85 c0 75 67 44 89 e2 48 89 ee bf 9c ff ff ff b8 01 01 00 00 0f 05 <48> 3d 00 f0 ff ff 0f 87 91 00 00 00 48 8b 4c 24 28 64 48 33 0c 25 RSP: 002b:00007ffda4c16c20 EFLAGS: 00000246 ORIG_RAX: 0000000000000101 RAX: ffffffffffffffda RBX: 0000000000000001 RCX: 00007fe4d9e9312b RDX: 0000000000000941 RSI: 00007ffda4c17f33 RDI: 00000000ffffff9c RBP: 00007ffda4c17f33 R08: 0000000000000000 R09: 0000000000000000 R10: 00000000000001b6 R11: 0000000000000246 R12: 0000000000000941 R13: 00007fe4d9f631a4 R14: 00007ffda4c17f33 R15: 0000000000000000 The buggy address belongs to the physical page: page:ffffea000405a2c0 refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10168b flags: 0x2fffff80000000(node=0|zone=2|lastcpupid=0x1fffff) raw: 002fffff80000000 ffffea0004057788 ffffea000402dbc8 0000000000000000 raw: 0000000000000000 0000000000170000 00000000ffffffff 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff88810168af00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ffff88810168af80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >ffff88810168b000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ^ ffff88810168b080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ffff88810168b100: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ================================================================== Disabling lock debugging due to kernel taint 00000000: 58 44 44 33 5b 53 35 c2 00 00 00 00 00 00 00 78 XDD3[S5........x XFS (sdb): Internal error xfs_dir2_data_use_free at line 1200 of file fs/xfs/libxfs/xfs_dir2_data.c. Caller xfs_dir2_data_use_free+0x28a/0xeb0 CPU: 5 PID: 1552 Comm: touch Tainted: G B 6.0.0-rc3+ Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 Call Trace: dump_stack_lvl+0x4d/0x66 xfs_corruption_error+0x132/0x150 xfs_dir2_data_use_free+0x198/0xeb0 xfs_dir2_leaf_addname+0xa59/0x1ac0 xfs_dir_createname+0x58c/0x7f0 xfs_create+0x7af/0x1010 xfs_generic_create+0x270/0x5e0 path_openat+0x270b/0x3450 do_filp_open+0x1cf/0x2b0 do_sys_openat2+0x46b/0x7a0 do_sys_open+0xb7/0x130 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcd RIP: 0033:0x7fe4d9e9312b Code: 25 00 00 41 00 3d 00 00 41 00 74 4b 64 8b 04 25 18 00 00 00 85 c0 75 67 44 89 e2 48 89 ee bf 9c ff ff ff b8 01 01 00 00 0f 05 <48> 3d 00 f0 ff ff 0f 87 91 00 00 00 48 8b 4c 24 28 64 48 33 0c 25 RSP: 002b:00007ffda4c16c20 EFLAGS: 00000246 ORIG_RAX: 0000000000000101 RAX: ffffffffffffffda RBX: 0000000000000001 RCX: 00007fe4d9e9312b RDX: 0000000000000941 RSI: 00007ffda4c17f46 RDI: 00000000ffffff9c RBP: 00007ffda4c17f46 R08: 0000000000000000 R09: 0000000000000001 R10: 00000000000001b6 R11: 0000000000000246 R12: 0000000000000941 R13: 00007fe4d9f631a4 R14: 00007ffda4c17f46 R15: 0000000000000000 XFS (sdb): Corruption detected. Unmount and run xfs_repair [1] https://lore.kernel.org/all/20220928095355.2074025-1-guoxuenan@huawei.com/ Reviewed-by: Hou Tao Signed-off-by: Guo Xuenan Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- libxfs/xfs_dir2_leaf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_dir2_leaf.c b/libxfs/xfs_dir2_leaf.c index 8827c96c18..5da66006cb 100644 --- a/libxfs/xfs_dir2_leaf.c +++ b/libxfs/xfs_dir2_leaf.c @@ -144,6 +144,8 @@ xfs_dir3_leaf_check_int( xfs_dir2_leaf_tail_t *ltp; int stale; int i; + bool isleaf1 = (hdr->magic == XFS_DIR2_LEAF1_MAGIC || + hdr->magic == XFS_DIR3_LEAF1_MAGIC); ltp = xfs_dir2_leaf_tail_p(geo, leaf); @@ -156,8 +158,7 @@ xfs_dir3_leaf_check_int( return __this_address; /* Leaves and bests don't overlap in leaf format. */ - if ((hdr->magic == XFS_DIR2_LEAF1_MAGIC || - hdr->magic == XFS_DIR3_LEAF1_MAGIC) && + if (isleaf1 && (char *)&hdr->ents[hdr->count] > (char *)xfs_dir2_leaf_bests_p(ltp)) return __this_address; @@ -173,6 +174,10 @@ xfs_dir3_leaf_check_int( } if (hdr->ents[i].address == cpu_to_be32(XFS_DIR2_NULL_DATAPTR)) stale++; + if (isleaf1 && xfs_dir2_dataptr_to_db(geo, + be32_to_cpu(hdr->ents[i].address)) >= + be32_to_cpu(ltp->bestcount)) + return __this_address; } if (hdr->stale != stale) return __this_address; From patchwork Wed Nov 9 02:06:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037060 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E22FAC433FE for ; Wed, 9 Nov 2022 02:06:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229602AbiKICGe (ORCPT ); Tue, 8 Nov 2022 21:06:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229610AbiKICGb (ORCPT ); Tue, 8 Nov 2022 21:06:31 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B752167F6F for ; Tue, 8 Nov 2022 18:06:28 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5400B6187F for ; Wed, 9 Nov 2022 02:06:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B038FC433C1; Wed, 9 Nov 2022 02:06:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959587; bh=OTc487UXuHdbnY9ShMdHrCRg80Ia9/wBidA55RlkOKU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=NV/+0N4DrQZim9bgUbxgxIULi7Q13/AViUUzH4G/DjYCR8WK80wiv2itGW+T3hiRN vgeubg424E2LuZvJEa0yrl/2EvNeO6pH0fouTttnnzr6MGOU4CaIOt03Qq7cqlTUse KYJ5ary6hZL3xnw8ZhR0Uv8foHeIPR1buHwlMy9g1qVP5pcjenWywy7GzAGnYDC5QM LAKcN3hWieFFi2bCjSYqjQ8WNfOO7i3uCFHWx1qMbKMcH66/J3IOlPIG9Lk5HJ/jFk plfm8MYHocHrhhdx+s4A50WRrHANOztg1bArCbHuTcN9gsLUU5ypbyLxj0aesBWx4u KVaW7/1sYTilA== Subject: [PATCH 08/24] xfs: increase rename inode reservation From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Allison Henderson , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:06:27 -0800 Message-ID: <166795958729.3761583.16534685915746168184.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Allison Henderson Source kernel commit: e07ee6fe21f47cfd72ae566395c67a80e7c66163 xfs_rename can update up to 5 inodes: src_dp, target_dp, src_ip, target_ip and wip. So we need to increase the inode reservation to match. Signed-off-by: Allison Henderson Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong --- libxfs/xfs_trans_resv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_trans_resv.c b/libxfs/xfs_trans_resv.c index 797176d7d3..04c444806f 100644 --- a/libxfs/xfs_trans_resv.c +++ b/libxfs/xfs_trans_resv.c @@ -421,7 +421,7 @@ xfs_calc_itruncate_reservation_minlogsize( /* * In renaming a files we can modify: - * the four inodes involved: 4 * inode size + * the five inodes involved: 5 * inode size * the two directory btrees: 2 * (max depth + v2) * dir block size * the two directory bmap btrees: 2 * max depth * block size * And the bmap_finish transaction can free dir and bmap blocks (two sets @@ -436,7 +436,7 @@ xfs_calc_rename_reservation( struct xfs_mount *mp) { return XFS_DQUOT_LOGRES(mp) + - max((xfs_calc_inode_res(mp, 4) + + max((xfs_calc_inode_res(mp, 5) + xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp), XFS_FSB_TO_B(mp, 1))), (xfs_calc_buf_res(7, mp->m_sb.sb_sectsize) + From patchwork Wed Nov 9 02:06:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037061 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB975C4332F for ; Wed, 9 Nov 2022 02:06:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229639AbiKICGh (ORCPT ); Tue, 8 Nov 2022 21:06:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229611AbiKICGe (ORCPT ); Tue, 8 Nov 2022 21:06:34 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F49B663E1 for ; Tue, 8 Nov 2022 18:06:34 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CFB1861808 for ; Wed, 9 Nov 2022 02:06:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B731C433D6; Wed, 9 Nov 2022 02:06:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959593; bh=bfWun4uSMFgH+W6v76YBGOgQVtJjf6QyvENWuqQ3KD0=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=nja+/t51u5dRFvkAukyu7Hk4AVO8Ozl5cSGfDs4oNw5ao4JSR0qnQgPykopP7Qtyt 4+Fnz6GCrrezix+WHNX6q3BIKPGLoNUZIYaM5cIdIiDq32vgBq/BPnUmY3/UihAeuN GCsFk6b0m8XLFaojxXJpiYf5wGMmMvII3IK1jL/0K1TOstkkpfuiJgug/AanJeGFVe jdxyYTKeUV4T/giaq8wf5lldXzFeD0/bUu0Ny7PiuS65ogzPp9rBkKlLVhTOeR4ncH dk/QSQlwzzvW8I+dciZrT5lA00Jcoax65RDkd9QwRnVltiP+A9lD1yT8d2NclorCF4 l365NIWssJh+Q== Subject: [PATCH 09/24] xfs: fix memcpy fortify errors in EFI log format copying From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:06:32 -0800 Message-ID: <166795959288.3761583.14358034387087854299.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: b276f256ced3233b74b83d7df4e1b4ba8672ee98 Starting in 6.1, CONFIG_FORTIFY_SOURCE checks the length parameter of memcpy. Since we're already fixing problems with BUI item copying, we should fix it everything else. Refactor the xfs_efi_copy_format function to handle the copying of the head and the flex array members separately, and do the same for the EFI relogging functions. While we're at it, fix a minor validation deficiency in the recovery function. Signed-off-by: Darrick J. Wong --- libxfs/xfs_log_format.h | 12 ++++++------ logprint/log_redo.c | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libxfs/xfs_log_format.h b/libxfs/xfs_log_format.h index b351b9dc65..2f41fa8477 100644 --- a/libxfs/xfs_log_format.h +++ b/libxfs/xfs_log_format.h @@ -613,7 +613,7 @@ typedef struct xfs_efi_log_format { uint16_t efi_size; /* size of this item */ uint32_t efi_nextents; /* # extents to free */ uint64_t efi_id; /* efi identifier */ - xfs_extent_t efi_extents[1]; /* array of extents to free */ + xfs_extent_t efi_extents[]; /* array of extents to free */ } xfs_efi_log_format_t; typedef struct xfs_efi_log_format_32 { @@ -621,7 +621,7 @@ typedef struct xfs_efi_log_format_32 { uint16_t efi_size; /* size of this item */ uint32_t efi_nextents; /* # extents to free */ uint64_t efi_id; /* efi identifier */ - xfs_extent_32_t efi_extents[1]; /* array of extents to free */ + xfs_extent_32_t efi_extents[]; /* array of extents to free */ } __attribute__((packed)) xfs_efi_log_format_32_t; typedef struct xfs_efi_log_format_64 { @@ -629,7 +629,7 @@ typedef struct xfs_efi_log_format_64 { uint16_t efi_size; /* size of this item */ uint32_t efi_nextents; /* # extents to free */ uint64_t efi_id; /* efi identifier */ - xfs_extent_64_t efi_extents[1]; /* array of extents to free */ + xfs_extent_64_t efi_extents[]; /* array of extents to free */ } xfs_efi_log_format_64_t; /* @@ -642,7 +642,7 @@ typedef struct xfs_efd_log_format { uint16_t efd_size; /* size of this item */ uint32_t efd_nextents; /* # of extents freed */ uint64_t efd_efi_id; /* id of corresponding efi */ - xfs_extent_t efd_extents[1]; /* array of extents freed */ + xfs_extent_t efd_extents[]; /* array of extents freed */ } xfs_efd_log_format_t; typedef struct xfs_efd_log_format_32 { @@ -650,7 +650,7 @@ typedef struct xfs_efd_log_format_32 { uint16_t efd_size; /* size of this item */ uint32_t efd_nextents; /* # of extents freed */ uint64_t efd_efi_id; /* id of corresponding efi */ - xfs_extent_32_t efd_extents[1]; /* array of extents freed */ + xfs_extent_32_t efd_extents[]; /* array of extents freed */ } __attribute__((packed)) xfs_efd_log_format_32_t; typedef struct xfs_efd_log_format_64 { @@ -658,7 +658,7 @@ typedef struct xfs_efd_log_format_64 { uint16_t efd_size; /* size of this item */ uint32_t efd_nextents; /* # of extents freed */ uint64_t efd_efi_id; /* id of corresponding efi */ - xfs_extent_64_t efd_extents[1]; /* array of extents freed */ + xfs_extent_64_t efd_extents[]; /* array of extents freed */ } xfs_efd_log_format_64_t; /* diff --git a/logprint/log_redo.c b/logprint/log_redo.c index 1974382d2d..12d041da1c 100644 --- a/logprint/log_redo.c +++ b/logprint/log_redo.c @@ -20,9 +20,9 @@ xfs_efi_copy_format( { uint i; uint nextents = ((xfs_efi_log_format_t *)buf)->efi_nextents; - uint dst_len = sizeof(xfs_efi_log_format_t) + (nextents - 1) * sizeof(xfs_extent_t); - uint len32 = sizeof(xfs_efi_log_format_32_t) + (nextents - 1) * sizeof(xfs_extent_32_t); - uint len64 = sizeof(xfs_efi_log_format_64_t) + (nextents - 1) * sizeof(xfs_extent_64_t); + uint dst_len = sizeof(xfs_efi_log_format_t) + nextents * sizeof(xfs_extent_t); + uint len32 = sizeof(xfs_efi_log_format_32_t) + nextents * sizeof(xfs_extent_32_t); + uint len64 = sizeof(xfs_efi_log_format_64_t) + nextents * sizeof(xfs_extent_64_t); if (len == dst_len || continued) { memcpy((char *)dst_efi_fmt, buf, len); @@ -86,7 +86,7 @@ xlog_print_trans_efi( *ptr += src_len; /* convert to native format */ - dst_len = sizeof(xfs_efi_log_format_t) + (src_f->efi_nextents - 1) * sizeof(xfs_extent_t); + dst_len = sizeof(xfs_efi_log_format_t) + src_f->efi_nextents * sizeof(xfs_extent_t); if (continued && src_len < core_size) { printf(_("EFI: Not enough data to decode further\n")); @@ -144,7 +144,7 @@ xlog_recover_print_efi( * Need to convert to native format. */ dst_len = sizeof(xfs_efi_log_format_t) + - (src_f->efi_nextents - 1) * sizeof(xfs_extent_t); + src_f->efi_nextents * sizeof(xfs_extent_t); if ((f = (xfs_efi_log_format_t *)malloc(dst_len)) == NULL) { fprintf(stderr, _("%s: xlog_recover_print_efi: malloc failed\n"), progname); @@ -177,7 +177,7 @@ xlog_print_trans_efd(char **ptr, uint len) xfs_efd_log_format_t *f; xfs_efd_log_format_t lbuf; /* size without extents at end */ - uint core_size = sizeof(xfs_efd_log_format_t) - sizeof(xfs_extent_t); + uint core_size = sizeof(struct xfs_efd_log_format); /* * memmove to ensure 8-byte alignment for the long longs in From patchwork Wed Nov 9 02:06:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037062 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30391C4332F for ; Wed, 9 Nov 2022 02:06:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229621AbiKICGm (ORCPT ); Tue, 8 Nov 2022 21:06:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229611AbiKICGm (ORCPT ); Tue, 8 Nov 2022 21:06:42 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7740168294 for ; Tue, 8 Nov 2022 18:06:41 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2DC5CB81619 for ; Wed, 9 Nov 2022 02:06:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC3C9C433C1; Wed, 9 Nov 2022 02:06:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959598; bh=SpHR5Waiz5a9EK9GLHJFvFOQ5RtC6jyKYMAio89VcGQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=hWzPn/6YcLGZZX0zj8rtw2e6TGghKDeYGgkrcva2LKxplMmV9Vn2Ioe6moQ7ztrSI +jxmbOZ5881sS3riu1KQK3UvuA5Sq6uNhJbrAAWNponHgwwQgTBAom2Skztjx5XlmD 5kNjE/ENjU8lWogDD8VvKSHbx7qvdSOAFBkM5LIt9j64aOeCCANQugsJFgbyqZ5oWc 1jirHhgzLShUhBXG7gdNMBGYKimzwkAwkDD71Efc4dWhg44zB9JSJ/1LAtu9KehwnR ZlbfTMTd1PoTBx4uEtGFyS6KIwUJ5L8eql9RExzU0O5FsxHnGBiUb+ms6Pgcis+wDP hCTrPMueTRDeQ== Subject: [PATCH 10/24] xfs: refactor all the EFI/EFD log format sizeof logic From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:06:38 -0800 Message-ID: <166795959840.3761583.11500851812367396592.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: eaf7a21a10f90578f14966c2eafaab4896add356 Refactor all the open-coded sizeof logic for EFI/EFD log items into a common helper function. Signed-off-by: Darrick J. Wong --- libxfs/xfs_log_format.h | 48 +++++++++++++++++++++++++++++++++++++++++++++++ logprint/log_redo.c | 8 ++++---- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/libxfs/xfs_log_format.h b/libxfs/xfs_log_format.h index 2f41fa8477..f13e0809dc 100644 --- a/libxfs/xfs_log_format.h +++ b/libxfs/xfs_log_format.h @@ -616,6 +616,14 @@ typedef struct xfs_efi_log_format { xfs_extent_t efi_extents[]; /* array of extents to free */ } xfs_efi_log_format_t; +static inline size_t +xfs_efi_log_format_sizeof( + unsigned int nr) +{ + return sizeof(struct xfs_efi_log_format) + + nr * sizeof(struct xfs_extent); +} + typedef struct xfs_efi_log_format_32 { uint16_t efi_type; /* efi log item type */ uint16_t efi_size; /* size of this item */ @@ -624,6 +632,14 @@ typedef struct xfs_efi_log_format_32 { xfs_extent_32_t efi_extents[]; /* array of extents to free */ } __attribute__((packed)) xfs_efi_log_format_32_t; +static inline size_t +xfs_efi_log_format32_sizeof( + unsigned int nr) +{ + return sizeof(struct xfs_efi_log_format_32) + + nr * sizeof(struct xfs_extent_32); +} + typedef struct xfs_efi_log_format_64 { uint16_t efi_type; /* efi log item type */ uint16_t efi_size; /* size of this item */ @@ -632,6 +648,14 @@ typedef struct xfs_efi_log_format_64 { xfs_extent_64_t efi_extents[]; /* array of extents to free */ } xfs_efi_log_format_64_t; +static inline size_t +xfs_efi_log_format64_sizeof( + unsigned int nr) +{ + return sizeof(struct xfs_efi_log_format_64) + + nr * sizeof(struct xfs_extent_64); +} + /* * This is the structure used to lay out an efd log item in the * log. The efd_extents array is a variable size array whose @@ -645,6 +669,14 @@ typedef struct xfs_efd_log_format { xfs_extent_t efd_extents[]; /* array of extents freed */ } xfs_efd_log_format_t; +static inline size_t +xfs_efd_log_format_sizeof( + unsigned int nr) +{ + return sizeof(struct xfs_efd_log_format) + + nr * sizeof(struct xfs_extent); +} + typedef struct xfs_efd_log_format_32 { uint16_t efd_type; /* efd log item type */ uint16_t efd_size; /* size of this item */ @@ -653,6 +685,14 @@ typedef struct xfs_efd_log_format_32 { xfs_extent_32_t efd_extents[]; /* array of extents freed */ } __attribute__((packed)) xfs_efd_log_format_32_t; +static inline size_t +xfs_efd_log_format32_sizeof( + unsigned int nr) +{ + return sizeof(struct xfs_efd_log_format_32) + + nr * sizeof(struct xfs_extent_32); +} + typedef struct xfs_efd_log_format_64 { uint16_t efd_type; /* efd log item type */ uint16_t efd_size; /* size of this item */ @@ -661,6 +701,14 @@ typedef struct xfs_efd_log_format_64 { xfs_extent_64_t efd_extents[]; /* array of extents freed */ } xfs_efd_log_format_64_t; +static inline size_t +xfs_efd_log_format64_sizeof( + unsigned int nr) +{ + return sizeof(struct xfs_efd_log_format_64) + + nr * sizeof(struct xfs_extent_64); +} + /* * RUI/RUD (reverse mapping) log format definitions */ diff --git a/logprint/log_redo.c b/logprint/log_redo.c index 12d041da1c..580abf9b15 100644 --- a/logprint/log_redo.c +++ b/logprint/log_redo.c @@ -20,9 +20,9 @@ xfs_efi_copy_format( { uint i; uint nextents = ((xfs_efi_log_format_t *)buf)->efi_nextents; - uint dst_len = sizeof(xfs_efi_log_format_t) + nextents * sizeof(xfs_extent_t); - uint len32 = sizeof(xfs_efi_log_format_32_t) + nextents * sizeof(xfs_extent_32_t); - uint len64 = sizeof(xfs_efi_log_format_64_t) + nextents * sizeof(xfs_extent_64_t); + uint dst_len = xfs_efi_log_format_sizeof(nextents); + uint len32 = xfs_efi_log_format32_sizeof(nextents); + uint len64 = xfs_efi_log_format64_sizeof(nextents); if (len == dst_len || continued) { memcpy((char *)dst_efi_fmt, buf, len); @@ -86,7 +86,7 @@ xlog_print_trans_efi( *ptr += src_len; /* convert to native format */ - dst_len = sizeof(xfs_efi_log_format_t) + src_f->efi_nextents * sizeof(xfs_extent_t); + dst_len = xfs_efi_log_format_sizeof(src_f->efi_nextents); if (continued && src_len < core_size) { printf(_("EFI: Not enough data to decode further\n")); From patchwork Wed Nov 9 02:06:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB1F7C433FE for ; Wed, 9 Nov 2022 02:06:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229591AbiKICGr (ORCPT ); Tue, 8 Nov 2022 21:06:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229700AbiKICGp (ORCPT ); Tue, 8 Nov 2022 21:06:45 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7922F68687 for ; Tue, 8 Nov 2022 18:06:45 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 158C0617FF for ; Wed, 9 Nov 2022 02:06:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7327AC43140; Wed, 9 Nov 2022 02:06:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959604; bh=1JVi/5pDan09LUFMVms/79Xz9MxLevnSIYOnUMTAPVw=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=b8JFM+fhbxH8Jy4M5WTWEWJncutU70gQO/RJL71Z5bCRqP5MmxpQjDqwk7ciU4PMQ Bb2u0xwVe3IEOrEV3S91Vg9BRGsPe1XV+mDRxuvUcNtcm2sAO0joYKTkYBeBxjQY57 /jxI/pJNQ9KfII7WjwXf0Xafn60AfFIaV6wStViJLGwOxUrtS3GzC11aSvKXPviCEU bQmIiFYlBUDfgco62F6MF2ywkW6ThRH3HZ0mJVO41WOuESquRXWesxa/C7FdgBzIYc zjYART5BEYsi5kGiRkWrY6RBbrepY8ZD/HQrBQNJ+2gSHQbEs8lUb31Sx0g6JPustS LzT3hH4QVwesw== Subject: [PATCH 11/24] xfs: make sure aglen never goes negative in xfs_refcount_adjust_extents From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:06:44 -0800 Message-ID: <166795960400.3761583.7960144983090565358.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 3a3a253f66c5d3ab2712a9d4794b457195a503d7 Prior to calling xfs_refcount_adjust_extents, we trimmed agbno/aglen such that the end of the range would not be in the middle of a refcount record. If this is no longer the case, something is seriously wrong with the btree. Bail out with a corruption error. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner --- libxfs/xfs_refcount.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index bcd760fe12..146e833b0d 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -985,15 +985,29 @@ xfs_refcount_adjust_extents( (*agbno) += tmp.rc_blockcount; (*aglen) -= tmp.rc_blockcount; + /* Stop if there's nothing left to modify */ + if (*aglen == 0 || !xfs_refcount_still_have_space(cur)) + break; + + /* Move the cursor to the start of ext. */ error = xfs_refcount_lookup_ge(cur, *agbno, &found_rec); if (error) goto out_error; } - /* Stop if there's nothing left to modify */ - if (*aglen == 0 || !xfs_refcount_still_have_space(cur)) - break; + /* + * A previous step trimmed agbno/aglen such that the end of the + * range would not be in the middle of the record. If this is + * no longer the case, something is seriously wrong with the + * btree. Make sure we never feed the synthesized record into + * the processing loop below. + */ + if (XFS_IS_CORRUPT(cur->bc_mp, ext.rc_blockcount == 0) || + XFS_IS_CORRUPT(cur->bc_mp, ext.rc_blockcount > *aglen)) { + error = -EFSCORRUPTED; + goto out_error; + } /* * Adjust the reference count and either update the tree From patchwork Wed Nov 9 02:06:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037065 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D1B8C433FE for ; Wed, 9 Nov 2022 02:06:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229470AbiKICGz (ORCPT ); Tue, 8 Nov 2022 21:06:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229610AbiKICGw (ORCPT ); Tue, 8 Nov 2022 21:06:52 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01BDD68AE3 for ; Tue, 8 Nov 2022 18:06:51 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 94B1B61882 for ; Wed, 9 Nov 2022 02:06:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3DAAC4314E; Wed, 9 Nov 2022 02:06:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959610; bh=XQU+SqyUb8sdTOQIqSN6fgw+9i9glN70NEMzoORQRHA=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=MC4DN1c0rqvhwmTffm47DhL+TZ6Yh6V0Yj49kvyk7v2oBaKuC89n31wmmYN4q47mk k0kSuZAEiBSOIXTTB2N8H/mOHMZqunxkvB01IECmdCbCkvSut/kF7A6zPfUq03Ofta RyJyqEZkE3cKU1Qw1mNyXwwUV2rQ0VZG3Z3q/ZVUXACblBhXkhZo7oHc6///afA63e wGMua3Z/dpQV9EF2dPGTa3D+QewYTy5L1P3S3yK4ObFCIO/XaxPS7O9pDrb19NPSrp qxNa/N7wysSKglLHwaGapcN3Rl3GFz/btTcbxEPcaiyMfuTzuRO3M+8hA/KNtlhF/N s5ZcsYNWqjCjA== Subject: [PATCH 12/24] xfs: create a predicate to verify per-AG extents From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:06:49 -0800 Message-ID: <166795960964.3761583.1986799629757742162.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: b332a16ce61f24b3392f5fc31f2a7be59d314ed4 Create a predicate function to verify that a given agbno/blockcount pair fit entirely within a single allocation group and don't suffer mathematical overflows. Refactor the existng open-coded logic; we're going to add more calls to this function in the next patch. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner --- libxfs/xfs_ag.h | 15 +++++++++++++++ libxfs/xfs_alloc.c | 6 +----- libxfs/xfs_refcount.c | 6 +----- libxfs/xfs_rmap.c | 9 ++------- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index 517a138faa..191b22b9a3 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -133,6 +133,21 @@ xfs_verify_agbno(struct xfs_perag *pag, xfs_agblock_t agbno) return true; } +static inline bool +xfs_verify_agbext( + struct xfs_perag *pag, + xfs_agblock_t agbno, + xfs_agblock_t len) +{ + if (agbno + len <= agbno) + return false; + + if (!xfs_verify_agbno(pag, agbno)) + return false; + + return xfs_verify_agbno(pag, agbno + len - 1); +} + /* * Verify that an AG inode number pointer neither points outside the AG * nor points at static metadata. diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c index 3e310ce3e5..8c2c2e832f 100644 --- a/libxfs/xfs_alloc.c +++ b/libxfs/xfs_alloc.c @@ -259,11 +259,7 @@ xfs_alloc_get_rec( goto out_bad_rec; /* check for valid extent range, including overflow */ - if (!xfs_verify_agbno(pag, *bno)) - goto out_bad_rec; - if (*bno > *bno + *len) - goto out_bad_rec; - if (!xfs_verify_agbno(pag, *bno + *len - 1)) + if (!xfs_verify_agbext(pag, *bno, *len)) goto out_bad_rec; return 0; diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 146e833b0d..c1ebc5047b 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -134,11 +134,7 @@ xfs_refcount_get_rec( } /* check for valid extent range, including overflow */ - if (!xfs_verify_agbno(pag, realstart)) - goto out_bad_rec; - if (realstart > realstart + irec->rc_blockcount) - goto out_bad_rec; - if (!xfs_verify_agbno(pag, realstart + irec->rc_blockcount - 1)) + if (!xfs_verify_agbext(pag, realstart, irec->rc_blockcount)) goto out_bad_rec; if (irec->rc_refcount == 0 || irec->rc_refcount > MAXREFCOUNT) diff --git a/libxfs/xfs_rmap.c b/libxfs/xfs_rmap.c index fa4ae8fca3..b3caff1da3 100644 --- a/libxfs/xfs_rmap.c +++ b/libxfs/xfs_rmap.c @@ -234,13 +234,8 @@ xfs_rmap_get_rec( goto out_bad_rec; } else { /* check for valid extent range, including overflow */ - if (!xfs_verify_agbno(pag, irec->rm_startblock)) - goto out_bad_rec; - if (irec->rm_startblock > - irec->rm_startblock + irec->rm_blockcount) - goto out_bad_rec; - if (!xfs_verify_agbno(pag, - irec->rm_startblock + irec->rm_blockcount - 1)) + if (!xfs_verify_agbext(pag, irec->rm_startblock, + irec->rm_blockcount)) goto out_bad_rec; } From patchwork Wed Nov 9 02:06:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037066 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5468C433FE for ; Wed, 9 Nov 2022 02:07:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229549AbiKICG7 (ORCPT ); Tue, 8 Nov 2022 21:06:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbiKICG7 (ORCPT ); Tue, 8 Nov 2022 21:06:59 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C4D96868A for ; Tue, 8 Nov 2022 18:06:58 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DAB8BB81CF3 for ; Wed, 9 Nov 2022 02:06:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85512C433D6; Wed, 9 Nov 2022 02:06:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959615; bh=7Dti90X9F2xuEvqdbFllmQsnBIgdgmOdToufiR1tiF4=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=QfCZPteQd83CG2Vevzn79ZAA7qz/tlM+4HYcX4apmWfcPjDfIRPH/PUS4UJpw3YmP iOYCiz0vQX2SHSIWbMj24/Bf+onMn45+xfrWikWT2W9KRmGWl0hdo3hixdY72nxr6g t9i+ApWlj+YE69+lvdIJ89nuQsby5RtIR4NArZ3MrJCdTqNjTQFfduUI+fZTLkhJes 5gwP4Rc1IGmYq1jywkUp/O+vU89dHWI8OI1M+BcUrvE9ygTPWo65lR3RHEy9vVQIXf HDxCdWT0/glUoDRgJldboF0OfbQMipVLsPVTst2ngDNlkMVBCiyRhbx80GNzDiUr4Z 3qWPyD8EgovDQ== Subject: [PATCH 13/24] xfs: check deferred refcount op continuation parameters From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:06:55 -0800 Message-ID: <166795961515.3761583.4388997331012220257.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 4fa6f60a07b5ef09691919459cd7f6405810d4c2 If we're in the middle of a deferred refcount operation and decide to roll the transaction to avoid overflowing the transaction space, we need to check the new agbno/aglen parameters that we're about to record in the new intent. Specifically, we need to check that the new extent is completely within the filesystem, and that continuation does not put us into a different AG. If the keys of a node block are wrong, the lookup to resume an xfs_refcount_adjust_extents operation can put us into the wrong record block. If this happens, we might not find that we run out of aglen at an exact record boundary, which will cause the loop control to do the wrong thing. The previous patch should take care of that problem, but let's add this extra sanity check to stop corruption problems sooner than later. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner --- libxfs/xfs_refcount.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index c1ebc5047b..5ba8241998 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -1133,6 +1133,32 @@ xfs_refcount_finish_one_cleanup( xfs_trans_brelse(tp, agbp); } +/* + * Set up a continuation a deferred refcount operation by updating the intent. + * Checks to make sure we're not going to run off the end of the AG. + */ +static inline int +xfs_refcount_continue_op( + struct xfs_btree_cur *cur, + xfs_fsblock_t startblock, + xfs_agblock_t new_agbno, + xfs_extlen_t new_len, + xfs_fsblock_t *new_fsbno) +{ + struct xfs_mount *mp = cur->bc_mp; + struct xfs_perag *pag = cur->bc_ag.pag; + + if (XFS_IS_CORRUPT(mp, !xfs_verify_agbext(pag, new_agbno, new_len))) + return -EFSCORRUPTED; + + *new_fsbno = XFS_AGB_TO_FSB(mp, pag->pag_agno, new_agbno); + + ASSERT(xfs_verify_fsbext(mp, *new_fsbno, new_len)); + ASSERT(pag->pag_agno == XFS_FSB_TO_AGNO(mp, *new_fsbno)); + + return 0; +} + /* * Process one of the deferred refcount operations. We pass back the * btree cursor to maintain our lock on the btree between calls. @@ -1200,12 +1226,20 @@ xfs_refcount_finish_one( case XFS_REFCOUNT_INCREASE: error = xfs_refcount_adjust(rcur, bno, blockcount, &new_agbno, new_len, XFS_REFCOUNT_ADJUST_INCREASE); - *new_fsb = XFS_AGB_TO_FSB(mp, pag->pag_agno, new_agbno); + if (error) + goto out_drop; + if (*new_len > 0) + error = xfs_refcount_continue_op(rcur, startblock, + new_agbno, *new_len, new_fsb); break; case XFS_REFCOUNT_DECREASE: error = xfs_refcount_adjust(rcur, bno, blockcount, &new_agbno, new_len, XFS_REFCOUNT_ADJUST_DECREASE); - *new_fsb = XFS_AGB_TO_FSB(mp, pag->pag_agno, new_agbno); + if (error) + goto out_drop; + if (*new_len > 0) + error = xfs_refcount_continue_op(rcur, startblock, + new_agbno, *new_len, new_fsb); break; case XFS_REFCOUNT_ALLOC_COW: *new_fsb = startblock + blockcount; From patchwork Wed Nov 9 02:07:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037067 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C66D9C433FE for ; Wed, 9 Nov 2022 02:07:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229700AbiKICHD (ORCPT ); Tue, 8 Nov 2022 21:07:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229689AbiKICHC (ORCPT ); Tue, 8 Nov 2022 21:07:02 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A261682B9 for ; Tue, 8 Nov 2022 18:07:02 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B9F90617EF for ; Wed, 9 Nov 2022 02:07:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2768DC433C1; Wed, 9 Nov 2022 02:07:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959621; bh=7NuPoWIjVsv8VNqlenre8l/ESDvUXptBR783ikn3+4c=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=OaUUjrHbHEB045uxwKm4CxGwUt+wvd+O2NIYn3IOraSsHgBxG0rP+IS2hpNvw36rU dmGwVTLtkK8A7Lk98yLVshAfX1et4NifA77lccAEg3PAn497lRQLKAFi3BPXG7SLSl ltWFJK4awg4A7PMABcAM8wXXvD8znXn2RsenTz2p72pHTO+S8Hbrirbp1QJlNFD032 WTuvcjDFaZsTs7a0R7dtI89HmEHlH27kQUjVkoVy1IXFWGT3QiK8HT7T1/crOgPJQy hIMqizjiswaYboGdpwc/Qhr18kv0+cR5zBxEcqH+txl+vzOyAomHzp2GZBOW/B1NhW zyJau9do7Rn3w== Subject: [PATCH 14/24] xfs: move _irec structs to xfs_types.h From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:07:00 -0800 Message-ID: <166795962070.3761583.2162344429822338243.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 61373167ce829d5805c07a86416cb9b4d5c4a3bb Structure definitions for incore objects do not belong in the ondisk format header. Move them to the incore types header where they belong. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner --- libxfs/xfs_format.h | 20 -------------------- libxfs/xfs_types.h | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index b55bdfa9c8..005dd65b71 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -1564,20 +1564,6 @@ struct xfs_rmap_rec { #define RMAPBT_UNUSED_OFFSET_BITLEN 7 #define RMAPBT_OFFSET_BITLEN 54 -#define XFS_RMAP_ATTR_FORK (1 << 0) -#define XFS_RMAP_BMBT_BLOCK (1 << 1) -#define XFS_RMAP_UNWRITTEN (1 << 2) -#define XFS_RMAP_KEY_FLAGS (XFS_RMAP_ATTR_FORK | \ - XFS_RMAP_BMBT_BLOCK) -#define XFS_RMAP_REC_FLAGS (XFS_RMAP_UNWRITTEN) -struct xfs_rmap_irec { - xfs_agblock_t rm_startblock; /* extent start block */ - xfs_extlen_t rm_blockcount; /* extent length */ - uint64_t rm_owner; /* extent owner */ - uint64_t rm_offset; /* offset within the owner */ - unsigned int rm_flags; /* state flags */ -}; - /* * Key structure * @@ -1640,12 +1626,6 @@ struct xfs_refcount_key { __be32 rc_startblock; /* starting block number */ }; -struct xfs_refcount_irec { - xfs_agblock_t rc_startblock; /* starting block number */ - xfs_extlen_t rc_blockcount; /* count of free blocks */ - xfs_nlink_t rc_refcount; /* number of inodes linked here */ -}; - #define MAXREFCOUNT ((xfs_nlink_t)~0U) #define MAXREFCEXTLEN ((xfs_extlen_t)~0U) diff --git a/libxfs/xfs_types.h b/libxfs/xfs_types.h index a6b7d98cf6..2d9ebc7338 100644 --- a/libxfs/xfs_types.h +++ b/libxfs/xfs_types.h @@ -166,6 +166,26 @@ typedef struct xfs_bmbt_irec xfs_exntst_t br_state; /* extent state */ } xfs_bmbt_irec_t; +struct xfs_refcount_irec { + xfs_agblock_t rc_startblock; /* starting block number */ + xfs_extlen_t rc_blockcount; /* count of free blocks */ + xfs_nlink_t rc_refcount; /* number of inodes linked here */ +}; + +#define XFS_RMAP_ATTR_FORK (1 << 0) +#define XFS_RMAP_BMBT_BLOCK (1 << 1) +#define XFS_RMAP_UNWRITTEN (1 << 2) +#define XFS_RMAP_KEY_FLAGS (XFS_RMAP_ATTR_FORK | \ + XFS_RMAP_BMBT_BLOCK) +#define XFS_RMAP_REC_FLAGS (XFS_RMAP_UNWRITTEN) +struct xfs_rmap_irec { + xfs_agblock_t rm_startblock; /* extent start block */ + xfs_extlen_t rm_blockcount; /* extent length */ + uint64_t rm_owner; /* extent owner */ + uint64_t rm_offset; /* offset within the owner */ + unsigned int rm_flags; /* state flags */ +}; + /* per-AG block reservation types */ enum xfs_ag_resv_type { XFS_AG_RESV_NONE = 0, From patchwork Wed Nov 9 02:07:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037068 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFA73C433FE for ; Wed, 9 Nov 2022 02:07:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229689AbiKICHK (ORCPT ); Tue, 8 Nov 2022 21:07:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229610AbiKICHJ (ORCPT ); Tue, 8 Nov 2022 21:07:09 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C00C268687 for ; Tue, 8 Nov 2022 18:07:07 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4CB5161808 for ; Wed, 9 Nov 2022 02:07:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A67EEC433C1; Wed, 9 Nov 2022 02:07:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959626; bh=Y7RBzALXikoH3Q6b+Z+F4HjC7yU5G8xloiq2poNWUTU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=LbS1QKKo70cctXr+mD8+vlRw2QxO6nsEmzYZvxPk2X43iDrhfT7eqZEPGxYBJ3yzm Qhjt32ovzN5Chz2CZKDHrztuH6AqIHSvHdStXK7hBqbpvAM1858f8uDw033WfxFJ+J 8ep+xZZekyQAfyHLUkDLusxYIN77N0kecnsxzuj7wT/D5cF1Gsj9TBwJNpq7LKHYFj 1oNJr2KN/UOZl4RarGrSCVs9XOCHmOH371tgHJUl3ydE+qDc0xfFvZveOkK31RlRm6 meOdqFfwi47u/tIRpUMzy7V8h43qeqssRKHI2e0fae/kT5tK1BV5Ilbema5JAWaq0j xN6nDfY4gTt1A== Subject: [PATCH 15/24] xfs: track cow/shared record domains explicitly in xfs_refcount_irec From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:07:06 -0800 Message-ID: <166795962631.3761583.16845808206856458930.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 0c1c2c41f40453ff9fa24cbbd3d3784dff67fe81 Just prior to committing the reflink code into upstream, the xfs maintainer at the time requested that I find a way to shard the refcount records into two domains -- one for records tracking shared extents, and a second for tracking CoW staging extents. The idea here was to minimize mount time CoW reclamation by pushing all the CoW records to the right edge of the keyspace, and it was accomplished by setting the upper bit in rc_startblock. We don't allow AGs to have more than 2^31 blocks, so the bit was free. Unfortunately, this was a very late addition to the codebase, so most of the refcount record processing code still treats rc_startblock as a u32 and pays no attention to whether or not the upper bit (the cow flag) is set. This is a weakness is theoretically exploitable, since we're not fully validating the incoming metadata records. Fuzzing demonstrates practical exploits of this weakness. If the cow flag of a node block key record is corrupted, a lookup operation can go to the wrong record block and start returning records from the wrong cow/shared domain. This causes the math to go all wrong (since cow domain is still implicit in the upper bit of rc_startblock) and we can crash the kernel by tricking xfs into jumping into a nonexistent AG and tripping over xfs_perag_get(mp, ) returning NULL. To fix this, start tracking the domain as an explicit part of struct xfs_refcount_irec, adjust all refcount functions to check the domain of a returned record, and alter the function definitions to accept them where necessary. Found by fuzzing keys[2].cowflag = add in xfs/464. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner --- libxfs/xfs_refcount.c | 146 +++++++++++++++++++++++++++++-------------- libxfs/xfs_refcount.h | 28 +++++++- libxfs/xfs_refcount_btree.c | 15 ++++ libxfs/xfs_types.h | 6 ++ repair/rmap.c | 18 ++++- 5 files changed, 155 insertions(+), 58 deletions(-) diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 5ba8241998..7094a27dce 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -45,13 +45,16 @@ STATIC int __xfs_refcount_cow_free(struct xfs_btree_cur *rcur, int xfs_refcount_lookup_le( struct xfs_btree_cur *cur, + enum xfs_refc_domain domain, xfs_agblock_t bno, int *stat) { - trace_xfs_refcount_lookup(cur->bc_mp, cur->bc_ag.pag->pag_agno, bno, + trace_xfs_refcount_lookup(cur->bc_mp, cur->bc_ag.pag->pag_agno, + xfs_refcount_encode_startblock(bno, domain), XFS_LOOKUP_LE); cur->bc_rec.rc.rc_startblock = bno; cur->bc_rec.rc.rc_blockcount = 0; + cur->bc_rec.rc.rc_domain = domain; return xfs_btree_lookup(cur, XFS_LOOKUP_LE, stat); } @@ -62,13 +65,16 @@ xfs_refcount_lookup_le( int xfs_refcount_lookup_ge( struct xfs_btree_cur *cur, + enum xfs_refc_domain domain, xfs_agblock_t bno, int *stat) { - trace_xfs_refcount_lookup(cur->bc_mp, cur->bc_ag.pag->pag_agno, bno, + trace_xfs_refcount_lookup(cur->bc_mp, cur->bc_ag.pag->pag_agno, + xfs_refcount_encode_startblock(bno, domain), XFS_LOOKUP_GE); cur->bc_rec.rc.rc_startblock = bno; cur->bc_rec.rc.rc_blockcount = 0; + cur->bc_rec.rc.rc_domain = domain; return xfs_btree_lookup(cur, XFS_LOOKUP_GE, stat); } @@ -79,13 +85,16 @@ xfs_refcount_lookup_ge( int xfs_refcount_lookup_eq( struct xfs_btree_cur *cur, + enum xfs_refc_domain domain, xfs_agblock_t bno, int *stat) { - trace_xfs_refcount_lookup(cur->bc_mp, cur->bc_ag.pag->pag_agno, bno, + trace_xfs_refcount_lookup(cur->bc_mp, cur->bc_ag.pag->pag_agno, + xfs_refcount_encode_startblock(bno, domain), XFS_LOOKUP_LE); cur->bc_rec.rc.rc_startblock = bno; cur->bc_rec.rc.rc_blockcount = 0; + cur->bc_rec.rc.rc_domain = domain; return xfs_btree_lookup(cur, XFS_LOOKUP_EQ, stat); } @@ -95,7 +104,17 @@ xfs_refcount_btrec_to_irec( const union xfs_btree_rec *rec, struct xfs_refcount_irec *irec) { - irec->rc_startblock = be32_to_cpu(rec->refc.rc_startblock); + uint32_t start; + + start = be32_to_cpu(rec->refc.rc_startblock); + if (start & XFS_REFC_COW_START) { + start &= ~XFS_REFC_COW_START; + irec->rc_domain = XFS_REFC_DOMAIN_COW; + } else { + irec->rc_domain = XFS_REFC_DOMAIN_SHARED; + } + + irec->rc_startblock = start; irec->rc_blockcount = be32_to_cpu(rec->refc.rc_blockcount); irec->rc_refcount = be32_to_cpu(rec->refc.rc_refcount); } @@ -113,7 +132,6 @@ xfs_refcount_get_rec( struct xfs_perag *pag = cur->bc_ag.pag; union xfs_btree_rec *rec; int error; - xfs_agblock_t realstart; error = xfs_btree_get_rec(cur, &rec, stat); if (error || !*stat) @@ -123,18 +141,14 @@ xfs_refcount_get_rec( if (irec->rc_blockcount == 0 || irec->rc_blockcount > MAXREFCEXTLEN) goto out_bad_rec; - /* handle special COW-staging state */ - realstart = irec->rc_startblock; - if (realstart & XFS_REFC_COW_START) { - if (irec->rc_refcount != 1) - goto out_bad_rec; - realstart &= ~XFS_REFC_COW_START; - } else if (irec->rc_refcount < 2) { + /* handle special COW-staging domain */ + if (irec->rc_domain == XFS_REFC_DOMAIN_COW && irec->rc_refcount != 1) + goto out_bad_rec; + if (irec->rc_domain == XFS_REFC_DOMAIN_SHARED && irec->rc_refcount < 2) goto out_bad_rec; - } /* check for valid extent range, including overflow */ - if (!xfs_verify_agbext(pag, realstart, irec->rc_blockcount)) + if (!xfs_verify_agbext(pag, irec->rc_startblock, irec->rc_blockcount)) goto out_bad_rec; if (irec->rc_refcount == 0 || irec->rc_refcount > MAXREFCOUNT) @@ -164,12 +178,17 @@ xfs_refcount_update( struct xfs_refcount_irec *irec) { union xfs_btree_rec rec; + uint32_t start; int error; trace_xfs_refcount_update(cur->bc_mp, cur->bc_ag.pag->pag_agno, irec); - rec.refc.rc_startblock = cpu_to_be32(irec->rc_startblock); + + start = xfs_refcount_encode_startblock(irec->rc_startblock, + irec->rc_domain); + rec.refc.rc_startblock = cpu_to_be32(start); rec.refc.rc_blockcount = cpu_to_be32(irec->rc_blockcount); rec.refc.rc_refcount = cpu_to_be32(irec->rc_refcount); + error = xfs_btree_update(cur, &rec); if (error) trace_xfs_refcount_update_error(cur->bc_mp, @@ -191,9 +210,12 @@ xfs_refcount_insert( int error; trace_xfs_refcount_insert(cur->bc_mp, cur->bc_ag.pag->pag_agno, irec); + cur->bc_rec.rc.rc_startblock = irec->rc_startblock; cur->bc_rec.rc.rc_blockcount = irec->rc_blockcount; cur->bc_rec.rc.rc_refcount = irec->rc_refcount; + cur->bc_rec.rc.rc_domain = irec->rc_domain; + error = xfs_btree_insert(cur, i); if (error) goto out_error; @@ -239,7 +261,8 @@ xfs_refcount_delete( } if (error) goto out_error; - error = xfs_refcount_lookup_ge(cur, irec.rc_startblock, &found_rec); + error = xfs_refcount_lookup_ge(cur, irec.rc_domain, irec.rc_startblock, + &found_rec); out_error: if (error) trace_xfs_refcount_delete_error(cur->bc_mp, @@ -338,6 +361,7 @@ xfs_refc_next( STATIC int xfs_refcount_split_extent( struct xfs_btree_cur *cur, + enum xfs_refc_domain domain, xfs_agblock_t agbno, bool *shape_changed) { @@ -346,7 +370,7 @@ xfs_refcount_split_extent( int error; *shape_changed = false; - error = xfs_refcount_lookup_le(cur, agbno, &found_rec); + error = xfs_refcount_lookup_le(cur, domain, agbno, &found_rec); if (error) goto out_error; if (!found_rec) @@ -418,8 +442,8 @@ xfs_refcount_merge_center_extents( * call removes the center and the second one removes the right * extent. */ - error = xfs_refcount_lookup_ge(cur, center->rc_startblock, - &found_rec); + error = xfs_refcount_lookup_ge(cur, center->rc_domain, + center->rc_startblock, &found_rec); if (error) goto out_error; if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) { @@ -446,8 +470,8 @@ xfs_refcount_merge_center_extents( } /* Enlarge the left extent. */ - error = xfs_refcount_lookup_le(cur, left->rc_startblock, - &found_rec); + error = xfs_refcount_lookup_le(cur, left->rc_domain, + left->rc_startblock, &found_rec); if (error) goto out_error; if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) { @@ -488,8 +512,8 @@ xfs_refcount_merge_left_extent( /* If the extent at agbno (cleft) wasn't synthesized, remove it. */ if (cleft->rc_refcount > 1) { - error = xfs_refcount_lookup_le(cur, cleft->rc_startblock, - &found_rec); + error = xfs_refcount_lookup_le(cur, cleft->rc_domain, + cleft->rc_startblock, &found_rec); if (error) goto out_error; if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) { @@ -507,8 +531,8 @@ xfs_refcount_merge_left_extent( } /* Enlarge the left extent. */ - error = xfs_refcount_lookup_le(cur, left->rc_startblock, - &found_rec); + error = xfs_refcount_lookup_le(cur, left->rc_domain, + left->rc_startblock, &found_rec); if (error) goto out_error; if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) { @@ -552,8 +576,8 @@ xfs_refcount_merge_right_extent( * remove it. */ if (cright->rc_refcount > 1) { - error = xfs_refcount_lookup_le(cur, cright->rc_startblock, - &found_rec); + error = xfs_refcount_lookup_le(cur, cright->rc_domain, + cright->rc_startblock, &found_rec); if (error) goto out_error; if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) { @@ -571,8 +595,8 @@ xfs_refcount_merge_right_extent( } /* Enlarge the right extent. */ - error = xfs_refcount_lookup_le(cur, right->rc_startblock, - &found_rec); + error = xfs_refcount_lookup_le(cur, right->rc_domain, + right->rc_startblock, &found_rec); if (error) goto out_error; if (XFS_IS_CORRUPT(cur->bc_mp, found_rec != 1)) { @@ -611,11 +635,17 @@ xfs_refcount_find_left_extents( int flags) { struct xfs_refcount_irec tmp; + enum xfs_refc_domain domain; int error; int found_rec; + if (flags & XFS_FIND_RCEXT_SHARED) + domain = XFS_REFC_DOMAIN_SHARED; + else + domain = XFS_REFC_DOMAIN_COW; + left->rc_startblock = cleft->rc_startblock = NULLAGBLOCK; - error = xfs_refcount_lookup_le(cur, agbno - 1, &found_rec); + error = xfs_refcount_lookup_le(cur, domain, agbno - 1, &found_rec); if (error) goto out_error; if (!found_rec) @@ -666,6 +696,7 @@ xfs_refcount_find_left_extents( cleft->rc_blockcount = min(aglen, tmp.rc_startblock - agbno); cleft->rc_refcount = 1; + cleft->rc_domain = domain; } } else { /* @@ -675,6 +706,7 @@ xfs_refcount_find_left_extents( cleft->rc_startblock = agbno; cleft->rc_blockcount = aglen; cleft->rc_refcount = 1; + cleft->rc_domain = domain; } trace_xfs_refcount_find_left_extent(cur->bc_mp, cur->bc_ag.pag->pag_agno, left, cleft, agbno); @@ -700,11 +732,17 @@ xfs_refcount_find_right_extents( int flags) { struct xfs_refcount_irec tmp; + enum xfs_refc_domain domain; int error; int found_rec; + if (flags & XFS_FIND_RCEXT_SHARED) + domain = XFS_REFC_DOMAIN_SHARED; + else + domain = XFS_REFC_DOMAIN_COW; + right->rc_startblock = cright->rc_startblock = NULLAGBLOCK; - error = xfs_refcount_lookup_ge(cur, agbno + aglen, &found_rec); + error = xfs_refcount_lookup_ge(cur, domain, agbno + aglen, &found_rec); if (error) goto out_error; if (!found_rec) @@ -755,6 +793,7 @@ xfs_refcount_find_right_extents( cright->rc_blockcount = right->rc_startblock - cright->rc_startblock; cright->rc_refcount = 1; + cright->rc_domain = domain; } } else { /* @@ -764,6 +803,7 @@ xfs_refcount_find_right_extents( cright->rc_startblock = agbno; cright->rc_blockcount = aglen; cright->rc_refcount = 1; + cright->rc_domain = domain; } trace_xfs_refcount_find_right_extent(cur->bc_mp, cur->bc_ag.pag->pag_agno, cright, right, agbno + aglen); @@ -928,7 +968,8 @@ xfs_refcount_adjust_extents( if (*aglen == 0) return 0; - error = xfs_refcount_lookup_ge(cur, *agbno, &found_rec); + error = xfs_refcount_lookup_ge(cur, XFS_REFC_DOMAIN_SHARED, *agbno, + &found_rec); if (error) goto out_error; @@ -940,6 +981,7 @@ xfs_refcount_adjust_extents( ext.rc_startblock = cur->bc_mp->m_sb.sb_agblocks; ext.rc_blockcount = 0; ext.rc_refcount = 0; + ext.rc_domain = XFS_REFC_DOMAIN_SHARED; } /* @@ -952,6 +994,8 @@ xfs_refcount_adjust_extents( tmp.rc_blockcount = min(*aglen, ext.rc_startblock - *agbno); tmp.rc_refcount = 1 + adj; + tmp.rc_domain = XFS_REFC_DOMAIN_SHARED; + trace_xfs_refcount_modify_extent(cur->bc_mp, cur->bc_ag.pag->pag_agno, &tmp); @@ -986,7 +1030,8 @@ xfs_refcount_adjust_extents( break; /* Move the cursor to the start of ext. */ - error = xfs_refcount_lookup_ge(cur, *agbno, + error = xfs_refcount_lookup_ge(cur, + XFS_REFC_DOMAIN_SHARED, *agbno, &found_rec); if (error) goto out_error; @@ -1079,13 +1124,15 @@ xfs_refcount_adjust( /* * Ensure that no rcextents cross the boundary of the adjustment range. */ - error = xfs_refcount_split_extent(cur, agbno, &shape_changed); + error = xfs_refcount_split_extent(cur, XFS_REFC_DOMAIN_SHARED, + agbno, &shape_changed); if (error) goto out_error; if (shape_changed) shape_changes++; - error = xfs_refcount_split_extent(cur, agbno + aglen, &shape_changed); + error = xfs_refcount_split_extent(cur, XFS_REFC_DOMAIN_SHARED, + agbno + aglen, &shape_changed); if (error) goto out_error; if (shape_changed) @@ -1350,7 +1397,8 @@ xfs_refcount_find_shared( *flen = 0; /* Try to find a refcount extent that crosses the start */ - error = xfs_refcount_lookup_le(cur, agbno, &have); + error = xfs_refcount_lookup_le(cur, XFS_REFC_DOMAIN_SHARED, agbno, + &have); if (error) goto out_error; if (!have) { @@ -1498,17 +1546,18 @@ xfs_refcount_adjust_cow_extents( return 0; /* Find any overlapping refcount records */ - error = xfs_refcount_lookup_ge(cur, agbno, &found_rec); + error = xfs_refcount_lookup_ge(cur, XFS_REFC_DOMAIN_COW, agbno, + &found_rec); if (error) goto out_error; error = xfs_refcount_get_rec(cur, &ext, &found_rec); if (error) goto out_error; if (!found_rec) { - ext.rc_startblock = cur->bc_mp->m_sb.sb_agblocks + - XFS_REFC_COW_START; + ext.rc_startblock = cur->bc_mp->m_sb.sb_agblocks; ext.rc_blockcount = 0; ext.rc_refcount = 0; + ext.rc_domain = XFS_REFC_DOMAIN_COW; } switch (adj) { @@ -1523,6 +1572,8 @@ xfs_refcount_adjust_cow_extents( tmp.rc_startblock = agbno; tmp.rc_blockcount = aglen; tmp.rc_refcount = 1; + tmp.rc_domain = XFS_REFC_DOMAIN_COW; + trace_xfs_refcount_modify_extent(cur->bc_mp, cur->bc_ag.pag->pag_agno, &tmp); @@ -1585,16 +1636,16 @@ xfs_refcount_adjust_cow( bool shape_changed; int error; - agbno += XFS_REFC_COW_START; - /* * Ensure that no rcextents cross the boundary of the adjustment range. */ - error = xfs_refcount_split_extent(cur, agbno, &shape_changed); + error = xfs_refcount_split_extent(cur, XFS_REFC_DOMAIN_COW, + agbno, &shape_changed); if (error) goto out_error; - error = xfs_refcount_split_extent(cur, agbno + aglen, &shape_changed); + error = xfs_refcount_split_extent(cur, XFS_REFC_DOMAIN_COW, + agbno + aglen, &shape_changed); if (error) goto out_error; @@ -1730,7 +1781,6 @@ xfs_refcount_recover_cow_leftovers( union xfs_btree_irec low; union xfs_btree_irec high; xfs_fsblock_t fsb; - xfs_agblock_t agbno; int error; if (mp->m_sb.sb_agblocks >= XFS_REFC_COW_START) @@ -1760,7 +1810,7 @@ xfs_refcount_recover_cow_leftovers( /* Find all the leftover CoW staging extents. */ memset(&low, 0, sizeof(low)); memset(&high, 0, sizeof(high)); - low.rc.rc_startblock = XFS_REFC_COW_START; + low.rc.rc_domain = high.rc.rc_domain = XFS_REFC_DOMAIN_COW; high.rc.rc_startblock = -1U; error = xfs_btree_query_range(cur, &low, &high, xfs_refcount_recover_extent, &debris); @@ -1781,8 +1831,8 @@ xfs_refcount_recover_cow_leftovers( &rr->rr_rrec); /* Free the orphan record */ - agbno = rr->rr_rrec.rc_startblock - XFS_REFC_COW_START; - fsb = XFS_AGB_TO_FSB(mp, pag->pag_agno, agbno); + fsb = XFS_AGB_TO_FSB(mp, pag->pag_agno, + rr->rr_rrec.rc_startblock); xfs_refcount_free_cow_extent(tp, fsb, rr->rr_rrec.rc_blockcount); @@ -1813,6 +1863,7 @@ xfs_refcount_recover_cow_leftovers( int xfs_refcount_has_record( struct xfs_btree_cur *cur, + enum xfs_refc_domain domain, xfs_agblock_t bno, xfs_extlen_t len, bool *exists) @@ -1824,6 +1875,7 @@ xfs_refcount_has_record( low.rc.rc_startblock = bno; memset(&high, 0xFF, sizeof(high)); high.rc.rc_startblock = bno + len - 1; + low.rc.rc_domain = high.rc.rc_domain = domain; return xfs_btree_has_record(cur, &low, &high, exists); } diff --git a/libxfs/xfs_refcount.h b/libxfs/xfs_refcount.h index e8b322de7f..3beb5a30a9 100644 --- a/libxfs/xfs_refcount.h +++ b/libxfs/xfs_refcount.h @@ -14,14 +14,33 @@ struct xfs_bmbt_irec; struct xfs_refcount_irec; extern int xfs_refcount_lookup_le(struct xfs_btree_cur *cur, - xfs_agblock_t bno, int *stat); + enum xfs_refc_domain domain, xfs_agblock_t bno, int *stat); extern int xfs_refcount_lookup_ge(struct xfs_btree_cur *cur, - xfs_agblock_t bno, int *stat); + enum xfs_refc_domain domain, xfs_agblock_t bno, int *stat); extern int xfs_refcount_lookup_eq(struct xfs_btree_cur *cur, - xfs_agblock_t bno, int *stat); + enum xfs_refc_domain domain, xfs_agblock_t bno, int *stat); extern int xfs_refcount_get_rec(struct xfs_btree_cur *cur, struct xfs_refcount_irec *irec, int *stat); +static inline uint32_t +xfs_refcount_encode_startblock( + xfs_agblock_t startblock, + enum xfs_refc_domain domain) +{ + uint32_t start; + + /* + * low level btree operations need to handle the generic btree range + * query functions (which set rc_domain == -1U), so we check that the + * domain is /not/ shared. + */ + start = startblock & ~XFS_REFC_COW_START; + if (domain != XFS_REFC_DOMAIN_SHARED) + start |= XFS_REFC_COW_START; + + return start; +} + enum xfs_refcount_intent_type { XFS_REFCOUNT_INCREASE = 1, XFS_REFCOUNT_DECREASE, @@ -79,7 +98,8 @@ extern int xfs_refcount_recover_cow_leftovers(struct xfs_mount *mp, #define XFS_REFCOUNT_ITEM_OVERHEAD 32 extern int xfs_refcount_has_record(struct xfs_btree_cur *cur, - xfs_agblock_t bno, xfs_extlen_t len, bool *exists); + enum xfs_refc_domain domain, xfs_agblock_t bno, + xfs_extlen_t len, bool *exists); union xfs_btree_rec; extern void xfs_refcount_btrec_to_irec(const union xfs_btree_rec *rec, struct xfs_refcount_irec *irec); diff --git a/libxfs/xfs_refcount_btree.c b/libxfs/xfs_refcount_btree.c index 0707cbc024..983d4276d1 100644 --- a/libxfs/xfs_refcount_btree.c +++ b/libxfs/xfs_refcount_btree.c @@ -13,6 +13,7 @@ #include "xfs_btree.h" #include "xfs_btree_staging.h" #include "xfs_refcount_btree.h" +#include "xfs_refcount.h" #include "xfs_alloc.h" #include "xfs_trace.h" #include "xfs_trans.h" @@ -159,7 +160,12 @@ xfs_refcountbt_init_rec_from_cur( struct xfs_btree_cur *cur, union xfs_btree_rec *rec) { - rec->refc.rc_startblock = cpu_to_be32(cur->bc_rec.rc.rc_startblock); + const struct xfs_refcount_irec *irec = &cur->bc_rec.rc; + uint32_t start; + + start = xfs_refcount_encode_startblock(irec->rc_startblock, + irec->rc_domain); + rec->refc.rc_startblock = cpu_to_be32(start); rec->refc.rc_blockcount = cpu_to_be32(cur->bc_rec.rc.rc_blockcount); rec->refc.rc_refcount = cpu_to_be32(cur->bc_rec.rc.rc_refcount); } @@ -181,10 +187,13 @@ xfs_refcountbt_key_diff( struct xfs_btree_cur *cur, const union xfs_btree_key *key) { - struct xfs_refcount_irec *rec = &cur->bc_rec.rc; const struct xfs_refcount_key *kp = &key->refc; + const struct xfs_refcount_irec *irec = &cur->bc_rec.rc; + uint32_t start; - return (int64_t)be32_to_cpu(kp->rc_startblock) - rec->rc_startblock; + start = xfs_refcount_encode_startblock(irec->rc_startblock, + irec->rc_domain); + return (int64_t)be32_to_cpu(kp->rc_startblock) - start; } STATIC int64_t diff --git a/libxfs/xfs_types.h b/libxfs/xfs_types.h index 2d9ebc7338..eb9a98338b 100644 --- a/libxfs/xfs_types.h +++ b/libxfs/xfs_types.h @@ -166,10 +166,16 @@ typedef struct xfs_bmbt_irec xfs_exntst_t br_state; /* extent state */ } xfs_bmbt_irec_t; +enum xfs_refc_domain { + XFS_REFC_DOMAIN_SHARED = 0, + XFS_REFC_DOMAIN_COW, +}; + struct xfs_refcount_irec { xfs_agblock_t rc_startblock; /* starting block number */ xfs_extlen_t rc_blockcount; /* count of free blocks */ xfs_nlink_t rc_refcount; /* number of inodes linked here */ + enum xfs_refc_domain rc_domain; /* shared or cow staging extent? */ }; #define XFS_RMAP_ATTR_FORK (1 << 0) diff --git a/repair/rmap.c b/repair/rmap.c index a7c4b25b1f..2c809fd4f2 100644 --- a/repair/rmap.c +++ b/repair/rmap.c @@ -734,6 +734,8 @@ refcount_emit( rlrec.rc_startblock = agbno; rlrec.rc_blockcount = len; rlrec.rc_refcount = REFCOUNT_CLAMP(nr_rmaps); + rlrec.rc_domain = XFS_REFC_DOMAIN_SHARED; + error = slab_add(rlslab, &rlrec); if (error) do_error( @@ -1393,7 +1395,8 @@ check_refcounts( while (rl_rec) { /* Look for a refcount record in the btree */ error = -libxfs_refcount_lookup_le(bt_cur, - rl_rec->rc_startblock, &have); + XFS_REFC_DOMAIN_SHARED, rl_rec->rc_startblock, + &have); if (error) { do_warn( _("Could not read reference count record for (%u/%u).\n"), @@ -1424,14 +1427,21 @@ _("Missing reference count record for (%u/%u) len %u count %u\n"), } /* Compare each refcount observation against the btree's */ - if (tmp.rc_startblock != rl_rec->rc_startblock || + if (tmp.rc_domain != rl_rec->rc_domain || + tmp.rc_startblock != rl_rec->rc_startblock || tmp.rc_blockcount != rl_rec->rc_blockcount || - tmp.rc_refcount != rl_rec->rc_refcount) + tmp.rc_refcount != rl_rec->rc_refcount) { + unsigned int start; + + start = xfs_refcount_encode_startblock( + tmp.rc_startblock, tmp.rc_domain); + do_warn( _("Incorrect reference count: saw (%u/%u) len %u nlinks %u; should be (%u/%u) len %u nlinks %u\n"), - agno, tmp.rc_startblock, tmp.rc_blockcount, + agno, start, tmp.rc_blockcount, tmp.rc_refcount, agno, rl_rec->rc_startblock, rl_rec->rc_blockcount, rl_rec->rc_refcount); + } next_loop: rl_rec = pop_slab_cursor(rl_cur); } From patchwork Wed Nov 9 02:07:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037069 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E4C7C4332F for ; Wed, 9 Nov 2022 02:07:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229600AbiKICHQ (ORCPT ); Tue, 8 Nov 2022 21:07:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229735AbiKICHP (ORCPT ); Tue, 8 Nov 2022 21:07:15 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D89FF68687 for ; Tue, 8 Nov 2022 18:07:14 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 960B2B81CF4 for ; Wed, 9 Nov 2022 02:07:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42AF7C433D7; Wed, 9 Nov 2022 02:07:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959632; bh=OO1INIrpAEtRSWqjJ4QRES5SjbhvEkOIun18VAa1XKY=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=XYscSKlqdzy13VNW8JemfcAGOLQVUO5oLgXl6eRgucaCwR2J6zl3FM6fjKmX9PMEO /YKPuOEw2fejzXyveJMj+B2I7rMcR2lVr9bXoBK640Cw8rUxPKQbHNaKviB2XKJUJH 7dYSpMPsbdPfWOJyMBcUKMXEQBtZoeL4psl9txBYDREJpQzYpLj+rwj5FZGhXZmNj/ NVmzpm2dhIY1XLoc0qalU4YZ+Pv8eCU6Yb+YwO+W90dLKpfXSfmtxt/TZwRDREfJ2w +hO1AHnfGKYMEa5rwB+2M6A30bXMJcV97vrb/wvz42yAI2WDOtNfbjtIVaHdRzQd/B fWxyzZWXyGhjw== Subject: [PATCH 16/24] xfs: report refcount domain in tracepoints From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:07:11 -0800 Message-ID: <166795963186.3761583.1303087482752452396.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 440759208b71e1854dfcb332434f9a41e9c8e432 Now that we've broken out the startblock and shared/cow domain in the incore refcount extent record structure, update the tracepoints to report the domain. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner --- libxfs/xfs_types.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libxfs/xfs_types.h b/libxfs/xfs_types.h index eb9a98338b..5ebdda7e10 100644 --- a/libxfs/xfs_types.h +++ b/libxfs/xfs_types.h @@ -171,6 +171,10 @@ enum xfs_refc_domain { XFS_REFC_DOMAIN_COW, }; +#define XFS_REFC_DOMAIN_STRINGS \ + { XFS_REFC_DOMAIN_SHARED, "shared" }, \ + { XFS_REFC_DOMAIN_COW, "cow" } + struct xfs_refcount_irec { xfs_agblock_t rc_startblock; /* starting block number */ xfs_extlen_t rc_blockcount; /* count of free blocks */ From patchwork Wed Nov 9 02:07:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037070 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E79A6C433FE for ; Wed, 9 Nov 2022 02:07:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229735AbiKICHV (ORCPT ); Tue, 8 Nov 2022 21:07:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229610AbiKICHV (ORCPT ); Tue, 8 Nov 2022 21:07:21 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74BB0686A5 for ; Tue, 8 Nov 2022 18:07:20 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2D32FB81CE7 for ; Wed, 9 Nov 2022 02:07:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEE64C433D6; Wed, 9 Nov 2022 02:07:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959637; bh=YQKjqx+guOrHfKZhgvh8DiZbr2hTYzHhEaHsMVC/42M=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=fWE+3og3b6duzk+drX99LvTzmMl29e7K7s4MiNB11LO8LG3rDHQ7IANnmZddHe2tZ h9bIkrJxHrjobQjTdUXQNF5G1J15B9p/rN7Jf9zGIWjJKW3O8pS88ycUpi83XXJBWY m8/KHMt/BoUXQDl4UVEUSBUy43e8JnZAKPYU9ZRyQkXw6bhNDIIZER9c8sWlJ3M/PZ 7ZH0ypCZN0T4CLuYPpaOuMDEF1/vklLS5Yj0sQaMsAxKqtHlsjLVTdT6wobSeZS+3n bUIWj75NJsL5Pb+uJFpw5bQEDbFf+YPG2vGxt9XVNN/7Bc/N3YS6HUp8zKc5+fcjM0 UvPnu0JX/BTKA== Subject: [PATCH 17/24] xfs: refactor domain and refcount checking From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:07:17 -0800 Message-ID: <166795963742.3761583.10209840169462299066.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: ea3d9e89f37160240af1c9f1706d17fea9e20ce9 Create a helper function to ensure that CoW staging extent records have a single refcount and that shared extent records have more than 1 refcount. We'll put this to more use in the next patch. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner --- libxfs/xfs_refcount.c | 5 +---- libxfs/xfs_refcount.h | 12 ++++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 7094a27dce..f0fc96da6a 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -141,10 +141,7 @@ xfs_refcount_get_rec( if (irec->rc_blockcount == 0 || irec->rc_blockcount > MAXREFCEXTLEN) goto out_bad_rec; - /* handle special COW-staging domain */ - if (irec->rc_domain == XFS_REFC_DOMAIN_COW && irec->rc_refcount != 1) - goto out_bad_rec; - if (irec->rc_domain == XFS_REFC_DOMAIN_SHARED && irec->rc_refcount < 2) + if (!xfs_refcount_check_domain(irec)) goto out_bad_rec; /* check for valid extent range, including overflow */ diff --git a/libxfs/xfs_refcount.h b/libxfs/xfs_refcount.h index 3beb5a30a9..ee32e8eb5a 100644 --- a/libxfs/xfs_refcount.h +++ b/libxfs/xfs_refcount.h @@ -55,6 +55,18 @@ struct xfs_refcount_intent { xfs_fsblock_t ri_startblock; }; +/* Check that the refcount is appropriate for the record domain. */ +static inline bool +xfs_refcount_check_domain( + const struct xfs_refcount_irec *irec) +{ + if (irec->rc_domain == XFS_REFC_DOMAIN_COW && irec->rc_refcount != 1) + return false; + if (irec->rc_domain == XFS_REFC_DOMAIN_SHARED && irec->rc_refcount < 2) + return false; + return true; +} + void xfs_refcount_increase_extent(struct xfs_trans *tp, struct xfs_bmbt_irec *irec); void xfs_refcount_decrease_extent(struct xfs_trans *tp, From patchwork Wed Nov 9 02:07:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037071 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D2F9C4332F for ; Wed, 9 Nov 2022 02:07:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229759AbiKICH2 (ORCPT ); Tue, 8 Nov 2022 21:07:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229610AbiKICH1 (ORCPT ); Tue, 8 Nov 2022 21:07:27 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2ADBF682BD for ; Tue, 8 Nov 2022 18:07:26 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DA157B81CF2 for ; Wed, 9 Nov 2022 02:07:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82D87C433D7; Wed, 9 Nov 2022 02:07:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959643; bh=AmPjuulyoQn8D295TRVgE6OlKVtBC6LTvaJxMpkhW8c=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=n7hl2BxQRHZTBWlb/Ye5JLFwkvNqa8bjn0RH1P8C8OauPWOZLg379Vmp2rxvBEqZl nT54onPELNiu7ndKI3lT0JPoT4h+KDgB+Q0ripG/7dXqp5l9fhfFzA984UEHCrPnop XH8QFdFffXHdMlypOZtMVHMYflhLg7hFOd9NEcHhmBi9lB1RoKvN63qBrQj1pnxJaA 3QVi3HLB9Hj3t/1Z43ZJYA1zDg+5q+KUJdOlYKTsNPVHd7tmcr1CrLY/oONcQjITFD tTazFdQHrJwK9c31HGIKI4l9UV3jQQoQRFsDEe5ivqOr711VRQx6h4GuM4nkSPHb1K eEHapO57y1e5A== Subject: [PATCH 18/24] xfs: remove XFS_FIND_RCEXT_SHARED and _COW From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:07:23 -0800 Message-ID: <166795964302.3761583.6759285188672122147.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 912fb9d3e44628aca3f3b29793ed5942c194ed44 Now that we have an explicit enum for shared and CoW staging extents, we can get rid of the old FIND_RCEXT flags. Omit a couple of conversions that disappear in the next patches. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner --- libxfs/xfs_refcount.c | 48 +++++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index f0fc96da6a..192014d00c 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -616,8 +616,6 @@ xfs_refcount_merge_right_extent( return error; } -#define XFS_FIND_RCEXT_SHARED 1 -#define XFS_FIND_RCEXT_COW 2 /* * Find the left extent and the one after it (cleft). This function assumes * that we've already split any extent crossing agbno. @@ -627,20 +625,14 @@ xfs_refcount_find_left_extents( struct xfs_btree_cur *cur, struct xfs_refcount_irec *left, struct xfs_refcount_irec *cleft, + enum xfs_refc_domain domain, xfs_agblock_t agbno, - xfs_extlen_t aglen, - int flags) + xfs_extlen_t aglen) { struct xfs_refcount_irec tmp; - enum xfs_refc_domain domain; int error; int found_rec; - if (flags & XFS_FIND_RCEXT_SHARED) - domain = XFS_REFC_DOMAIN_SHARED; - else - domain = XFS_REFC_DOMAIN_COW; - left->rc_startblock = cleft->rc_startblock = NULLAGBLOCK; error = xfs_refcount_lookup_le(cur, domain, agbno - 1, &found_rec); if (error) @@ -658,9 +650,9 @@ xfs_refcount_find_left_extents( if (xfs_refc_next(&tmp) != agbno) return 0; - if ((flags & XFS_FIND_RCEXT_SHARED) && tmp.rc_refcount < 2) + if (domain == XFS_REFC_DOMAIN_SHARED && tmp.rc_refcount < 2) return 0; - if ((flags & XFS_FIND_RCEXT_COW) && tmp.rc_refcount > 1) + if (domain == XFS_REFC_DOMAIN_COW && tmp.rc_refcount > 1) return 0; /* We have a left extent; retrieve (or invent) the next right one */ *left = tmp; @@ -724,20 +716,14 @@ xfs_refcount_find_right_extents( struct xfs_btree_cur *cur, struct xfs_refcount_irec *right, struct xfs_refcount_irec *cright, + enum xfs_refc_domain domain, xfs_agblock_t agbno, - xfs_extlen_t aglen, - int flags) + xfs_extlen_t aglen) { struct xfs_refcount_irec tmp; - enum xfs_refc_domain domain; int error; int found_rec; - if (flags & XFS_FIND_RCEXT_SHARED) - domain = XFS_REFC_DOMAIN_SHARED; - else - domain = XFS_REFC_DOMAIN_COW; - right->rc_startblock = cright->rc_startblock = NULLAGBLOCK; error = xfs_refcount_lookup_ge(cur, domain, agbno + aglen, &found_rec); if (error) @@ -755,9 +741,9 @@ xfs_refcount_find_right_extents( if (tmp.rc_startblock != agbno + aglen) return 0; - if ((flags & XFS_FIND_RCEXT_SHARED) && tmp.rc_refcount < 2) + if (domain == XFS_REFC_DOMAIN_SHARED && tmp.rc_refcount < 2) return 0; - if ((flags & XFS_FIND_RCEXT_COW) && tmp.rc_refcount > 1) + if (domain == XFS_REFC_DOMAIN_COW && tmp.rc_refcount > 1) return 0; /* We have a right extent; retrieve (or invent) the next left one */ *right = tmp; @@ -826,10 +812,10 @@ xfs_refc_valid( STATIC int xfs_refcount_merge_extents( struct xfs_btree_cur *cur, + enum xfs_refc_domain domain, xfs_agblock_t *agbno, xfs_extlen_t *aglen, enum xfs_refc_adjust_op adjust, - int flags, bool *shape_changed) { struct xfs_refcount_irec left = {0}, cleft = {0}; @@ -844,12 +830,12 @@ xfs_refcount_merge_extents( * just below (agbno + aglen) [cright], and just above (agbno + aglen) * [right]. */ - error = xfs_refcount_find_left_extents(cur, &left, &cleft, *agbno, - *aglen, flags); + error = xfs_refcount_find_left_extents(cur, &left, &cleft, domain, + *agbno, *aglen); if (error) return error; - error = xfs_refcount_find_right_extents(cur, &right, &cright, *agbno, - *aglen, flags); + error = xfs_refcount_find_right_extents(cur, &right, &cright, domain, + *agbno, *aglen); if (error) return error; @@ -1138,8 +1124,8 @@ xfs_refcount_adjust( /* * Try to merge with the left or right extents of the range. */ - error = xfs_refcount_merge_extents(cur, new_agbno, new_aglen, adj, - XFS_FIND_RCEXT_SHARED, &shape_changed); + error = xfs_refcount_merge_extents(cur, XFS_REFC_DOMAIN_SHARED, + new_agbno, new_aglen, adj, &shape_changed); if (error) goto out_error; if (shape_changed) @@ -1649,8 +1635,8 @@ xfs_refcount_adjust_cow( /* * Try to merge with the left or right extents of the range. */ - error = xfs_refcount_merge_extents(cur, &agbno, &aglen, adj, - XFS_FIND_RCEXT_COW, &shape_changed); + error = xfs_refcount_merge_extents(cur, XFS_REFC_DOMAIN_COW, &agbno, + &aglen, adj, &shape_changed); if (error) goto out_error; From patchwork Wed Nov 9 02:07:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037072 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F2BAC433FE for ; Wed, 9 Nov 2022 02:07:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229610AbiKICHf (ORCPT ); Tue, 8 Nov 2022 21:07:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbiKICHc (ORCPT ); Tue, 8 Nov 2022 21:07:32 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B30D3686A5 for ; Tue, 8 Nov 2022 18:07:31 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6D765B81CE7 for ; Wed, 9 Nov 2022 02:07:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24F61C433C1; Wed, 9 Nov 2022 02:07:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959649; bh=NHUKUfRvJL30Jn4i3f/WcvaDPqB4ZVNyKpwwQ+Mm5gA=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=ZVRhH0k876V9z9Ad8wS7lkEo3ep8z91RbSnbL4TtGuuQSdoOgSVrlcQPcABC7/PnX ta4sTpIy1T7zCMVd+Xah/MoqlDs5dd873NB+kr6bcOP/Omap3OVI6Uw2PYX0r584oj k25U3klDCViv7MOue9ga0mX2BH//t2fjCwqLNbP7zCRf72/ORXkD9+qBU6AjsrODRV YQ7034yHUhKkjVrNDpogLUyMMiwdhHmzh71ZP4d8cSUenGmMPtPGkwJIXooqZxYAAr rQEMPpQeW3CelInHswZ4vQAPUqE9O/B4aysfV/b0iRafAKsZDHA9xKel3covfLEHs4 Q8pq120iKVY9A== Subject: [PATCH 19/24] xfs: check record domain when accessing refcount records From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:07:28 -0800 Message-ID: <166795964870.3761583.7630465137549563227.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 607646ffbb04dd01e73c53f6ae22cfa63f44dfbd Now that we've separated the startblock and CoW/shared extent domain in the incore refcount record structure, check the domain whenever we retrieve a record to ensure that it's still in the domain that we want. Depending on the circumstances, a change in domain either means we're done processing or that we've found a corruption and need to fail out. The refcount check in xchk_xref_is_cow_staging is redundant since _get_rec has done that for a long time now, so we can get rid of it. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner --- libxfs/xfs_refcount.c | 53 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 192014d00c..179b686792 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -380,6 +380,8 @@ xfs_refcount_split_extent( error = -EFSCORRUPTED; goto out_error; } + if (rcext.rc_domain != domain) + return 0; if (rcext.rc_startblock == agbno || xfs_refc_next(&rcext) <= agbno) return 0; @@ -431,6 +433,9 @@ xfs_refcount_merge_center_extents( trace_xfs_refcount_merge_center_extents(cur->bc_mp, cur->bc_ag.pag->pag_agno, left, center, right); + ASSERT(left->rc_domain == center->rc_domain); + ASSERT(right->rc_domain == center->rc_domain); + /* * Make sure the center and right extents are not in the btree. * If the center extent was synthesized, the first delete call @@ -507,6 +512,8 @@ xfs_refcount_merge_left_extent( trace_xfs_refcount_merge_left_extent(cur->bc_mp, cur->bc_ag.pag->pag_agno, left, cleft); + ASSERT(left->rc_domain == cleft->rc_domain); + /* If the extent at agbno (cleft) wasn't synthesized, remove it. */ if (cleft->rc_refcount > 1) { error = xfs_refcount_lookup_le(cur, cleft->rc_domain, @@ -568,6 +575,8 @@ xfs_refcount_merge_right_extent( trace_xfs_refcount_merge_right_extent(cur->bc_mp, cur->bc_ag.pag->pag_agno, cright, right); + ASSERT(right->rc_domain == cright->rc_domain); + /* * If the extent ending at agbno+aglen (cright) wasn't synthesized, * remove it. @@ -648,12 +657,10 @@ xfs_refcount_find_left_extents( goto out_error; } + if (tmp.rc_domain != domain) + return 0; if (xfs_refc_next(&tmp) != agbno) return 0; - if (domain == XFS_REFC_DOMAIN_SHARED && tmp.rc_refcount < 2) - return 0; - if (domain == XFS_REFC_DOMAIN_COW && tmp.rc_refcount > 1) - return 0; /* We have a left extent; retrieve (or invent) the next right one */ *left = tmp; @@ -669,6 +676,9 @@ xfs_refcount_find_left_extents( goto out_error; } + if (tmp.rc_domain != domain) + goto not_found; + /* if tmp starts at the end of our range, just use that */ if (tmp.rc_startblock == agbno) *cleft = tmp; @@ -688,6 +698,7 @@ xfs_refcount_find_left_extents( cleft->rc_domain = domain; } } else { +not_found: /* * No extents, so pretend that there's one covering the whole * range. @@ -739,12 +750,10 @@ xfs_refcount_find_right_extents( goto out_error; } + if (tmp.rc_domain != domain) + return 0; if (tmp.rc_startblock != agbno + aglen) return 0; - if (domain == XFS_REFC_DOMAIN_SHARED && tmp.rc_refcount < 2) - return 0; - if (domain == XFS_REFC_DOMAIN_COW && tmp.rc_refcount > 1) - return 0; /* We have a right extent; retrieve (or invent) the next left one */ *right = tmp; @@ -760,6 +769,9 @@ xfs_refcount_find_right_extents( goto out_error; } + if (tmp.rc_domain != domain) + goto not_found; + /* if tmp ends at the end of our range, just use that */ if (xfs_refc_next(&tmp) == agbno + aglen) *cright = tmp; @@ -779,6 +791,7 @@ xfs_refcount_find_right_extents( cright->rc_domain = domain; } } else { +not_found: /* * No extents, so pretend that there's one covering the whole * range. @@ -888,7 +901,7 @@ xfs_refcount_merge_extents( aglen); } - return error; + return 0; } /* @@ -960,7 +973,7 @@ xfs_refcount_adjust_extents( error = xfs_refcount_get_rec(cur, &ext, &found_rec); if (error) goto out_error; - if (!found_rec) { + if (!found_rec || ext.rc_domain != XFS_REFC_DOMAIN_SHARED) { ext.rc_startblock = cur->bc_mp->m_sb.sb_agblocks; ext.rc_blockcount = 0; ext.rc_refcount = 0; @@ -1399,6 +1412,8 @@ xfs_refcount_find_shared( error = -EFSCORRUPTED; goto out_error; } + if (tmp.rc_domain != XFS_REFC_DOMAIN_SHARED) + goto done; /* If the extent ends before the start, look at the next one */ if (tmp.rc_startblock + tmp.rc_blockcount <= agbno) { @@ -1414,6 +1429,8 @@ xfs_refcount_find_shared( error = -EFSCORRUPTED; goto out_error; } + if (tmp.rc_domain != XFS_REFC_DOMAIN_SHARED) + goto done; } /* If the extent starts after the range we want, bail out */ @@ -1445,7 +1462,8 @@ xfs_refcount_find_shared( error = -EFSCORRUPTED; goto out_error; } - if (tmp.rc_startblock >= agbno + aglen || + if (tmp.rc_domain != XFS_REFC_DOMAIN_SHARED || + tmp.rc_startblock >= agbno + aglen || tmp.rc_startblock != *fbno + *flen) break; *flen = min(*flen + tmp.rc_blockcount, agbno + aglen - *fbno); @@ -1536,6 +1554,11 @@ xfs_refcount_adjust_cow_extents( error = xfs_refcount_get_rec(cur, &ext, &found_rec); if (error) goto out_error; + if (XFS_IS_CORRUPT(cur->bc_mp, found_rec && + ext.rc_domain != XFS_REFC_DOMAIN_COW)) { + error = -EFSCORRUPTED; + goto out_error; + } if (!found_rec) { ext.rc_startblock = cur->bc_mp->m_sb.sb_agblocks; ext.rc_blockcount = 0; @@ -1745,8 +1768,14 @@ xfs_refcount_recover_extent( rr = kmem_alloc(sizeof(struct xfs_refcount_recovery), 0); xfs_refcount_btrec_to_irec(rec, &rr->rr_rrec); + + if (XFS_IS_CORRUPT(cur->bc_mp, + rr->rr_rrec.rc_domain != XFS_REFC_DOMAIN_COW)) { + kmem_free(rr); + return -EFSCORRUPTED; + } + list_add_tail(&rr->rr_list, debris); - return 0; } From patchwork Wed Nov 9 02:07:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037073 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F51EC433FE for ; Wed, 9 Nov 2022 02:07:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229770AbiKICHi (ORCPT ); Tue, 8 Nov 2022 21:07:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbiKICHi (ORCPT ); Tue, 8 Nov 2022 21:07:38 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54875686AD for ; Tue, 8 Nov 2022 18:07:37 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 14300B81CE7 for ; Wed, 9 Nov 2022 02:07:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4D7AC433C1; Wed, 9 Nov 2022 02:07:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959654; bh=cdv03xghOKXO1UB+WVAHBDP5oMZvGGf655qV0dGpNCQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=E7ic39/BZM+ik8aGLRoQwJR4g3NcRv2KE4QWKxYzEMo+HqQRtZm50+c8FZ7TerZFB SE3Wmik2yNWrRtlkRbGauNCXDzLST1G4MlO7kIDkC4D05p7X/HyqhnnvY7gPtE1JTv STx7yMf42qR+znY/lHvOAR740cFLVB3Lw/4tsuLjxKfYuZ7uxWqRjUF6Di7C6b8Wj5 mE+3/GK+DoqMQGuu16Pha5TjYc41r2j16LOuDA9E3NuJ59HHE85ZIh7yqy04ZqqXCA MigYTV6YGjGm5e2KQcb3kPyCIhF17Bw1bq9x3O3ERGMhAUy+/rKR4LiSBqySxFaakT 9k2gjWIpwBsBA== Subject: [PATCH 20/24] xfs: fix agblocks check in the cow leftover recovery function From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:07:34 -0800 Message-ID: <166795965431.3761583.15719682752076571294.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 2373f381819de8807fdd19be2d1a06bc62f8e595 As we've seen, refcount records use the upper bit of the rc_startblock field to ensure that all the refcount records are at the right side of the refcount btree. This works because an AG is never allowed to have more than (1U << 31) blocks in it. If we ever encounter a filesystem claiming to have that many blocks, we absolutely do not want reflink touching it at all. However, this test at the start of xfs_refcount_recover_cow_leftovers is slightly incorrect -- it /should/ be checking that agblocks isn't larger than the XFS_MAX_CRC_AG_BLOCKS constant, and it should check that the constant is never large enough to conflict with that CoW flag. Note that the V5 superblock verifier has not historically rejected filesystems where agblocks >= XFS_MAX_CRC_AG_BLOCKS, which is why this ended up in the COW recovery routine. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner --- libxfs/xfs_refcount.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 179b686792..52983aeef1 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -1795,7 +1795,9 @@ xfs_refcount_recover_cow_leftovers( xfs_fsblock_t fsb; int error; - if (mp->m_sb.sb_agblocks >= XFS_REFC_COW_START) + /* reflink filesystems mustn't have AGs larger than 2^31-1 blocks */ + BUILD_BUG_ON(XFS_MAX_CRC_AG_BLOCKS >= XFS_REFC_COW_START); + if (mp->m_sb.sb_agblocks > XFS_MAX_CRC_AG_BLOCKS) return -EOPNOTSUPP; INIT_LIST_HEAD(&debris); From patchwork Wed Nov 9 02:07:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037074 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3941BC433FE for ; Wed, 9 Nov 2022 02:07:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229776AbiKICHo (ORCPT ); Tue, 8 Nov 2022 21:07:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbiKICHn (ORCPT ); Tue, 8 Nov 2022 21:07:43 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEFCE686AB for ; Tue, 8 Nov 2022 18:07:42 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A0035B81CF3 for ; Wed, 9 Nov 2022 02:07:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52247C433D7; Wed, 9 Nov 2022 02:07:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959660; bh=FXMgiDkqv5NPtn5B85dCpaCKfLmYbCaU0Daq7lRJY5A=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=ralFth5xk6xiq9L8SRhNBAkqNZ9Gi6lyrgQL9Yy1DN91oBO1r2ZHAzZFLccewXpJq N5k7vZlX3whPgyCMjtP9ziu+c6FZtpVPvTi6eo3BwvfMJCJfWW+SZcZlk7E7XjZeLL dOW+AdItr3018YU2tDf/0mTN7cihCTSmJ51MEbgc4+/HeZ3fI4NUP5v02l/T9VZiL7 h9RN0EyFbHQARsduW62gb0CIG1c+iVqSmru88nj5Nu0TT4a4/IeBnHQkMO8PkNUXXT 8S6SXquVUdW+FguaIbReBBSuBx8uuEqnIDZUH4LShUobSMAbtV9ELGur6e58RabO6l BINswHNNr13Rg== Subject: [PATCH 21/24] xfs: fix uninitialized list head in struct xfs_refcount_recovery From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:07:39 -0800 Message-ID: <166795965990.3761583.13864634191918555385.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 55bb7e256b78994d756c40b0c8f05fc53c12532c We're supposed to initialize the list head of an object before adding it to another list. Fix that, and stop using the kmem_{alloc,free} calls from the Irix days. Fixes: 174edb0e46e5 ("xfs: store in-progress CoW allocations in the refcount btree") Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner --- include/kmem.h | 10 ++++++++++ libxfs/xfs_refcount.c | 10 ++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/kmem.h b/include/kmem.h index 20e4bfe3c0..8ae919c706 100644 --- a/include/kmem.h +++ b/include/kmem.h @@ -60,4 +60,14 @@ kmem_free(const void *ptr) { extern void *krealloc(void *, size_t, int); +static inline void *kmalloc(size_t size, gfp_t flags) +{ + return kvmalloc(size, flags); +} + +static inline void kfree(const void *ptr) +{ + return kmem_free(ptr); +} + #endif diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 52983aeef1..0a934aecc6 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -1766,12 +1766,14 @@ xfs_refcount_recover_extent( be32_to_cpu(rec->refc.rc_refcount) != 1)) return -EFSCORRUPTED; - rr = kmem_alloc(sizeof(struct xfs_refcount_recovery), 0); + rr = kmalloc(sizeof(struct xfs_refcount_recovery), + GFP_KERNEL | __GFP_NOFAIL); + INIT_LIST_HEAD(&rr->rr_list); xfs_refcount_btrec_to_irec(rec, &rr->rr_rrec); if (XFS_IS_CORRUPT(cur->bc_mp, rr->rr_rrec.rc_domain != XFS_REFC_DOMAIN_COW)) { - kmem_free(rr); + kfree(rr); return -EFSCORRUPTED; } @@ -1858,7 +1860,7 @@ xfs_refcount_recover_cow_leftovers( goto out_free; list_del(&rr->rr_list); - kmem_free(rr); + kfree(rr); } return error; @@ -1868,7 +1870,7 @@ xfs_refcount_recover_cow_leftovers( /* Free the leftover list */ list_for_each_entry_safe(rr, n, &debris, rr_list) { list_del(&rr->rr_list); - kmem_free(rr); + kfree(rr); } return error; } From patchwork Wed Nov 9 02:07:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037075 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33E08C4332F for ; Wed, 9 Nov 2022 02:07:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229777AbiKICHv (ORCPT ); Tue, 8 Nov 2022 21:07:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbiKICHt (ORCPT ); Tue, 8 Nov 2022 21:07:49 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99000686AB for ; Tue, 8 Nov 2022 18:07:48 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 51B9EB81CF2 for ; Wed, 9 Nov 2022 02:07:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA84EC433D6; Wed, 9 Nov 2022 02:07:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959666; bh=RDD1tainKMkY9uZXkakn22BG9G0VSx9/vhQ2vxSac+w=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=GdYRoLVSFijtp4ZpkpWggwCjJT0Z2NXzqHXSMZ2M2ucPzX8lNWaTAI3ixtHEhnRqb TQ3Bs/HCZ2OgJ8LnAx+QOa4SnY+RThhGqTEn2N1lTQdnYReqBNPbDFRwoTaCEVHZie rIDRT/7V/9sj9+QhCQAvRhHJo9I7UN6inTp9FVgn5SP/TAZErJqd2sQd8nUb+E5EPt NF4I5JiAZMRbvg+yqHYNDJrA4rjS9XdC5RuFLULmv8dDItYGZ4iabUgZ7/0KgPrp0E Q/pS58QvJeBHOzF9DuIbzNm5TAqJimWVFI161H2pPp++v/28wxMHubPTIawhKr6Lyn iZ3nrQpGp6NLA== Subject: [PATCH 22/24] xfs: rename XFS_REFC_COW_START to _COWFLAG From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: Dave Chinner , linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:07:45 -0800 Message-ID: <166795966550.3761583.6200011571727727812.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Source kernel commit: 345bfca998c4ac57daabb7618769a3f0a75331d1 We've been (ab)using XFS_REFC_COW_START as both an integer quantity and a bit flag, even though it's *only* a bit flag. Rename the variable to reflect its nature and update the cast target since we're not supposed to be comparing it to xfs_agblock_t now. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner --- db/check.c | 4 ++-- libxfs/xfs_format.h | 2 +- libxfs/xfs_refcount.c | 6 +++--- libxfs/xfs_refcount.h | 4 ++-- repair/scan.c | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/db/check.c b/db/check.c index c9149daadf..680edf1f9e 100644 --- a/db/check.c +++ b/db/check.c @@ -4848,8 +4848,8 @@ scanfunc_refcnt( char *msg; agbno = be32_to_cpu(rp[i].rc_startblock); - if (agbno >= XFS_REFC_COW_START) { - agbno -= XFS_REFC_COW_START; + if (agbno >= XFS_REFC_COWFLAG) { + agbno -= XFS_REFC_COWFLAG; msg = _( "leftover CoW extent (%u/%u) len %u\n"); } else { diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h index 005dd65b71..371dc07233 100644 --- a/libxfs/xfs_format.h +++ b/libxfs/xfs_format.h @@ -1612,7 +1612,7 @@ unsigned int xfs_refc_block(struct xfs_mount *mp); * on the startblock. This speeds up mount time deletion of stale * staging extents because they're all at the right side of the tree. */ -#define XFS_REFC_COW_START ((xfs_agblock_t)(1U << 31)) +#define XFS_REFC_COWFLAG (1U << 31) #define REFCNTBT_COWFLAG_BITLEN 1 #define REFCNTBT_AGBLOCK_BITLEN 31 diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 0a934aecc6..64e66861b8 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -107,8 +107,8 @@ xfs_refcount_btrec_to_irec( uint32_t start; start = be32_to_cpu(rec->refc.rc_startblock); - if (start & XFS_REFC_COW_START) { - start &= ~XFS_REFC_COW_START; + if (start & XFS_REFC_COWFLAG) { + start &= ~XFS_REFC_COWFLAG; irec->rc_domain = XFS_REFC_DOMAIN_COW; } else { irec->rc_domain = XFS_REFC_DOMAIN_SHARED; @@ -1798,7 +1798,7 @@ xfs_refcount_recover_cow_leftovers( int error; /* reflink filesystems mustn't have AGs larger than 2^31-1 blocks */ - BUILD_BUG_ON(XFS_MAX_CRC_AG_BLOCKS >= XFS_REFC_COW_START); + BUILD_BUG_ON(XFS_MAX_CRC_AG_BLOCKS >= XFS_REFC_COWFLAG); if (mp->m_sb.sb_agblocks > XFS_MAX_CRC_AG_BLOCKS) return -EOPNOTSUPP; diff --git a/libxfs/xfs_refcount.h b/libxfs/xfs_refcount.h index ee32e8eb5a..452f30556f 100644 --- a/libxfs/xfs_refcount.h +++ b/libxfs/xfs_refcount.h @@ -34,9 +34,9 @@ xfs_refcount_encode_startblock( * query functions (which set rc_domain == -1U), so we check that the * domain is /not/ shared. */ - start = startblock & ~XFS_REFC_COW_START; + start = startblock & ~XFS_REFC_COWFLAG; if (domain != XFS_REFC_DOMAIN_SHARED) - start |= XFS_REFC_COW_START; + start |= XFS_REFC_COWFLAG; return start; } diff --git a/repair/scan.c b/repair/scan.c index 7e4d4d8b8e..859a6e6937 100644 --- a/repair/scan.c +++ b/repair/scan.c @@ -1374,16 +1374,16 @@ _("%s btree block claimed (state %d), agno %d, bno %d, suspect %d\n"), b = agb = be32_to_cpu(rp[i].rc_startblock); len = be32_to_cpu(rp[i].rc_blockcount); nr = be32_to_cpu(rp[i].rc_refcount); - if (b >= XFS_REFC_COW_START && nr != 1) + if (b >= XFS_REFC_COWFLAG && nr != 1) do_warn( _("leftover CoW extent has incorrect refcount in record %u of %s btree block %u/%u\n"), i, name, agno, bno); if (nr == 1) { - if (agb < XFS_REFC_COW_START) + if (agb < XFS_REFC_COWFLAG) do_warn( _("leftover CoW extent has invalid startblock in record %u of %s btree block %u/%u\n"), i, name, agno, bno); - agb -= XFS_REFC_COW_START; + agb -= XFS_REFC_COWFLAG; } end = agb + len; From patchwork Wed Nov 9 02:07:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037076 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34730C4332F for ; Wed, 9 Nov 2022 02:07:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229547AbiKICH5 (ORCPT ); Tue, 8 Nov 2022 21:07:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229790AbiKICHz (ORCPT ); Tue, 8 Nov 2022 21:07:55 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 244FB686AF for ; Tue, 8 Nov 2022 18:07:54 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D1467B81CEF for ; Wed, 9 Nov 2022 02:07:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C7A9C433D6; Wed, 9 Nov 2022 02:07:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959671; bh=E8n189QsG6qYwkskcZOfvTgihNF8jVP+qYx6QfrGrlM=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=J0r8cvcxk+P1Rl0zyVWpSLKM5koLIylz9E3gMqelnXqyW/P9yTOXem7gpj7O6Gfkd 4YhfgoPh3MMr/sYxoDHfNjPoEzt/rLqT89kyS6Y8Hnq31KQys/C1/4ICx31X4xeaVg oXl/Fkt+nwfhby189Jm3/VWpUYivGl4hKm2BthRRyI6aFa7ffJD14op4gUO3CfX4d3 3HZox5dfqAYzbgOII3ZhK+QQDzF+PIjr6jKtrQQxzf+hs8e2ElwiPKkZd7/vR+ORie jT5JlEYG6n7DOLbwsM7/JET2x/ZE0HygirMl2FRO68kWWmnbJNlueXqq+UlLddbPvU X2zamYdKnpizQ== Subject: [PATCH 23/24] xfs_{db,repair}: fix XFS_REFC_COW_START usage From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:07:51 -0800 Message-ID: <166795967110.3761583.11794162638528640620.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong This is really a bit field stashed in the upper bit of the rc_startblock field, so change its usage patterns to use masking instead of integer addition and subtraction. Signed-off-by: Darrick J. Wong --- db/check.c | 4 ++-- repair/scan.c | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/db/check.c b/db/check.c index 680edf1f9e..bb27ce5805 100644 --- a/db/check.c +++ b/db/check.c @@ -4848,8 +4848,8 @@ scanfunc_refcnt( char *msg; agbno = be32_to_cpu(rp[i].rc_startblock); - if (agbno >= XFS_REFC_COWFLAG) { - agbno -= XFS_REFC_COWFLAG; + if (agbno & XFS_REFC_COWFLAG) { + agbno &= ~XFS_REFC_COWFLAG; msg = _( "leftover CoW extent (%u/%u) len %u\n"); } else { diff --git a/repair/scan.c b/repair/scan.c index 859a6e6937..7b72013153 100644 --- a/repair/scan.c +++ b/repair/scan.c @@ -1367,6 +1367,7 @@ _("%s btree block claimed (state %d), agno %d, bno %d, suspect %d\n"), pag = libxfs_perag_get(mp, agno); for (i = 0; i < numrecs; i++) { + enum xfs_refc_domain domain; xfs_agblock_t b, agb, end; xfs_extlen_t len; xfs_nlink_t nr; @@ -1374,16 +1375,23 @@ _("%s btree block claimed (state %d), agno %d, bno %d, suspect %d\n"), b = agb = be32_to_cpu(rp[i].rc_startblock); len = be32_to_cpu(rp[i].rc_blockcount); nr = be32_to_cpu(rp[i].rc_refcount); - if (b >= XFS_REFC_COWFLAG && nr != 1) + + if (b & XFS_REFC_COWFLAG) { + domain = XFS_REFC_DOMAIN_COW; + agb &= ~XFS_REFC_COWFLAG; + } else { + domain = XFS_REFC_DOMAIN_SHARED; + } + + if (domain == XFS_REFC_DOMAIN_COW && nr != 1) do_warn( _("leftover CoW extent has incorrect refcount in record %u of %s btree block %u/%u\n"), i, name, agno, bno); if (nr == 1) { - if (agb < XFS_REFC_COWFLAG) + if (domain != XFS_REFC_DOMAIN_COW) do_warn( _("leftover CoW extent has invalid startblock in record %u of %s btree block %u/%u\n"), i, name, agno, bno); - agb -= XFS_REFC_COWFLAG; } end = agb + len; @@ -1438,15 +1446,17 @@ _("extent (%u/%u) len %u claimed, state is %d\n"), } /* Is this record mergeable with the last one? */ - if (refc_priv->last_rec.rc_startblock + - refc_priv->last_rec.rc_blockcount == b && + if (refc_priv->last_rec.rc_domain == domain && + refc_priv->last_rec.rc_startblock + + refc_priv->last_rec.rc_blockcount == agb && refc_priv->last_rec.rc_refcount == nr) { do_warn( _("record %d in block (%u/%u) of %s tree should be merged with previous record\n"), i, agno, bno, name); refc_priv->last_rec.rc_blockcount += len; } else { - refc_priv->last_rec.rc_startblock = b; + refc_priv->last_rec.rc_domain = domain; + refc_priv->last_rec.rc_startblock = agb; refc_priv->last_rec.rc_blockcount = len; refc_priv->last_rec.rc_refcount = nr; } From patchwork Wed Nov 9 02:07:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13037077 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 818EDC4332F for ; Wed, 9 Nov 2022 02:08:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229846AbiKICID (ORCPT ); Tue, 8 Nov 2022 21:08:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229790AbiKICIA (ORCPT ); Tue, 8 Nov 2022 21:08:00 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A906868ADD for ; Tue, 8 Nov 2022 18:07:59 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 681FAB81CF2 for ; Wed, 9 Nov 2022 02:07:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17577C433C1; Wed, 9 Nov 2022 02:07:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667959677; bh=nWpajHOeICKFAToJyw/7xZBo1ulOqQgMlGieysfB9R0=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=dq4LTqyKIoRf7Ih+oD3MRnBQWodbCTgnzS4pdpaUb8Q/U028kySZ/YF9jIVwTh4c8 XUBU+huv02L7t1ijJhSkWuMejm0a3gvDkDMvE3GMQy8liAL0DVF+ZlTBhSPKW3jNBN nmPxyO3LNbVzyRzK+N0v1rIRNP7KoagTbNphXA0mxKqig6fXE5lqQQYtk73Df4eiFr JuHXB1zYz90itq4VDOcDj0qDHxysysOS2vMBH5//tL4NEjzrxcfN1fgcjAs44gZMN2 xN72lL9gbAJsVWsp9vASHhpvyDsbCPGddJqFF35H4Ua3l3cdEgKcRX1WXgOvy1kJM8 lBCK+DAmwougA== Subject: [PATCH 24/24] mkfs.xfs: add mkfs config file for the 6.1 LTS kernel From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Tue, 08 Nov 2022 18:07:56 -0800 Message-ID: <166795967667.3761583.11171982365663628466.stgit@magnolia> In-Reply-To: <166795954256.3761583.3551179546135782562.stgit@magnolia> References: <166795954256.3761583.3551179546135782562.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Add a new mkfs config file to reflect the default featureset for the 6.1 LTS release. Signed-off-by: Darrick J. Wong --- mkfs/Makefile | 3 ++- mkfs/lts_6.1.conf | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 mkfs/lts_6.1.conf diff --git a/mkfs/Makefile b/mkfs/Makefile index 55d9362f6b..6c7ee186fa 100644 --- a/mkfs/Makefile +++ b/mkfs/Makefile @@ -14,7 +14,8 @@ CFGFILES = \ lts_4.19.conf \ lts_5.4.conf \ lts_5.10.conf \ - lts_5.15.conf + lts_5.15.conf \ + lts_6.1.conf LLDLIBS += $(LIBXFS) $(LIBXCMD) $(LIBFROG) $(LIBRT) $(LIBBLKID) \ $(LIBUUID) $(LIBINIH) $(LIBURCU) $(LIBPTHREAD) diff --git a/mkfs/lts_6.1.conf b/mkfs/lts_6.1.conf new file mode 100644 index 0000000000..08bbe9f3c7 --- /dev/null +++ b/mkfs/lts_6.1.conf @@ -0,0 +1,14 @@ +# V5 features that were the mkfs defaults when the upstream Linux 6.1 LTS +# kernel was released at the end of 2022. + +[metadata] +nrext64=0 +bigtime=1 +crc=1 +finobt=1 +inobtcount=1 +reflink=1 +rmapbt=0 + +[inode] +sparse=1