Received: by 2002:a05:7412:518d:b0:e2:908c:2ebd with SMTP id fn13csp348542rdb; Thu, 5 Oct 2023 07:44:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEtVKDaIrENTnUMz096Ui6WqFLAKiyIQr5bOQiY9C2o/rjtDB4LQzxRc18lEjEsNtEZIiyX X-Received: by 2002:a05:6a21:66c9:b0:153:588c:f197 with SMTP id ze9-20020a056a2166c900b00153588cf197mr4752806pzb.35.1696517048716; Thu, 05 Oct 2023 07:44:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696517048; cv=none; d=google.com; s=arc-20160816; b=xLenfC2oj/2+0WnQlWAPDoyiJSofssnvvrjpz8dNksbzDvHI7/SBNXFSv1cf2z5BHE zhdqgbvhIsJs78sBge3LzN8WAeiBP62/NKAxZV4+B5xP2OM0TueWx/0PyQi7aMFz2c6h rDk478bGIxg/DoHYiM9V7Lwrh/9VIVgORK1BNtqspkKsulKoo1ueR9EUgUIYuxI/9lVp yCBJ7jfedW/V96WgLTX9eFWfZ3w6XiJSB5OA+KoiqBM2qFTwsSjKaeYwJXawR4V6EOj/ fFpfFBSdQNsJLtksfnu6MvparadQGRlIiQgcHbm+wYBCf+/PdTElzRnD8cArCV1oy8Cs /yNQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EjXhEfE1OrJcKnhCJyxwAo8KiJx3bHJaCHUom/r3V6k=; fh=F1gpqSS/HYttK+doOKuW4yrAifo5qykyq1MCI9SIQmQ=; b=E+je1ebauKwt0DuYEMZl9/QICUK5inqFUlLHyXyYJLIfknOQzlFY1MpolUrnljIgUN NFl9EATpVckgWSYO9GR9sNopGCRjbEaf6SScpPmhzxsrK0HmQHB8sQszZAF6Y6cJ5Eil Pfzi3aP5vTJcrPFXQEndE5eGL3ibGhbz2wW8Z4wqzw8Kdl66L9K2/x4o1+0V0hGoNYoT FPl7R2f9mEFQNuD+TcddVHrq+hlDx1PQkpgMqToGPkrQqGIIaAx2a1CU9zD4ud9p7TaY hNffddAzRKNdkkomsGzjuJ8BhBPxPsbvIIqR3lvXTmoqmq9mTH9M06PGxOlQnxrkTpQv /7jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QzVqYIAG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id i73-20020a636d4c000000b005824bad8f83si1527012pgc.846.2023.10.05.07.44.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 07:44:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QzVqYIAG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 2FA82860AD3A; Thu, 5 Oct 2023 07:44:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238804AbjJEOnu (ORCPT + 99 others); Thu, 5 Oct 2023 10:43:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237224AbjJEOiu (ORCPT ); Thu, 5 Oct 2023 10:38:50 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27C424E348 for ; Thu, 5 Oct 2023 07:04:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696514675; x=1728050675; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dQGt0n5D7SP1i4kXyMIPUS/joI3SOgsexxI/o9/iCB0=; b=QzVqYIAGi50KufyVOrlk9yTxf0A68HiArsv2rW4ovU2NXTQdSeDF3c4a r35H/Fpdmz7ofbGANr6mk9hA6vhpb3fR6AnLFVPod3X9GD36MAt61tSUW NjGTWMIfbt0sDsX1S0X3JKDVWPCoPv5eQTGQFM1xDJRhy8qyuKG06PZ/z e1j/sfstqOYeF3Y5Nf/s8nM8Q2KI2qmVT6KD+c9yrtKteM9x1G/ShdwFO S49ZxR0mLPayn8+GNLqqmg6dC6S1YidS7U86SNSieJ/8RlJu78ShopC1X 48FDx4MsSvz++DDR5fRAlM0MK1heJfCR4QfD9jKAIufMH2ZNDYOqwDAYN w==; X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="382357595" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="382357595" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 06:14:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10854"; a="817564325" X-IronPort-AV: E=Sophos;i="6.03,203,1694761200"; d="scan'208";a="817564325" Received: from skwasnia-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.251.222.71]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Oct 2023 06:14:23 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 5CDA710A152; Thu, 5 Oct 2023 16:14:14 +0300 (+03) From: "Kirill A. Shutemov" To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "Rafael J. Wysocki" , Peter Zijlstra , Adrian Hunter , Kuppuswamy Sathyanarayanan , Elena Reshetova , Jun Nakajima , Rick Edgecombe , Tom Lendacky , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCH 08/13] KVM: x86: Add config option to gate emergency virt callback support Date: Thu, 5 Oct 2023 16:13:57 +0300 Message-ID: <20231005131402.14611-9-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231005131402.14611-1-kirill.shutemov@linux.intel.com> References: <20231005131402.14611-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 05 Oct 2023 07:44:07 -0700 (PDT) KVM uses emergency virt call back to shutdown virtualization extension during crash, so the crash kernel can work correctly. So far the virt callback is only supported if KVM_INTEL or KVM_AMD is enabled. TDX guest has similar needs. Add a config option to gate virt emergency callback support. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/reboot.h | 4 ++-- arch/x86/kernel/reboot.c | 4 ++-- arch/x86/kvm/Kconfig | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h index 6536873f8fc0..f72bdd4abbe8 100644 --- a/arch/x86/include/asm/reboot.h +++ b/arch/x86/include/asm/reboot.h @@ -25,14 +25,14 @@ void __noreturn machine_real_restart(unsigned int type); #define MRR_BIOS 0 #define MRR_APM 1 -#if IS_ENABLED(CONFIG_KVM_INTEL) || IS_ENABLED(CONFIG_KVM_AMD) +#ifdef CONFIG_EMERGENCY_VIRT_CALLBACK typedef void (cpu_emergency_virt_cb)(void); void cpu_emergency_register_virt_callback(cpu_emergency_virt_cb *callback); void cpu_emergency_unregister_virt_callback(cpu_emergency_virt_cb *callback); void cpu_emergency_disable_virtualization(void); #else static inline void cpu_emergency_disable_virtualization(void) {} -#endif /* CONFIG_KVM_INTEL || CONFIG_KVM_AMD */ +#endif /* CONFIG_EMERGENCY_VIRT_CALLBACK */ typedef void (*nmi_shootdown_cb)(int, struct pt_regs*); void nmi_shootdown_cpus(nmi_shootdown_cb callback); diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c index 830425e6d38e..6a781f2f11c8 100644 --- a/arch/x86/kernel/reboot.c +++ b/arch/x86/kernel/reboot.c @@ -529,7 +529,7 @@ static inline void kb_wait(void) static inline void nmi_shootdown_cpus_on_restart(void); -#if IS_ENABLED(CONFIG_KVM_INTEL) || IS_ENABLED(CONFIG_KVM_AMD) +#ifdef CONFIG_EMERGENCY_VIRT_CALLBACK /* RCU-protected callback to disable virtualization prior to reboot. */ static cpu_emergency_virt_cb __rcu *cpu_emergency_virt_callback; @@ -599,7 +599,7 @@ static void emergency_reboot_disable_virtualization(void) } #else static void emergency_reboot_disable_virtualization(void) { } -#endif /* CONFIG_KVM_INTEL || CONFIG_KVM_AMD */ +#endif /* CONFIG_EMERGENCY_VIRT_CALLBACK */ void __attribute__((weak)) mach_reboot_fixups(void) { diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig index ed90f148140d..7df3f0c45cfe 100644 --- a/arch/x86/kvm/Kconfig +++ b/arch/x86/kvm/Kconfig @@ -80,6 +80,7 @@ config KVM_WERROR config KVM_INTEL tristate "KVM for Intel (and compatible) processors support" depends on KVM && IA32_FEAT_CTL + select EMERGENCY_VIRT_CALLBACK help Provides support for KVM on processors equipped with Intel's VT extensions, a.k.a. Virtual Machine Extensions (VMX). @@ -102,6 +103,7 @@ config X86_SGX_KVM config KVM_AMD tristate "KVM for AMD processors support" depends on KVM && (CPU_SUP_AMD || CPU_SUP_HYGON) + select EMERGENCY_VIRT_CALLBACK help Provides support for KVM on AMD processors equipped with the AMD-V (SVM) extensions. @@ -155,3 +157,6 @@ config KVM_EXTERNAL_WRITE_TRACKING bool endif # VIRTUALIZATION + +config EMERGENCY_VIRT_CALLBACK + bool -- 2.41.0