From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 EDDD0297B94; Mon, 12 May 2025 18:05:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747073155; cv=none; b=dvqLbBs6pEB9unwmEaYtDSVYmJ6FIORLV692YyFHISgM8s3Nx8MFnqilN5nLp1HW4wG9RTfGX7KwofZL/Kxp6mR95fuGND1e7C1YMZPeLnt7gQtRsB2Hm4uuC0wsKtxQ8jbbrcwFuScu3tdbgI0jH3gPzGvmmLRx0G2dBjuVROM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747073155; c=relaxed/simple; bh=ynO3R7f0uxa87L0k55FwoFNcHOoralYW4/J6Af2WP6A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UaakruP6/ht2sJU3UT5X5kFwtW6CWVGQYJeRr4MN/KQOH9ZFkXRffjL+RyH6B75O7mUHRv9Jv7SIatWLwvQgSNOtB66h8ajrc9F3xiJ2nNdec5qREszYgvtnzpro2eRgsyqZTn1NuP900qC5OyW6n/BpUXi0YwsCzZJzf2vyMVk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ZjrhXnpl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ZjrhXnpl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE7B9C4CEF1; Mon, 12 May 2025 18:05:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1747073154; bh=ynO3R7f0uxa87L0k55FwoFNcHOoralYW4/J6Af2WP6A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZjrhXnplYEGOguoQEXUWbEY4mGXL5Q10+/pj2ZSDkyKi9lSUVxmnNdCgZmiHt34HU kMwF/2cl+rm/80YEvBWEAlCIPSergegj7wKl8U4yDfpwcPfxYg0TBln9v+Fef7zIlQ ZVwj/56U4kO4xm0hTG76CflVbccBKndMzoyoXSgM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Josh Poimboeuf , Pawan Gupta , Ingo Molnar , Linus Torvalds , Peter Zijlstra Subject: [PATCH 6.12 172/184] x86/speculation: Add a conditional CS prefix to CALL_NOSPEC Date: Mon, 12 May 2025 19:46:13 +0200 Message-ID: <20250512172048.813831999@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250512172041.624042835@linuxfoundation.org> References: <20250512172041.624042835@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Pawan Gupta commit 052040e34c08428a5a388b85787e8531970c0c67 upstream. Retpoline mitigation for spectre-v2 uses thunks for indirect branches. To support this mitigation compilers add a CS prefix with -mindirect-branch-cs-prefix. For an indirect branch in asm, this needs to be added manually. CS prefix is already being added to indirect branches in asm files, but not in inline asm. Add CS prefix to CALL_NOSPEC for inline asm as well. There is no JMP_NOSPEC for inline asm. Reported-by: Josh Poimboeuf Signed-off-by: Pawan Gupta Signed-off-by: Ingo Molnar Cc: Andrew Cooper Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20250228-call-nospec-v3-2-96599fed0f33@linux.intel.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/nospec-branch.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -210,9 +210,8 @@ .endm /* - * Equivalent to -mindirect-branch-cs-prefix; emit the 5 byte jmp/call - * to the retpoline thunk with a CS prefix when the register requires - * a RAX prefix byte to encode. Also see apply_retpolines(). + * Emits a conditional CS prefix that is compatible with + * -mindirect-branch-cs-prefix. */ .macro __CS_PREFIX reg:req .irp rs,r8,r9,r10,r11,r12,r13,r14,r15 @@ -439,11 +438,23 @@ static inline void call_depth_return_thu #ifdef CONFIG_X86_64 /* + * Emits a conditional CS prefix that is compatible with + * -mindirect-branch-cs-prefix. + */ +#define __CS_PREFIX(reg) \ + ".irp rs,r8,r9,r10,r11,r12,r13,r14,r15\n" \ + ".ifc \\rs," reg "\n" \ + ".byte 0x2e\n" \ + ".endif\n" \ + ".endr\n" + +/* * Inline asm uses the %V modifier which is only in newer GCC * which is ensured when CONFIG_MITIGATION_RETPOLINE is defined. */ #ifdef CONFIG_MITIGATION_RETPOLINE -#define CALL_NOSPEC "call __x86_indirect_thunk_%V[thunk_target]\n" +#define CALL_NOSPEC __CS_PREFIX("%V[thunk_target]") \ + "call __x86_indirect_thunk_%V[thunk_target]\n" #else #define CALL_NOSPEC "call *%[thunk_target]\n" #endif