From nobody Sun May 24 22:33:48 2026 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) (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 78007231A21 for ; Thu, 21 May 2026 00:00:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779321628; cv=none; b=S113nW5OT1mNEsjgrEEVD5ojmAlZipFLyUo/5vT0QkJlAQyxMUxpmWeZP37gqiwR5oTwtH55nSncSte1G1w13VT4jCIh4MHPUbTyJ5uyPGijgrOTnNJy/LYWJB8nhSYXTpjwqXn/KhRvAEYlEdaXPj4K/N1ZeW6X9/PE3FDoFrI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779321628; c=relaxed/simple; bh=X+W/YHzPoCUahhtpS/Xb0ipiz24eu9VL2XWeWvGwfa8=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=nJKMuZVEHE3Pvn3v0wewo8IjQesz0xDvMP5bY2w891SP8D45eCotrWNvn8XpMaKSZNvgqUQes9s7te/exQV8WnHLY1nXO9wi+6w9+tC3UrK+Qu9rawCgkd7d/06a33wbFCIKRAfoYNz2/w9/vTHFEw6my6RngGr8CdQTB43aRUg= 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=tRq5FrLu; arc=none smtp.client-ip=209.85.221.73 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="tRq5FrLu" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-44dad1b938fso3388936f8f.1 for ; Wed, 20 May 2026 17:00:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779321625; x=1779926425; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=4FKJ44APKE4F4RPJqq2Y8WDCowtEX/JWR3MrsO2GC6c=; b=tRq5FrLuTmJfS9XfTt9aLY9gGaYQXpdPOQsF4p+zDMzY80tuK1Sw6cniitGpBBMYlz 7Xuu2brxDGuZ7ne+RtUg7R66zOsaTl4769QoEQgysK6js/jZQuHu8gLsntPzsGNYF1lS YtW1dqjNWCa1Mc8KL2phmKyO3Yd9UhwQW84JR6pNjTkm0jBl3RrXc7iTQHn7o3OlgrXp 3A667QUwu9pQ/0VUE3f1GFTUPAuSJAuzOgYBH7opA0c91UE1/YEiAEDtkSoDypl1rbMp gAFZKJwVVEZUHBn6uwo1Q0O39vdreMJGucySTXRZmEk1rUuI80u1VUMLvT9N/lYz35Gc wVUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779321625; x=1779926425; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4FKJ44APKE4F4RPJqq2Y8WDCowtEX/JWR3MrsO2GC6c=; b=PVNpz3za86YseNEyQyt9iIvIGLuLp3c2+oNFItIxDt6Kp2Y+rFGrawLbKnf23tgGGk vhOq78uGix003xEZMkuaSeygzhyU0E2UrM7kymg5c/EnOuC5oaPYJ4ysYY9Bx8eiXZ0k 2OHO9IUjk0eGEY+70nvDDDmDO7l9ie9YTa+hCv8Oc6sZuSUXGEUm/oY7taLW6xldTrXN rSTJDHS9jVMnLaWXWk2wNc3Gk+BOV12VNzBj+gJn1zUQ8by05JIZNl+HIM/WugCEcmNY 5uPjmnfqOyPiMS6Ru7lDlyZAxjQL8P5qPUadj8drsR/luWZHP0HtZNzRh02DBgpXapOu XWlw== X-Forwarded-Encrypted: i=1; AFNElJ+OEkAIyoKD3JZg8daKlstB5VRR1duZ6A/ckoRNiWkg46kx1DSLKqOUhkjcX7UqyRCFX9tSe7+DA6qWw4M=@vger.kernel.org X-Gm-Message-State: AOJu0YywoKcGjfbUSi3uEevcjm4PyZJxO/Hx+RG/n9tTkN3Ku35mXz6O 86PbZ1XdNzG9twX/gkX8PO0HjUIrBg8NEL0vyVaCdIYhN0OKeMEtFHAII3bgFOWV565Jyk2isbG gVQ== X-Received: from wmsl5.prod.google.com ([2002:a05:600c:1d05:b0:489:1fa6:34a3]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:468b:b0:48e:89b8:7c6d with SMTP id 5b1f17b1804b1-490360bfac5mr5820725e9.25.1779321624535; Wed, 20 May 2026 17:00:24 -0700 (PDT) Date: Thu, 21 May 2026 02:00:09 +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: <20260521000011.3926424-1-elver@google.com> Subject: [PATCH] x86: Implement _THIS_IP_ using inline asm for 32-bit From: Marco Elver To: elver@google.com Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , linux-kernel@vger.kernel.org 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; }); } Like the 64-bit version (which was missing 'volatile'), fix it by overriding _THIS_IP_ in using an inline asm version for 32-bit x86. 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/x86/include/asm/linkage.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/linkage.h b/arch/x86/include/asm/linkage.h index a7294656ad90..bce3c6f4b94f 100644 --- a/arch/x86/include/asm/linkage.h +++ b/arch/x86/include/asm/linkage.h @@ -13,11 +13,12 @@ * The generic version tends to create spurious ENDBR instructions under * certain conditions. */ -#define _THIS_IP_ ({ unsigned long __here; asm ("lea 0(%%rip), %0" : "=3Dr= " (__here)); __here; }) +#define _THIS_IP_ ({ unsigned long __here; asm volatile("lea 0(%%rip), %0"= : "=3Dr" (__here)); __here; }) #endif =20 #ifdef CONFIG_X86_32 #define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0))) +#define _THIS_IP_ ({ unsigned long __ip; asm volatile("call 1f\n1: pop %0"= : "=3Dr" (__ip)); __ip; }) #endif /* CONFIG_X86_32 */ =20 #define __ALIGN .balign CONFIG_FUNCTION_ALIGNMENT, 0x90; --=20 2.54.0.746.g67dd491aae-goog