From nobody Thu Sep 18 21:54:28 2025 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 5CFA6EB64DD for ; Fri, 21 Jul 2023 20:19:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231295AbjGUUTk (ORCPT ); Fri, 21 Jul 2023 16:19:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230356AbjGUUTT (ORCPT ); Fri, 21 Jul 2023 16:19:19 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDBFDC6 for ; Fri, 21 Jul 2023 13:19:12 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-57059e6f9c7so39817167b3.0 for ; Fri, 21 Jul 2023 13:19:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1689970752; x=1690575552; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=KapJsJDXZSaTZ0KCMkqJA+w32osB4ivWYrQOtexabwQ=; b=TrXZbzXJvXjAFMtmdjbY6g43FEEUJ51e56dkvtg+kfgYdfON7FtAc+d4i+2limdYih Fjpb36idC7mIVH+9ApO7W85B+EBgNR1y6VZFqbg9bjcKv172M5172Tu0I1dzmE0TZhX3 D9a4xyqNrw76UX3aD/sp0MisPY3yUWWKy6fXVSHGN4RpngnPjxMpr1WT6B57I5nDMM9h IGtYIrkL6QnQtXLq3ifiyUfnkXFyNu8goNHHb5EOEskvSfgSpgVq/fQOHdiQZkOKHfsp pRjXnhp8+gJFBM/PT+CJZnzWIouDqwd+pTmAWoAH8rgQR31KG+5TVJ87+VibBetAjN4U 9KGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689970752; x=1690575552; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KapJsJDXZSaTZ0KCMkqJA+w32osB4ivWYrQOtexabwQ=; b=RUOv8jvbXetdtINDT/14WhPjhxxpX31Z1U95Omh5sR15DO+xxKTRbLLbrHtiG/X2C2 zltzAERAY6vY3jshWLtB0kjanCm3xNFfQB2b7A+GlxJWd5CNEZoVwqjyGWweiB82cVa3 5hSB2ox0jNwADFrrui1gU7V+/mXQwJ/zz8B66chTZEy2acwHDYNZ09ZnJfUnn9uAKCmj RX2izTEuwrpMviwDK/Vaw8JnsVysOkFlthz1SF562aCK/DVqSGElV08Ev4S7/jC5lDTs v0HPa/cUzD53U0wBDUcaDaSQI3yHaBtRZc6XKoeWIEkCvr5qF7hBKbxz8+6QNOvpfMKM 9IxQ== X-Gm-Message-State: ABy/qLZMD2lVe1yhT5uqmYVFeFRyFuZD0cA6mpE8lczuSCAXkErMh2pU J8XA7c7DYu0/2K9vom9UPNVa4pcT40c= X-Google-Smtp-Source: APBJJlGu5YOBwzaswNuu+hMFwXKYPw6WfFvR2MaNIQNXi7dan4IRvarFADNDlK9IoFXtUVAADyo+h6fqziI= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:ad24:0:b0:56c:e53d:ae90 with SMTP id l36-20020a81ad24000000b0056ce53dae90mr13963ywh.4.1689970752188; Fri, 21 Jul 2023 13:19:12 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 21 Jul 2023 13:18:44 -0700 In-Reply-To: <20230721201859.2307736-1-seanjc@google.com> Mime-Version: 1.0 References: <20230721201859.2307736-1-seanjc@google.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog Message-ID: <20230721201859.2307736-5-seanjc@google.com> Subject: [PATCH v4 04/19] x86/reboot: KVM: Disable SVM during reboot via virt/KVM reboot callback From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Sean Christopherson , Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Andrew Cooper , Kai Huang , Chao Gao Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the virt callback to disable SVM (and set GIF=3D1) during an emergency instead of blindly attempting to disable SVM. Like the VMX case, if a hypervisor, i.e. KVM, isn't loaded/active, SVM can't be in use. Acked-by: Kai Huang Signed-off-by: Sean Christopherson --- arch/x86/include/asm/virtext.h | 8 -------- arch/x86/kernel/reboot.c | 3 --- arch/x86/kvm/svm/svm.c | 19 +++++++++++++++++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/arch/x86/include/asm/virtext.h b/arch/x86/include/asm/virtext.h index 5bc29fab15da..aaed66249ccf 100644 --- a/arch/x86/include/asm/virtext.h +++ b/arch/x86/include/asm/virtext.h @@ -133,12 +133,4 @@ static inline void cpu_svm_disable(void) } } =20 -/** Makes sure SVM is disabled, if it is supported on the CPU - */ -static inline void cpu_emergency_svm_disable(void) -{ - if (cpu_has_svm(NULL)) - cpu_svm_disable(); -} - #endif /* _ASM_X86_VIRTEX_H */ diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c index d2d0f2672a64..48ad2d1ff83d 100644 --- a/arch/x86/kernel/reboot.c +++ b/arch/x86/kernel/reboot.c @@ -826,9 +826,6 @@ void cpu_emergency_disable_virtualization(void) if (callback) callback(); rcu_read_unlock(); - - /* KVM_AMD doesn't yet utilize the common callback. */ - cpu_emergency_svm_disable(); } =20 #if defined(CONFIG_SMP) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index d381ad424554..1ae9c2c7eacb 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -39,6 +39,7 @@ #include #include #include +#include #include =20 #include @@ -563,6 +564,11 @@ void __svm_write_tsc_multiplier(u64 multiplier) preempt_enable(); } =20 +static void svm_emergency_disable(void) +{ + cpu_svm_disable(); +} + static void svm_hardware_disable(void) { /* Make sure we clean up behind us */ @@ -5209,6 +5215,13 @@ static struct kvm_x86_init_ops svm_init_ops __initda= ta =3D { .pmu_ops =3D &amd_pmu_ops, }; =20 +static void __svm_exit(void) +{ + kvm_x86_vendor_exit(); + + cpu_emergency_unregister_virt_callback(svm_emergency_disable); +} + static int __init svm_init(void) { int r; @@ -5222,6 +5235,8 @@ static int __init svm_init(void) if (r) return r; =20 + cpu_emergency_register_virt_callback(svm_emergency_disable); + /* * Common KVM initialization _must_ come last, after this, /dev/kvm is * exposed to userspace! @@ -5234,14 +5249,14 @@ static int __init svm_init(void) return 0; =20 err_kvm_init: - kvm_x86_vendor_exit(); + __svm_exit(); return r; } =20 static void __exit svm_exit(void) { kvm_exit(); - kvm_x86_vendor_exit(); + __svm_exit(); } =20 module_init(svm_init) --=20 2.41.0.487.g6d72f3e995-goog