On Tue, Nov 10, 2026 at 02:39:30PM +0200, Manos Pitsidianakis wrote:
> virtio_error() also signals a RESET, which is not what we want: we want
> the guest driver to read the VIRTIO_SND_S_BAD_MSG response.
> 
> If a guest sends an invalid command and we do virtio_error() and reply
> with a BAD_MSG response, the guest needs to detect the device reset
> otherwise it hangs forever waiting for the response.
> 
> Signed-off-by: Manos Pitsidianakis <[email protected]>
> ---
>  hw/audio/virtio-snd.c | 29 ++++++++++++++---------------
>  1 file changed, 14 insertions(+), 15 deletions(-)
> 
> diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c
> index fb22d79949..bed36203f2 100644
> --- a/hw/audio/virtio-snd.c
> +++ b/hw/audio/virtio-snd.c
> @@ -298,8 +298,8 @@ uint32_t virtio_snd_set_pcm_params(VirtIOSound *s,
>  
>      stream = virtio_snd_pcm_get_stream(s, stream_id);
>      if (!stream) {
> -        virtio_error(VIRTIO_DEVICE(s), "invalid stream id: %"PRIu32,
> -                     stream_id);
> +        error_report("%s invalid stream id: %"PRIu32,
> +                     VIRTIO_DEVICE(s)->name, stream_id);
>          return cpu_to_le32(VIRTIO_SND_S_BAD_MSG);
>      }
>  
> @@ -310,8 +310,8 @@ uint32_t virtio_snd_set_pcm_params(VirtIOSound *s,
>      case VIRTIO_SND_PCM_STATE_RELEASED:
>          break;
>      default:
> -        virtio_error(VIRTIO_DEVICE(s), "unexpected stream state: %"PRIu32,
> -                     stream->state);
> +        error_report("%s unexpected stream state in %s: %"PRIu32,
> +                     VIRTIO_DEVICE(s)->name, __func__, stream->state);
>          return cpu_to_le32(VIRTIO_SND_S_BAD_MSG);
>      }
>  
> @@ -535,8 +535,8 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, 
> uint32_t stream_id)
>      case VIRTIO_SND_PCM_STATE_RELEASED:
>          break;
>      default:
> -        virtio_error(VIRTIO_DEVICE(s), "unexpected stream state: %"PRIu32,
> -                     stream->state);
> +        error_report("%s unexpected stream state in %s: %"PRIu32,
> +                     VIRTIO_DEVICE(s)->name, __func__, stream->state);
>          return cpu_to_le32(VIRTIO_SND_S_BAD_MSG);
>      }
>  
> @@ -624,8 +624,8 @@ static uint32_t virtio_snd_pcm_start_stop(VirtIOSound *s,
>          case VIRTIO_SND_PCM_STATE_STOPPED:
>              break;
>          default:
> -            virtio_error(VIRTIO_DEVICE(s), "unexpected stream state: 
> %"PRIu32,
> -                         stream->state);
> +            error_report("%s unexpected stream state in %s start: %"PRIu32,
> +                         VIRTIO_DEVICE(s)->name, __func__, stream->state);
>              return cpu_to_le32(VIRTIO_SND_S_BAD_MSG);
>          }
>  
> @@ -635,7 +635,8 @@ static uint32_t virtio_snd_pcm_start_stop(VirtIOSound *s,
>          case VIRTIO_SND_PCM_STATE_STARTED:
>              break;
>          default:
> -            virtio_error(VIRTIO_DEVICE(s), "unexpected stream state: 
> %"PRIu32,
> +            error_report("%s unexpected stream state in %s stop: %"PRIu32,
> +                         VIRTIO_DEVICE(s)->name, __func__,
>                           stream->state);
>              return cpu_to_le32(VIRTIO_SND_S_BAD_MSG);
>          }
> @@ -724,10 +725,8 @@ static void virtio_snd_handle_pcm_release(VirtIOSound *s,
>      trace_virtio_snd_handle_pcm_release(stream_id);
>      stream = virtio_snd_pcm_get_stream(s, stream_id);
>      if (stream == NULL) {
> -        error_report("already released stream %"PRIu32, stream_id);
> -        virtio_error(VIRTIO_DEVICE(s),
> -                     "already released stream %"PRIu32,
> -                     stream_id);
> +        error_report("%s already released stream %"PRIu32,
> +                     VIRTIO_DEVICE(s)->name, stream_id);
>          cmd->resp.code = cpu_to_le32(VIRTIO_SND_S_BAD_MSG);
>          return;
>      }
> @@ -737,8 +736,8 @@ static void virtio_snd_handle_pcm_release(VirtIOSound *s,
>      case VIRTIO_SND_PCM_STATE_STOPPED:
>          break;
>      default:
> -        virtio_error(VIRTIO_DEVICE(s), "unexpected stream state: %"PRIu32,
> -                     stream->state);
> +        error_report("%s unexpected stream state in %s: %"PRIu32,
> +                     VIRTIO_DEVICE(s)->name, __func__, stream->state);
>          cmd->resp.code = cpu_to_le32(VIRTIO_SND_S_BAD_MSG);
>          return;
>      }

Reviewed-by: Jim MacArthur <[email protected]>


Reply via email to