Fixes for virtio PCI interrupt handling
cover Fixes for virtio PCI interrupt handling
Please consider these simple fixes and cleanups to legacy interrupt handling for virtio PCI devices.
Keir Fraser (3):
virtio/pci: Level-trigger the legacy IRQ line in all cases virtio/pci: Treat PCI ISR as a set of bit flags virtio/pci: Use consistent naming for the PCI ISR bit flags
virtio/pci-legacy.c | 2 +- virtio/pci.c | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-)
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
PATCH 1/3 virtio/pci: Level-trigger the legacy IRQ line in all cases
The PCI legacy IRQ line is level triggered, but is treated as edge triggered via kvm__irq_trigger() for signalling of config changes.
Fix this by using kvm__irq_level(), as for queue signalling.
--- virtio/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
virtio/pci.c +1 -1
@@ -264,7 +264,7 @@ int virtio_pci__signal_config(struct kvm *kvm, struct virtio_device *vdev)kvm__irq_trigger (kvm, vpci->config_gsi); }else { vpci->isr =VIRTIO_PCI_ISR_CONFIG ; -kvm__irq_trigger (kvm, vpci->legacy_irq_line); +kvm__irq_line (kvm, vpci->legacy_irq_line,VIRTIO_IRQ_HIGH ); }return 0 ;
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
PATCH 2/3 virtio/pci: Treat PCI ISR as a set of bit flags
In reply to Keir FraserThe PCI ISR is defined in the virtio spec as a set of flags which can be bitwise ORed together. Therefore we should avoid clearing previously-set flags.
--- virtio/pci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
virtio/pci.c +2 -2
@@ -239,7 +239,7 @@ int virtio_pci__signal_vq(struct kvm *kvm, struct virtio_device *vdev, u32 vq)else kvm__irq_trigger (kvm, vpci->gsis[vq]); }else { - vpci->isr =VIRTIO_IRQ_HIGH ; + vpci->isr |=VIRTIO_IRQ_HIGH ;kvm__irq_line (kvm, vpci->legacy_irq_line,VIRTIO_IRQ_HIGH ); }return 0 ;
@@ -263,7 +263,7 @@ int virtio_pci__signal_config(struct kvm *kvm, struct virtio_device *vdev)else kvm__irq_trigger (kvm, vpci->config_gsi); }else { - vpci->isr =VIRTIO_PCI_ISR_CONFIG ; + vpci->isr |=VIRTIO_PCI_ISR_CONFIG ;kvm__irq_line (kvm, vpci->legacy_irq_line,VIRTIO_IRQ_HIGH ); }
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
PATCH 3/3 virtio/pci: Use consistent naming for the PCI ISR bit flags
In reply to Keir FraserAvoid using VIRTIO_IRQ_{HIGH,LOW} which belong to a different namespace. Instead define VIRTIO_PCI_ISR_QUEUE as a logical extension of the VIRTIO_PCI_ISR_* namespace. Since this bit flag is missing from a header imported verbatim from Linux, define it directly in pci.c.
--- virtio/pci-legacy.c | 2 +- virtio/pci.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-)
virtio/pci-legacy.c +1 -1
@@ -61,7 +61,7 @@ static bool virtio_pci__data_in(struct kvm_cpu *vcpu, struct virtio_device *vdevcase VIRTIO_PCI_ISR :ioport__write8 (data, vpci->isr);kvm__irq_line (kvm, vpci->legacy_irq_line,VIRTIO_IRQ_LOW ); - vpci->isr =VIRTIO_IRQ_LOW ; + vpci->isr =0 ;break ;default : ret =virtio_pci__specific_data_in (kvm, vdev, data, size, offset);
virtio/pci.c +4 -1
@@ -14,6 +14,9 @@#include <assert.h> #include <string.h> +/* The bit of the ISR which indicates a queue change. */ +#define VIRTIO_PCI_ISR_QUEUE 0x1 +int virtio_pci__add_msix_route (struct virtio_pci *vpci,u32 vec) {int gsi;
@@ -239,7 +242,7 @@ int virtio_pci__signal_vq(struct kvm *kvm, struct virtio_device *vdev, u32 vq)else kvm__irq_trigger (kvm, vpci->gsis[vq]); }else { - vpci->isr |=VIRTIO_IRQ_HIGH ; + vpci->isr |=VIRTIO_PCI_ISR_QUEUE ;kvm__irq_line (kvm, vpci->legacy_irq_line,VIRTIO_IRQ_HIGH ); }return 0 ;
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
Will Deacon
AppliedQuoted 9 lines · Keir Fraser
Please consider these simple fixes and cleanups to legacy interrupt handling for virtio PCI devices.
Keir Fraser (3):
virtio/pci: Level-trigger the legacy IRQ line in all cases virtio/pci: Treat PCI ISR as a set of bit flags virtio/pci: Use consistent naming for the PCI ISR bit flags[...]
Applied to kvmtool (master), thanks!
[1/3] virtio/pci: Level-trigger the legacy IRQ line in all cases
https://git.kernel.org/will/kvmtool/c/353fa0d89e29 [2/3] virtio/pci: Treat PCI ISR as a set of bit flags https://git.kernel.org/will/kvmtool/c/292144845000 [3/3] virtio/pci: Use consistent naming for the PCI ISR bit flags https://git.kernel.org/will/kvmtool/c/d560235f4556
Cheers,
Signature · 5 lines
Will https://fixes.arm64.dev https://next.arm64.dev https://will.arm64.dev