Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2549679rdh; Sun, 29 Oct 2023 23:39:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE7RTcuzQi40YThpfF/88COoi5EBJHR9YkwxMzPqPb7lS1O0f6QxHca71esAtZhd62SGvX6 X-Received: by 2002:a17:902:cec3:b0:1cc:5671:8d9 with SMTP id d3-20020a170902cec300b001cc567108d9mr654459plg.27.1698647969465; Sun, 29 Oct 2023 23:39:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698647969; cv=pass; d=google.com; s=arc-20160816; b=KdYPklfwi0L30/XzKiOtJcsYONh5WY6bFiE7yUIpMpqzd1/LhyuRdHKGsdmz/z6CcV TBq9l7Qlqik7L2XvXz1zaFighJskvimEZHktD0thLwmdf0m9rSvMEbjVXA2YSbgor8IT HVM+xSHkBQMkuM7Opn79It2esWx6rc3x5nmQ17OtQ2Ij48WvNKyUOZOJPF5JryBcLMkt e72cG7WSQ3bUR4ya1hCxiXezVL8Fc3CDTm1ByCkB1k5ivNCst6te3+qTaTzRCKdGC7Fa a0znP8EM82Es/Xg3DL9R9hVkhNAIbR3fR9rtJ9tyPxjKQ/fwyXrc9pof5n6vEiD2KGaZ hx/Q== 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=SOpPYnPPYgd8ZYlruYWJfqYAnjA4CKjDFWE63jFS0BU=; fh=GrBYTfaCmKSBoJ0OQBiloTDpWB/NcGHvBdTqN4MlWVs=; b=sA4GbeOW/aN15LJhDcB2onqJvWjWdnd7L1StoeLRLJR5lTDC2ryydIB0FlEggXLG5P hgb06vW2iivgwnUm1XI2RuizUeflJTZLpd8CpOeKt9p3cxIgBXjswXNoYKJbjNWC7GN/ Z/0gxKRp1xXdwi3RUJGoAzDhTDUl+i3Vl3PwTxMJ7Ew+LHst5sT5OkQLJgrOi8RZqFAK KdEVQ+xgwPWO4IDykkVrRha5sa7xxupEwsWSCS04WE4kmuFrJwgahzHnaxaipRCltDZn OHT09WrP+xZLBiaGpxOzZ1u5MK4mYx40lkO9+/B/KAVcOih96x8Y67jp6zGZRZ+VDTnv x/sw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=dNSk7sYp; 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 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id r10-20020a170902e3ca00b001ca529e3d29si4543144ple.168.2023.10.29.23.39.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Oct 2023 23:39:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=dNSk7sYp; 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 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 7784C80C0381; Sun, 29 Oct 2023 23:39:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231741AbjJ3GjQ (ORCPT + 99 others); Mon, 30 Oct 2023 02:39:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231891AbjJ3Gir (ORCPT ); Mon, 30 Oct 2023 02:38:47 -0400 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2065.outbound.protection.outlook.com [40.107.212.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84E60D57; Sun, 29 Oct 2023 23:38:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Dky7irwTM2ac4p+mMMtmzC6teC9RFTYBad+0DbZDbZ0AaKrxYOgZEZYbPDP1hG9OGvFCbPgvUeDvf8go+wS3Iht0aBvV+9paU1Ek+Q5I0x4b1lKhVZuI4h08wi/V2+rtNSEU4KYqrMkC6UwL/3D0goPtveVp/BN69Tf8/YgcKNMTqmuVlzC3JZfIq6oFz4gRrKo7k0CAI9C5yBpOWKDFS8oi0tDNAnack/YoIlpHOPC0ydShxAXGt2lnhOAj35sK6AxRJwQZws9HG3AwPGsyjh6AcDsiQ7gjbuub5j7ASGeKXgoAqx7WXFrsveINwktk+3R8rEi29l/s6e4iMW51Zw== 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=SOpPYnPPYgd8ZYlruYWJfqYAnjA4CKjDFWE63jFS0BU=; b=mMhrZ5bY5aYL3Hygu07HAc/0yGSKeOrh3fiYMoGC0Be6NnateP8ilFW5KhNn1anf9UEcsG3mfFDzCKwPmNV2aFMMSnpPuQ4Bdsj3eH8PtNOMuqwNStEd5ClNniTEmLzcDv++m6qBh0GYtu0frL/hG3/1cuCs5mUQhgOmiv1nzKIcOiQo75VKHEuMPEulF2TtPQBj3aX7E/pYf8SEamjErt64C8uJGR+tID4o+7IpbZtTTjRj8UMWncUnFbjgMvA8NBk9aYZdvTTILILe3pzhNXuDWlJsG+0wM+/UqQk4iCQ803jtQppoxdE7VZdVd2rstMAT/ULFm+d9tjYJgwsrSA== 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=SOpPYnPPYgd8ZYlruYWJfqYAnjA4CKjDFWE63jFS0BU=; b=dNSk7sYpUUktu1tGCXdnXXLniumOsyH60q3d1992O/gTwVQ+zbHJXfgUdGAUu3BnOdzJGqfqKq7Jl6pnWyFTxy8BwFs4MvF55KXmiqv686Gcj6+lcFxD8bBcN9ZkpQZ6yBuI8PEYCKmJlBE6DDf7Kct8gfskzWH+wcEzLJYZoYk= Received: from BL0PR02CA0101.namprd02.prod.outlook.com (2603:10b6:208:51::42) by MN0PR12MB6319.namprd12.prod.outlook.com (2603:10b6:208:3c0::11) 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:36 +0000 Received: from BL6PEPF0001AB77.namprd02.prod.outlook.com (2603:10b6:208:51:cafe::b8) by BL0PR02CA0101.outlook.office365.com (2603:10b6:208:51::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.27 via Frontend Transport; Mon, 30 Oct 2023 06:38:36 +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 BL6PEPF0001AB77.mail.protection.outlook.com (10.167.242.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6933.15 via Frontend Transport; Mon, 30 Oct 2023 06:38:36 +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:32 -0500 From: Nikunj A Dadhania To: , , , CC: , , , , , , , , Subject: [PATCH v5 10/14] x86/sev: Change TSC MSR behavior for Secure TSC enabled guests Date: Mon, 30 Oct 2023 12:06:48 +0530 Message-ID: <20231030063652.68675-11-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: BL6PEPF0001AB77:EE_|MN0PR12MB6319:EE_ X-MS-Office365-Filtering-Correlation-Id: 6d676607-123c-4106-8bd3-08dbd912d860 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /tYNyEsoJAMpYa6UD0ZN5sjX2MhZHN9BUtuNqxNT348m3wU5nnmfyPNYwWP6hk0/XFs8uv/lbjqRtyxbInL8mv7aTPyAwUMrlpNVO8ubq8mIXb2cjEGxttI5KPREYfXWwULPAEgG4FKcEOAqg41TYJiJQ3lx7LZMex5c3B1NkJFTJXgaj/mgMmrud26TN5PPWWNjGvY9ezFqKAOtQwE3jLwEJqGKHVIf+E+ocsYCpM9K47wWE64j31zU7uJhVE60m2DmyLrllP6rhJUX+41EOhQCNWMVbMz4oWhw4ey5pxmw2TVo9Od2bLSzGdoRv6v43ZsCIhwO7PaiBidSvFWkEBMPhC0KUk54tvgeK168ktXr1kcXqapTHYp4NFI2ZiDzpC10o3l2xjiutV0LgTyGKme10daZyPyvmjvFYjB6/EXlnuUpXt5+hYsvjkq2LWWzuCwOHSO9CI8xsVpzfk0WiSG25BPgS8MW2FWQw4Ixd458WrQ5NiJ3OyEdFBe8ki9zzDpE3dE690gkLywANInHDrzcnY/g5e0TqjhogMmP1n0R/sBR0gdqk/OaHQQW3p02Ek3ez9W5/3+LLrmEvK1otkFGfzVGYGxiqdk8jvlsNVeGu3QM0ZW+6HZ6JyawKn/HqaX5SbIwKBZ+NuEKKW8AmHRTx/L9O2t8P0yPCJqmDDDvBjimP5ulhqNDuI0uafhzYG2L2q0TlJLJWyUoJPteM9hq7i9DEa6/8qeQDe035o+qwVNDvAs7gObyP40wVLp5iVx2zlC9xMp8I3YQr2qLxA== 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)(346002)(396003)(39860400002)(136003)(376002)(230922051799003)(1800799009)(186009)(82310400011)(64100799003)(451199024)(40470700004)(46966006)(36840700001)(7696005)(6666004)(478600001)(83380400001)(16526019)(47076005)(26005)(2616005)(1076003)(336012)(426003)(2906002)(5660300002)(7416002)(41300700001)(54906003)(316002)(70206006)(110136005)(4326008)(8676002)(8936002)(70586007)(82740400003)(36860700001)(36756003)(81166007)(356005)(40460700003)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2023 06:38:36.5433 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6d676607-123c-4106-8bd3-08dbd912d860 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: BL6PEPF0001AB77.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB6319 X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Sun, 29 Oct 2023 23:39:28 -0700 (PDT) Secure TSC enabled guests should not write MSR_IA32_TSC(10H) register as the subsequent TSC value reads are undefined. MSR_IA32_TSC related accesses should not exit to the hypervisor for such guests. Accesses to MSR_IA32_TSC needs special handling in the #VC handler for the guests with Secure TSC enabled. Writes to MSR_IA32_TSC should be ignored, and reads of MSR_IA32_TSC should return the result of the RDTSC instruction. Signed-off-by: Nikunj A Dadhania Reviewed-by: Tom Lendacky --- arch/x86/kernel/sev.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 9468809d02c7..47e2be38a6bc 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -1711,6 +1711,30 @@ static enum es_result vc_handle_msr(struct ghcb *ghcb, struct es_em_ctxt *ctxt) /* Is it a WRMSR? */ exit_info_1 = (ctxt->insn.opcode.bytes[1] == 0x30) ? 1 : 0; + /* + * TSC related accesses should not exit to the hypervisor when a + * guest is executing with SecureTSC enabled, so special handling + * is required for accesses of MSR_IA32_TSC: + * + * Writes: Writing to MSR_IA32_TSC can cause subsequent reads + * of the TSC to return undefined values, so ignore all + * writes. + * Reads: Reads of MSR_IA32_TSC should return the current TSC + * value, use the value returned by RDTSC. + */ + if (regs->cx == MSR_IA32_TSC && cc_platform_has(CC_ATTR_GUEST_SECURE_TSC)) { + u64 tsc; + + if (exit_info_1) + return ES_OK; + + tsc = rdtsc(); + regs->ax = UINT_MAX & tsc; + regs->dx = UINT_MAX & (tsc >> 32); + + return ES_OK; + } + ghcb_set_rcx(ghcb, regs->cx); if (exit_info_1) { ghcb_set_rax(ghcb, regs->ax); -- 2.34.1