From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 9A87737D131 for ; Thu, 21 May 2026 16:33:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779381220; cv=none; b=ZSoRFBzeuVtGlM8AzGmGHL1GBdELt/qpLNFOYE33+nzrLhKVNFpPV0afUH6zQXEJMXvgC08bwiUi+/CpRL4miCY8DSu58GvFa+g38Gmvfri5EJUlKZkC5Vh7bB86tUfzgoVB6WeaZypqi+G4pWiEL8UWZtNJhNswyqlQKISxocw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779381220; c=relaxed/simple; bh=V3s2PsRyCxJxJsbvXfl+94inWurhDWs9oX743n6jFIA=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JqNeR4dHiJpVfbu6jpeQqtoKsymdnot/fNxbSUxsSqWMXvGYjFUZ3dxrTk1qMTvJZTHz6a9ld0sNl+UByo7q/mv9/DI2+a8/1CuQLA7wqqJkOeBzaEZJ8se6TFDYpAHkdnAoCKTjpgfRbPnmhbHeibe2kIzFBBpra3SMeEGem0w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bdlbsNUs; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bdlbsNUs" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-48896199cbaso49754105e9.1 for ; Thu, 21 May 2026 09:33:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779381218; x=1779986018; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=BRu0OBs+wWdZvwPy7YlhWorhctP1jqt95JXJtfPwL+A=; b=bdlbsNUsUFNAQU1neGuoaxWVgj7+eaS0gGLLYIxunRKwez+PXxASCmC2Ntzo65fIts EbXvV1ycUwOYTdU1/JEPSUJLIVEQfyMg9/ZUOc3wQ+jsonwIH11dwZU9T6SqQFxgnujb r8pYbcVNLwxOsH3cGACbvnQycBqC2ZV8psBFEz5pfdvM71Qfo2pOJLtEtSiUOGZB64K7 /9jiDWsOrUgVAJPHVR+Y1WpUFWHamVU9udWu9RIInXyGSvAIKIYzSLk73nK2IUAMyDxG cTDAutRgSyfsuxM9xeF2EOnp2Y6lmL82JJruHnK6K7fWRZJdB8yAaUTkG6HrQvpHDrIW SFIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779381218; x=1779986018; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=BRu0OBs+wWdZvwPy7YlhWorhctP1jqt95JXJtfPwL+A=; b=RQ2N9kvUXoB3EZT/m7PlZOT75BiG4XRErctWwL2H3QArgEUnblvZd7cJlobxeXocHC vujAoub2vJ3yWbJMmlELzt5wmT89nUQguiDQEv1pcSwWPPssICJFWXXMEMFWx1HtKpz5 a1Vaj1JxJo7Dz3E4FK9IU8YaODjDrWhOHvcPLy5WFrjyGHYCJ3bCmRKWDrssfRJY+JI9 0foD/akn3RniDCT/lpYpPHPDyNU6co9YY14skfl/ri5dGgtE/iKwYNw+0ATb1OMti5Wd Ow1GkFEuFsIXKdjxm8xKUIKVOcpBzFJ0/I2ygYc9quT09fb7QVh09KiF2CKQPDlCXz0t Q8Sw== X-Forwarded-Encrypted: i=1; AFNElJ9vQJPfMrgaBun9cp4lluvtg/osk851edETp2iT/rHw0BJrGJMf04I1/8Fq29ugxUsMYpO/zT5FHtwPo4I=@vger.kernel.org X-Gm-Message-State: AOJu0Yxo8nflrG3hgF4/PaZ87AeikN/cCgImi16sgNQrRIYU1iudRmD1 /WwVyeXaSnxhhcvr3MiLvL1kiCgM2vOzr/7kyVp6RM0FSQ1V1yaVFZ0JkIAgXnwI X-Gm-Gg: Acq92OHF07LYYejEB8BRPOFHLGby+VH+4Gyc/gE6k0FEDa/HGLSZhf3cpBv91C0aXID 9ZMZN5Vw+ikP2AztPitg8T1QLQcDHj6asNMKPUfcJJEXAEkgdwdIhL+ZSC4Qp5qcTbg1lX9ZEK5 z6HpJnDfc1XkkQ7377agpspNnktnOsjTjgkMAUG2UsLcRIrx0VvJJQllDZ3x4a+mp3FvW7udP66 vfOS7YU8m3MgAs31Kt+RSoGTLeZY8xUF1av4nMLg95WDMJ7DclCcsk1UJoZSztFwUurtR9FoIPc orhFRAD21GJ9JRvL6Ak6f3n+VNX4Btki4niX7vsa77Tk65WUtjq9W4oQ+OYyHl71DFCll6wzvib 0VlYkTfexcBcS7sewx9rua+YLA5D/qIimX6yugUWZ0v/+IXqbUWGGDBpN6pCovRCJVGB98BNpAE P3J8UC38AIczVxConX+F6OQ4EDp1Xi75MjqIIHk6xLgmx+MQwNq/7MAfcZsFaf+Nnw7E16gFQKS XM= X-Received: by 2002:a05:6000:1863:b0:45d:402f:d514 with SMTP id ffacd0b85a97d-45ea3bef4d7mr5747500f8f.39.1779381217689; Thu, 21 May 2026 09:33:37 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45eaa7dab28sm4349444f8f.12.2026.05.21.09.33.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2026 09:33:37 -0700 (PDT) Date: Thu, 21 May 2026 17:33:36 +0100 From: David Laight To: Marco Elver Cc: Dinh Nguyen , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Subject: Re: [PATCH] nios2: Implement _THIS_IP_ using inline asm Message-ID: <20260521173336.1465113d@pumpkin> In-Reply-To: <20260521122427.140196-1-elver@google.com> References: <20260521122427.140196-1-elver@google.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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(+) > > diff --git a/arch/nios2/include/asm/linkage.h b/arch/nios2/include/asm/linkage.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" > > +#define _THIS_IP_ ({ unsigned long __ip; asm volatile("nextpc %0" : "=r" (__ip)); __ip; }) > + > #endif