From patchwork Fri May 12 23:50:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 93423 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp5462237vqo; Fri, 12 May 2023 16:51:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6/nrreEGjA3wRl4XovyFbdXh02DsV/2TDkLUcIzJk+ritShF+bVWTVDa5S4BtlR0Ft/AT2 X-Received: by 2002:a17:90a:134a:b0:252:935b:cbde with SMTP id y10-20020a17090a134a00b00252935bcbdemr6840353pjf.19.1683935516084; Fri, 12 May 2023 16:51:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683935516; cv=none; d=google.com; s=arc-20160816; b=irq/y7L4HgY5ITVMo6VWkKD3PWL+85AaHTPoJHfmzvoNSuinkHKl+U5HfEgwXbSWyH X81qPw8EqI/RR8r5liQ2lAac43CRkRQB/9EQqGjZCwISEx09Ae0cjn2nwn64ruFpSBkm RvKiSnGcykexSa8uJmxe63GJGny8tAVtKIpOgW0zVwgdwiMFKoV/DrYWUgQ3kZMGuRKR mGJtIpkQmsbX8oRd7tqhw00Q8tLo7eNgnCA4hB7VsFh2JeXrm++p9rZVVt2lVaMLieTO As+I8vUkhdyvveWqq7V++4A+YNAESpluGcNhrcxNQxTCikeysSaJBtcdTv/Q7R0YzlUj R9SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=/jmBez73RsnuS+uU/xiNQiFMzjYNw0oV2iJF3mbgvJ0=; b=TpSnbmIqRN7Es4M/DLEtym/8mZQKm3tJ1TH8rZy5kRylhbfuhh6LZiy8Pnej6pMHbb QiWQMsfS7fk2eDUoKtBxMBhQKsnQMc11ndmdNsbXZhMLgw2/p1SE25QIMp4Mf3lguG2s 9I3+3jHuBkHQp41Wyt07wR4p17RDdHv6Y49a03gcLGZd2SS4IwYBFSllIAQcghBkKAcn h2mTShH99dBxgNU6cAnEQkh4dpSJ5jl3/HKDjun+GgKrjh0gw5n9hj4mtJm3iGFGifyy N781GC0EjoGrOLdimTern2FhPsIDApc7M9Yy/67RGrSTufYtoBqRgaVQbxyL4UtYUhgb +0ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=xlRxYqTP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s12-20020a17090aad8c00b0024e184e5a53si28373106pjq.117.2023.05.12.16.51.44; Fri, 12 May 2023 16:51:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=xlRxYqTP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240938AbjELXuw (ORCPT + 99 others); Fri, 12 May 2023 19:50:52 -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-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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765734367404854629?= X-GMAIL-MSGID: =?utf-8?q?1765734367404854629?= Use the virt callback to disable SVM (and set GIF=1) 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) } } -/** 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(); } #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 #include @@ -568,6 +569,11 @@ void __svm_write_tsc_multiplier(u64 multiplier) preempt_enable(); } +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 __initdata = { .pmu_ops = &amd_pmu_ops, }; +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; + 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; err_kvm_init: - kvm_x86_vendor_exit(); + __svm_exit(); return r; } static void __exit svm_exit(void) { kvm_exit(); - kvm_x86_vendor_exit(); + __svm_exit(); } module_init(svm_init)