Re: [PATCH] KVM: x86: Take PIC lock on KVM_GET_IRQCHIP path
From: Sean Christopherson
Date: Fri May 29 2026 - 10:02:50 EST
On Fri, May 29, 2026, Carlos López wrote:
> On 5/29/26 3:24 PM, Sean Christopherson wrote:
> > On Fri, May 29, 2026, Carlos López wrote:
> >> When userspace issues the KVM_SET_IRQCHIP ioctl to set the state of
> >> the PIC, kvm_vm_ioctl_set_irqchip() grabs @kvm->arch.vpic->lock before
> >> updating the state. However, the KVM_GET_IRQCHIP ioctl to retrieve the
> >> same PIC state does not grab such lock, potentially causing torn reads
> >> for userspace.
> >
> > Meh, if userspace hasn't fully paused the VM, save/restore is going to fail
> > anyways. Heck, torn reads is probably _better_ than the alternative, because
> > at least that might cause visible failure during the restore. If there are
> > concurrent modifications in-flight, then KVM_GET_IRQCHIP is going to return
> > stale data (assuming userspace doesn't redo KVM_GET_IRQCHIP), i.e. save/restore
> > will effectively corrupt the guest.
>
> Right, do you want a v2 to at least prevent userspace from reading a
> torn state? It seems wrong to have this asymmetry with KVM_SET_IRQCHIP
> and other save/restore ioctls (e.g. KVM_{G,S}ET_PIT).
Yeah, please send a v2. I 100% agree there should be symmetry, which is why
it's tempting to drop the locks for SET :-)