qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Volker Rümelin" <vr_qemu@t-online.de>
To: "Gerd Hoffmann" <kraxel@redhat.com>,
	"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: [PATCH 05/10] hw/audio/virtio-sound: return correct command response size
Date: Thu,  4 Jan 2024 21:34:17 +0100	[thread overview]
Message-ID: <20240104203422.12308-5-vr_qemu@t-online.de> (raw)
In-Reply-To: <b416aee3-72a9-4642-b219-3e1800ee5b3c@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.

Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
 hw/audio/virtio-snd.c         | 7 +++++--
 include/hw/audio/virtio-snd.h | 1 +
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
index a2817a64b5..9f3269d72b 100644
--- a/hw/audio/virtio-snd.c
+++ b/hw/audio/virtio-snd.c
@@ -262,12 +262,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);
 }
 
 /*
@@ -805,7 +806,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);
 }
 
@@ -856,6 +858,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));
     }
diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h
index d1a68444d0..d6e08bd30d 100644
--- a/include/hw/audio/virtio-snd.h
+++ b/include/hw/audio/virtio-snd.h
@@ -210,6 +210,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
-- 
2.35.3



  parent reply	other threads:[~2024-01-04 20:35 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-04 20:32 [PATCH 00/10] virtio-sound migration part 1 Volker Rümelin
2024-01-04 20:34 ` [PATCH 01/10] hw/audio/virtio-sound: remove command and stream mutexes Volker Rümelin
2024-01-05 10:10   ` Marc-André Lureau
2024-01-04 20:34 ` [PATCH 02/10] hw/audio/virtio-sound: allocate all streams in advance Volker Rümelin
2024-01-05 10:54   ` Marc-André Lureau
2024-01-06 12:24     ` Volker Rümelin
2024-01-04 20:34 ` [PATCH 03/10] hw/audio/virtio-sound: split out virtio_snd_pcm_start_stop() Volker Rümelin
2024-01-05 10:57   ` Marc-André Lureau
2024-01-04 20:34 ` [PATCH 04/10] hw/audio/virtio-sound: add stream state variable Volker Rümelin
2024-01-04 20:34 ` Volker Rümelin [this message]
2024-01-05 11:36   ` [PATCH 05/10] hw/audio/virtio-sound: return correct command response size Marc-André Lureau
2024-02-18  8:19     ` Volker Rümelin
2024-01-04 20:34 ` [PATCH 06/10] hw/audio/virtio-sound: introduce virtio_snd_pcm_open() Volker Rümelin
2024-01-05 11:39   ` Marc-André Lureau
2024-01-04 20:34 ` [PATCH 07/10] hw/audio/virtio-sound: introduce virtio_snd_set_active() Volker Rümelin
2024-01-05 11:40   ` Marc-André Lureau
2024-01-04 20:34 ` [PATCH 08/10] hw/audio/virtio-sound: fix segmentation fault in tx/rx xfer handler Volker Rümelin
2024-01-04 20:34 ` [PATCH 09/10] hw/audio/virtio-sound: add missing vmstate fields Volker Rümelin
2024-01-04 20:34 ` [PATCH 10/10] hw/audio/virtio-sound: add placeholder for buffer write position Volker Rümelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240104203422.12308-5-vr_qemu@t-online.de \
    --to=vr_qemu@t-online.de \
    --cc=kraxel@redhat.com \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=marcandre.lureau@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).