From nobody Mon Feb 9 05:01:34 2026 Received: from fout-b6-smtp.messagingengine.com (fout-b6-smtp.messagingengine.com [202.12.124.149]) (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 3796D2F0C46; Mon, 20 Oct 2025 22:36:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760999815; cv=none; b=RSRlSu50PYT0mKYSKnS19pyYbnypbdoxKouqNMH8+dRYGSWdonIZGLxjpthivwp+BQtiLEvVBdUWGXk9FeS6PvvNlK9hOtQtTDzN80JmbN9LolRzdPefNRy88L5ATlsv2VGZvOfW77hxM5/6i+96gw2hvzmJEmnoE2s/a1WNDAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760999815; c=relaxed/simple; bh=oAwsmojtKX1hlDXyiaKqg3VsPIxLw2dunAdcVhMc1Mo=; h=To:Cc:Message-ID:In-Reply-To:References:From:Subject:Date; b=CdL23ckbIpBH6eC5x6Oqi34CEqNx0zoi2Qh5yBkK+WaWf0C6InGbC065cZGDZTnw12WyNCgBVSKPbde2umkUwCMoTXQQu/AYxgYCIvNOj3lFJI4PyyrwBryLYU0skEeTn+vUE0Ovu5W9a2WqJqMHP3Lg3eBjTrrPxB3k4IME8J8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org; spf=none smtp.mailfrom=linux-m68k.org; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=vZySVlpO; arc=none smtp.client-ip=202.12.124.149 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux-m68k.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="vZySVlpO" Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfout.stl.internal (Postfix) with ESMTP id 036191D00149; Mon, 20 Oct 2025 18:36:52 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Mon, 20 Oct 2025 18:36:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1760999812; x= 1761086212; bh=xCzEtoNxSS71DBOWSJCr+vKOLnsVoIb0CZZ05NZm2s0=; b=v ZySVlpOqjUr2UiuoNNKy0hKoVzCr47R5TPjuxzyezI0RG8okQ4l/K77vPWkRV9kX VynGCYcR03rg9O4qc780NESiW7XQ81+hv1Y9lMhpRUieOxoBcTuKH4OOjTSGqYcb OmnKyatZhwSXtl21/uIYgRFplnonxhigIfJoHBNLTL3x/PJIBievYtPQx9dPY0ni pOMu4pbut+jgVSTg4TmlaW4KlOrXYz3ZEXwQeK8aZaRuGzUBApSEeGfzTW6SsJmh eh0R5P+cPeKMMcLEdgG3fHpd73fOAkkAS9Akn7yS+R+kNrBzIxQYdaaY7DlyD9VA cbKk1wAoEGYu6WQEPcQqg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddufeeltdefucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepvfevkfgjfhfhufffsedttdertddttddtnecuhfhrohhmpefhihhnnhcuvfhhrghi nhcuoehfthhhrghinheslhhinhhugidqmheikehkrdhorhhgqeenucggtffrrghtthgvrh hnpeevgffgtdfhhfefveeuudfgtdeugfeftedtveekieeggfduleetgeegueehgeffffen ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehfthhhrg hinheslhhinhhugidqmheikehkrdhorhhgpdhnsggprhgtphhtthhopedutddpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepphgvthgvrhiisehinhhfrhgruggvrggurdhorh hgpdhrtghpthhtohepfihilhhlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrkhhp mheslhhinhhugidqfhhouhhnuggrthhiohhnrdhorhhgpdhrtghpthhtoheprghrnhguse grrhhnuggsrdguvgdprhgtphhtthhopegsohhquhhnrdhfvghnghesghhmrghilhdrtgho mhdprhgtphhtthhopehgvggvrhhtsehlihhnuhigqdhmieekkhdrohhrghdprhgtphhtth hopehlihhnuhigqdgrrhgthhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthho pehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtth hopehlihhnuhigqdhmieekkhesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i58a146ae:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 20 Oct 2025 18:36:50 -0400 (EDT) To: Peter Zijlstra , Will Deacon Cc: Andrew Morton , Arnd Bergmann , Boqun Feng , Geert Uytterhoeven , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-m68k@vger.kernel.org, Mark Rutland Message-ID: <98018681b75da61108b992ab15ad455569863924.1760999284.git.fthain@linux-m68k.org> In-Reply-To: References: From: Finn Thain Subject: [RFC v4 5/5] atomic: Add option for weaker alignment check Date: Tue, 21 Oct 2025 09:28:04 +1100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a new Kconfig symbol to make CONFIG_DEBUG_ATOMIC more useful on those architectures which do not align dynamic allocations to 8-byte boundaries. Without this, CONFIG_DEBUG_ATOMIC produces excessive WARN splats. --- Changed since v3: - Dropped #include to avoid a build failure on arm64. - Rewrote Kconfig help text to better describe preferred alignment. - Refactored to avoid line-wrapping and duplication. --- include/linux/instrumented.h | 17 ++++++++++++++--- lib/Kconfig.debug | 8 ++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/include/linux/instrumented.h b/include/linux/instrumented.h index 402a999a0d6b..ca946c5860be 100644 --- a/include/linux/instrumented.h +++ b/include/linux/instrumented.h @@ -56,6 +56,17 @@ static __always_inline void instrument_read_write(const = volatile void *v, size_t kcsan_check_read_write(v, size); } =20 +static __always_inline void instrument_atomic_check_alignment(const volati= le void *v, size_t size) +{ + if (IS_ENABLED(CONFIG_DEBUG_ATOMIC)) { + unsigned int mask =3D size - 1; + + if (IS_ENABLED(CONFIG_DEBUG_ATOMIC_LARGEST_ALIGN)) + mask &=3D sizeof(struct { long x; } __aligned_largest) - 1; + WARN_ON_ONCE((unsigned long)v & mask); + } +} + /** * instrument_atomic_read - instrument atomic read access * @v: address of access @@ -68,7 +79,7 @@ static __always_inline void instrument_atomic_read(const = volatile void *v, size_ { kasan_check_read(v, size); kcsan_check_atomic_read(v, size); - WARN_ON_ONCE(IS_ENABLED(CONFIG_DEBUG_ATOMIC) && ((unsigned long)v & (size= - 1))); + instrument_atomic_check_alignment(v, size); } =20 /** @@ -83,7 +94,7 @@ static __always_inline void instrument_atomic_write(const= volatile void *v, size { kasan_check_write(v, size); kcsan_check_atomic_write(v, size); - WARN_ON_ONCE(IS_ENABLED(CONFIG_DEBUG_ATOMIC) && ((unsigned long)v & (size= - 1))); + instrument_atomic_check_alignment(v, size); } =20 /** @@ -98,7 +109,7 @@ static __always_inline void instrument_atomic_read_write= (const volatile void *v, { kasan_check_write(v, size); kcsan_check_atomic_read_write(v, size); - WARN_ON_ONCE(IS_ENABLED(CONFIG_DEBUG_ATOMIC) && ((unsigned long)v & (size= - 1))); + instrument_atomic_check_alignment(v, size); } =20 /** diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 1c7e30cdfe04..4d3ebe501d17 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1373,6 +1373,14 @@ config DEBUG_ATOMIC =20 This option has potentially significant overhead. =20 +config DEBUG_ATOMIC_LARGEST_ALIGN + bool "Check alignment only up to __aligned_largest" + depends on DEBUG_ATOMIC + help + If you say Y here then the check for natural alignment of + atomic accesses will be constrained to the compiler's largest + alignment for scalar types. + menu "Lock Debugging (spinlocks, mutexes, etc...)" =20 config LOCK_DEBUGGING_SUPPORT --=20 2.49.1