Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp385630rwb; Tue, 25 Jul 2023 17:52:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlFF+qZbL2v+K65lroevQ75hIrA4PqgZ3JVV/6e2ZDkgqUvqEFcktNFb+0oh5vIIzD5u5Oxu X-Received: by 2002:a17:902:b708:b0:1bb:85cd:9190 with SMTP id d8-20020a170902b70800b001bb85cd9190mr676108pls.18.1690332751083; Tue, 25 Jul 2023 17:52:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690332751; cv=none; d=google.com; s=arc-20160816; b=VDhBZ+89ZULWYmTTBnJTZe2ktxxD3ogEkAGemakm49sa5/KGlcJibzfdlbu2n1M4F3 nwPxHnkfiigKefes9MisiXZw/Ahlqjf7nvcUCQfYpE8w80dwrDupbH/1TfxY3nSg0XPe UNZv5rFZ/j5d+G9p5R88XNrgQodTnD6ZUHYnAawKgyrOdmb1Nxf956dWV27zZL/HyfFB u6AIUoyvvlTH7t1Hl+t/jYMU4p29koDSo7+dBc6uF1ACzM9/DJEu26b6TxMRKIFRzsJA wgIIGR+wAUqXsz3nhnmRNPuvSm1JwGbryX5uOZfP8Mx98hOcB646T7fKrGIumCcwBztd B2hw== 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=Juu2wF7JzcLbg8kFyDmmTDPCbI4ZppI2LC+2kilf2xw=; fh=juxwNcA6iKwLISFgUCNwdoIYC0NKLUseq3xZdq25RR4=; b=irjK/SM/O/f+aNVBzRaOcatuhF5fWF2UMljo/1HNfyXNnOwQSEPCIjcMn84v+cqkRY epyPWrdomiug8Y2dcQoDEUIM5wokq26cZxrtQ6TvRhdwzoBXjja/GgqUVlg5UTFLTe/i G8C7wCrelLjQbjdqYTDoJrYcT/BsVvnvYVgMqhXC30Mi3dFcU/cC7OLtZBfCdomLbkBl X0OL6oo9yC+ZGU8fJzfCZWvedBW5cCkC6gNsYcoj3tQvqmyWTNwGWtO4b9GjAPkNXLOQ nm8sMxuWdt5DN4WN0dmBZKQa9hFaKjNE590rFfn9ATsMfXmM/mwA2n8di6ry5qkVPEYU EV4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Yrmuos0Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l20-20020a170903005400b001b9c34985e1si11739822pla.497.2023.07.25.17.52.06; Tue, 25 Jul 2023 17:52:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Yrmuos0Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233169AbjGYW0b (ORCPT + 99 others); Tue, 25 Jul 2023 18:26:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233244AbjGYWXk (ORCPT ); Tue, 25 Jul 2023 18:23:40 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A3C33A9E; Tue, 25 Jul 2023 15:19:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690323545; x=1721859545; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cKuLNRzp3wBlzce5fueNwYUzg7I0dNiO3o6pLEg3h/k=; b=Yrmuos0Z1W2EJesqfM/x6E4MovYMAXcYlsjJvLT7doRcNQ7ro2o1lZdQ tc47Sk6JJ+41aRM7ndjeymJnmrG88CKFAjTUcCvKNeP/zqmU4lOTcKOUT Qwwzq5Ed4aZBCYEwyBqZZveJ5G+PUH8Q+e14Pf6q55Jzomm3L+s75DOS/ 0aaZPmacDehNYBJrrhE2Fy3YaeX/0+Cy9zzWv9OHgg83dBFLDfySGwqjl bCeNRQrqDYRtczNelf4rdeZH5cHJebtbDLrDm4yG2OtnrqsPviIr9ZOyn rCemAtstJIdER78OWE+FpQy5rzyFgeuhzsaRZmSAlV5D3Z3eSjdOhOZqH w==; X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="367882769" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="367882769" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:16:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10782"; a="840001957" X-IronPort-AV: E=Sophos;i="6.01,231,1684825200"; d="scan'208";a="840001957" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jul 2023 15:16:09 -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 v15 107/115] KVM: TDX: Add methods to ignore accesses to TSC Date: Tue, 25 Jul 2023 15:14:58 -0700 Message-Id: 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=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 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 c2ad9c734376..ad74900bbc56 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -827,6 +827,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, u64 offset) +{ + /* In TDX, tsc offset can't be changed. */ + if (is_td_vcpu(vcpu)) + return; + + vmx_write_tsc_offset(vcpu, offset); +} + +static void vt_write_tsc_multiplier(struct kvm_vcpu *vcpu, u64 multiplier) +{ + /* In TDX, tsc multiplier can't be changed. */ + if (is_td_vcpu(vcpu)) + return; + + vmx_write_tsc_multiplier(vcpu, multiplier); +} + static void vt_update_cpu_dirty_logging(struct kvm_vcpu *vcpu) { if (KVM_BUG_ON(is_td_vcpu(vcpu), vcpu->kvm)) @@ -983,10 +1019,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