virtio: set ISR status when delivering queue MSI
RFC PATCH 1/1 virtio: set ISR status when delivering queue MSI
There is a discrepancy between dataplane and no-dataplane virtio behavior with respect to the ISR status register and MSI-X capability.
Without dataplane the Queue interrupt ISR status bit is set regardless of how the notification is delivered to the guest.
With dataplane the Queue interrupt ISR status bit is set only if the notification is delivered as an IRQ.
While both conform to the spec, QEMU should be consistent to minimize surprises with broken drivers.
This RFC patch shows the relevant code location and contains a possible fix which makes QEMU set the bit on the MSI dataplane code path.
--- hw/virtio/virtio.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
hw/virtio/virtio.c +14 -5
@@ -1192,7 +1192,7 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue *vq) }trace_virtio_notify (vdev, vq); - vdev->isr |=0x01 ; + vdev->isr |=0x01 ;// <= here we set ISR status even if we don't raise IRQ virtio_notify_vector (vdev, vq->vector); }
@@ -1757,16 +1757,25 @@ static void virtio_queue_guest_notifier_read(EventNotifier *n) } } +static void virtio_queue_guest_notifier_read_irqfd (EventNotifier *n) +{ +VirtQueue *vq =container_of (n, VirtQueue, guest_notifier); +if (event_notifier_test_and_clear (n)) { + vq->vdev->isr |=0x01 ; + } +} +void virtio_queue_set_guest_notifier_fd_handler (VirtQueue *vq,bool assign,bool with_irqfd) { -if (assign && !with_irqfd) { +if (assign) {event_notifier_set_handler (&vq->guest_notifier, - virtio_queue_guest_notifier_read); + with_irqfd ? + virtio_queue_guest_notifier_read_irqfd : + virtio_queue_guest_notifier_read); }else {event_notifier_set_handler (&vq->guest_notifier,NULL ); - } -if (!assign) { +/* Test and clear notifier before closing it, * in case poll callback didn't have time to run. */ virtio_queue_guest_notifier_read (&vq->guest_notifier);
Signature · 1 line
2.5.5
Quoted 10 lines · Ladi Prosek
There is a discrepancy between dataplane and no-dataplane virtio behavior with respect to the ISR status register and MSI-X capability.
Without dataplane the Queue interrupt ISR status bit is set regardless of how the notification is delivered to the guest.
With dataplane the Queue interrupt ISR status bit is set only if the notification is delivered as an IRQ.
Quoted 8 lines
While both conform to the spec, QEMU should be consistent to minimize surprises with broken drivers.
This RFC patch shows the relevant code location and contains a possible fix which makes QEMU set the bit on the MSI dataplane code path.
Signed-off-by Ladi Prosek <[email protected]>
How is this supposed to work when injecting interrupts using irqfd? If anything, I would rather drop setting the flag on non-dataplane.
Quoted 49 lines
--- hw/virtio/virtio.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)hw/virtio/virtio.c +14
-5@@ -1192,7 +1192,7 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue *vq) }trace_virtio_notify (vdev, vq); - vdev->isr |=0x01 ; + vdev->isr |=0x01 ;// <= here we set ISR status even if we don't raise IRQ virtio_notify_vector (vdev, vq->vector); }@@ -1757,16 +1757,25 @@ static void virtio_queue_guest_notifier_read(EventNotifier *n) } } +static void virtio_queue_guest_notifier_read_irqfd (EventNotifier *n) +{ +VirtQueue *vq =container_of (n, VirtQueue, guest_notifier); +if (event_notifier_test_and_clear (n)) { + vq->vdev->isr |=0x01 ; + } +} +void virtio_queue_set_guest_notifier_fd_handler (VirtQueue *vq,bool assign,bool with_irqfd) { -if (assign && !with_irqfd) { +if (assign) {event_notifier_set_handler (&vq->guest_notifier, - virtio_queue_guest_notifier_read); + with_irqfd ? + virtio_queue_guest_notifier_read_irqfd : + virtio_queue_guest_notifier_read); }else {event_notifier_set_handler (&vq->guest_notifier,NULL ); - } -if (!assign) { +/* Test and clear notifier before closing it, * in case poll callback didn't have time to run. */ virtio_queue_guest_notifier_read (&vq->guest_notifier);Signature · 1 line
2.5.5
Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · Ladi Prosek
There is a discrepancy between dataplane and no-dataplane virtio behavior with respect to the ISR status register and MSI-X capability.
Without dataplane the Queue interrupt ISR status bit is set regardless of how the notification is delivered to the guest.
With dataplane the Queue interrupt ISR status bit is set only if the notification is delivered as an IRQ.
While both conform to the spec, QEMU should be consistent to minimize surprises with broken drivers.
Quoted 8 lines
Quoted 5 lines
This RFC patch shows the relevant code location and contains a possible fix which makes QEMU set the bit on the MSI dataplane code path.
Signed-off-by Ladi Prosek <[email protected]>How is this supposed to work when injecting interrupts using irqfd? If anything, I would rather drop setting the flag on non-dataplane.
My bad, this is messed up. For some reason it works, or appears to be working at least.
The reason why I'd like to add setting the flag in dataplane is that if we go the other way we'll break drivers. I know for sure that there are drivers depending on this.
Quoted 50 lines
Quoted 50 lines
--- hw/virtio/virtio.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)hw/virtio/virtio.c +14
-6@@ -1192,7 +1192,7 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue *vq) }trace_virtio_notify (vdev, vq); - vdev->isr |=0x01 ; + vdev->isr |=0x01 ;// <= here we set ISR status even if we don't raise IRQ virtio_notify_vector (vdev, vq->vector); }@@ -1757,16 +1757,25 @@ static void virtio_queue_guest_notifier_read(EventNotifier *n) } } +static void virtio_queue_guest_notifier_read_irqfd (EventNotifier *n) +{ +VirtQueue *vq =container_of (n, VirtQueue, guest_notifier); +if (event_notifier_test_and_clear (n)) { + vq->vdev->isr |=0x01 ; + } +} +void virtio_queue_set_guest_notifier_fd_handler (VirtQueue *vq,bool assign,bool with_irqfd) { -if (assign && !with_irqfd) { +if (assign) {event_notifier_set_handler (&vq->guest_notifier, - virtio_queue_guest_notifier_read); + with_irqfd ? + virtio_queue_guest_notifier_read_irqfd : + virtio_queue_guest_notifier_read); }else {event_notifier_set_handler (&vq->guest_notifier,NULL ); - } -if (!assign) { +/* Test and clear notifier before closing it, * in case poll callback didn't have time to run. */ virtio_queue_guest_notifier_read (&vq->guest_notifier); --2.5.5
Quoted 24 lines · Ladi Prosek
Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · Ladi Prosek
There is a discrepancy between dataplane and no-dataplane virtio behavior with respect to the ISR status register and MSI-X capability.
Without dataplane the Queue interrupt ISR status bit is set regardless of how the notification is delivered to the guest.
With dataplane the Queue interrupt ISR status bit is set only if the notification is delivered as an IRQ.
While both conform to the spec, QEMU should be consistent to minimize surprises with broken drivers.
Quoted 8 lines
Quoted 5 lines
This RFC patch shows the relevant code location and contains a possible fix which makes QEMU set the bit on the MSI dataplane code path.
Signed-off-by Ladi Prosek <[email protected]>How is this supposed to work when injecting interrupts using irqfd? If anything, I would rather drop setting the flag on non-dataplane.
Quoted 6 lines
My bad, this is messed up. For some reason it works, or appears to be working at least.
The reason why I'd like to add setting the flag in dataplane is that if we go the other way we'll break drivers. I know for sure that there are drivers depending on this.
Rly? These are way out of spec then. I'd rather have these drivers
fixed: virtio said ISR can't be used with MSI since the 1st version where MSI was introduced. virtio 1.0 allows using ISR for config interrupts only.
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
--- hw/virtio/virtio.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)hw/virtio/virtio.c +14
-6@@ -1192,7 +1192,7 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue *vq) }trace_virtio_notify (vdev, vq); - vdev->isr |=0x01 ; + vdev->isr |=0x01 ;// <= here we set ISR status even if we don't raise IRQ virtio_notify_vector (vdev, vq->vector); }@@ -1757,16 +1757,25 @@ static void virtio_queue_guest_notifier_read(EventNotifier *n) } } +static void virtio_queue_guest_notifier_read_irqfd (EventNotifier *n) +{ +VirtQueue *vq =container_of (n, VirtQueue, guest_notifier); +if (event_notifier_test_and_clear (n)) { + vq->vdev->isr |=0x01 ; + } +} +void virtio_queue_set_guest_notifier_fd_handler (VirtQueue *vq,bool assign,bool with_irqfd) { -if (assign && !with_irqfd) { +if (assign) {event_notifier_set_handler (&vq->guest_notifier, - virtio_queue_guest_notifier_read); + with_irqfd ? + virtio_queue_guest_notifier_read_irqfd : + virtio_queue_guest_notifier_read); }else {event_notifier_set_handler (&vq->guest_notifier,NULL ); - } -if (!assign) { +/* Test and clear notifier before closing it, * in case poll callback didn't have time to run. */ virtio_queue_guest_notifier_read (&vq->guest_notifier); --2.5.5
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Ladi Prosek
Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · Ladi Prosek
There is a discrepancy between dataplane and no-dataplane virtio behavior with respect to the ISR status register and MSI-X capability.
Without dataplane the Queue interrupt ISR status bit is set regardless of how the notification is delivered to the guest.
With dataplane the Queue interrupt ISR status bit is set only if the notification is delivered as an IRQ.
While both conform to the spec, QEMU should be consistent to minimize surprises with broken drivers.
Quoted 8 lines
Quoted 5 lines
This RFC patch shows the relevant code location and contains a possible fix which makes QEMU set the bit on the MSI dataplane code path.
Signed-off-by Ladi Prosek <[email protected]>How is this supposed to work when injecting interrupts using irqfd? If anything, I would rather drop setting the flag on non-dataplane.
My bad, this is messed up. For some reason it works, or appears to be working at least.
Quoted 8 lines
Quoted 3 lines
The reason why I'd like to add setting the flag in dataplane is that if we go the other way we'll break drivers. I know for sure that there are drivers depending on this.
Rly? These are way out of spec then. I'd rather have these drivers
fixed: virtio said ISR can't be used with MSI since the 1st version where MSI was introduced. virtio 1.0 allows using ISR for config interrupts only.
Should the below paragraph be worded differently then? Or explicitly say that the contents of the status word is undefined? Specified since 1st version vs. actually behaving since 1st version. If you think it's safe to remove the |= 0x01 from the regular path I'll fix the drivers I know of, that's not a problem.
4.1.4.5.2 Driver Requirements: ISR status capability
If MSI-X capability is enabled, the driver SHOULD NOT access ISR status upon detecting a Queue Interrupt.
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
--- hw/virtio/virtio.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)hw/virtio/virtio.c +14
-6@@ -1192,7 +1192,7 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue *vq) }trace_virtio_notify (vdev, vq); - vdev->isr |=0x01 ; + vdev->isr |=0x01 ;// <= here we set ISR status even if we don't raise IRQ virtio_notify_vector (vdev, vq->vector); }@@ -1757,16 +1757,25 @@ static void virtio_queue_guest_notifier_read(EventNotifier *n) } } +static void virtio_queue_guest_notifier_read_irqfd (EventNotifier *n) +{ +VirtQueue *vq =container_of (n, VirtQueue, guest_notifier); +if (event_notifier_test_and_clear (n)) { + vq->vdev->isr |=0x01 ; + } +} +void virtio_queue_set_guest_notifier_fd_handler (VirtQueue *vq,bool assign,bool with_irqfd) { -if (assign && !with_irqfd) { +if (assign) {event_notifier_set_handler (&vq->guest_notifier, - virtio_queue_guest_notifier_read); + with_irqfd ? + virtio_queue_guest_notifier_read_irqfd : + virtio_queue_guest_notifier_read); }else {event_notifier_set_handler (&vq->guest_notifier,NULL ); - } -if (!assign) { +/* Test and clear notifier before closing it, * in case poll callback didn't have time to run. */ virtio_queue_guest_notifier_read (&vq->guest_notifier); --2.5.5
Quoted 33 lines · Ladi Prosek
Quoted 32 lines · Michael S. Tsirkin
Quoted 30 lines · Ladi Prosek
Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · Ladi Prosek
There is a discrepancy between dataplane and no-dataplane virtio behavior with respect to the ISR status register and MSI-X capability.
Without dataplane the Queue interrupt ISR status bit is set regardless of how the notification is delivered to the guest.
With dataplane the Queue interrupt ISR status bit is set only if the notification is delivered as an IRQ.
While both conform to the spec, QEMU should be consistent to minimize surprises with broken drivers.
Quoted 8 lines
Quoted 5 lines
This RFC patch shows the relevant code location and contains a possible fix which makes QEMU set the bit on the MSI dataplane code path.
Signed-off-by Ladi Prosek <[email protected]>How is this supposed to work when injecting interrupts using irqfd? If anything, I would rather drop setting the flag on non-dataplane.
My bad, this is messed up. For some reason it works, or appears to be working at least.
The reason why I'd like to add setting the flag in dataplane is that if we go the other way we'll break drivers. I know for sure that there are drivers depending on this.
Quoted 7 lines
Quoted 4 lines
Rly? These are way out of spec then. I'd rather have these drivers
fixed: virtio said ISR can't be used with MSI since the 1st version where MSI was introduced. virtio 1.0 allows using ISR for config interrupts only.Should the below paragraph be worded differently then? Or explicitly say that the contents of the status word is undefined?
It says don't access. How would you word a driver requirement otherwise?
Quoted 2 lines
Specified since
1st version vs. actually behaving since 1st version.
Yea. Yack. People just try whatever seems to work.
Quoted 3 lines
If you think it's
safe to remove the |=0x01from the regular path I'll fix the drivers I know of, that's not a problem.
Maybe we should keep the |= 0x01 in QEMU for now, but let's not mess up dataplace. Please fix the drivers.
Maybe remove |= 0x01 if legacy is disabled.
Quoted 55 lines
4.1.4.5.2 Driver Requirements: ISR status capability
If MSI-X capability is enabled, the driver SHOULD NOT access ISR status upon detecting a Queue Interrupt.
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
--- hw/virtio/virtio.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)hw/virtio/virtio.c +14
-6@@ -1192,7 +1192,7 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue *vq) }trace_virtio_notify (vdev, vq); - vdev->isr |=0x01 ; + vdev->isr |=0x01 ;// <= here we set ISR status even if we don't raise IRQ virtio_notify_vector (vdev, vq->vector); }@@ -1757,16 +1757,25 @@ static void virtio_queue_guest_notifier_read(EventNotifier *n) } } +static void virtio_queue_guest_notifier_read_irqfd (EventNotifier *n) +{ +VirtQueue *vq =container_of (n, VirtQueue, guest_notifier); +if (event_notifier_test_and_clear (n)) { + vq->vdev->isr |=0x01 ; + } +} +void virtio_queue_set_guest_notifier_fd_handler (VirtQueue *vq,bool assign,bool with_irqfd) { -if (assign && !with_irqfd) { +if (assign) {event_notifier_set_handler (&vq->guest_notifier, - virtio_queue_guest_notifier_read); + with_irqfd ? + virtio_queue_guest_notifier_read_irqfd : + virtio_queue_guest_notifier_read); }else {event_notifier_set_handler (&vq->guest_notifier,NULL ); - } -if (!assign) { +/* Test and clear notifier before closing it, * in case poll callback didn't have time to run. */ virtio_queue_guest_notifier_read (&vq->guest_notifier); --2.5.5
Quoted 39 lines · Michael S. Tsirkin
Quoted 38 lines · Ladi Prosek
Quoted 36 lines · Michael S. Tsirkin
Quoted 24 lines · Ladi Prosek
Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · Ladi Prosek
There is a discrepancy between dataplane and no-dataplane virtio behavior with respect to the ISR status register and MSI-X capability.
Without dataplane the Queue interrupt ISR status bit is set regardless of how the notification is delivered to the guest.
With dataplane the Queue interrupt ISR status bit is set only if the notification is delivered as an IRQ.
While both conform to the spec, QEMU should be consistent to minimize surprises with broken drivers.
Quoted 8 lines
Quoted 5 lines
This RFC patch shows the relevant code location and contains a possible fix which makes QEMU set the bit on the MSI dataplane code path.
Signed-off-by Ladi Prosek <[email protected]>How is this supposed to work when injecting interrupts using irqfd? If anything, I would rather drop setting the flag on non-dataplane.
Quoted 6 lines
My bad, this is messed up. For some reason it works, or appears to be working at least.
The reason why I'd like to add setting the flag in dataplane is that if we go the other way we'll break drivers. I know for sure that there are drivers depending on this.
Rly? These are way out of spec then. I'd rather have these drivers
fixed: virtio said ISR can't be used with MSI since the 1st version where MSI was introduced. virtio 1.0 allows using ISR for config interrupts only.
Quoted 4 lines
Quoted 2 lines
Should the below paragraph be worded differently then? Or explicitly say that the contents of the status word is undefined?
It says don't access. How would you word a driver requirement otherwise?
I would use a stronger mode than "SHOULD NOT". Playing devil's advocate, I could interpret the sentence as a suggested perf optimization - i.e. the interrupt message conveys the required information, no need to consult ISR status.
Quoted 5 lines
Quoted 2 lines
Specified since
1st version vs. actually behaving since 1st version.Yea. Yack. People just try whatever seems to work.
Quoted 8 lines
Quoted 3 lines
If you think it's
safe to remove the |=0x01from the regular path I'll fix the drivers I know of, that's not a problem.Maybe we should keep the |=
0x01in QEMU for now, but let's not mess up dataplace. Please fix the drivers.Maybe remove |=
0x01if legacy is disabled.
Ok, sounds good. Thanks!
Quoted 55 lines
Quoted 55 lines
4.1.4.5.2 Driver Requirements: ISR status capability
If MSI-X capability is enabled, the driver SHOULD NOT access ISR status upon detecting a Queue Interrupt.
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
--- hw/virtio/virtio.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)hw/virtio/virtio.c +14
-6@@ -1192,7 +1192,7 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue *vq) }trace_virtio_notify (vdev, vq); - vdev->isr |=0x01 ; + vdev->isr |=0x01 ;// <= here we set ISR status even if we don't raise IRQ virtio_notify_vector (vdev, vq->vector); }@@ -1757,16 +1757,25 @@ static void virtio_queue_guest_notifier_read(EventNotifier *n) } } +static void virtio_queue_guest_notifier_read_irqfd (EventNotifier *n) +{ +VirtQueue *vq =container_of (n, VirtQueue, guest_notifier); +if (event_notifier_test_and_clear (n)) { + vq->vdev->isr |=0x01 ; + } +} +void virtio_queue_set_guest_notifier_fd_handler (VirtQueue *vq,bool assign,bool with_irqfd) { -if (assign && !with_irqfd) { +if (assign) {event_notifier_set_handler (&vq->guest_notifier, - virtio_queue_guest_notifier_read); + with_irqfd ? + virtio_queue_guest_notifier_read_irqfd : + virtio_queue_guest_notifier_read); }else {event_notifier_set_handler (&vq->guest_notifier,NULL ); - } -if (!assign) { +/* Test and clear notifier before closing it, * in case poll callback didn't have time to run. */ virtio_queue_guest_notifier_read (&vq->guest_notifier); --2.5.5
Quoted 43 lines · Ladi Prosek
Quoted 42 lines · Michael S. Tsirkin
Quoted 40 lines · Ladi Prosek
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Ladi Prosek
Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · Ladi Prosek
There is a discrepancy between dataplane and no-dataplane virtio behavior with respect to the ISR status register and MSI-X capability.
Without dataplane the Queue interrupt ISR status bit is set regardless of how the notification is delivered to the guest.
With dataplane the Queue interrupt ISR status bit is set only if the notification is delivered as an IRQ.
While both conform to the spec, QEMU should be consistent to minimize surprises with broken drivers.
Quoted 8 lines
Quoted 5 lines
This RFC patch shows the relevant code location and contains a possible fix which makes QEMU set the bit on the MSI dataplane code path.
Signed-off-by Ladi Prosek <[email protected]>How is this supposed to work when injecting interrupts using irqfd? If anything, I would rather drop setting the flag on non-dataplane.
My bad, this is messed up. For some reason it works, or appears to be working at least.
Quoted 8 lines
Quoted 3 lines
The reason why I'd like to add setting the flag in dataplane is that if we go the other way we'll break drivers. I know for sure that there are drivers depending on this.
Rly? These are way out of spec then. I'd rather have these drivers
fixed: virtio said ISR can't be used with MSI since the 1st version where MSI was introduced. virtio 1.0 allows using ISR for config interrupts only.Should the below paragraph be worded differently then? Or explicitly say that the contents of the status word is undefined?
Quoted 6 lines
Quoted 1 line
It says don't access. How would you word a driver requirement otherwise?
I would use a stronger mode than "SHOULD NOT". Playing devil's advocate, I could interpret the sentence as a suggested perf optimization - i.e. the interrupt message conveys the required information, no need to consult ISR status.
OK, maybe it should be "MUST NOT".
Older virtio said it is not valid.
Want to reports this on virtio comments mailing list?
Quoted 71 lines
Quoted 5 lines
Quoted 2 lines
Specified since
1st version vs. actually behaving since 1st version.Yea. Yack. People just try whatever seems to work.
Quoted 8 lines
Quoted 3 lines
If you think it's
safe to remove the |=0x01from the regular path I'll fix the drivers I know of, that's not a problem.Maybe we should keep the |=
0x01in QEMU for now, but let's not mess up dataplace. Please fix the drivers.Maybe remove |=
0x01if legacy is disabled.Ok, sounds good. Thanks!
Quoted 55 lines
Quoted 55 lines
4.1.4.5.2 Driver Requirements: ISR status capability
If MSI-X capability is enabled, the driver SHOULD NOT access ISR status upon detecting a Queue Interrupt.
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
--- hw/virtio/virtio.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)hw/virtio/virtio.c +14
-6@@ -1192,7 +1192,7 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue *vq) }trace_virtio_notify (vdev, vq); - vdev->isr |=0x01 ; + vdev->isr |=0x01 ;// <= here we set ISR status even if we don't raise IRQ virtio_notify_vector (vdev, vq->vector); }@@ -1757,16 +1757,25 @@ static void virtio_queue_guest_notifier_read(EventNotifier *n) } } +static void virtio_queue_guest_notifier_read_irqfd (EventNotifier *n) +{ +VirtQueue *vq =container_of (n, VirtQueue, guest_notifier); +if (event_notifier_test_and_clear (n)) { + vq->vdev->isr |=0x01 ; + } +} +void virtio_queue_set_guest_notifier_fd_handler (VirtQueue *vq,bool assign,bool with_irqfd) { -if (assign && !with_irqfd) { +if (assign) {event_notifier_set_handler (&vq->guest_notifier, - virtio_queue_guest_notifier_read); + with_irqfd ? + virtio_queue_guest_notifier_read_irqfd : + virtio_queue_guest_notifier_read); }else {event_notifier_set_handler (&vq->guest_notifier,NULL ); - } -if (!assign) { +/* Test and clear notifier before closing it, * in case poll callback didn't have time to run. */ virtio_queue_guest_notifier_read (&vq->guest_notifier); --2.5.5
Quoted 46 lines · Michael S. Tsirkin
Quoted 45 lines · Ladi Prosek
Quoted 43 lines · Michael S. Tsirkin
Quoted 33 lines · Ladi Prosek
Quoted 32 lines · Michael S. Tsirkin
Quoted 30 lines · Ladi Prosek
Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · Ladi Prosek
There is a discrepancy between dataplane and no-dataplane virtio behavior with respect to the ISR status register and MSI-X capability.
Without dataplane the Queue interrupt ISR status bit is set regardless of how the notification is delivered to the guest.
With dataplane the Queue interrupt ISR status bit is set only if the notification is delivered as an IRQ.
While both conform to the spec, QEMU should be consistent to minimize surprises with broken drivers.
Quoted 8 lines
Quoted 5 lines
This RFC patch shows the relevant code location and contains a possible fix which makes QEMU set the bit on the MSI dataplane code path.
Signed-off-by Ladi Prosek <[email protected]>How is this supposed to work when injecting interrupts using irqfd? If anything, I would rather drop setting the flag on non-dataplane.
My bad, this is messed up. For some reason it works, or appears to be working at least.
The reason why I'd like to add setting the flag in dataplane is that if we go the other way we'll break drivers. I know for sure that there are drivers depending on this.
Quoted 7 lines
Quoted 4 lines
Rly? These are way out of spec then. I'd rather have these drivers
fixed: virtio said ISR can't be used with MSI since the 1st version where MSI was introduced. virtio 1.0 allows using ISR for config interrupts only.Should the below paragraph be worded differently then? Or explicitly say that the contents of the status word is undefined?
It says don't access. How would you word a driver requirement otherwise?
Quoted 8 lines
Quoted 4 lines
I would use a stronger mode than "SHOULD NOT". Playing devil's advocate, I could interpret the sentence as a suggested perf optimization - i.e. the interrupt message conveys the required information, no need to consult ISR status.
OK, maybe it should be "MUST NOT".
Older virtio said it is not valid.
Want to reports this on virtio comments mailing list?
Sure, will do.
Quoted 71 lines
Quoted 71 lines
Quoted 5 lines
Quoted 2 lines
Specified since
1st version vs. actually behaving since 1st version.Yea. Yack. People just try whatever seems to work.
Quoted 8 lines
Quoted 3 lines
If you think it's
safe to remove the |=0x01from the regular path I'll fix the drivers I know of, that's not a problem.Maybe we should keep the |=
0x01in QEMU for now, but let's not mess up dataplace. Please fix the drivers.Maybe remove |=
0x01if legacy is disabled.Ok, sounds good. Thanks!
Quoted 55 lines
Quoted 55 lines
4.1.4.5.2 Driver Requirements: ISR status capability
If MSI-X capability is enabled, the driver SHOULD NOT access ISR status upon detecting a Queue Interrupt.
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
Quoted 50 lines
--- hw/virtio/virtio.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)hw/virtio/virtio.c +14
-6@@ -1192,7 +1192,7 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue *vq) }trace_virtio_notify (vdev, vq); - vdev->isr |=0x01 ; + vdev->isr |=0x01 ;// <= here we set ISR status even if we don't raise IRQ virtio_notify_vector (vdev, vq->vector); }@@ -1757,16 +1757,25 @@ static void virtio_queue_guest_notifier_read(EventNotifier *n) } } +static void virtio_queue_guest_notifier_read_irqfd (EventNotifier *n) +{ +VirtQueue *vq =container_of (n, VirtQueue, guest_notifier); +if (event_notifier_test_and_clear (n)) { + vq->vdev->isr |=0x01 ; + } +} +void virtio_queue_set_guest_notifier_fd_handler (VirtQueue *vq,bool assign,bool with_irqfd) { -if (assign && !with_irqfd) { +if (assign) {event_notifier_set_handler (&vq->guest_notifier, - virtio_queue_guest_notifier_read); + with_irqfd ? + virtio_queue_guest_notifier_read_irqfd : + virtio_queue_guest_notifier_read); }else {event_notifier_set_handler (&vq->guest_notifier,NULL ); - } -if (!assign) { +/* Test and clear notifier before closing it, * in case poll callback didn't have time to run. */ virtio_queue_guest_notifier_read (&vq->guest_notifier); --2.5.5