Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp172287rdb; Mon, 22 Jan 2024 16:19:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGkfFQNUze61ps0XgC2p1g/4b+xGDesOavjm8pj6Lc952XYBX+WXuC86HbDuJFwMKAujeF+ X-Received: by 2002:a17:907:a08d:b0:a30:c3f6:d79b with SMTP id hu13-20020a170907a08d00b00a30c3f6d79bmr7900ejc.103.1705969157066; Mon, 22 Jan 2024 16:19:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705969157; cv=pass; d=google.com; s=arc-20160816; b=KMD3nxjkoKpJVzbCjZY3+Qts5lejKrDsBBdUCIYKa7DhU4GlzZPWc59eUGB36TxVR9 0rvG3uSyRZpiehJgCOLUAhSarJeHBIe7qcojq9cFGWPpE6YOuQRDm2JP+RP2CHymNk4+ 81yBBTiAlqR8Eu3uN7e1S3YhtoHeS2XRfoV0fHIExpSMPzCmFYxBZX5ypbv/H7SWpsdp 6K6X9zH/xvVaeci6ZbVx/x6AAIph/2yQtVY5/ht+iPljLORCQpzm9fP03+NqQCaoLEaf maaHGsg5fOeJkgRslnwRtbZ7wch6mE/ASrvRJe/EMrxWXHqHBSch8BUEcUgrOP2nIGpg kJIA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=kqazyGIpshMXcoC4EMPD2bdC9ppXf2Iqq+4OxfWr1hU=; fh=Itbyk7CEvizIrzGEESCqq3I2tZgG1kc/GkVOa3S7Hsg=; b=lKX3uQuxcr4aB/iHTM2+5tC6t8vN2L8GM/TcQAcPOjqoXhiEF4mMY8MJL24S6P+JZs Csum+nyIvVsIVzN7f+i1320EaODYgqqAzORuzyjkiiiuQ9pwqzKJyq9eux2QcOzh94Jr qYAGBBlgYdvwjpm+vLCbjnZio1IULB1ofLcKESDFZRpDRGUGfrbFB91Ij7jKdKYcA0ND nw3Bvr5CxzeGBvT9pdDJODac8vpmt/V0eoutcWBOMvmBodDVNE6strVxihYP+Bp+FX3o /KQ3XQmQr1/X+SK3NPy/F3vN/fJdTRKrbMNjBIcMXlX/+N9Dc7buUVAdeV7Ahgtk1LAS zuiA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bdeUTAO9; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-34417-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34417-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id q5-20020a170906a08500b00a23619be213si11454889ejy.159.2024.01.22.16.19.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 16:19:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-34417-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=bdeUTAO9; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-34417-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-34417-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CC7981F2102D for ; Tue, 23 Jan 2024 00:19:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 471647FBC0; Mon, 22 Jan 2024 23:56:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="bdeUTAO9" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C43EB7E780; Mon, 22 Jan 2024 23:56:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.55.52.120 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967772; cv=none; b=Cmp1DbIvpPOREQcK1Xt9L3ACZ3HCg8AQVncrQdkvhPK43e49PkH2lt6YleJ+xcdwXeJME1QRCCjyImRB6wj8lhNqMsbb4EBpCYV9OQ4QZkQY4zy9Iv9byotIYAdTRRwX0Gqwsa4BfggCW9NY2rjww3PYObQdR5L37fyqcZZru6c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705967772; c=relaxed/simple; bh=oAY2vBodBoJjRLKa8EO0C+EcU6IOAxDgw153dv5CsIU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tgLTK6iDe3KGnbAow12TXP5GhyiLHIi9pUslMfGvmieznBJm/2xa3tljzvOShQaGxkarp/Z4n2FiJFKe8fa8T7EedBcINU0YuKioYjI9Q0p6Gv9YTa2wP/7lK5yVFtTEw4tWWStzOJed5dDVth1+jLjIA4QFXqShQiey3f/38Y4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=bdeUTAO9; arc=none smtp.client-ip=192.55.52.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705967770; x=1737503770; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oAY2vBodBoJjRLKa8EO0C+EcU6IOAxDgw153dv5CsIU=; b=bdeUTAO9J4XrOlUsGg00cDa7NkneGqhleqY9pJedbr++3ZEv+b2U6pym z6TUDG6VGRL1248RjMOHBA4CYN5D0FzMFqqR+KQot6ybAeVVLbgtPJAsf 1ml6EHVL65VYHs+ciIcMCtKsihraeGEp1KJDP02sVYzpCaQ0DLgr2kGTm 0Ns2W1hcs9S0OQBcR38LKE9eCcQPjfcE/Sz85WxH1LDw/6x79bSU/wjVY wxtT28Q5r0Z92bn+RM9UipLGy93S7dYFz/qjJWwF7La9Z9wWHJPXgE22F /ksZVuRMLf358Cxf4DPbsOiiQW3UibRuWilj/ULaiKLM8DlwJ07rvYIf+ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10961"; a="400217929" X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="400217929" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,212,1701158400"; d="scan'208";a="27818021" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jan 2024 15:55:57 -0800 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 , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com Subject: [PATCH v18 111/121] KVM: TDX: Add methods to ignore accesses to TSC Date: Mon, 22 Jan 2024 15:54:27 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 74e5197733ef..adaf61bb754c 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -847,6 +847,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)) @@ -1004,10 +1040,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