Received: by 2002:a05:6358:795:b0:dc:4c66:fc3e with SMTP id n21csp1450012rwj; Sun, 30 Oct 2022 00:34:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4aoKgNccJNDfnWLs/3MzLNg95I7ahRSTmJjH2/0/LwsIK+3GG+j/oAT5Ynx4nfKifjpfHd X-Received: by 2002:a17:907:a047:b0:7ac:ff72:977c with SMTP id gz7-20020a170907a04700b007acff72977cmr7259910ejc.260.1667115244779; Sun, 30 Oct 2022 00:34:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667115244; cv=none; d=google.com; s=arc-20160816; b=nEfx2bw714295Pyj7X541roSsM0LFIg7rqdQY6O5LeAh+D0z7mSdhGXsb0bAKuqIQs Ho1Q+nwSnFyr3Wi924ZqZi1wo0VQApLWsX7lPYytEzqlquT8AK5GDhz5KaNisjUHAJ+P SYq/QrnePC3L80tlzWVYa9dbXI97kPs2+BNzU8187XwH6sFynHdE1O2Amgo21terPSbB eIFWShO2A3RnqBT1r6YUPx6X6ZOZnVJ92oPjPFHe7JUxN7a1HqZXG3qt3k4lXsQ6UdYN MNdfmEQa1MqHjvicYBKndebYMzzofmt93t/X1uAPi7SHyQWnpZZeAK/DPLwi5bmXBHwY rHSw== 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=HQgxkx/m2vl6aE+FQL3MOlEqoORtlynoJ57yzgn26Ws=; b=BzazHegmoSb8/gotVljLhcn3YfVPQHUo8cCgPTDXgKTjfo9XqBaSsj0PwFFmgSjgdg C13bTjKcowT0dCOlUsskEjaDrNOwuwrfbgZN/4eHFK9MDgsTupvQRISAsZQDzmvO19/E Wa0lJcWE9dzLZV5P9sIwYrctdPWdJzFBV/AqMNPErWvhEH30Fcji4/IHc7gWjuPnhf/W jwNOxDJH7ZkstNBYAYNOiwBohdWgL9aLQs/z1nw6DwlkVyDftfDhkdJ5sEg+dxCQCMUM RNcvTqpTWf9bgpxnFoO+kvnsf6TMTbuXd+jimu2jFeEAFZ8y4ZDAH4sQLDfjREsbCLzk z2NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Hx6r1DF5; 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 h10-20020a0564020e8a00b004570e4887desi3132618eda.437.2022.10.30.00.33.34; Sun, 30 Oct 2022 00:34:04 -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=Hx6r1DF5; 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 S231603AbiJ3GdW (ORCPT + 99 others); Sun, 30 Oct 2022 02:33:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231501AbiJ3GcU (ORCPT ); Sun, 30 Oct 2022 02:32:20 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDEA1BAA; Sat, 29 Oct 2022 23:25:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667111105; x=1698647105; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=39PnIeDQnGG7uhnXgi1UbAsJ6LOJDAraBTB2/rPpwig=; b=Hx6r1DF5mVqcybgSDgispdVZ3vnFwWzy+KPw2CpFnVU/nq8x5HuUnYjE a9r5/s0HA90WO8aa7I7uAg1JxHlN9k5dL0Dh66KKp2xwD4g4P2tue9r7y PnB0tiG8BT4itZDcF0/hoEMRP8xzdIQ3bKLT877LlQdnkRKCieOJZU3SW 7SHJ6Mv+g0UPd7r1zRdENgnVUdQ9KAaTCARIgK3kNHJfeubsEm12uRKl8 bo8bVmxAm7Eb8JqETtkAomeSSx/LinN1c5YQGVzB5rZ3oQ3iej0JpcyEq hrnObqJ09whkv1J7rnZh9T7+nHXGd4Qy8AtEqCgJYgjzCSaXsluSZyrQA Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10515"; a="395037217" X-IronPort-AV: E=Sophos;i="5.95,225,1661842800"; d="scan'208";a="395037217" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2022 23:24:14 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10515"; a="878393159" X-IronPort-AV: E=Sophos;i="5.95,225,1661842800"; d="scan'208";a="878393159" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2022 23:24:14 -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 Subject: [PATCH v10 099/108] KVM: TDX: Handle TDX PV rdmsr/wrmsr hypercall Date: Sat, 29 Oct 2022 23:23:40 -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=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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 b820475ce0ab..e3062c245e70 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -1033,6 +1033,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)) @@ -1047,6 +1082,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