Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp3402534iog; Mon, 27 Jun 2022 15:34:16 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uF4kOjtBRHsHmlJj1GsUDeXP8UdHLfttv/1WTNUlCOQVbrKsDflWBID7TEGgeXRC8o3qLY X-Received: by 2002:a17:907:7f28:b0:726:2b19:a366 with SMTP id qf40-20020a1709077f2800b007262b19a366mr14763880ejc.372.1656369255784; Mon, 27 Jun 2022 15:34:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656369255; cv=none; d=google.com; s=arc-20160816; b=iNKLCspLNzm7J2OH2Fy7FjNKSqmrwCZNmtEdf1qVDnhaSybaEX1DE7nLMt3cnjgej8 JwY/WQlL02TtLxXIYzXg6FoIKxNjcgZ7EbgH32ETGD3ozhIT877pAKc5VXWrLPqSQtyE DpU8hGVNTi4PRbQ2WsECX0vDbiV3x1t0ZsjMXCz2G4VjXTBQMOlR0b37aYNUnGYns9AA DXubuERiQwtqukZm9YBr8iLgYsJv4JXvS3yQqF9GyLEdD2vMmjnDOa1E41P109GcDx1D 8THBOJMlO+L3L8rCu3Ba27hArTYJflKvhUirSoU3k6BCtyjIAF0TGZ6xP3dGQbJHBx0e plhg== 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=idWh2CEQoPBHJnDuPN42+frCmBnlTcxLDiGYIJjGaDM=; b=R1NEERuLDW8ZVw6c3XdYdSOSIgF62BaIpki2ZcP8pVy9sQMuGLhVQq2zWCCqw0J2Wr fPoI6cl6npmSGcrwixAvRVMLj6/OLzgB3lFh0ae4Ds+cwewO6km3t7j/VI23pjiCb6GV uLxbUtM1KeZm/GBbNPxJ+E1g8Nqtl+Ebp0fWypHqVEkMIzY0LqUjdejGupVbsn+qCfnV 5/0gFW+BtMOugXD9TvS3UC5TgR4RqR8CKA7R7etYJHxBoCbGzSpfg2J8QrRAVjkEHdtc xEqCSldpm7wUHnMgKuxLUKASD4IPBmYLEnxGzHbuwojexGjeUVCKWJOsrc9+VEPD1dEg ZZGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="VcSf/qjU"; 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 co6-20020a0564020c0600b004357dec2beasi13186744edb.73.2022.06.27.15.33.50; Mon, 27 Jun 2022 15:34:15 -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="VcSf/qjU"; 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 S241880AbiF0WBp (ORCPT + 99 others); Mon, 27 Jun 2022 18:01:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241242AbiF0Vzv (ORCPT ); Mon, 27 Jun 2022 17:55:51 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD68817E24; Mon, 27 Jun 2022 14:55:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656366908; x=1687902908; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jSrS5oiO5IBfcWPeUPov/rhPiMcio5Bnjv4uVfJnZGA=; b=VcSf/qjU4gyyQMbNfemE1cBHr9L8fIQCwowxsAbXEzQiAdAoOylDJgiv VduJLCVBEg3FEjoJ2mY+gT9+5yEUCFrUgLJ0DKUG7EKpHdEc7k0UIuGSG LFjKVnuT2ByW7yWQGZsAaWX6L+ln81aEsdVfGsV84XsLHTzOXfzhqJWwd Tn+8AFTfgSYk2kPOsV0DRyHd3GuxrTYojkeXDKXvDABSCC+iBClq7iFUo 2/WWuf2AnRNt01XvHXXugCWiUz9p9U4oVgn1zh4kDWLGQ4lk4eXpr2wGu 6AJlINB9ziBaGVSIc/w9AeoeRXApY9KrWWg8TMjSROcm/aIoEjHmBzSyh g==; X-IronPort-AV: E=McAfee;i="6400,9594,10391"; a="279116146" X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="279116146" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:55:02 -0700 X-IronPort-AV: E=Sophos;i="5.92,227,1650956400"; d="scan'208";a="657863750" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jun 2022 14:55:02 -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 Subject: [PATCH v7 094/102] KVM: TDX: Handle TDX PV rdmsr/wrmsr hypercall Date: Mon, 27 Jun 2022 14:54:26 -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.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 162cab67d1ef..dc66c799cae8 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1170,6 +1170,39 @@ 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_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_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)) @@ -1184,6 +1217,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