From patchwork Mon Feb 26 08:27:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 206457 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1952101dyb; Mon, 26 Feb 2024 01:10:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU544yGsk0W4pDyrcZTfKeKDeGR06glFyVK2Z2vkoUxNIGHEv2+jziKxGfigvyjpdWW5Iu6PbgHIJA8PX6Io/m+3g6wzg== X-Google-Smtp-Source: AGHT+IHScp5Sy8P+Ivk7NbKDDnyYQTK1sVRRkLZLFGvx0PMNWlI0Ler1/pZ26CIf3VuyTEc8geop X-Received: by 2002:a17:906:b796:b0:a3f:9df3:2a4f with SMTP id dt22-20020a170906b79600b00a3f9df32a4fmr3754344ejb.9.1708938602018; Mon, 26 Feb 2024 01:10:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708938602; cv=pass; d=google.com; s=arc-20160816; b=S6T/W7v2EkmC37sYBD52wNOXJRxo2pOKad8eE/vAHvNTwvr/Rcj6ZdBj3Kt1NsqncU TJ0NM13RTvgBaWLy+dCA/iP5u4VouSQno5uPmSa5j9nX7zwIBX+dFnF6nyZbmhaewfMr gYZZdrXGvYsMif1UP9clpDzW4Ihvp++fKe9wsYkgCAfLMIaf1IzkWaHU8lvtUqHwlPNp QLgIOa+yhv5Kamly+2p/7VPHvUqZucpo5e86AkHVjRRzxoaegS0FBJmULYYHWKqhrLIX RomTtlMwANF3fdSV4YLIP3q7DqckvWmveCJlN2B6fms8EvKj2/buCIW52teXWI6DqTiZ tjKQ== 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=lEAj52DYyC0sA8MxKAcdq3E7EcaPNwv3OLQbnDtAh3Q=; fh=Itbyk7CEvizIrzGEESCqq3I2tZgG1kc/GkVOa3S7Hsg=; b=HHJgK8nhNodvWs5SYM67wdcALn1Bvd6h6iZ7lM1lIprV4cffLPycOgyd2ySfrKEz2d K7vh7SePVvbiyXQ3057PLz65RRXE5ZTTR81LEprcCB+075Pi+JV1f5vqi5Gm4faTc54C UQSNLeS4jd6BZSocHn+ekn6ZqHJPIxLkPXwLe1tsEvXA3piaCX5fhZxQTpd8/r1j3y69 7xZ9dHqDp4pB9RcPKSOAsNtc3xkHziFzvUexl3o44RgItm76vbfFwDIGJ+ID7I1m1TXJ Ap+XrhbS5GGADJepJNrW241ephHYSrEqntpVMZ+fhdGpr2i8CDpNaZlOepz+o81EfPyC G1zA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hSLTQWfo; 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-80887-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80887-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id m1-20020a170906580100b00a4160485d26si1905468ejq.1041.2024.02.26.01.10.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:10:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80887-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hSLTQWfo; 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-80887-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80887-ouuuleilei=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 A321C1F2289D for ; Mon, 26 Feb 2024 09:10:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D09B130E2F; Mon, 26 Feb 2024 08:29:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hSLTQWfo" Received: from mgamail.intel.com (unknown [192.198.163.8]) (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 E591912EBC9; Mon, 26 Feb 2024 08:29:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936159; cv=none; b=SwR0F63Ihq7Yh44armnywC0qpynOCi1xgAM+BSEtSpgCuxw9hBWoew+VeOezOzPydgmJjXXEgo24tlcGGhr+NgshlL6FwPrJHCw7ynI0QH+AKy/Pu1r37p97TfiqPTb7jr4x3pokuIh5GcdPyTW/nEDl/k5vjC7KGNvgDGJ9MGo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708936159; c=relaxed/simple; bh=m7n7i1eS4On2R241lFqJmq0+vkwcQBjfN5ADiMO6W+o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JiuN+Fyf2t/OP9h62xhwW7pBUy55Akea2xDSp/VJfZDF66hxaA1Mf7IqIp9DKhQgC6MsNj8Zn1A3NgWzHdNMDaQKJMTd7Q7hzqj8B7qJ9R83v1UT32rxX+zFvYlLwumxuafbPuDJbS8FGIY2XxQWtOOi62uPP1rdD9lAEEzD7Is= 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=hSLTQWfo; arc=none smtp.client-ip=192.198.163.8 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=1708936157; x=1740472157; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m7n7i1eS4On2R241lFqJmq0+vkwcQBjfN5ADiMO6W+o=; b=hSLTQWfojQc90/ad0OUazIBxZqbpipGJT4vsEsZ3pmh5yvyf3Twyb8aN XC0kXtFBlrNdQgt0HUKxt/88To1/5Os85T3O8EhAZLbTbyTzGk7entFAC OgVbu1Cxk0QYcvRLMma6OYBFiLstzpVYAOibZU8m1gQTDYQp0575mUkIL CpZc9plHOR2oFxLWRwbsfXfrQX96rw+vrylrYqFLDEmL8nzK3svAdj9Yq Q4/v5ZY0TPjlWlGcx+Zmn0WvwxlRmN6ASZZ4PwDmdsclI1sgUEYiWMxEM IhrKkzpnLNYoJlC2cNmaSsZVm6zzunUtoOSONzm7EcUCfj+yIjXCjJTRE g==; X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="20751396" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="20751396" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:29:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="6735128" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 00:29:10 -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 v19 122/130] KVM: TDX: Add methods to ignore accesses to TSC Date: Mon, 26 Feb 2024 00:27:04 -0800 Message-Id: <59ff42a2dd3769de6127fde30c9b2b355a1a4c17.1708933498.git.isaku.yamahata@intel.com> 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791952003691045323 X-GMAIL-MSGID: 1791952003691045323 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 ec5c0fda92e9..9fcd71999bba 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -834,6 +834,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)) @@ -1022,10 +1058,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,