From patchwork Mon Jan 6 12:46:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nikunj A. Dadhania" X-Patchwork-Id: 13927396 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2074.outbound.protection.outlook.com [40.107.220.74]) (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 EEEB41DEFF7; Mon, 6 Jan 2025 12:47:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.74 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736167664; cv=fail; b=RlFx2Zi2Kwmyv3RGXcuI6QQDiHj1b35YTg2WsBiR++BwcaoTBlVVC1PBwkH+5GkRZRFY8p8aIAZ3FZmfI7nP+G34Pl/0s+18LgPz761G2F81zRvcj4x3gHgG6sJjva13FP4A1cEFMZHwGoL1lXxXXvXPJubD3IKpMoKZaRUQb7o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736167664; c=relaxed/simple; bh=w4JF1BsypmiAtMx5rcJ0oEC9BR9U5wlldptjLU+7VdM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r0Hzox0W3UXPsihrmmQFncDtPSr2CZnXLiMthg6PnL/pJzTW9P8TS19NA11y17MQb0X+n7qkcpVlg8PeJOoTXI/eYaBOET/N4qCkgf96CS7cKQzqB5lr/sTAL4PxilHhOuQuljhtYxeZe38MvEx6/SaD/jJiznbr7qgfBTqfjkM= 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=WKZDskFg; arc=fail smtp.client-ip=40.107.220.74 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="WKZDskFg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QDV+X76h+KoGzSavG6SMlmtKFwxI1EslKD8wR2ifjMLR48sWbt6sm6URfRz0j6ZRMhcWCnlqtpF1lEcEdAZv26ZskJCgw/PrlsZm3yZ1jiScJ1Gw2eLaKpEqSD/bFLW9hB02Z7hec+275ZLLzV2R16wdkVPmlP/uARcMzgGtv3pibP50t35/inVeHEulDNTDScsSmt0eY3Ff91S1JLilupQSQKqkh49aJY6yoFneRIAHYSX3FV722RGM6OieMIXBRQ2ASbeD0qhCRHD9yC9CNMYIEIUhwlu74B26cyBDhWBFjqxujTfdtf3CWXc5fYllG5lyz2vgnbxx51npCII67A== 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=Am8CZG0IEztf4DaYRJD9YIDRhI1BpmSNVZb7FO6xBc4=; b=uVaWsxPx1eGDUUKf6hr3ZF5ihJDxg3n+86VAcnXaxc3R4AMjr9b+HqoBCcdwqkYfWPvaKBg0DyCHUqGnkoPyI3y2G8YIj4cWFxVaVTATT2Rhyc2rN0yw+5qNA1uLavqfCC9dmiW2jUus7fkMnaY3Z6LfPPrnXKMSVWon8AAjbCII+XOik0eKr9mE/pfWsCX2s/z759dewjmkA6I6dJpMWhbXWsqBk0z+Iy4VE5O91WCs7kcQN3fDY+Xrd2T4hZuOh1ppcPRoDtv2Q8rJ3BNNrOY0Lkp0kRy0FBpf6SetsqO/A85CyeNcG3/x3fDMsjJubFAqMgWa7pth0xmkqrJgpw== 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=Am8CZG0IEztf4DaYRJD9YIDRhI1BpmSNVZb7FO6xBc4=; b=WKZDskFgNVMXDA2sdnIrqHqP017U1XE8xVn5CqlHtYTPXXP6teiw0aEwE7DiP05bU+a5zCgCbQ2O9ZPTe9KA3osiwY4qOq70lbvlInBg0s4o/qmYBRTXSrE29X18wBF2FHLd2jZjQVtFXmWFMPqsGUb0YkYID+XCnzwU2gZ7oKc= Received: from PH7P221CA0008.NAMP221.PROD.OUTLOOK.COM (2603:10b6:510:32a::26) by IA1PR12MB8189.namprd12.prod.outlook.com (2603:10b6:208:3f0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.16; Mon, 6 Jan 2025 12:47:35 +0000 Received: from CY4PEPF0000EDD2.namprd03.prod.outlook.com (2603:10b6:510:32a:cafe::15) by PH7P221CA0008.outlook.office365.com (2603:10b6:510:32a::26) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8314.17 via Frontend Transport; Mon, 6 Jan 2025 12:47:34 +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 CY4PEPF0000EDD2.mail.protection.outlook.com (10.167.241.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8335.7 via Frontend Transport; Mon, 6 Jan 2025 12:47:34 +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.39; Mon, 6 Jan 2025 06:47:30 -0600 From: Nikunj A Dadhania To: , , , CC: , , , , , , , , Subject: [PATCH v16 09/13] x86/sev: Mark Secure TSC as reliable clocksource Date: Mon, 6 Jan 2025 18:16:29 +0530 Message-ID: <20250106124633.1418972-10-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250106124633.1418972-1-nikunj@amd.com> References: <20250106124633.1418972-1-nikunj@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EDD2:EE_|IA1PR12MB8189:EE_ X-MS-Office365-Filtering-Correlation-Id: 02c04b73-bdde-44f0-471c-08dd2e504b19 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|82310400026|376014|7416014|1800799024; X-Microsoft-Antispam-Message-Info: J6Xxxzw7x8rnHwOLvBqz00i/HqYKr5B/vZAEMAh5dnYSLCksJWwOVJKk5OSLXky+ygX+9dzICE1WCBW8SnmFQepm7cpu80/NFW6lHZC7sBnwAgVKz27R1WR9CgXIIMQ92cYs9uSrh7HsYPrPNyeyj6V5oVfHMRozc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ywU2G8A9YNTB75mDiTQGi8+z1BVNdxkxqqsb3DiiVSMMQxgdXgWE+2y0wJDV+5xYXBoF/3IovjC7/bzd5aT9/05zkmH4LE7fFoYVxihXVv2Xe/6QKc9wjpwzy5x6pUY2z7+vv5ZfGkHCz3CJYg3j7VKAVJLJdzWMsNbR+A23B1JVAiKRM/jPT3FlXpvEYSqNg6ArULfHXprGJWhQvyLPfxQ4eJcV0Q6V510ZmQsv5t9SpIhuVl8K1cDzm7UwmAUVS6mJmuNkkqSxy9tXCBAAw= 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)(82310400026)(376014)(7416014)(1800799024);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jan 2025 12:47:34.6968 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 02c04b73-bdde-44f0-471c-08dd2e504b19 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: CY4PEPF0000EDD2.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8189 In SNP guest environment with Secure TSC enabled, unlike other clock sources (such as HPET, ACPI timer, APIC, etc), the RDTSC instruction is handled without causing a VM exit, resulting in minimal overhead and jitters. Even when the host CPU's TSC is tampered with, the Secure TSC enabled guest keeps on ticking forward. Hence, mark Secure TSC as the only reliable clock source, bypassing unstable calibration. Signed-off-by: Nikunj A Dadhania Tested-by: Peter Gonda Reviewed-by: Tom Lendacky --- arch/x86/mm/mem_encrypt_amd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/mm/mem_encrypt_amd.c b/arch/x86/mm/mem_encrypt_amd.c index 774f9677458f..fa0bc52ef707 100644 --- a/arch/x86/mm/mem_encrypt_amd.c +++ b/arch/x86/mm/mem_encrypt_amd.c @@ -541,6 +541,10 @@ void __init sme_early_init(void) * kernel mapped. */ snp_update_svsm_ca(); + + /* Mark the TSC as reliable when Secure TSC is enabled */ + if (sev_status & MSR_AMD64_SNP_SECURE_TSC) + setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE); } void __init mem_encrypt_free_decrypted_mem(void)