From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 0670836CDF2 for ; Fri, 22 May 2026 12:18:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779452297; cv=none; b=FAZkSyJBc7ln2t6UEurrC6OB9DpQ9dg2K5Au9QnnKRCr1XKDn3dsC9RlUTbuEjwZRrTd+KSd5d3LIhQL5JsgAV34orwd6mcx4/IcyEpDXQAWpX+nB0LvB8HMvI6qF+thNcnTM3gH0hGeM1Vqv7C+8etd7kgNf2k9K0sUWv/vTzM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779452297; c=relaxed/simple; bh=sa4pwlAmga1Dtd6Js8bj3JFTWrhVGK059dL446ZzIMs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=nB6hDxvCXdG8+0lWCY99lC+pcv+M4M+2dqnmjkfus1R8RE61IwESDE2oKKucL7rStjqL2N9oHiygVQcJmy0dBMrnnBUP7r3a2oxHVsziOTf8f10AMME4k0wYL6eOgWv7KELUUPQnFB+YyXWmReYhhYm6/1PMBFQz83lMf9LqQsU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ezrzOmW9; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ezrzOmW9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44AF41F000E9; Fri, 22 May 2026 12:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779452295; bh=84ix6O1D17GL+jKvFR9RiKu7tCx4Xea6cS19QkKEuEk=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=ezrzOmW9bsrqpiNdLelKcIKa0MREtfzfNFWfUd+oZImq39jeawIm/Tx8IjakNS5on qyyMeuVi83faWeJG9hiVXd3mMECNP7mGrBI/oUqnmteN5dOl428pyfk4QXy6ixsLxM XVGQ8aO7tEKpk3umS5KfJzN5vh8dX8GM/5S7FHtpC/r+yrTDLgUantIQKi1wwCPyZI qHXK0uLF7FK15Jsi6xufJG0F77H0tlyD5Co0ze13NXgQ2lNIY3fTACbOVBk8davANL l5+DVDHfcx7TQt4D9DJXdi6lbdd5OqDZZgP6b76C1ipiwlGegoVwq62Jim6B5h4y2p 5RntQ1GuJnYhw== Message-ID: <56601cbd-99ee-4992-9974-7c25a91c5e0f@kernel.org> Date: Fri, 22 May 2026 07:18:14 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] nios2: Implement _THIS_IP_ using inline asm Content-Language: en-US To: David Laight , Marco Elver Cc: linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com References: <20260521122427.140196-1-elver@google.com> <20260521173336.1465113d@pumpkin> From: Dinh Nguyen In-Reply-To: <20260521173336.1465113d@pumpkin> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 5/21/26 11:33, David Laight wrote: > On Thu, 21 May 2026 14:23:55 +0200 > Marco Elver wrote: > >> 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 > > I know more than enough about the Nios-II instruction set to know it > is the correct opcode, so: > > Reviewed-by: David Laight > >> --- >> arch/nios2/include/asm/linkage.h | 2 ++ >> 1 file changed, 2 insertions(+) >> Applied! Thanks, Dinh