From: "Jiaming Fan" <fan.jiaming@hotmail.com>
To: "Sean Christopherson" <seanjc@google.com>
Cc: "Matthew Leach" <matthew.leach@collabora.com>,
"Paolo Bonzini" <pbonzini@redhat.com>, <kvm@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <kernel@collabora.com>
Subject: Re: [PATCH] KVM: x86: Reevaluate pending interrupts when enabling ExtINT through LVT0
Date: Mon, 16 Nov 2026 14:17:15 +0000 [thread overview]
Message-ID: <OS3PR01MB10251C0B5CDCF9538DA3A1727E77C2@OS3PR01MB10251.jpnprd01.prod.outlook.com> (raw)
In-Reply-To: <auuQ8pE439EB63tm@google.com>
On Wed, Nov 04, 2026, Sean Christopherson wrote:
> Ahh, but there's nowhere for edge-triggered events to be latched, so this only
> affects level-triggered events. Which means, this?
>
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index d6e5fbc3c58c..b72930a8516d 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -2554,6 +2554,8 @@ static int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
> val |= APIC_LVT_MASKED;
> val &= apic_lvt_mask[index];
> kvm_lapic_set_reg(apic, reg, val);
> + if (!(val & APIC_LVT_MASKED) && (val & APIC_LVT_LEVEL_TRIGGER))
> + kvm_make_request(KVM_REQ_EVENT, apic->vcpu);
> break;
> }
The trigger mode check doesn't catch the case Matthew hit. Linux's
setup_local_APIC() writes LVT0 as plain APIC_DM_EXTINT, without
APIC_LVT_LEVEL_TRIGGER, so no request is made and the "noapic" hang
remains. For ExtINT the pending interrupt is latched in the 8259A,
whose output stays asserted until the guest acks it, not in the LVT
entry, so the trigger mode bit doesn't tell whether anything is
pending. Your first version (any unmasked LVT) does work for LVT0.
There is a second path with the same problem that neither version
covers: hardware-disabling the APIC through IA32_APIC_BASE. With the
APIC disabled, kvm_apic_accept_pic_intr() returns true, so an ExtINT
latched while LVT0 was masked becomes deliverable, but
__kvm_apic_set_base() doesn't request KVM_REQ_EVENT either:
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -2825,6 +2825,7 @@ static void __kvm_apic_set_base(struct kvm_vcpu *vcpu, u64 value)
} else {
static_branch_inc(&apic_hw_disabled.key);
atomic_set_release(&apic->vcpu->kvm->arch.apic_map_dirty, DIRTY);
+ kvm_make_request(KVM_REQ_EVENT, vcpu);
}
}
I ran into the same hang independently (a small VMM booting Linux with
"noapic" on the in-kernel irqchip, roughly 1 in 5 boots when nested) and
wrote a selftest that reproduces both paths deterministically. The
guest programs the master PIC and masks LVT0, the host raises IRQ4 with
KVM_IRQ_LINE and checks that the PIC latched it, then the guest unmasks
LVT0 (directly, or after an SPIV soft-disable as setup_local_APIC()
does) or hardware-disables the APIC, and opens a single interrupt window
(sti; nop; cli) to count deliveries. It runs with xAPIC and x2APIC.
Results on kvm-x86/next (cbe54fc3462b), 3+ runs each, all deterministic:
kernel selftest result
------------------------------------- ----------------------------------
unpatched "LVT0 unmasked after masking:
got 1 IRQs, expected 2"
Matthew's v1 condition "APIC hardware-disabled:
got 3 IRQs, expected 4"
any unmasked LVT (your 1st version) "APIC hardware-disabled:
got 3 IRQs, expected 4"
unmasked + level (your 2nd version) "LVT0 unmasked after masking:
got 1 IRQs, expected 2"
any unmasked LVT + APIC_BASE fix pass
Tested on AMD only, nested under QEMU with AVIC disabled. Not tested on
Intel or with APICv/AVIC enabled. With Matthew's condition plus the
APIC_BASE fix, the full KVM selftests differ from the unpatched kernel
only in the new test, and kvm-unit-tests show no differences beyond the
"MOV SS + watchpoint" cases of the debug test, which fail intermittently
on both kernels in this nested setup. I haven't run the full suites
with your first version yet.
Matthew, are you planning a v2? If so, I'm happy to hand over the
selftest and the APIC_BASE fix. Otherwise I can post a series with your
patch (reworked per Sean's first suggestion) followed by the APIC_BASE
fix and the selftest.
Thanks,
Jiaming
prev parent reply other threads:[~2026-11-16 14:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 12:49 Matthew Leach
2026-11-04 20:09 ` Sean Christopherson
2026-11-16 14:17 ` Jiaming Fan [this message]
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=OS3PR01MB10251C0B5CDCF9538DA3A1727E77C2@OS3PR01MB10251.jpnprd01.prod.outlook.com \
--to=fan.jiaming@hotmail.com \
--cc=kernel@collabora.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matthew.leach@collabora.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.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
all inboxes | Powered by JetHome®