From: Sean Christopherson <seanjc@google.com>
To: Kai Huang <kai.huang@intel.com>
Cc: "bestswngs@gmail.com" <bestswngs@gmail.com>,
"jasowang@redhat.com" <jasowang@redhat.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
"stable@vger.kernel.org" <stable@vger.kernel.org>,
"zhanghy@sangfor.com" <zhanghy@sangfor.com>,
Zhong Wang <wangzhong.c0ss4ck@bytedance.com>,
"shixuanqing.11@bytedance.com" <shixuanqing.11@bytedance.com>
Subject: Re: [PATCH v2] KVM: x86: Destroy the PIC and IOAPIC before destroying vCPUs
Date: Mon, 6 Jul 2026 15:10:15 -0700 [thread overview]
Message-ID: <akwnx1ovr-Rkl6q7@google.com> (raw)
In-Reply-To: <51b8068149510179f59901b439e5f393c7757760.camel@intel.com>
On Mon, Jul 06, 2026, Kai Huang wrote:
>
> > Alternatively, KVM could simply destroy the I/O APIC during the "pre" phase
> > of VM destruction, but that gets more than a bit sketchy as KVM expects the
> > I/O APIC to exist if ioapic_in_kernel() is true, and nested virtualization
> > in particular has a bad habit of touching VM-scope state during vCPU
> > destruction. E.g. attempting to free the PIC during the pre phase would
> > lead to a NULL pointer dereference in kvm_cpu_has_extint(), and it's not
> > hard to imagine the I/O APIC having a similar flaw.
>
> Hmm seems vmx_vcpu_free() can eventually call into kvm_cpu_has_extint() via
> nested_vmx_vmexit(). Thanks for pointing out.
Yeah, I found out the hard way :-)
> > Fixes: 17bcd7144263 ("KVM: x86: Free vCPUs before freeing VM state")
> > Reported-by: <zdi-disclosures@trendmicro.com>
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Sean Christopherson <seanjc@google.com>
> >
> > diff --git arch/x86/kvm/x86.c arch/x86/kvm/x86.c
> > index 0626e835e9eb..a0cc74c8ded1 100644
> > --- arch/x86/kvm/x86.c
> > +++ arch/x86/kvm/x86.c
> > @@ -9942,6 +9942,8 @@ void kvm_arch_pre_destroy_vm(struct kvm *kvm)
> > */
> > #ifdef CONFIG_KVM_IOAPIC
> > kvm_free_pit(kvm);
> > + if (kvm->arch.vioapic)
> > + cancel_delayed_work_sync(&kvm->arch.vioapic->eoi_inject);
>
> Maybe add a comment to explain why we cannot destroy IOAPIC and PIC here?
Hmm, agreed, the block comment above can/should be extended to explain why it's
ok to destroy the PIT, but not the PIC or I/O APIC.
next prev parent reply other threads:[~2026-07-06 22:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260705045450.1325048-2-bestswngs@gmail.com>
2026-07-06 18:00 ` [PATCH v2] KVM: x86: Destroy the PIC and IOAPIC before destroying vCPUs Weiming Shi
2026-07-06 18:20 ` Sean Christopherson
2026-07-06 22:06 ` Huang, Kai
2026-07-06 22:10 ` Sean Christopherson [this message]
2026-07-06 22:33 ` Huang, Kai
2026-07-06 18:20 ` sashiko-bot
2026-07-07 6:32 ` [syzbot ci] " syzbot ci
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=akwnx1ovr-Rkl6q7@google.com \
--to=seanjc@google.com \
--cc=bestswngs@gmail.com \
--cc=jasowang@redhat.com \
--cc=kai.huang@intel.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=shixuanqing.11@bytedance.com \
--cc=stable@vger.kernel.org \
--cc=wangzhong.c0ss4ck@bytedance.com \
--cc=zhanghy@sangfor.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox