From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.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 20969287259 for ; Sat, 14 Feb 2026 01:27:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771032433; cv=none; b=b3tbKk4tZROmmbOJznoRiHBvm/EiO2Is5MBmJtmASxJnsUO69KZmUyqvELCUxmyu6ohDI3N+sGm1JkCac3rIGL9QxZ8Eq7EINP3nbzBLU4Jzlcoj+s2cCJIu1wKqypjfSjp2czSbPnpQJE/qdaHCtNfH5yRQHgSYQMoJ9OucdJU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771032433; c=relaxed/simple; bh=gnRLsQcZywazDuEdGGXGGq+fa2JWlZCKtOcI/j1sQ60=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ejoU758SM/nkgb66OBmYX0hMw+eDwC+nUqdrIHpb3qVVCJufM/5YhGQWDdcua55Zw8EKEqiIlqZdWUBR4v69ET7mUvkus+g/CYdBN3y6hY+bGb50eIua19gXAFZEayVHp3UV7NQo7K/TVffaUjwaQgptfwDvqRzAatk+pYfzwFM= 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=vOrgXoIC; arc=none smtp.client-ip=209.85.210.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="vOrgXoIC" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-824a2df507eso3589388b3a.2 for ; Fri, 13 Feb 2026 17:27:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1771032431; x=1771637231; darn=lists.linux.dev; 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=LlribCFdngaQSRseMvArVzR7Ue2wpxs9f06/EhF3nRU=; b=vOrgXoIClo+/YUJN5H/iUCet05SsrQ5T1FztK9mHI9SbIqisCt70DHTHB2uYfpNrh6 bdgEXidDdi0gRCBQBCaCv8xLUm977ETyfZ97kYPM0HyLnTBQqQvRvrHzGGbmLn9Q1p1v QsjoSqcGg5oordK3LMOG6rDzSEyLBc529vr+/rDatX56o/NIlTBA63xjA/g/q3pIMn2a gT4KiY1hgIh/l/XZaWS8TcCr1GMDlIpY1V+P9/25QD06WgFdtypS+7AgKKJBb1V9zqLI l5Ucx/PEKRvI6Bz0DjL9s55sKIpV8Cu4uyblEdVkvcRYptfFAX/26kkPfnyeyX8I5kN3 rcCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771032431; x=1771637231; 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=LlribCFdngaQSRseMvArVzR7Ue2wpxs9f06/EhF3nRU=; b=oV6nrhEHSUeLeu+XUy6AY620iPFSFvYI1zLL7PvGcuQ9mZ4KO9gcwNBaeODQabivAB 8B//+z9mBJdGa4fuGYw4JQK4mm5qPuYO9gnPvOp6i+j9HJtF8CiTzTbbqQ3qynBXMse3 PFAA7Lx5E+NZfdcfVWbRWVwdGMZ5p9tiPMjOdXy9i/bJkGxparMASe0EpB/osPJCXElf 8phD0f/5mQtjFbdVQzPfawsKFp7AIQg3wjRAt6Up+LDvfJxLtf0AWH36Req7orYnxUAZ z9apZSfLp0BqND8MAqqNBSb/2rkKbExfp4eejviPju5aBPC11zxpwcEPS6jVOqF/02+g OdQw== X-Forwarded-Encrypted: i=1; AJvYcCWACrDVLDW81kN6KU9BGiMJFbwVZwMlFhghMR0KNOK9l24E0MrpERrYhsQzrL03P7/yZoL+fvILJ6lQ@lists.linux.dev X-Gm-Message-State: AOJu0YwPnI+Y+YqESVMkW+u1Srbl0PGZegZUjFlfOL2qycTiMcFSkiC/ GNQib2U9MGIxhOvPdmu/iW9CfxsHOr8l0yckIDfIvPkGhuK7B0xHOC60sYOsXoXYJuap3pSOLMn 3SSz6Kw== X-Received: from pfbem2.prod.google.com ([2002:a05:6a00:3742:b0:823:c4bd:60eb]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:4b10:b0:81c:785e:1216 with SMTP id d2e1a72fcca58-824d932e621mr967760b3a.0.1771032431208; Fri, 13 Feb 2026 17:27:11 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 13 Feb 2026 17:26:49 -0800 In-Reply-To: <20260214012702.2368778-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260214012702.2368778-1-seanjc@google.com> X-Mailer: git-send-email 2.53.0.310.g728cabbaf7-goog Message-ID: <20260214012702.2368778-4-seanjc@google.com> Subject: [PATCH v3 03/16] KVM: x86: Move "kvm_rebooting" to kernel as "virt_rebooting" From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Kiryl Shutsemau , Peter Zijlstra , Arnaldo Carvalho de Melo , Namhyung Kim , Sean Christopherson , Paolo Bonzini Cc: linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, kvm@vger.kernel.org, linux-perf-users@vger.kernel.org, Chao Gao , Xu Yilun , Dan Williams Content-Type: text/plain; charset="UTF-8" Move "kvm_rebooting" to the kernel, exported for KVM, as one of many steps towards extracting the innermost VMXON and EFER.SVME management logic out of KVM and into to core x86. For lack of a better name, call the new file "hw.c", to yield "virt hardware" when combined with its parent directory. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/virt.h | 11 +++++++++++ arch/x86/kvm/svm/svm.c | 3 ++- arch/x86/kvm/svm/vmenter.S | 10 +++++----- arch/x86/kvm/vmx/tdx.c | 3 ++- arch/x86/kvm/vmx/vmenter.S | 2 +- arch/x86/kvm/vmx/vmx.c | 5 +++-- arch/x86/kvm/x86.c | 17 ++++++++--------- arch/x86/kvm/x86.h | 1 - arch/x86/virt/Makefile | 2 ++ arch/x86/virt/hw.c | 7 +++++++ 10 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 arch/x86/include/asm/virt.h create mode 100644 arch/x86/virt/hw.c diff --git a/arch/x86/include/asm/virt.h b/arch/x86/include/asm/virt.h new file mode 100644 index 000000000000..131b9bf9ef3c --- /dev/null +++ b/arch/x86/include/asm/virt.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASM_X86_VIRT_H +#define _ASM_X86_VIRT_H + +#include + +#if IS_ENABLED(CONFIG_KVM_X86) +extern bool virt_rebooting; +#endif + +#endif /* _ASM_X86_VIRT_H */ diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 8f8bc863e214..0ae66c770ebc 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -44,6 +44,7 @@ #include #include #include +#include #include @@ -495,7 +496,7 @@ static inline void kvm_cpu_svm_disable(void) static void svm_emergency_disable_virtualization_cpu(void) { - kvm_rebooting = true; + virt_rebooting = true; kvm_cpu_svm_disable(); } diff --git a/arch/x86/kvm/svm/vmenter.S b/arch/x86/kvm/svm/vmenter.S index 3392bcadfb89..d47c5c93c991 100644 --- a/arch/x86/kvm/svm/vmenter.S +++ b/arch/x86/kvm/svm/vmenter.S @@ -298,16 +298,16 @@ SYM_FUNC_START(__svm_vcpu_run) RESTORE_GUEST_SPEC_CTRL_BODY RESTORE_HOST_SPEC_CTRL_BODY (%_ASM_SP) -10: cmpb $0, _ASM_RIP(kvm_rebooting) +10: cmpb $0, _ASM_RIP(virt_rebooting) jne 2b ud2 -30: cmpb $0, _ASM_RIP(kvm_rebooting) +30: cmpb $0, _ASM_RIP(virt_rebooting) jne 4b ud2 -50: cmpb $0, _ASM_RIP(kvm_rebooting) +50: cmpb $0, _ASM_RIP(virt_rebooting) jne 6b ud2 -70: cmpb $0, _ASM_RIP(kvm_rebooting) +70: cmpb $0, _ASM_RIP(virt_rebooting) jne 8b ud2 @@ -394,7 +394,7 @@ SYM_FUNC_START(__svm_sev_es_vcpu_run) RESTORE_GUEST_SPEC_CTRL_BODY RESTORE_HOST_SPEC_CTRL_BODY %sil -3: cmpb $0, kvm_rebooting(%rip) +3: cmpb $0, virt_rebooting(%rip) jne 2b ud2 diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 5df9d32d2058..0c790eb0bfa6 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "capabilities.h" #include "mmu.h" #include "x86_ops.h" @@ -1994,7 +1995,7 @@ int tdx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t fastpath) * TDX_SEAMCALL_VMFAILINVALID. */ if (unlikely((vp_enter_ret & TDX_SW_ERROR) == TDX_SW_ERROR)) { - KVM_BUG_ON(!kvm_rebooting, vcpu->kvm); + KVM_BUG_ON(!virt_rebooting, vcpu->kvm); goto unhandled_exit; } diff --git a/arch/x86/kvm/vmx/vmenter.S b/arch/x86/kvm/vmx/vmenter.S index 4426d34811fc..8a481dae9cae 100644 --- a/arch/x86/kvm/vmx/vmenter.S +++ b/arch/x86/kvm/vmx/vmenter.S @@ -310,7 +310,7 @@ SYM_INNER_LABEL_ALIGN(vmx_vmexit, SYM_L_GLOBAL) RET .Lfixup: - cmpb $0, _ASM_RIP(kvm_rebooting) + cmpb $0, _ASM_RIP(virt_rebooting) jne .Lvmfail ud2 .Lvmfail: diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 967b58a8ab9d..fc6e3b620866 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -814,13 +815,13 @@ void vmx_emergency_disable_virtualization_cpu(void) int cpu = raw_smp_processor_id(); struct loaded_vmcs *v; - kvm_rebooting = true; + virt_rebooting = true; /* * Note, CR4.VMXE can be _cleared_ in NMI context, but it can only be * set in task context. If this races with VMX is disabled by an NMI, * VMCLEAR and VMXOFF may #UD, but KVM will eat those faults due to - * kvm_rebooting set. + * virt_rebooting set. */ if (!(__read_cr4() & X86_CR4_VMXE)) return; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 77edc24f8309..69937d14f5e1 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -83,6 +83,8 @@ #include #include #include +#include + #include #define CREATE_TRACE_POINTS @@ -700,9 +702,6 @@ static void drop_user_return_notifiers(void) kvm_on_user_return(&msrs->urn); } -__visible bool kvm_rebooting; -EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_rebooting); - /* * Handle a fault on a hardware virtualization (VMX or SVM) instruction. * @@ -713,7 +712,7 @@ EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_rebooting); noinstr void kvm_spurious_fault(void) { /* Fault while not rebooting. We want the trace. */ - BUG_ON(!kvm_rebooting); + BUG_ON(!virt_rebooting); } EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_spurious_fault); @@ -13184,16 +13183,16 @@ int kvm_arch_enable_virtualization_cpu(void) void kvm_arch_shutdown(void) { /* - * Set kvm_rebooting to indicate that KVM has asynchronously disabled + * Set virt_rebooting to indicate that KVM has asynchronously disabled * hardware virtualization, i.e. that errors and/or exceptions on SVM * and VMX instructions are expected and should be ignored. */ - kvm_rebooting = true; + virt_rebooting = true; /* - * Ensure kvm_rebooting is visible before IPIs are sent to other CPUs + * Ensure virt_rebooting is visible before IPIs are sent to other CPUs * to disable virtualization. Effectively pairs with the reception of - * the IPI (kvm_rebooting is read in task/exception context, but only + * the IPI (virt_rebooting is read in task/exception context, but only * _needs_ to be read as %true after the IPI function callback disables * virtualization). */ @@ -13214,7 +13213,7 @@ void kvm_arch_disable_virtualization_cpu(void) * disable virtualization arrives. Handle the extreme edge case here * instead of trying to account for it in the normal flows. */ - if (in_task() || WARN_ON_ONCE(!kvm_rebooting)) + if (in_task() || WARN_ON_ONCE(!virt_rebooting)) drop_user_return_notifiers(); else __module_get(THIS_MODULE); diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index b314649e5c02..94d4f07aaaa0 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -54,7 +54,6 @@ struct kvm_host_values { u64 arch_capabilities; }; -extern bool kvm_rebooting; void kvm_spurious_fault(void); #define SIZE_OF_MEMSLOTS_HASHTABLE \ diff --git a/arch/x86/virt/Makefile b/arch/x86/virt/Makefile index ea343fc392dc..6e485751650c 100644 --- a/arch/x86/virt/Makefile +++ b/arch/x86/virt/Makefile @@ -1,2 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y += svm/ vmx/ + +obj-$(subst m,y,$(CONFIG_KVM_X86)) += hw.o \ No newline at end of file diff --git a/arch/x86/virt/hw.c b/arch/x86/virt/hw.c new file mode 100644 index 000000000000..df3dc18d19b4 --- /dev/null +++ b/arch/x86/virt/hw.c @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include + +#include + +__visible bool virt_rebooting; +EXPORT_SYMBOL_FOR_KVM(virt_rebooting); -- 2.53.0.310.g728cabbaf7-goog