Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2549829rdh; Sun, 29 Oct 2023 23:39:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG1fDa0GpfwToCX+eRatDBZ1ABRSDSDvOfvYNZLMmMI8X+EloakhF1X0t/iEaQ90/3uhJtb X-Received: by 2002:a05:6a20:7f95:b0:152:4615:cb9d with SMTP id d21-20020a056a207f9500b001524615cb9dmr15757643pzj.12.1698647996775; Sun, 29 Oct 2023 23:39:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698647996; cv=pass; d=google.com; s=arc-20160816; b=LeafLKUmvE0swZAB9YKNZiSBJ0Idpqe84sOH8iuGVKAW/kGITzD8B8sgKV8+hxW/+R N5uITARGxLUn7mP9SVwJ9naHx8Q3VT8zZ6LzwF65VcDt7bKaulzDhYolcz59ylkxOyQy wqhJvwl/LulLZo8YpB6LIxRhbMD2e/fu0WNphJPxJ/2kxKuu6uCc8jt77g5vukeeUwlg dZHm5ydpomlDzLXoqzN6F4vpXRaH4WYk7kdl+/fflsajDEcIaVpeyFqJrF6lpcQ/DJBe ZaScY61ITfODJPw670SbT4wOJrlYxODPZ4hbRLzvD7n1bXQW8N6zbd6E8a2V8KBJ8l0x +2qw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UgD9DpK8J/pJKDXITmBQ3y9a5TY6d+jIq/civj9oco4=; fh=GrBYTfaCmKSBoJ0OQBiloTDpWB/NcGHvBdTqN4MlWVs=; b=kB1z6y64r6jjig3w4oUrCzgFLzQX6ZZpiINchcK8ohlH0WdZA7dZvG+mei8Mq4ckt5 RtHmmhYlBHrWN5Eb7uVAw6feqyUwZN8q/yL228LMfL/hp7BKEk1ea8OO9LG8mEJORXC6 09RaEcjFVcH3bHgWdISzfay5Gwxa0fimUhZ0HapFCH0JO7laj+UW/v34K22+vNK0NGRQ GRFzXi5is5IFQLmyFKP7Db7teLkYycKJPEiBNWdv75JSNFQVc8x6Kdreik1QbL3yeu1W qpTF7Q6Mvfqln+/bxd4Uw7dohmgTx4jUr/HsIKihhWrl95JKZVE93Dvymjp1aFn7bt0z e01A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=Nj8YE48D; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id n184-20020a6327c1000000b005b7fb04f1fdsi4665727pgn.140.2023.10.29.23.39.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Oct 2023 23:39:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=Nj8YE48D; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 477C480AA24B; Sun, 29 Oct 2023 23:39:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231824AbjJ3GjX (ORCPT + 99 others); Mon, 30 Oct 2023 02:39:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231895AbjJ3Giy (ORCPT ); Mon, 30 Oct 2023 02:38:54 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2069.outbound.protection.outlook.com [40.107.92.69]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C825D4A; Sun, 29 Oct 2023 23:38:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EckQaWDMQ8/JA001HsWQX1kcd6J5+g0Y2yImAHk76vQXF5o7PwG6jKJpbCbqdjNrM0WWHbOHTC0rVkuk5q+YhBR1idpu8G5RIQr3wknVdO8zBigp9j40Vxo4HZO+uFJuEgv6/8qkaq5yYU9afZa6qCBP2t3/VyJYod9KFQ5joYLsmnNt+idng2HR9DPSjGZMTTGZGey0HR7I5gU8L14msF+rYydRVhXvW/NvrbBKzTjOM/GC1s1FZQRsH8cWAj6tJ1GrHQpppwVeMklI7loRTF67A1ChXenDdui53AKw4vLbFJY34BDuVc+NghCR/mA/cNsWYZnXeLPmeNMydThXqQ== 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=UgD9DpK8J/pJKDXITmBQ3y9a5TY6d+jIq/civj9oco4=; b=N6HSddYUAFQalY0AnpKHshclTU1AvaD3ScMPCxHir+vd4fIAY+ijt7HQu5YfdvBkNfn4mLTF6ZS22lGyz+YjrY4SH6I94hsGvaJp8t/kxRmsQf2RhGrFYNqkT6MuzgjbtO6WgTglR3CA6+x3+E84G6rrzm+Ef/AjhdQ51iBS43ZIkdrHVZidoyCKs3C0bOr1MYwGLYW4N9/yNjamr3CD7rb+pn/BOafYWEpiqgcqZqUCzGoWDNZXyFpITDj2SMCqVY6WeUMiL8ow71RgZOO/tVap49mJTiwmMeTc7+jLZq4ibP0mX2mCDgf6EUSedBk4XfCL5CuAthjM8yGf3ehYIw== 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=UgD9DpK8J/pJKDXITmBQ3y9a5TY6d+jIq/civj9oco4=; b=Nj8YE48Du3miCw6xhJydAAFUDivnSiCvMxQnoQJkBOIBnTRqwh81wcNx+XsJU8eZNHSn7i//SKOm92o+JERFmWsoIns4hYtxHNtjkQWxnZHASCBbo/gFx3/i4JgkcGMXojLScLwFpR/P2scO/tBozSnWWcpKt/xOTNgO8PLl2KQ= Received: from MN2PR20CA0037.namprd20.prod.outlook.com (2603:10b6:208:235::6) by PH8PR12MB6841.namprd12.prod.outlook.com (2603:10b6:510:1c8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.28; Mon, 30 Oct 2023 06:38:41 +0000 Received: from BL6PEPF0001AB73.namprd02.prod.outlook.com (2603:10b6:208:235:cafe::95) by MN2PR20CA0037.outlook.office365.com (2603:10b6:208:235::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.28 via Frontend Transport; Mon, 30 Oct 2023 06:38:40 +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 BL6PEPF0001AB73.mail.protection.outlook.com (10.167.242.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6933.22 via Frontend Transport; Mon, 30 Oct 2023 06:38:40 +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.32; Mon, 30 Oct 2023 01:38:36 -0500 From: Nikunj A Dadhania To: , , , CC: , , , , , , , , Subject: [PATCH v5 11/14] x86/sev: Prevent RDTSC/RDTSCP interception for Secure TSC enabled guests Date: Mon, 30 Oct 2023 12:06:49 +0530 Message-ID: <20231030063652.68675-12-nikunj@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231030063652.68675-1-nikunj@amd.com> References: <20231030063652.68675-1-nikunj@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] 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: BL6PEPF0001AB73:EE_|PH8PR12MB6841:EE_ X-MS-Office365-Filtering-Correlation-Id: 6ea45773-7517-4a44-fec6-08dbd912dad5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UNybn2yb/fdoVElC3FMVDiIWrB7LPlcrGL3jNCCB9Dm6lU0rNQBLB4zdifGImziGkMlCn90hHsq+HrkbKlLSrVUpmqh+HRhku0aUiPGLEth13urF2HE6sfoopJsT/irz/CVwe6vrF518AG9syZLDR7+Pw469M7RPVhRPFp/WeYyBH5l8fzhF6Fh4Y8dzJAG6pL/HHv0s6GTfekCc/oVGHaogmOsD9DQrSSBr0/steg5wF3UK02JdfQhbf/kzqAJGWFRUn+OPgyhT5/TowOz9QEy3fpE0PlS8S/2chigOoHCDqzUs6nyIhGvYFFa7scFJ71FD4Daj1nXkvpUhrWPQyDs2bFR/bNfRESaMNHO5SFyof36e3JmGLEGLMDzvuJES/qgNC1uvLNsRWDBod+t60ffXc9xZvetxl257M+1LKmWRh2WCF2ebZcDiOQBptJVwzF+mFnfNpgV3W3jtDzabOEsIJutv94bzqmClnzL1MZb5UrfOZwoNyjNckO6uF+6a8r/ULyN1eCjNQIAnyRbpC8V7OCp3KWECPcISsas/1R1m1KKpz5VRYt69sfIuXsmBd8SsxYVXY7YwIAePpQl+/BvGnDMcnwev5+9O1iZQzyvvz1vI5aWmUsSVLfL1+IPRS3ZJexRNaSNz3AdIZ50Pmb0xICRxSUt4BMogPqGn9m0Uoy9yVNsigkIkSIhQWVoX9cHK9NbCMPLYBGEeKFr1+5q1wTTjhars6Esr0T0d95/gYAdIMVxKX4YnvghBPTTKq03cW9Rge1N35/6qaC14ZQ== 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)(4636009)(39860400002)(376002)(396003)(346002)(136003)(230922051799003)(82310400011)(451199024)(186009)(64100799003)(1800799009)(40470700004)(36840700001)(46966006)(40460700003)(110136005)(54906003)(70586007)(70206006)(4326008)(8936002)(8676002)(316002)(7416002)(5660300002)(41300700001)(2906002)(426003)(336012)(356005)(81166007)(47076005)(82740400003)(26005)(16526019)(2616005)(1076003)(36860700001)(478600001)(40480700001)(6666004)(7696005)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2023 06:38:40.6840 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6ea45773-7517-4a44-fec6-08dbd912dad5 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: BL6PEPF0001AB73.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6841 X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sun, 29 Oct 2023 23:39:54 -0700 (PDT) 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 --- arch/x86/kernel/sev-shared.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c index ccb0915e84e1..833b0ae38f0b 100644 --- a/arch/x86/kernel/sev-shared.c +++ b/arch/x86/kernel/sev-shared.c @@ -991,6 +991,13 @@ 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. + */ + 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