Skip to contentSkip to conversation

virtio: regression fixes

GIT PULL Applied Michael S. Tsirkin 3 participants 6 messages Aug 20, 2024 – Aug 30, 2024 Networking

lore
Share & tools
lore
#0 lore raw

The following changes since commit 76277cf82f0e1123bd69ec59d22014b8f78485ec:

Merge tag 'hw-misc-20240820' of https://github.com/philmd/qemu into staging (2024-08-20 09:17:41 +1000)

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 a8e63ff289d137197ad7a701a587cc432872d798:

virtio-pci: Fix the use of an uninitialized irqfd (2024-08-20 06:57:47 -0400)

----------------------------------------------------------------
virtio: regression fixes

3 small patches to make sure we don't ship regressions.

----------------------------------------------------------------
Akihiko Odaki (1):
vhost: Add VIRTIO_NET_F_RSC_EXT to vhost feature bits

Cindy Lu (1):
virtio-pci: Fix the use of an uninitialized irqfd

Volker Rümelin (1):
hw/audio/virtio-snd: fix invalid param check

 hw/audio/virtio-snd.c  | 4 ++--
 hw/net/vhost_net.c     | 2 ++
 hw/virtio/virtio-pci.c | 3 +++
 net/vhost-vdpa.c       | 1 +
 4 files changed, 8 insertions(+), 2 deletions(-)
#1 lore raw

[PULL 2/3] hw/audio/virtio-snd: fix invalid param check

From: Volker Rümelin <[email protected]>

Commit 9b6083465f ("virtio-snd: check for invalid param shift operands") tries to prevent invalid parameters specified by the guest. However, the code is not correct.

Change the code so that the parameters format and rate, which are a bit numbers, are compared with the bit size of the data type.

Fixes 9b6083465f ("virtio-snd: check for invalid param shift operands")

Message-Id: <[email protected]>

---
 hw/audio/virtio-snd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/audio/virtio-snd.c +2 -2
index e5196aa4bb..d1cf5eb445 100644
@@ -282,12 +282,12 @@ uint32_t virtio_snd_set_pcm_params(VirtIOSound *s,
         error_report("Number of channels is not supported.");
         return cpu_to_le32(VIRTIO_SND_S_NOT_SUPP);
     }
-    if (BIT(params->format) > sizeof(supported_formats) ||
+    if (params->format >= sizeof(supported_formats) * BITS_PER_BYTE ||
         !(supported_formats & BIT(params->format))) {
         error_report("Stream format is not supported.");
         return cpu_to_le32(VIRTIO_SND_S_NOT_SUPP);
     }
-    if (BIT(params->rate) > sizeof(supported_rates) ||
+    if (params->rate >= sizeof(supported_rates) * BITS_PER_BYTE ||
         !(supported_rates & BIT(params->rate))) {
         error_report("Stream rate is not supported.");
         return cpu_to_le32(VIRTIO_SND_S_NOT_SUPP);
Signature · 1 line
MST
#3 lore raw

[PULL 3/3] virtio-pci: Fix the use of an uninitialized irqfd

In reply to Michael S. Tsirkin

From: Cindy Lu <[email protected]>

The crash was reported in MAC OS and NixOS, here is the link for this bug
https://gitlab.com/qemu-project/qemu/-/issues/2334
https://gitlab.com/qemu-project/qemu/-/issues/2321

In this bug, they are using the virtio_input device. The guest notifier was not supported for this device, The function virtio_pci_set_guest_notifiers() was not called, and the vector_irqfd was not initialized.

So the fix is adding the check for vector_irqfd in virtio_pci_get_notifier()

The function virtio_pci_get_notifier() can be used in various devices. It could also be called when VIRTIO_CONFIG_S_DRIVER_OK is not set. In this situation, the vector_irqfd being NULL is acceptable. We can allow the device continue to boot

If the vector_irqfd still hasn't been initialized after VIRTIO_CONFIG_S_DRIVER_OK is set, it means that the function set_guest_notifiers was not called before the driver started. This indicates that the device is not using the notifier. At this point, we will let the check fail.

This fix is verified in vyatta,MacOS,NixOS,fedora system.

The bt tree for this bug is:
Thread 6 "CPU 0/KVM" received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7c817be006c0 (LWP 1269146)] kvm_virtio_pci_vq_vector_use () at ../qemu-9.0.0/hw/virtio/virtio-pci.c:817
817 if (irqfd->users == 0) {
(gdb) thread apply all bt
...
Thread 6 (Thread 0x7c817be006c0 (LWP 1269146) "CPU 0/KVM"):

0  kvm_virtio_pci_vq_vector_use () at ../qemu-9.0.0/hw/virtio/virtio-pci.c:817
1  kvm_virtio_pci_vector_use_one () at ../qemu-9.0.0/hw/virtio/virtio-pci.c:893
2  0x00005983657045e2 in memory_region_write_accessor () at ../qemu-9.0.0/system/memory.c:497
3  0x0000598365704ba6 in access_with_adjusted_size () at ../qemu-9.0.0/system/memory.c:573
4  0x0000598365705059 in memory_region_dispatch_write () at ../qemu-9.0.0/system/memory.c:1528
5  0x00005983659b8e1f in flatview_write_continue_step.isra.0 () at ../qemu-9.0.0/system/physmem.c:2713
6  0x000059836570ba7d in flatview_write_continue () at ../qemu-9.0.0/system/physmem.c:2743
7  flatview_write () at ../qemu-9.0.0/system/physmem.c:2774
8  0x000059836570bb76 in address_space_write () at ../qemu-9.0.0/system/physmem.c:2894
9  0x0000598365763afe in address_space_rw () at ../qemu-9.0.0/system/physmem.c:2904

10 kvm_cpu_exec () at ../qemu-9.0.0/accel/kvm/kvm-all.c:2917
11 0x000059836576656e in kvm_vcpu_thread_fn () at ../qemu-9.0.0/accel/kvm/kvm-accel-ops.c:50 12 0x0000598365926ca8 in qemu_thread_start () at ../qemu-9.0.0/util/qemu-thread-posix.c:541 13 0x00007c8185bcd1cf in ??? () at /usr/lib/libc.so.6
14 0x00007c8185c4e504 in clone () at /usr/lib/libc.so.6

Fixes 2ce6cff94d ("virtio-pci: fix use of a released vector")

Message-Id: <[email protected]>

---
 hw/virtio/virtio-pci.c | 3 +++
 1 file changed, 3 insertions(+)
hw/virtio/virtio-pci.c +3 -0
index 9534730bba..524b63e5c7 100644
@@ -866,6 +866,9 @@ static int virtio_pci_get_notifier(VirtIOPCIProxy *proxy, int queue_no,
     VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
     VirtQueue *vq;
 
+    if (!proxy->vector_irqfd && vdev->status & VIRTIO_CONFIG_S_DRIVER_OK)
+        return -1;
+
     if (queue_no == VIRTIO_CONFIG_IRQ_IDX) {
         *n = virtio_config_get_guest_notifier(vdev);
         *vector = vdev->config_vector;
Signature · 1 line
MST
#4 lore raw

[PULL 1/3] vhost: Add VIRTIO_NET_F_RSC_EXT to vhost feature bits

In reply to Michael S. Tsirkin

From: Akihiko Odaki <[email protected]>

VIRTIO_NET_F_RSC_EXT is implemented in the rx data path, which vhost implements, so vhost needs to support the feature if it is ever to be enabled with vhost. The feature must be disabled otherwise.

Fixes 2974e916df87 ("virtio-net: support RSC v4/v6 tcp traffic for Windows HCK")

Message-Id: <[email protected]>

---
 hw/net/vhost_net.c | 2 ++
 net/vhost-vdpa.c   | 1 +
 2 files changed, 3 insertions(+)
hw/net/vhost_net.c +2 -0
index a788e6937e..dedf9ad7c2 100644
@@ -50,6 +50,7 @@ static const int kernel_feature_bits[] = {
     VIRTIO_F_RING_RESET,
     VIRTIO_F_IN_ORDER,
     VIRTIO_F_NOTIFICATION_DATA,
+    VIRTIO_NET_F_RSC_EXT,
     VIRTIO_NET_F_HASH_REPORT,
     VHOST_INVALID_FEATURE_BIT
 };
@@ -81,6 +82,7 @@ static const int user_feature_bits[] = {
     VIRTIO_F_RING_RESET,
     VIRTIO_F_IN_ORDER,
     VIRTIO_NET_F_RSS,
+    VIRTIO_NET_F_RSC_EXT,
     VIRTIO_NET_F_HASH_REPORT,
     VIRTIO_NET_F_GUEST_USO4,
     VIRTIO_NET_F_GUEST_USO6,
net/vhost-vdpa.c +1 -0
index 03457ead66..46b02c50be 100644
@@ -88,6 +88,7 @@ const int vdpa_feature_bits[] = {
     VIRTIO_NET_F_MQ,
     VIRTIO_NET_F_MRG_RXBUF,
     VIRTIO_NET_F_MTU,
+    VIRTIO_NET_F_RSC_EXT,
     VIRTIO_NET_F_RSS,
     VIRTIO_NET_F_STATUS,
     VIRTIO_RING_F_EVENT_IDX,
Signature · 1 line
MST
#5 lore raw
In reply to Michael S. Tsirkin
Quoted 8 lines · Michael S. Tsirkin

The following changes since commit 76277cf82f0e1123bd69ec59d22014b8f78485ec:

   Merge tag 'hw-misc-20240820' ofhttps://github.com/philmd/qemu into staging (2024-08-20 09:17:41 +1000)

are available in the Git repository at:

https://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream

Quoted 8 lines

for you to fetch changes up to a8e63ff289d137197ad7a701a587cc432872d798:

virtio-pci: Fix the use of an uninitialized irqfd (2024-08-20 06:57:47 -0400)

----------------------------------------------------------------
virtio: regression fixes

3 small patches to make sure we don't ship regressions.

Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/9.1 as appropriate.

r~

#2 lore raw

Re: [PULL 2/3] hw/audio/virtio-snd: fix invalid param check

In reply to Michael S. Tsirkin

Without this patch, the virtio-sound device will not work in the next QEMU stable-8.2 and stable-9.0 versions.

With best regards,
Volker

Quoted 38 lines

From: Volker Rümelin <[email protected]>

Commit 9b6083465f ("virtio-snd: check for invalid param shift operands") tries to prevent invalid parameters specified by the guest. However, the code is not correct.

Change the code so that the parameters format and rate, which are a bit numbers, are compared with the bit size of the data type.

Fixes 9b6083465f ("virtio-snd: check for invalid param shift operands")

Message-Id: <[email protected]>

---
 hw/audio/virtio-snd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/audio/virtio-snd.c +2 -2
index e5196aa4bb..d1cf5eb445 100644
@@ -282,12 +282,12 @@ uint32_t virtio_snd_set_pcm_params(VirtIOSound *s,
         error_report("Number of channels is not supported.");
         return cpu_to_le32(VIRTIO_SND_S_NOT_SUPP);
     }
-    if (BIT(params->format) > sizeof(supported_formats) ||
+    if (params->format >= sizeof(supported_formats) * BITS_PER_BYTE ||
         !(supported_formats & BIT(params->format))) {
         error_report("Stream format is not supported.");
         return cpu_to_le32(VIRTIO_SND_S_NOT_SUPP);
     }
-    if (BIT(params->rate) > sizeof(supported_rates) ||
+    if (params->rate >= sizeof(supported_rates) * BITS_PER_BYTE ||
         !(supported_rates & BIT(params->rate))) {
         error_report("Stream rate is not supported.");
         return cpu_to_le32(VIRTIO_SND_S_NOT_SUPP);