From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm2-f12.google.com (mail-wm2-f12.google.com [74.125.225.140]) (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 21835367B65 for ; Thu, 24 Sep 2026 12:36:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.225.140 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790253421; cv=none; b=Os0gVW7JRjzJCdkKdPZLC6Qg1m4TD6THvND9qGzK31K6Ib3PvH2agtZJKcgUQsYp4mVzk0/+hw+Oyn8ZygwvRJwgylcVV1d8JcUUeYtIlfIwCzihc7nOjyvJ6Szf98LJeqJ/vN1gZYWLR17U+ynx3rTqN+KOWTYea4/KVbCKGpc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790253421; c=relaxed/simple; bh=CLLX1WGSyy5uutnydf7E+boNfhnOuNdZ5bWoEr7Diic=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Gbfk2id8ud0fcDHKdWXi525wRwtsYneim37ll6LHta1F5CuZfzEy/vLzMuy2+whQBuBM3jIALxV5FFeOP58Sm8v915jgV+NvS2UOoAJckPRH+eEHG8bUR0khZq7iYpVbbUg9zIhN2BD0R7jhEQzrROutHQVtroTDzT99y4kDxmA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=UhNAzhcN; arc=none smtp.client-ip=74.125.225.140 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UhNAzhcN" Received: by mail-wm2-f12.google.com with SMTP id 5b1f17b1804b1-49b912df756so15602675e9.3 for ; Thu, 24 Sep 2026 05:36:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1790253418; x=1790858218; darn=vger.kernel.org; h=user-agent:in-reply-to:content-disposition:content-type :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to:content-type; bh=gAR7nTOPxRo/mfR2u3OdcokbjHynlMhWcl3pdNDsUgo=; b=UhNAzhcNXOjaJXClMavP7UWOxdIiJlADvA7MBdnyw5QYrwEEyyqzNKnGzSn8dnp6Mb bxTF0vG7q/55fEl2t5D7obCYWPO5kClnjU0fjEqG8a6Sg17Sm8Y8B7pWCwIW2vX1SDKz bk+9Awm1ZCftwFZjBanLl5YEClbmi4WbJVuzOFVaqaZ7ig7IfoGSM49ZGRrqwEWiEJMK CJt6Sudt5LBWpn5TaGfOWJHhq1Tw1ndQUL15dTzA76UqI3sg2mShlreZwnTw8ayFheNY cz09vl2qNqLWdTAu4X7acbRlu2lj8GgvjPB+jX57HIGaN50k4h5t8Osu2VYBIAvIre1P JOtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790253418; x=1790858218; h=user-agent:in-reply-to:content-disposition:content-type :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=gAR7nTOPxRo/mfR2u3OdcokbjHynlMhWcl3pdNDsUgo=; b=GPtRq/5fZ4MQT/hJWV4dqbceMzQY0+MKAbvHdUdhpZebVvHCOy+T0qg7Bt7P/hDOwv 80w0D/ly+e92e2KHm7aIMHwAW0/aAYpcK/bTB5vsnegN7mhKHeaShOsQVDIkVBhfFfj0 Hma1ertcS3+qHeyx6Fcjhjiu1nr4XyRLNFROlDAMsLFA7AB3Cc/o6c5wBt+bEKVdcKOF Cx30Y+fsc7+ufwaXoho0/ajWBD2K+ZckVjQmUyPMYFQsWtVOLAo7YROuo3fbVpCT8RK+ zJNJum48WE+K+GPnXCypDft34xJgJGEGQkGQz3sz6y0oyw570oY6MSsMw0/nXDyeveZv UD/A== X-Forwarded-Encrypted: i=1; AKwUvBy0UShlOZU3IdA0fj0SP8nQP7Dwm5GEe7pYvnxSaspyvso6OMg7oXu1T9hJhKevppqvbUu66tokGf2x@vger.kernel.org X-Gm-Message-State: AFuF++mTvJPBN5b19TTjF0xWtJsBR/GLTmk2ub2k+Ns/L3k1EkcV5Kmn TeUij3UosVHXYYGV0ssh5XR6Pkh2G4nxbpIir9pFGnItQLBfgxd09dm21h6yWOCc6Q== X-Gm-Gg: AYBFou3N0ME3uN7ey7PN/IT+G1Acd228gERuk/VdtY8jNzuyNMv+LiqchetwdnBEGyq ZJzkAUZqE6uL4QzEvp9JUz4RBNuJP6mCTH3PARWl1xl0lLDVdEFyL/aysiXF35wd/NH6pWciaj2 90ANuz3mV0BrtQxLfG7hdSGxXit76Q6HToFBb4Xn8D5L0U7GL7evyyYLiDdcRxUVJrXB0eA1amu oVoAvtb2YDULl1OUJH4qan6SKy4hkn4DFo3W8mKzyuK30HZMu25zRevCnUvgWjS/IspIBk+snIz mm5bWtQtegSoDzUMhEXq8AGZSxVYDqstI1u6Iqy3B9UqoQHm2Mo1nIOYlFymfyzEDCryWrrW37L ywCEHfRBjW4/HDDKzuRb1bh9oh2YPV7lJGbfIFzF/Gq/3zI0ONHNp4JdPVKMUoDG5RaapCADqQF nLwaiYV+RLxlB59WlfZWPTBUOf/g9wDMcXppGvsRYrjYuvoY9WDcBMR6TvyO/kBTXmWp4gtEnfs hgEBkp6oO3E/YYXer67qMqEBCHZ75VSCMay403S1Q== X-Received: by 2002:a05:600c:3514:b0:49f:ce72:e931 with SMTP id 5b1f17b1804b1-49fe6701e7emr38631215e9.35.1790253412640; Thu, 24 Sep 2026 05:36:52 -0700 (PDT) Received: from elver.google.com (17.83.155.104.bc.googleusercontent.com. [104.155.83.17]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fe0c4cc01sm56905385e9.3.2026.09.24.05.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2026 05:36:47 -0700 (PDT) Date: Thu, 24 Sep 2026 12:36:40 +0000 From: Marco Elver To: Guenter Roeck Cc: Vlastimil Babka , Andrew Morton , "Gustavo A. R. Silva" , "Liam R. Howlett" , Andrey Konovalov , Bill Wendling , David Hildenbrand , David Rientjes , Dmitry Vyukov , Jann Horn , Justin Stitt , KP Singh , Kees Cook , Lorenzo Stoakes , Matteo Rizzo , Michal Hocko , Mike Rapoport , Nathan Chancellor , Nick Desaulniers , Roman Gushchin , Suren Baghdasaryan , linux-hardening@vger.kernel.org, Nicolas Schier , Dennis Zhou , Tejun Heo , Christoph Lameter , Harry Yoo , Hao Li , "Liam R. Howlett" , Alexander Potapenko , Miguel Ojeda , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, llvm@lists.linux.dev, Guo Ren , linux-csky@vger.kernel.org Subject: Re: csky ICe (was: Re: [PATCH v4 2/3] slab: improve KMALLOC_PARTITION_RANDOM randomness) Message-ID: References: <20260511200136.3201646-1-elver@google.com> <20260511200136.3201646-2-elver@google.com> <6106aefa-47c7-4bda-a51f-8a2fba3bf715@roeck-us.net> Precedence: bulk X-Mailing-List: linux-csky@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6106aefa-47c7-4bda-a51f-8a2fba3bf715@roeck-us.net> User-Agent: Mutt/2.3.2 (2026-04-26) On Tue, Sep 22, 2026 at 07:58AM -0700, Guenter Roeck wrote: > Hi, > > On Mon, May 11, 2026 at 10:00:49PM +0200, Marco Elver wrote: > > When using CONFIG_KMALLOC_PARTITION_RANDOM, _RET_IP_ was previously used > > to identify the allocation site. _RET_IP_, however, evaluates to the > > caller's parent's instruction pointer rather than the actual allocation > > site; this would lead to collisions where a function performs multiple > > allocations. > > > > With the generalization to kmalloc_token_t, we now generate the token at > > the outermost macro, and using _THIS_IP_ would fix this for all cases. > > > > Unfortunately, the generic implementation of _THIS_IP_ relies on taking > > the address of a local label, which is considered broken by both GCC [1] > > and Clang [2] because label addresses are only expected to be used with > > computed gotos. While the generic version more or less works today, it > > is known to be brittle. For example, Clang -O2 always returns 1 when > > this function is inlined: > > > > static inline unsigned long get_ip(void) > > { return ({ __label__ __here; __here: (unsigned long)&&__here; }); } > > > > To provide a reliable unique identifier without breaking architectures > > relying on the generic _THIS_IP_, introduce _CODE_LOCATION_: it resolves > > to _THIS_IP_ where architectures provide a safe implementation, and > > falls back to a zero-cost static marker where _THIS_IP_ is broken. > > > > Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120071 [1] > > Link: https://github.com/llvm/llvm-project/issues/138272 [2] > > Signed-off-by: Marco Elver > > With this patch in the tree, I get ICE erors when trying to build > csky:allmodconfig. > > Example: > > Error log: > sound/core/oss/mixer_oss.c: In function 'snd_mixer_oss_proc_write': > sound/core/oss/mixer_oss.c:1202:1: error: could not split insn > 1202 | } > | ^ > (insn 183 400 184 (set (reg:SI 0 a0 [orig:307 _55 ] [307]) > (xor:SI (reg:SI 3 a3 [orig:308 random_kmalloc_seed ] [308]) > (const:SI (plus:SI (symbol_ref:SI ("*.LANCHOR0") [flags 0x182]) > (const_int 132 [0x84]))))) "include/linux/slab.h":759:52 288 {cskyv2_xorsi3} > (expr_list:REG_DEAD (reg:SI 3 a3 [orig:308 random_kmalloc_seed ] [308]) > (nil))) > during RTL pass: final > sound/core/oss/mixer_oss.c:1202:1: internal compiler error: in final_scan_insn_1, at final.cc:2813 > 0x779b51e2a1c9 __libc_start_call_main > ../sysdeps/nptl/libc_start_call_main.h:58 > 0x779b51e2a28a __libc_start_main_impl > ../csu/libc-start.c:360 > > This happens with lots of files, not just this one. It is seen with all > versions of gcc starting with at least v13.x. Reverting this patch fixes > the problem. Bisect log is attached for reference. > > Any idea what I could do to avoid the problem other than stopping to build > csky:allmodconfig ? No idea what gcc is falling over here, but the below patch could be a workaround/fix. Does that work better? ------ >8 ------ From: Marco Elver Date: Fri, 8 May 2026 14:51:45 +0200 Subject: [PATCH] csky: Implement _THIS_IP_ using inline asm Both GCC [1] and Clang [2] consider the generic version of _THIS_IP_ to be broken: #define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; }) In particular, the address of a label is only expected to be used with a computed goto. While the generic version more or less works today, it is known to be brittle and may break with current and future optimizations. For example, Clang -O2 always returns 1 when this function is inlined: static inline unsigned long get_ip(void) { return ({ __label__ __here; __here: (unsigned long)&&__here; }); } Fix it by overriding _THIS_IP_ in (which is included by ) using an architecture-specific inline asm version. Additionally, avoiding taking the address of a label prevents compilers from emitting spurious indirect branch targets (e.g. ENDBR or BTI) under control-flow integrity schemes. Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120071 [1] Link: https://github.com/llvm/llvm-project/issues/138272 [2] Signed-off-by: Marco Elver --- arch/csky/include/asm/linkage.h | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 arch/csky/include/asm/linkage.h diff --git a/arch/csky/include/asm/linkage.h b/arch/csky/include/asm/linkage.h new file mode 100644 index 000000000000..04afd3583e25 --- /dev/null +++ b/arch/csky/include/asm/linkage.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_CSKY_LINKAGE_H +#define __ASM_CSKY_LINKAGE_H + +#define _THIS_IP_ ({ unsigned long __ip; asm volatile("grs %0, ." : "=r" (__ip)); __ip; }) + +#endif /* __ASM_CSKY_LINKAGE_H */ -- 2.56.0.rc1.315.gc6ed9934b7-goog