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 4F90B2459FD; Tue, 20 May 2025 13:52:32 +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=1747749153; cv=none; b=upnJngI62W+lqFLI7nQEySkFA7LHAGphGdY/VInYKHRe2ZYrb1OPpZg7WAv++Gw2kJBMkmUeF1eEsFYR4u3XZSSIyBKWcUSsj4PZ9n0+GXdwp0XAzrdZtdIljYfw5dS/FSaniOEB4zpr5OfSBk+03hesuJIHXlpQnSmvmaPkn2c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747749153; c=relaxed/simple; bh=z+9u8BILfVmReEGhEcpIxrlYM5s24fKa9+B/wmXnfbQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=afn4lnaLhuZpL0RtTB5gCow0CUhIWl0gAU7asRngSxtg3NEnqR33RhcWC2DY0x8mv+ZkG8A4I2e1iTfhrMrtEgJpnnWHEf2DRNoWJ1rjBdSC2FBNG883/7AWPst3YvE46bR5gV4XgDXHjS1KwnwH5tLgoI6kp8xogi2LRG8jIk0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=OKQM7+9Y; 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="OKQM7+9Y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5754BC4CEE9; Tue, 20 May 2025 13:52:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1747749152; bh=z+9u8BILfVmReEGhEcpIxrlYM5s24fKa9+B/wmXnfbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OKQM7+9YZEUF6KHBtrJAQfCYjk3rGYM0qjGh9KCxd30WT2FxoHLSwGA4VykYOny4J ohsbsm0bxw1hwtj9fTXmkNiq2n0ZKKTtyKPWOJXDtbQ0KKV3O27pwcHY4XsH/xD2Qe OiJPQTvNzJpEyE7qHDD0stiz9aqJ81o6V2SBtpcc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Peter Zijlstra , Pawan Gupta Subject: [PATCH 5.15 14/59] x86,nospec: Simplify {JMP,CALL}_NOSPEC Date: Tue, 20 May 2025 15:50:05 +0200 Message-ID: <20250520125754.398559258@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250520125753.836407405@linuxfoundation.org> References: <20250520125753.836407405@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 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Peter Zijlstra commit 09d09531a51a24635bc3331f56d92ee7092f5516 upstream. Have {JMP,CALL}_NOSPEC generate the same code GCC does for indirect calls and rely on the objtool retpoline patching infrastructure. There's no reason these should be alternatives while the vast bulk of compiler generated retpolines are not. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Pawan Gupta Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/nospec-branch.h | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -119,25 +119,37 @@ .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(). + */ +.macro __CS_PREFIX reg:req + .irp rs,r8,r9,r10,r11,r12,r13,r14,r15 + .ifc \reg,\rs + .byte 0x2e + .endif + .endr +.endm + +/* * JMP_NOSPEC and CALL_NOSPEC macros can be used instead of a simple * indirect jmp/call which may be susceptible to the Spectre variant 2 * attack. */ .macro JMP_NOSPEC reg:req #ifdef CONFIG_RETPOLINE - ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), \ - __stringify(jmp __x86_indirect_thunk_\reg), X86_FEATURE_RETPOLINE, \ - __stringify(lfence; ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), X86_FEATURE_RETPOLINE_LFENCE + __CS_PREFIX \reg + jmp __x86_indirect_thunk_\reg #else jmp *%\reg + int3 #endif .endm .macro CALL_NOSPEC reg:req #ifdef CONFIG_RETPOLINE - ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; call *%\reg), \ - __stringify(call __x86_indirect_thunk_\reg), X86_FEATURE_RETPOLINE, \ - __stringify(lfence; ANNOTATE_RETPOLINE_SAFE; call *%\reg), X86_FEATURE_RETPOLINE_LFENCE + __CS_PREFIX \reg + call __x86_indirect_thunk_\reg #else call *%\reg #endif