Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp538918ybz; Wed, 22 Apr 2020 03:15:25 -0700 (PDT) X-Google-Smtp-Source: APiQypJCQbgzqFwU1TMlZsyzr6g32vGw8O3oS3AduRebTyE9+vyJ2+cTEFbXHY4SJqPseIFHqVza X-Received: by 2002:aa7:c608:: with SMTP id h8mr13823296edq.232.1587550525799; Wed, 22 Apr 2020 03:15:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587550525; cv=none; d=google.com; s=arc-20160816; b=y7mwhyU89gSwrf2sa05BXxG4BimmDkUxoPpRJZEgEWPA4iB972wi/Fnmzj2Zz8U+n5 F4cU3brZOCOfi4vqZrVgFuhwj9fOk1W6pDmFE0cia5hVubVqSP8FIh+G+2/MU+Pp0S8y NUAWZZa+uXA72Ji6ir6jEM844/7Ww6cuxltm84iZH2WxSoLdNRicBlTj/tm6aXX/ebkn 5D8USO93MqIddq8uyO67gDq5FNhOIFdoUpIyDLHlbyX5JjcXhbVqfRzY9jkWE/IPfz/w 4XDMEVwK+1PL/4Juhtbvw/gT/Vkn0uDN83IaThCtxzJRazoXN7O1/wXWdpFbwPflcKNU Uvqw== 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=7HBO2pu7asXLBrWI/nVV7pNs4xwueifo4ga9px00/YA=; b=J4L+F1fwLhANK+zT9lJSzhLuz6RB/3rDew4lhN1dQns/48TMIKMnyCbs4hOch3LQM+ gbyhnXBP5q+5khnXt1sGwR8ZOro6OLXQzTui4rzj4QdH2/SfqWnqWhD0sVgDmlOMDQ7F AiCYVOoSIBw979cnSs2ytqVBSF9N5zFDMeZcsosxJh6Rbr6dxVXZVeoknPHwLSaHVCTa hWF8fEkee2tURAWZrh6ob2kRvSzHQsfOSMJImAmWYr6OG/vzFwKyY3SVHLSgbceOfH7t pbsxiDD4IZj63J5z4XwS5FZuvBj4viKzeJG3F9Bnd0UcsLloDnIFJD4Z1ZbKya4EVMDj FyBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jngezCdN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v2si3414184edd.536.2020.04.22.03.15.02; Wed, 22 Apr 2020 03:15:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jngezCdN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729335AbgDVKM1 (ORCPT + 99 others); Wed, 22 Apr 2020 06:12:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:45146 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729321AbgDVKMP (ORCPT ); Wed, 22 Apr 2020 06:12:15 -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 103E52070B; Wed, 22 Apr 2020 10:12:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587550334; bh=sItzWrsRKdwC5QEvlKIli2KrdE3jMIrVDLdEUJrfUqc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jngezCdN3dshGXPFwugTM2UTvPxP0KT690+cGAgqDaY78BZ6rE91mXPSAsf7WBnWY X/6iXXZF9E+C6Muved98xqo345PXkTFIjHyA3+6kmeDswbhPwKvnn8jhjl/sZgQa5k +wykr2lEW3tI249d5ZaTPGrC5a8i5AnDUXUEi+3A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vitaly Kuznetsov , Sean Christopherson , Paolo Bonzini Subject: [PATCH 4.14 062/199] KVM: VMX: fix crash cleanup when KVM wasnt used Date: Wed, 22 Apr 2020 11:56:28 +0200 Message-Id: <20200422095104.459711739@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200422095057.806111593@linuxfoundation.org> References: <20200422095057.806111593@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 dbef2808af6c594922fe32833b30f55f35e9da6d upstream. If KVM wasn't used at all before we crash the cleanup procedure fails with BUG: unable to handle page fault for address: ffffffffffffffc8 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 23215067 P4D 23215067 PUD 23217067 PMD 0 Oops: 0000 [#8] SMP PTI CPU: 0 PID: 3542 Comm: bash Kdump: loaded Tainted: G D 5.6.0-rc2+ #823 RIP: 0010:crash_vmclear_local_loaded_vmcss.cold+0x19/0x51 [kvm_intel] The root cause is that loaded_vmcss_on_cpu list is not yet initialized, we initialize it in hardware_enable() but this only happens when we start a VM. Previously, we used to have a bitmap with enabled CPUs and that was preventing [masking] the issue. Initialized loaded_vmcss_on_cpu list earlier, right before we assign crash_vmclear_loaded_vmcss pointer. blocked_vcpu_on_cpu list and blocked_vcpu_on_cpu_lock are moved altogether for consistency. Fixes: 31603d4fc2bb ("KVM: VMX: Always VMCLEAR in-use VMCSes during crash with kexec support") Signed-off-by: Vitaly Kuznetsov Message-Id: <20200401081348.1345307-1-vkuznets@redhat.com> Reviewed-by: Sean Christopherson Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/vmx.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -3776,10 +3776,6 @@ static int hardware_enable(void) if (cr4_read_shadow() & X86_CR4_VMXE) return -EBUSY; - INIT_LIST_HEAD(&per_cpu(loaded_vmcss_on_cpu, cpu)); - INIT_LIST_HEAD(&per_cpu(blocked_vcpu_on_cpu, cpu)); - spin_lock_init(&per_cpu(blocked_vcpu_on_cpu_lock, cpu)); - rdmsrl(MSR_IA32_FEATURE_CONTROL, old); test_bits = FEATURE_CONTROL_LOCKED; @@ -12900,7 +12896,7 @@ module_exit(vmx_exit) static int __init vmx_init(void) { - int r; + int r, cpu; r = kvm_init(&vmx_x86_ops, sizeof(struct vcpu_vmx), __alignof__(struct vcpu_vmx), THIS_MODULE); @@ -12922,6 +12918,12 @@ static int __init vmx_init(void) } } + for_each_possible_cpu(cpu) { + INIT_LIST_HEAD(&per_cpu(loaded_vmcss_on_cpu, cpu)); + INIT_LIST_HEAD(&per_cpu(blocked_vcpu_on_cpu, cpu)); + spin_lock_init(&per_cpu(blocked_vcpu_on_cpu_lock, cpu)); + } + #ifdef CONFIG_KEXEC_CORE rcu_assign_pointer(crash_vmclear_loaded_vmcss, crash_vmclear_local_loaded_vmcss);