From nobody Sun May 24 20:34:04 2026 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (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 F029F3CF66C for ; Thu, 21 May 2026 12:24:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779366285; cv=none; b=T+ThI/wjlgX0rf2K72ctlPrEiNK850grZZWiyN15nPWMsAIibnVGgeqHvQQ5vHTiyML0KoEBTR9oE5e7KLbOr9fK1L5OE//IcqUIRyLA0jAbVVfWq7oaNLpmqlDCN3qdCcvf3gpsFp0GjYZ+Fgmlfabm9n+0JlKnZEQe+lKLAxk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779366285; c=relaxed/simple; bh=0Jfg5MzJ2Q5vfQg6I3BnMXOhzi9fJrQGoO3EvFjHMKg=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=K7CYcNMCt8/fSn3RuyoEmizPuhzKGxrEtpaXTJTmOebbtpzPz270P9/wP1W+dOjCbBEM9IorsOvYZth0YIAWsSosHSfwRkc1NqL0mKKGalcSJpsvwlRsl6WNI7cWYy95OA/Wab5L2RadXQw4T4hdI5p5DZRGuPzhrFlsd60WnN0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--elver.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=lhyoVGqy; arc=none smtp.client-ip=209.85.221.74 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=flex--elver.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="lhyoVGqy" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-43d7b7bacddso4427801f8f.0 for ; Thu, 21 May 2026 05:24:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779366276; x=1779971076; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=3nzvx5MM2FO6LoXrgdxvMXAwGx2HvwOUKaosOKn4ZPs=; b=lhyoVGqyBJ3Zr4tOwwro6QkF+1+wm5JhaO+dC4hO+F47D8IvFs0yStowJ8uODipdDU gNJjLJK8Bq2cXz6gjAE/wyZgPdAwiOIQMZIJBGJzgp6OzP2gH3WhWRb7c9AqbsGXVPn6 7EQqvUF7sTMpp3ltj/G0I/rk0WoHqjvfIjoWH5nQ/zsyoFR9C5lpD0kOKBf6kHg9OREN 1mZlfSkLe3pUcawL+GRAqC6WTbb1v4hCgl1/iA31pkf9HfZJo0vdEKze8Srkt7bnak+W nvIg62hHKpMJMGJTBwEaP40pTlwn7I23Wx0vz9yspa/F0e1dn2y0O9GIUufhCVHjqun9 0ruQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779366276; x=1779971076; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=3nzvx5MM2FO6LoXrgdxvMXAwGx2HvwOUKaosOKn4ZPs=; b=CC2DUn03ecETpfzZkDRnwHV09FlI3AHX//gAFsKBO4/tkWPAb8mKHuK4eW26S8a1BB kvPAOkx7kLuOhbiak3wlpZKUMcm0/G2Oh+PnSbu45boiamu52QnHUuGlUausmJFX8H1G qvC9NnLy7J0q8GjtqXpr4DEENno9dXyz9TXsDNVcaPAhJoE3s1EvlW0ROKxGGrSfKjJH J/DQSbpE0HSr9aLmfEpq0fiXHACZkupqt/oepaIXralCT3iGnB4QYIJjSE/Zrf/Guz5Q 1r7tjGOjulpv9mLbAL/w8FQSAfHh2H6kLWq/qiAv1w1Pk/MHFSyyfHdutz0io0ubx74i sG8Q== X-Forwarded-Encrypted: i=1; AFNElJ8tLsTgjsdT3GmT+o75K7CBvWX8fayafzrqj5s7q4bv4k8cRA6nYn/3BWqzYcaVWiP+u/KqiKsQPGnnR1M=@vger.kernel.org X-Gm-Message-State: AOJu0YynOJydfGDvJomiImqZrOMfungTGRfchC4aXVttXIE0p85nEekO VkGkFY6njVY9S45hvqz8vkHrBQI53zjnVPtD/Ij+iByzKCuVreAAcL9te/8UNzht/gEVQvk1Vn/ LRQ== X-Received: from wmcm7.prod.google.com ([2002:a7b:ce07:0:b0:490:38f3:e8b8]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3147:b0:487:2439:b7c8 with SMTP id 5b1f17b1804b1-49036033406mr36157755e9.1.1779366276178; Thu, 21 May 2026 05:24:36 -0700 (PDT) Date: Thu, 21 May 2026 14:23:55 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.54.0.746.g67dd491aae-goog Message-ID: <20260521122427.140196-1-elver@google.com> Subject: [PATCH] nios2: Implement _THIS_IP_ using inline asm From: Marco Elver To: elver@google.com Cc: Dinh Nguyen , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, David Laight Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3D120071 [1] Link: https://github.com/llvm/llvm-project/issues/138272 [2] Signed-off-by: Marco Elver Reviewed-by: David Laight --- arch/nios2/include/asm/linkage.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/nios2/include/asm/linkage.h b/arch/nios2/include/asm/link= age.h index 211302301a8a..c4073235852b 100644 --- a/arch/nios2/include/asm/linkage.h +++ b/arch/nios2/include/asm/linkage.h @@ -12,4 +12,6 @@ #define __ALIGN .align 4 #define __ALIGN_STR ".align 4" =20 +#define _THIS_IP_ ({ unsigned long __ip; asm volatile("nextpc %0" : "=3Dr"= (__ip)); __ip; }) + #endif --=20 2.54.0.746.g67dd491aae-goog