From nobody Mon Sep 28 23:53:39 2026 Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (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 6AF4E364043 for ; Fri, 14 Aug 2026 16:11:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786723898; cv=none; b=XaGS21l0pDmoRdIcPaD2gq/x5eqYwqyukVIaLCuo85tOFJI/igR50sGzziPItSVt7ptqEpXjV/wBI9nnZG/n7tbZGvw/Y4NdJMzyOQK7G0fPp54Pu8LEs6mQIky8bjMCrmOkqfIJP0evYIjDm2Q4txsmngPyRf0FFcihg+rpw1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786723898; c=relaxed/simple; bh=Sgd9XnUUTm8lQMTzKPLc9R4iKeBuq0hzQamu72aWQkw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=tDnhBJRPdKIRnq3McWduEMcn4sEzin+cQAyyA7RVxHWtMeElOdOZFjiD/Si9WrxPDUMze/UkFSjzityIBcliA7G4FLlN7A1dhfxMv9bBHsGWvrsMBgQnbpfpUKy0KLfFdn/9mJavSuAPyBJJsZOXLuwkKAxyK4FU9lhgxHxWfWA= 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=Dmv3CZDx; arc=none smtp.client-ip=209.85.215.200 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="Dmv3CZDx" Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-cbedbd182f5so783810a12.1 for ; Fri, 14 Aug 2026 09:11:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786723893; x=1787328693; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:from:to:cc:subject:date:message-id :reply-to:content-type; bh=1X+CoeJub4jvKxL0wB0sEMpRW5OuyV9yrXjVoPm820Q=; b=Dmv3CZDxb1iNFYf9MUT8YXRtomU2Xn1c5oA/cNbS9tXucfQ7i5JttHr3rGzPlhHjGy XVIjfBdH7450XuA776C3lkdBfrlex+kNXDqRq8RCmoDQQ7DmAm1p+9VN0/AspWQugjEm iS1TAn0+ClluysXLF+Hy+VxQOqNOftezyVeGy8M05PjoHDr1Ia3KmkupYjoTo4aLnqAB vcmc1gqiLxgI6xCMDdnG3TQrqpHqJGJn+EahebkjzA85C3EedsYiX1rAReioBl0SiOTz MG8z91nzkL9Vvn0WoInga/crfJY8kNZllm1w8F1Q0eouggDcZ7o7RgchyZJs0oGfUH/O xPoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786723893; x=1787328693; h=content-type: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:content-type; bh=1X+CoeJub4jvKxL0wB0sEMpRW5OuyV9yrXjVoPm820Q=; b=jJ3scryynHtiDwtHHuK63fDJYhhpfbPEOw6nBZLyWiEGwtNpFRx1feHKTBQLCaOo9Z O4pTchFuxx27AEJ5xDDb8l+lA0aGCsXY44/hlePGrUN98T1bSjMWWye0sIwCI1TvYi1j zY5qeWpRCdHq3pXaoHP6JuN9x1n9Uz5QN5g8ebMLgQYTYnAYLD3kDyZS446jkEYsblmP 5854sCk2eak5V2FQQykx7GwpKMW9gdSQHP7u4tsqirflbq4YuCpgoBbuBMQ0JHfqPFL3 JJpFndSZyHcTp343UMzf0ZejB2DmeVD53OHEbzlYCt6+eNkQjmi3f7YYfKO6J0INYPNA z7iQ== X-Forwarded-Encrypted: i=1; AHgh+Rp4Ng0RNtpRtquQGeUEklw8EDqRBHv+6iqj3ZOHbUyJAhapciDyFJUGCPopd5Vq5Qq2B802XzGu1omOpIU=@vger.kernel.org X-Gm-Message-State: AOJu0Yx8p6EQe1DQrChFj3y9zyMMMci1bHYAt4LLwDy/IVs7Hu6rxyHP FO7UJJQgd8LZyPFYTXWB30AXcVy0/bPAgX9l0bxa0M96b876tVkVTtbfCvMeLHi3V286E2PLhfD 0V52umQ== X-Received: from pfaw13.prod.google.com ([2002:a05:6a00:ab8d:b0:84a:1163:2ad0]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:9f86:b0:3cc:35e1:8dd9 with SMTP id adf61e73a8af0-3cc708b4270mr6825648637.17.1786723892552; Fri, 14 Aug 2026 09:11:32 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 14 Aug 2026 09:11:27 -0700 In-Reply-To: <20260814161129.2177118-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: <20260814161129.2177118-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.691.gc56d675ccc-goog Message-ID: <20260814161129.2177118-2-seanjc@google.com> Subject: [PATCH 1/3] KVM: VMX: Move the shared "IRQs off" exit handler(s) to common code From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini , Kiryl Shutsemau , Rick Edgecombe Cc: Dave Hansen , kvm@vger.kernel.org, x86@kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, Xiaoyao Li , Binbin Wu , Kai Huang , Yan Zhao Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move vmx_handle_exit_irqoff() and its helpers to common.h / main.c to capture that it's a common handler and to allow guarding against incorrectly using to_vmx(), and to allow for Cc: Rick Edgecombe Cc: Xiaoyao Li Cc: Binbin Wu Cc: Kai Huang Cc: Yan Zhao Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/common.h | 6 ++++ arch/x86/kvm/vmx/main.c | 69 +++++++++++++++++++++++++++++++++++ arch/x86/kvm/vmx/vmx.c | 74 -------------------------------------- arch/x86/kvm/vmx/x86_ops.h | 1 - 4 files changed, 75 insertions(+), 75 deletions(-) diff --git a/arch/x86/kvm/vmx/common.h b/arch/x86/kvm/vmx/common.h index 08005676702c..88f637c81353 100644 --- a/arch/x86/kvm/vmx/common.h +++ b/arch/x86/kvm/vmx/common.h @@ -74,6 +74,12 @@ static __always_inline bool is_td_vcpu(struct kvm_vcpu *= vcpu) { return false; } =20 #endif =20 +static inline bool is_xfd_nm_fault(struct kvm_vcpu *vcpu) +{ + return vcpu->arch.guest_fpu.fpstate->xfd && + !kvm_is_cr0_bit_set(vcpu, X86_CR0_TS); +} + static inline bool vt_is_tdx_private_gpa(struct kvm *kvm, gpa_t gpa) { /* For TDX the direct mask is the shared mask. */ diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c index 0ff3230fd95e..aa5b44bb212b 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -1,4 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include =20 #include "x86_ops.h" @@ -876,6 +877,74 @@ static int vt_gmem_max_mapping_level(struct kvm *kvm, = kvm_pfn_t pfn, #define vt_op_tdx_only(name) NULL #endif /* CONFIG_KVM_INTEL_TDX */ =20 +static void handle_nm_fault_irqoff(struct kvm_vcpu *vcpu) +{ + /* + * Save xfd_err to guest_fpu before interrupt is enabled, so the + * MSR value is not clobbered by the host activity before the guest + * has chance to consume it. + * + * Update the guest's XFD_ERR if and only if XFD is enabled, as the #NM + * interception may have been caused by L1 interception. Per the SDM, + * XFD_ERR is not modified for non-XFD #NM, i.e. if CR0.TS=3D1. + * + * Note, XFD_ERR is updated _before_ the #NM interception check, i.e. + * unlike CR2 and DR6, the value is not a payload that is attached to + * the #NM exception. + */ + if (is_xfd_nm_fault(vcpu)) + rdmsrq(MSR_IA32_XFD_ERR, vcpu->arch.guest_fpu.xfd_err); +} + +static void handle_exception_irqoff(struct kvm_vcpu *vcpu, u32 intr_info) +{ + /* if exit due to PF check for async PF */ + if (is_page_fault(intr_info)) + vcpu->arch.apf.host_apf_flags =3D kvm_read_and_reset_apf_flags(); + /* if exit due to NM, handle before interrupts are enabled */ + else if (is_nm_fault(intr_info)) + handle_nm_fault_irqoff(vcpu); + /* Handle machine checks before interrupts are enabled */ + else if (is_machine_check(intr_info)) + kvm_machine_check(); +} + +static void handle_external_interrupt_irqoff(struct kvm_vcpu *vcpu, + u32 intr_info) +{ + unsigned int vector =3D intr_info & INTR_INFO_VECTOR_MASK; + + if (KVM_BUG(!is_external_intr(intr_info), vcpu->kvm, + "unexpected VM-Exit interrupt info: 0x%x", intr_info)) + return; + + kvm_before_interrupt(vcpu, KVM_HANDLING_IRQ); + x86_entry_from_kvm(EVENT_TYPE_EXTINT, vector); + kvm_after_interrupt(vcpu); + + vcpu->arch.at_instruction_boundary =3D true; +} + +static void vmx_handle_exit_irqoff(struct kvm_vcpu *vcpu) +{ + if (to_vt(vcpu)->emulation_required) + return; + + switch (vmx_get_exit_reason(vcpu).basic) { + case EXIT_REASON_EXTERNAL_INTERRUPT: + handle_external_interrupt_irqoff(vcpu, vmx_get_intr_info(vcpu)); + break; + case EXIT_REASON_EXCEPTION_NMI: + handle_exception_irqoff(vcpu, vmx_get_intr_info(vcpu)); + break; + case EXIT_REASON_MCE_DURING_VMENTRY: + kvm_machine_check(); + break; + default: + break; + } +} + #define VMX_REQUIRED_APICV_INHIBITS \ (BIT(APICV_INHIBIT_REASON_DISABLED) | \ BIT(APICV_INHIBIT_REASON_ABSENT) | \ diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index e3bfe6aca1a0..aa0098723976 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5379,12 +5379,6 @@ bool vmx_guest_inject_ac(struct kvm_vcpu *vcpu) (kvm_get_rflags(vcpu) & X86_EFLAGS_AC); } =20 -static bool is_xfd_nm_fault(struct kvm_vcpu *vcpu) -{ - return vcpu->arch.guest_fpu.fpstate->xfd && - !kvm_is_cr0_bit_set(vcpu, X86_CR0_TS); -} - static int vmx_handle_page_fault(struct kvm_vcpu *vcpu, u32 error_code) { unsigned long cr2 =3D vmx_get_exit_qual(vcpu); @@ -7143,74 +7137,6 @@ void vmx_load_eoi_exitmap(struct kvm_vcpu *vcpu, u64= *eoi_exit_bitmap) vmcs_write64(EOI_EXIT_BITMAP3, eoi_exit_bitmap[3]); } =20 -static void handle_nm_fault_irqoff(struct kvm_vcpu *vcpu) -{ - /* - * Save xfd_err to guest_fpu before interrupt is enabled, so the - * MSR value is not clobbered by the host activity before the guest - * has chance to consume it. - * - * Update the guest's XFD_ERR if and only if XFD is enabled, as the #NM - * interception may have been caused by L1 interception. Per the SDM, - * XFD_ERR is not modified for non-XFD #NM, i.e. if CR0.TS=3D1. - * - * Note, XFD_ERR is updated _before_ the #NM interception check, i.e. - * unlike CR2 and DR6, the value is not a payload that is attached to - * the #NM exception. - */ - if (is_xfd_nm_fault(vcpu)) - rdmsrq(MSR_IA32_XFD_ERR, vcpu->arch.guest_fpu.xfd_err); -} - -static void handle_exception_irqoff(struct kvm_vcpu *vcpu, u32 intr_info) -{ - /* if exit due to PF check for async PF */ - if (is_page_fault(intr_info)) - vcpu->arch.apf.host_apf_flags =3D kvm_read_and_reset_apf_flags(); - /* if exit due to NM, handle before interrupts are enabled */ - else if (is_nm_fault(intr_info)) - handle_nm_fault_irqoff(vcpu); - /* Handle machine checks before interrupts are enabled */ - else if (is_machine_check(intr_info)) - kvm_machine_check(); -} - -static void handle_external_interrupt_irqoff(struct kvm_vcpu *vcpu, - u32 intr_info) -{ - unsigned int vector =3D intr_info & INTR_INFO_VECTOR_MASK; - - if (KVM_BUG(!is_external_intr(intr_info), vcpu->kvm, - "unexpected VM-Exit interrupt info: 0x%x", intr_info)) - return; - - kvm_before_interrupt(vcpu, KVM_HANDLING_IRQ); - x86_entry_from_kvm(EVENT_TYPE_EXTINT, vector); - kvm_after_interrupt(vcpu); - - vcpu->arch.at_instruction_boundary =3D true; -} - -void vmx_handle_exit_irqoff(struct kvm_vcpu *vcpu) -{ - if (to_vt(vcpu)->emulation_required) - return; - - switch (vmx_get_exit_reason(vcpu).basic) { - case EXIT_REASON_EXTERNAL_INTERRUPT: - handle_external_interrupt_irqoff(vcpu, vmx_get_intr_info(vcpu)); - break; - case EXIT_REASON_EXCEPTION_NMI: - handle_exception_irqoff(vcpu, vmx_get_intr_info(vcpu)); - break; - case EXIT_REASON_MCE_DURING_VMENTRY: - kvm_machine_check(); - break; - default: - break; - } -} - /* * The kvm parameter can be NULL (module initialization, or invocation bef= ore * VM creation). Be sure to check the kvm parameter before using it. diff --git a/arch/x86/kvm/vmx/x86_ops.h b/arch/x86/kvm/vmx/x86_ops.h index cdb38d940cfb..4dcaa36bbd8c 100644 --- a/arch/x86/kvm/vmx/x86_ops.h +++ b/arch/x86/kvm/vmx/x86_ops.h @@ -27,7 +27,6 @@ void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_even= t); void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu); void vmx_vcpu_put(struct kvm_vcpu *vcpu); int vmx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath); -void vmx_handle_exit_irqoff(struct kvm_vcpu *vcpu); int vmx_skip_emulated_instruction(struct kvm_vcpu *vcpu); void vmx_update_emulated_instruction(struct kvm_vcpu *vcpu); bool vmx_unhandleable_emulation_required(struct kvm_vcpu *vcpu); --=20 2.55.0.691.gc56d675ccc-goog From nobody Mon Sep 28 23:53:39 2026 Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (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 695C748B383 for ; Fri, 14 Aug 2026 16:11:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786723902; cv=none; b=NxVw4Q5z75gFT1+gFrkh7qFXkgn6lB94CIdOmDeHo0NxRS24KRvvJ9e+ztPrJRyFwKOJTWLCuWMdScFnOGTXXGxtAxEK2mAR/wtTfR6YYIjdSXuYxEmXT8HDUDIvMNvnhJ9K58OGVA0anco4vJlk87E4Vk4z7sjkxLqn69LE+MA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786723902; c=relaxed/simple; bh=jVDZ6RnPX9na/oXpRc2RUSVKCpg/b4zH+emyqfa+r6Q=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=UdPGMuh/Q6Qh/Nt4wza/Kjiozl4asfkBeDkxy+p6G5c7yP8uAzS3rvfUxxm5pplkQSfIecyIo1IM9gGBMSQ4+TIYP/WQ/b+h0bZnL+r/5OtiedW1XwLC2YR6GmIFjjR4Rdf+ty5+9FXvKaiVMBRDJljskB0OgO8AyesJhx/8rkY= 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=WGJtYjT/; arc=none smtp.client-ip=209.85.214.198 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="WGJtYjT/" Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-2cfc52ddc55so15800185ad.3 for ; Fri, 14 Aug 2026 09:11:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786723894; x=1787328694; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:from:to:cc:subject:date:message-id :reply-to:content-type; bh=npuY0OiAv0Qcgrb1+8fGuXoJuldQQTrhGouNj7zkH78=; b=WGJtYjT/1WAVWPtP7VwUJYF99H4zegvdZoXUWtc6LP+H41erJtTIAsfjmIqmYXPgmw 1ZrrneyH1UawgZx1ppU4sJOhdE8T2j8nPAWheXg3Sh5Gux+p1qK9a/jItHq4MSMxk2x8 NqPACZJWUbrb4vb5Bn+nEGmVG6u3Q46cFyjbMLeDky0G3+8RhpSjUtJGF0UUvFoc3vpw OcINpCRMdtD7Zpx+4JFMlhPPcxUpQmeQ4nuydjG9uZyeQC2QhVWc6SGBm0yO28ydrtbD hi5Ir4qyMa7ixIQ3IU2vgQ8idNTw6CsdOCNID9+7S3OBAE96mHEtaYAzaKWFPWYHx7sk UD+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786723894; x=1787328694; h=content-type: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:content-type; bh=npuY0OiAv0Qcgrb1+8fGuXoJuldQQTrhGouNj7zkH78=; b=sCWUmPEhKrksGU8L8TuQJ+CWeE+Ns9ZMLGN03sQ9KM/vxVvEXrjvlU51GKAPtxSRCE 7P8tMHfsvgsBKL77tO1aWjHV4/A+K5lsnT0joo3+qijLm4lmFNSiLUmx9Ei7ilSJrf2H BANk2utigveXG63vnjCpJGGfN4VzCUdOlbCFddVbHMxWFrzTnz7+77/T7IiDN2BhyVWX 4aS0hWf31O6Zfb/plD+t/dvro42E0u+oGbs0XbSuGFG8EYFDS+qJgP+Pl80sOW05ICyl 6+xW+fHGFWRxPSPRf05UXhSjPgZcKkSkfwP1sLWXChhrFvtIo/74hviz9aF7mIo9vSyw o6fQ== X-Forwarded-Encrypted: i=1; AHgh+RqOdkLOV5HRVN/+OlgIpz1J8DZ8kvyz6KDzMRlq2n52L4pc4TdMON7PHIuRfoYz9H2Eo3hVGWOAeMrn+Bg=@vger.kernel.org X-Gm-Message-State: AOJu0YxqcqXJzklO8uPt8rsd0PP4akcxG4IMPo9k9ZVx3O028xzChqRq FMElCUOXiuHXdk3k/Qx0+RWYt8p9yuu++z0kQu+/5pT/gk4l4h5fDd2DcSn8YLNGAcO1Tz+64Sz IR8I1tg== X-Received: from plou15.prod.google.com ([2002:a17:903:1aef:b0:2d1:1cee:1618]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ce86:b0:2c8:f34c:82c0 with SMTP id d9443c01a7336-2d3b0aeeb6cmr71992085ad.2.1786723893656; Fri, 14 Aug 2026 09:11:33 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 14 Aug 2026 09:11:28 -0700 In-Reply-To: <20260814161129.2177118-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: <20260814161129.2177118-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.691.gc56d675ccc-goog Message-ID: <20260814161129.2177118-3-seanjc@google.com> Subject: [PATCH 2/3] KVM: VMX: Disallowing using to_vmx() in common VT code From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini , Kiryl Shutsemau , Rick Edgecombe Cc: Dave Hansen , kvm@vger.kernel.org, x86@kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, Xiaoyao Li , Binbin Wu , Kai Huang , Yan Zhao Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Poison to_vmx() in main.c and posted_intr.c so that attempting to interpret the vCPU as a VMX vCPU will fail at compile time, as opposed to failing at runtime, or worse corrupting state without outright failing. Note, to_tdx() is buried in tdx.c, i.e. isn't broadly reachable, and so doesn't need the same treatment as to_vmx(). Signed-off-by: Sean Christopherson Reviewed-by: Binbin Wu > --- --- arch/x86/kvm/vmx/main.c | 2 ++ arch/x86/kvm/vmx/posted_intr.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c index aa5b44bb212b..95d89d809c19 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -11,6 +11,8 @@ #include "tdx.h" #include "tdx_arch.h" =20 +#pragma GCC poison to_vmx + #ifdef CONFIG_KVM_INTEL_TDX static_assert(offsetof(struct vcpu_vmx, vt) =3D=3D offsetof(struct vcpu_td= x, vt)); =20 diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c index 4a6d9a17da23..24221ba553be 100644 --- a/arch/x86/kvm/vmx/posted_intr.c +++ b/arch/x86/kvm/vmx/posted_intr.c @@ -14,6 +14,8 @@ #include "vmx.h" #include "tdx.h" =20 +#pragma GCC poison to_vmx + /* * Maintain a per-CPU list of vCPUs that need to be awakened by wakeup_han= dler() * when a WAKEUP_VECTOR interrupted is posted. vCPUs are added to the lis= t when --=20 2.55.0.691.gc56d675ccc-goog From nobody Mon Sep 28 23:53:39 2026 Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (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 658B547253A for ; Fri, 14 Aug 2026 16:11:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.200 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786723901; cv=none; b=T6kmX0BYI9M/ktUgoGbSqjJmwg2wO2hmBBJo8GDharXI3Np4EbcScxLtOH0AJmpuXXfnqn2TvQiKY7JqfI/+pKJK+zZ0G8hTTaghc+xtWyOdngbWI+G4BRpU5HHU2F56fhke5EctAwIm+FouQNQqgBA0Ir+oozJCuiEWRdFF+oA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786723901; c=relaxed/simple; bh=zec9Bn6B1wmg9c8Qo8oD/pbZR6VpiOSIiT/CmRsxMu0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RvtsEoc2i/imm02DW2LbXP05w0kbU7R9oUFwkpKOWPZ6sExKqOTDVUUkP4O9HqNyviYuwPoLbfbYMhxwqdwK7AdoSl8W6r2/4msTyNyjybNSCOrLvQPZe0ZMGnbQWlSjWrJ0Upgcr2lyagxMT+j0NQO9SymeOkvqsSuOsU39vow= 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=VErEhOnC; arc=none smtp.client-ip=209.85.210.200 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="VErEhOnC" Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-8485b7e18b4so1668946b3a.1 for ; Fri, 14 Aug 2026 09:11:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786723895; x=1787328695; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:from:to:cc:subject:date:message-id :reply-to:content-type; bh=FnW9wsBSO7OxZHDCPddc5vJtLigKE2XL3AEM5oSheVQ=; b=VErEhOnCRGn4ExQ/g4eAyOTHN6A4fVrVGlsNOmC5JsOKG8KKZ02kf2/PQ8+hPES+Ay DI1jcboE7UALlJuCJ81YW4aERXF6EfDHNnR1fr8gUsVV+W5pRTX/AFE4fj0+BH2FYpAh sBPW1Rz1bNWNP20Gf2IINsH2VdoaltjBHIDjz0gVeFfX46/shpcAFNE7HBdVOnsW5TjF Z779BWWQQe5UUjq3iZktg6DuwNJPiF+Ny0zlI5C/vT38YmL1rebOShK54qqXVCkrDJUr 53PWmqK3uiklX0uBcNigPK0lCzdB1yUQvy9cPjnCOeAS78tCs2bxAvxfYeftaSrlrjbG +9cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786723895; x=1787328695; h=content-type: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:content-type; bh=FnW9wsBSO7OxZHDCPddc5vJtLigKE2XL3AEM5oSheVQ=; b=OtxwQFZpbaf6kxtqNBjzHakkb8/GmU+7Kk7ToSwI9g1EcuD0KsHAr/PITfVyMMD8VU 6d+jBA39+DnedbhcpFHh992PypYFixDJcpI+l/TYLR2QQjWm7ROrUqr2NMxQCBeEucuL iXsJTnXmCasZ/cEp1hKJZUztqBjAF6IJdoXIrO9MQXuVzWf24rE0r+SbcyZDfsn0uFBT 47KH/6fbbRnSSzsVx7CShMZ4MJm88WXmdeFSFRk2qgXMxznvESUn8PinFCk5jTSDvtYT yuQxmYXQJwJ3n/WBH/seJzWCuJ367dtajIF+K+6PT0gSn/61ibKpDIjAkav1NH9T3ckF eCEQ== X-Forwarded-Encrypted: i=1; AHgh+RoGdHBMHbBSZXeDOOc7sdqMVaGX8kRYf6+3cfCTNzj8VuS4ALG8J0+I/zirSu7f+OA1pNOmoQFCQ/YygLU=@vger.kernel.org X-Gm-Message-State: AOJu0Yyr7dJmGc5+HDWHGhBVRxg2zKv2LnDdXe30aK/L6wTpO7e+ycVW osPnPFGj/NiHG1zZRro+fKUnuNWbdyH0Aw/55e81zcK9gOi/iFuFzgSHVNKp1jyQFU2omPXKBjJ yrMQ7NA== X-Received: from pfbgp12.prod.google.com ([2002:a05:6a00:3b8c:b0:84b:4480:8b65]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:4193:b0:848:56ff:6ced with SMTP id d2e1a72fcca58-84fde11d751mr8247332b3a.8.1786723894753; Fri, 14 Aug 2026 09:11:34 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 14 Aug 2026 09:11:29 -0700 In-Reply-To: <20260814161129.2177118-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: <20260814161129.2177118-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.691.gc56d675ccc-goog Message-ID: <20260814161129.2177118-4-seanjc@google.com> Subject: [PATCH 3/3] KVM: VMX: Rename posted interrupt prefixes from "vmx" to "vt" From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini , Kiryl Shutsemau , Rick Edgecombe Cc: Dave Hansen , kvm@vger.kernel.org, x86@kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, Xiaoyao Li , Binbin Wu , Kai Huang , Yan Zhao Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rename all common posted interrupt APIs that use a "vmx" prefix to instead use a "vt" prefix to capture that they are used for both VMX and TDX vCPUs. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/main.c | 4 ++-- arch/x86/kvm/vmx/posted_intr.c | 16 ++++++++-------- arch/x86/kvm/vmx/posted_intr.h | 8 ++++---- arch/x86/kvm/vmx/tdx.c | 4 ++-- arch/x86/kvm/vmx/vmx.c | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c index 95d89d809c19..9a113613a1f9 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -1075,8 +1075,8 @@ struct kvm_x86_ops vt_x86_ops __initdata =3D { =20 .update_cpu_dirty_logging =3D vt_op(update_cpu_dirty_logging), =20 - .pi_update_irte =3D vmx_pi_update_irte, - .pi_start_bypass =3D vmx_pi_start_bypass, + .pi_update_irte =3D vt_pi_update_irte, + .pi_start_bypass =3D vt_pi_start_bypass, =20 #ifdef CONFIG_X86_64 .set_hv_timer =3D vt_op(set_hv_timer), diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c index 24221ba553be..7a6a44587044 100644 --- a/arch/x86/kvm/vmx/posted_intr.c +++ b/arch/x86/kvm/vmx/posted_intr.c @@ -56,7 +56,7 @@ static int pi_try_set_control(struct pi_desc *pi_desc, u6= 4 *pold, u64 new) return 0; } =20 -void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu) +void vt_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu) { struct pi_desc *pi_desc =3D vcpu_to_pi_desc(vcpu); struct vcpu_vt *vt =3D to_vt(vcpu); @@ -146,7 +146,7 @@ void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu) pi_set_on(pi_desc); } =20 -static bool vmx_can_use_vtd_pi(struct kvm *kvm) +static bool vt_can_use_vtd_pi(struct kvm *kvm) { /* * Note, reading the number of possible bypass IRQs can race with a @@ -219,10 +219,10 @@ static bool vmx_needs_pi_wakeup(struct kvm_vcpu *vcpu) * back to the pi_wakeup_handler() function. */ return (vmx_can_use_ipiv(vcpu) && !is_td_vcpu(vcpu)) || - vmx_can_use_vtd_pi(vcpu->kvm); + vt_can_use_vtd_pi(vcpu->kvm); } =20 -void vmx_vcpu_pi_put(struct kvm_vcpu *vcpu) +void vt_vcpu_pi_put(struct kvm_vcpu *vcpu) { struct pi_desc *pi_desc =3D vcpu_to_pi_desc(vcpu); =20 @@ -294,17 +294,17 @@ bool pi_has_pending_interrupt(struct kvm_vcpu *vcpu) /* * Kick all vCPUs when the first possible bypass IRQ is attached to a VM, = as * blocking vCPUs may scheduled out without reconfiguring PID.NV to the wa= keup - * vector, i.e. if the bypass IRQ came along after vmx_vcpu_pi_put(). + * vector, i.e. if the bypass IRQ came along after vt_vcpu_pi_put(). */ -void vmx_pi_start_bypass(struct kvm *kvm) +void vt_pi_start_bypass(struct kvm *kvm) { - if (WARN_ON_ONCE(!vmx_can_use_vtd_pi(kvm))) + if (WARN_ON_ONCE(!vt_can_use_vtd_pi(kvm))) return; =20 kvm_make_all_cpus_request(kvm, KVM_REQ_UNBLOCK); } =20 -int vmx_pi_update_irte(struct kvm_kernel_irqfd *irqfd, struct kvm *kvm, +int vt_pi_update_irte(struct kvm_kernel_irqfd *irqfd, struct kvm *kvm, unsigned int host_irq, uint32_t guest_irq, struct kvm_vcpu *vcpu, u32 vector) { diff --git a/arch/x86/kvm/vmx/posted_intr.h b/arch/x86/kvm/vmx/posted_intr.h index a4af39948cf0..c5860ea828ae 100644 --- a/arch/x86/kvm/vmx/posted_intr.h +++ b/arch/x86/kvm/vmx/posted_intr.h @@ -8,16 +8,16 @@ =20 #include =20 -void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu); -void vmx_vcpu_pi_put(struct kvm_vcpu *vcpu); +void vt_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu); +void vt_vcpu_pi_put(struct kvm_vcpu *vcpu); void pi_wakeup_handler(void); void __init pi_init_cpu(int cpu); void pi_apicv_pre_state_restore(struct kvm_vcpu *vcpu); bool pi_has_pending_interrupt(struct kvm_vcpu *vcpu); -int vmx_pi_update_irte(struct kvm_kernel_irqfd *irqfd, struct kvm *kvm, +int vt_pi_update_irte(struct kvm_kernel_irqfd *irqfd, struct kvm *kvm, unsigned int host_irq, uint32_t guest_irq, struct kvm_vcpu *vcpu, u32 vector); -void vmx_pi_start_bypass(struct kvm *kvm); +void vt_pi_start_bypass(struct kvm *kvm); =20 static inline int pi_find_highest_vector(struct pi_desc *pi_desc) { diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index b272c20586a7..6e7a2acb3f92 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -716,7 +716,7 @@ void tdx_vcpu_load(struct kvm_vcpu *vcpu, int cpu) { struct vcpu_tdx *tdx =3D to_tdx(vcpu); =20 - vmx_vcpu_pi_load(vcpu, cpu); + vt_vcpu_pi_load(vcpu, cpu); if (vcpu->cpu =3D=3D cpu || !is_hkid_assigned(to_kvm_tdx(vcpu->kvm))) return; =20 @@ -826,7 +826,7 @@ static void tdx_prepare_switch_to_host(struct kvm_vcpu = *vcpu) =20 void tdx_vcpu_put(struct kvm_vcpu *vcpu) { - vmx_vcpu_pi_put(vcpu); + vt_vcpu_pi_put(vcpu); tdx_prepare_switch_to_host(vcpu); } =20 diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index aa0098723976..40bae81bc041 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1577,12 +1577,12 @@ void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu) =20 vmx_vcpu_load_vmcs(vcpu, cpu); =20 - vmx_vcpu_pi_load(vcpu, cpu); + vt_vcpu_pi_load(vcpu, cpu); } =20 void vmx_vcpu_put(struct kvm_vcpu *vcpu) { - vmx_vcpu_pi_put(vcpu); + vt_vcpu_pi_put(vcpu); =20 vmx_prepare_switch_to_host(to_vmx(vcpu)); } --=20 2.55.0.691.gc56d675ccc-goog