Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3457955rwb; Fri, 30 Sep 2022 04:02:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6CDWsHEMgEbzSfO8w2FinKYVQZK0u2u1j+Rv5Z1quehC9M3DVU+3jq54NB82yuaqrHmbGr X-Received: by 2002:a17:902:7ed6:b0:178:378a:ebbf with SMTP id p22-20020a1709027ed600b00178378aebbfmr8405977plb.117.1664535754292; Fri, 30 Sep 2022 04:02:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664535754; cv=none; d=google.com; s=arc-20160816; b=WR/MK3SiFV5sssOEXNbAidRrPLh2WCWOzMDpmGk3jxGXIr2MIOuAiUyZ+qWIhUIAhn 5tMfMQTGavshSZtaOC1wBVmM3Jt1SmICqpjnBg67DyQgeTANTwwJVIGFOzzit47x/5LX hbCRelyHrWsMj2vbghByZ9YPU4vacbah+2rojiNIwfDzNJ12Xg5fKKPcBW1DvbLNlIA4 En0VXUSzMN9xCaGZ7YQ4N2ONwSEWf17K/si4M44PHrtZpatqXu31YWvw3ymL25Xq5PVj ElpDKv3ypZKwEfiMhFoblGKRKVPVAA6wdaEKG9uwRGYbxhGFXTr+t6QIcVIgFx0gpque MI9w== 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=3hky9cUezTLoCgVpaamoFNWvKNKOsjPjw0y42obXrpQ=; b=POh7mQt/RQHLn4NGmQlfSHSjoJol6QV9iLDtyBACZspR2Uubef/YPFPL5NjrXblO4c /yrD20759n+1LJ0At16yGY7jTDt3VXPiWfbP/5QY7KDlyQKM3idvqnQpzbiySRWQFbOy /RvhsVAZGrtUCYSWF9F3l9nEmd4J1rqeMxffoixnjaIsMko5nzrGt+tXKxTlZ6Hd9BMd sZLJsox0Hg3EhFTXCtMIEb2EATgvep0HT1PwW8jMuloygYNIkBBUbq6fbrv94qoQMbVM YMyUhTM9HZTTWT+7///4XO7JNpqHH+6jv7l3E8azVyQqptl7ObQsTPSIShsDrLSI+fvS R3WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IQ8FEhXB; 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 q194-20020a632acb000000b00434c2c0a834si2414715pgq.734.2022.09.30.04.02.18; Fri, 30 Sep 2022 04:02:34 -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=IQ8FEhXB; 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 S232665AbiI3K1O (ORCPT + 99 others); Fri, 30 Sep 2022 06:27:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232375AbiI3KXl (ORCPT ); Fri, 30 Sep 2022 06:23:41 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 967D51DF11; Fri, 30 Sep 2022 03:19:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664533188; x=1696069188; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=D67l/HHFxfKH6r8PtuMSvx6zUANhihvOPiWPfIrfNOQ=; b=IQ8FEhXBgUWGQDoB1BVM0DMHfbe089Or7OMWLN9rPAMql59ijLs2QMu1 yiwzSgO1Iw7oJts1Cbp67PkCv9LOThLnMnzDKEX8FdER90LiY8Y0Br5Xw /CKyJZK4gJsYEUI+nIelMez7b/ytrj/sRYEc09dzNXOAi2aqZk1Do+gAI jNMtcoiXQ2tHpx4D98uM1p02OHqHvBr6Wwnjb4CzHSC+Iob90LcW2c30t AIksxdsG0ULG6+4UqDJf3LOaSxQ9M/xcRw8cNzQ8xoeGOaW9wEeOZLgKt rotH648gtjbvlmuY0KTBK11TeC2yTCaixRWBpG7nNYheucn4KAgQ75xt3 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="328540176" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="328540176" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 03:19:07 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10485"; a="726807819" X-IronPort-AV: E=Sophos;i="5.93,358,1654585200"; d="scan'208";a="726807819" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2022 03:19:07 -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 Subject: [PATCH v9 096/105] KVM: TDX: Handle TDX PV rdmsr/wrmsr hypercall Date: Fri, 30 Sep 2022 03:18:30 -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=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE 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 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 86bde12c7818..6cf18eca654a 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1025,6 +1025,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)) @@ -1039,6 +1074,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