Skip to content
Snippets Groups Projects
Commit 8d48ef43 authored by Nadav Har'El's avatar Nadav Har'El
Browse files

Revert 4c1dd505

I'm returning Dor's original virtio_driver::wait_for_queue().

The rewrite just masked, with its slightly different timing and redundant
second check before waiting, the real bug which a missing memory barrier
(see separate patch fixing that).

Dor's original code has the good feature that after waking up from a
sleep - when presumably we already have something in the queue - we
check the queue before pessimisticly enabling the host notifications.
So let's use Dor's original code.
parent 7ab8afa5
No related branches found
No related tags found
No related merge requests found
......@@ -192,23 +192,24 @@ vring* virtio_driver::get_virt_queue(unsigned idx)
void virtio_driver::wait_for_queue(vring* queue, bool (vring::*pred)() const)
{
if ((queue->*pred)()) {
return;
}
queue->enable_interrupts();
// It is possible that after checking pred() and before enabling
// interrupts, the delivered us a packet, for which we will not get an
// interrupt. So we much check again.
if ((queue->*pred)()) {
queue->disable_interrupts();
return;
}
sched::thread::wait_until([&] {
// Need to re-enable interrupts as the interrupt disabled them.
queue->enable_interrupts();
return (queue->*pred)();
sched::thread::wait_until([queue,pred] {
bool have_elements = (queue->*pred)();
if (!have_elements) {
queue->enable_interrupts();
// we must check that the ring is not empty *after*
// we enable interrupts to avoid a race where a packet
// may have been delivered between queue->used_ring_not_empty()
// and queue->enable_interrupts() above
have_elements = (queue->*pred)();
if (have_elements) {
queue->disable_interrupts();
}
}
trace_virtio_wait_for_queue(queue, have_elements);
return have_elements;
});
queue->disable_interrupts();
}
u32 virtio_driver::get_device_features(void)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment