From nobody Fri Sep 25 13:19:17 2026 Received: from mail-pj2-f13.google.com (mail-pj2-f13.google.com [74.125.227.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C4EB48640F for ; Fri, 11 Sep 2026 22:14:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.227.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789164898; cv=none; b=hNtlsrXKpXU2etrxJD/EytjGsMYJ/6PdO/ohcmVusl5UyW/3pr5K/aaiG5i/1aQ8mHcwyTYMH39/D8AeXjGrZh/66bkkHAAq80N3Gmw95S7rxGct1rG7Z5z4zBhGPUp6C7nzev9Ac27knNkMoLAp1wJT7UfTIpVBCoDB87l2QuU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789164898; c=relaxed/simple; bh=nqm+qgcrDbRH0g5TEzWGEqU1WZ6bbOniRLl1yX0/X+Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cQeCgs62acn5dL7Own9lkvFAZalr0ZxqjIL0wb8xCyuA1OrLCx935wWuZt+QEOU5nlVLvmAX+pkYUZPIDD+DuxRki5fb2dFNB5NrLEBxXL3CfCKabSr8Tt+4mgHnmHssB2B1L8MGRLNnSa8cpawnsB7JxVfVxY5iROK8A1V++4I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DdgDJty3; arc=none smtp.client-ip=74.125.227.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DdgDJty3" Received: by mail-pj2-f13.google.com with SMTP id 98e67ed59e1d1-396ccafb750so282371a91.1 for ; Fri, 11 Sep 2026 15:14:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789164890; x=1789769690; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=r2k+37bKOMj5uflztInqcHyMEmLHoz6JlZjzrLWxQac=; b=DdgDJty3eQhtWdUClp4cLd00Buf85QwNLXU3OHgNikurRiw2L5KM2f9WTlDwFxwU6G Me6ZUADl7lQfen3ltBad+mwrkDqALCHzYO91pwcfamIHeGDPy6HOf5YsaMvPvDJrb4qH eGAR5dqY7mFWyOQGj6HEaWa8se7Ctg8WpzN+ZA5CEPQcILhC30jrfmIAQXBK01ch/mzk /0ctkzIhf40ohV0ZD9hQ+cq70Q0oW882uemZ/hKCbpFCruIw3Wzozxz9QsmHw2N4yvWq rMeM3bhl8yVvYKSyKfZyfDbiW+5T6QfPsGDzhAEsw8aOqBE/IuFCiDTinjofMt+NC0gQ 2J+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789164890; x=1789769690; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=r2k+37bKOMj5uflztInqcHyMEmLHoz6JlZjzrLWxQac=; b=VLGs4eAGvBN44548wDxAP3txCdqbwZxvAADIk7ZWdPhT3SyE8Z2B/qRMiLoA2GU+Yj CIC8wpgII4Bex4QMRFwDvitUbs9rYS97CCap55uKbNAqrjlc6M/VCArS8d64cQH/iAN5 fKmL23jbGMZmhOE17r54BUUFTgy/E1LeB+ll1FMH2LUg6iwYONIF0bt9NqBD9uys2KIs NTUMCA6KwI2/31HLF3vutJ3FWgRcC2n7xwQUkGtWkP2TH3u5oSecodnDV33O6GHTT7Hp WuPgkn1XauA+1D19hIGHB0a/W+eFrq+42H9S0OWtAUYrloSpBaqnsYHm9DjejZthBA+F 3/PA== X-Forwarded-Encrypted: i=1; AKwUvBw3rHLfJNFVwI6ytfGz4lZWsm3IlHkmlAeNX6tZ1fk+cp8oRaqEFZkEm29QumDIDeOZe0AtbdPOiwqxt/M=@vger.kernel.org X-Gm-Message-State: AFuF++nroAEGxuSVH6WQL9C3zIFX8jrLW+T+9yiGD5KX/a6SpPjgQkdK YBBCNDfDEMAslAbhS52GmsaQSigiP0GChnE9kfu4KwktcWdK0fFLWGyp X-Gm-Gg: AYBFou2JDvtc76jpx75q4lhlQwjfVIJSwH4Ox97M69QYw6vybUQKuuc8fSZaH2myzMl nDErOvqf47I2Z70YVt/f8lsSxjnUf+dcK0xyn0U+utie55kb4/ntQgTw8dJhisk013mmms20Qq2 JVlQyDEc4vYaZ1C4W/FPFFUk03dl96Ie8Ca/14Z2JirNqufuaNEM1UDN9yxSguTeIgkIi8p4SND Ybk+xN0weg3ku8lCIXdSp9johdC8xMrceXtXDb2egnUFun/Gjlv/Q4kscgIuzpsRYe8s5Vu5ZQM QlfhwlnByZzmmXCEnyjE5u8rk3UdSMrWdJnSR5pkf7lrheTNB+mjKf7KF+UzsPvJlJS6nfXiuT2 0pi7HaegaQLu7nwS/QX2M+FMbGvg6MZSH40wXDQx21MH14tY/LBv/PUrCtuP2IAeRdZRomjZH/H wIqBi8eTk1NtlOCgzYCJ+G838LlPy0M7W9fwMJuS0cXGekYFSVz9xwoar3Sjt9P0LUrh8= X-Received: by 2002:a17:90b:3c03:b0:398:de23:9af6 with SMTP id 98e67ed59e1d1-39d9c1db154mr11222277a91.15.1789164889827; Fri, 11 Sep 2026 15:14:49 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-14365b8137fsm9073522c88.9.2026.09.11.15.14.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 15:14:49 -0700 (PDT) From: Yury Norov X-Google-Original-From: Yury Norov To: Andrew Morton , Matthew Wilcox , "Liam R. Howlett" Cc: Yury Norov , Chris Li , Alice Ryhl , Andrew Ballance , Yury Norov , linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, maple-tree@lists.infradead.org Subject: [PATCH 1/3] compiler.h: add ASSERT_STATIC_STORAGE() Date: Fri, 11 Sep 2026 18:14:41 -0400 Message-ID: <20260911221444.1523311-2-ynorov@nvidia.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260911221444.1523311-1-ynorov@nvidia.com> References: <20260911221444.1523311-1-ynorov@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Static lock initializers rely on a persistent object address when lockdep assigns a lock-class key. Using such an initializer for an automatic local object can compile successfully but disable lockdep on the first lock acquisition. Add ASSERT_STATIC_STORAGE() for declaration macros that require static storage duration. It declares an unused static pointer initialized with the object's address. An automatic local object's address is not a valid static initializer, so the compiler rejects it. Mirror the helper in tools/include/linux/compiler.h because the userspace radix-tree tests include the kernel IDA and Maple Tree headers with the tools compiler definitions. For example: void example(void) { int object; ASSERT_STATIC_STORAGE(object); } GCC reports: error: initializer element is not constant name##_storage_check =3D &(name) ^ note: in expansion of macro 'ASSERT_STATIC_STORAGE' ASSERT_STATIC_STORAGE(object); File-scope objects and static local objects remain valid. The helper takes an object identifier and must be used as a declaration after that object has been declared. Link: https://lore.kernel.org/all/20260911155244.1406122-1-ynorov@nvidia.co= m/ Signed-off-by: Yury Norov --- include/linux/compiler.h | 5 +++++ tools/include/linux/compiler.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index cb2f6050bdf7..ef9036fa5413 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -275,6 +275,11 @@ static inline void *offset_to_ptr(const int *off) #define __ADDRESSABLE(sym) \ ___ADDRESSABLE(sym, __section(".discard.addressable")) =20 +/* Enforce static storage duration. */ +#define ASSERT_STATIC_STORAGE(name) \ + static typeof(name) * const __always_unused \ + name##_storage_check =3D &(name) + /* * This returns a constant expression while determining if an argument is * a constant expression, most importantly without evaluating the argument. diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h index f2f54b038168..03ecf9086643 100644 --- a/tools/include/linux/compiler.h +++ b/tools/include/linux/compiler.h @@ -73,6 +73,11 @@ # define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(= b)) #endif =20 +/* Enforce static storage duration. */ +#define ASSERT_STATIC_STORAGE(name) \ + static typeof(name) * const __always_unused \ + name##_storage_check =3D &(name) + /* * This returns a constant expression while determining if an argument is * a constant expression, most importantly without evaluating the argument. --=20 2.53.0 From nobody Fri Sep 25 13:19:17 2026 Received: from mail-pz2-f43.google.com (mail-pz2-f43.google.com [74.125.228.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC7C3389104 for ; Fri, 11 Sep 2026 22:14:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789164898; cv=none; b=IICoCBBzh6tFcaVNyhVSVr2PH5NjuhOs4xlkwTtxXXKgH/bfeZ21qaRMVf+CYIOxrsSp6Y8aLkol3EOw1eRN9eoLfd2E2yHzHu40aZ4ZbXy/uNo0HT8RLhewvpo56a3JLhR/8WRdvJC3BivxyGMYGC18ayErDfsHtxYyRWcxYoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789164898; c=relaxed/simple; bh=LdQoQbgZU0lrWT2pURL+7/e3k5+0HWD3ja5iw2sMZws=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T+OaWi5g5Z2ddsFJ1uCxjVzoWpjHmiXm/slJpeDkBF08oQObq2xR3dJSqtUGdXygtYtiNgybI32O/UOMm9occlBxl9RNVisAGFaqVY0EXlHK+wTUYtFGPHUW1IoF3RS/BXqkVKYMA/CTcyX4Fy/jJSiTSkV4X7FLoVP5N49DHpU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=rrVk6KRS; arc=none smtp.client-ip=74.125.228.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rrVk6KRS" Received: by mail-pz2-f43.google.com with SMTP id 41be03b00d2f7-cc4c08393dfso36353a12.3 for ; Fri, 11 Sep 2026 15:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789164893; x=1789769693; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=bZMF2qooMPRk5Hq78os7KgYAWUsTasHU8sMqJeIvwpw=; b=rrVk6KRSqjxvzJ+D42cYDvBAtF2/WIXzMMqbkVrCRgEA6udEx+DbmuyffQkpfW9OdZ eVo5R5OjMVvCdMTIMluZuG6iYjZvQ2+TiaFyCzvHXSFrePjwcoaDwc92R8hbc9puoF0c VLrZ9UfOJkw47pNqd6rksfJtMxgkOIPQH+S5We6VMSvzoU+tw9vBQaagy79oZMO+mNHx UCbzemGSeygMJrdlwrhaTYOreDpwJkW48fgi9a0EYLgu9Ynirp2EJTbEEWXL5UupL/CC TiAwlASF5L/FHyS8SxF7l+qyEz9iRJIR+SxcYopKL68zxjV+FiqtB0xyvZPi0PkNZyKZ wqsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789164893; x=1789769693; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=bZMF2qooMPRk5Hq78os7KgYAWUsTasHU8sMqJeIvwpw=; b=EK6BKKKEHoAaDcbqxHJPvq0NUwafQyT+yNtGyKH+tdp+0+kejJdQayN91qYHgZ7lJ+ pC30JqSzkDXZnMaiQVa80iFHCtXvu40jp3TFMfX/cBAq4lRe5NX9uZiuccqG9ReYFZQ8 JEZAoI6e+TqbyRFRnRqTumrPN6/onmJRq/xcmtcn1z7tjmtyE9DELcQ8psJE73uZKork tjIScIWBZNs23WfbR0kAsCnxThLPwTXruOZ3BpYvEGNcM5ZH7k/otjLVvp9q16gnVyd/ ZzfJRwpxLmnOyEJUmKiZnTPS5wnYRFR8JepeX/aOUmm5CsGIK79F0H8d2Rwufbfm2OFl u1fg== X-Forwarded-Encrypted: i=1; AKwUvBxkAd80YCfYb5afZrzlsmtGfxWnMhp8nvyGgsmJgRG3ldgqnjX4QODeHYFcujkEtHXaAnKpng8oXjedDN0=@vger.kernel.org X-Gm-Message-State: AFuF++nM5XyAzgvlhJFH7mbPjHFQDpDP9300s33iqTGNkMDPIymFSPEi ouIWROkSGctPUFzC33ok0NgZPFtmlv7XBhYP3ZhM2qCPH0X98g+2+L0E X-Gm-Gg: AYBFou0cYgqOLBMQALO8I1PRYwFzH9k+b6UzzCoVePGNuUhCu++cu4dmxTwmcr0lVQV 2M5qc48ehO9F9rjoi2TPfxn9sv0yugl8UWU9l6N1b1ca7reUKQbyu7f6kMF7ol2fm9Oyghrs+4q O+hlvh8rhoFUb9Q2Trp6GgZfT88swoFPwewaE9ZTTJgvtxBAleUoMGIxW3EkfrLbwW/g0z0Gk0/ pHzmOPVahpcNcPz2KSq+tfbSe/vbE3MvZ/dGWMY1pC6/mVF8e6BgtB+76nFR2GRuP30tC9xRa3R fVPsL1spiWPJ7u46fY+ATDUFrVriLJjajjhtB3GW39+gL6MickOpChYGmxZY8r7pR4CQOfibiKe 3nccRqTiaBVtKVVCOquY8xXz0r+WBVOoKAPm0OIl87hsQrEUSWwbs5pG4hTp4acLqto1B9gH1Az JjupnMogzpxrkZY0IS45G7tTAXMhyqfuiy2tyBBjAphnHte4a+Xdky5VAs1F30mTNMflOx X-Received: by 2002:a17:90b:258e:b0:39b:2c00:c3f5 with SMTP id 98e67ed59e1d1-39dbc6d8753mr375019a91.18.1789164892609; Fri, 11 Sep 2026 15:14:52 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-33ba4e51449sm7862656eec.5.2026.09.11.15.14.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 15:14:51 -0700 (PDT) From: Yury Norov X-Google-Original-From: Yury Norov To: Andrew Morton , Matthew Wilcox , "Liam R. Howlett" Cc: Yury Norov , Chris Li , Alice Ryhl , Andrew Ballance , Yury Norov , linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, maple-tree@lists.infradead.org Subject: [PATCH 2/3] idr: assert static storage for DEFINE_IDA() Date: Fri, 11 Sep 2026 18:14:42 -0400 Message-ID: <20260911221444.1523311-3-ynorov@nvidia.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260911221444.1523311-1-ynorov@nvidia.com> References: <20260911221444.1523311-1-ynorov@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" DEFINE_IDA() uses IDA_INIT(), which initializes the embedded XArray lock with a static spinlock initializer. For an automatic local IDA, lockdep cannot use the lock address as a persistent class key and reports "INFO: trying to register non-static key" before disabling itself. Apply ASSERT_STATIC_STORAGE() to DEFINE_IDA() so that this misuse is rejected at compile time. For example: void example(void) { DEFINE_IDA(ida); ida_destroy(&ida); } GCC reports: error: initializer element is not constant name##_storage_check =3D &(name) ^ note: in expansion of macro 'ASSERT_STATIC_STORAGE' ASSERT_STATIC_STORAGE(name) note: in expansion of macro 'DEFINE_IDA' DEFINE_IDA(ida); File-scope definitions and static DEFINE_IDA() within a function remain valid. Automatic local IDAs must instead be initialized with ida_init(). Direct uses of IDA_INIT() are not covered by this declaration check. Convert the five automatic local IDAs in the userspace radix-tree tests to ida_init() so they satisfy the new requirement. Validated file-scope and static local definitions with a kernel object build, and confirmed that an automatic local definition fails to compile. Signed-off-by: Yury Norov --- include/linux/idr.h | 5 ++++- tools/testing/radix-tree/idr-test.c | 20 +++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/include/linux/idr.h b/include/linux/idr.h index 789e23e67444..e2a4b6298511 100644 --- a/include/linux/idr.h +++ b/include/linux/idr.h @@ -16,6 +16,7 @@ #include #include #include +#include =20 struct idr { struct radix_tree_root idr_rt; @@ -269,7 +270,9 @@ struct ida { #define IDA_INIT(name) { \ .xa =3D XARRAY_INIT(name, IDA_INIT_FLAGS) \ } -#define DEFINE_IDA(name) struct ida name =3D IDA_INIT(name) +#define DEFINE_IDA(name) \ + struct ida name =3D IDA_INIT(name); \ + ASSERT_STATIC_STORAGE(name) =20 int ida_alloc_range(struct ida *, unsigned int min, unsigned int max, gfp_= t); void ida_free(struct ida *, unsigned int id); diff --git a/tools/testing/radix-tree/idr-test.c b/tools/testing/radix-tree= /idr-test.c index 945144e98507..6fcba5b5870b 100644 --- a/tools/testing/radix-tree/idr-test.c +++ b/tools/testing/radix-tree/idr-test.c @@ -460,9 +460,11 @@ void ida_dump(struct ida *); */ void ida_check_nomem(void) { - DEFINE_IDA(ida); + struct ida ida; int id; =20 + ida_init(&ida); + id =3D ida_alloc_min(&ida, 256, GFP_NOWAIT); IDA_BUG_ON(&ida, id !=3D -ENOMEM); id =3D ida_alloc_min(&ida, 1UL << 30, GFP_NOWAIT); @@ -475,9 +477,11 @@ void ida_check_nomem(void) */ void ida_check_conv_user(void) { - DEFINE_IDA(ida); + struct ida ida; unsigned long i; =20 + ida_init(&ida); + for (i =3D 0; i < 1000000; i++) { int id =3D ida_alloc(&ida, GFP_NOWAIT); if (id =3D=3D -ENOMEM) { @@ -496,11 +500,13 @@ void ida_check_conv_user(void) =20 void ida_check_random(void) { - DEFINE_IDA(ida); + struct ida ida; DECLARE_BITMAP(bitmap, 2048); unsigned int i; time_t s =3D time(NULL); =20 + ida_init(&ida); + repeat: memset(bitmap, 0, sizeof(bitmap)); for (i =3D 0; i < 100000; i++) { @@ -522,9 +528,11 @@ void ida_check_random(void) =20 void ida_alloc_free_test(void) { - DEFINE_IDA(ida); + struct ida ida; unsigned long i; =20 + ida_init(&ida); + for (i =3D 0; i < 10000; i++) assert(ida_alloc_max(&ida, 20000, GFP_KERNEL) =3D=3D i); assert(ida_alloc_range(&ida, 5, 30, GFP_KERNEL) < 0); @@ -576,10 +584,12 @@ static void *ida_leak_fn(void *arg) =20 void ida_thread_tests(void) { - DEFINE_IDA(ida); + struct ida ida; pthread_t threads[20]; int i; =20 + ida_init(&ida); + for (i =3D 0; i < ARRAY_SIZE(threads); i++) if (pthread_create(&threads[i], NULL, ida_random_fn, NULL)) { perror("creating ida thread"); --=20 2.53.0 From nobody Fri Sep 25 13:19:17 2026 Received: from mail-pj2-f13.google.com (mail-pj2-f13.google.com [74.125.227.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3ECA497B7D for ; Fri, 11 Sep 2026 22:14:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.227.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789164902; cv=none; b=C64eE7OERWN/DVeStnke4mJLglO8DodT8TzRsndXR8vlGGCSYliKnkmLxPrEwFQ7hceYnrQPMcdAS5O4k1KJl4A6uKmZpCSbz9vUwncFXMb7U9CQ2Xs3LdFYzhZxur4HnoP7Pr4kdWM77FZy3M0k2vpGlKBXt9G4mxuaC3Invz8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789164902; c=relaxed/simple; bh=kudAxJVFZ3LQbBf9zKs5zuF1NACSED3RdhqSu+YS0fU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i6FjcQhV7au2haFsA6djBUIEPH2NyRSvKJQT5pi4KNHlcrQ/02Q+3SBHHb+bFuVt6iZcwj0WCr2Lhy6H7a69KW8LwB01WsUZD59ZBS3nGy9NPtJbdyI3h9v8gSADm0M2tAaBsftpyPxD9etLjjxEABothnB4Xa5vHVPSq8kNKfk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fHJG2xrY; arc=none smtp.client-ip=74.125.227.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fHJG2xrY" Received: by mail-pj2-f13.google.com with SMTP id 98e67ed59e1d1-396ccb1a98fso39964a91.1 for ; Fri, 11 Sep 2026 15:14:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789164895; x=1789769695; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=SryPbedwt+PB/tIiQ1DKQcYvegcDPhcxT20I1ilZbIQ=; b=fHJG2xrYjiL5PLaGfFFj/j1/KQCLrVyMA6VNZN9eBuw2f2Y9Qwx0OERj4fIXafwoi9 AjwLb12BpPcNEBDU2szOAnFqcj1CwnWzDIbYagfy0FbEXDKjszhlTo+76fUOR95TeQ+s FLWAOEGdCwyLsV6ul7SsoNhobgOQdufVuVTsKPnmWXvHt52E8405ieIZzjQSaIInky3b 16nTjwGOJuiuFdc2OuBwaAIERak01AjMLJHyf1Mz91KyFPyoZhrpnAReU/JWxucRT/ZU 3fevjdDFpDy2AAs8kUCtrAzwCTwKY6MPHzkpnYckQ0/SuYIBK3B3ALNGz9G9bBnj1hH2 JkRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789164895; x=1789769695; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=SryPbedwt+PB/tIiQ1DKQcYvegcDPhcxT20I1ilZbIQ=; b=V2l79X5IXp3WnYdngQf/9qtt+AYAAmtWx8i6bVffrcH6zahir20KhXG/Q+S21GH9UD ofc74m6jTloeeyJPqWtd78whmrYdKeH8TmH9smuMjii2mHJFdPQPw01n43dZtkt30wi0 xLM3gu40yu5WpeVw0yJ5dXh1E63dS5fMmpvnaidQOZV3Xid0hW9X0msgJxpq/w/XLER8 VqGYk1cYD57r2qrnX+7hcJ9GYR+vpVlTR401MaYxdApFo7stLNWHZiw+3B5VzsLhuoOJ YhZXjshoviw7kR/n3DadDMC06r7a3aMrEw35B05nXXzz65MuOQRAGBnhMXSdJLK74VCm y7jw== X-Forwarded-Encrypted: i=1; AKwUvByqrjb7pGvff6XNi8ZS9AY6PAluXeaJz+mGrUrALMAk0XQjaN6CWHtVmCB24QDepFGmU5Z6ZqlYQ4l9V7M=@vger.kernel.org X-Gm-Message-State: AFuF++kSYEDQr8Lp4KTj8XrmUg0C3bdCAYu8YaOeOlHPuyQ2e4COF8gr YDaXwWc56uMiOdHWkffra+vO9pxYqiGU3XxiQtF2i60IQnVoORaMfBvk/3yzaA== X-Gm-Gg: AYBFou17l17osLQGgnkCphz6qC5WN7AFiySIrpjrmX8rRFQIko7wk5FbE6jqo2mwIgr 91e1hcHDEn6D1O8Ww9nJHOnQlWeF9F1PJbF0v0gMprCVOiFxjGMS3TvMNnzrlGZHR38rufk2JQB jUI0DBvaZ4IbEZf4AA2brblvTgbJEJnP11XX0IluaEgdlQG3FfJ7Fct9oT0uz3SMPXPh6ItX94/ TMGB/peC8a4wFsrFa/I7ZkjsYlZwjJwzrVSOPGO+SycqCs9eBwQqsJL/L2yoO/r68B5DcJuMC19 a+IchbMdHB6CBsa9yLuFcsbTYhox3RGZzzh42wKn6wIh/PD+8joLnMp7KP6Qw6QnURSgFxc9TAy E8R0e0Bq7AL2AvMlk5elr3tLMxzFY5gUuKKFQ8aM2qnai8Bq2OJAOKTJKLw7l01S5Bo8TlKZtFS rkJq4/lJLky1T3Nt1oxpehf4s6Zz8/p22Xao65W/7RC8R6G3zkcS79JNIcZvj8+3T37qc= X-Received: by 2002:a17:90b:4c0d:b0:38e:b400:a860 with SMTP id 98e67ed59e1d1-39dbc6a3e56mr392229a91.13.1789164895357; Fri, 11 Sep 2026 15:14:55 -0700 (PDT) Received: from localhost ([216.228.127.128]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-14365ba71cesm8971595c88.13.2026.09.11.15.14.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 15:14:54 -0700 (PDT) From: Yury Norov X-Google-Original-From: Yury Norov To: Andrew Morton , Matthew Wilcox , "Liam R. Howlett" Cc: Yury Norov , Chris Li , Alice Ryhl , Andrew Ballance , Yury Norov , linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, maple-tree@lists.infradead.org Subject: [PATCH 3/3] maple_tree: assert static storage for DEFINE_MTREE() Date: Fri, 11 Sep 2026 18:14:43 -0400 Message-ID: <20260911221444.1523311-4-ynorov@nvidia.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260911221444.1523311-1-ynorov@nvidia.com> References: <20260911221444.1523311-1-ynorov@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" DEFINE_MTREE() uses MTREE_INIT(), which initializes the tree's embedded lock with a static spinlock initializer. If the tree is an automatic local object, lockdep rejects its address as a non-static class key and disables locking validation on the first lock acquisition. Apply ASSERT_STATIC_STORAGE() to DEFINE_MTREE() to catch automatic local definitions at compile time. For example: void example(void) { DEFINE_MTREE(mt); mtree_destroy(&mt); } GCC reports: error: initializer element is not constant name##_storage_check =3D &(name) ^ note: in expansion of macro 'ASSERT_STATIC_STORAGE' ASSERT_STATIC_STORAGE(name) note: in expansion of macro 'DEFINE_MTREE' DEFINE_MTREE(mt); File-scope definitions and static local trees remain valid. Automatic local trees must instead use mt_init() or mt_init_flags(). Direct uses of MTREE_INIT() and MTREE_INIT_EXT() are unchanged. Replace the local DEFINE_MTREE() in the interval-tree span test with a plain declaration; the test already initializes the tree with mt_init_flags() before use. Convert the three local Maple Trees in the userspace radix-tree tests to mt_init(). Validated file-scope and static local definitions with a kernel object build, and confirmed that an automatic local definition fails to compile. The Maple Tree test and region allocation benchmark objects also build with lockdep enabled. Signed-off-by: Yury Norov --- include/linux/maple_tree.h | 4 +++- lib/interval_tree_test.c | 2 +- tools/testing/radix-tree/maple.c | 12 +++++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/linux/maple_tree.h b/include/linux/maple_tree.h index e595ae5cd0ee..e30e57f5f3df 100644 --- a/include/linux/maple_tree.h +++ b/include/linux/maple_tree.h @@ -9,6 +9,7 @@ */ =20 #include +#include #include #include =20 @@ -297,7 +298,8 @@ struct maple_tree { #endif =20 #define DEFINE_MTREE(name) \ - struct maple_tree name =3D MTREE_INIT(name, 0) + struct maple_tree name =3D MTREE_INIT(name, 0); \ + ASSERT_STATIC_STORAGE(name) =20 #define mtree_lock(mt) spin_lock((&(mt)->ma_lock)) #define mtree_lock_nested(mas, subclass) \ diff --git a/lib/interval_tree_test.c b/lib/interval_tree_test.c index b0b07270ce7c..06f77fb3179f 100644 --- a/lib/interval_tree_test.c +++ b/lib/interval_tree_test.c @@ -244,7 +244,7 @@ static int span_iteration_check(void) unsigned long start, last; struct interval_tree_span_iter span, mas_span; =20 - DEFINE_MTREE(tree); + struct maple_tree tree; =20 MA_STATE(mas, &tree, 0, 0); =20 diff --git a/tools/testing/radix-tree/maple.c b/tools/testing/radix-tree/ma= ple.c index d967e76a3c06..bfe4b8626c42 100644 --- a/tools/testing/radix-tree/maple.c +++ b/tools/testing/radix-tree/maple.c @@ -36022,10 +36022,12 @@ static noinline void __init check_erase_rebalance= (struct maple_tree *mt) =20 static noinline void __init check_mtree_dup(struct maple_tree *mt) { - DEFINE_MTREE(new); + struct maple_tree new; int i, j, ret, count =3D 0; unsigned int rand_seed =3D 17, rand; =20 + mt_init(&new); + /* store a value at [0, 0] */ mt_init_flags(mt, 0); mtree_store_range(mt, 0, 0, xa_mk_value(0), GFP_KERNEL); @@ -36319,7 +36321,9 @@ static inline int check_vma_modification(struct map= le_tree *mt) void farmer_tests(void) { struct maple_node *node; - DEFINE_MTREE(tree); + struct maple_tree tree; + + mt_init(&tree); =20 mt_dump(&tree, mt_dump_dec); =20 @@ -36432,9 +36436,11 @@ static unsigned long get_last_index(struct ma_stat= e *mas) static void test_spanning_store_regression(void) { unsigned long from =3D 0, to =3D 0; - DEFINE_MTREE(tree); + struct maple_tree tree; MA_STATE(mas, &tree, 0, 0); =20 + mt_init(&tree); + /* * Build a 3-level tree. We require a parent node below the root node * and 2 leaf nodes under it, so we can span the entirety of the right --=20 2.53.0