Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp218832lqh; Thu, 30 May 2024 21:38:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVyMiz6xlzLogrBIYPttkCIPeZZiEZ7Wmb1rjX4l1A8Bin5umKsVq8ZYT0EaVUPqumycxGaicfeRu1+f3oHlUvxZY+doc9tLTD+zGPc2A== X-Google-Smtp-Source: AGHT+IHsAOqVF0VXqhFAuvU5louNi+NjsDlHJnqbCjohOCk4h62U+HQY0iBQ1wixh+kOeGv3r4mK X-Received: by 2002:a05:620a:113b:b0:792:c13a:1a80 with SMTP id af79cd13be357-794f5c99206mr73775685a.44.1717130307517; Thu, 30 May 2024 21:38:27 -0700 (PDT) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-794f2f04f04si127069085a.60.2024.05.30.21.38.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 21:38:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-196269-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=@amd.com header.s=selector1 header.b=mqxqcnqx; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-196269-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-196269-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com 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 2F7351C22187 for ; Fri, 31 May 2024 04:38:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 697E1132110; Fri, 31 May 2024 04:34:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="mqxqcnqx" Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2062.outbound.protection.outlook.com [40.107.237.62]) (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 E6C8C823BC; Fri, 31 May 2024 04:34:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.62 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130091; cv=fail; b=gANCK0/+IrgrB0eR6UhyJg7xSAlRnPn14c0799GSfcpjQIWhPVLszOqzAPqb9+KPsDO+GNZxyg89MZsokYm/LPH4ukOwo86JUgQyUJyhtcmEGUz78+gmszOGQ4+24RDlfFqCQvbm/nydvWDPV5LK/3GaGCr7vBucfzOW7d6gReQ= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717130091; c=relaxed/simple; bh=Qhaju30KipVL3Ll8fiKoLEqeztNPGqtph/BGVhSyR00=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=P+2QvwCjtK683FvF30nA5gUv76J5EdHeeM/XZMlN9Lf2W4wRlHclncS7BXua3s6CK3Crua4ZYGtNv1A7eVSUxS2MoAmf5fqwOFKxl4AZNEQWuF0t7qFYEJyIfvw3pA4SB5EeBhq8GWkmvZV0AU/9en/RLh67OF0CeXqbQTrn9z4= 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=mqxqcnqx; arc=fail smtp.client-ip=40.107.237.62 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 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XU80TUA+KqrFw8thbC8/HSX3sr5cdmnPfwedzxjrBUAT2hMdPtWnpNhl3S3jF2aCb/WlxVyMka1AsAsDYHpTgFSDFXZ1gjIRiuf6hE/aFkwDaknPo0WIkftAmxIryBt29piblJ4rhP50sGHuHoxqbhyMYphLTlQcChYzXxt5ZlL7K8N5usJxkTctQ5kbCoiAo5TONesCY09bq67PwAA7m3jWvnd1PzQeuprOm+Ck4SqMdnKnSbsgbPF/1jtM86ABE61SyiGqJvESq4Xjfet3HzpWcz1IlcjbxsSQ6z/T5H9/zC3Bs77+qXlshdNGKvnIy/n7ToW+OV5nrMtwC+6xCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=cqwMbsLTloE6koXkAIOHwo2P0VGFRONchM4ZooyM3iY=; b=Ml7VVGVrHfirmqhVJD+TAvkl03lmzKYGGFNPL5FtqYl0j8xuYjvx7jwLpmcl/G2hlTv+PdihfmsKOlR9vAqJF8LRo2eozogQZMi/TtzOjVPVylxWHwG6OOmn60crtPleX6OEkwnw81RP/yjSZDDNiKGEX8pB53mwWfQy2JtXrE/TBdMr3m8NuRRhp/OLsRNp0KybOtc/Bft1BBLrpZkgOv+yveRsYNRvD1r3osabPjnZJUhsxyPEoOnV5T3Eso/WMGHdXlwp69SakZ/pbq095BsHscQzEA38fp+itfp6OOe/6rSwL/6p5wpV5uV5v0jta2OihJ8KA2etNXmfgNLMVw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org 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=cqwMbsLTloE6koXkAIOHwo2P0VGFRONchM4ZooyM3iY=; b=mqxqcnqx0cBnC+/1ulozspS+ZYG4FhdhVu64h6tKQ5yqiw+grn3m61BndMcgaTNEQB59nLjlmSFrF3HWIo/CmJ1oSDPHCRX2nCb87CFu1FNxsRJZwpaGR1ddgvEBcU1kc2sfDXmbRYnnvtszntk2QA4k0qlIEdMPfDR2xjuIdso= Received: from CH2PR07CA0046.namprd07.prod.outlook.com (2603:10b6:610:5b::20) by MN2PR12MB4424.namprd12.prod.outlook.com (2603:10b6:208:26a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.22; Fri, 31 May 2024 04:34:47 +0000 Received: from DS3PEPF000099D8.namprd04.prod.outlook.com (2603:10b6:610:5b:cafe::68) by CH2PR07CA0046.outlook.office365.com (2603:10b6:610:5b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.22 via Frontend Transport; Fri, 31 May 2024 04:34:47 +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 DS3PEPF000099D8.mail.protection.outlook.com (10.167.17.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Fri, 31 May 2024 04:34:47 +0000 Received: from gomati.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.35; Thu, 30 May 2024 23:34:43 -0500 From: Nikunj A Dadhania To: , , , , CC: , , , , , , Subject: [PATCH v9 20/24] x86/sev: Prevent RDTSC/RDTSCP interception for Secure TSC enabled guests Date: Fri, 31 May 2024 10:00:34 +0530 Message-ID: <20240531043038.3370793-21-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240531043038.3370793-1-nikunj@amd.com> References: <20240531043038.3370793-1-nikunj@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: 8bit Content-Type: text/plain 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: DS3PEPF000099D8:EE_|MN2PR12MB4424:EE_ X-MS-Office365-Filtering-Correlation-Id: ab0180ac-01c1-4996-7b14-08dc812b0080 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|7416005|1800799015|82310400017|36860700004; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?IQMvkIeLADztyziUK7JbWdZLnJNqgYYBYqJ/uIFG6CtmqDWJiFE1oZbJ0vJh?= =?us-ascii?Q?/iNPNwo6fq/0CfhOkKF7t9vC1AZUkmUYKZSItKfUbMzWqUchP64ZZGvF4n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QJJ6Ewva4EP8761f4JmPcCajH?= =?us-ascii?Q?gdoW2wVDIacieTd5aiF/ec6gjnK3Hl+KborwfT95q9bfEUt9DAXVe2zHXyBI?= =?us-ascii?Q?Gj7+mHfsaGc7GCwYxbhHU4/v3X7F92XkYasTkPY1TKfcCvaVFz98Y3MfcZk7?= =?us-ascii?Q?JqGzfPrJ0wxQzT/zDqW/5xpmp3s4UGUKvnujizAGRt5TnLfUVvptxM/12oOa?= =?us-ascii?Q?/dQGE3QRfL03LuaPzVJIoI2h+1MHuoDFjER8Wsdkubah6i/pA54uT3ptaVwq?= =?us-ascii?Q?dwHxYL8+7hRvWt1NYOdPxfYMWe8VEN6iBx0o+ALI12vooqwdNdMdLTPNCfGq?= =?us-ascii?Q?gO1MpGpE28JC14ujgfOX3r01JQzQmE9jE7rZinTZ7wfSRZWjCY0DnNtzvPHa?= =?us-ascii?Q?y6DQYvc=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:(13230031)(376005)(7416005)(1800799015)(82310400017)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2024 04:34:47.0983 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ab0180ac-01c1-4996-7b14-08dc812b0080 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: DS3PEPF000099D8.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4424 The hypervisor should not be intercepting RDTSC/RDTSCP when Secure TSC is enabled. A #VC exception will be generated if the RDTSC/RDTSCP instructions are being intercepted. If this should occur and Secure TSC is enabled, terminate guest execution. Signed-off-by: Nikunj A Dadhania Tested-by: Peter Gonda --- arch/x86/kernel/sev-shared.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c index b4f8fa0f722c..58888a086dcd 100644 --- a/arch/x86/kernel/sev-shared.c +++ b/arch/x86/kernel/sev-shared.c @@ -998,6 +998,16 @@ static enum es_result vc_handle_rdtsc(struct ghcb *ghcb, bool rdtscp = (exit_code == SVM_EXIT_RDTSCP); enum es_result ret; + /* + * RDTSC and RDTSCP should not be intercepted when Secure TSC is + * enabled. Terminate the SNP guest when the interception is enabled. + * This file is included from kernel/sev.c and boot/compressed/sev.c, + * use sev_status here as cc_platform_has() is not available when + * compiling boot/compressed/sev.c. + */ + if (sev_status & MSR_AMD64_SNP_SECURE_TSC) + return ES_VMM_ERROR; + ret = sev_es_ghcb_hv_call(ghcb, ctxt, exit_code, 0, 0); if (ret != ES_OK) return ret; -- 2.34.1