Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp432572rdb; Fri, 6 Oct 2023 07:46:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEcziy/8wDp5oaGUGq3ioXrMg9FR0zPoFxZI7DaLppNsdxBllEBYcWMUTwVt5NSSbOG1SR8 X-Received: by 2002:a9d:7383:0:b0:6b9:2869:bd81 with SMTP id j3-20020a9d7383000000b006b92869bd81mr8629201otk.18.1696603596945; Fri, 06 Oct 2023 07:46:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696603596; cv=none; d=google.com; s=arc-20160816; b=Xce889ocrBngpAhZB9x1n5Bdy5W/kSAeMCauqqxaNEfqjMSDDGV2fm3rxLC0NqxbuI 16sa9qFx9QqrAF6Le36mq2R0JET2l7hD9E8tvmTKMiqza7u6hu/cqaowUda2QcxBmGyP oXNyaIw4R98LjY/Sp5EydSbSYJBMAg4K2y4QOTM6U92yMzirbmdTP8O1PL0lLA/m14aJ s7YiizL+0iGfFHakMxPeZS2qHTxhISOtgeIS+iIE7rkPU7dAceYPCoKQ/6iAn9C5oDud hWTuu2P01sN6FzPekwxRpZalZwT5oOR2XiUZOyjD2d6Q47JEHuXOzDhNd+Su4U0NSGGG 4/Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=r1cA4t7kiuX0s3hA9gMJup6TaKFqz4i2f9ByuQMs3H0=; fh=CgYuHfdsq0TsCJLzHF0j6zXJU/1ugNWgxwYo+5chsyw=; b=ONKybh5Ij9mxXpViN4r8Yr4OoTYQqjdEJr3Lvjwgnqws37WBNmO3AzGtDLqKnF0L2n XGOxsGD8Bq6yrvRbrD/G4Jaj4uPF15n2TrrTy5ETpYXg3yKqpxfEbqmGsh3v9EN2L2ZZ SguEnjelTLgObrYz72Rc8EPMmEcTXszHVkdVNAJya8+JeKfQtFXFs6B0IoAcf4px8hh7 EdNAAnludtmMBiOs6VK8aMqoCEds3h4BHf8QEX2OSNwSkmtIOJMn8vDa6fYefoNfvy5M NBPqnqiAmWguicMKGKgYcCTN3wQgjiJ5kL5NACb2X6enymsEsbMxQEYL6MpW4Cr3WuMb k5Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Qsxq2BLf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id t10-20020a65608a000000b00578b6e32b5dsi3707691pgu.405.2023.10.06.07.46.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 07:46:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Qsxq2BLf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 3399D80A9F57; Fri, 6 Oct 2023 07:46:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232592AbjJFOqV (ORCPT + 99 others); Fri, 6 Oct 2023 10:46:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232572AbjJFOqT (ORCPT ); Fri, 6 Oct 2023 10:46:19 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF861E4 for ; Fri, 6 Oct 2023 07:46:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696603577; x=1728139577; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=YBcpvjCK4+25iq2YgElEdnQeYkCFUq/UFQ9ZwM6zUaA=; b=Qsxq2BLfkLlM/Jgl9M9VGM2gpGNr4+qx7KjdSIhxUYqGbH2Sx3gf2EWF Y3PgmTjRx+oTShkHti1dFLm7GZAL0L1E6QhiUhu2SXhQpKJda8sGEOvkj bB8LmjAjGm5FrJmPE8stMRBc10PCTGQB7ph1gU2LP5W7oUE1OHgWfsmX9 ZpZFc0nrk+EdcwQOlnpHu4oU/tl5yjojo9HpMARsCLP4zvjq/t3N18dxE kXKw5NvVcA34VID39Xzv+u/VAOfL4IwM9HJLqWDa+JZTEOWKAxbU3fD8R WZd7LkSEOj8tjzL70lo6F3owjU/i9/UcIuBzzCD4wewyrGtb9dFkbrM1F Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10855"; a="363116172" X-IronPort-AV: E=Sophos;i="6.03,204,1694761200"; d="scan'208";a="363116172" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2023 07:46:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10855"; a="1083474099" X-IronPort-AV: E=Sophos;i="6.03,204,1694761200"; d="scan'208";a="1083474099" Received: from kvsudesh-mobl1.gar.corp.intel.com (HELO box.shutemov.name) ([10.251.222.76]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Oct 2023 07:46:12 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id ABA8110A172; Fri, 6 Oct 2023 17:46:09 +0300 (+03) From: "Kirill A. Shutemov" To: Thomas Gleixner , Dave Hansen , Borislav Petkov , Andy Lutomirski Cc: Kuppuswamy Sathyanarayanan , Elena Reshetova , Jun Nakajima , Erdem Aktas , x86@kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Isaku Yamahata , Kai Huang Subject: [PATCHv3] x86/tdx: Mark TSC reliable Date: Fri, 6 Oct 2023 17:45:49 +0300 Message-ID: <20231006144549.2633-1-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Fri, 06 Oct 2023 07:46:34 -0700 (PDT) X-Spam-Level: ** In x86 virtualization environments, including TDX, RDTSC instruction is handled without causing a VM exit, resulting in minimal overhead and jitters. On the other hand, other clock sources (such as HPET, ACPI timer, APIC, etc.) necessitate VM exits to implement, resulting in more fluctuating measurements compared to TSC. Thus, those clock sources are not effective for calibrating TSC. The host TSC is invariant on platforms where TDX is available. In TD guests, TSC is virtualized by the TDX module, which ensures: - Virtual TSC is monotonously incrementing for any single VCPU; - Virtual TSC values are consistent among all the TD’s VCPUs at the level supported by the CPU: + VMM is required to set the same TSC_ADJUST; + VMM must not modify from initial value of TSC_ADJUST before SEAMCALL; - The frequency is determined by TD configuration: + Virtual TSC frequency is specified by VMM on TDH.MNG.INIT; + Virtual TSC starts counting from 0 at TDH.MNG.INIT; Reliable TSC is architectural guarantee for the TDX platform and it must work for any sane TDX implementation. Use TSC as the only reliable clock source in TD guests, bypassing unstable calibration. Signed-off-by: Kirill A. Shutemov Reviewed-by: Kuppuswamy Sathyanarayanan Reviewed-by: Erdem Aktas Reviewed-by: Isaku Yamahata Acked-by: Kai Huang --- v3: - More details in the commit message; - Add Reviewed-bys and Acked-by; arch/x86/coco/tdx/tdx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c index 3e6dbd2199cf..2f27ae1e2c6b 100644 --- a/arch/x86/coco/tdx/tdx.c +++ b/arch/x86/coco/tdx/tdx.c @@ -816,6 +816,9 @@ void __init tdx_early_init(void) setup_force_cpu_cap(X86_FEATURE_TDX_GUEST); + /* TSC is the only reliable clock in TDX guest */ + setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE); + cc_vendor = CC_VENDOR_INTEL; tdx_parse_tdinfo(&cc_mask); cc_set_mask(cc_mask); -- 2.41.0