From nobody Fri Dec 19 13:56:36 2025 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43EED21D585 for ; Sat, 6 Dec 2025 01:11:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764983472; cv=none; b=iGT9ra1AOektNVp46rRAPo94k4btYb6dXUIziLiWuuipDpGMqvwKSsHCAXXZZoToAcl/p+5OsqhmJPmIzxCHZjaVSlWp2M44CBuz0ABXNmcrKn1p0n1k6FUcfW5sFBPOIjbnDkeJb+HLeqQxV9qaS8BPqp7rQ2Z0eXefxMQCRJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764983472; c=relaxed/simple; bh=Xoj3VzQYzVhpJbx4kNzoLA3tCFxy7VEFT4XaIsLRops=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mPU7Fg3uQZRCWzhVR3mNvT+IKeaIxMvJT5k5HKwSt7eZT+Vadtdf3XFt1PinZwpZ4UA26Jbqfexj9Sk0HOy1pvcL4ve2kbsYdLeiUEP71/x9mkPEHcaK2Fvysus3y6aRkHfUxilyk7eeG3AfusYV30YTvOoTdKKwHD3V6sR7Dxw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=P0f8EGub; arc=none smtp.client-ip=209.85.214.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="P0f8EGub" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-295915934bfso37435245ad.0 for ; Fri, 05 Dec 2025 17:11:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764983468; x=1765588268; darn=vger.kernel.org; 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=pC6DfslZcu3nvvZIIA0BpqpSQzylE5RCvOKLxGkj7nQ=; b=P0f8EGubhEzbIREB811oRmqYboTX0t576lIZqsFwwTeg2uQxPDM2AToOrIYQnGZmGt Ge1f2+4B3WPRwKi1oucFmWHHCCHbGz65EHaWjmpI9huipUg0UFfDckIimPwefGgkSDLZ FyZiB1QhhoeWVy5G8N8czISVFgtGHsD2p5SAYkhurK/HqMX6oB209etYOiFrRRh+UxJG Ye/o+pKHHt8GEITwpUrIFVZAV21mX++GIMhNpEnmgCCflYsd9LijbZOz+qYyq62rmLQy AmOdDxri/4/wshYu2nZBYGnZCuPnW8jgx0dGKBSJui5lE5qU6MT1BgbcwyIcP09aK3og r4vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764983468; x=1765588268; 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=pC6DfslZcu3nvvZIIA0BpqpSQzylE5RCvOKLxGkj7nQ=; b=gsA/9lVsuOu0yOGGeUvk0mk7BJhqZwLIAxML7o7wZ08rSPdmWruqJ2Y29yoDRHbagv efg9ZmHaZ7loGJUSCoZ06DZPRt2N7ARy1f1LBsLDk+Ybl1iE7RXg4lzebGzsSbKaM3V1 TVx1kbtBXIANEC1ACVfMrQsljSWaH/eV9KJoHvckmbRgaC2jArUzLoGBHuOuNdL8Az5G n8MGdjtkXphgXjFpHK28+1IxrlCojckgZ7cyD415GdVdXQhbXC8VI1JYb8xvZSrOVRMR 7awJEzPLy9Q1hdE05XVkYa5SjCKJBw+STeSd4oZiNDH9ZmQxxgEKkE3jG8JWPxXztAxm nq2A== X-Gm-Message-State: AOJu0YxepKPvDu+dQ6/6OTuMIskCeh+aF5k/ipySkfpfYRBBahO3410I EQP4Ea+Bn6ZjRASUZd/E5cQds/4/ksTwNAejlFAGePotoZsK/IcxbcP6nJxbCwe6IlzY8J8NSeY l6akiBw== X-Google-Smtp-Source: AGHT+IHqg7v/oM3O+Iza+gbHQ+Fut3uvvdzLynuyyGHbiI9eTt5zTPTdsfs0StG85k5cWuU3XEHxZlf+cm8= X-Received: from pldo13.prod.google.com ([2002:a17:903:8d:b0:27e:ed03:b5a5]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:e805:b0:295:ac6f:c899 with SMTP id d9443c01a7336-29df5dd24f3mr8573855ad.47.1764983468487; Fri, 05 Dec 2025 17:11:08 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 5 Dec 2025 17:10:48 -0800 In-Reply-To: <20251206011054.494190-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251206011054.494190-1-seanjc@google.com> X-Mailer: git-send-email 2.52.0.223.gf5cc29aaa4-goog Message-ID: <20251206011054.494190-2-seanjc@google.com> Subject: [PATCH v2 1/7] KVM: x86: Move kvm_rebooting to x86 From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Kiryl Shutsemau , Sean Christopherson , Paolo Bonzini Cc: linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, kvm@vger.kernel.org, Chao Gao , Dan Williams Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move kvm_rebooting, which is only read by x86, to KVM x86 so that it can be moved again to core x86 code. Add a "shutdown" arch hook to facilate setting the flag in KVM x86. Signed-off-by: Sean Christopherson Reviewed-by: Chao Gao --- arch/x86/kvm/x86.c | 13 +++++++++++++ arch/x86/kvm/x86.h | 1 + include/linux/kvm_host.h | 2 +- virt/kvm/kvm_main.c | 14 +++++++------- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 0c6d899d53dd..80cb882f19e2 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -694,6 +694,9 @@ static void drop_user_return_notifiers(void) kvm_on_user_return(&msrs->urn); } =20 +__visible bool kvm_rebooting; +EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_rebooting); + /* * Handle a fault on a hardware virtualization (VMX or SVM) instruction. * @@ -13100,6 +13103,16 @@ int kvm_arch_enable_virtualization_cpu(void) return 0; } =20 +void kvm_arch_shutdown(void) +{ + /* + * Set kvm_rebooting to indicate that KVM has asynchronously disabled + * hardware virtualization, i.e. that relevant errors and exceptions + * aren't entirely unexpected. + */ + kvm_rebooting =3D true; +} + void kvm_arch_disable_virtualization_cpu(void) { kvm_x86_call(disable_virtualization_cpu)(); diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index fdab0ad49098..40993348a967 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -54,6 +54,7 @@ struct kvm_host_values { u64 arch_capabilities; }; =20 +extern bool kvm_rebooting; void kvm_spurious_fault(void); =20 #define SIZE_OF_MEMSLOTS_HASHTABLE \ diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index d93f75b05ae2..a453fe6ce05a 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1621,6 +1621,7 @@ static inline void kvm_create_vcpu_debugfs(struct kvm= _vcpu *vcpu) {} #endif =20 #ifdef CONFIG_KVM_GENERIC_HARDWARE_ENABLING +void kvm_arch_shutdown(void); /* * kvm_arch_{enable,disable}_virtualization() are called on one CPU, under * kvm_usage_lock, immediately after/before 0=3D>1 and 1=3D>0 transitions = of @@ -2302,7 +2303,6 @@ static inline bool kvm_check_request(int req, struct = kvm_vcpu *vcpu) =20 #ifdef CONFIG_KVM_GENERIC_HARDWARE_ENABLING extern bool enable_virt_at_load; -extern bool kvm_rebooting; #endif =20 extern unsigned int halt_poll_ns; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index f1f6a71b2b5f..3278ee9381bd 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -5586,13 +5586,15 @@ bool enable_virt_at_load =3D true; module_param(enable_virt_at_load, bool, 0444); EXPORT_SYMBOL_FOR_KVM_INTERNAL(enable_virt_at_load); =20 -__visible bool kvm_rebooting; -EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_rebooting); - static DEFINE_PER_CPU(bool, virtualization_enabled); static DEFINE_MUTEX(kvm_usage_lock); static int kvm_usage_count; =20 +__weak void kvm_arch_shutdown(void) +{ + +} + __weak void kvm_arch_enable_virtualization(void) { =20 @@ -5646,10 +5648,9 @@ static int kvm_offline_cpu(unsigned int cpu) =20 static void kvm_shutdown(void) { + kvm_arch_shutdown(); + /* - * Disable hardware virtualization and set kvm_rebooting to indicate - * that KVM has asynchronously disabled hardware virtualization, i.e. - * that relevant errors and exceptions aren't entirely unexpected. * Some flavors of hardware virtualization need to be disabled before * transferring control to firmware (to perform shutdown/reboot), e.g. * on x86, virtualization can block INIT interrupts, which are used by @@ -5658,7 +5659,6 @@ static void kvm_shutdown(void) * 100% comprehensive. */ pr_info("kvm: exiting hardware virtualization\n"); - kvm_rebooting =3D true; on_each_cpu(kvm_disable_virtualization_cpu, NULL, 1); } =20 --=20 2.52.0.223.gf5cc29aaa4-goog