Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2619642rdg; Mon, 16 Oct 2023 09:34:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGVg/d3yQEz1G0QotesEI3lxivuoDGcO6q7MLF4LSrhdy9uZnaZwbNhVJz5jl5lROtI4VPO X-Received: by 2002:a17:902:c40a:b0:1c7:5a63:43bb with SMTP id k10-20020a170902c40a00b001c75a6343bbmr40608323plk.8.1697474058146; Mon, 16 Oct 2023 09:34:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697474058; cv=none; d=google.com; s=arc-20160816; b=Tbou4op70NGasgnczO3JUEd4NM3nKOC17lFMga3U76GsQ/gwqeL+HS14vcdE+5GBpm 0v+le0AR8+txP9ydBfmJzKAoA9hj1lnWHOKAgUkRjSJxLyuR3BDu394hjBeaaqfNIP19 Af2cLjLkcQPqQkOQ6rHTRWnlNZAF1XEE36QWSLw9LnXCG7QxvqymHRJVg/rzdAbHaqqJ oyGNr6+9QXvznawlhBX8phTMOOrBIeQA/zDFzbPWKiPWqVU3x+GZiWcEfZvHfP585KPo CHH4C91UVMi3y0ZTqTQOBKLoBkfZL0k7BSAkvO1Dk+5J4QzyOXMCL1Ud6B9X9WJeIjdW llHw== 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=/RlR40d3i0XnRU6CGW/21LlgnUAOU4X+HiuixbECIOc=; fh=lRdU2Q/1zx5DcPdZuWBjshA5VT5Oc9cEhB1tCFiV0Nw=; b=Mnzf7rQb30i+TI9w9IMjR+MRNugRe5C9sqxdhJ2zphxTADdpN8vrepegXdbpEkHDLF jVgHv+n4lIVc0NEVMRWPcQlRexHyHJgKiUX75c5LBAUIk0AQqVQFkJ2DlIgBjpuXW+9E S/IJ4NSUikPhNXW+MiUj9sigGiJ+FkPBc4/ypp7MxKtfih3gL7r1zWPl2VhdoWIpS7CA W4E8MWpzPQNPACvYPCwXn0VDfBk56w6e7r0A1WNkAEjb2aaJ5MMCs4mnMjDYVl1Gt/W8 JNeiHVlKH8ASqKT8Lt26P95xTcaeUbWyb87J6zR5efykOKgr9zMyqO/jUkuhUaWUlKhx 7t9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HMYdNcvb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id f7-20020a17090274c700b001b9ea0f0e25si10618278plt.607.2023.10.16.09.34.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 09:34:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HMYdNcvb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 3C0AF80AF823; Mon, 16 Oct 2023 09:34:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233592AbjJPQco (ORCPT + 99 others); Mon, 16 Oct 2023 12:32:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233969AbjJPQb5 (ORCPT ); Mon, 16 Oct 2023 12:31:57 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F0AD4C2B; Mon, 16 Oct 2023 09:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697473269; x=1729009269; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MyMZbxBs64n/RgUrYgycCLns9IrLs3zX0v4Q/4yMLvc=; b=HMYdNcvbsEucyjr5grnha4ZapufIFim4vZ/V3dmv5Q2rlsuwbmqwwG8h kr5T58LtFuXhhH2p6Lad1mJwK1ylEiq81XtICyschmzaYZ6RGI4r6NC2W sK1TWSNVXcw6n/W0BtbTKgT0PJd+NzF/4Sl/7m1F3FuWly3SVCoMwB5Id KWKCk3yaMScBGHo0fMlRoPetNv/BJy21vw2NYzVXqKWax5PAGjTiL7WVK RYIUM/NEQtoptaLj0vqbIWYsth7hgQjG7BEnrrPXtnBu146JllOK1Pffe AyMSA46jVpsoTqa3dP72b4hObq2Pk7OiR7zRqPn4HCYLcxN9kr3fc9aYC g==; X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="364922073" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="364922073" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:16:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10865"; a="846448326" X-IronPort-AV: E=Sophos;i="6.03,229,1694761200"; d="scan'208";a="846448326" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Oct 2023 09:16:06 -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 096/116] KVM: TDX: Handle TDX PV rdmsr/wrmsr hypercall Date: Mon, 16 Oct 2023 09:14:48 -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=-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 howler.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 (howler.vger.email [0.0.0.0]); Mon, 16 Oct 2023 09:34:09 -0700 (PDT) From: Isaku Yamahata Wire up TDX PV rdmsr/wrmsr hypercall to the KVM backend function. Signed-off-by: Isaku Yamahata Reviewed-by: Paolo Bonzini --- arch/x86/kvm/vmx/tdx.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 7e24683e430b..41f7ad98cab5 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1307,6 +1307,41 @@ static int tdx_emulate_mmio(struct kvm_vcpu *vcpu) return 1; } +static int tdx_emulate_rdmsr(struct kvm_vcpu *vcpu) +{ + u32 index = tdvmcall_a0_read(vcpu); + u64 data; + + if (!kvm_msr_allowed(vcpu, index, KVM_MSR_FILTER_READ) || + kvm_get_msr(vcpu, index, &data)) { + trace_kvm_msr_read_ex(index); + tdvmcall_set_return_code(vcpu, TDG_VP_VMCALL_INVALID_OPERAND); + return 1; + } + trace_kvm_msr_read(index, data); + + tdvmcall_set_return_code(vcpu, TDG_VP_VMCALL_SUCCESS); + tdvmcall_set_return_val(vcpu, data); + return 1; +} + +static int tdx_emulate_wrmsr(struct kvm_vcpu *vcpu) +{ + u32 index = tdvmcall_a0_read(vcpu); + u64 data = tdvmcall_a1_read(vcpu); + + if (!kvm_msr_allowed(vcpu, index, KVM_MSR_FILTER_WRITE) || + kvm_set_msr(vcpu, index, data)) { + trace_kvm_msr_write_ex(index, data); + tdvmcall_set_return_code(vcpu, TDG_VP_VMCALL_INVALID_OPERAND); + return 1; + } + + trace_kvm_msr_write(index, data); + tdvmcall_set_return_code(vcpu, TDG_VP_VMCALL_SUCCESS); + return 1; +} + static int handle_tdvmcall(struct kvm_vcpu *vcpu) { if (tdvmcall_exit_type(vcpu)) @@ -1321,6 +1356,10 @@ static int handle_tdvmcall(struct kvm_vcpu *vcpu) return tdx_emulate_io(vcpu); case EXIT_REASON_EPT_VIOLATION: return tdx_emulate_mmio(vcpu); + case EXIT_REASON_MSR_READ: + return tdx_emulate_rdmsr(vcpu); + case EXIT_REASON_MSR_WRITE: + return tdx_emulate_wrmsr(vcpu); default: break; } -- 2.25.1