* [Qemu-devel] Question on ioeventfd behavior
@ 2016-02-26 7:51 Markus Armbruster
2016-02-26 9:41 ` Paolo Bonzini
0 siblings, 1 reply; 4+ messages in thread
From: Markus Armbruster @ 2016-02-26 7:51 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel
Unlike much of QEMU, memory.h actually has useful contracts, much
appreciated. Here's the one in question:
/**
* memory_region_add_eventfd: Request an eventfd to be triggered when a word
* is written to a location.
*
* Marks a word in an IO region (initialized with memory_region_init_io())
* as a trigger for an eventfd event. The I/O callback will not be called.
* The caller must be prepared to handle failure (that is, take the required
* action if the callback _is_ called).
*
* @mr: the memory region being updated.
* @addr: the address within @mr that is to be monitored
* @size: the size of the access to trigger the eventfd
* @match_data: whether to match against @data, instead of just @addr
* @data: the data to match against the guest write
* @fd: the eventfd to be triggered when @addr, @size, and @data all match.
**/
void memory_region_add_eventfd(MemoryRegion *mr,
hwaddr addr,
unsigned size,
bool match_data,
uint64_t data,
EventNotifier *e);
ivshmem uses it to implement its Doorbell register efficiently:
memory_region_add_eventfd(&s->ivshmem_mmio,
DOORBELL,
4,
true,
(posn << 16) | i,
&s->peers[posn].eventfds[i]);
This runs for every (posn, i) pair in use. The contract makes perfectly
clear what happens when the value written matches and everything works:
the matching s->peers[posn].eventfds[i] gets notified.
What exactly does "The caller must be prepared to handle failure" mean?
What are the failure modes?
Does "value written doesn't match" count as failure in the sense of this
clause? Rephrasing my question: what happens when the guest writes a
value to the Doorbell register that does not match any of the values
registered with memory_region_add_eventfd()? Is the I/O callback
called exactly as if ioeventfd was not in use?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] Question on ioeventfd behavior
2016-02-26 7:51 [Qemu-devel] Question on ioeventfd behavior Markus Armbruster
@ 2016-02-26 9:41 ` Paolo Bonzini
2016-02-26 9:58 ` Markus Armbruster
0 siblings, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2016-02-26 9:41 UTC (permalink / raw)
To: Markus Armbruster; +Cc: qemu-devel
On 26/02/2016 08:51, Markus Armbruster wrote:
> /**
> * memory_region_add_eventfd: Request an eventfd to be triggered when a word
> * is written to a location.
> *
> * Marks a word in an IO region (initialized with memory_region_init_io())
> * as a trigger for an eventfd event. The I/O callback will not be called.
> * The caller must be prepared to handle failure (that is, take the required
> * action if the callback _is_ called).
> *
> * @mr: the memory region being updated.
> * @addr: the address within @mr that is to be monitored
> * @size: the size of the access to trigger the eventfd
> * @match_data: whether to match against @data, instead of just @addr
> * @data: the data to match against the guest write
> * @fd: the eventfd to be triggered when @addr, @size, and @data all match.
> **/
> void memory_region_add_eventfd(MemoryRegion *mr,
> hwaddr addr,
> unsigned size,
> bool match_data,
> uint64_t data,
> EventNotifier *e);
>
> What exactly does "The caller must be prepared to handle failure" mean?
> What are the failure modes?
I think it simply meant that the caller should be ready for the case
where ioeventfd is _not_ implemented (e.g. when running on TCG) and the
MMIO callback is invoked anyway.
memory.c now implements a generic fallback in
memory_region_dispatch_write_eventfds, so that should not be necessary
anymore. I cannot think of other meanings of "failure mode".
In any case, ivshmem_io_write helpfully does the required
event_notifier_set, so you're good.
> Does "value written doesn't match" count as failure in the sense of this
> clause? Rephrasing my question: what happens when the guest writes a
> value to the Doorbell register that does not match any of the values
> registered with memory_region_add_eventfd()? Is the I/O callback
> called exactly as if ioeventfd was not in use?
Yes, the latter.
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] Question on ioeventfd behavior
2016-02-26 9:41 ` Paolo Bonzini
@ 2016-02-26 9:58 ` Markus Armbruster
2016-02-26 10:10 ` Paolo Bonzini
0 siblings, 1 reply; 4+ messages in thread
From: Markus Armbruster @ 2016-02-26 9:58 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel
Paolo Bonzini <pbonzini@redhat.com> writes:
> On 26/02/2016 08:51, Markus Armbruster wrote:
>> /**
>> * memory_region_add_eventfd: Request an eventfd to be triggered when a word
>> * is written to a location.
>> *
>> * Marks a word in an IO region (initialized with memory_region_init_io())
>> * as a trigger for an eventfd event. The I/O callback will not be called.
>> * The caller must be prepared to handle failure (that is, take the required
>> * action if the callback _is_ called).
>> *
>> * @mr: the memory region being updated.
>> * @addr: the address within @mr that is to be monitored
>> * @size: the size of the access to trigger the eventfd
>> * @match_data: whether to match against @data, instead of just @addr
>> * @data: the data to match against the guest write
>> * @fd: the eventfd to be triggered when @addr, @size, and @data all match.
>> **/
>> void memory_region_add_eventfd(MemoryRegion *mr,
>> hwaddr addr,
>> unsigned size,
>> bool match_data,
>> uint64_t data,
>> EventNotifier *e);
>>
>> What exactly does "The caller must be prepared to handle failure" mean?
>> What are the failure modes?
>
> I think it simply meant that the caller should be ready for the case
> where ioeventfd is _not_ implemented (e.g. when running on TCG) and the
> MMIO callback is invoked anyway.
>
> memory.c now implements a generic fallback in
> memory_region_dispatch_write_eventfds, so that should not be necessary
> anymore. I cannot think of other meanings of "failure mode".
>
> In any case, ivshmem_io_write helpfully does the required
> event_notifier_set, so you're good.
>
>> Does "value written doesn't match" count as failure in the sense of this
>> clause? Rephrasing my question: what happens when the guest writes a
>> value to the Doorbell register that does not match any of the values
>> registered with memory_region_add_eventfd()? Is the I/O callback
>> called exactly as if ioeventfd was not in use?
>
> Yes, the latter.
Double-checking: can i rely on ivshmem_io_write() getting called on a
write of a non-matching value?
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-02-26 10:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-26 7:51 [Qemu-devel] Question on ioeventfd behavior Markus Armbruster
2016-02-26 9:41 ` Paolo Bonzini
2016-02-26 9:58 ` Markus Armbruster
2016-02-26 10:10 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).