* [PULL 0/1] virtio: bugfix @ 2024-04-15 10:52 Michael S. Tsirkin 2024-04-15 10:52 ` [PULL 1/1] virtio-pci: fix use of a released vector Michael S. Tsirkin 2024-04-15 14:24 ` [PULL 0/1] virtio: bugfix Peter Maydell 0 siblings, 2 replies; 12+ messages in thread From: Michael S. Tsirkin @ 2024-04-15 10:52 UTC (permalink / raw) To: qemu-devel; +Cc: Peter Maydell The following changes since commit e1999904a960c33b68fedf26dfb7b8e00abab8f2: qdev-monitor: fix error message in find_device_state() (2024-04-09 02:31:33 -0400) are available in the Git repository at: https://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream for you to fetch changes up to 2ce6cff94df2650c460f809e5ad263f1d22507c0: virtio-pci: fix use of a released vector (2024-04-15 06:50:44 -0400) ---------------------------------------------------------------- virtio: bugfix A last minute fix for a use of a vector after it's released. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> ---------------------------------------------------------------- Cindy Lu (1): virtio-pci: fix use of a released vector hw/virtio/virtio-pci.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PULL 1/1] virtio-pci: fix use of a released vector 2024-04-15 10:52 [PULL 0/1] virtio: bugfix Michael S. Tsirkin @ 2024-04-15 10:52 ` Michael S. Tsirkin 2024-04-16 10:01 ` Peter Maydell 2024-04-15 14:24 ` [PULL 0/1] virtio: bugfix Peter Maydell 1 sibling, 1 reply; 12+ messages in thread From: Michael S. Tsirkin @ 2024-04-15 10:52 UTC (permalink / raw) To: qemu-devel; +Cc: Peter Maydell, Cindy Lu, qemu-stable, Lei Yang, Jason Wang From: Cindy Lu <lulu@redhat.com> During the booting process of the non-standard image, the behavior of the called function in qemu is as follows: 1. vhost_net_stop() was triggered by guest image. This will call the function virtio_pci_set_guest_notifiers() with assgin= false, virtio_pci_set_guest_notifiers() will release the irqfd for vector 0 2. virtio_reset() was triggered, this will set configure vector to VIRTIO_NO_VECTOR 3.vhost_net_start() was called (at this time, the configure vector is still VIRTIO_NO_VECTOR) and then call virtio_pci_set_guest_notifiers() with assgin=true, so the irqfd for vector 0 is still not "init" during this process 4. The system continues to boot and sets the vector back to 0. After that msix_fire_vector_notifier() was triggered to unmask the vector 0 and meet the crash To fix the issue, we need to support changing the vector after VIRTIO_CONFIG_S_DRIVER_OK is set. (gdb) bt 0 __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44 1 0x00007fc87148ec53 in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78 2 0x00007fc87143e956 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26 3 0x00007fc8714287f4 in __GI_abort () at abort.c:79 4 0x00007fc87142871b in __assert_fail_base (fmt=0x7fc8715bbde0 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x5606413efd53 "ret == 0", file=0x5606413ef87d "../accel/kvm/kvm-all.c", line=1837, function=<optimized out>) at assert.c:92 5 0x00007fc871437536 in __GI___assert_fail (assertion=0x5606413efd53 "ret == 0", file=0x5606413ef87d "../accel/kvm/kvm-all.c", line=1837, function=0x5606413f06f0 <__PRETTY_FUNCTION__.19> "kvm_irqchip_commit_routes") at assert.c:101 6 0x0000560640f884b5 in kvm_irqchip_commit_routes (s=0x560642cae1f0) at ../accel/kvm/kvm-all.c:1837 7 0x0000560640c98f8e in virtio_pci_one_vector_unmask (proxy=0x560643c65f00, queue_no=4294967295, vector=0, msg=..., n=0x560643c6e4c8) at ../hw/virtio/virtio-pci.c:1005 8 0x0000560640c99201 in virtio_pci_vector_unmask (dev=0x560643c65f00, vector=0, msg=...) at ../hw/virtio/virtio-pci.c:1070 9 0x0000560640bc402e in msix_fire_vector_notifier (dev=0x560643c65f00, vector=0, is_masked=false) at ../hw/pci/msix.c:120 10 0x0000560640bc40f1 in msix_handle_mask_update (dev=0x560643c65f00, vector=0, was_masked=true) at ../hw/pci/msix.c:140 11 0x0000560640bc4503 in msix_table_mmio_write (opaque=0x560643c65f00, addr=12, val=0, size=4) at ../hw/pci/msix.c:231 12 0x0000560640f26d83 in memory_region_write_accessor (mr=0x560643c66540, addr=12, value=0x7fc86b7bc628, size=4, shift=0, mask=4294967295, attrs=...) at ../system/memory.c:497 13 0x0000560640f270a6 in access_with_adjusted_size (addr=12, value=0x7fc86b7bc628, size=4, access_size_min=1, access_size_max=4, access_fn=0x560640f26c8d <memory_region_write_accessor>, mr=0x560643c66540, attrs=...) at ../system/memory.c:573 14 0x0000560640f2a2b5 in memory_region_dispatch_write (mr=0x560643c66540, addr=12, data=0, op=MO_32, attrs=...) at ../system/memory.c:1521 15 0x0000560640f37bac in flatview_write_continue (fv=0x7fc65805e0b0, addr=4273803276, attrs=..., ptr=0x7fc871e9c028, len=4, addr1=12, l=4, mr=0x560643c66540) at ../system/physmem.c:2714 16 0x0000560640f37d0f in flatview_write (fv=0x7fc65805e0b0, addr=4273803276, attrs=..., buf=0x7fc871e9c028, len=4) at ../system/physmem.c:2756 17 0x0000560640f380bf in address_space_write (as=0x560642161ae0 <address_space_memory>, addr=4273803276, attrs=..., buf=0x7fc871e9c028, len=4) at ../system/physmem.c:2863 18 0x0000560640f3812c in address_space_rw (as=0x560642161ae0 <address_space_memory>, addr=4273803276, attrs=..., buf=0x7fc871e9c028, len=4, is_write=true) at ../system/physmem.c:2873 --Type <RET> for more, q to quit, c to continue without paging-- 19 0x0000560640f8aa55 in kvm_cpu_exec (cpu=0x560642f205e0) at ../accel/kvm/kvm-all.c:2915 20 0x0000560640f8d731 in kvm_vcpu_thread_fn (arg=0x560642f205e0) at ../accel/kvm/kvm-accel-ops.c:51 21 0x00005606411949f4 in qemu_thread_start (args=0x560642f292b0) at ../util/qemu-thread-posix.c:541 22 0x00007fc87148cdcd in start_thread (arg=<optimized out>) at pthread_create.c:442 23 0x00007fc871512630 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81 (gdb) MST: coding style and typo fixups Fixes: f9a09ca3ea ("vhost: add support for configure interrupt") Cc: qemu-stable@nongnu.org Signed-off-by: Cindy Lu <lulu@redhat.com> Message-ID: <2321ade5f601367efe7380c04e3f61379c59b48f.1713173550.git.mst@redhat.com> Cc: Lei Yang <leiyang@redhat.com> Cc: Jason Wang <jasowang@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Tested-by: Cindy Lu <lulu@redhat.com> --- hw/virtio/virtio-pci.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index cb6940fc0e..cb159fd078 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1424,6 +1424,38 @@ static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy, return offset; } +static void virtio_pci_set_vector(VirtIODevice *vdev, + VirtIOPCIProxy *proxy, + int queue_no, uint16_t old_vector, + uint16_t new_vector) +{ + bool kvm_irqfd = (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) && + msix_enabled(&proxy->pci_dev) && kvm_msi_via_irqfd_enabled(); + + if (new_vector == old_vector) { + return; + } + + /* + * If the device uses irqfd and the vector changes after DRIVER_OK is + * set, we need to release the old vector and set up the new one. + * Otherwise just need to set the new vector on the device. + */ + if (kvm_irqfd && old_vector != VIRTIO_NO_VECTOR) { + kvm_virtio_pci_vector_release_one(proxy, queue_no); + } + /* Set the new vector on the device. */ + if (queue_no == VIRTIO_CONFIG_IRQ_IDX) { + vdev->config_vector = new_vector; + } else { + virtio_queue_set_vector(vdev, queue_no, new_vector); + } + /* If the new vector changed need to set it up. */ + if (kvm_irqfd && new_vector != VIRTIO_NO_VECTOR) { + kvm_virtio_pci_vector_use_one(proxy, queue_no); + } +} + int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy, uint8_t bar, uint64_t offset, uint64_t length, uint8_t id) @@ -1570,7 +1602,8 @@ static void virtio_pci_common_write(void *opaque, hwaddr addr, } else { val = VIRTIO_NO_VECTOR; } - vdev->config_vector = val; + virtio_pci_set_vector(vdev, proxy, VIRTIO_CONFIG_IRQ_IDX, + vdev->config_vector, val); break; case VIRTIO_PCI_COMMON_STATUS: if (!(val & VIRTIO_CONFIG_S_DRIVER_OK)) { @@ -1610,7 +1643,7 @@ static void virtio_pci_common_write(void *opaque, hwaddr addr, } else { val = VIRTIO_NO_VECTOR; } - virtio_queue_set_vector(vdev, vdev->queue_sel, val); + virtio_pci_set_vector(vdev, proxy, vdev->queue_sel, vector, val); break; case VIRTIO_PCI_COMMON_Q_ENABLE: if (val == 1) { -- MST ^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PULL 1/1] virtio-pci: fix use of a released vector 2024-04-15 10:52 ` [PULL 1/1] virtio-pci: fix use of a released vector Michael S. Tsirkin @ 2024-04-16 10:01 ` Peter Maydell 2024-04-16 11:04 ` Cindy Lu 0 siblings, 1 reply; 12+ messages in thread From: Peter Maydell @ 2024-04-16 10:01 UTC (permalink / raw) To: Michael S. Tsirkin Cc: qemu-devel, Cindy Lu, qemu-stable, Lei Yang, Jason Wang On Mon, 15 Apr 2024 at 11:52, Michael S. Tsirkin <mst@redhat.com> wrote: > > From: Cindy Lu <lulu@redhat.com> > > During the booting process of the non-standard image, the behavior of the > called function in qemu is as follows: > > 1. vhost_net_stop() was triggered by guest image. This will call the function > virtio_pci_set_guest_notifiers() with assgin= false, > virtio_pci_set_guest_notifiers() will release the irqfd for vector 0 > > 2. virtio_reset() was triggered, this will set configure vector to VIRTIO_NO_VECTOR > > 3.vhost_net_start() was called (at this time, the configure vector is > still VIRTIO_NO_VECTOR) and then call virtio_pci_set_guest_notifiers() with > assgin=true, so the irqfd for vector 0 is still not "init" during this process > > 4. The system continues to boot and sets the vector back to 0. After that > msix_fire_vector_notifier() was triggered to unmask the vector 0 and meet the crash > > To fix the issue, we need to support changing the vector after VIRTIO_CONFIG_S_DRIVER_OK is set. > Hi; Coverity points out what it thinks is a problem in this commit (CID 1543938): > diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c > index cb6940fc0e..cb159fd078 100644 > --- a/hw/virtio/virtio-pci.c > +++ b/hw/virtio/virtio-pci.c > @@ -1424,6 +1424,38 @@ static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy, > return offset; > } > > +static void virtio_pci_set_vector(VirtIODevice *vdev, > + VirtIOPCIProxy *proxy, > + int queue_no, uint16_t old_vector, > + uint16_t new_vector) > +{ > + bool kvm_irqfd = (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) && > + msix_enabled(&proxy->pci_dev) && kvm_msi_via_irqfd_enabled(); > + > + if (new_vector == old_vector) { > + return; > + } > + > + /* > + * If the device uses irqfd and the vector changes after DRIVER_OK is > + * set, we need to release the old vector and set up the new one. > + * Otherwise just need to set the new vector on the device. > + */ > + if (kvm_irqfd && old_vector != VIRTIO_NO_VECTOR) { > + kvm_virtio_pci_vector_release_one(proxy, queue_no); > + } > + /* Set the new vector on the device. */ > + if (queue_no == VIRTIO_CONFIG_IRQ_IDX) { > + vdev->config_vector = new_vector; > + } else { > + virtio_queue_set_vector(vdev, queue_no, new_vector); > + } Here queue_no can be VIRTIO_CONFIG_IRQ_IDX, which is -1. > + /* If the new vector changed need to set it up. */ > + if (kvm_irqfd && new_vector != VIRTIO_NO_VECTOR) { > + kvm_virtio_pci_vector_use_one(proxy, queue_no); Here we pass that through to kvm_virtio_pci_vector_use_one(). In kvm_virtio_pci_vector_use_one()'s error-exit path ("undo") it does vector = virtio_queue_vector(vdev, queue_no); and in virtio_queue_vector() it does: return n < VIRTIO_QUEUE_MAX ? vdev->vq[n].vector : VIRTIO_NO_VECTOR; where 'n' is an int, so if we can get here with queue_no being VIRTIO_CONFIG_IRQ_IDX then we'll index off the front of the vdev->vq[] array. Maybe this is a "can't happen" case, but it does seem odd that virtio_queue_vector() only bounds-checks the "too big" case for its argument and not the "too small" case and/or it doesn't have a special case for VIRTIO_CONFIG_IRQ_IDX. > + } > +} > + thanks -- PMM ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PULL 1/1] virtio-pci: fix use of a released vector 2024-04-16 10:01 ` Peter Maydell @ 2024-04-16 11:04 ` Cindy Lu 2024-04-16 11:50 ` Peter Maydell 0 siblings, 1 reply; 12+ messages in thread From: Cindy Lu @ 2024-04-16 11:04 UTC (permalink / raw) To: Peter Maydell Cc: Michael S. Tsirkin, qemu-devel, qemu-stable, Lei Yang, Jason Wang On Tue, Apr 16, 2024 at 6:01 PM Peter Maydell <peter.maydell@linaro.org> wrote: > > On Mon, 15 Apr 2024 at 11:52, Michael S. Tsirkin <mst@redhat.com> wrote: > > > > From: Cindy Lu <lulu@redhat.com> > > > > During the booting process of the non-standard image, the behavior of the > > called function in qemu is as follows: > > > > 1. vhost_net_stop() was triggered by guest image. This will call the function > > virtio_pci_set_guest_notifiers() with assgin= false, > > virtio_pci_set_guest_notifiers() will release the irqfd for vector 0 > > > > 2. virtio_reset() was triggered, this will set configure vector to VIRTIO_NO_VECTOR > > > > 3.vhost_net_start() was called (at this time, the configure vector is > > still VIRTIO_NO_VECTOR) and then call virtio_pci_set_guest_notifiers() with > > assgin=true, so the irqfd for vector 0 is still not "init" during this process > > > > 4. The system continues to boot and sets the vector back to 0. After that > > msix_fire_vector_notifier() was triggered to unmask the vector 0 and meet the crash > > > > To fix the issue, we need to support changing the vector after VIRTIO_CONFIG_S_DRIVER_OK is set. > > > > Hi; Coverity points out what it thinks is a problem in this commit > (CID 1543938): > > > diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c > > index cb6940fc0e..cb159fd078 100644 > > --- a/hw/virtio/virtio-pci.c > > +++ b/hw/virtio/virtio-pci.c > > @@ -1424,6 +1424,38 @@ static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy, > > return offset; > > } > > > > +static void virtio_pci_set_vector(VirtIODevice *vdev, > > + VirtIOPCIProxy *proxy, > > + int queue_no, uint16_t old_vector, > > + uint16_t new_vector) > > +{ > > + bool kvm_irqfd = (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) && > > + msix_enabled(&proxy->pci_dev) && kvm_msi_via_irqfd_enabled(); > > + > > + if (new_vector == old_vector) { > > + return; > > + } > > + > > + /* > > + * If the device uses irqfd and the vector changes after DRIVER_OK is > > + * set, we need to release the old vector and set up the new one. > > + * Otherwise just need to set the new vector on the device. > > + */ > > + if (kvm_irqfd && old_vector != VIRTIO_NO_VECTOR) { > > + kvm_virtio_pci_vector_release_one(proxy, queue_no); > > + } > > + /* Set the new vector on the device. */ > > + if (queue_no == VIRTIO_CONFIG_IRQ_IDX) { > > + vdev->config_vector = new_vector; > > + } else { > > + virtio_queue_set_vector(vdev, queue_no, new_vector); > > + } > > Here queue_no can be VIRTIO_CONFIG_IRQ_IDX, which is -1. > > > + /* If the new vector changed need to set it up. */ > > + if (kvm_irqfd && new_vector != VIRTIO_NO_VECTOR) { > > + kvm_virtio_pci_vector_use_one(proxy, queue_no); > > Here we pass that through to kvm_virtio_pci_vector_use_one(). > In kvm_virtio_pci_vector_use_one()'s error-exit path ("undo") > it does > vector = virtio_queue_vector(vdev, queue_no); > and in virtio_queue_vector() it does: > > return n < VIRTIO_QUEUE_MAX ? vdev->vq[n].vector : > VIRTIO_NO_VECTOR; > > where 'n' is an int, so if we can get here with queue_no being > VIRTIO_CONFIG_IRQ_IDX then we'll index off the front of the > vdev->vq[] array. > > Maybe this is a "can't happen" case, but it does seem odd that > virtio_queue_vector() only bounds-checks the "too big" case > for its argument and not the "too small" case and/or it > doesn't have a special case for VIRTIO_CONFIG_IRQ_IDX. > > > + } > > +} > > + > hi peter I think we can simply remove the part vector = virtio_queue_vector(vdev, queue_no); the vector is get from virtio_pci_get_notifier() and don't need to get it again I will send the fix soon thanks cindy > thanks > -- PMM > ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PULL 1/1] virtio-pci: fix use of a released vector 2024-04-16 11:04 ` Cindy Lu @ 2024-04-16 11:50 ` Peter Maydell 2024-04-16 12:22 ` Peter Maydell 2024-04-16 12:47 ` Cindy Lu 0 siblings, 2 replies; 12+ messages in thread From: Peter Maydell @ 2024-04-16 11:50 UTC (permalink / raw) To: Cindy Lu Cc: Michael S. Tsirkin, qemu-devel, qemu-stable, Lei Yang, Jason Wang On Tue, 16 Apr 2024 at 12:05, Cindy Lu <lulu@redhat.com> wrote: > > On Tue, Apr 16, 2024 at 6:01 PM Peter Maydell <peter.maydell@linaro.org> wrote: > > Here we pass that through to kvm_virtio_pci_vector_use_one(). > > In kvm_virtio_pci_vector_use_one()'s error-exit path ("undo") > > it does > > vector = virtio_queue_vector(vdev, queue_no); > > and in virtio_queue_vector() it does: > > > > return n < VIRTIO_QUEUE_MAX ? vdev->vq[n].vector : > > VIRTIO_NO_VECTOR; > > > > where 'n' is an int, so if we can get here with queue_no being > > VIRTIO_CONFIG_IRQ_IDX then we'll index off the front of the > > vdev->vq[] array. > > > > Maybe this is a "can't happen" case, but it does seem odd that > > virtio_queue_vector() only bounds-checks the "too big" case > > for its argument and not the "too small" case and/or it > > doesn't have a special case for VIRTIO_CONFIG_IRQ_IDX. > > > > > + } > > > +} > > > + > > > hi peter > I think we can simply remove the part > vector = virtio_queue_vector(vdev, queue_no); > the vector is get from virtio_pci_get_notifier() and don't need to get it again > I will send the fix soon The error handling in kvm_virtio_pci_vector_use_one() looks a bit odd in other ways, too. The only bit of "undoing" it does as far as I can see is calling kvm_virtio_pci_irqfd_release(), but there is no code path that gets to there where the main codepath's call to kvm_virtio-pci_irqfd_use() succeeded and needs to be undone. So perhaps the entire "undo" code block should be deleted, and the "goto undo" lines replaced by simple "return ret;" ? (The codepath for "kvm_virtio_pci_irqfd_use() failed" already does the "kvm_virtio_pci_vq_vector_release()" by hand there.) thanks -- PMM ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PULL 1/1] virtio-pci: fix use of a released vector 2024-04-16 11:50 ` Peter Maydell @ 2024-04-16 12:22 ` Peter Maydell 2024-04-16 13:06 ` Cindy Lu 2024-04-16 12:47 ` Cindy Lu 1 sibling, 1 reply; 12+ messages in thread From: Peter Maydell @ 2024-04-16 12:22 UTC (permalink / raw) To: Cindy Lu Cc: Michael S. Tsirkin, qemu-devel, qemu-stable, Lei Yang, Jason Wang, Paolo Bonzini On Tue, 16 Apr 2024 at 12:50, Peter Maydell <peter.maydell@linaro.org> wrote: > > On Tue, 16 Apr 2024 at 12:05, Cindy Lu <lulu@redhat.com> wrote: > > > > On Tue, Apr 16, 2024 at 6:01 PM Peter Maydell <peter.maydell@linaro.org> wrote: > > > Hi; Coverity points out what it thinks is a problem in > > > this commit (CID 1543938): > > > Here we pass that through to kvm_virtio_pci_vector_use_one(). > > > In kvm_virtio_pci_vector_use_one()'s error-exit path ("undo") > > > it does > > > vector = virtio_queue_vector(vdev, queue_no); > > > and in virtio_queue_vector() it does: > > > > > > return n < VIRTIO_QUEUE_MAX ? vdev->vq[n].vector : > > > VIRTIO_NO_VECTOR; > > > > > > where 'n' is an int, so if we can get here with queue_no being > > > VIRTIO_CONFIG_IRQ_IDX then we'll index off the front of the > > > vdev->vq[] array. > > > > > > Maybe this is a "can't happen" case, but it does seem odd that > > > virtio_queue_vector() only bounds-checks the "too big" case > > > for its argument and not the "too small" case and/or it > > > doesn't have a special case for VIRTIO_CONFIG_IRQ_IDX. > > > > > > > + } > > > > +} > > > > + > > > > > hi peter > > I think we can simply remove the part > > vector = virtio_queue_vector(vdev, queue_no); > > the vector is get from virtio_pci_get_notifier() and don't need to get it again > > I will send the fix soon > > The error handling in kvm_virtio_pci_vector_use_one() looks > a bit odd in other ways, too. The only bit of "undoing" > it does as far as I can see is calling kvm_virtio_pci_irqfd_release(), > but there is no code path that gets to there where the > main codepath's call to kvm_virtio-pci_irqfd_use() succeeded > and needs to be undone. So perhaps the entire "undo" code > block should be deleted, and the "goto undo" lines > replaced by simple "return ret;" ? (The codepath > for "kvm_virtio_pci_irqfd_use() failed" already does the > "kvm_virtio_pci_vq_vector_release()" by hand there.) In any case since the error handling in kvm_virtio_pci_vector_use_one() isn't new in this commit (you can get the same problem via kvm_virtio_pci_vector_config_use(), which is CID 1468940 first detected in 2022), I think this is not something we need to rush to fix before we release 9.0. If anybody disagrees now would be a good time to say so :-) Paolo's comment on CID 1468940 was to suggest "virtio_queue_vector should check VIRTIO_CONFIG_IRQ_IDX just like virtio_pci_get_notifier", incidentally. thanks -- PMM ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PULL 1/1] virtio-pci: fix use of a released vector 2024-04-16 12:22 ` Peter Maydell @ 2024-04-16 13:06 ` Cindy Lu 2024-04-16 13:11 ` Peter Maydell 0 siblings, 1 reply; 12+ messages in thread From: Cindy Lu @ 2024-04-16 13:06 UTC (permalink / raw) To: Peter Maydell Cc: Michael S. Tsirkin, qemu-devel, qemu-stable, Lei Yang, Jason Wang, Paolo Bonzini On Tue, Apr 16, 2024 at 8:22 PM Peter Maydell <peter.maydell@linaro.org> wrote: > > On Tue, 16 Apr 2024 at 12:50, Peter Maydell <peter.maydell@linaro.org> wrote: > > > > On Tue, 16 Apr 2024 at 12:05, Cindy Lu <lulu@redhat.com> wrote: > > > > > > On Tue, Apr 16, 2024 at 6:01 PM Peter Maydell <peter.maydell@linaro.org> wrote: > > > > Hi; Coverity points out what it thinks is a problem in > > > > this commit (CID 1543938): > > > > > Here we pass that through to kvm_virtio_pci_vector_use_one(). > > > > In kvm_virtio_pci_vector_use_one()'s error-exit path ("undo") > > > > it does > > > > vector = virtio_queue_vector(vdev, queue_no); > > > > and in virtio_queue_vector() it does: > > > > > > > > return n < VIRTIO_QUEUE_MAX ? vdev->vq[n].vector : > > > > VIRTIO_NO_VECTOR; > > > > > > > > where 'n' is an int, so if we can get here with queue_no being > > > > VIRTIO_CONFIG_IRQ_IDX then we'll index off the front of the > > > > vdev->vq[] array. > > > > > > > > Maybe this is a "can't happen" case, but it does seem odd that > > > > virtio_queue_vector() only bounds-checks the "too big" case > > > > for its argument and not the "too small" case and/or it > > > > doesn't have a special case for VIRTIO_CONFIG_IRQ_IDX. > > > > > > > > > + } > > > > > +} > > > > > + > > > > > > > hi peter > > > I think we can simply remove the part > > > vector = virtio_queue_vector(vdev, queue_no); > > > the vector is get from virtio_pci_get_notifier() and don't need to get it again > > > I will send the fix soon > > > > The error handling in kvm_virtio_pci_vector_use_one() looks > > a bit odd in other ways, too. The only bit of "undoing" > > it does as far as I can see is calling kvm_virtio_pci_irqfd_release(), > > but there is no code path that gets to there where the > > main codepath's call to kvm_virtio-pci_irqfd_use() succeeded > > and needs to be undone. So perhaps the entire "undo" code > > block should be deleted, and the "goto undo" lines > > replaced by simple "return ret;" ? (The codepath > > for "kvm_virtio_pci_irqfd_use() failed" already does the > > "kvm_virtio_pci_vq_vector_release()" by hand there.) > > In any case since the error handling in kvm_virtio_pci_vector_use_one() > isn't new in this commit (you can get the same problem via > kvm_virtio_pci_vector_config_use(), which is CID 1468940 > first detected in 2022), I think this is not something we need > to rush to fix before we release 9.0. If anybody disagrees now > would be a good time to say so :-) > > Paolo's comment on CID 1468940 was to suggest "virtio_queue_vector > should check VIRTIO_CONFIG_IRQ_IDX just like virtio_pci_get_notifier", > incidentally. > Hi peter, Really sorry all these mess, but I still have a stuipid question, where can I get this CID result ?maybe there are a mailing list?I just wonder maybe I can fix these code earlier next time, Really thanks for your help thanks cindy > thanks > -- PMM > ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PULL 1/1] virtio-pci: fix use of a released vector 2024-04-16 13:06 ` Cindy Lu @ 2024-04-16 13:11 ` Peter Maydell 0 siblings, 0 replies; 12+ messages in thread From: Peter Maydell @ 2024-04-16 13:11 UTC (permalink / raw) To: Cindy Lu Cc: Michael S. Tsirkin, qemu-devel, qemu-stable, Lei Yang, Jason Wang, Paolo Bonzini On Tue, 16 Apr 2024 at 14:06, Cindy Lu <lulu@redhat.com> wrote: > > On Tue, Apr 16, 2024 at 8:22 PM Peter Maydell <peter.maydell@linaro.org> wrote: > > Paolo's comment on CID 1468940 was to suggest "virtio_queue_vector > > should check VIRTIO_CONFIG_IRQ_IDX just like virtio_pci_get_notifier", > > incidentally. > > > Hi peter, > Really sorry all these mess, but I still have a stuipid question, > where can I get > this CID result ?maybe there are a mailing list?I just wonder maybe I can fix > these code earlier next time, Really thanks for your help These CID numbers are the identifiers of the issues in the Coverity Scan online UI: https://scan.coverity.com/projects/qemu You need to apply for access but we give that to anybody who's a QEMU developer. Unfortunately we can only do a very limited amount of Coverity Scan runs (about one a day), so we run them only on code that has been committed to QEMU already, and we aren't able to use it to find problems in patches before we apply them. thanks -- PMM ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PULL 1/1] virtio-pci: fix use of a released vector 2024-04-16 11:50 ` Peter Maydell 2024-04-16 12:22 ` Peter Maydell @ 2024-04-16 12:47 ` Cindy Lu 1 sibling, 0 replies; 12+ messages in thread From: Cindy Lu @ 2024-04-16 12:47 UTC (permalink / raw) To: Peter Maydell Cc: Michael S. Tsirkin, qemu-devel, qemu-stable, Lei Yang, Jason Wang On Tue, Apr 16, 2024 at 7:50 PM Peter Maydell <peter.maydell@linaro.org> wrote: > > On Tue, 16 Apr 2024 at 12:05, Cindy Lu <lulu@redhat.com> wrote: > > > > On Tue, Apr 16, 2024 at 6:01 PM Peter Maydell <peter.maydell@linaro.org> wrote: > > > Here we pass that through to kvm_virtio_pci_vector_use_one(). > > > In kvm_virtio_pci_vector_use_one()'s error-exit path ("undo") > > > it does > > > vector = virtio_queue_vector(vdev, queue_no); > > > and in virtio_queue_vector() it does: > > > > > > return n < VIRTIO_QUEUE_MAX ? vdev->vq[n].vector : > > > VIRTIO_NO_VECTOR; > > > > > > where 'n' is an int, so if we can get here with queue_no being > > > VIRTIO_CONFIG_IRQ_IDX then we'll index off the front of the > > > vdev->vq[] array. > > > > > > Maybe this is a "can't happen" case, but it does seem odd that > > > virtio_queue_vector() only bounds-checks the "too big" case > > > for its argument and not the "too small" case and/or it > > > doesn't have a special case for VIRTIO_CONFIG_IRQ_IDX. > > > > > > > + } > > > > +} > > > > + > > > > > hi peter > > I think we can simply remove the part > > vector = virtio_queue_vector(vdev, queue_no); > > the vector is get from virtio_pci_get_notifier() and don't need to get it again > > I will send the fix soon > > The error handling in kvm_virtio_pci_vector_use_one() looks > a bit odd in other ways, too. The only bit of "undoing" > it does as far as I can see is calling kvm_virtio_pci_irqfd_release(), > but there is no code path that gets to there where the > main codepath's call to kvm_virtio-pci_irqfd_use() succeeded > and needs to be undone. So perhaps the entire "undo" code > block should be deleted, and the "goto undo" lines > replaced by simple "return ret;" ? (The codepath > for "kvm_virtio_pci_irqfd_use() failed" already does the > "kvm_virtio_pci_vq_vector_release()" by hand there.) > > thanks > -- PMM > Hi peter, Really thanks for your help. I have rewrite this part, the error handling part is incorrect Thanks Cindy ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PULL 0/1] virtio: bugfix 2024-04-15 10:52 [PULL 0/1] virtio: bugfix Michael S. Tsirkin 2024-04-15 10:52 ` [PULL 1/1] virtio-pci: fix use of a released vector Michael S. Tsirkin @ 2024-04-15 14:24 ` Peter Maydell 1 sibling, 0 replies; 12+ messages in thread From: Peter Maydell @ 2024-04-15 14:24 UTC (permalink / raw) To: Michael S. Tsirkin; +Cc: qemu-devel On Mon, 15 Apr 2024 at 11:52, Michael S. Tsirkin <mst@redhat.com> wrote: > > The following changes since commit e1999904a960c33b68fedf26dfb7b8e00abab8f2: > > qdev-monitor: fix error message in find_device_state() (2024-04-09 02:31:33 -0400) > > are available in the Git repository at: > > https://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream > > for you to fetch changes up to 2ce6cff94df2650c460f809e5ad263f1d22507c0: > > virtio-pci: fix use of a released vector (2024-04-15 06:50:44 -0400) > > ---------------------------------------------------------------- > virtio: bugfix > > A last minute fix for a use of a vector after it's released. > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com> > > ---------------------------------------------------------------- Applied, thanks. Please update the changelog at https://wiki.qemu.org/ChangeLog/9.0 for any user-visible changes. -- PMM ^ permalink raw reply [flat|nested] 12+ messages in thread
* [PULL 0/1] virtio: bugfix @ 2020-07-09 23:04 Michael S. Tsirkin 2020-07-11 12:55 ` Peter Maydell 0 siblings, 1 reply; 12+ messages in thread From: Michael S. Tsirkin @ 2020-07-09 23:04 UTC (permalink / raw) To: qemu-devel; +Cc: Peter Maydell Fixes a single bug in vdpa. The following changes since commit eb2c66b10efd2b914b56b20ae90655914310c925: Merge remote-tracking branch 'remotes/maxreitz/tags/pull-block-2020-07-06' into staging (2020-07-07 19:47:26 +0100) are available in the Git repository at: git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream for you to fetch changes up to 4dc5acc07e88b2776513db75944f2e240116ebda: vhost-vdpa: fix the compile issue without kvm (2020-07-08 06:16:48 -0400) ---------------------------------------------------------------- virtio: bugfix fixes vdpa on non-kvm platforms Signed-off-by: Michael S. Tsirkin <mst@redhat.com> ---------------------------------------------------------------- Cindy Lu (1): vhost-vdpa: fix the compile issue without kvm hw/virtio/vhost-vdpa.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PULL 0/1] virtio: bugfix 2020-07-09 23:04 Michael S. Tsirkin @ 2020-07-11 12:55 ` Peter Maydell 0 siblings, 0 replies; 12+ messages in thread From: Peter Maydell @ 2020-07-11 12:55 UTC (permalink / raw) To: Michael S. Tsirkin; +Cc: QEMU Developers On Fri, 10 Jul 2020 at 00:04, Michael S. Tsirkin <mst@redhat.com> wrote: > > Fixes a single bug in vdpa. > > The following changes since commit eb2c66b10efd2b914b56b20ae90655914310c925: > > Merge remote-tracking branch 'remotes/maxreitz/tags/pull-block-2020-07-06' into staging (2020-07-07 19:47:26 +0100) > > are available in the Git repository at: > > git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream > > for you to fetch changes up to 4dc5acc07e88b2776513db75944f2e240116ebda: > > vhost-vdpa: fix the compile issue without kvm (2020-07-08 06:16:48 -0400) > > ---------------------------------------------------------------- > virtio: bugfix > > fixes vdpa on non-kvm platforms > > Signed-off-by: Michael S. Tsirkin <mst@redhat.com> > > ---------------------------------------------------------------- Applied, thanks. Please update the changelog at https://wiki.qemu.org/ChangeLog/5.1 for any user-visible changes. -- PMM ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2024-04-16 13:12 UTC | newest] Thread overview: 12+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-04-15 10:52 [PULL 0/1] virtio: bugfix Michael S. Tsirkin 2024-04-15 10:52 ` [PULL 1/1] virtio-pci: fix use of a released vector Michael S. Tsirkin 2024-04-16 10:01 ` Peter Maydell 2024-04-16 11:04 ` Cindy Lu 2024-04-16 11:50 ` Peter Maydell 2024-04-16 12:22 ` Peter Maydell 2024-04-16 13:06 ` Cindy Lu 2024-04-16 13:11 ` Peter Maydell 2024-04-16 12:47 ` Cindy Lu 2024-04-15 14:24 ` [PULL 0/1] virtio: bugfix Peter Maydell -- strict thread matches above, loose matches on Subject: below -- 2020-07-09 23:04 Michael S. Tsirkin 2020-07-11 12:55 ` Peter Maydell
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).