Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3561157pxb; Mon, 1 Mar 2021 13:23:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJxIzAoM+tCFQxXsw0KI9q+h1ujaKqNJLJA48RHCSVGDzjEZn1BFb1RAS6n+sLwh9/A5CVoT X-Received: by 2002:aa7:c6d2:: with SMTP id b18mr18105538eds.183.1614633706143; Mon, 01 Mar 2021 13:21:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614633706; cv=none; d=google.com; s=arc-20160816; b=WHXK9kZbJyeV+VKh6CV58IK1Av70mittknqcSgmx4l4i+WQd8tDFFfGY/mgpCSmwkn QNqh4dKdz6K7GR5tmltze1TUXWrvBprMBtfC74OEQUiShlflILhjwINmDaNyIxDjUonA G37uYZHfmgy20CBhPvzzOW6sy1etCtuEgAj3+0yA4Z0a3vw/V6I7j2+Xg983N51YCXTO ryeHQi0OV+mYK0p+2G+XtnXV1EX9ziWHqrp6U4uL9u01Kx+RhAwzjmS5ZntIUsDOBSVk RS1desQ2DOkoNtiDXxRq3GpXGbzU8hrGQKfV7poS4HDnqFnG6SzknqQWduUMsOv0K4NK WNAg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xK76NeqsbyyEKrNqKBL/UiXUaKe8y/gG64tjnwRL1oE=; b=0/IbhGcx57jLgE/xq95pNYz3i+kYOXaa7/pk4wSMxfohn184nm9Bq1wVXOoBD81H1l 4SepfBO05q10OYo2wBthJrrOaahn//hKOpbyOiblEb9oDudPeQt2LNGT4QcscKy2fn6f w+HgrUzfgX0s0uoXHb3ofzz8Z6uWO0y0cqMPRwmZPDq3TJt1BO0oRg2/QiRSjlMed4nj owozHp2AKzGv2S9SM/AFXlSjSmwE6NL+LtAq3eLEHURu4W58a3wioO9HE8FrnoNXCo6z UnZVy40I7BT73E5gJeKIjQN+V2/1EmSPwp6kca1d3hq+YAqrKaKrVwHVLWRCdBThe3/6 GIUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="GmuOw/NB"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f11si3413104ejr.284.2021.03.01.13.21.23; Mon, 01 Mar 2021 13:21:46 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b="GmuOw/NB"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244091AbhCAVRx (ORCPT + 99 others); Mon, 1 Mar 2021 16:17:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:50436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234850AbhCAROD (ORCPT ); Mon, 1 Mar 2021 12:14:03 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C4DFC6503E; Mon, 1 Mar 2021 16:45:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614617132; bh=d4FduEAJdMaDDRP243VE1K2XEo86U7X0COC90qEgY3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GmuOw/NBZVkEKAdzr7kxmBarwRkSFBD04WWIGbNo0OWfHN9L9l7x4+f5Utx5+XP1Y bftlLGBy9FitGHER8dkNFjigKz6e0hHfN1m/AaAMzW3NDzJDhtAJgmdKQdFGZZ5sE3 5fJZLdJb9H5KXtgjbM6Hy8w5XW3HLCvB6AbbQa0c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , "David P. Reed" , Paolo Bonzini Subject: [PATCH 4.19 213/247] x86/reboot: Force all cpus to exit VMX root if VMX is supported Date: Mon, 1 Mar 2021 17:13:53 +0100 Message-Id: <20210301161042.098175585@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson commit ed72736183c45a413a8d6974dd04be90f514cb6b upstream. Force all CPUs to do VMXOFF (via NMI shootdown) during an emergency reboot if VMX is _supported_, as VMX being off on the current CPU does not prevent other CPUs from being in VMX root (post-VMXON). This fixes a bug where a crash/panic reboot could leave other CPUs in VMX root and prevent them from being woken via INIT-SIPI-SIPI in the new kernel. Fixes: d176720d34c7 ("x86: disable VMX on all CPUs on reboot") Cc: stable@vger.kernel.org Suggested-by: Sean Christopherson Signed-off-by: David P. Reed [sean: reworked changelog and further tweaked comment] Signed-off-by: Sean Christopherson Message-Id: <20201231002702.2223707-3-seanjc@google.com> Signed-off-by: Paolo Bonzini Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/reboot.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) --- a/arch/x86/kernel/reboot.c +++ b/arch/x86/kernel/reboot.c @@ -538,29 +538,20 @@ static void emergency_vmx_disable_all(vo local_irq_disable(); /* - * We need to disable VMX on all CPUs before rebooting, otherwise - * we risk hanging up the machine, because the CPU ignore INIT - * signals when VMX is enabled. + * Disable VMX on all CPUs before rebooting, otherwise we risk hanging + * the machine, because the CPU blocks INIT when it's in VMX root. * - * We can't take any locks and we may be on an inconsistent - * state, so we use NMIs as IPIs to tell the other CPUs to disable - * VMX and halt. + * We can't take any locks and we may be on an inconsistent state, so + * use NMIs as IPIs to tell the other CPUs to exit VMX root and halt. * - * For safety, we will avoid running the nmi_shootdown_cpus() - * stuff unnecessarily, but we don't have a way to check - * if other CPUs have VMX enabled. So we will call it only if the - * CPU we are running on has VMX enabled. - * - * We will miss cases where VMX is not enabled on all CPUs. This - * shouldn't do much harm because KVM always enable VMX on all - * CPUs anyway. But we can miss it on the small window where KVM - * is still enabling VMX. + * Do the NMI shootdown even if VMX if off on _this_ CPU, as that + * doesn't prevent a different CPU from being in VMX root operation. */ - if (cpu_has_vmx() && cpu_vmx_enabled()) { - /* Disable VMX on this CPU. */ - cpu_vmxoff(); + if (cpu_has_vmx()) { + /* Safely force _this_ CPU out of VMX root operation. */ + __cpu_emergency_vmxoff(); - /* Halt and disable VMX on the other CPUs */ + /* Halt and exit VMX root operation on the other CPUs. */ nmi_shootdown_cpus(vmxoff_nmi); }