From patchwork Fri Oct 6 14:45:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 149282 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp382076vqo; Fri, 6 Oct 2023 07:46:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG0LYDIFgJq3oSEJvJBcc02FyIkwFhXopMAk7eXCu+/EAZIGkHL4B+Aca8UbecA/eRCKV0o X-Received: by 2002:a05:6358:9042:b0:142:efb8:5295 with SMTP id f2-20020a056358904200b00142efb85295mr10274203rwf.19.1696603605816; Fri, 06 Oct 2023 07:46:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696603605; cv=none; d=google.com; s=arc-20160816; b=UrcJdKH37HQvROPh5yv4+3SJdkEpiKlGmfagQ0bVxV0gU56uVLIi1y3p7n35eH1iSZ vs5OUL9PyVfZb/H17pGkDc7vWwFHV52M0I3DSgki0scR2YV3j03DXb801mVrKdDmohQZ gUtkY0QgP9N+qd6LLoOAT1iyMu1yVTODtXXfMT0bsDivJNsni3yjEExVt6273qxpFmnp r9QEazxmq7TSqW6vKj517+iXoSM7NqAhuc9qHJx+BMGu2QT+4NiffINyssn8Nyaccs5H mxfqFx0631AYTXa1NFCAwwOM3pi0FK+LEsBFWpqYW8VET5gOj5gsHCY7fwAvxLA9g0bp 2PZg== 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 Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id cp18-20020a056a00349200b00690d25b1988si1582667pfb.30.2023.10.06.07.46.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 07:46:45 -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 8D16980293EB; Fri, 6 Oct 2023 07:46:43 -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 S232560AbjJFOqV (ORCPT + 18 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 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:43 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779017822532672653 X-GMAIL-MSGID: 1779017822532672653 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);