From patchwork Wed Mar 13 17:28:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13591649 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 6C0B883CD0 for ; Wed, 13 Mar 2024 17:28:27 +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=1710350907; cv=none; b=fN7Pi/XQv+mRTiD8K9kXHlvJIhkVjI12a1lye11q75izphwy6l+GpD55307OljSRH3YIjlyk5ZFSXrldONTxTWFiIyVtX84hr465zpZ5/iM6hXuLZz13EwP/WwsRMlsN2+fS8FoX99MEphEjss5mTxG/ao7FOC59ZIznY/sZNuw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710350907; c=relaxed/simple; bh=QGx4x/dap8z34uSrgy9vLkFO9eETVAAiMwooC5u/gFY=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=n9Yp+5l2C56eJXfFm4YjXHuPFMuEbVWek8sYKKmnwXMdm8LmWRwYhPOtDuGe7ld+AsFyHlGnTxoez52exObc4BctobTgGVI6OPgBoc61MrNsh16Og2ovqk1/jmkMVE7JO7yeYlGLLCtuOyA9tj7RDMf8B77W1NVgwL9O4WDDvh4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VWdO8o/K; 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="VWdO8o/K" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B413C43394 for ; Wed, 13 Mar 2024 17:28:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710350907; bh=QGx4x/dap8z34uSrgy9vLkFO9eETVAAiMwooC5u/gFY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VWdO8o/KXD3Aua6WJgbn7fFqupLxI+FviGXCt5xwFkXGgLeCZ4bCcIcJMehlwa9up Xn1PmBLi6O189PQDfHgjt+JU4oMLOUcA03rjXTYwBbnhj7PEwoTLgMh98lJaJeRKzi 7qtd8foy2B0ftHWx+7fQphL94/St/2t5lK3uTIYaRQ++ERYZUM+vfzhvdMSaohQaci DejqUuEFsAxJT2YkEytbwx3vQ+78bVh8UNMqQnuhP/s/GEDKD2RI9RD8+Jcdv+YHNj QxlselXlP2Ia0O7Tiba5P9wN0g3bbztYj3H7hIK0K3RsMdL5QZQWVTPhKaBwk5R4MN lsZfoOhcPGLRA== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 1/4] btrfs: fix extent map leak in unexpected scenario at unpin_extent_cache() Date: Wed, 13 Mar 2024 17:28:19 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana At unpin_extent_cache() if we happen to find an extent map with an unexpected start offset, we jump to the 'out' label and never release the reference we added to the extent map through the call to lookup_extent_mapping(), therefore resulting in a leak. So fix this by moving the free_extent_map() under the 'out' label. Fixes: c03c89f821e5 ("btrfs: handle errors returned from unpin_extent_cache()") Signed-off-by: Filipe Manana Reviewed-by: Anand Jain --- fs/btrfs/extent_map.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c index 347ca13d15a9..e03953dbcd5e 100644 --- a/fs/btrfs/extent_map.c +++ b/fs/btrfs/extent_map.c @@ -340,9 +340,9 @@ int unpin_extent_cache(struct btrfs_inode *inode, u64 start, u64 len, u64 gen) em->mod_len = em->len; } - free_extent_map(em); out: write_unlock(&tree->lock); + free_extent_map(em); return ret; } From patchwork Wed Mar 13 17:28:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13591650 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 5B00783CDB for ; Wed, 13 Mar 2024 17:28:28 +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=1710350908; cv=none; b=BIYVs0jFxAWF6B2d5ktFBVcGCndG/EFhlOfOkv0/xZ86UhZ2aathihLtEExw4a5sx5PetOcJzdZaA4p6eGypsSH2hz0JbSyZ/xqfKWEkIG27MaobAGZ4r3vPThpnNZvQ0iLrHf0SUfAqB1rS5zmWKav+Y26cU6y+JSb9GNmgBoY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710350908; c=relaxed/simple; bh=0qHg+kqnHcIbRamgUH5v7fnWmZdE08NLcXsJknoxAbc=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ETCb9/n2BeeYRtypNEWyNtPBL5eFFV5xXjTMXbPDYSCK0y+zT+mX3sPzw0S5SD0l+rlO9+TQDIVVo3/YnxpZ3S005z/pr0iNU+9OMFzbnud7MKad6KZfCz9fS5QgUJMPnebv7dIn79bLQIGFElgSQeX3By8MYBLJ1mTCC9eiI7E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XkjBhpsC; 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="XkjBhpsC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66C2EC433C7 for ; Wed, 13 Mar 2024 17:28:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710350907; bh=0qHg+kqnHcIbRamgUH5v7fnWmZdE08NLcXsJknoxAbc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=XkjBhpsCUyRi9Uvw2R7xQToAH9NvCsqq8ry3ScqliJKRpD2/tMdMsNOrQzpLq88/t VxxsBkhJnl05UMUuLFSorVuKVnEeI4+swNzCTUSUzQk9cTwbf2WBp8fhjyOduP0PE/ 1RbVsfFeq9ETwgQyT3Wi/w4Gxe/0EhOFftbIchAYrerTxZeNEKl6ri8gvb7vnXrllk ISqNUAFuEqSfMnUJm13aM/l/d82L0NuvrZW+bun/TIdrXOOlmXngiXVaR4lRCL6SRh Hm/bvf20nxrZlJtShYwmYIFBG8FG/pa4fwEghVL+/+gMqXdvpdsUk06DvXI/Nw6NHO 1w1RBqFnb8xPg== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 2/4] btrfs: fix warning messages not printing interval at unpin_extent_range() Date: Wed, 13 Mar 2024 17:28:20 +0000 Message-Id: <7039902fc65bb3ec188a461436d19afbc71da1c1.1710350741.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana At unpin_extent_range() we print warning messages that are supposed to print an interval in the form "[X, Y)", with the first element being an inclusive start offset and the second element being the exclusive end offset of a range. However we end up printing the range's length instead of the range's exclusive end offset, so fix that to avoid having confusing and non-sense messages in case we hit one of these unexpected scenarios. Fixes: 00deaf04df35 ("btrfs: log messages at unpin_extent_range() during unexpected cases") Signed-off-by: Filipe Manana --- fs/btrfs/extent_map.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c index e03953dbcd5e..2cfc6e8cf76f 100644 --- a/fs/btrfs/extent_map.c +++ b/fs/btrfs/extent_map.c @@ -309,7 +309,7 @@ int unpin_extent_cache(struct btrfs_inode *inode, u64 start, u64 len, u64 gen) btrfs_warn(fs_info, "no extent map found for inode %llu (root %lld) when unpinning extent range [%llu, %llu), generation %llu", btrfs_ino(inode), btrfs_root_id(inode->root), - start, len, gen); + start, start + len, gen); ret = -ENOENT; goto out; } @@ -318,7 +318,7 @@ int unpin_extent_cache(struct btrfs_inode *inode, u64 start, u64 len, u64 gen) btrfs_warn(fs_info, "found extent map for inode %llu (root %lld) with unexpected start offset %llu when unpinning extent range [%llu, %llu), generation %llu", btrfs_ino(inode), btrfs_root_id(inode->root), - em->start, start, len, gen); + em->start, start, start + len, gen); ret = -EUCLEAN; goto out; } From patchwork Wed Mar 13 17:28:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13591651 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 0B5CB84038 for ; Wed, 13 Mar 2024 17:28:29 +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=1710350909; cv=none; b=LPZWmBKhzNTRCZSrSdWdEo0EAGmdAw/AMI8YvoL5rWahJjIQIIHlMHACS8NYtbeNz3zHUdhcrYKoQeBDoJ1econoBayDXmncesHd5dXnH7TIfqLZLTWltxoJZv0uMAzelzUJw1E6e1reZAHBnMk1dv4V3esfYBOu86zwMXabvlo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710350909; c=relaxed/simple; bh=TPIpgh436/RTkMU6hqLipvWCgLN+GFBBbvyuHhDu76s=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MtXGsIyTfXVD4JArPFqeEHXWSa2fS1mpRTEOTSqwaYfcgaFUH8kSgIQxtQVMWfm5ZEXP3cs/5xN3uB+kFEIWfPEMkWX/iqNYuDeF+MKBFgtSMao3nYpw7Kc1d2nLGddQHoaEq8UFTebt3SMjhuEpjq+Ew7pFMOM6rlPNFOO0UTc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BthV/ShU; 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="BthV/ShU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 616B9C43390 for ; Wed, 13 Mar 2024 17:28:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710350908; bh=TPIpgh436/RTkMU6hqLipvWCgLN+GFBBbvyuHhDu76s=; h=From:To:Subject:Date:In-Reply-To:References:From; b=BthV/ShU3Y2Mri0AdzfCRdpS6ZMc3OvWWLHrhGUgv8np0XZpYsiA8eMe4RtAIP3Ql sN9MStuLtWUAuHlaWrAT6u8MofsARBRk9ocqRZM/0j6LSMJhzy9YBkUipVr8bxDjdf /+SwzI1oWTY6SsiOQfiJ6jucurW+ZC1tF7DUh2MHbIAclvfC3JUj1OT8d41XC5hqQp ubyPmSl2EZmUWsJRccqNm3FX0f5GSsxYQy9/+yorCIEYZMmxpawl0ra3vNccIXsD/f HMBfmhejHjFIcwDRSy9reCOJJdZfFJlKm9OzRz6qA6Xy5bu9o5ePWeoIR30aLPRudO PHBHuGIKCbo4g== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 3/4] btrfs: fix message not properly printing interval when adding extent map Date: Wed, 13 Mar 2024 17:28:21 +0000 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana At btrfs_add_extent_mapping(), if we are unable to merge the existing extent map, we print a warning message that suggests interval ranges in the form "[X, Y)", where the first element is the inclusive start offset of a range and the second element is the exclusive end offset. However we end up printing the length of the ranges instead of the exclusive end offsets. So fix this by printing the range end offsets. Signed-off-by: Filipe Manana --- fs/btrfs/extent_map.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c index 2cfc6e8cf76f..16685cb8a91d 100644 --- a/fs/btrfs/extent_map.c +++ b/fs/btrfs/extent_map.c @@ -634,8 +634,8 @@ int btrfs_add_extent_mapping(struct btrfs_fs_info *fs_info, *em_in = NULL; WARN_ONCE(ret, "extent map merge error existing [%llu, %llu) with em [%llu, %llu) start %llu\n", - existing->start, existing->len, - orig_start, orig_len, start); + existing->start, extent_map_end(existing), + orig_start, orig_start + orig_len, start); } free_extent_map(existing); } From patchwork Wed Mar 13 17:28:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13591652 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 4FB0384A30 for ; Wed, 13 Mar 2024 17:28:30 +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=1710350910; cv=none; b=f1yAoPac9+j1UD5mTXa0mIGTzF6jU3bV8SO7bDQDLvvWF49PKjsiabZbCFHRaJWmDXkZBkEa9RUWrpPx8MNMT7UhLW7uTTnuTBR9ze7CbXR3qm1CsRjTNePWairV0Yi4WHVObyCSQLLuyZu7KGiO/jVzk/oWl1j4tF/ZTav6h48= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710350910; c=relaxed/simple; bh=DVPDeU0cmDBdqhuhGCk7LpAUe3v+CuTzMTDHPA17fcA=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GOxiPMkwFb3rkRkNY40GNZW5A5Bzp1SrRy0cBmh2X3r/xIE5ZmiKc+tq55AlehMyb20LnLp+bsoZ087wPdVaQ1whe5JgGFmt3HV6/xNnY/31iJ6tpGYAARw5J53MPPO8f9jyDcuDESLgqcur0SPYGnflrDcp1kmilxGQqlR6wj8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=os6u2zqc; 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="os6u2zqc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5BB8EC43390 for ; Wed, 13 Mar 2024 17:28:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710350909; bh=DVPDeU0cmDBdqhuhGCk7LpAUe3v+CuTzMTDHPA17fcA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=os6u2zqcKNFyy6YCHxnOgjkDf0larSgFzahmz5FSckbYQBVJs/sQYAqur8bmpaUJg 3PgPajjPLMTO+rpgpge7ERpWQ4Hq6Asa/e8qqPFMjH1QXfF65dzCR3g1IG1+ibheR0 wSFI6vI1TehPNyrzI9rOBGmgr6s1UMZdp2K/RIhJKSEQIAhfdWmHsL2ZbvqlA/fYU5 /d4c6oV6T/qBE7kvIHxngXp99zvZmokcPRYIP238VrGkkCT+TzWvVtA/Q+pQ6clne1 O9UgfEG/hVQyaBOAKiklooRewiGzTy/cTOy3hGVRDGK8iov6HewFSBGxpDwOZlRWLJ qlGbBpEWEKltw== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 4/4] btrfs: use btrfs_warn() to log message at btrfs_add_extent_mapping() Date: Wed, 13 Mar 2024 17:28:22 +0000 Message-Id: <0e3229ebf093bd436e4323ef0fd8f2b9124ba308.1710350741.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana At btrfs_add_extent_mapping(), if we failed to merge the extent map, which is unexpected and theoretically should never happen, we use WARN_ONCE() to log a message which is not great because we don't get information about which filesystem it relates to in case we have multiple btrfs filesystems mounted. So change this to use btrfs_warn() and surround the error check with WARN_ON() so we always get a useful stack trace and the condition is flagged as "unlikely" since it's not expected to ever happen. Signed-off-by: Filipe Manana --- fs/btrfs/extent_map.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c index 16685cb8a91d..445f7716f1e2 100644 --- a/fs/btrfs/extent_map.c +++ b/fs/btrfs/extent_map.c @@ -629,13 +629,13 @@ int btrfs_add_extent_mapping(struct btrfs_fs_info *fs_info, */ ret = merge_extent_mapping(em_tree, existing, em, start); - if (ret) { + if (WARN_ON(ret)) { free_extent_map(em); *em_in = NULL; - WARN_ONCE(ret, -"extent map merge error existing [%llu, %llu) with em [%llu, %llu) start %llu\n", - existing->start, extent_map_end(existing), - orig_start, orig_start + orig_len, start); + btrfs_warn(fs_info, +"extent map merge error existing [%llu, %llu) with em [%llu, %llu) start %llu", + existing->start, extent_map_end(existing), + orig_start, orig_start + orig_len, start); } free_extent_map(existing); }