Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp258185lqg; Thu, 11 Apr 2024 01:41:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWu7K6ble34PYnWQ+qbRvSF2Mkenc/rf3NNpSRLG4fRO+wIff3HIp+FqRRl6A+/9RBAYIMub8RPSWJi0POA41oO/zwsN0lM7eHZcnE4iw== X-Google-Smtp-Source: AGHT+IEslTHbfDxX1AjiqpUH35kWylVInQiuGHytYfXMPl2DIoK/9WB9lDLHbJm7tdbYkoJ9TBb3 X-Received: by 2002:a05:620a:4d01:b0:78d:74b5:d9b with SMTP id wa1-20020a05620a4d0100b0078d74b50d9bmr5074368qkn.42.1712824863759; Thu, 11 Apr 2024 01:41:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712824863; cv=pass; d=google.com; s=arc-20160816; b=oabO9vSvEvPyUnDleRvsKgiGxibtL92ufGFmhtVaYJf+/V0QjV+tlpYcIYsyNZGAxx dWP1ZKbkqFhhRKzxRK6dqtL8SavRGlH/hUj3XHMhArqyi6Djhez7OAdvJMQmhc+nehNI Pl7+7PUP7lVos5MKajL3uvHqq1gI8XQqdU+o+ZcgdegrvXZ3WL5TdvwijqfOQYihyXjL jlAQBcEd4utkWMU3Wd3qNwa+sK773tgHFNjqk37J9RcoIc8p0ZXqQk9+pYP6AJY2r/7s QIa5hrMEzcpm6GEPNcd2uNpwl5AuM7cCJdn08McJjxprNvUhSkEIL+U9iNaBRGTBjlXc BS7w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=+B9eSipx42XBHLk1kpXJApTX+sTUtARYSjasOkJpPb8=; fh=d3HZVZB9sRYuF7bycx+OpgKllfJjh6vh0uJCgzEWQTE=; b=S5CXB9LDr6NQ56prCWpMpzvYlWRdilD37/AfN3z3a/5em2gx0IGgCFMBYowSJYNbhi Bk98Kug8FeQQzazFAhVdIFd+y79wKcITLCp4qENwObSdjF62PhgHaBVweEzL339+00G3 gK9DLNaGaKPivAXnvhWPsZ5cWiW3jvsAEiaFtCQbgPjuj7aFYvcw07UAZ1kqTSlnmd4d MD55afr30MBPO1g0dlfWaDulzVYL+FCCrmYUfz/4A0ipeJPufS9YzDAEzz8Tr3B0pgLA jfpTJb5VBIr6EslJXBIp4Zjfi7blDpVGzWGB2EUmJt/SxvI+t94CuJC9KthIe/4dkNYA 9F5w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yAalkGHD; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-140106-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140106-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id dw23-20020a05620a601700b0078d75055a2csi1177653qkb.218.2024.04.11.01.41.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 01:41:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-140106-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yAalkGHD; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-140106-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140106-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 7C19A1C21A03 for ; Thu, 11 Apr 2024 08:41:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 887771448CF; Thu, 11 Apr 2024 08:40:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="yAalkGHD"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="fWN+60Ae" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 DE1EC1411C8; Thu, 11 Apr 2024 08:40:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712824831; cv=none; b=WJLk9KA1VgcIt6m22MNNNN/D3FrbepJS07hliXWUntyu15/5ysP8hVziaW9wGAFedHjuJnaoJAG6riexPJQSNf05JDkXXfE1bpvFwyfJQuQgCEWFBsi9I5ALmIjcSNboNI9Qzpjk5E/L4LgyvY137jn2nYde5Nem9aYFZv6KSGM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712824831; c=relaxed/simple; bh=l1U2uyw5KZunZtipYulzUxi+GzehzrcAueEtq+XGCUE=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=sCR5c+GzQ/54bcTxHIHUIQiZuJbwaMzGCDJZrVKAK0qNsKEbgbp3amhjLu5OXql9tBYMdiVq6SMIKg1PnCfAjzuth2/KtGsqxJEP5xXKF/im/1eC2IfqtMJ4nvg3BTi4u9jzUf2npiu6Xv7sJURmglf8cHe4fu5rLtT6fGrmAJM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=yAalkGHD; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=fWN+60Ae; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Thu, 11 Apr 2024 08:40:21 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1712824822; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+B9eSipx42XBHLk1kpXJApTX+sTUtARYSjasOkJpPb8=; b=yAalkGHDyYhrveGxW/Zb9qE1PI9QbfamtAt75VsazPSCoj/PjqAJP1Zo6yTjAzCFN3JnUz bgsCLg9leirKTishsj+IvplfNfKuSpEoYHZrJWj2lHxZiHsre3QXgJNpEjPLD3y0FRxDf8 KcDttQRWqFlaZ7V10JpML2/uUMTnWc4sZa/uR522ktAkkTWHpYnBL4EYJb0sNzHpKgUk0I +Xc38Z97jDOH9Yyi2KG6J88E6IXVhzmKgU2Xyv1ySJwjGqQSRr/ZEj2QqWVAyzHREuzxkB hVyAACNpda3B7vP45aw/IupyQjbAK56Sf3zzUKOpwFdgs5QtHClyKiKv1nKkhQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1712824822; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+B9eSipx42XBHLk1kpXJApTX+sTUtARYSjasOkJpPb8=; b=fWN+60Ae0hF9FsGWRG4QLJ5W3vJH3bJnd7QMrFICdyYY1X+ukB1CoRd89AavP6iv6EQi4w xRaC3TlZUiqG7BDg== From: "tip-bot2 for Josh Poimboeuf" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/bugs: Fix BHI handling of RRSBA Cc: Josh Poimboeuf , Ingo Molnar , Linus Torvalds , Sean Christopherson , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <6f56f13da34a0834b69163467449be7f58f253dc.1712813475.git.jpoimboe@kernel.org> References: <6f56f13da34a0834b69163467449be7f58f253dc.1712813475.git.jpoimboe@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171282482137.10875.9684446730020395583.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 1cea8a280dfd1016148a3820676f2f03e3f5b898 Gitweb: https://git.kernel.org/tip/1cea8a280dfd1016148a3820676f2f03e3f5b898 Author: Josh Poimboeuf AuthorDate: Wed, 10 Apr 2024 22:40:47 -07:00 Committer: Ingo Molnar CommitterDate: Thu, 11 Apr 2024 10:30:33 +02:00 x86/bugs: Fix BHI handling of RRSBA The ARCH_CAP_RRSBA check isn't correct: RRSBA may have already been disabled by the Spectre v2 mitigation (or can otherwise be disabled by the BHI mitigation itself if needed). In that case retpolines are fine. Fixes: ec9404e40e8f ("x86/bhi: Add BHI mitigation knob") Signed-off-by: Josh Poimboeuf Signed-off-by: Ingo Molnar Cc: Linus Torvalds Cc: Sean Christopherson Link: https://lore.kernel.org/r/6f56f13da34a0834b69163467449be7f58f253dc.1712813475.git.jpoimboe@kernel.org --- arch/x86/kernel/cpu/bugs.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index 1b0cfc1..08dfb94 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -1538,20 +1538,25 @@ static enum spectre_v2_mitigation __init spectre_v2_select_retpoline(void) return SPECTRE_V2_RETPOLINE; } +static bool __ro_after_init rrsba_disabled; + /* Disable in-kernel use of non-RSB RET predictors */ static void __init spec_ctrl_disable_kernel_rrsba(void) { - u64 x86_arch_cap_msr; + if (rrsba_disabled) + return; - if (!boot_cpu_has(X86_FEATURE_RRSBA_CTRL)) + if (!(x86_arch_cap_msr & ARCH_CAP_RRSBA)) { + rrsba_disabled = true; return; + } - x86_arch_cap_msr = x86_read_arch_cap_msr(); + if (!boot_cpu_has(X86_FEATURE_RRSBA_CTRL)) + return; - if (x86_arch_cap_msr & ARCH_CAP_RRSBA) { - x86_spec_ctrl_base |= SPEC_CTRL_RRSBA_DIS_S; - update_spec_ctrl(x86_spec_ctrl_base); - } + x86_spec_ctrl_base |= SPEC_CTRL_RRSBA_DIS_S; + update_spec_ctrl(x86_spec_ctrl_base); + rrsba_disabled = true; } static void __init spectre_v2_determine_rsb_fill_type_at_vmexit(enum spectre_v2_mitigation mode) @@ -1652,9 +1657,11 @@ static void __init bhi_select_mitigation(void) return; /* Retpoline mitigates against BHI unless the CPU has RRSBA behavior */ - if (cpu_feature_enabled(X86_FEATURE_RETPOLINE) && - !(x86_read_arch_cap_msr() & ARCH_CAP_RRSBA)) - return; + if (cpu_feature_enabled(X86_FEATURE_RETPOLINE)) { + spec_ctrl_disable_kernel_rrsba(); + if (rrsba_disabled) + return; + } if (spec_ctrl_bhi_dis()) return; @@ -2809,8 +2816,7 @@ static const char *spectre_bhi_state(void) return "; BHI: BHI_DIS_S"; else if (boot_cpu_has(X86_FEATURE_CLEAR_BHB_LOOP)) return "; BHI: SW loop, KVM: SW loop"; - else if (boot_cpu_has(X86_FEATURE_RETPOLINE) && - !(x86_arch_cap_msr & ARCH_CAP_RRSBA)) + else if (boot_cpu_has(X86_FEATURE_RETPOLINE) && rrsba_disabled) return "; BHI: Retpoline"; else if (boot_cpu_has(X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT)) return "; BHI: Syscall hardening, KVM: SW loop";