From nobody Fri Dec 19 19:04:53 2025 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2083.outbound.protection.outlook.com [40.107.244.83]) (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 39B07207A02 for ; Wed, 8 Jan 2025 20:26:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.83 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736367964; cv=fail; b=GkkdQRZJfBwaU7yKRzLim6jSnwLiXzCL+KZd2v37iwQPreTfKMYXp1Ztmhq9lj29mh2GG3GUPlnR00IULoWelRtWQUdCSeUlPo1zE2I5E9VjzyAw3VDbFEAMhzuj03qpoKgzNihCOk1pDxAatqdhnSfi91llkHL48/wDTb+7upA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736367964; c=relaxed/simple; bh=Gg6WRmKCAJ1GjmtG6YpYP664Ba+JddV2E3uOhzYbO68=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=scnuZuNaNo2QT5MbZigfCagKpitU6Lk7YvZmJx1EEsOu85lsgq9Ncfkgwx7iIW9mnksu9qhPAfD2tpn91alhOwQj4oVFIpKFSxkOyA1FGJ1XwM5CazSpQeT3DWQMKCAYZxSsgzAxahu2s7obE3/yhtbJWZ4TXmeg/jEy713TCoI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Y78B8kaM; arc=fail smtp.client-ip=40.107.244.83 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Y78B8kaM" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Ziciti2c/TOzeTnDzJMwfksqfEdnnM9cyx659IGA74tOKrKvMYaDeehq/nPLvDaZKemQqV7dxlNm9VfBSXNpd0GCaPpsxa3HZ3QEUnP04dW0a8d+jUloiIiwIuIMaDmz5gYsV7JMWHN3YlkhuKZaI8gRKMMRoEZBrdjiaC1Qsexs5xQGJ6SBPQ7UNicmhrMOitK49thFMdWqSMGt0nCiN2pp4mnSBKKfwN8n3TTuSshgOgv4/5R0qAG9QL8JGNnO5stGHAhtu3IUElHxuVpV9u3Tl0f5ilMuaZap1pHC1ENVmfkRJgTlhzSz/G8/EmKUAaGCB6W7Xveal6XhUd/IdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CWXfOMvnoyfIlaVSu8jHpMHHRYhEQNBNlx5+8g5+Tsw=; b=g/Hm0TcBpJsjXhV87mIbeLBJYJCqpsihufdbz/jIs+5S0HQnuxMbSVOUh528w6KtI8Ty8Jjl+cxBIsWxqLmblGJu7BQ+MznCjnKp3zJiDhHx2pxklOzo3uBN2rtfMryCGVAjimXe05vbJeO0GNYenTzEQSg62EPmU0ikcrYregqIW52CXmkQOovgPilzGrdk6jV57t2lwlKg94AsTdBXmU/d5SV760vCq/e9L4gjv3Z+oKGpzjt4th1xdeDZw9bED/hL/xxxMNltC71zilDyiKPfoL8BNrmNPOXh71YFi14e/QyzoHj3RiXULzlBE7NeawsEdArILDpQxYuiG4xCqg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linutronix.de smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CWXfOMvnoyfIlaVSu8jHpMHHRYhEQNBNlx5+8g5+Tsw=; b=Y78B8kaMc9Wi1Eubj82ThfH+BzyjahCiPkOOvLc8OegE51WOSBLzmHRvZH/PkUs/Izc8ovPEy/1yMIwXiTqrP1Afwu18zhr+RTcpgtqAmxleMvgXljZWBNVe8XYdgHW3RpqsuIfEXMPcJ1UFggFaOXnVDARt+aq6AOBWbuA3CQM= Received: from SA9PR11CA0006.namprd11.prod.outlook.com (2603:10b6:806:6e::11) by CH2PR12MB4053.namprd12.prod.outlook.com (2603:10b6:610:7c::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.18; Wed, 8 Jan 2025 20:25:57 +0000 Received: from DS3PEPF000099E2.namprd04.prod.outlook.com (2603:10b6:806:6e:cafe::bb) by SA9PR11CA0006.outlook.office365.com (2603:10b6:806:6e::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8335.10 via Frontend Transport; Wed, 8 Jan 2025 20:25:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099E2.mail.protection.outlook.com (10.167.17.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8335.7 via Frontend Transport; Wed, 8 Jan 2025 20:25:57 +0000 Received: from tiny.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 8 Jan 2025 14:25:52 -0600 From: David Kaplan To: Thomas Gleixner , Borislav Petkov , Peter Zijlstra , Josh Poimboeuf , Pawan Gupta , Ingo Molnar , Dave Hansen , , "H . Peter Anvin" CC: Subject: [PATCH v3 31/35] x86/bugs: Add attack vector controls for bhi Date: Wed, 8 Jan 2025 14:25:11 -0600 Message-ID: <20250108202515.385902-32-david.kaplan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250108202515.385902-1-david.kaplan@amd.com> References: <20250108202515.385902-1-david.kaplan@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099E2:EE_|CH2PR12MB4053:EE_ X-MS-Office365-Filtering-Correlation-Id: d8c7ae18-54b1-4ffe-4fc0-08dd3022a8d1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|7416014|1800799024|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?F3RKUEPy7iN1FTEmgqRrkr0JhVfo+Qxde0K6/s81ZQoQU20WNgQ6ZIT8wFS4?= =?us-ascii?Q?asQZ3L9MsgYcYzw5EHvGQNiskHPwy1c3RaekOFDZx7mxRHpQ6QiDaINmbjzc?= =?us-ascii?Q?YMjvjjnAof5OLl4Loqc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= =?us-ascii?Q?l2Y71nSjxS+U+bHTNWUDhRimT451sfyKDSO2fSaRw8BZzi+o6XHtZFH0Fa3D?= =?us-ascii?Q?CWClgi9fF9d3N/fBhAKMAz8/9Ixoln6trEBVxmptY0I1D8Xrt1WpJQm+Fhq6?= =?us-ascii?Q?+sRRS1FVW6EBx7dMhUMrLQTJFqVSYh/vc7sf8chjvwJNsUyj6sBAT35y2HX/?= =?us-ascii?Q?uFx/WFXW7zm37rrosMJm6ckZSCtaHosA2MiBux2oDvb1rdjWKJV+vOvrIk17?= =?us-ascii?Q?JR+FOJfw0zxBOgwBFyqvokq0FdXsLzcU/v4E1YGVTm2AC/qKqdD/UkocT3Fp?= =?us-ascii?Q?qTi0hxMve1EToRAr61GcZFbg0F+E9Rwy3RFaSl1JVXH1vGntmPSphVOH0tya?= =?us-ascii?Q?Bb9bSAwSU4Zb/eh/RY2tKi8VvCWyIKh1KpxjPx8hEMs9ZrHmk3evNQPAK5xc?= =?us-ascii?Q?5NFwJnBjqbswo3DpNqH/pDloEZLEFjXEXPqj/ScDI45CCaZs1tD32vTgvlkW?= =?us-ascii?Q?YhOg+rHTRHaGees=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(36860700013)(7416014)(1800799024)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jan 2025 20:25:57.4383 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d8c7ae18-54b1-4ffe-4fc0-08dd3022a8d1 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099E2.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4053 Content-Type: text/plain; charset="utf-8" There are two BHI mitigations, one for SYSCALL and one for VMEXIT. Split these up so they can be selected individually based on attack vector. Signed-off-by: David Kaplan --- arch/x86/kernel/cpu/bugs.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index c1b60ffa3218..57c762d86fca 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -1945,8 +1945,9 @@ static bool __init spec_ctrl_bhi_dis(void) enum bhi_mitigations { BHI_MITIGATION_OFF, BHI_MITIGATION_AUTO, - BHI_MITIGATION_ON, - BHI_MITIGATION_VMEXIT_ONLY, + BHI_MITIGATION_FULL, + BHI_MITIGATION_VMEXIT, + BHI_MITIGATION_SYSCALL }; =20 static enum bhi_mitigations bhi_mitigation __ro_after_init =3D @@ -1960,9 +1961,9 @@ static int __init spectre_bhi_parse_cmdline(char *str) if (!strcmp(str, "off")) bhi_mitigation =3D BHI_MITIGATION_OFF; else if (!strcmp(str, "on")) - bhi_mitigation =3D BHI_MITIGATION_ON; + bhi_mitigation =3D BHI_MITIGATION_FULL; else if (!strcmp(str, "vmexit")) - bhi_mitigation =3D BHI_MITIGATION_VMEXIT_ONLY; + bhi_mitigation =3D BHI_MITIGATION_VMEXIT; else pr_err("Ignoring unknown spectre_bhi option (%s)", str); =20 @@ -1975,8 +1976,17 @@ static void __init bhi_select_mitigation(void) if (!boot_cpu_has(X86_BUG_BHI) || cpu_mitigations_off()) bhi_mitigation =3D BHI_MITIGATION_OFF; =20 - if (bhi_mitigation =3D=3D BHI_MITIGATION_AUTO) - bhi_mitigation =3D BHI_MITIGATION_ON; + if (bhi_mitigation =3D=3D BHI_MITIGATION_AUTO) { + if (cpu_mitigate_attack_vector(CPU_MITIGATE_USER_KERNEL)) { + if (cpu_mitigate_attack_vector(CPU_MITIGATE_GUEST_HOST)) + bhi_mitigation =3D BHI_MITIGATION_FULL; + else + bhi_mitigation =3D BHI_MITIGATION_SYSCALL; + } else if (cpu_mitigate_attack_vector(CPU_MITIGATE_GUEST_HOST)) + bhi_mitigation =3D BHI_MITIGATION_VMEXIT; + else + bhi_mitigation =3D BHI_MITIGATION_OFF; + } } =20 static void __init bhi_apply_mitigation(void) @@ -1999,15 +2009,19 @@ static void __init bhi_apply_mitigation(void) if (!IS_ENABLED(CONFIG_X86_64)) return; =20 - if (bhi_mitigation =3D=3D BHI_MITIGATION_VMEXIT_ONLY) { - pr_info("Spectre BHI mitigation: SW BHB clearing on VM exit only\n"); + /* Mitigate KVM if guest->host protection is desired */ + if (bhi_mitigation =3D=3D BHI_MITIGATION_FULL || + bhi_mitigation =3D=3D BHI_MITIGATION_VMEXIT) { setup_force_cpu_cap(X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT); - return; + pr_info("Spectre BHI mitigation: SW BHB clearing on VM exit\n"); } =20 - pr_info("Spectre BHI mitigation: SW BHB clearing on syscall and VM exit\n= "); - setup_force_cpu_cap(X86_FEATURE_CLEAR_BHB_LOOP); - setup_force_cpu_cap(X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT); + /* Mitigate syscalls if user->kernel protection is desired */ + if (bhi_mitigation =3D=3D BHI_MITIGATION_FULL || + bhi_mitigation =3D=3D BHI_MITIGATION_SYSCALL) { + setup_force_cpu_cap(X86_FEATURE_CLEAR_BHB_LOOP); + pr_info("Spectre BHI mitigation: SW BHB clearing on syscall\n"); + } } =20 static void __init spectre_v2_select_mitigation(void) --=20 2.34.1