From patchwork Mon Sep 2 18:32:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13787621 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 569991C62C8 for ; Mon, 2 Sep 2024 18:32:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301967; cv=none; b=pWTNyzAsMstAyMw+9VzyVa4umgV3c/IQGUfs1Ye3kr+N0sa3E2bdUPJyLHmDAXwnBrWOYPi9UVo0mNj+6WkoMdjcxtL7rtu4YF37ONLqZlLN4187GqnTK09b5AHC8+A+0yqDqsQ+Cz/8NTiYo8eAcnmA657lWg429po0Ln3nu6s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301967; c=relaxed/simple; bh=mOysTuo09h7rA9cVz+NftFQZNNwSPVsXe3mCS+4bFU4=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QI0qkrM/UpXIWB64ik/dJ+k41FRMYKG3uEDV/Venh2NQbrVijdZw7/feH133zcI4Xc7z/n2UdPwWtSBJWx/5GpCZees4booIUxTDtG+CiWz44ZHEacTeDecrCBOYFmG129nbl5HnjLbOu9QQr/e527S1xbuC89Qrg6b6TcepF5I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=o3FyYVKa; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="o3FyYVKa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7482C4AF09; Mon, 2 Sep 2024 18:32:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301966; bh=mOysTuo09h7rA9cVz+NftFQZNNwSPVsXe3mCS+4bFU4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=o3FyYVKaNQm/efNhDivIL65KGKPsBZSGTxhJmw2QiKSzUrSyLKt3NRmO4SqCS/Y/g esf2juOALF1bsIdgkNatj6JqsukVBg8ZnPjfPlzZBNMcU9xlQA/SPpqLl+zIuZWFmS 3BH33NInDDZ+RLptqlZEp9Gr1lzWNLSfDvul15F3sct9aioWpZRDK1ULrjanORYgZy keL9r9Je/tXW5CGoIevWu/+5NGWkUvL6qmKUF/XZs8a4o2l70CWlRRVrUob59NWGJR C5jza2X+FrhFojCPJWLXPIkE41MIBEIjLhZ2iWVvrC6weplofS4ZHywooxM2sVF+cH Fw/jTSpwfxWIA== Date: Mon, 02 Sep 2024 11:32:46 -0700 Subject: [PATCH 1/3] xfs: fix C++ compilation errors in xfs_fs.h From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: kernel@mattwhitlock.name, sam@gentoo.org, Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530107611.3326571.13323604540410354264.stgit@frogsfrogsfrogs> In-Reply-To: <172530107589.3326571.1610526525006344754.stgit@frogsfrogsfrogs> References: <172530107589.3326571.1610526525006344754.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Several people reported C++ compilation errors due to things that C compilers allow but C++ compilers do not. Fix both of these problems, and hope there aren't more of these brown paper bags in 2 months when we finally get these fixes through the process into a released xfsprogs. NOTE: I am submitting this bugfix over the objections of a former maintainer, who insists that we should remove this function from the published userspace ABI instead of fixing the C++ compilation errors. No deprecation period, no discussion, just a hard drop of an already provided and correct C function, which would be in contravention of Linus' rules. IOWs, removing ABI that have already shipped in a released kernel requires a careful deprecation period, so I will let that maintainer run that process. Reported-by: kernel@mattwhitlock.name Reported-by: sam@gentoo.org Closes: https://bugzilla.kernel.org/show_bug.cgi?id=219203 Fixes: 233f4e12bbb2c ("xfs: add parent pointer ioctls") Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_fs.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h index c85c8077fac3..860284064c5a 100644 --- a/fs/xfs/libxfs/xfs_fs.h +++ b/fs/xfs/libxfs/xfs_fs.h @@ -8,6 +8,7 @@ /* * SGI's XFS filesystem's major stuff (constants, structures) + * NOTE: This file must be compile-able with C++ compilers. */ /* @@ -930,13 +931,13 @@ static inline struct xfs_getparents_rec * xfs_getparents_next_rec(struct xfs_getparents *gp, struct xfs_getparents_rec *gpr) { - void *next = ((void *)gpr + gpr->gpr_reclen); + void *next = ((char *)gpr + gpr->gpr_reclen); void *end = (void *)(uintptr_t)(gp->gp_buffer + gp->gp_bufsize); if (next >= end) return NULL; - return next; + return (struct xfs_getparents_rec *)next; } /* Iterate through this file handle's directory parent pointers. */ From patchwork Mon Sep 2 18:33:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13787622 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 15B901A2654 for ; Mon, 2 Sep 2024 18:33:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301983; cv=none; b=m3ew1uBXnlyYab+Q8tzmcnVPVug2gztHhv3KLeb4gmCNVytAoekGBCFNSDFMGI6cr2bMtSbp+cLRI5UT9EBH0lWbRkm9eX9SSrNCIzryCGnTLun5CV90lwN9cTfqHos/EDO9BFOdlV+0YMoSSQYq+VE7Wb2C9EzXGgGS114ZMnE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301983; c=relaxed/simple; bh=vtlfmftwg2p6QvLNVxCWHwUrUbnIs3nkMIz3kOxhX2w=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=URkY39OhiE4YlsLIG9bv4SltpKLbezzr0nZN6Cd1IMLShhA3J9bUbt89mHgSLyaLSo51oVFiS2MbC6tlQWAR/qXYWG/9OsR5mKUY4Rg9wSzZKoF25JcAPNaIF1Y/0HeelliCS3W0AVnIjjz7GjS6pl/rsAJaWD0Ngf1DLp/lqeE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cvXF9rig; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cvXF9rig" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A0D2C4CEC2; Mon, 2 Sep 2024 18:33:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301982; bh=vtlfmftwg2p6QvLNVxCWHwUrUbnIs3nkMIz3kOxhX2w=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=cvXF9rigKXyTHc/pLRCKpOjoGzvxoyfL9LKjNEjXd+GBGkyRIa0Van3qa9oGeQGco /ZJKi0o3rQurmZeGAEm806hQh7NvvRvLxqomGOYk6nUPJltiO5wpYfnnmAIjBiMGDP rEO8IL16lNoZJR9q/u7RujhNA+lPiqHvRHpOGNXLUQwNlEomljbld6gMqPMAeAKfT2 /U4DousWHKcEC6PZFCBhcvAO5eU7OOiTaU6QWl2oO4UrSJ0ZWio/lheyzaQDXvtrep CfE8BYZgBqdfJvjH93S5AhStmSTZqK8SDcWOHZUtQ9Q/tjyLD1ARewjGVnUQY0RgSG wQ+x2D5raE7NA== Date: Mon, 02 Sep 2024 11:33:02 -0700 Subject: [PATCH 2/3] xfs: fix FITRIM reporting again From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530107627.3326571.9730729950210869015.stgit@frogsfrogsfrogs> In-Reply-To: <172530107589.3326571.1610526525006344754.stgit@frogsfrogsfrogs> References: <172530107589.3326571.1610526525006344754.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Don't report FITRIMming more bytes than possibly exist in the filesystem. Fixes: 410e8a18f8e93 ("xfs: don't bother reporting blocks trimmed via FITRIM") Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_discard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c index bf1e3f330018..d8c4a5dcca7a 100644 --- a/fs/xfs/xfs_discard.c +++ b/fs/xfs/xfs_discard.c @@ -707,7 +707,7 @@ xfs_ioc_trim( return last_error; range.len = min_t(unsigned long long, range.len, - XFS_FSB_TO_B(mp, max_blocks)); + XFS_FSB_TO_B(mp, max_blocks) - range.start); if (copy_to_user(urange, &range, sizeof(range))) return -EFAULT; return 0; From patchwork Mon Sep 2 18:33:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13787623 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB8AD19CC31 for ; Mon, 2 Sep 2024 18:33:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301998; cv=none; b=SZBg+YYbWrAkDBhfwDQtwnNPNM8kwoD5JxZrzrCGb9bAff0CYLhnKfgGegn5UaweYfgdAFq9QpKwWnfR1v7zxGjbqZkcibIdVY3G96IvhhVDa30JGjgan5lUGMozyJfIFT2Aj76VEQPswD9uwN6kRDzIuqSvJe6P+OKxewqrTgw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725301998; c=relaxed/simple; bh=DCI7kwTH88FpIBoGdduz/HMziG2sNxAu1noSRoXa/bc=; h=Date:Subject:From:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZCEgjfrpAdZpAfk4FM4sbmmPFRK/ab8vpy6N2vQsiRUkWHtdFHCHUUcygrV6JaEFgGOWfFfmbdGp8e6rzI8ye4/dAwWoXewLnS3N6WIj7QpT560B59RfXKUAzSh0zzKBuPrng8K1odW5VfSKb6pELNOoFhA8l4WImzK+dlC4nVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DsAZ8RKq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DsAZ8RKq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29D26C4CEC2; Mon, 2 Sep 2024 18:33:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725301998; bh=DCI7kwTH88FpIBoGdduz/HMziG2sNxAu1noSRoXa/bc=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=DsAZ8RKq4PkfpEYRMT20pW1irs7av6Ip7I7aLFN+ek/FHTAm0iwml6yZhDcYMIqr0 Bf2MlE2u0oP/AU0lb0yiYpaYzMYIbay+wesjLQj3lSZBcJK1qzeLn7axbc1CvG0d/v 3JnKnReVC+cEAxSUqzGemzX17B58Z7IPa8cXy4XoYnhX5vU40OHGGKGWaSlcnT4BIo +bI4vx3oih+kcyYO7dLpPybf+02HQM74gbRXXRWcw2FVho1YbD1GfCJPHpLE82NzVJ 5GefY8LqcDEf9i1DxuN+ZHQNH8SnVxpLZqx8bObzzlSONsl6l15cW8Rt5aDu3HNPyH 6oL/gJuNXgYnQ== Date: Mon, 02 Sep 2024 11:33:17 -0700 Subject: [PATCH 3/3] xfs: fix a sloppy memory handling bug in xfs_iroot_realloc From: "Darrick J. Wong" To: chandanbabu@kernel.org, djwong@kernel.org Cc: Christoph Hellwig , linux-xfs@vger.kernel.org Message-ID: <172530107644.3326571.6313363096496638714.stgit@frogsfrogsfrogs> In-Reply-To: <172530107589.3326571.1610526525006344754.stgit@frogsfrogsfrogs> References: <172530107589.3326571.1610526525006344754.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong While refactoring code, I noticed that when xfs_iroot_realloc tries to shrink a bmbt root block, it allocates a smaller new block and then copies "records" and pointers to the new block. However, bmbt root blocks cannot ever be leaves, which means that it's not technically correct to copy records. We /should/ be copying keys. Note that this has never resulted in actual memory corruption because sizeof(bmbt_rec) == (sizeof(bmbt_key) + sizeof(bmbt_ptr)). However, this will no longer be true when we start adding realtime rmap stuff, so fix this now. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_inode_fork.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c index 9d11ae015909..622382300904 100644 --- a/fs/xfs/libxfs/xfs_inode_fork.c +++ b/fs/xfs/libxfs/xfs_inode_fork.c @@ -463,15 +463,15 @@ xfs_iroot_realloc( } /* - * Only copy the records and pointers if there are any. + * Only copy the keys and pointers if there are any. */ if (new_max > 0) { /* - * First copy the records. + * First copy the keys. */ - op = (char *)XFS_BMBT_REC_ADDR(mp, ifp->if_broot, 1); - np = (char *)XFS_BMBT_REC_ADDR(mp, new_broot, 1); - memcpy(np, op, new_max * (uint)sizeof(xfs_bmbt_rec_t)); + op = (char *)XFS_BMBT_KEY_ADDR(mp, ifp->if_broot, 1); + np = (char *)XFS_BMBT_KEY_ADDR(mp, new_broot, 1); + memcpy(np, op, new_max * (uint)sizeof(xfs_bmbt_key_t)); /* * Then copy the pointers.