From nobody Tue Feb 10 06:05:23 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 76D38C7EE25 for ; Fri, 12 May 2023 23:50:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241078AbjELXuy (ORCPT ); Fri, 12 May 2023 19:50:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240906AbjELXuk (ORCPT ); Fri, 12 May 2023 19:50:40 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 245C140ED for ; Fri, 12 May 2023 16:50:38 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-643aad3bbf3so5464094b3a.0 for ; Fri, 12 May 2023 16:50:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683935437; x=1686527437; 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=/jmBez73RsnuS+uU/xiNQiFMzjYNw0oV2iJF3mbgvJ0=; b=xlRxYqTPR40AEoqZn/L6lxwwX9jASAhxh5BJ5/+5IZF9h4us7R3K362Avf7/wX0IcA XTozwVsltuizAmLhIaW3V3/21m8bc73W8EZrhnFEUFojSwvZ7LUDqY+bvD9ru1AX3dKO 3ckkn9O26SKBX0x9uwUd++Tk3Jd2jrWNd2OCjimqKsp62OdmL9Yw2VrLsjKpUYgGdIv8 NwoqiH0UDdzPyG2QqKyzIxBUM3G6PM2lfN1HYpbsW/ELVvGhofKPj+IwwQ4AGX0NGDr3 w2Le63AVJ0fMXR33ixFj7na0sT9Yg5wSWbImsdoBS0QVDLO0t/VW8428aurQQH8BXPhW hhog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683935437; x=1686527437; 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=/jmBez73RsnuS+uU/xiNQiFMzjYNw0oV2iJF3mbgvJ0=; b=b3x+I5fiSmBV/vkW8Zn+wleBfQvTpMvWbZZSu7ODTKykZHh2GHhnVI0CHBPvosWgwh KGxBwvMBVFAFE/6xqizsjpdFlfQj8ONctW47hW9rcF2mpxFQbTYEKV5wBLrt72xhA4aZ YDp4lJOT+XAxfY1sFlB6HvxRBPl+bHr7BDGYAv3zUqsNfpdqAhHLVxiX8j0nxBvz+S8g vl62kzjM3BmQo/rg7zApPKSc6brOGWTZcl4rK8w+hppKkbnlauZP3s2SfYE4oVWC6xMv AbVLUWxesQkL0R+iGowGiZ9gqZVOGI1MEy+dYnBAAh2uv/w6wtA1fHiGsHky35j2+ArF w/4Q== X-Gm-Message-State: AC+VfDxw1gdfYuAdGz1EX40kUpbWGMeAHy0hQi6LzjI5vAzBGfehEffp PLOf4mKMRIrdRBfB4VrRHSX/UNGjRQQ= X-Google-Smtp-Source: ACHHUZ6TWHazXiZOhV3QRVyclx3u8oyy3vtvy+owJF/RtDMeFsLh/zrVPtZPdDtRyNHbm9QOLl8WMmX7aFU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:7d6:b0:624:5886:4b4b with SMTP id n22-20020a056a0007d600b0062458864b4bmr6850731pfu.5.1683935437710; Fri, 12 May 2023 16:50:37 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 12 May 2023 16:50:12 -0700 In-Reply-To: <20230512235026.808058-1-seanjc@google.com> Mime-Version: 1.0 References: <20230512235026.808058-1-seanjc@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Message-ID: <20230512235026.808058-5-seanjc@google.com> Subject: [PATCH v3 04/18] x86/reboot: KVM: Disable SVM during reboot via virt/KVM reboot callback From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@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. Signed-off-by: Sean Christopherson Acked-by: Kai Huang --- 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 0cf2261c2dec..92b380e199a3 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 eb308c9994f9..0f0d04900bf2 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -38,6 +38,7 @@ #include #include #include +#include #include =20 #include @@ -568,6 +569,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 */ @@ -5184,6 +5190,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; @@ -5197,6 +5210,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! @@ -5209,14 +5224,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.40.1.606.ga4b1b128d6-goog