Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3891405imu; Mon, 10 Dec 2018 09:24:05 -0800 (PST) X-Google-Smtp-Source: AFSGD/X0bgwttv1iO5YIC8H7vsd1xua1AS0I1zHtyAB8r5fVO/epJj6+705qot/F9mjwkJsxWiES X-Received: by 2002:a62:13c3:: with SMTP id 64mr13095630pft.93.1544462645202; Mon, 10 Dec 2018 09:24:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544462645; cv=none; d=google.com; s=arc-20160816; b=NA8MeU+YEripIwZNHZplp/10u+2ps/V4qcwrjdwXr2Tws58WpDoBOhz/7+UylOaORs sNXuyQVeyo1gc+jrPP4Q6aiWZ1P5SP+NDVBb/9ZSnVkilGJGnY+cq2KG9kCEWlMGGabl E787tcTW9bQGiUTkR5qbfgiesnQsEuiNhwGWfdo0Hkty6ss4eNuFarnvkHdvTDN044nr qQvE7WbkR0eswC906L3HpRaljmFrK3N+z4dlzd5CJy3mF5+ZiXBl9nQGURCf55N5dy46 89gjDtmcjSZVEXsq5o1ApRWpI4/vu6Mj/SCbu1nSNrExdYuYC+O2f/DBS8HLeTS153Ft kWNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=dwSiCct7rYZKtbbF5kAISvRS0VLJOWZhWBbkoofzoNY=; b=TILBLkPfmoYuleVcNQeO0iRPnjlYv+xLKR71dXq4ZsZWEFq9O8BYNbqutvTfP+lsiZ ZJIyT8TdQS9VacKSbIUBeMYUkziOwDbRiVnr7mnTS5Wai98nXJfDwu72TYWaTx1dsJmu sT4XbiFNxkiidfFun5aYAP28cSdiDo1LikMgzSzFK+TqTQLc4uG/c+JN2AV283OjcopT yN4Vs18x2D2ZBELLXn8oKSLZ/JFmBAM0s0ZCRd5XRlR/QzBdAhG8o8PvifpwGEtZeGF5 QjDi+9I0qIq8TWaLHYiYLXiMB7TbvkRm31PqPZswSvHU4naZ8Q8xQgkOqhIPss5wys7D qbPA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u30si9772753pgn.170.2018.12.10.09.23.49; Mon, 10 Dec 2018 09:24:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728887AbeLJRWO (ORCPT + 99 others); Mon, 10 Dec 2018 12:22:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42650 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728935AbeLJRWM (ORCPT ); Mon, 10 Dec 2018 12:22:12 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CED8CC049588; Mon, 10 Dec 2018 17:22:11 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 778F1608EF; Mon, 10 Dec 2018 17:22:09 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , linux-kernel@vger.kernel.org, Roman Kagan , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , x86@kernel.org, "Michael Kelley (EOSG)" , Eduardo Habkost Subject: [PATCH v2 3/7] x86/kvm/hyper-v: Introduce nested_get_evmcs_version() helper Date: Mon, 10 Dec 2018 18:21:55 +0100 Message-Id: <20181210172159.410-4-vkuznets@redhat.com> In-Reply-To: <20181210172159.410-1-vkuznets@redhat.com> References: <20181210172159.410-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 10 Dec 2018 17:22:11 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The upcoming KVM_GET_SUPPORTED_HV_CPUID ioctl will need to return Enlightened VMCS version in HYPERV_CPUID_NESTED_FEATURES.EAX when it was enabled. Signed-off-by: Vitaly Kuznetsov --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm.c | 7 +++++++ arch/x86/kvm/vmx.c | 24 +++++++++++++++++------- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index e1a40e649cdc..184669d48d80 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1185,6 +1185,7 @@ struct kvm_x86_ops { int (*nested_enable_evmcs)(struct kvm_vcpu *vcpu, uint16_t *vmcs_version); + uint16_t (*nested_get_evmcs_version)(struct kvm_vcpu *vcpu); }; struct kvm_arch_async_pf { diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 0e21ccc46792..472f950ccab7 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -7037,6 +7037,12 @@ static int svm_unregister_enc_region(struct kvm *kvm, return ret; } +static uint16_t nested_get_evmcs_version(struct kvm_vcpu *vcpu) +{ + /* Not supported */ + return 0; +} + static int nested_enable_evmcs(struct kvm_vcpu *vcpu, uint16_t *vmcs_version) { @@ -7175,6 +7181,7 @@ static struct kvm_x86_ops svm_x86_ops __ro_after_init = { .mem_enc_unreg_region = svm_unregister_enc_region, .nested_enable_evmcs = nested_enable_evmcs, + .nested_get_evmcs_version = nested_get_evmcs_version, }; static int __init svm_init(void) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 4555077d69ce..f5d865e88095 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -1605,6 +1605,21 @@ static inline void evmcs_sanitize_exec_ctrls(struct vmcs_config *vmcs_conf) {} static inline void evmcs_touch_msr_bitmap(void) {} #endif /* IS_ENABLED(CONFIG_HYPERV) */ +static uint16_t nested_get_evmcs_version(struct kvm_vcpu *vcpu) +{ + struct vcpu_vmx *vmx = to_vmx(vcpu); + /* + * vmcs_version represents the range of supported Enlightened VMCS + * versions: lower 8 bits is the minimal version, higher 8 bits is the + * maximum supported version. KVM supports versions from 1 to + * KVM_EVMCS_VERSION. + */ + if (vmx->nested.enlightened_vmcs_enabled) + return (KVM_EVMCS_VERSION << 8) | 1; + + return 0; +} + static int nested_enable_evmcs(struct kvm_vcpu *vcpu, uint16_t *vmcs_version) { @@ -1616,14 +1631,8 @@ static int nested_enable_evmcs(struct kvm_vcpu *vcpu, vmx->nested.enlightened_vmcs_enabled = true; - /* - * vmcs_version represents the range of supported Enlightened VMCS - * versions: lower 8 bits is the minimal version, higher 8 bits is the - * maximum supported version. KVM supports versions from 1 to - * KVM_EVMCS_VERSION. - */ if (vmcs_version) - *vmcs_version = (KVM_EVMCS_VERSION << 8) | 1; + *vmcs_version = nested_get_evmcs_version(vcpu); vmx->nested.msrs.pinbased_ctls_high &= ~EVMCS1_UNSUPPORTED_PINCTRL; vmx->nested.msrs.entry_ctls_high &= ~EVMCS1_UNSUPPORTED_VMENTRY_CTRL; @@ -15107,6 +15116,7 @@ static struct kvm_x86_ops vmx_x86_ops __ro_after_init = { .enable_smi_window = enable_smi_window, .nested_enable_evmcs = nested_enable_evmcs, + .nested_get_evmcs_version = nested_get_evmcs_version, }; static void vmx_cleanup_l1d_flush(void) -- 2.19.2