From nobody Sat Feb 7 08:43:24 2026 Received: from fhigh-b7-smtp.messagingengine.com (fhigh-b7-smtp.messagingengine.com [202.12.124.158]) (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 4B3F3267B89; Wed, 31 Dec 2025 08:32:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767169937; cv=none; b=O5GbpfoTPp+kECYscmn4jtfGFoL1pAiFdCPYs8JXiE99G1X3ukGCdfksA3Rne47jo1FFR2HT5D0ZQw1h93YsmbmTlJ7lbMVPSgOGeV4kzF1JOFYMajkkMejSxcKSu5KfCfx5A0bf/3DEfbyE/gOyuxMJQM/Jb0UsfM9msCuPixc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767169937; c=relaxed/simple; bh=6BaawB/5vhO7v/rumx07zT9BPZyyoYZDc4iUgex6uao=; h=To:Cc:Message-ID:In-Reply-To:References:From:Subject:Date; b=OjFnRPQ8e24yjHgfo0103QL9GTksGZzQ29zMFXVOfxCTvRBlt+pgnv9s2H4JDoWryJHhvxP50juwzyvZAiHFuV3TbfoB9nTSLo2dR4PMVAqe9HnWnEfqKSv9C3ZZ47ZUHR9iy5lsWaVnt3IkUa3xdHuXoFSSBLkHRCJqWdImyeg= 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=r1tTti8U; arc=none smtp.client-ip=202.12.124.158 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="r1tTti8U" Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfhigh.stl.internal (Postfix) with ESMTP id D5DB77A00DD; Wed, 31 Dec 2025 03:32:13 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Wed, 31 Dec 2025 03:32:14 -0500 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=1767169933; x= 1767256333; bh=nL9oXUgaQPIU6S4mzvMLiKSGthFWHu05i1DeuxQmtGs=; b=r 1tTti8Up8Zi+al8bvnYxDoJW3Jw48pwJGUd3uU2witdKmm68bwDFvju56NN7BRti hHfPal/dtoP0W4H6uCHkO7JiPXgYCv3i1z/V9mAS3+xJiQgErXtp3pmkBHAMzsbV mEm1zpriUVrKMVmHQF6w+ISYDrtS4T0Twevykb/r4Vr74jc8nVWKNFd/OA2iXUmK Uv9XooUtQO8+rdETxdEsVhqtQKLwOQ40u0KqWuVmLrx1Nz9iFiC5wctEQb67JuBc uosJaU6N1SztN4DIFQA7hsM/DzpXn67S1THmmUTSL9yYyxLgc3DrkDwIQ4Ig1M+q L4LRldDsdeso1zdw32oJA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdekvdegfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefvvefkjghfhffuffestddtredttddttdenucfhrhhomhephfhinhhnucfvhhgrihhn uceofhhthhgrihhnsehlihhnuhigqdhmieekkhdrohhrgheqnecuggftrfgrthhtvghrnh epvefggfdthffhfeevuedugfdtuefgfeettdevkeeigefgudelteeggeeuheegffffnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepfhhthhgrih hnsehlihhnuhigqdhmieekkhdrohhrghdpnhgspghrtghpthhtohepvdegpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopegrkhhpmheslhhinhhugidqfhhouhhnuggrthhioh hnrdhorhhgpdhrtghpthhtohepphgvthgvrhiisehinhhfrhgruggvrggurdhorhhgpdhr tghpthhtohepfihilhhlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrrhhnugesrg hrnhgusgdruggvpdhrtghpthhtohepsghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhm pdhrtghpthhtohepghgrrhihsehgrghrhihguhhordhnvghtpdhrtghpthhtohepmhgrrh hkrdhruhhtlhgrnhgusegrrhhmrdgtohhmpdhrtghpthhtoheplhhinhhugidqrghrtghh sehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvg hlsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i58a146ae:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 31 Dec 2025 03:32:11 -0500 (EST) To: Andrew Morton , Peter Zijlstra , Will Deacon Cc: Arnd Bergmann , Boqun Feng , Gary Guo , Mark Rutland , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-m68k@lists.linux-m68k.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Geert Uytterhoeven , bpf@vger.kernel.org Message-ID: <5803c4a180975f102bc8f78a3251540f0396fa46.1767169542.git.fthain@linux-m68k.org> In-Reply-To: References: From: Finn Thain Subject: [PATCH v6 1/4] bpf: Explicitly align bpf_res_spin_lock Date: Wed, 31 Dec 2025 19:25:42 +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" Align bpf_res_spin_lock to avoid a BUILD_BUG_ON() when the alignment changes, as it will do on m68k when, in a subsequent patch, the minimum alignment of the atomic_t member of struct rqspinlock gets increased from 2 to 4. Drop the BUILD_BUG_ON() as it becomes redundant. Cc: Geert Uytterhoeven Cc: linux-m68k@lists.linux-m68k.org Acked-by: Alexei Starovoitov Reviewed-by: Arnd Bergmann Signed-off-by: Finn Thain --- Changed since v5: - Added tag from Arnd Bergmann. --- include/asm-generic/rqspinlock.h | 2 +- kernel/bpf/rqspinlock.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/include/asm-generic/rqspinlock.h b/include/asm-generic/rqspinl= ock.h index 0f2dcbbfee2f..dd36ac96bf66 100644 --- a/include/asm-generic/rqspinlock.h +++ b/include/asm-generic/rqspinlock.h @@ -28,7 +28,7 @@ struct rqspinlock { */ struct bpf_res_spin_lock { u32 val; -}; +} __aligned(__alignof__(struct rqspinlock)); =20 struct qspinlock; #ifdef CONFIG_QUEUED_SPINLOCKS diff --git a/kernel/bpf/rqspinlock.c b/kernel/bpf/rqspinlock.c index f7d0c8d4644e..8d892fb099ac 100644 --- a/kernel/bpf/rqspinlock.c +++ b/kernel/bpf/rqspinlock.c @@ -694,7 +694,6 @@ __bpf_kfunc int bpf_res_spin_lock(struct bpf_res_spin_l= ock *lock) int ret; =20 BUILD_BUG_ON(sizeof(rqspinlock_t) !=3D sizeof(struct bpf_res_spin_lock)); - BUILD_BUG_ON(__alignof__(rqspinlock_t) !=3D __alignof__(struct bpf_res_sp= in_lock)); =20 preempt_disable(); ret =3D res_spin_lock((rqspinlock_t *)lock); --=20 2.49.1 From nobody Sat Feb 7 08:43:24 2026 Received: from fhigh-b7-smtp.messagingengine.com (fhigh-b7-smtp.messagingengine.com [202.12.124.158]) (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 2CD74267B89; Wed, 31 Dec 2025 08:32:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767169945; cv=none; b=fK3kZcynBPiLJ6OOv7XgqntPgHhGg5lj5H+Xr6GXGGh7qaI/00whu1iXVJczefx9wrVdapsvqcAexidw0iJyn43ylUANKK1H9wETNCxaGC0ci8cJTW5FhL39wM1F7pxC/xKFalvRd3Cf4ZGVko7fHDYmUMiAYtNv+yPgzC9GF6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767169945; c=relaxed/simple; bh=j7setGtZxKj0GpDffae+KtqWqssWmlZc0B7lMZPOSAI=; h=To:Cc:Message-ID:In-Reply-To:References:From:Subject:Date; b=paLTuKBdfrObaIOhrorL7M5xlRYIqYOHHXD7q/FF0rPxfsQ80qZ62BuWNFifTH21FfY8acy6qHSbH+1HUWLtaqQnHngv6p7VeueZEEeq4247u1R5YxApGKuNANrvSNHXzVO6QgsFa1BB2v9T16RaYM77i1VWtFfKu1CJ9+2IupM= 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=wypE0iwm; arc=none smtp.client-ip=202.12.124.158 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="wypE0iwm" Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfhigh.stl.internal (Postfix) with ESMTP id 0F2E67A008A; Wed, 31 Dec 2025 03:32:23 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Wed, 31 Dec 2025 03:32:23 -0500 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=1767169942; x= 1767256342; bh=vBuKVea7vxP3Xqw+0VhXZu0Nuyaahlp6eJXWokICzlg=; b=w ypE0iwmRaLxYjHF9ptlWaLGVQ7qc/E6hZPji49twgiSo2Pb4hbVovN2SvLx4MwBH BRSvNx9oQYjaYsf8R/nolfANNWqq6WVUR5dDewntajqPn6xdrX1+V/64l4m424or L7zRWiMd3jUQWjqBjaCi8e5jAjJdvy2L34iKiAc4Jna99Y7ZSJ6m9gQyPiTPe33a btGHqbPNyT2alIICDF22hLN8qKSFKRdA0Tmj6TZv19Ymwkwq3xe/K+7XeVTqNLcp 8AfneayDDsoZZTfraNTyrqShmuIix2kiYAbpMh3FtGkBxLFcSrNLilcKkDSKDXEZ nXOCdQp/E5bqEerHa0sJg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdekvdegfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefvvefkjghfhffuffestddtredttddttdenucfhrhhomhephfhinhhnucfvhhgrihhn uceofhhthhgrihhnsehlihhnuhigqdhmieekkhdrohhrgheqnecuggftrfgrthhtvghrnh epheekudffheejvdeiveekleelgeffieduvdegleeuhfeuudegkeekheffkefggfehnecu ffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehfthhhrghinheslhhinhhugidqmheikehkrdhorhhg pdhnsggprhgtphhtthhopedvvddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheprg hkphhmsehlihhnuhigqdhfohhunhgurghtihhonhdrohhrghdprhgtphhtthhopehpvght vghriiesihhnfhhrrgguvggrugdrohhrghdprhgtphhtthhopeifihhllheskhgvrhhnvg hlrdhorhhgpdhrtghpthhtoheprghrnhgusegrrhhnuggsrdguvgdprhgtphhtthhopegs ohhquhhnrdhfvghnghesghhmrghilhdrtghomhdprhgtphhtthhopehgrghrhiesghgrrh ihghhuohdrnhgvthdprhgtphhtthhopehmrghrkhdrrhhuthhlrghnugesrghrmhdrtgho mhdprhgtphhtthhopehlihhnuhigqdgrrhgthhesvhhgvghrrdhkvghrnhgvlhdrohhrgh dprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhr gh X-ME-Proxy: Feedback-ID: i58a146ae:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 31 Dec 2025 03:32:21 -0500 (EST) To: Andrew Morton , Peter Zijlstra , Will Deacon Cc: Arnd Bergmann , Boqun Feng , Gary Guo , Mark Rutland , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-m68k@lists.linux-m68k.org, Guo Ren , linux-csky@vger.kernel.org, Geert Uytterhoeven , Dinh Nguyen , Jonas Bonn , Stefan Kristiansson , Stafford Horne , linux-openrisc@vger.kernel.org, Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , linux-sh@vger.kernel.org Message-ID: <88df424bfb93bdabe73bf91f5985c5b89f04d123.1767169542.git.fthain@linux-m68k.org> In-Reply-To: References: From: Finn Thain Subject: [PATCH v6 2/4] atomic: Specify alignment for atomic_t and atomic64_t Date: Wed, 31 Dec 2025 19:25:42 +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" Some recent commits incorrectly assumed 4-byte alignment of locks. That assumption fails on Linux/m68k (and, interestingly, would have failed on Linux/cris also). The jump label implementation makes a similar alignment assumption. The expectation that atomic_t and atomic64_t variables will be naturally aligned seems reasonable, as indeed they are on 64-bit architectures. But atomic64_t isn't naturally aligned on csky, m68k, microblaze, nios2, openrisc and sh. Neither atomic_t nor atomic64_t are naturally aligned on m68k. This patch brings a little uniformity by specifying natural alignment for atomic types. One benefit is that atomic64_t variables do not get split across a page boundary. The cost is that some structs grow which leads to cache misses and wasted memory. Cc: Guo Ren Cc: linux-csky@vger.kernel.org Cc: Geert Uytterhoeven Cc: linux-m68k@lists.linux-m68k.org Cc: Dinh Nguyen Cc: Jonas Bonn Cc: Stefan Kristiansson Cc: Stafford Horne Cc: linux-openrisc@vger.kernel.org Cc: Yoshinori Sato Cc: Rich Felker Cc: John Paul Adrian Glaubitz Cc: linux-sh@vger.kernel.org Link: https://lore.kernel.org/lkml/CAFr9PX=3DMYUDGJS2kAvPMkkfvH+0-SwQB_kxE4= ea0J_wZ_pk=3D7w@mail.gmail.com Link: https://lore.kernel.org/lkml/CAMuHMdW7Ab13DdGs2acMQcix5ObJK0O2dG_Fxzr= 8_g58Rc1_0g@mail.gmail.com/ Acked-by: Guo Ren Reviewed-by: Arnd Bergmann Signed-off-by: Finn Thain --- Changed since v5: - Added tags from Guo Ren and Arnd Bergmann. Changed since v2: - Specify natural alignment for atomic64_t. Changed since v1: - atomic64_t now gets an __aligned attribute too. - The 'Fixes' tag has been dropped because Lance sent a different fix for commit e711faaafbe5 ("hung_task: replace blocker_mutex with encoded blocker") that's suitable for -stable. --- include/asm-generic/atomic64.h | 2 +- include/linux/types.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h index 100d24b02e52..f22ccfc0df98 100644 --- a/include/asm-generic/atomic64.h +++ b/include/asm-generic/atomic64.h @@ -10,7 +10,7 @@ #include =20 typedef struct { - s64 counter; + s64 __aligned(sizeof(s64)) counter; } atomic64_t; =20 #define ATOMIC64_INIT(i) { (i) } diff --git a/include/linux/types.h b/include/linux/types.h index d4437e9c452c..1760e1feeab9 100644 --- a/include/linux/types.h +++ b/include/linux/types.h @@ -180,7 +180,7 @@ typedef phys_addr_t resource_size_t; typedef unsigned long irq_hw_number_t; =20 typedef struct { - int counter; + int __aligned(sizeof(int)) counter; } atomic_t; =20 #define ATOMIC_INIT(i) { (i) } --=20 2.49.1 From nobody Sat Feb 7 08:43:24 2026 Received: from fout-b7-smtp.messagingengine.com (fout-b7-smtp.messagingengine.com [202.12.124.150]) (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 5A0CB2F7455; Wed, 31 Dec 2025 08:32:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767169957; cv=none; b=sV5jEza3gL9zmeOf521hBO8oo3QkiqhybZVFQIFueiqnN1GRp+MnC64JxzjQZ/OgLmlMa+t7f3AWEu6Gab/EQ9BsN7R7KL99Yo8XblzoCZqxb40kdu7mpTZkU8JD6KfdSuqTpqVI+hBrcepYhETtzLSoYe/1YUsA7u6oFfYJ1gE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767169957; c=relaxed/simple; bh=D8CLdfYVhw03T7M683GXA2rJE7VSouolMexLSrJZi+s=; h=To:Cc:Message-ID:In-Reply-To:References:From:Subject:Date; b=ErqIM/AX9IspjWOBmwf+8up/L290nFH27CEbelS/IoVJf36W8c/JzxxI1VZNuVP+dikydBXbW6qHJereI8EFtsTJ4In2XzhwfGEt7J/taMz7QlGce9DYAvd+Kp3PYXJfsfeIUG0xrouPaQthIe5GlmMbuexKRbhFumMi8ned198= 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=sEL39B7U; arc=none smtp.client-ip=202.12.124.150 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="sEL39B7U" Received: from phl-compute-11.internal (phl-compute-11.internal [10.202.2.51]) by mailfout.stl.internal (Postfix) with ESMTP id 1CE611D000C4; Wed, 31 Dec 2025 03:32:34 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Wed, 31 Dec 2025 03:32:34 -0500 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=1767169953; x= 1767256353; bh=GTOExrkFdZz6ILdbiBTGhbMt+0HZHq9E17gN90wdwYg=; b=s EL39B7URD/7b1EY2rfw7KLprl3qc+VO5DMWLvcLsZZqT5MNNq13qeno7NsVGmscZ qDSKEeef15KEvl4EITkf0HiN6+8eMPFzZPtVqXhva5ucIm3cM7qpjdFcGuebuzA9 vf2dEajXjppmhi1L5wIJC3JfN1pwAqPDkoJ+Y/ZJIB7nqs6oawi7gB813qLyrNd3 IREBEjMpCaNnqgmraxgs0deUFuG5GQok6Kp/d6i0hEOQRF4LNbtLqJ44AVsN82jT b09jJijckWquJsL5S4jCRC1Cv+zxb5CzWFsEf89Z+ya/Camw6drDaTN7maz6UiwF sZVbJ4Gyu9O8EXqyt2l0A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdekvdegfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefvvefkjghfhffuffestddtredttddttdenucfhrhhomhephfhinhhnucfvhhgrihhn uceofhhthhgrihhnsehlihhnuhigqdhmieekkhdrohhrgheqnecuggftrfgrthhtvghrnh epheekudffheejvdeiveekleelgeffieduvdegleeuhfeuudegkeekheffkefggfehnecu ffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehfthhhrghinheslhhinhhugidqmheikehkrdhorhhg pdhnsggprhgtphhtthhopeduledpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheprg hkphhmsehlihhnuhigqdhfohhunhgurghtihhonhdrohhrghdprhgtphhtthhopehpvght vghriiesihhnfhhrrgguvggrugdrohhrghdprhgtphhtthhopeifihhllheskhgvrhhnvg hlrdhorhhgpdhrtghpthhtoheprghrnhgusegrrhhnuggsrdguvgdprhgtphhtthhopegs ohhquhhnrdhfvghnghesghhmrghilhdrtghomhdprhgtphhtthhopehgrghrhiesghgrrh ihghhuohdrnhgvthdprhgtphhtthhopehmrghrkhdrrhhuthhlrghnugesrghrmhdrtgho mhdprhgtphhtthhopehlihhnuhigqdgrrhgthhesvhhgvghrrdhkvghrnhgvlhdrohhrgh dprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhr gh X-ME-Proxy: Feedback-ID: i58a146ae:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 31 Dec 2025 03:32:32 -0500 (EST) To: Andrew Morton , Peter Zijlstra , Will Deacon Cc: Arnd Bergmann , Boqun Feng , Gary Guo , Mark Rutland , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-m68k@lists.linux-m68k.org, Sasha Levin , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Ard Biesheuvel , "H. Peter Anvin" , linux-efi@vger.kernel.org Message-ID: In-Reply-To: References: From: Finn Thain Subject: [PATCH v6 3/4] atomic: Add alignment check to instrumented atomic operations Date: Wed, 31 Dec 2025 19:25:42 +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" From: Peter Zijlstra Add a Kconfig option for debug builds which logs a warning when an instrumented atomic operation takes place that's misaligned. Some platforms don't trap for this. [fthain: added __DISABLE_BUG_TABLE macro.] Cc: Sasha Levin Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: x86@kernel.org Cc: Ard Biesheuvel Cc: "H. Peter Anvin" Link: https://lore.kernel.org/lkml/20250901093600.GF4067720@noisy.programmi= ng.kicks-ass.net/ Link: https://lore.kernel.org/linux-next/df9fbd22-a648-ada4-fee0-68fe4325ff= 82@linux-m68k.org/ Signed-off-by: Finn Thain --- Checkpatch.pl says... ERROR: Missing Signed-off-by: line by nominal patch author 'Peter Ziljstra = ' --- Changed since v5: - Add new __DISABLE_BUG_TABLE macro to prevent a build failure on those architectures which use atomics in pre-boot code like the EFI stub loader: x86_64-linux-gnu-ld: error: unplaced orphan section `__bug_table' from `arc= h/x86/boot/compressed/sev-handle-vc.o' Changed since v2: - Always check for natural alignment. --- arch/x86/boot/compressed/Makefile | 1 + drivers/firmware/efi/libstub/Makefile | 1 + include/linux/instrumented.h | 10 ++++++++++ lib/Kconfig.debug | 10 ++++++++++ 4 files changed, 22 insertions(+) diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/M= akefile index 68f9d7a1683b..122967c80e48 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -42,6 +42,7 @@ KBUILD_CFLAGS +=3D -Wno-microsoft-anon-tag endif KBUILD_CFLAGS +=3D -Wno-pointer-sign KBUILD_CFLAGS +=3D -fno-asynchronous-unwind-tables +KBUILD_CFLAGS +=3D -D__DISABLE_BUG_TABLE KBUILD_CFLAGS +=3D -D__DISABLE_EXPORTS # Disable relocation relaxation in case the link is not PIE. KBUILD_CFLAGS +=3D $(call cc-option,-Wa$(comma)-mrelax-relocations=3Dno) diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/l= ibstub/Makefile index 7d15a85d579f..ac3e7c64aedb 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -42,6 +42,7 @@ KBUILD_CFLAGS :=3D $(subst $(CC_FLAGS_FTRACE),,$(cflags= -y)) \ -ffreestanding \ -fno-stack-protector \ $(call cc-option,-fno-addrsig) \ + -D__DISABLE_BUG_TABLE \ -D__DISABLE_EXPORTS =20 # diff --git a/include/linux/instrumented.h b/include/linux/instrumented.h index 711a1f0d1a73..bcd1113b55a1 100644 --- a/include/linux/instrumented.h +++ b/include/linux/instrumented.h @@ -7,6 +7,7 @@ #ifndef _LINUX_INSTRUMENTED_H #define _LINUX_INSTRUMENTED_H =20 +#include #include #include #include @@ -67,6 +68,9 @@ static __always_inline void instrument_atomic_read(const = volatile void *v, size_ { kasan_check_read(v, size); kcsan_check_atomic_read(v, size); +#ifndef __DISABLE_BUG_TABLE + WARN_ON_ONCE(IS_ENABLED(CONFIG_DEBUG_ATOMIC) && ((unsigned long)v & (size= - 1))); +#endif } =20 /** @@ -81,6 +85,9 @@ static __always_inline void instrument_atomic_write(const= volatile void *v, size { kasan_check_write(v, size); kcsan_check_atomic_write(v, size); +#ifndef __DISABLE_BUG_TABLE + WARN_ON_ONCE(IS_ENABLED(CONFIG_DEBUG_ATOMIC) && ((unsigned long)v & (size= - 1))); +#endif } =20 /** @@ -95,6 +102,9 @@ static __always_inline void instrument_atomic_read_write= (const volatile void *v, { kasan_check_write(v, size); kcsan_check_atomic_read_write(v, size); +#ifndef __DISABLE_BUG_TABLE + WARN_ON_ONCE(IS_ENABLED(CONFIG_DEBUG_ATOMIC) && ((unsigned long)v & (size= - 1))); +#endif } =20 /** diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index ba36939fda79..4b4d1445ef9c 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1359,6 +1359,16 @@ config DEBUG_PREEMPT depending on workload as it triggers debugging routines for each this_cpu operation. It should only be used for debugging purposes. =20 +config DEBUG_ATOMIC + bool "Debug atomic variables" + depends on DEBUG_KERNEL + help + If you say Y here then the kernel will add a runtime alignment check + to atomic accesses. Useful for architectures that do not have trap on + mis-aligned access. + + This option has potentially significant overhead. + menu "Lock Debugging (spinlocks, mutexes, etc...)" =20 config LOCK_DEBUGGING_SUPPORT --=20 2.49.1 From nobody Sat Feb 7 08:43:24 2026 Received: from fhigh-b7-smtp.messagingengine.com (fhigh-b7-smtp.messagingengine.com [202.12.124.158]) (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 CC92A279908; Wed, 31 Dec 2025 08:32:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.158 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767169968; cv=none; b=FRL7TeldJ96G0L251Ftl7eOUx1O7c1m55iMakoBih5jcjIwCex9hMT3FqPWpRv8MTyPvWhZmP1/mDBMdKi16SmX1l/DE1FAG8YGSOAhIY3YuRdaOoT1Q3aftaLb5qC5XPecKnK9VpNkQZO8e6QJLSapoNwV9OeOEA+1+8TXt6Ss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767169968; c=relaxed/simple; bh=U4VqbO4P2f3x2GMgPUIPlhERgz/ilB6phqhTbRHe7js=; h=To:Cc:Message-ID:In-Reply-To:References:From:Subject:Date; b=Hh4NKBcDXfALErXSq6tO1aunwWmn6MPvbVpic4qadsYSpOvviLN9An8ZJBOXD1+4vvWztHZy8IXSW8XbPtcjkdbXQrs15I+Pfps5K7APlQ4qsnp24s+BOqEBv3k9DDLRyyxix1UjEUSVTyPnG73gIdYGvsRTgD47Cbn5Vj3Qd2w= 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=wuoV1y42; arc=none smtp.client-ip=202.12.124.158 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="wuoV1y42" Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfhigh.stl.internal (Postfix) with ESMTP id C8A127A00C1; Wed, 31 Dec 2025 03:32:45 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Wed, 31 Dec 2025 03:32:46 -0500 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=1767169965; x= 1767256365; bh=VIxsHF1gcnZiebTLYVRqozMlqAy59qKl00/sv4CyMFA=; b=w uoV1y42E7uXm6v0ZwAGLXYvJtKnAfYK9b5NUPlcXO/6lHsCfbDhhKijzkeHbpeZa oQn3KHNq5cm2oWQJ9JyyoLjYVtxmtc7CsOjN1v/F66zVc78Wc9RclYIjNsLE3otu URJDouQzhwY2uMCWtq1l8x9tqxl8kbUo7cVxJG8q5zVQXKhXo0YRgBQC2XFqVgQA oeBdfeqtPrSsbjbJejEipogBWik4WgS/Xe1yei+mLXlWmubZWIaq0KyZlHXPuSfH b70k4lmOjENX+mMp8J/f9PmWgEszOosKbMF9xqQQLMw0OmjOyAsKh247yuhHg+i5 gkmfRrxbT+cmSmzZ480Pw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdekvdegfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefvvefkjghfhffuffestddtredttddttdenucfhrhhomhephfhinhhnucfvhhgrihhn uceofhhthhgrihhnsehlihhnuhigqdhmieekkhdrohhrgheqnecuggftrfgrthhtvghrnh epvefggfdthffhfeevuedugfdtuefgfeettdevkeeigefgudelteeggeeuheegffffnecu vehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepfhhthhgrih hnsehlihhnuhigqdhmieekkhdrohhrghdpnhgspghrtghpthhtohepuddtpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopegrkhhpmheslhhinhhugidqfhhouhhnuggrthhioh hnrdhorhhgpdhrtghpthhtohepphgvthgvrhiisehinhhfrhgruggvrggurdhorhhgpdhr tghpthhtohepfihilhhlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrrhhnugesrg hrnhgusgdruggvpdhrtghpthhtohepsghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhm pdhrtghpthhtohepghgrrhihsehgrghrhihguhhordhnvghtpdhrtghpthhtohepmhgrrh hkrdhruhhtlhgrnhgusegrrhhmrdgtohhmpdhrtghpthhtoheplhhinhhugidqrghrtghh sehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvg hlsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i58a146ae:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 31 Dec 2025 03:32:43 -0500 (EST) To: Andrew Morton , Peter Zijlstra , Will Deacon Cc: Arnd Bergmann , Boqun Feng , Gary Guo , Mark Rutland , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-m68k@lists.linux-m68k.org Message-ID: <0c8ef95ea5e9a949a28412a3c791b2167592ae80.1767169542.git.fthain@linux-m68k.org> In-Reply-To: References: From: Finn Thain Subject: [PATCH v6 4/4] atomic: Add option for weaker alignment check Date: Wed, 31 Dec 2025 19:25:42 +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. Signed-off-by: Finn Thain --- Changed since v5: - Rebased. 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 | 25 ++++++++++++++++--------- lib/Kconfig.debug | 8 ++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/include/linux/instrumented.h b/include/linux/instrumented.h index bcd1113b55a1..e8983eb8a888 100644 --- a/include/linux/instrumented.h +++ b/include/linux/instrumented.h @@ -56,6 +56,19 @@ 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) +{ +#ifndef __DISABLE_BUG_TABLE + 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); + } +#endif +} + /** * instrument_atomic_read - instrument atomic read access * @v: address of access @@ -68,9 +81,7 @@ static __always_inline void instrument_atomic_read(const = volatile void *v, size_ { kasan_check_read(v, size); kcsan_check_atomic_read(v, size); -#ifndef __DISABLE_BUG_TABLE - WARN_ON_ONCE(IS_ENABLED(CONFIG_DEBUG_ATOMIC) && ((unsigned long)v & (size= - 1))); -#endif + instrument_atomic_check_alignment(v, size); } =20 /** @@ -85,9 +96,7 @@ static __always_inline void instrument_atomic_write(const= volatile void *v, size { kasan_check_write(v, size); kcsan_check_atomic_write(v, size); -#ifndef __DISABLE_BUG_TABLE - WARN_ON_ONCE(IS_ENABLED(CONFIG_DEBUG_ATOMIC) && ((unsigned long)v & (size= - 1))); -#endif + instrument_atomic_check_alignment(v, size); } =20 /** @@ -102,9 +111,7 @@ static __always_inline void instrument_atomic_read_writ= e(const volatile void *v, { kasan_check_write(v, size); kcsan_check_atomic_read_write(v, size); -#ifndef __DISABLE_BUG_TABLE - WARN_ON_ONCE(IS_ENABLED(CONFIG_DEBUG_ATOMIC) && ((unsigned long)v & (size= - 1))); -#endif + instrument_atomic_check_alignment(v, size); } =20 /** diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 4b4d1445ef9c..977a2c9163a2 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -1369,6 +1369,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