From nobody Sun May 24 20:34:04 2026 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.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 44AD83D47AE for ; Thu, 21 May 2026 12:34:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779366885; cv=none; b=nf812JVyy1+0YQt5SbD0VVH8gFSKuMApHwEa8lVEyNU9KfbTBE6f3FigFUbNQrFtHnJ10PrSicXTCCSpv+ZdHqKyS3n8099VhB7YQLVxI46QTY36bsBRY7KFvKjm/QMq35tKoOgbX0Sf1RDwTYfLDv6HBa3vfko5fEdfIKmjkKg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779366885; c=relaxed/simple; bh=RX42IKvUQTV6WMHKbuFkLzcEWeRTFdf9qlpwIdsjjqs=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=Pxrst3Q6G6rI3Zc2nEEklxle0qfhBzP2z0GX50tUoUfop9AFGccO0u1N1jqg8dUWg1sTuh571RoVrUf1oAxy1588xn2E5T0sPAc38objB0+qk+ChdPLeEer+EohnoO4hSgSjQsFp1W3TVXmizjlKD7UdjtkVmc0Fo55wzjpL7iU= 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=oG68+6kc; arc=none smtp.client-ip=209.85.128.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="oG68+6kc" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-48d1bc85bb3so22359405e9.0 for ; Thu, 21 May 2026 05:34:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779366882; x=1779971682; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=30zwX92UDLp3WVrdLPg947prqG16XeA2s2EFLRkEXpo=; b=oG68+6kcfQ0HxjKFArzeIxPNFDulp93WVqcG3dKGRIAbIohsycaFuV2BynHXPLDuVi HhyrNKkVE9cLLLrm7QEeutm6qoZQFwSjY7O8vJqLPpZGNOTm4lQautxHTdi8cFCgJFeT sOKELWK2lmfBmGF71Gv5owaCu1LXmUfy4YquBf45iK+xjUU5uiB+mhBgrrFkHB4XCgvV x39DhMS1Uc4hWoApb+eiDTpReae45vbC6KsvBMg2UftkFnwq3fXQU0rusm3Wul5zoLDc 1qGdYpSn6NugN1Q/VJHQE8M2YO0sV/ANFb5EEEwD2F/vo1N7EWfIK45+vcDeT4V7T31p yCMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779366882; x=1779971682; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=30zwX92UDLp3WVrdLPg947prqG16XeA2s2EFLRkEXpo=; b=HkcbTpp8/JpWSTqZH2O8+FXgHvp6EOVrJFJnGcC/IycAJb2BHGJR8wXxTnhDalIjdH T7WuxDjEi4ylfzgeEdeuOJ/G/fQwzufDA7zuhmF6+dtfmM0DjASWwVpTtXsxJnslT6rm yLfplqTPMejBF+9rWW98/JtSsCVBT0dmOfyOP9DDEdzmwbBbKhOze5ZqZz4bCZm3r/A9 73Ldro+Si7k9ySsf7Kv2IrEgVr7dxBykfwEvPAQ7IXyVxIZngblb/nSny/+FWGx+M8Cn SgJZExKBGcw7j8esuloLMg2IS2wRIZuqnuOu76mgc7n7RYKS+Ux7PMl/ZU2tzN26YUYK o/+w== X-Forwarded-Encrypted: i=1; AFNElJ/QCMnyCKL3AyfIGrC4795e5rpD1rMBblEJtsoEnm4Xatv7HM9BY+jJkAudShpLq5q+IlFJmEEo3fJYVjw=@vger.kernel.org X-Gm-Message-State: AOJu0YwSxmwXFdaFX+Ftg6tBAnjvyr+o4oYxLzp7NzfBJ4U+Da9L9vti 2aIZaBK7L4oCjU9XoP9SpU3OQ1Xsb2MV/K43UDZEFBsVxEudSy8t/vwtUzZwbhX2IC0IUGV8pf+ +cg== X-Received: from wmbf13.prod.google.com ([2002:a05:600c:594d:b0:48a:55cc:4954]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4e02:b0:48f:d620:c27f with SMTP id 5b1f17b1804b1-49036053ec5mr32796905e9.4.1779366882474; Thu, 21 May 2026 05:34:42 -0700 (PDT) Date: Thu, 21 May 2026 14:34:30 +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: <20260521123438.147789-1-elver@google.com> Subject: [PATCH] m68k: Implement _THIS_IP_ using inline asm From: Marco Elver To: elver@google.com Cc: Geert Uytterhoeven , linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com 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 --- arch/m68k/include/asm/linkage.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/m68k/include/asm/linkage.h b/arch/m68k/include/asm/linkag= e.h index c8b84282764c..9ed2f36830d0 100644 --- a/arch/m68k/include/asm/linkage.h +++ b/arch/m68k/include/asm/linkage.h @@ -35,4 +35,6 @@ __asmlinkage_protect_n(ret, "m" (arg1), "m" (arg2), "m" (arg3), \ "m" (arg4), "m" (arg5), "m" (arg6)) =20 +#define _THIS_IP_ ({ unsigned long __ip; asm volatile("lea %%pc@(.), %0" := "=3Da" (__ip)); __ip; }) + #endif --=20 2.54.0.746.g67dd491aae-goog