Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2618719rdg; Mon, 16 Oct 2023 09:32:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHD/zvKayTJXS93EAwPERzBynbgBegh1FkTfkmd7HRHRGArccMO6tF2vlHXHfGV9eMk979H X-Received: by 2002:a17:903:2342:b0:1ca:7a4c:8356 with SMTP id c2-20020a170903234200b001ca7a4c8356mr4269493plh.27.1697473963187; Mon, 16 Oct 2023 09:32:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697473963; cv=none; d=google.com; s=arc-20160816; b=OccSDPRfGGE/OlMha6o7trsoP6STbvg5ZJIeYXtSSl3D+HbEFo3Wxq6z+WgCxYegK6 eiAgP9CKghbLAc5iWMF/m9U69DHTn7sDnAeASWZbkcxFtiXcItzDxjxNvkh0XAUX+PLD K+Su5dr0adz70A5nhaoAoTylpeg3UdCFjL0SWrO9iR0pc9K+beILyDgnB4TPkSHoYdcR H9shbepcF22b2zegZv0ygKjvwflu2jg/slEg3Nn1g3AoqRlCpqjDve68qJTZ6YeGpnfv YCXqHUXbiiA5cv+XLYh66HMHBZD18njnlbiw+K1RPmQrkf9nAxB/5bD4zRWi7lbA0LJ0 bQJA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vOhaVHFalwQqZbJ3zzjOFwuL8kn4J7FtqSbQl5dOTNs=; fh=lRdU2Q/1zx5DcPdZuWBjshA5VT5Oc9cEhB1tCFiV0Nw=; b=qrOognIeoso5/R2HXSFn4R0p4vHQF/FDX7Ugw/7UIbGMFjtSi2qrbQYfjGcGWlQgXj TvfTRlIhPNKtTtqo8XxA2mhQbmc1/MzoU1jYp0GL6L1b3jaNW4d4RzH5bcaZp6saluX3 OxQK4i09k4zp7ugGlr9Pw6RqghTyGrlWTPOomibunnPz7VFewh7GaAcn5XMFp7JQVJFw Ed3vIdXUBsEkEM4Yn/0JQab6nsBKNKA/IfjPJP/ybPQ7LNxvpyBe03Br5tPQ8Ue/0sTF 0vp5Rd2NcIb6hfxW5KuVGAWUyGnwIP8Q26gEnx4d0PaPqunDx4OKxDcgIx25SgRUEmWO 1pHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MLpe1YUr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id k1-20020a170902c40100b001b8b4330585si12111989plk.510.2023.10.16.09.32.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 09:32:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MLpe1YUr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id E1F5E8022B5A; Mon, 16 Oct 2023 09:32:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234173AbjJPQcM (ORCPT + 99 others); Mon, 16 Oct 2023 12:32:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234178AbjJPQbX (ORCPT ); Mon, 16 Oct 2023 12:31:23 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 163406FB1; Mon, 16 Oct 2023 09:22:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697473352; x=1729009352; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Rqe8JWmQL7lWy7/1ccjjeL1rxw1w6oaAJODRl4a2koI=; b=MLpe1YUrZoloJ/gZC5XyJ/a8x4S5f5EA4hDUuzxXKFfRkET2v3vFLcxe /O620G1KqxJ7KTZk5o14rgzUl1UU7nzqULCFkyYMIW+I5iH7vd/gpHq9k 7u+u4fLCsWl2ZJz8HhhqtS3hJm/Np9U496hjAuZVuzGo5gvOgwsNBe17d 7Wi0ZpA9l7rE2FO0ORVfT7ZQBwbtvykYdyc7J8W+AZt8pL+bnTRkNY/qx ach4dCLE6jSoxC79Eebo8R5kLBpbrE6EaKMkfuRx8s+mkaB6+rQATJcIZ 5T3azRui4xhBF5fJJtR4k9FiKbrwJlAYsEljrKbCz6SuuO/HqJFACbGnL Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="364922132" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="364922132" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:16:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="1003006472" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="1003006472" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:16:10 -0700 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , David Matlack , Kai Huang , Zhi Wang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v16 106/116] KVM: TDX: Add methods to ignore accesses to TSC Date: Mon, 16 Oct 2023 09:14:58 -0700 Message-Id: <056718e01e4f0aaaa27b7fab89422381a9f04a72.1697471314.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 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 fry.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 (fry.vger.email [0.0.0.0]); Mon, 16 Oct 2023 09:32:36 -0700 (PDT) From: Isaku Yamahata TDX protects TDX guest TSC state from VMM. Implement access methods to ignore guest TSC. Signed-off-by: Isaku Yamahata --- arch/x86/kvm/vmx/main.c | 44 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c index eb02a73f3bb0..d5ee4069f684 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -843,6 +843,42 @@ static u8 vt_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio) return vmx_get_mt_mask(vcpu, gfn, is_mmio); } +static u64 vt_get_l2_tsc_offset(struct kvm_vcpu *vcpu) +{ + /* TDX doesn't support L2 guest at the moment. */ + if (KVM_BUG_ON(is_td_vcpu(vcpu), vcpu->kvm)) + return 0; + + return vmx_get_l2_tsc_offset(vcpu); +} + +static u64 vt_get_l2_tsc_multiplier(struct kvm_vcpu *vcpu) +{ + /* TDX doesn't support L2 guest at the moment. */ + if (KVM_BUG_ON(is_td_vcpu(vcpu), vcpu->kvm)) + return 0; + + return vmx_get_l2_tsc_multiplier(vcpu); +} + +static void vt_write_tsc_offset(struct kvm_vcpu *vcpu) +{ + /* In TDX, tsc offset can't be changed. */ + if (is_td_vcpu(vcpu)) + return; + + vmx_write_tsc_offset(vcpu); +} + +static void vt_write_tsc_multiplier(struct kvm_vcpu *vcpu) +{ + /* In TDX, tsc multiplier can't be changed. */ + if (is_td_vcpu(vcpu)) + return; + + vmx_write_tsc_multiplier(vcpu); +} + static void vt_update_cpu_dirty_logging(struct kvm_vcpu *vcpu) { if (KVM_BUG_ON(is_td_vcpu(vcpu), vcpu->kvm)) @@ -1000,10 +1036,10 @@ struct kvm_x86_ops vt_x86_ops __initdata = { .has_wbinvd_exit = cpu_has_vmx_wbinvd_exit, - .get_l2_tsc_offset = vmx_get_l2_tsc_offset, - .get_l2_tsc_multiplier = vmx_get_l2_tsc_multiplier, - .write_tsc_offset = vmx_write_tsc_offset, - .write_tsc_multiplier = vmx_write_tsc_multiplier, + .get_l2_tsc_offset = vt_get_l2_tsc_offset, + .get_l2_tsc_multiplier = vt_get_l2_tsc_multiplier, + .write_tsc_offset = vt_write_tsc_offset, + .write_tsc_multiplier = vt_write_tsc_multiplier, .load_mmu_pgd = vt_load_mmu_pgd, -- 2.25.1