From nobody Sun Nov 24 14:02:09 2024 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2070.outbound.protection.outlook.com [40.107.220.70]) (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 360FA216A02 for ; Tue, 5 Nov 2024 21:55:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.70 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730843733; cv=fail; b=uWMf3JBVLb6Q3w/t4wzsxJF7/IW18hdHvupoc2MtiHiLc7Dfc7SU5jWOs03Xa9cLZUQbRVmuWVjjJNPw4O4ArQYocPLOeX6wKOU5B8tnq2V147e7CINkSUQgxjn4ID6TnUsSpaT9JU3bycxnlmAxu4qCGxOde6+iUymIwZMmF5c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730843733; c=relaxed/simple; bh=eF2qGs/x5mPS6vMvQ++RYnUyl+EGpL2+dCo6UC0rP8U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HhULwk39wEXpZTeArji7pV0bpjhV0yBu7/k4VGg450Oc3sGFpLK8C9c6vcKIkKMtfX/ZNp6w6gBuzsAu2kycGef9JuHbkGyP5lEOzErKI5eGtQEd2HRPWpp93metUqBF7LmHOY5Emc8hCSsuZq474cdv3C2blrNdklPNqpPNZHE= 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=dje8/i2N; arc=fail smtp.client-ip=40.107.220.70 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="dje8/i2N" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YsJygN92ZHW0FjPa0cTFA8aVCWxS8TqBBB8Hk2MQbFUx3p2EaGSCQlTcb3E88LHeZCl6OcrVTAVdOLk6mI2w4iNoMHviFk78hBpYcLamsRhlQS2G+5/tvDmLOr0zPSnVA54ThxsqbnbJk7MyPfAFnkxZe4ydjc+AKYALGU5ZMCjhsm4kN9fxXW4bSKttIcM1YoIe0Us0HsiVgpf5ZwcfzitBP69Eg5wBHTfuK+Up0BBQGsFFnOjLzNiXzB3FYC7H7qfWKkYpUkXh0BjhoGA2e2vqB7AIfc8RfKubX6GwjNudodrYGXBsCJMXIwZoSKjrgz4kmB51ywTPcdU9dD0saw== 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=gfrtubeXU+x14zoauGuZY8QL4fmLcZGrL5yDSr7sTME=; b=OSvEW9ZjZQSZ0nZuMNSvWiu4CKY96mXHchYctWztNV6oAbM//D6CJ6Y6i/pNuGc2ZfwbY93VQD79z6heNU5LM8c/vVho+0hDgmVMQN3p3oJf7EPM32eBYUgjHbKQS1aCac8wlP6xgrPIWK3r9rzhyB7cgQL2v71uWXHdWx+FzWc/aBC8A9cvV0DREXHe7T0+ItU20CwG3swlSW1galGO/QWKBGW+i/+EkCCHipQiOmFmi7APftDOyK+6RSplotKWs1oM5a56psuofA1jupyGETDqzW+IO9+/hWYVndzhv/Ftgs7UUb9TxYxyl2hYaTbzyddUmF9JtW5JKGp/BLF/CA== 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=gfrtubeXU+x14zoauGuZY8QL4fmLcZGrL5yDSr7sTME=; b=dje8/i2NynHm4mobt49MdwReT2WaLvZE8FFyL/SZ0vMRwkal124k9nVLJKT9QUDSSK4HEUO0ujqPexpbZEwI9hsaqX9TIshxBCqOIS67sUqQsgbP8IzqyMyylu4EUbGC98LKns4WfPtJmc0xEbz0uDzUEHtBYX5gS8PGQnff8FE= Received: from MN2PR15CA0044.namprd15.prod.outlook.com (2603:10b6:208:237::13) by BL3PR12MB6522.namprd12.prod.outlook.com (2603:10b6:208:3be::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.19; Tue, 5 Nov 2024 21:55:25 +0000 Received: from BN3PEPF0000B374.namprd21.prod.outlook.com (2603:10b6:208:237:cafe::70) by MN2PR15CA0044.outlook.office365.com (2603:10b6:208:237::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8137.18 via Frontend Transport; Tue, 5 Nov 2024 21:55:25 +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 BN3PEPF0000B374.mail.protection.outlook.com (10.167.243.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8158.0 via Frontend Transport; Tue, 5 Nov 2024 21:55:25 +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; Tue, 5 Nov 2024 15:55:23 -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 v2 05/35] x86/bugs: Restructure taa mitigation Date: Tue, 5 Nov 2024 15:54:25 -0600 Message-ID: <20241105215455.359471-6-david.kaplan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105215455.359471-1-david.kaplan@amd.com> References: <20241105215455.359471-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: BN3PEPF0000B374:EE_|BL3PR12MB6522:EE_ X-MS-Office365-Filtering-Correlation-Id: 88da9bd6-d179-44b8-78ed-08dcfde48e1d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|36860700013|376014|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?D44NXf/dnkpI9HMPBGXwKhyN918kMQe8joEbVJbj5yhWw48qx7RayWoulmx3?= =?us-ascii?Q?sDwWaZ7HJZF1CZCWsFbY6UETyAn5rDSjFoRRHyKMaiC9bYznznAZROdKWCsg?= =?us-ascii?Q?haXa35AZIuKY7YLTm/JoP1j1dbVR5/LUgDw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KpDdrgZo4JPijXUp+6e1pZnrXG+NjFnUi/4Oy+85gVp7v?= =?us-ascii?Q?ZCu/PMbyM+V4XLWLldoZlvl6JgHgwFuSDoqRV7n6hvs4FGRo8BLuT/rHvXWj?= =?us-ascii?Q?IOnc50xu4/IzUPaSTyuQEkXZuxoTraADWAKxzI2levULitX7VUd1/IURsNMw?= =?us-ascii?Q?szOAXn1IbG/YaTCy744SxqXnZAqlBhS0wwTiQUS3pulkt/4lQfb0WC/sRlrA?= =?us-ascii?Q?QNVucerefNv3w5SCX8Q4fitNGfs3E23ltuhv/PI5dIsJqZjn1lsuWijvWw0N?= =?us-ascii?Q?nXYDbrNBGe+XoQkozlU61x7Zdc+/zfWS3CWENCTtvLBOp8Ehaaml/Pj1qtWr?= =?us-ascii?Q?fNp2bvDFQDqr0o1NpFQgxq8fijeRsKN05pIcjSm7bVN3KkvR6A=3D=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)(7416014)(36860700013)(376014)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Nov 2024 21:55:25.7809 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 88da9bd6-d179-44b8-78ed-08dcfde48e1d 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: BN3PEPF0000B374.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6522 Content-Type: text/plain; charset="utf-8" Restructure taa mitigation to use select/update/apply functions to create consistent vulnerability handling. Signed-off-by: David Kaplan --- arch/x86/kernel/cpu/bugs.c | 58 +++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index 4f35dcd9dee8..c676804dfd84 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -65,6 +65,8 @@ static void __init mds_apply_mitigation(void); static void __init md_clear_update_mitigation(void); static void __init md_clear_select_mitigation(void); static void __init taa_select_mitigation(void); +static void __init taa_update_mitigation(void); +static void __init taa_apply_mitigation(void); static void __init mmio_select_mitigation(void); static void __init srbds_select_mitigation(void); static void __init l1d_flush_select_mitigation(void); @@ -187,6 +189,7 @@ void __init cpu_select_mitigations(void) ssb_select_mitigation(); l1tf_select_mitigation(); mds_select_mitigation(); + taa_select_mitigation(); md_clear_select_mitigation(); srbds_select_mitigation(); l1d_flush_select_mitigation(); @@ -203,8 +206,10 @@ void __init cpu_select_mitigations(void) * choices. */ mds_update_mitigation(); + taa_update_mitigation(); =20 mds_apply_mitigation(); + taa_apply_mitigation(); } =20 /* @@ -374,9 +379,6 @@ static int __init mds_cmdline(char *str) } early_param("mds", mds_cmdline); =20 -#undef pr_fmt -#define pr_fmt(fmt) "TAA: " fmt - static bool taa_nosmt __ro_after_init; =20 static const char * const taa_strings[] =3D { @@ -399,19 +401,19 @@ static void __init taa_select_mitigation(void) return; } =20 - if (cpu_mitigations_off()) { + if (cpu_mitigations_off()) taa_mitigation =3D TAA_MITIGATION_OFF; - return; - } =20 /* * TAA mitigation via VERW is turned off if both * tsx_async_abort=3Doff and mds=3Doff are specified. + * + * MDS mitigation will be checked in taa_update_mitigation(). */ - if (taa_mitigation =3D=3D TAA_MITIGATION_OFF && - mds_mitigation =3D=3D MDS_MITIGATION_OFF) + if (taa_mitigation =3D=3D TAA_MITIGATION_OFF) return; =20 + /* This handles the AUTO case. */ if (boot_cpu_has(X86_FEATURE_MD_CLEAR)) taa_mitigation =3D TAA_MITIGATION_VERW; else @@ -430,17 +432,36 @@ static void __init taa_select_mitigation(void) !(x86_arch_cap_msr & ARCH_CAP_TSX_CTRL_MSR)) taa_mitigation =3D TAA_MITIGATION_UCODE_NEEDED; =20 - /* - * TSX is enabled, select alternate mitigation for TAA which is - * the same as MDS. Enable MDS static branch to clear CPU buffers. - * - * For guests that can't determine whether the correct microcode is - * present on host, enable the mitigation for UCODE_NEEDED as well. - */ - setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF); +} + +static void __init taa_update_mitigation(void) +{ + if (!boot_cpu_has_bug(X86_BUG_TAA)) + return; + + if (mitigate_any_verw()) + taa_mitigation =3D TAA_MITIGATION_VERW; + + pr_info("TAA: %s\n", taa_strings[taa_mitigation]); +} + +static void __init taa_apply_mitigation(void) +{ + if (taa_mitigation =3D=3D TAA_MITIGATION_VERW || + taa_mitigation =3D=3D TAA_MITIGATION_UCODE_NEEDED) { + /* + * TSX is enabled, select alternate mitigation for TAA which is + * the same as MDS. Enable MDS static branch to clear CPU buffers. + * + * For guests that can't determine whether the correct microcode is + * present on host, enable the mitigation for UCODE_NEEDED as well. + */ + setup_force_cpu_cap(X86_FEATURE_CLEAR_CPU_BUF); + + if (taa_nosmt || cpu_mitigations_auto_nosmt()) + cpu_smt_disable(false); + } =20 - if (taa_nosmt || cpu_mitigations_auto_nosmt()) - cpu_smt_disable(false); } =20 static int __init tsx_async_abort_parse_cmdline(char *str) @@ -649,7 +670,6 @@ static void __init md_clear_update_mitigation(void) =20 static void __init md_clear_select_mitigation(void) { - taa_select_mitigation(); mmio_select_mitigation(); rfds_select_mitigation(); =20 --=20 2.34.1