From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796355271; b=inS6gSc7xQwivbAXvy8hv/QdW1lFkBM4+FkSnZK/kWsFCscQLHnn/B77pyxCS16Nz7Dk O8vjWvliK6DbVpwRi8/cwBqa8loRcYJ2phJmoQt95Ir93lHwfVr19ZixWp8F3F+HGOeaX geMQH8GtW7/E/7H7RX10WTL1A208a/rL/POiVLt9RagLrfIuqurDLm4tupfPEileb6lMQ ooTWPRWfqPbdLOWFk0e3tc+c1LNDewpuEkxfyYwmTmOFQXporHqpUaF2ZHVJK+sFqOHJr 3hIcUB3amXPLNQFnj3YMfiy5qlLoe7+O+zn7SSo5tvOOUvy74pJLX01zjNEDBowL5JA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796355271; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=zBGEuiVsrdPDZVuivveVOBfoXcuKesIjmFXFqyezwqU=; b=P9YUo0ZqirHn/Ax0HWlWl1eE9bvBfFMTaGb45us0tHvx4FazK28UDxlDdj+8u65VDHzu e8k58Zfai1YfBNddjzOVc3DRxI0UclVkFh5qxMeIfw9mofaRU6bABtwXCd7V1YU4BjYdN 4e5vbEBtMOeTOITpTCMtUt+FVfLo8l0P6p23eugrJkmiY62e5Bpao2h/XN6UL9c5QVdp1 BenrfLHBfkdXt+ESse/sMLMJWgrNL6VhoeG/PNafrp48Z5LMCC/B+2Vvx1TSGOh2PDT2c 9vfgA2QmjZg4gZTgLz5HWwhnivpC6XhLpceQ3Lwdk6DzTb4Ow3lmJFXVP+yMSrE+KPg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mdtYh0xs; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE701606A322 for ; Fri, 4 Dec 2026 03:34:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=mdtYh0xs Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FCFD1F00897; Fri, 4 Dec 2026 03:34:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796355271; bh=zBGEuiVsrdPDZVuivveVOBfoXcuKesIjmFXFqyezwqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=mdtYh0xsiVnT+ZYF/DBWlugS3kvPmI8Zkv1r6Blvx5RTC0iuwezk/6QynOpiKclA1 pYGEhfqGQ19L44bNuIuNUzXumRCOga15nmTOV6PQLsNeOj0E0lr5CkDyv95z2vH4NX zi+naDtyHlUv0AG5ZhRGk+XJ+V++2tbF/r+ocyka7St08gjgpKJ02arwvrRFnhiDQ8 761dh0wR5W1l1ZkX1WeYugOH5ztAQ8FeCTBI7fVFcPiQX+t5uL8arraIXyP5+sM88v FZpO1qA1ygoYD9E4ni+s8wNxRjFzwMr5gaMeqURg3wvTiq/zOBFQwYJm/AMMv23qfY WwK0ebIlueJvQ== From: Sasha Levin To: stable@vger.kernel.org Cc: "Liam R. Howlett (Google)" , Andrew Morton , Lorenzo Stoakes , Chris Mason , Alice Ryhl , Andrew Ballance , Sasha Levin Subject: [PATCH 6.12.y 2/2] maple_tree: update internal warning and bug_on code Date: Thu, 3 Dec 2026 22:34:28 -0500 Message-ID: <20261204033359.2424881-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261204033359.2424881-1-sashal@kernel.org> References: <2026120221-brisket-jaunt-0540@gregkh> <20261204033359.2424881-1-sashal@kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Liam R. Howlett (Google)" [ Upstream commit f51d35b81fb572c551e82ff72575d6dbb8e35ba9 ] When CONFIG_DEBUG_MAPLE_TREE is set, call WARN_ON() once per site after the custom information is dumped about the tree. Without using the kernel's WARN_ON calls, syzbot will not catch issues detected by this code. The BUG_ON variants now stop instead of dumping and continuing. Update the non-debug code to call WARN_ON_ONCE() as well. The userspace tests asserted on dump_stack() but only print on WARN_ON(), so make WARN() fatal in maple-shared.h and have the maple test exit with the result of maple_tree_seed(). Link: https://lore.kernel.org/20261103020724.2614498-4-liam@infradead.org Fixes: f0a1f866aba1 ("maple_tree: add debug BUG_ON and WARN_ON variants") Signed-off-by: Liam R. Howlett (Google) Signed-off-by: Andrew Morton Reported-by: Lorenzo Stoakes Reviewed-by: Lorenzo Stoakes (ARM) Cc: Chris Mason Cc: Alice Ryhl Cc: Andrew Ballance Cc: Signed-off-by: Sasha Levin --- include/linux/maple_tree.h | 48 ++++++++++++++--------------- tools/testing/radix-tree/maple.c | 13 +++++--- tools/testing/shared/maple-shared.h | 33 ++++++++++++++++++++ 3 files changed, 66 insertions(+), 28 deletions(-) diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h index 4300f7746f2dc..8647f2980c999 100644 --- a/include/linux/maple_tree.h +++ b/include/linux/maple_tree.h @@ -619,7 +619,7 @@ void mt_cache_shrink(void); pr_info("Pass: %u Run:%u\n", \ atomic_read(&maple_tree_tests_passed), \ atomic_read(&maple_tree_tests_run)); \ - dump_stack(); \ + BUG_ON(1); \ } else { \ atomic_inc(&maple_tree_tests_passed); \ } \ @@ -635,7 +635,7 @@ void mt_cache_shrink(void); pr_info("Pass: %u Run:%u\n", \ atomic_read(&maple_tree_tests_passed), \ atomic_read(&maple_tree_tests_run)); \ - dump_stack(); \ + BUG_ON(1); \ } else { \ atomic_inc(&maple_tree_tests_passed); \ } \ @@ -652,7 +652,7 @@ void mt_cache_shrink(void); pr_info("Pass: %u Run:%u\n", \ atomic_read(&maple_tree_tests_passed), \ atomic_read(&maple_tree_tests_run)); \ - dump_stack(); \ + BUG_ON(1); \ } else { \ atomic_inc(&maple_tree_tests_passed); \ } \ @@ -661,16 +661,16 @@ void mt_cache_shrink(void); #define MT_WARN_ON(__tree, __x) ({ \ int ret = !!(__x); \ atomic_inc(&maple_tree_tests_run); \ - if (ret) { \ - pr_info("WARN at %s:%d (%u)\n", \ - __func__, __LINE__, __x); \ + if (!ret) { \ + atomic_inc(&maple_tree_tests_passed); \ + } else if (__ONCE_LITE_IF(ret)) { \ + pr_info("WARN at %s:%d\n", \ + __func__, __LINE__); \ mt_dump(__tree, mt_dump_hex); \ pr_info("Pass: %u Run:%u\n", \ atomic_read(&maple_tree_tests_passed), \ atomic_read(&maple_tree_tests_run)); \ - dump_stack(); \ - } else { \ - atomic_inc(&maple_tree_tests_passed); \ + WARN_ON(1); \ } \ unlikely(ret); \ }) @@ -678,17 +678,17 @@ void mt_cache_shrink(void); #define MAS_WARN_ON(__mas, __x) ({ \ int ret = !!(__x); \ atomic_inc(&maple_tree_tests_run); \ - if (ret) { \ - pr_info("WARN at %s:%d (%u)\n", \ - __func__, __LINE__, __x); \ + if (!ret) { \ + atomic_inc(&maple_tree_tests_passed); \ + } else if (__ONCE_LITE_IF(ret)) { \ + pr_info("WARN at %s:%d\n", \ + __func__, __LINE__); \ mas_dump(__mas); \ mt_dump((__mas)->tree, mt_dump_hex); \ pr_info("Pass: %u Run:%u\n", \ atomic_read(&maple_tree_tests_passed), \ atomic_read(&maple_tree_tests_run)); \ - dump_stack(); \ - } else { \ - atomic_inc(&maple_tree_tests_passed); \ + WARN_ON(1); \ } \ unlikely(ret); \ }) @@ -696,18 +696,18 @@ void mt_cache_shrink(void); #define MAS_WR_WARN_ON(__wrmas, __x) ({ \ int ret = !!(__x); \ atomic_inc(&maple_tree_tests_run); \ - if (ret) { \ - pr_info("WARN at %s:%d (%u)\n", \ - __func__, __LINE__, __x); \ + if (!ret) { \ + atomic_inc(&maple_tree_tests_passed); \ + } else if (__ONCE_LITE_IF(ret)) { \ + pr_info("WARN at %s:%d\n", \ + __func__, __LINE__); \ mas_wr_dump(__wrmas); \ mas_dump((__wrmas)->mas); \ mt_dump((__wrmas)->mas->tree, mt_dump_hex); \ pr_info("Pass: %u Run:%u\n", \ atomic_read(&maple_tree_tests_passed), \ atomic_read(&maple_tree_tests_run)); \ - dump_stack(); \ - } else { \ - atomic_inc(&maple_tree_tests_passed); \ + WARN_ON(1); \ } \ unlikely(ret); \ }) @@ -715,9 +715,9 @@ void mt_cache_shrink(void); #define MT_BUG_ON(__tree, __x) BUG_ON(__x) #define MAS_BUG_ON(__mas, __x) BUG_ON(__x) #define MAS_WR_BUG_ON(__mas, __x) BUG_ON(__x) -#define MT_WARN_ON(__tree, __x) WARN_ON(__x) -#define MAS_WARN_ON(__mas, __x) WARN_ON(__x) -#define MAS_WR_WARN_ON(__mas, __x) WARN_ON(__x) +#define MT_WARN_ON(__tree, __x) WARN_ON_ONCE(__x) +#define MAS_WARN_ON(__mas, __x) WARN_ON_ONCE(__x) +#define MAS_WR_WARN_ON(__mas, __x) WARN_ON_ONCE(__x) #endif /* CONFIG_DEBUG_MAPLE_TREE */ /** diff --git a/tools/testing/radix-tree/maple.c b/tools/testing/radix-tree/maple.c index 551ae6898c1d2..152f4e7f0c6d9 100644 --- a/tools/testing/radix-tree/maple.c +++ b/tools/testing/radix-tree/maple.c @@ -36515,22 +36515,27 @@ static void regression_tests(void) test_spanning_store_regression(); } -void maple_tree_tests(void) +int maple_tree_tests(void) { + int ret; + #if !defined(BENCH) regression_tests(); farmer_tests(); #endif - maple_tree_seed(); + ret = maple_tree_seed(); maple_tree_harvest(); + return ret; } int __weak main(void) { + int ret; + maple_tree_init(); - maple_tree_tests(); + ret = maple_tree_tests(); rcu_barrier(); if (nr_allocated) printf("nr_allocated = %d\n", nr_allocated); - return 0; + return ret ? EXIT_FAILURE : EXIT_SUCCESS; } diff --git a/tools/testing/shared/maple-shared.h b/tools/testing/shared/maple-shared.h index 2a1e9a8594a28..5f827709773a0 100644 --- a/tools/testing/shared/maple-shared.h +++ b/tools/testing/shared/maple-shared.h @@ -8,6 +8,7 @@ #include "shared.h" #include #include +#include #include "linux/init.h" void maple_rcu_cb(struct rcu_head *head); @@ -20,5 +21,37 @@ do { \ call_rcu(&((_p_struct)->_memb), rcu_cb); \ } while(0); +/* Make WARN() fatal */ +#undef WARN +#undef WARN_ON +#undef WARN_ONCE +#undef WARN_ON_ONCE +#define WARN(condition, format...) ({ \ + int __ret_warn_on = !!(condition); \ + if (unlikely(__ret_warn_on)) { \ + __WARN_printf(format); \ + assert(0); \ + } \ + unlikely(__ret_warn_on); \ +}) +#define WARN_ON(condition) \ + WARN(condition, "assertion failed at %s:%d\n", __FILE__, __LINE__) +#define WARN_ONCE(condition, format...) WARN(condition, format) +#define WARN_ON_ONCE(condition) WARN_ON(condition) + +/* Once state for the debug macros */ +#ifndef __ONCE_LITE_IF +#define __ONCE_LITE_IF(condition) \ + ({ \ + static bool __already_done; \ + bool __ret_once = false; \ + \ + if ((condition) && !__already_done) { \ + __already_done = true; \ + __ret_once = true; \ + } \ + __ret_once; \ + }) +#endif #endif /* __MAPLE_SHARED_H__ */ -- 2.53.0