Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5745876ybl; Tue, 27 Aug 2019 09:05:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqxAvrrJTX9K05TDMu8vLb+rxI4mC/9V33uIIDPvJjY1Ain6Nb7o9Mszx/FFI+KQFx7Vjtcx X-Received: by 2002:a17:902:d202:: with SMTP id t2mr24868681ply.1.1566921930517; Tue, 27 Aug 2019 09:05:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566921930; cv=none; d=google.com; s=arc-20160816; b=lMQ61zIlKcUNVe/YRvFjkvc2dnZRj/qZf81C6cI+dv5eiM8/YF7sAIXT3mZUBO3B05 rNWUn6ZCnpWRjyAral2xTnpna7nPELssQKUAFTdB4bjowqw4TNdZOhWxNNkvVSfmJkok 54o0ovAVMQkgjcEw8FJUC0BhMEe3HRJEN9RyvVPTTsFlrYiqbNPGPXF9rQsGLvnQxYCU 2t97NUtWoIZI7HCnUg+x+zXJ4HI4HAz5hD454520e4Me+5xGnHsWvLgkv0ddG7UXEFSS 0uflloMpM7CsM6NbxG2+mmdP+xiKLZqPPZucYd7sFXIJMcJmfK7rDT+km5Z+MAowsHsH KJgQ== 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=VhVONP1yOZ9qqPvIKZXfSIL1EWyqy2BDr9yNoXDMCHw=; b=J+ZRnPgVsPcfedDdGp9JJG9Y0o4ST7VbJrAIt0NaAuO60KGahsL6HJLdg6u+k8Q7LU 3pxBBzHS9vDtSxaHDcyz0eYx1p6n+QAkYOM+fFQj0hzUMxTAKEOrDBCDWHyCi9AbUjv0 0ABxioVUaSrH2yKBNElD5LiLuNDEGsreCx1ei1b98oMF7y7SKa0e9GKvz6PLUYkwmXXb 1r0OdsNrCdGL7A1sdj5Aspwa0Pt7o3AQVKjk4dPVu6b8c8CJeDcIBShwKbsWrh5dKl6S AIK7RBqsy0r06NdC7Y/RzLLVAuswn6wsScM77yU/PRkOCr+J9XL78nulFXc8pMqA/YJx xubw== 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 59si13559022plf.400.2019.08.27.09.05.12; Tue, 27 Aug 2019 09:05:30 -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; 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 S1730215AbfH0QEO (ORCPT + 99 others); Tue, 27 Aug 2019 12:04:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18230 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726735AbfH0QEK (ORCPT ); Tue, 27 Aug 2019 12:04:10 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C791A2D6A3E for ; Tue, 27 Aug 2019 16:04:09 +0000 (UTC) Received: by mail-wm1-f70.google.com with SMTP id x13so1247863wmj.9 for ; Tue, 27 Aug 2019 09:04:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VhVONP1yOZ9qqPvIKZXfSIL1EWyqy2BDr9yNoXDMCHw=; b=clnyyfRYCnITAQ884F9lb7w47xsOc18p1owTf4cXEx6jZjQ0CAJQHNyA2GcxxXxSUo zYsjohAZ7v3pxMEeSay6inBxe61TNTEOKU7wye1Yr2NobuSZgRoK6ZFxOiqbeoFbp4jA ntsr7KuzYI5yPVu848NihzqJecDs1JSQSFoSkdLTlN+65fbewd3wzWfjlQjvTC7ulbrd 2e0TwuivL/xrO5Cay9A/5jONAO7aYivdvhsGuHlSq29BEa5V/PiLf7sHZKF2ZGY12oIt arjwJcDJxl2xtkkZt9Cq7qtYmnrDd6b4hpzUmSuNq4j98ISwk9qozXnbJQNg8i6AsJu+ G0mA== X-Gm-Message-State: APjAAAUZwoKE3tfQ/oS8fYVDgjS189fcMw8JTSzuwW3ayjkKx1jt5Ia4 2cBQ6H+dUliHg/voDe+Eh6MQBwaG99ZMnjia0w6pDSBg4dtsJyQv92Nk7G9SBL3WIxv1eg11hIX 3KX95kfMetXCGCqX+dJiyQkf3 X-Received: by 2002:a1c:f110:: with SMTP id p16mr28612681wmh.59.1566921848499; Tue, 27 Aug 2019 09:04:08 -0700 (PDT) X-Received: by 2002:a1c:f110:: with SMTP id p16mr28612666wmh.59.1566921848295; Tue, 27 Aug 2019 09:04:08 -0700 (PDT) Received: from vitty.brq.redhat.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id n8sm13461246wro.89.2019.08.27.09.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2019 09:04:07 -0700 (PDT) From: Vitaly Kuznetsov To: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Joerg Roedel , Jim Mattson , Sean Christopherson , Roman Kagan Subject: [PATCH 1/3] KVM: x86: hyper-v: don't crash on KVM_GET_SUPPORTED_HV_CPUID when kvm_intel.nested is disabled Date: Tue, 27 Aug 2019 18:04:02 +0200 Message-Id: <20190827160404.14098-2-vkuznets@redhat.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190827160404.14098-1-vkuznets@redhat.com> References: <20190827160404.14098-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Fixes: e2e871ab2f02 ("x86/kvm/hyper-v: Introduce nested_get_evmcs_version() helper") Signed-off-by: Vitaly Kuznetsov --- 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(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 58bf61b17431..3f5ad84853fb 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -1785,7 +1785,7 @@ int kvm_vm_ioctl_hv_eventfd(struct kvm *kvm, struct kvm_hyperv_eventfd *args) 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 }, @@ -1797,6 +1797,9 @@ int kvm_vcpu_ioctl_get_hv_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid, }; 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; diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 572c7c4ca974..40175c42f116 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -7122,12 +7122,6 @@ 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) { @@ -7344,7 +7338,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, + .nested_get_evmcs_version = NULL, .need_emulation_on_page_fault = svm_need_emulation_on_page_fault, diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 3c936e7366b9..c81e5210b159 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7812,6 +7812,7 @@ static struct kvm_x86_ops vmx_x86_ops __ro_after_init = { .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, .apic_init_signal_blocked = vmx_apic_init_signal_blocked, }; -- 2.20.1