[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 30/68] hw/audio/virtio-sound: return correct command response size
From: |
Michael S. Tsirkin |
Subject: |
[PULL 30/68] hw/audio/virtio-sound: return correct command response size |
Date: |
Tue, 12 Mar 2024 18:27:02 -0400 |
From: Volker Rümelin <vr_qemu@t-online.de>
The payload size returned by command VIRTIO_SND_R_PCM_INFO is
wrong. The code in process_cmd() assumes that all commands
return only a virtio_snd_hdr payload, but some commands like
VIRTIO_SND_R_PCM_INFO may return an additional payload.
Add a zero initialized payload_size variable to struct
virtio_snd_ctrl_command to allow for additional payloads.
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20240218083351.8524-1-vr_qemu@t-online.de>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/audio/virtio-snd.h | 1 +
hw/audio/virtio-snd.c | 7 +++++--
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h
index c3767f442b..3d79181364 100644
--- a/include/hw/audio/virtio-snd.h
+++ b/include/hw/audio/virtio-snd.h
@@ -230,6 +230,7 @@ struct virtio_snd_ctrl_command {
VirtQueue *vq;
virtio_snd_hdr ctrl;
virtio_snd_hdr resp;
+ size_t payload_size;
QTAILQ_ENTRY(virtio_snd_ctrl_command) next;
};
#endif
diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
index ea2aeaef14..e604d8f30c 100644
--- a/hw/audio/virtio-snd.c
+++ b/hw/audio/virtio-snd.c
@@ -243,12 +243,13 @@ static void virtio_snd_handle_pcm_info(VirtIOSound *s,
memset(&pcm_info[i].padding, 0, 5);
}
+ cmd->payload_size = sizeof(virtio_snd_pcm_info) * count;
cmd->resp.code = cpu_to_le32(VIRTIO_SND_S_OK);
iov_from_buf(cmd->elem->in_sg,
cmd->elem->in_num,
sizeof(virtio_snd_hdr),
pcm_info,
- sizeof(virtio_snd_pcm_info) * count);
+ cmd->payload_size);
}
/*
@@ -749,7 +750,8 @@ process_cmd(VirtIOSound *s, virtio_snd_ctrl_command *cmd)
0,
&cmd->resp,
sizeof(virtio_snd_hdr));
- virtqueue_push(cmd->vq, cmd->elem, sizeof(virtio_snd_hdr));
+ virtqueue_push(cmd->vq, cmd->elem,
+ sizeof(virtio_snd_hdr) + cmd->payload_size);
virtio_notify(VIRTIO_DEVICE(s), cmd->vq);
}
@@ -808,6 +810,7 @@ static void virtio_snd_handle_ctrl(VirtIODevice *vdev,
VirtQueue *vq)
cmd->elem = elem;
cmd->vq = vq;
cmd->resp.code = cpu_to_le32(VIRTIO_SND_S_OK);
+ /* implicit cmd->payload_size = 0; */
QTAILQ_INSERT_TAIL(&s->cmdq, cmd, next);
elem = virtqueue_pop(vq, sizeof(VirtQueueElement));
}
--
MST
- [PULL 19/68] libvhost-user: Don't search for duplicates when removing memory regions, (continued)
- [PULL 19/68] libvhost-user: Don't search for duplicates when removing memory regions, Michael S. Tsirkin, 2024/03/12
- [PULL 23/68] libvhost-user: Factor out vq usability check, Michael S. Tsirkin, 2024/03/12
- [PULL 26/68] pcie: Support PCIe Gen5/Gen6 link speeds, Michael S. Tsirkin, 2024/03/12
- [PULL 21/68] libvhost-user: Speedup gpa_to_mem_region() and vu_gpa_to_va(), Michael S. Tsirkin, 2024/03/12
- [PULL 22/68] libvhost-user: Use most of mmap_offset as fd_offset, Michael S. Tsirkin, 2024/03/12
- [PULL 27/68] vdpa: stash memory region properties in vars, Michael S. Tsirkin, 2024/03/12
- [PULL 20/68] libvhost-user: Factor out search for memory region by GPA and simplify, Michael S. Tsirkin, 2024/03/12
- [PULL 24/68] libvhost-user: Dynamically remap rings after (temporarily?) removing memory regions, Michael S. Tsirkin, 2024/03/12
- [PULL 28/68] vdpa: trace skipped memory sections, Michael S. Tsirkin, 2024/03/12
- [PULL 29/68] hw/pci-bridge/pxb-cxl: Drop RAS capability from host bridge., Michael S. Tsirkin, 2024/03/12
- [PULL 30/68] hw/audio/virtio-sound: return correct command response size,
Michael S. Tsirkin <=
- [PULL 31/68] hw/virtio: check owner for removing objects, Michael S. Tsirkin, 2024/03/12
- [PULL 33/68] hw/cxl/cxl-host: Fix missing ERRP_GUARD() in cxl_fixed_memory_window_config(), Michael S. Tsirkin, 2024/03/12
- [PULL 25/68] libvhost-user: Mark mmap'ed region memory as MADV_DONTDUMP, Michael S. Tsirkin, 2024/03/12
- [PULL 32/68] hw/virtio: Add support for VDPA network simulation devices, Michael S. Tsirkin, 2024/03/12
- [PULL 34/68] hw/display/macfb: Fix missing ERRP_GUARD() in macfb_nubus_realize(), Michael S. Tsirkin, 2024/03/12