* [PATCH 0/3] virtio-snd: snapshot prep cleanups
@ 2026-03-10 23:56 Roman Kiryanov
2026-03-10 23:56 ` [PATCH 1/3] virtio-snd: remove the unused field Roman Kiryanov
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Roman Kiryanov @ 2026-03-10 23:56 UTC (permalink / raw)
To: philmd, manos.pitsidianakis
Cc: qemu-devel, whollins, jansene, jpcottin, Roman Kiryanov
I am currently working on adding snapshot support for the virtio-snd
device. While implementing the VMStateDescription, I noticed that the
device currently retains more internal state than is strictly necessary,
including unused fields and full transport-specific layouts.
This patch series cleans up the internal PCM state to reduce the overall
allocation footprint and simplify the upcoming snapshotting and migration
handling code.
Roman Kiryanov (3):
virtio-snd: remove the unused field
virtio-snd: remove virtio_snd_pcm_set_params from VirtIOSoundPCMStream
virtio-snd: introduce VirtIOPcmParams
hw/audio/virtio-snd.c | 21 +++++++++------------
include/hw/audio/virtio-snd.h | 17 +++++++++++++----
2 files changed, 22 insertions(+), 16 deletions(-)
--
2.53.0.473.g4a7958ca14-goog
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] virtio-snd: remove the unused field
2026-03-10 23:56 [PATCH 0/3] virtio-snd: snapshot prep cleanups Roman Kiryanov
@ 2026-03-10 23:56 ` Roman Kiryanov
2026-03-10 23:56 ` [PATCH 2/3] virtio-snd: remove virtio_snd_pcm_set_params from VirtIOSoundPCMStream Roman Kiryanov
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Roman Kiryanov @ 2026-03-10 23:56 UTC (permalink / raw)
To: philmd, manos.pitsidianakis
Cc: qemu-devel, whollins, jansene, jpcottin, Roman Kiryanov
VirtIOSoundPCMStream::positions is set but
never read from. It can be added back once
required.
Signed-off-by: Roman Kiryanov <rkir@google.com>
---
hw/audio/virtio-snd.c | 3 ---
include/hw/audio/virtio-snd.h | 2 --
2 files changed, 5 deletions(-)
diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
index fb5cff3866..bd6a5d71bb 100644
--- a/hw/audio/virtio-snd.c
+++ b/hw/audio/virtio-snd.c
@@ -462,9 +462,6 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, uint32_t stream_id)
stream->info.formats = supported_formats;
stream->info.rates = supported_rates;
stream->params = *params;
-
- stream->positions[0] = VIRTIO_SND_CHMAP_FL;
- stream->positions[1] = VIRTIO_SND_CHMAP_FR;
stream->as = as;
if (stream->info.direction == VIRTIO_SND_D_OUTPUT) {
diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h
index e28f1be5db..f8bb5c95b9 100644
--- a/include/hw/audio/virtio-snd.h
+++ b/include/hw/audio/virtio-snd.h
@@ -137,8 +137,6 @@ struct VirtIOSoundPCMStream {
virtio_snd_pcm_info info;
virtio_snd_pcm_set_params params;
uint32_t id;
- /* channel position values (VIRTIO_SND_CHMAP_XXX) */
- uint8_t positions[VIRTIO_SND_CHMAP_MAX_SIZE];
VirtIOSound *s;
bool flushing;
audsettings as;
--
2.53.0.473.g4a7958ca14-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] virtio-snd: remove virtio_snd_pcm_set_params from VirtIOSoundPCMStream
2026-03-10 23:56 [PATCH 0/3] virtio-snd: snapshot prep cleanups Roman Kiryanov
2026-03-10 23:56 ` [PATCH 1/3] virtio-snd: remove the unused field Roman Kiryanov
@ 2026-03-10 23:56 ` Roman Kiryanov
2026-03-10 23:56 ` [PATCH 3/3] virtio-snd: introduce VirtIOPcmParams Roman Kiryanov
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Roman Kiryanov @ 2026-03-10 23:56 UTC (permalink / raw)
To: philmd, manos.pitsidianakis
Cc: qemu-devel, whollins, jansene, jpcottin, Roman Kiryanov
The virtio_snd_pcm_set_params values are latched
into a VirtIOSoundPCMStream instance during
the PREPARE request where they are converted into
audsettings. Only the `period_bytes` value is used
afterwards.
Having both audsettings and virtio_snd_pcm_set_params
next to each other grows sizeof and adds confusion to
snapshot handling.
Signed-off-by: Roman Kiryanov <rkir@google.com>
---
hw/audio/virtio-snd.c | 6 +++---
include/hw/audio/virtio-snd.h | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
index bd6a5d71bb..6d820b56a6 100644
--- a/hw/audio/virtio-snd.c
+++ b/hw/audio/virtio-snd.c
@@ -461,7 +461,7 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, uint32_t stream_id)
stream->info.channels_max = as.nchannels;
stream->info.formats = supported_formats;
stream->info.rates = supported_rates;
- stream->params = *params;
+ stream->period_bytes = params->period_bytes;
stream->as = as;
if (stream->info.direction == VIRTIO_SND_D_OUTPUT) {
@@ -1271,7 +1271,7 @@ static void virtio_snd_pcm_in_cb(void *data, int available)
return_rx_buffer(stream, buffer);
break;
}
- to_read = stream->params.period_bytes - buffer->size;
+ to_read = stream->period_bytes - buffer->size;
to_read = MIN(to_read, available);
to_read = MIN(to_read, max_size - buffer->size);
size = audio_be_read(stream->s->audio_be,
@@ -1284,7 +1284,7 @@ static void virtio_snd_pcm_in_cb(void *data, int available)
}
buffer->size += size;
available -= size;
- if (buffer->size >= stream->params.period_bytes) {
+ if (buffer->size >= stream->period_bytes) {
return_rx_buffer(stream, buffer);
break;
}
diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h
index f8bb5c95b9..a767f68301 100644
--- a/include/hw/audio/virtio-snd.h
+++ b/include/hw/audio/virtio-snd.h
@@ -135,8 +135,8 @@ struct VirtIOSoundPCM {
struct VirtIOSoundPCMStream {
virtio_snd_pcm_info info;
- virtio_snd_pcm_set_params params;
uint32_t id;
+ uint32_t period_bytes; /* from virtio_snd_pcm_set_params */
VirtIOSound *s;
bool flushing;
audsettings as;
--
2.53.0.473.g4a7958ca14-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] virtio-snd: introduce VirtIOPcmParams
2026-03-10 23:56 [PATCH 0/3] virtio-snd: snapshot prep cleanups Roman Kiryanov
2026-03-10 23:56 ` [PATCH 1/3] virtio-snd: remove the unused field Roman Kiryanov
2026-03-10 23:56 ` [PATCH 2/3] virtio-snd: remove virtio_snd_pcm_set_params from VirtIOSoundPCMStream Roman Kiryanov
@ 2026-03-10 23:56 ` Roman Kiryanov
2026-03-24 21:04 ` [PATCH 0/3] virtio-snd: snapshot prep cleanups Roman Kiryanov
2026-03-25 8:48 ` Marc-André Lureau
4 siblings, 0 replies; 6+ messages in thread
From: Roman Kiryanov @ 2026-03-10 23:56 UTC (permalink / raw)
To: philmd, manos.pitsidianakis
Cc: qemu-devel, whollins, jansene, jpcottin, Roman Kiryanov
Introduce the `VirtIOPcmParams` struct to represent
the payload of `virtio_snd_pcm_set_params` without
the VirtIO transport-specific header fields.
By decoupling the internal PCM state from the
transport layout, `VirtIOPcmParams` simplifies the
snapshot and migration handling code and slightly
reduces the allocation footprint per stream.
Signed-off-by: Roman Kiryanov <rkir@google.com>
---
hw/audio/virtio-snd.c | 12 ++++++------
include/hw/audio/virtio-snd.h | 13 ++++++++++++-
2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
index 6d820b56a6..8899eb7d5e 100644
--- a/hw/audio/virtio-snd.c
+++ b/hw/audio/virtio-snd.c
@@ -139,8 +139,8 @@ static VirtIOSoundPCMStream *virtio_snd_pcm_get_stream(VirtIOSound *s,
* @s: VirtIOSound device
* @stream_id: stream id
*/
-static virtio_snd_pcm_set_params *virtio_snd_pcm_get_params(VirtIOSound *s,
- uint32_t stream_id)
+static VirtIOPcmParams *virtio_snd_pcm_get_params(VirtIOSound *s,
+ uint32_t stream_id)
{
return stream_id >= s->snd_conf.streams ? NULL
: &s->pcm.pcm_params[stream_id];
@@ -258,7 +258,7 @@ uint32_t virtio_snd_set_pcm_params(VirtIOSound *s,
uint32_t stream_id,
virtio_snd_pcm_set_params *params)
{
- virtio_snd_pcm_set_params *st_params;
+ VirtIOPcmParams *st_params;
if (stream_id >= s->snd_conf.streams || s->pcm.pcm_params == NULL) {
virtio_error(VIRTIO_DEVICE(s), "Streams have not been initialized.\n");
@@ -384,7 +384,7 @@ static uint32_t virtio_snd_get_qemu_freq(uint32_t rate)
* params.
*/
static void virtio_snd_get_qemu_audsettings(audsettings *as,
- virtio_snd_pcm_set_params *params)
+ VirtIOPcmParams *params)
{
as->nchannels = MIN(AUDIO_MAX_CHANNELS, params->channels);
as->fmt = virtio_snd_get_qemu_format(params->format);
@@ -421,7 +421,7 @@ static void virtio_snd_pcm_close(VirtIOSoundPCMStream *stream)
static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, uint32_t stream_id)
{
audsettings as;
- virtio_snd_pcm_set_params *params;
+ VirtIOPcmParams *params;
VirtIOSoundPCMStream *stream;
if (s->pcm.streams == NULL ||
@@ -1063,7 +1063,7 @@ static void virtio_snd_realize(DeviceState *dev, Error **errp)
vsnd->pcm.streams =
g_new0(VirtIOSoundPCMStream *, vsnd->snd_conf.streams);
vsnd->pcm.pcm_params =
- g_new0(virtio_snd_pcm_set_params, vsnd->snd_conf.streams);
+ g_new0(VirtIOPcmParams, vsnd->snd_conf.streams);
virtio_init(vdev, VIRTIO_ID_SOUND, sizeof(virtio_snd_config));
virtio_add_feature(&vsnd->features, VIRTIO_F_VERSION_1);
diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h
index a767f68301..e9fa9c620d 100644
--- a/include/hw/audio/virtio-snd.h
+++ b/include/hw/audio/virtio-snd.h
@@ -71,6 +71,8 @@ typedef struct virtio_snd_pcm_status virtio_snd_pcm_status;
typedef struct VirtIOSound VirtIOSound;
+typedef struct VirtIOPcmParams VirtIOPcmParams;
+
typedef struct VirtIOSoundPCMStream VirtIOSoundPCMStream;
typedef struct virtio_snd_ctrl_command virtio_snd_ctrl_command;
@@ -121,6 +123,15 @@ struct VirtIOSoundPCMBuffer {
uint8_t data[];
};
+struct VirtIOPcmParams {
+ uint32_t buffer_bytes;
+ uint32_t period_bytes;
+ uint32_t features;
+ uint8_t channels;
+ uint8_t format;
+ uint8_t rate;
+};
+
struct VirtIOSoundPCM {
/*
* PCM parameters are a separate field instead of a VirtIOSoundPCMStream
@@ -129,7 +140,7 @@ struct VirtIOSoundPCM {
* means that some times we get parameters without having an allocated
* stream yet.
*/
- virtio_snd_pcm_set_params *pcm_params;
+ VirtIOPcmParams *pcm_params;
VirtIOSoundPCMStream **streams;
};
--
2.53.0.473.g4a7958ca14-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/3] virtio-snd: snapshot prep cleanups
2026-03-10 23:56 [PATCH 0/3] virtio-snd: snapshot prep cleanups Roman Kiryanov
` (2 preceding siblings ...)
2026-03-10 23:56 ` [PATCH 3/3] virtio-snd: introduce VirtIOPcmParams Roman Kiryanov
@ 2026-03-24 21:04 ` Roman Kiryanov
2026-03-25 8:48 ` Marc-André Lureau
4 siblings, 0 replies; 6+ messages in thread
From: Roman Kiryanov @ 2026-03-24 21:04 UTC (permalink / raw)
To: philmd, manos.pitsidianakis; +Cc: qemu-devel, whollins, jansene, jpcottin
On Tue, Mar 10, 2026 at 4:56 PM Roman Kiryanov <rkir@google.com> wrote:
> I am currently working on adding snapshot support for the virtio-snd device.
>
> This patch series cleans up the internal PCM state ...
Hi everyone, just a quick ping on this cleanup series.
Let me know if anyone has had a chance to look over these patch series
or if there are any concerns.
Thanks, Roman
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/3] virtio-snd: snapshot prep cleanups
2026-03-10 23:56 [PATCH 0/3] virtio-snd: snapshot prep cleanups Roman Kiryanov
` (3 preceding siblings ...)
2026-03-24 21:04 ` [PATCH 0/3] virtio-snd: snapshot prep cleanups Roman Kiryanov
@ 2026-03-25 8:48 ` Marc-André Lureau
4 siblings, 0 replies; 6+ messages in thread
From: Marc-André Lureau @ 2026-03-25 8:48 UTC (permalink / raw)
To: Roman Kiryanov
Cc: philmd, manos.pitsidianakis, qemu-devel, whollins, jansene,
jpcottin
Hi
On Wed, Mar 11, 2026 at 3:57 AM Roman Kiryanov <rkir@google.com> wrote:
>
> I am currently working on adding snapshot support for the virtio-snd
> device. While implementing the VMStateDescription, I noticed that the
> device currently retains more internal state than is strictly necessary,
> including unused fields and full transport-specific layouts.
>
> This patch series cleans up the internal PCM state to reduce the overall
> allocation footprint and simplify the upcoming snapshotting and migration
> handling code.
>
> Roman Kiryanov (3):
> virtio-snd: remove the unused field
> virtio-snd: remove virtio_snd_pcm_set_params from VirtIOSoundPCMStream
> virtio-snd: introduce VirtIOPcmParams
>
> hw/audio/virtio-snd.c | 21 +++++++++------------
> include/hw/audio/virtio-snd.h | 17 +++++++++++++----
> 2 files changed, 22 insertions(+), 16 deletions(-)
For the series:
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
--
Marc-André Lureau
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-03-25 8:49 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-10 23:56 [PATCH 0/3] virtio-snd: snapshot prep cleanups Roman Kiryanov
2026-03-10 23:56 ` [PATCH 1/3] virtio-snd: remove the unused field Roman Kiryanov
2026-03-10 23:56 ` [PATCH 2/3] virtio-snd: remove virtio_snd_pcm_set_params from VirtIOSoundPCMStream Roman Kiryanov
2026-03-10 23:56 ` [PATCH 3/3] virtio-snd: introduce VirtIOPcmParams Roman Kiryanov
2026-03-24 21:04 ` [PATCH 0/3] virtio-snd: snapshot prep cleanups Roman Kiryanov
2026-03-25 8:48 ` Marc-André Lureau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox