From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: Maxim Levitsky <mlevitsk@redhat.com>,
Sean Christopherson <seanjc@google.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Paolo Bonzini <pbonzini@redhat.com>, Peter Xu <peterx@redhat.com>,
"Maciej S. Szmigiero" <maciej.szmigiero@oracle.com>
Subject: Re: QEMU's Hyper-V HV_X64_MSR_EOM is broken with split IRQCHIP
Date: Thu, 06 Mar 2025 11:00:29 +0100 [thread overview]
Message-ID: <87senqo4w2.fsf@redhat.com> (raw)
In-Reply-To: <87a59zq0x2.fsf@redhat.com>
Vitaly Kuznetsov <vkuznets@redhat.com> writes:
> Maxim Levitsky <mlevitsk@redhat.com> writes:
>
>> On Tue, 2025-03-04 at 15:46 +0100, Vitaly Kuznetsov wrote:
>>> Sean Christopherson <seanjc@google.com> writes:
>>>
>>> > On Tue, Mar 04, 2025, Vitaly Kuznetsov wrote:
>>> > > Sean Christopherson <seanjc@google.com> writes:
>>> > >
>>> > > > FYI, QEMU's Hyper-V emulation of HV_X64_MSR_EOM has been broken since QEMU commit
>>> > > > c82d9d43ed ("KVM: Kick resamplefd for split kernel irqchip"), as nothing in KVM
>>> > > > will forward the EOM notification to userspace. I have no idea if anything in
>>> > > > QEMU besides hyperv_testdev.c cares.
>>> > >
>>> > > The only VMBus device in QEMU besides the testdev seems to be Hyper-V
>>> > > ballooning driver, Cc: Maciej to check whether it's a real problem for
>>> > > it or not.
>>> > >
>>> > > > The bug is reproducible by running the hyperv_connections KVM-Unit-Test with a
>>> > > > split IRQCHIP.
>>> > >
>>> > > Thanks, I can reproduce the problem too.
>>> > >
>>> > > > Hacking QEMU and KVM (see KVM commit 654f1f13ea56 ("kvm: Check irqchip mode before
>>> > > > assign irqfd") as below gets the test to pass. Assuming that's not a palatable
>>> > > > solution, the other options I can think of would be for QEMU to intercept
>>> > > > HV_X64_MSR_EOM when using a split IRQCHIP, or to modify KVM to do KVM_EXIT_HYPERV_SYNIC
>>> > > > on writes to HV_X64_MSR_EOM with a split IRQCHIP.
>>> > >
>>> > > AFAIR, Hyper-V message interface is a fairly generic communication
>>> > > mechanism which in theory can be used without interrupts at all: the
>>> > > corresponding SINT can be masked and the guest can be polling for
>>> > > messages, proccessing them and then writing to HV_X64_MSR_EOM to trigger
>>> > > delivery on the next queued message. To support this scenario on the
>>> > > backend, we need to receive HV_X64_MSR_EOM writes regardless of whether
>>> > > irqchip is split or not. (In theory, we can get away without this by
>>> > > just checking if pending messages can be delivered upon each vCPU entry
>>> > > but this can take an undefined amount of time in some scenarios so I
>>> > > guess we're better off with notifications).
>>> >
>>> > Before c82d9d43ed ("KVM: Kick resamplefd for split kernel irqchip"), and without
>>> > a split IRCHIP, QEMU gets notified via eventfd. On writes to HV_X64_MSR_EOM, KVM
>>> > invokes irq_acked(), i.e. irqfd_resampler_ack(), for all SINT routes. The eventfd
>>> > signal gets back to sint_ack_handler(), which invokes msg_retry() to re-post the
>>> > message.
>>> >
>>> > I.e. trapping HV_X64_MSR_EOM on would be a slow path relative to what's there for
>>> > in-kernel IRQCHIP.
>>>
>>> My understanding is that the only type of message which requires fast
>>> processing is STIMER messages but we don't do stimers in userspace. I
>>> guess it is possible to have a competing 'noisy neighbough' in userspace
>>> draining message slots but then we are slow anyway.
>>>
>>
>> Hi,
>>
>> AFAIK, HV_X64_MSR_EOM is only one of the ways for the guest to signal that it processed the SYNIC message.
>>
>> Guest can also signal that it finished processing a SYNIC message using HV_X64_MSR_EOI or even by writing to EOI
>> local apic register, and I actually think that the later is what is used by at least recent Windows.
>>
>
> Hyper-V SynIC has two distinct concepts: "messages" and "events". While
> events are just flags (like interrupts), messages actually carry
> information and the recipient is responsible for clearing message slot
> (there are only 16 of them per vCPU AFAIR). Strictly speaking,
> HV_X64_MSR_EOM is optional and hypervisor may deliver a new message to
> an empty slot at any time. It may use EOI as a trigger but note that
> not every message delivery results in an interrupt as e.g. SINT can be
> configured in 'polling' mode -- and that's when HV_X64_MSR_EOM comes
> handy.
>
Thinking more about this, I believe we should not be using eventfd for
delivering writes to HV_X64_MSR_EOM to VMM at all. Namely, writes to
HV_X64_MSR_EOM should not invoke irq_acked(): it should be valid for a
guest to poll for messages by writing to HV_X64_MSR_EOM within the
interrupt handler, drain the queue and then write to the EOI
register. In this case, the VMM may want to distinguish between EOI and
EOM. We can do a separate eventfd, of course, but I think it's an
overkill and 'slow' processing will do just fine.
--
Vitaly
prev parent reply other threads:[~2025-03-06 10:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-03 23:57 QEMU's Hyper-V HV_X64_MSR_EOM is broken with split IRQCHIP Sean Christopherson
2025-03-04 12:59 ` Vitaly Kuznetsov
2025-03-04 13:50 ` Maciej S. Szmigiero
2025-03-04 14:24 ` Sean Christopherson
2025-03-04 14:46 ` Vitaly Kuznetsov
2025-03-04 21:31 ` Maxim Levitsky
2025-03-05 9:31 ` Vitaly Kuznetsov
2025-03-06 10:00 ` Vitaly Kuznetsov [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=87senqo4w2.fsf@redhat.com \
--to=vkuznets@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maciej.szmigiero@oracle.com \
--cc=mlevitsk@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@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