Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1018879ybe; Wed, 4 Sep 2019 11:13:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvwkozlQG15+bHgMDRSf8tVeEPJ7f4mFTglCjLhvCVnuekLZ/CGAky/iAX87RVzwIqzM2J X-Received: by 2002:a63:524f:: with SMTP id s15mr34329123pgl.2.1567620817540; Wed, 04 Sep 2019 11:13:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620817; cv=none; d=google.com; s=arc-20160816; b=qdcUJXwjAcvgOA3EqqJVHpS7+vRBTkSWE89ZhLI843fKBdw1LtbPnbpofmtBL5GRO/ xslyDRUHAfvOTFI/9NE/CKuyuV2wOiygISr8ZVkafBnIrqq49XvJomogzCgo3XTBshkr j1LZGWdVcqZ79ki9ddATnQ95sq36l4rceONudHH6AW9tR42cXzu2AFgE32hGB8u7YeI/ m6m06uuvB3Q26Dk71MG61zp3qLNB9p+TDQIllkZM6ZlxXLIqGuSahnMzkwLsE2REZUQj xgL4gc4xpcCA5rOv44xrVLmFLcULcozoMmVplTFFiQU2HM8JaQctxZ2Q9A2XOXa2BPsz LNXg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pQcI6PFrlo6Bo7ww6K67/QQ6sCjHwkevarO8xncrULk=; b=o7MH4CMPplG/NjDQ/Gh8eQGKvPhJRewsq3WZ+MXyOuaVOyeCxlCy9VNjVtzba1XwNo jc3LNoxlaqKbfWc79o1ARRFuBm1Px/i7Hnuaw9N+pFYDtoHdnPfM9yl43ZIB103BzsMD te3RF2kFxzsdD3WOenAgWgXF3OCb55DexViI4YmUKCO5mc1k2MZDW00lBgn7+iJ1m6D+ sV4CHIbuHiTLi9ll6RQdWvyxVKcDqyLXBm4C6VOShseRUllM/7FAc5E+0EH4UgIfyh3T /oVfQZIVq364F2AuKIjcvrn6phMCvYtNSk1kOnSDRfwEZAHdnu2ALLvp2dJBRaFe/TxS P33g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zj9LpLe7; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w1si236677plq.205.2019.09.04.11.13.21; Wed, 04 Sep 2019 11:13:37 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=zj9LpLe7; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389991AbfIDSLz (ORCPT + 99 others); Wed, 4 Sep 2019 14:11:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:56078 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389206AbfIDSLy (ORCPT ); Wed, 4 Sep 2019 14:11:54 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 872812087E; Wed, 4 Sep 2019 18:11:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620713; bh=BpPuqPHxIOMgt89UJ/TXoIb3kBwQeVR8aQkQ6MGWwbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zj9LpLe72WoLGGM/ki3T/dQwOlucyfj0QZnwH312OJjkAFB1PNdT7LBRQ0LsiEIQu XKtUw5Is5NutdtvVDwAc+ZOQueCFg9pR8jHSvrQt1c4tZsP7P+1Iwz0h+DgqQzJuXW UE3A/RWPThRCBOUh5Ufm3L5bxKwtwShL/BEz7+OE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vitaly Kuznetsov , Jim Mattson , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PATCH 5.2 068/143] KVM: x86: hyper-v: dont crash on KVM_GET_SUPPORTED_HV_CPUID when kvm_intel.nested is disabled Date: Wed, 4 Sep 2019 19:53:31 +0200 Message-Id: <20190904175316.724705875@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vitaly Kuznetsov commit ea1529873ab18c204688cf31746df851c098cbea upstream. If kvm_intel is loaded with nested=0 parameter an attempt to perform KVM_GET_SUPPORTED_HV_CPUID results in OOPS as nested_get_evmcs_version hook in kvm_x86_ops is NULL (we assign it in nested_vmx_hardware_setup() and this only happens in case nested is enabled). Check that kvm_x86_ops->nested_get_evmcs_version is not NULL before calling it. With this, we can remove the stub from svm as it is no longer needed. Cc: Fixes: e2e871ab2f02 ("x86/kvm/hyper-v: Introduce nested_get_evmcs_version() helper") Signed-off-by: Vitaly Kuznetsov Reviewed-by: Jim Mattson Signed-off-by: Radim Krčmář Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/hyperv.c | 5 ++++- arch/x86/kvm/svm.c | 8 +------- arch/x86/kvm/vmx/vmx.c | 1 + 3 files changed, 6 insertions(+), 8 deletions(-) --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -1783,7 +1783,7 @@ int kvm_vm_ioctl_hv_eventfd(struct kvm * int kvm_vcpu_ioctl_get_hv_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid, struct kvm_cpuid_entry2 __user *entries) { - uint16_t evmcs_ver = kvm_x86_ops->nested_get_evmcs_version(vcpu); + uint16_t evmcs_ver = 0; struct kvm_cpuid_entry2 cpuid_entries[] = { { .function = HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS }, { .function = HYPERV_CPUID_INTERFACE }, @@ -1795,6 +1795,9 @@ int kvm_vcpu_ioctl_get_hv_cpuid(struct k }; int i, nent = ARRAY_SIZE(cpuid_entries); + if (kvm_x86_ops->nested_get_evmcs_version) + evmcs_ver = kvm_x86_ops->nested_get_evmcs_version(vcpu); + /* Skip NESTED_FEATURES if eVMCS is not supported */ if (!evmcs_ver) --nent; --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -7107,12 +7107,6 @@ failed: 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) { @@ -7283,7 +7277,7 @@ static struct kvm_x86_ops svm_x86_ops __ .mem_enc_unreg_region = svm_unregister_enc_region, .nested_enable_evmcs = nested_enable_evmcs, - .nested_get_evmcs_version = nested_get_evmcs_version, + .nested_get_evmcs_version = NULL, .need_emulation_on_page_fault = svm_need_emulation_on_page_fault, }; --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7733,6 +7733,7 @@ static struct kvm_x86_ops vmx_x86_ops __ .set_nested_state = NULL, .get_vmcs12_pages = NULL, .nested_enable_evmcs = NULL, + .nested_get_evmcs_version = NULL, .need_emulation_on_page_fault = vmx_need_emulation_on_page_fault, };