Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2685072rwd; Sun, 28 May 2023 22:10:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7rSeMsvkRgXzl3dmq7O7HULH3+/JrWQIndkk7K/EVsyDQ7jYJ/80aaMDevYLcXTa4T3bsT X-Received: by 2002:a17:902:7147:b0:1af:f668:e323 with SMTP id u7-20020a170902714700b001aff668e323mr7350838plm.10.1685337033816; Sun, 28 May 2023 22:10:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685337033; cv=none; d=google.com; s=arc-20160816; b=K579TPWNmzS1JdOUkQQV5N4gMccd/AVWvfkWWzNdJfq1nEtOF7STZpSNNi+LHCSeNk bT/fUFEVjmuCj3RZbcmrv/2Yw2Wu/as+QMLkICFB1a/nvgEmK9pw91QURahfKa/gUnp/ plsyg8XUkcr4RUfjhmIYN3RC9plQI2NMmYkeXVfL8Yqld6syhyN19M00/8ky7NfhKls0 8wZB57K45Vo4UlXadXlTDPwMwb1Zwjb5nf4K608K35LuFYomitKXUBkPLv9BODG1QvSk TkWh8WJGvZJhuLK7eJaqm8rl3RLWjTouHoseigIyh24VBRR8GNZ2wOx/waI6yMP7XNrs 7dKQ== 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=nbZn9s9lkyLRTKP80fYMlMm30uqDK/xJ3j6EYu5O9zk=; b=aZcMmdgSCES2LFr/Ty3be1+3djuoecioGvjK6W2bDP6DX+NW6QOdi9rtD6H/udu8EJ SIARJI6Y7W9/X0bA5tSmwrraeii7IArLq5N+7IHdQUJCL1nVFP0wI2M5NO8D8ZMa0LKT I0RX02gqWm1hPpV3hFAOcmsYV86WrhlzhouaZOXbcAwUyvNHsd/jEhVFNKC5Ng6ft7CB A66D7QUK6v8Ybjwgg8BHSSAudbdTw4cbJIZnSScnv5lekbjnn9351XJ7XGhH6e4OE4Au 3nxkWeneTWsEKFYtspBDYG4TPJH+MibqXtqWcZkBWch0s267qDeq0m6JW/FZqhltq/Y1 SFmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZXSdMeBP; 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 b5-20020a170902bd4500b001a691f376e8si3648493plx.415.2023.05.28.22.10.20; Sun, 28 May 2023 22:10:33 -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=ZXSdMeBP; 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 S232433AbjE2EaB (ORCPT + 99 others); Mon, 29 May 2023 00:30:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232131AbjE2E2h (ORCPT ); Mon, 29 May 2023 00:28:37 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E5B7172A; Sun, 28 May 2023 21:25: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=1685334308; x=1716870308; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uXPzkWTZlTTquytZPAiT/mSCCQe4Jvh/SGbhcfLu4NA=; b=ZXSdMeBPcZP3XmuSn1mz3az/X8uWLuuRgXdE5rG9butmo8KRXI7E2PLl idOOP3/ZGBINK7x2OfcUIlSRNU+o6o/feaFBWC7vD5Jy95bOZvfRGHMUS JmhJ/AmH78qIKDIXVrlBvi7sZ6qeZQGw5VD3FLeqQuWBI+aJr/qW9hvKL yN8Ux1OGibYxYnuaNzjRPGTbLM3FmBnwhy1Q2er1xa/TF91yCS7QjHVX4 uQIjreOVBLA7+jvyLh8oqhOuF53CxEHRrk1pMKQWrAO4+7YcaUKZYQVo3 PCTWQBSPTG7Os46f5BAIouRuhBW8pwuCawAYP/A7nV1+0AOC66meOwk9v A==; X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="356993450" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="356993450" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:21:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="830223478" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="830223478" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 21:21:42 -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 Subject: [PATCH v14 096/113] KVM: TDX: Handle TDX PV rdmsr/wrmsr hypercall Date: Sun, 28 May 2023 21:20:18 -0700 Message-Id: <7909d856116e9e737d0fbeeb5dfa54849837e780.1685333728.git.isaku.yamahata@intel.com> 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=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index f07c5ba153ec..4a5c7a210dfe 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1205,6 +1205,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)) @@ -1219,6 +1254,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