From nobody Thu May 7 21:41:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA226C433EF for ; Wed, 18 May 2022 00:17:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232490AbiERARA (ORCPT ); Tue, 17 May 2022 20:17:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231556AbiERAQ4 (ORCPT ); Tue, 17 May 2022 20:16:56 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82B0C377F7 for ; Tue, 17 May 2022 17:16:55 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id c4-20020aa79524000000b005180f331899so303028pfp.11 for ; Tue, 17 May 2022 17:16:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=rR9QT3FVOBG/jORwlMjkzEP1wf5ezoAh1SN5/FtrVoY=; b=FATeKh/LCpHK6gOSy0gpmtAfUOdYke2XGc3dJ8Hk3Pl1FyF3nl/egXhanbhZJlGBkI vSwXwaPVT0gwXBISR5DobJvih1f5ukLKTgfKZYMqu45YiyIOxI7FqCC17NMfyqzEVW3N e6/uqlg5cTi8eFkGt+je5HkOe8dxeIMRlRfBIPxaV3qRSlRjViHiWImOpos0vew0dfuc Ss4qVLJewDKxSA+WxJnbl/EOoO6wefHTPl/21drTNgPRAkn42q5XkWmGpPJaqRAA+K1R z52SBfDEP950vJw1M46aRekSt0ajx4TBzBTTl+k8nMtUX9MW+e85jwBvcpNuU09stk4v vHuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=rR9QT3FVOBG/jORwlMjkzEP1wf5ezoAh1SN5/FtrVoY=; b=3L+DY7TBo4jVdInZpWaLr+XjJKU7r6X6jk2ej4/5bCrKlRUD0WCk9mkiJi6TJt27Cp AOckO9wQkjKtAxMsx1T5EgnlaY4HFSxk/ip+ZbQTE+grH08yTrUydgxKz+0qO3GVSwT1 FdVdfCM//1AUDCGlUMYLhIw4KqAp8BXSLLg7jHV1kJPitsHAPvDd1e63ILxw/doFGhqm UH2gG+XYusLUp1mKvY14SYp25ytidfiwLbcX0yv6PuIhBs68e26rU0dnWwh3BRqxVwfn lNkkipVF2q+Wg/sJVPYnHOFcAn8RojRcxoW7ky6V62bG3EtFN8cPWqnzQoeRb/emPSbH OPMw== X-Gm-Message-State: AOAM531DZ/wTrshElZOPgem0oIN+bhQlGHPscukN7Nlfmh+LTOVkrzYu 34IFN70+4TlBWuU3H4jAKAxFr/Ou2sg= X-Google-Smtp-Source: ABdhPJwVDC2ZTd4lkiIiSXmzAr/jhuj2aEPPI9OE+watZa8joZlD439lQPClC8VjFT5XfOxWqWYZrj2yaqc= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:90b:1e41:b0:1de:b2dc:b2e with SMTP id pi1-20020a17090b1e4100b001deb2dc0b2emr27643168pjb.69.1652833015045; Tue, 17 May 2022 17:16:55 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 18 May 2022 00:16:45 +0000 In-Reply-To: <20220518001647.1291448-1-seanjc@google.com> Message-Id: <20220518001647.1291448-2-seanjc@google.com> Mime-Version: 1.0 References: <20220518001647.1291448-1-seanjc@google.com> X-Mailer: git-send-email 2.36.0.550.gb090851708-goog Subject: [PATCH v2 1/3] x86/crash: Disable virt in core NMI crash handler to avoid double shootdown From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, "Guilherme G . Piccoli" , Vitaly Kuznetsov , Paolo Bonzini , Sean Christopherson Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Disable virtualization in crash_nmi_callback() and rework the emergency_vmx_disable_all() path to do an NMI shootdown if and only if a shootdown has not already occurred. NMI crash shootdown fundamentally can't support multiple invocations as responding CPUs are deliberately put into halt state without unblocking NMIs. But, the emergency reboot path doesn't have any work of its own, it simply cares about disabling virtualization, i.e. so long as a shootdown occurred, emergency reboot doesn't care who initiated the shootdown, or when. If "crash_kexec_post_notifiers" is specified on the kernel command line, panic() will invoke crash_smp_send_stop() and result in a second call to nmi_shootdown_cpus() during native_machine_emergency_restart(). Invoke the callback _before_ disabling virtualization, as the current VMCS needs to be cleared before doing VMXOFF. Note, this results in a subtle change in ordering between disabling virtualization and stopping Intel PT on the responding CPUs. While VMX and Intel PT do interact, VMXOFF and writes to MSR_IA32_RTIT_CTL do not induce faults between one another, which is all that matters when panicking. Harden nmi_shootdown_cpus() against multiple invocations to try and capture any such kernel bugs via a WARN instead of hanging the system during a crash/dump, e.g. prior to the recent hardening of register_nmi_handler(), re-registering the NMI handler would trigger a double list_add() and hang the system if CONFIG_BUG_ON_DATA_CORRUPTION=3Dy. list_add double add: new=3Dffffffff82220800, prev=3Dffffffff8221cfe8, next= =3Dffffffff82220800. WARNING: CPU: 2 PID: 1319 at lib/list_debug.c:29 __list_add_valid+0x67/0x70 Call Trace: __register_nmi_handler+0xcf/0x130 nmi_shootdown_cpus+0x39/0x90 native_machine_emergency_restart+0x1c9/0x1d0 panic+0x237/0x29b Extract the disabling logic to a common helper to deduplicate code, and to prepare for doing the shootdown in the emergency reboot path if SVM is supported. Note, prior to commit ed72736183c4 ("x86/reboot: Force all cpus to exit VMX root if VMX is supported"), nmi_shootdown_cpus() was subtly protected against a second invocation by a cpu_vmx_enabled() check as the kdump handler would disable VMX if it ran first. Fixes: ed72736183c4 ("x86/reboot: Force all cpus to exit VMX root if VMX is= supported) Cc: stable@vger.kernel.org Reported-by: Guilherme G. Piccoli Cc: Vitaly Kuznetsov Cc: Paolo Bonzini Link: https://lore.kernel.org/all/20220427224924.592546-2-gpiccoli@igalia.c= om Signed-off-by: Sean Christopherson Tested-by: Guilherme G. Piccoli --- arch/x86/include/asm/reboot.h | 1 + arch/x86/kernel/crash.c | 16 +-------- arch/x86/kernel/reboot.c | 66 ++++++++++++++++++++++++++++------- 3 files changed, 56 insertions(+), 27 deletions(-) diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h index 04c17be9b5fd..8f2da36435a6 100644 --- a/arch/x86/include/asm/reboot.h +++ b/arch/x86/include/asm/reboot.h @@ -25,6 +25,7 @@ void __noreturn machine_real_restart(unsigned int type); #define MRR_BIOS 0 #define MRR_APM 1 =20 +void cpu_crash_disable_virtualization(void); typedef void (*nmi_shootdown_cb)(int, struct pt_regs*); void nmi_panic_self_stop(struct pt_regs *regs); void nmi_shootdown_cpus(nmi_shootdown_cb callback); diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c index e8326a8d1c5d..fe0cf83843ba 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c @@ -81,15 +81,6 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *= regs) */ cpu_crash_vmclear_loaded_vmcss(); =20 - /* Disable VMX or SVM if needed. - * - * We need to disable virtualization on all CPUs. - * Having VMX or SVM enabled on any CPU may break rebooting - * after the kdump kernel has finished its task. - */ - cpu_emergency_vmxoff(); - cpu_emergency_svm_disable(); - /* * Disable Intel PT to stop its logging */ @@ -148,12 +139,7 @@ void native_machine_crash_shutdown(struct pt_regs *reg= s) */ cpu_crash_vmclear_loaded_vmcss(); =20 - /* Booting kdump kernel with VMX or SVM enabled won't work, - * because (among other limitations) we can't disable paging - * with the virt flags. - */ - cpu_emergency_vmxoff(); - cpu_emergency_svm_disable(); + cpu_crash_disable_virtualization(); =20 /* * Disable Intel PT to stop its logging diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c index fa700b46588e..e67737418f7d 100644 --- a/arch/x86/kernel/reboot.c +++ b/arch/x86/kernel/reboot.c @@ -528,10 +528,7 @@ static inline void kb_wait(void) } } =20 -static void vmxoff_nmi(int cpu, struct pt_regs *regs) -{ - cpu_emergency_vmxoff(); -} +static inline void nmi_shootdown_cpus_on_restart(void); =20 /* Use NMIs as IPIs to tell all CPUs to disable virtualization */ static void emergency_vmx_disable_all(void) @@ -554,7 +551,7 @@ static void emergency_vmx_disable_all(void) __cpu_emergency_vmxoff(); =20 /* Halt and exit VMX root operation on the other CPUs. */ - nmi_shootdown_cpus(vmxoff_nmi); + nmi_shootdown_cpus_on_restart(); } } =20 @@ -802,6 +799,18 @@ static nmi_shootdown_cb shootdown_callback; static atomic_t waiting_for_crash_ipi; static int crash_ipi_issued; =20 +void cpu_crash_disable_virtualization(void) +{ + /* + * Disable virtualization, i.e. VMX or SVM, so that INIT is recognized + * during reboot. VMX blocks INIT if the CPU is post-VMXON, and SVM + * blocks INIT if GIF=3D0. Note, CLGI #UDs if SVM isn't enabled, so it's + * easier to just disable SVM unconditionally. + */ + cpu_emergency_vmxoff(); + cpu_emergency_svm_disable(); +} + static int crash_nmi_callback(unsigned int val, struct pt_regs *regs) { int cpu; @@ -817,7 +826,14 @@ static int crash_nmi_callback(unsigned int val, struct= pt_regs *regs) return NMI_HANDLED; local_irq_disable(); =20 - shootdown_callback(cpu, regs); + if (shootdown_callback) + shootdown_callback(cpu, regs); + + /* + * Prepare the CPU for reboot _after_ invoking the callback so that the + * callback can safely use virtualization instructions, e.g. VMCLEAR. + */ + cpu_crash_disable_virtualization(); =20 atomic_dec(&waiting_for_crash_ipi); /* Assume hlt works */ @@ -828,18 +844,32 @@ static int crash_nmi_callback(unsigned int val, struc= t pt_regs *regs) return NMI_HANDLED; } =20 -/* - * Halt all other CPUs, calling the specified function on each of them +/** + * nmi_shootdown_cpus - Stop other CPUs via NMI + * @callback: Optional callback to be invoked from the NMI handler * - * This function can be used to halt all other CPUs on crash - * or emergency reboot time. The function passed as parameter - * will be called inside a NMI handler on all CPUs. + * The NMI handler on the remote CPUs invokes @callback, if not + * NULL, first and then disables virtualization to ensure that + * INIT is recognized during reboot. + * + * nmi_shootdown_cpus() can only be invoked once. After the first + * invocation all other CPUs are stuck in crash_nmi_callback() and + * cannot respond to a second NMI. */ void nmi_shootdown_cpus(nmi_shootdown_cb callback) { unsigned long msecs; + local_irq_disable(); =20 + /* + * Avoid certain doom if a shootdown already occurred; re-registering + * the NMI handler will cause list corruption, modifying the callback + * will do who knows what, etc... + */ + if (WARN_ON_ONCE(crash_ipi_issued)) + return; + /* Make a note of crashing cpu. Will be used in NMI callback. */ crashing_cpu =3D safe_smp_processor_id(); =20 @@ -867,7 +897,17 @@ void nmi_shootdown_cpus(nmi_shootdown_cb callback) msecs--; } =20 - /* Leave the nmi callback set */ + /* + * Leave the nmi callback set, shootdown is a one-time thing. Clearing + * the callback could result in a NULL pointer dereference if a CPU + * (finally) responds after the timeout expires. + */ +} + +static inline void nmi_shootdown_cpus_on_restart(void) +{ + if (!crash_ipi_issued) + nmi_shootdown_cpus(NULL); } =20 /* @@ -897,6 +937,8 @@ void nmi_shootdown_cpus(nmi_shootdown_cb callback) /* No other CPUs to shoot down */ } =20 +static inline void nmi_shootdown_cpus_on_restart(void) { } + void run_crash_ipi_callback(struct pt_regs *regs) { } --=20 2.36.0.550.gb090851708-goog From nobody Thu May 7 21:41:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBD1DC433EF for ; Wed, 18 May 2022 00:17:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232513AbiERARC (ORCPT ); Tue, 17 May 2022 20:17:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232477AbiERAQ5 (ORCPT ); Tue, 17 May 2022 20:16:57 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43818377F7 for ; Tue, 17 May 2022 17:16:57 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id v10-20020a17090a0c8a00b001c7a548e4f7so2250172pja.2 for ; Tue, 17 May 2022 17:16:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=7mzm6qjp3Yai3B3eF57KZR4+IRYh/smYTo1V52UGyPA=; b=mADzZIq8tgjzX1Icd5MTvHVL3DMKraxuenM7VA62zM/HpQgWSd+BUH6roMy8Flnn0m Oj6JLdSkoa4CWEV+r3PWdbwsbw/b04baqhyerktWitfsOzcNNqte7moS6lTMK1SkartZ 8ulL8+55uTJVYUI4wIV3AwXuRXlaScpE6ofVMQQ8hIVvEKi4w4b+q4szqvTFhE99UI2w ZhGgPp+O/T4ZWnMMDXuL0WOB+uy+Tfy2eH+6Sw2qDhJ8caIiR9u0GPUMHzrUhFXGcNSQ 3fcl+nDhTD6TvOkzfwt3Y3leQBMDkgS6izYuVPWuprk7lu8FNe+AyWkrfOMHN7Nm70gz huww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=7mzm6qjp3Yai3B3eF57KZR4+IRYh/smYTo1V52UGyPA=; b=OEb19p8K9zjtZoBuvJ1wf+0KDrOPG4I2vrDRfB5zLvmYNKUZ3RLGD5c1+eIpnYByXU NKrCj2Usm1saVG/E2oMZblQR32lU/t9kdZ9OmqhpWejZ+dGmfh2ymOr9mJbW65jnB360 rYML5eCEKq/hTRBnVF4TK+SbaEwAu2e9Bom/GvtGGNhVTNua14r44jtV3WCdM08ADE5j YZWS0hgLSyXY0jO6v2pohnWVw+fMt1+zbXpvVbw4NfWPxm+lDkJ+wf0c5jLh0qb8QKEe ou+aQ2hkgP8YZbFBA5ydNfirXMeYgmUxp1f3Vqu9KwBIDdXfxCfa4fUQbu0KhR3cMAxY MGJw== X-Gm-Message-State: AOAM532ZFyPvxVUI//+qmpa5/w/95AnX0Lwpj5m14MisgkAvIMheVNA4 zb7Iwy/SItkaY6mb9T1ro6FsSPetTEY= X-Google-Smtp-Source: ABdhPJygTCCF+Hnb7HRTg8yNr37g9LpbXVaCpCe5YKtrwNXKsySOcfhf9HByxNerW9gAueXGX+txNxRe/90= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:9044:b0:15d:1c51:5bef with SMTP id w4-20020a170902904400b0015d1c515befmr24620576plz.170.1652833016740; Tue, 17 May 2022 17:16:56 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 18 May 2022 00:16:46 +0000 In-Reply-To: <20220518001647.1291448-1-seanjc@google.com> Message-Id: <20220518001647.1291448-3-seanjc@google.com> Mime-Version: 1.0 References: <20220518001647.1291448-1-seanjc@google.com> X-Mailer: git-send-email 2.36.0.550.gb090851708-goog Subject: [PATCH v2 2/3] x86/reboot: Disable virtualization in an emergency if SVM is supported From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, "Guilherme G . Piccoli" , Vitaly Kuznetsov , Paolo Bonzini , Sean Christopherson Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Disable SVM on all CPUs via NMI shootdown during an emergency reboot. Like VMX, SVM can block INIT and thus prevent bringing up other CPUs via INIT-SIPI-SIPI. Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson --- arch/x86/kernel/reboot.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c index e67737418f7d..0aba4a37f3f9 100644 --- a/arch/x86/kernel/reboot.c +++ b/arch/x86/kernel/reboot.c @@ -530,27 +530,26 @@ static inline void kb_wait(void) =20 static inline void nmi_shootdown_cpus_on_restart(void); =20 -/* Use NMIs as IPIs to tell all CPUs to disable virtualization */ -static void emergency_vmx_disable_all(void) +static void emergency_reboot_disable_virtualization(void) { /* Just make sure we won't change CPUs while doing this */ local_irq_disable(); =20 /* - * Disable VMX on all CPUs before rebooting, otherwise we risk hanging - * the machine, because the CPU blocks INIT when it's in VMX root. + * Disable virtualization on all CPUs before rebooting to avoid hanging + * the system, as VMX and SVM block INIT when running in the host. * * 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. + * use NMIs as IPIs to tell the other CPUs to disable VMX/SVM and halt. * - * 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. + * Do the NMI shootdown even if virtualization is off on _this_ CPU, as + * other CPUs may have virtualization enabled. */ - if (cpu_has_vmx()) { - /* Safely force _this_ CPU out of VMX root operation. */ - __cpu_emergency_vmxoff(); + if (cpu_has_vmx() || cpu_has_svm(NULL)) { + /* Safely force _this_ CPU out of VMX/SVM operation. */ + cpu_crash_disable_virtualization(); =20 - /* Halt and exit VMX root operation on the other CPUs. */ + /* Disable VMX/SVM and halt on other CPUs. */ nmi_shootdown_cpus_on_restart(); } } @@ -587,7 +586,7 @@ static void native_machine_emergency_restart(void) unsigned short mode; =20 if (reboot_emergency) - emergency_vmx_disable_all(); + emergency_reboot_disable_virtualization(); =20 tboot_shutdown(TB_SHUTDOWN_REBOOT); =20 --=20 2.36.0.550.gb090851708-goog From nobody Thu May 7 21:41:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1710C433F5 for ; Wed, 18 May 2022 00:17:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232533AbiERARH (ORCPT ); Tue, 17 May 2022 20:17:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232493AbiERARA (ORCPT ); Tue, 17 May 2022 20:17:00 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 025C537A1D for ; Tue, 17 May 2022 17:16:59 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id 2-20020a631542000000b003f5f09dd8c0so331983pgv.17 for ; Tue, 17 May 2022 17:16:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=5YuCWLet/PPts9g4RSdVal6LTdb/KAIKbqIvcb+vduY=; b=dA/qIleBSlZrZBhR7t57h+6p/ZhZLnqSXMaXUXu9jhDey23Igr2eYKnVrjc9gKwmr0 gFbDHINheRaVvWwg1bcNtFrvGhHJpC7VCRW/PVvwyN0mxmYErJsWJk7RUDpAQDKa2rZJ ICqG3XwJDV9mOi6Vnwke9oDgWXScDvseqk51ny/CoGNvVel6lmhsVWblT40ComgXwh6l zE7pOMFLOUMwoqhG76YKVubmdeoW1pVNVf5zByuX+ex9rVNPDXBQs70UWjIEvxwPV72A nRKqKyAs2spHVJogw1NY+76kPvH0k4gfRmb0IqXIFC9mzt4eebl7PVJhlBZ55UO3ZePz aGpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=5YuCWLet/PPts9g4RSdVal6LTdb/KAIKbqIvcb+vduY=; b=VoFkoFv2JiWAUisYXEYOawOm8PnzSrKTgSMyOGTV3YaicaXVdR386kULVZI4ZHA2YM bXftJ0kF8S+mFpusmBfNBb/cHxcm6FvicCUkSfYN9kZERgpAuXrNeDklQ2HBVwNQ2OmV BybxFUKZf7zrjG99d28INqk4dymSoHQUHQwjBaJHIsH09kXTiLlpJhp3Y4t2lBPpvIMX ztv25Gi5klQnF6QaokZVOJjAiTnqkk7mmbafRXsEe2YDqukpcb88+6B6v+Pz9W39lqmq 4kSg7RdWwFLC02njIx1YbqpYlY4EIOt9AXV3XeNWfKIG5pQfHAJYX0w+ARBJLiBxNCpV r2GA== X-Gm-Message-State: AOAM5334VsLd+AFV3V+PA0cc0c0Z9ROsIhbel08qGqnaepKzPbejBAJV CQiXwv+menfQarKvO3UvfeGvv2sFMbE= X-Google-Smtp-Source: ABdhPJxCHwscxVux3DXDPYVIjUJRhP48xvpihTLk7ont3PQnsFHZ4oYLJBoczxVPH4z+ghGchclueiLqaOg= X-Received: from seanjc.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:3e5]) (user=seanjc job=sendgmr) by 2002:a17:902:bc86:b0:161:5f4e:d7d0 with SMTP id bb6-20020a170902bc8600b001615f4ed7d0mr16123631plb.119.1652833018477; Tue, 17 May 2022 17:16:58 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 18 May 2022 00:16:47 +0000 In-Reply-To: <20220518001647.1291448-1-seanjc@google.com> Message-Id: <20220518001647.1291448-4-seanjc@google.com> Mime-Version: 1.0 References: <20220518001647.1291448-1-seanjc@google.com> X-Mailer: git-send-email 2.36.0.550.gb090851708-goog Subject: [PATCH v2 3/3] x86/virt: Fold __cpu_emergency_vmxoff() into its sole caller From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, "Guilherme G . Piccoli" , Vitaly Kuznetsov , Paolo Bonzini , Sean Christopherson Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fold __cpu_emergency_vmxoff() into cpu_emergency_vmxoff(), its sole remaining caller, to discourage crash/emergency code from handling VMX but not SVM. The behavior of VMX and SVM is so similar that it's highly unlikely that there will be a scenario where VMX needs to be disabled, but SVM can be left enabled. In other words, during a crash and/or emergency reboot, funnel all virtualization teardown sequences through cpu_crash_disable_virtualization(). No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/virtext.h | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/arch/x86/include/asm/virtext.h b/arch/x86/include/asm/virtext.h index 8757078d4442..a9414ef5269e 100644 --- a/arch/x86/include/asm/virtext.h +++ b/arch/x86/include/asm/virtext.h @@ -60,22 +60,12 @@ static inline int cpu_vmx_enabled(void) return __read_cr4() & X86_CR4_VMXE; } =20 -/** Disable VMX if it is enabled on the current CPU - * - * You shouldn't call this if cpu_has_vmx() returns 0. - */ -static inline void __cpu_emergency_vmxoff(void) -{ - if (cpu_vmx_enabled()) - cpu_vmxoff(); -} - /** Disable VMX if it is supported and enabled on the current CPU */ static inline void cpu_emergency_vmxoff(void) { - if (cpu_has_vmx()) - __cpu_emergency_vmxoff(); + if (cpu_has_vmx() && cpu_vmx_enabled()) + cpu_vmxoff(); } =20 =20 --=20 2.36.0.550.gb090851708-goog