From nobody Sat Sep 26 20:52:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1789716982; cv=none; d=zohomail.com; s=zohoarc; b=OIJFJWB2ImbqGuSTcbhRSZ1yNhZsD7E95JeL/adCHQcPFPo3cjyWRcyS1IKsU6jHsHfrIqgMF5fljWW4ts2Gd0/iy1ndjr57f7DCD2ffyirGivk+SawPa7fBZo6VFJh8bHSNrSYlFqJ/LMwpaBaLRvwRR2+4Q2AfhsgiiG/vCvs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789716982; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fdG8iXqPUCUC/4wJK/Az/Smh8dRjZ4Q22DabWoEWdDE=; b=FPTVT9nr06JQYB1uLpMObS3YAr1/6xcEfaWXNqNkd+H4maHy0qXN/CwY/LbJX3i/jGxSsX94E0PzDQAhWZZa+SyFmBT+cmRAaTv3UtNlhli+LO6lvalSP1k8IB1G7P7QrwTyUfduvhnjL+4bGL+DNbjwKpyKca/EjbiBQSgWHjU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789716982093747.0825873626238; Fri, 18 Sep 2026 00:36:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x7T7r-0005dN-BP; Fri, 18 Sep 2026 03:35:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x7T7n-0005cM-DO for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:11 -0400 Received: from mail-wm2-x11.google.com ([2a00:1450:4864:31::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x7T7k-00071I-2w for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:11 -0400 Received: by mail-wm2-x11.google.com with SMTP id 5b1f17b1804b1-49e6b885ef8so2242935e9.1 for ; Fri, 18 Sep 2026 00:35:06 -0700 (PDT) Received: from localhost.localdomain (athedsl-116222.home.otenet.gr. [85.75.29.157]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fc471b9a2sm23879825e9.0.2026.09.18.00.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 00:35:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789716906; x=1790321706; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=fdG8iXqPUCUC/4wJK/Az/Smh8dRjZ4Q22DabWoEWdDE=; b=VkWiK5j+LnQoV8ddSVx1zIKP/sJgXeSLK3CdGlsEKDdlgh3y0dhBaQ1RMpdEhMuxon OWVCFuxW9n4nbvX+5KzMZfwFLlCSw6NREVTjQbr71rETjDOQ6M9TYxVFLOc5k2/I/pyK l8h8kdoauXGQrGeEmszBA3timu2ebY8MtpQZA6CcuxsBh01BfTZX23xvsQNs2YGRi6v5 KU+B6RTNQtsWJ2qTBk+Fwpkh8hbwJ5C7kk0+ZOhw9rnz5liRyJeyOZ5pHo378C60Zqiu 2hKyxyJTVd20QW9R06ZWuDWZbC5W971bRPVY1O0pthj+KBgBHHOMnJSqF6K8FCnUZHMa +Afw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789716906; x=1790321706; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=fdG8iXqPUCUC/4wJK/Az/Smh8dRjZ4Q22DabWoEWdDE=; b=ZrMK8r8rSLGVPMXW3HqKQIIerZjejdX+s3t5R8YQuW6LYENi7UZb9tGC58xfVob0zJ ZIOwErmH+LW9ckbaofmBxN+u9sDV6Id7CJ/5CrUEangJebDtbXJbvxi58CNgpXtw6Z8c Xv6mPT1cdK9GRzdgjW9GnymCnZcq8uuNPkAn4ZU3EtEX0UlAo/NBv2e1bnwbYoWRJPM9 utngoFjsvu5yZ/ol0b30RhApq18e9KQ5fb+mPXpNq5qeA4lXeO/Iim2hCQLZDex9SSvw Oap6jmQ+bXyt69PeysSidFcnTxOotgwFFrBENKmtwH1wxfYCWWoRAkOqTgFLH/gGzt86 AacQ== X-Gm-Message-State: AFuF++kc+heuOdgi0kV4HdrfdYrpEUc1rmAOMXIrlWbQFB3mgbo06lTs lu2MXWBfraODVcWc+QSMLx/oF3aqzHZNLpIGFlMg2/fKxLBK3qQyT1DNFplGXbfPuiGF2sidcsf 3v9bONeU= X-Gm-Gg: AYBFou1y9jUJHrp0NFzHI7dFETnaD7L14PXEKU0izq3JaA/eQT+cMcrdb8gnj2iBOrc Bn1r6A6ht6z8MycBrkfRxEDTGK3o6Sto65LhQsDZiV3mz1jZp3/GGhCHgT3Q4DXh2gFWEwqWt8C HPpERTZfC8FzaO+sV/cSW89E7NFabq7rRooJG/VeGlocmZ4RcM4lwJIh9Z+q10vFqQMT3HQJgsu d0DBZ4rQAPbirUHFQSbD1F1qGNIqtbhSED4dq6rZLkEMN6BeYFP9+U7MGQKMnavFUKMGTVWlUDF m5SLu7SOpxWv5dBcmXLQ+aowaQrv5KlRisuO0X7Dr9L+adV6tjXCZ/Cw8+SiwTwrpRrrghkQq2i frgAvc1PCj9pLXyZd4x6m+lHIcuLkDYPcX98hRsRCDJ/Ki7LeXDRLLndNrbZkGjyLK+GN1xPupI eRu6B4G8noIcpNORZQy3rFH36NBU+x6RT3+C9R+Gj9TqLihycHhyRLKl79JaG8h7gso7JFakE8B zrP7dCaBBVmZ6FZDPs/tJzK/7P9SnsfNXnMdu6v+hbP2TKbDXQcf6vBID0WlEjHZu+FEaPlnsvl HsoMqju7wGJsjMV2d7QKhwlPTAtQkOXVmcEscO/BbbakxFmxx+PxCFEwQO3sXDQcSBYspvG7lXu o47qUboMRA8y1cAu5qV4C8im75Es/PLjEkA== X-Received: by 2002:a05:600c:4e46:b0:49e:642a:4f6f with SMTP id 5b1f17b1804b1-49fc585e9edmr16220255e9.33.1789716905703; Fri, 18 Sep 2026 00:35:05 -0700 (PDT) From: Manos Pitsidianakis To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , Gerd Hoffmann Subject: [PULL 01/10] hw/audio/virtio-sound: remove channel positions field from VirtIOSoundPCMStream Date: Fri, 18 Sep 2026 10:34:44 +0300 Message-ID: <20260918073502.3265143-2-manos.pitsidianakis@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> References: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::11; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-wm2-x11.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1789716983324158500 From: Alexander Mikhalitsyn This field seems to be useless currently, as we don't implement VIRTIO_SND_R_CHMAP_INFO. Suggested-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Alexander Mikhalitsyn Reviewed-by: Manos Pitsidianakis Reviewed-by: Marc-Andr=C3=A9 Lureau Message-ID: <20260803081159.91981-2-alexander@mihalicyn.com> Signed-off-by: Manos Pitsidianakis --- include/hw/audio/virtio-snd.h | 2 -- hw/audio/virtio-snd.c | 2 -- 2 files changed, 4 deletions(-) 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; diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index 694bcebb60..46d81cc9ec 100644 --- a/hw/audio/virtio-snd.c +++ b/hw/audio/virtio-snd.c @@ -463,8 +463,6 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, = uint32_t stream_id) stream->info.rates =3D supported_rates; stream->params =3D *params; =20 - stream->positions[0] =3D VIRTIO_SND_CHMAP_FL; - stream->positions[1] =3D VIRTIO_SND_CHMAP_FR; stream->as =3D as; =20 if (stream->info.direction =3D=3D VIRTIO_SND_D_OUTPUT) { --=20 =CE=B3=CE=B1=E1=BF=96=CE=B1 =CF=80=CF=85=CF=81=CE=AF =CE=BC=CE=B9=CF=87=CE= =B8=CE=AE=CF=84=CF=89 From nobody Sat Sep 26 20:52:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1789716978; cv=none; d=zohomail.com; s=zohoarc; b=nWJNyvj0lmQzKMGhDCXPpOAY5ELrnXILe0mkARmcBTOvS8rn2od5siyu/8r/dekPgjGqHhGz0UhreM45ZnDQA80Fx3+/ua02yr1Ws4wQ3EYbtqIVbTpnOItFKMKjMEBVKkoZSAnGhkeBz2+8MZ7Z53Q0NNbx4V3K2Z3r3ki++C8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789716978; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=TfWtRMVTGUYok1dnpe7O4lkf1E1YGNiXpJ5wSK2yxSE=; b=B4sIoJvn7fbVi/JAkoKOs+BIvsj0aFpdc3lrZL+7Vs6GwlCtG4cLDokR/rhLfOQaNgDrWALf/1pDOBpC7sQxX6hh9vaW35s7zT66eNCNkv3wrKbzPc1JDOP9vxXuu2oLrLYyq9B1fr+1fbfoBtkO09TuR66bbxbBBMD1rdzt4d4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789716978875410.4984088875128; Fri, 18 Sep 2026 00:36:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x7T7x-0005fT-7x; Fri, 18 Sep 2026 03:35:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x7T7n-0005cN-EP for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:11 -0400 Received: from mail-wm2-x11.google.com ([2a00:1450:4864:31::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x7T7k-0007A5-3N for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:11 -0400 Received: by mail-wm2-x11.google.com with SMTP id 5b1f17b1804b1-49e71cdb22bso3098975e9.2 for ; Fri, 18 Sep 2026 00:35:07 -0700 (PDT) Received: from localhost.localdomain (athedsl-116222.home.otenet.gr. [85.75.29.157]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fc471b9a2sm23879825e9.0.2026.09.18.00.35.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 00:35:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789716907; x=1790321707; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=TfWtRMVTGUYok1dnpe7O4lkf1E1YGNiXpJ5wSK2yxSE=; b=nB4Y/aTEVi76I6/7faUyrjkjXna/HuXr5Y+7II7mPf18tP+ngcNFHKDD5y+LzrGj6p Dc6JbYKfAnjqQ4cTK9YiQKP31PKfeNN/Xe2AkFkwMYA802l7excVGx1yJeLV4Nzs5pD7 Vmi4g0KvTsG+yoPPtGNlam7ZYcViXtz3IQqq7vm24ekR1fjFvrhdgPREiXMrEgvtjbk5 0O2XxkCdkC1VdQbGkAFjAK4o2F7EcbLFGvJbcwvGKMk1I5MeXE/p/HoX8OvYPCbGFwd9 d9Koc+YN6Z/wFnjp0MMG0jsKD/t1+L9sZZh0eJ3TvwShT4TN1/6LGXoyQSt87tguqZn5 UGjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789716907; x=1790321707; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=TfWtRMVTGUYok1dnpe7O4lkf1E1YGNiXpJ5wSK2yxSE=; b=aCuZQRk79LLJ1oBHfTEOA86Jq7tn3zuXA+jkznGDBZ6cWYWKpPtBnb11Ec4ypSPgyJ IA7RV6oWldBJONDdHzjKhizHay67sg4rHeJx41xd6RNZCY+9UlB49SdwrQ/rl+hOKpMV mfBS4fEYkRkvSyp7fM65sFN7ER9/Zf4vr3GJJ3WPNFH0sdOet/ENhdefFV/Pwqcv5HNV LCEtA45oQiIZcrn0VtVdcIeN5JrXm8phmPXv6U6o83Ybo8saOtF3Kk6y79jlJhXbAz3c XAT1YcCCwLsDu2E3kvU/JWK923YLyUgYtWHdv1ktTQFQeAjJfGKYQ/syqY5T/sL3SwQl M37A== X-Gm-Message-State: AFuF++mpVIAni77y7F2Pt0rP4XnsZfD/A/9EJbwH3P00ubOQucvludWZ YmOKqV9K7lVYwBuO2N4dGYe4jMionBOJ62+vDP1ytuT+j9iGQ/LbpWvcmsI+1KrbjXHC3Pptlsw noa3nMcI= X-Gm-Gg: AYBFou1MIzF7E+nBYsRsmOGHznelIePFfG2i4TakcdtcAwfkEz1PAXzhKCMapMrLIs2 jXjJIBEb+Q3Xc0KaEGUAyCF/01XUe1xJyRFhDTqIRtFc1SbkwamQayMu3Xja1k2zqCY55PsWzpm 53xntpmZDLZ7bFJcMiduhbDkOcpSw7OBbj0Qmql0nvYoa/t9+ifQLo0+8+RYBkWwFnSYSfu2cU7 VFx3et3zOF/K0hq5qRKz/4qJQfXFvI43l64N7K1czEKKoxObUVDFkWbcncUzEwtReZDTK/1+rnw kBINFexc/xzfMiYFMj3bTXma4es4H3kpBumykE7sTf2WYeXV2/C5OlhUmHC3AnM5ybFhoGEXn8t KnNFHBvsg/F4mrngx4TszJ51SKOu9WcDUrpNPpJqySV2DF5AcNYjVikbpCcCMheGUmT62GmuI9m BzkprUzP/QA59b/Rp0VHo+1m/hcRM/DuTVQsdlOw3679IhaIwCneV3xCWvFobDVnpU3ZyGQB4mg vccJnpCdwpjiiO9yUeh3RkyrYGGhY3gwsDsQvBR47tBhl/g0CTK3FBf2NcUeriQOkdj2SdZwFTH B4E9ftinAWS7Ue0L+AP5BD89ozlj8b23xgTaJGoWSGTMX5F8armYKwPb8tqhcAFouvEp/3n3FVd Tl1nqu5geLePVFZKTM9jVQcpYb+1Di6smo1kDeuJ+0qRf X-Received: by 2002:a05:600c:6308:b0:49c:fa20:cbfd with SMTP id 5b1f17b1804b1-49fc5728e35mr16994485e9.20.1789716906620; Fri, 18 Sep 2026 00:35:06 -0700 (PDT) From: Manos Pitsidianakis To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , Gerd Hoffmann Subject: [PULL 02/10] hw/audio/virtio-sound: drop unused struct VirtIOSoundPCMStream.flushing field Date: Fri, 18 Sep 2026 10:34:45 +0300 Message-ID: <20260918073502.3265143-3-manos.pitsidianakis@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> References: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::11; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-wm2-x11.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1789716979365158500 From: Alexander Mikhalitsyn Signed-off-by: Alexander Mikhalitsyn Reviewed-by: Manos Pitsidianakis Message-ID: <20260803081159.91981-3-alexander@mihalicyn.com> Signed-off-by: Manos Pitsidianakis --- include/hw/audio/virtio-snd.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h index f8bb5c95b9..b60b098ccd 100644 --- a/include/hw/audio/virtio-snd.h +++ b/include/hw/audio/virtio-snd.h @@ -138,7 +138,6 @@ struct VirtIOSoundPCMStream { virtio_snd_pcm_set_params params; uint32_t id; VirtIOSound *s; - bool flushing; audsettings as; union { SWVoiceIn *in; --=20 =CE=B3=CE=B1=E1=BF=96=CE=B1 =CF=80=CF=85=CF=81=CE=AF =CE=BC=CE=B9=CF=87=CE= =B8=CE=AE=CF=84=CF=89 From nobody Sat Sep 26 20:52:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1789716964; cv=none; d=zohomail.com; s=zohoarc; b=WNBlI7tzjCYIxumdAUNyK8P0vWSA00yI5vyiJWDr9YjcaNcgfKsiRUKANpFbSB0RnaAuIJ0TJ81EsUSKBs8qcV0sl15xVnd7yE2LqAQB8k42tLbeRVryy31aO72dvv7xsjJtypRSRKwVYflrIbAShJXwOcTzlpguVr3iKZJBQTQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789716964; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=6M0nfJL6B1hRZbNEfE9XctLUkdS0dQKDP4zpnJvlvQU=; b=XsMbpuNw+itn+6vzhnHVcY8XSQmBE4mfxWWps3zoVpAnMVdICmyY3Y6YcwqLNcnCDS3SplP5GuBAA+zICIzRRg/DWVArOA3RVsk9/sJsvTmOp6oaake/tfVrnhnjvp/1Feg6jTYqlDZ60TLav2VaC+vl3MHp7o1vF42EICkTOZ8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789716964919794.0875774857789; Fri, 18 Sep 2026 00:36:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x7T7q-0005d8-IB; Fri, 18 Sep 2026 03:35:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x7T7o-0005ck-Co for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:12 -0400 Received: from mail-wm2-x11.google.com ([2a00:1450:4864:31::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x7T7m-0007CF-0I for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:12 -0400 Received: by mail-wm2-x11.google.com with SMTP id 5b1f17b1804b1-49b912e4ad9so2325405e9.2 for ; Fri, 18 Sep 2026 00:35:09 -0700 (PDT) Received: from localhost.localdomain (athedsl-116222.home.otenet.gr. [85.75.29.157]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fc471b9a2sm23879825e9.0.2026.09.18.00.35.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 00:35:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789716908; x=1790321708; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=6M0nfJL6B1hRZbNEfE9XctLUkdS0dQKDP4zpnJvlvQU=; b=Kn2lqyxEZPyUwX2vdvkfofiuMlnrCwPycolIPyqItJ0lZAs2p3aXkIE6/cEhxS5eIP n0bGvZ0vVd1nid3Qx7geUmy7qqVqt7VsPEgl7Bw1QN5OP8A3YFCU68N+s51RFVuHi1Fy D369M3VtcaN8bKnFkD8GHaSI/Gyn+aC+5HtLRqsVG2rAG13Dn1urQuoQAvlf3PKxrYhi EBqdjVZtFuB2wkPYN1JOYFj9wLlCNHubZoQOfu3Roau8loXFByptN2sSC46HpnoZRfW6 vrZ6kTyvXROouW6gqd3WhG3lV2sa+NQNIr2GQlkkpZafyDYf3KutarqRBCM8RxBagt0q vAUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789716908; x=1790321708; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=6M0nfJL6B1hRZbNEfE9XctLUkdS0dQKDP4zpnJvlvQU=; b=fRxvRSbRojxYURh+/9JNX/M/1TQt1rxf8YRmcFOseh5E3NWjWXf6CeUSZ6G90vNzJe mTB4Ewvs+V2RehH/2NAvFZOBzNFmo3SZV5q0XeD5ootmQQg2+AmAIHdHXCRMqs4mxdKr 4LMuoXXvXln+VaXYP+QSCMJywQ4Svt1wtMBJaZuDi7GIgla89KKAxjPFLnN+o9g36od4 FbC7VLCj7oJEaZk5zz4Wu6+BAJLfQD81OHnBMx2VTSzsAHPdu4PNjFiQn9XYBGyyyqrF dRH+KgskfCoiyoqV1gdu8W+E+arEorJfs9ClZjNecONjAvv/AgDqNLQNX39sRcdTO4Oi 5TOA== X-Gm-Message-State: AFuF++lAc0IlDh9I0ApUdeSwWtM8JqivxaH+IXaa5cpNnmPiYDB/OmXd FxasBawd3Yhu7OgNOXsoHGGOJLRQ1YCjoAi9mw42uNuHFdhNaN9AyeldtIjRNxBX0Yi8Ms7AvVf dTjKTbu4= X-Gm-Gg: AYBFou2U/6d1+TVBGQ17fK5WmrwDdTpP+k7YKpVoCHic3UMquv+ksDy5w95VyCFOm24 Jf+uftehJaUwE+1aUCYI0FqDYm5Gi8pHv5R2exmKe+cHHetsudtwVnF1fwZeA+utRSHw4noweML GxBSKvXiyYAPKGaHogNPK+m+7Br3YRo3eCzKlTf9ocXfzExxOxTdurV33pRtFXWreVkCKCHfQQQ BOQTnRB2WRtyRqEG8hQNdvoghqEGi4et7BvKJSbvzmPNuXxSebG30PbWRcp7Ah1Kft4n5aJQmQY jPw+dDgNkDKRNsKR2niZGL+ftgzKqPekKVVvo+qzP3HqQ9vbcJi2UXsvioDwmPoXuquIHxoSl7K xlF0FtcmPLZqd8Iu4ZcOtd5/mKNxAAJDYknwXxujSG07snQ6RD2JHqCDeY8jsx8LaQw9J+QMThz gJkqgnFpjrlijIkML4DeXus+u1qHWGx7raoVhRthmf5iEX6Nk2FW0cRonT4BsjMjM9VEi+GQN9u dq5no7h1vlEAx+UN4lEnDV+2n/RHjimily4oVwplpn1J87W3PRH770EOh52gosjzHCiY+uP3TFg 1huXjIpKWPlt1Xi0sGooFrkw3vvLlX4dl2rKMpSPCCZdw9E+6VEnT35Imc/LFQFjvyz4I5jqtkS WUhLHwqb3ZmxpNHQRu7c+zkTogHhkflKsMw== X-Received: by 2002:a05:600c:19d1:b0:49c:fc6e:a3d6 with SMTP id 5b1f17b1804b1-49fc574ef3cmr15840265e9.21.1789716907870; Fri, 18 Sep 2026 00:35:07 -0700 (PDT) From: Manos Pitsidianakis To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Volker=20R=C3=BCmelin?= , Alexander Mikhalitsyn , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , "Michael S. Tsirkin" Subject: [PULL 03/10] hw/audio/virtio-sound: remove command and stream mutexes Date: Fri, 18 Sep 2026 10:34:46 +0300 Message-ID: <20260918073502.3265143-4-manos.pitsidianakis@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> References: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::11; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-wm2-x11.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1789716967497158500 From: Volker R=C3=BCmelin All code in virtio-snd.c runs with the BQL held. Remove the command queue mutex and the stream queue mutexes. The qatomic functions are also not needed. [AM: there were too many conflicts, I did `git checkout --ours -- <.>` and then reimplemented the patch idea /AM] Signed-off-by: Volker R=C3=BCmelin Signed-off-by: Alexander Mikhalitsyn Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Manos Pitsidianakis Message-ID: <20260803081159.91981-4-alexander@mihalicyn.com> Signed-off-by: Manos Pitsidianakis --- include/hw/audio/virtio-snd.h | 3 - hw/audio/virtio-snd.c | 244 +++++++++++++++------------------- 2 files changed, 109 insertions(+), 138 deletions(-) diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h index b60b098ccd..884c475ffd 100644 --- a/include/hw/audio/virtio-snd.h +++ b/include/hw/audio/virtio-snd.h @@ -143,7 +143,6 @@ struct VirtIOSoundPCMStream { SWVoiceIn *in; SWVoiceOut *out; } voice; - QemuMutex queue_mutex; bool active; uint32_t latency_bytes; QSIMPLEQ_HEAD(, VirtIOSoundPCMBuffer) queue; @@ -215,9 +214,7 @@ struct VirtIOSound { AudioBackend *audio_be; VMChangeStateEntry *vmstate; virtio_snd_config snd_conf; - QemuMutex cmdq_mutex; QTAILQ_HEAD(, virtio_snd_ctrl_command) cmdq; - bool processing_cmdq; /* * Convenience queue to keep track of invalid tx/rx queue messages ins= ide * the tx/rx callbacks. diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index 46d81cc9ec..cbf739f8a7 100644 --- a/hw/audio/virtio-snd.c +++ b/hw/audio/virtio-snd.c @@ -19,7 +19,6 @@ #include "qemu/iov.h" #include "qemu/log.h" #include "qemu/error-report.h" -#include "qemu/lockable.h" #include "system/runstate.h" #include "trace.h" #include "qapi/error.h" @@ -442,7 +441,6 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, = uint32_t stream_id) stream->id =3D stream_id; stream->s =3D s; stream->latency_bytes =3D 0; - qemu_mutex_init(&stream->queue_mutex); QSIMPLEQ_INIT(&stream->queue); =20 /* @@ -566,9 +564,7 @@ static void virtio_snd_handle_pcm_start_stop(VirtIOSoun= d *s, =20 stream =3D virtio_snd_pcm_get_stream(s, stream_id); if (stream) { - WITH_QEMU_LOCK_GUARD(&stream->queue_mutex) { - stream->active =3D start; - } + stream->active =3D start; if (stream->info.direction =3D=3D VIRTIO_SND_D_OUTPUT) { audio_be_set_active_out(s->audio_be, stream->voice.out, start); } else { @@ -592,10 +588,8 @@ static size_t virtio_snd_pcm_get_io_msgs_count(VirtIOS= oundPCMStream *stream) VirtIOSoundPCMBuffer *buffer, *next; size_t count =3D 0; =20 - WITH_QEMU_LOCK_GUARD(&stream->queue_mutex) { - QSIMPLEQ_FOREACH_SAFE(buffer, &stream->queue, entry, next) { - count +=3D 1; - } + QSIMPLEQ_FOREACH_SAFE(buffer, &stream->queue, entry, next) { + count +=3D 1; } return count; } @@ -737,23 +731,15 @@ static void virtio_snd_process_cmdq(VirtIOSound *s) { virtio_snd_ctrl_command *cmd; =20 - if (unlikely(qatomic_read(&s->processing_cmdq))) { - return; - } + while (!QTAILQ_EMPTY(&s->cmdq)) { + cmd =3D QTAILQ_FIRST(&s->cmdq); =20 - WITH_QEMU_LOCK_GUARD(&s->cmdq_mutex) { - qatomic_set(&s->processing_cmdq, true); - while (!QTAILQ_EMPTY(&s->cmdq)) { - cmd =3D QTAILQ_FIRST(&s->cmdq); + /* process command */ + process_cmd(s, cmd); =20 - /* process command */ - process_cmd(s, cmd); + QTAILQ_REMOVE(&s->cmdq, cmd, next); =20 - QTAILQ_REMOVE(&s->cmdq, cmd, next); - - virtio_snd_ctrl_cmd_free(cmd); - } - qatomic_set(&s->processing_cmdq, false); + virtio_snd_ctrl_cmd_free(cmd); } } =20 @@ -896,17 +882,16 @@ static void virtio_snd_handle_tx_xfer(VirtIODevice *v= dev, VirtQueue *vq) if (!g_size_checked_add(&tmp, sizeof(VirtIOSoundPCMBuffer), size))= { goto tx_err; } - WITH_QEMU_LOCK_GUARD(&stream->queue_mutex) { - buffer =3D g_malloc0(sizeof(VirtIOSoundPCMBuffer) + size); - buffer->elem =3D elem; - buffer->populated =3D false; - buffer->vq =3D vq; - buffer->size =3D size; - buffer->offset =3D 0; - stream->latency_bytes +=3D size; =20 - QSIMPLEQ_INSERT_TAIL(&stream->queue, buffer, entry); - } + buffer =3D g_malloc0(sizeof(VirtIOSoundPCMBuffer) + size); + buffer->elem =3D elem; + buffer->populated =3D false; + buffer->vq =3D vq; + buffer->size =3D size; + buffer->offset =3D 0; + stream->latency_bytes +=3D size; + + QSIMPLEQ_INSERT_TAIL(&stream->queue, buffer, entry); continue; =20 tx_err: @@ -983,14 +968,14 @@ static void virtio_snd_handle_rx_xfer(VirtIODevice *v= dev, VirtQueue *vq) if (!g_size_checked_add(&tmp, sizeof(VirtIOSoundPCMBuffer), size))= { goto rx_err; } - WITH_QEMU_LOCK_GUARD(&stream->queue_mutex) { - buffer =3D g_malloc0(sizeof(VirtIOSoundPCMBuffer) + size); - buffer->elem =3D elem; - buffer->vq =3D vq; - buffer->size =3D 0; - buffer->offset =3D 0; - QSIMPLEQ_INSERT_TAIL(&stream->queue, buffer, entry); - } + + buffer =3D g_malloc0(sizeof(VirtIOSoundPCMBuffer) + size); + buffer->elem =3D elem; + buffer->vq =3D vq; + buffer->size =3D 0; + buffer->offset =3D 0; + QSIMPLEQ_INSERT_TAIL(&stream->queue, buffer, entry); + continue; =20 rx_err: @@ -1094,7 +1079,6 @@ static void virtio_snd_realize(DeviceState *dev, Erro= r **errp) virtio_add_queue(vdev, 64, virtio_snd_handle_tx_xfer); vsnd->queues[VIRTIO_SND_VQ_RX] =3D virtio_add_queue(vdev, 64, virtio_snd_handle_rx_xfer); - qemu_mutex_init(&vsnd->cmdq_mutex); QTAILQ_INIT(&vsnd->cmdq); QSIMPLEQ_INIT(&vsnd->invalid); =20 @@ -1162,52 +1146,50 @@ static void virtio_snd_pcm_out_cb(void *data, int a= vailable) VirtIOSoundPCMBuffer *buffer; size_t size; =20 - WITH_QEMU_LOCK_GUARD(&stream->queue_mutex) { - while (!QSIMPLEQ_EMPTY(&stream->queue)) { - buffer =3D QSIMPLEQ_FIRST(&stream->queue); - if (!virtio_queue_ready(buffer->vq)) { - return; + while (!QSIMPLEQ_EMPTY(&stream->queue)) { + buffer =3D QSIMPLEQ_FIRST(&stream->queue); + if (!virtio_queue_ready(buffer->vq)) { + return; + } + if (!stream->active) { + /* Stream has stopped, so do not perform audio_be_write. */ + return_tx_buffer(stream, buffer); + continue; + } + if (!buffer->populated) { + iov_to_buf(buffer->elem->out_sg, + buffer->elem->out_num, + sizeof(virtio_snd_pcm_xfer), + buffer->data, + buffer->size); + buffer->populated =3D true; + } + for (;;) { + size =3D audio_be_write(stream->s->audio_be, + stream->voice.out, + buffer->data + buffer->offset, + MIN(buffer->size, available)); + assert(size <=3D MIN(buffer->size, available)); + if (size =3D=3D 0) { + /* break out of both loops */ + available =3D 0; + break; } - if (!stream->active) { - /* Stream has stopped, so do not perform audio_be_write. */ + buffer->size -=3D size; + buffer->offset +=3D size; + available -=3D size; + update_latency(stream, size); + if (buffer->size < 1) { return_tx_buffer(stream, buffer); - continue; - } - if (!buffer->populated) { - iov_to_buf(buffer->elem->out_sg, - buffer->elem->out_num, - sizeof(virtio_snd_pcm_xfer), - buffer->data, - buffer->size); - buffer->populated =3D true; - } - for (;;) { - size =3D audio_be_write(stream->s->audio_be, - stream->voice.out, - buffer->data + buffer->offset, - MIN(buffer->size, available)); - assert(size <=3D MIN(buffer->size, available)); - if (size =3D=3D 0) { - /* break out of both loops */ - available =3D 0; - break; - } - buffer->size -=3D size; - buffer->offset +=3D size; - available -=3D size; - update_latency(stream, size); - if (buffer->size < 1) { - return_tx_buffer(stream, buffer); - break; - } - if (!available) { - break; - } + break; } if (!available) { break; } } + if (!available) { + break; + } } } =20 @@ -1258,55 +1240,53 @@ static void virtio_snd_pcm_in_cb(void *data, int av= ailable) VirtIOSoundPCMBuffer *buffer; size_t size, max_size, to_read; =20 - WITH_QEMU_LOCK_GUARD(&stream->queue_mutex) { - while (!QSIMPLEQ_EMPTY(&stream->queue)) { - buffer =3D QSIMPLEQ_FIRST(&stream->queue); - if (!virtio_queue_ready(buffer->vq)) { - return; - } - if (!stream->active) { - /* Stream has stopped, so do not perform audio_be_read. */ - return_rx_buffer(stream, buffer); - continue; - } + while (!QSIMPLEQ_EMPTY(&stream->queue)) { + buffer =3D QSIMPLEQ_FIRST(&stream->queue); + if (!virtio_queue_ready(buffer->vq)) { + return; + } + if (!stream->active) { + /* Stream has stopped, so do not perform audio_be_read. */ + return_rx_buffer(stream, buffer); + continue; + } + + max_size =3D iov_size(buffer->elem->in_sg, buffer->elem->in_num); + if (max_size <=3D sizeof(virtio_snd_pcm_status)) { + return_rx_buffer(stream, buffer); + continue; + } + max_size -=3D sizeof(virtio_snd_pcm_status); =20 - max_size =3D iov_size(buffer->elem->in_sg, buffer->elem->in_nu= m); - if (max_size <=3D sizeof(virtio_snd_pcm_status)) { + for (;;) { + if (buffer->size >=3D max_size) { return_rx_buffer(stream, buffer); - continue; + break; } - max_size -=3D sizeof(virtio_snd_pcm_status); - - for (;;) { - if (buffer->size >=3D max_size) { - return_rx_buffer(stream, buffer); - break; - } - to_read =3D stream->params.period_bytes - buffer->size; - to_read =3D MIN(to_read, available); - to_read =3D MIN(to_read, max_size - buffer->size); - size =3D audio_be_read(stream->s->audio_be, - stream->voice.in, - buffer->data + buffer->size, - to_read); - if (!size) { - available =3D 0; - break; - } - buffer->size +=3D size; - available -=3D size; - if (buffer->size >=3D stream->params.period_bytes) { - return_rx_buffer(stream, buffer); - break; - } - if (!available) { - break; - } + to_read =3D stream->params.period_bytes - buffer->size; + to_read =3D MIN(to_read, available); + to_read =3D MIN(to_read, max_size - buffer->size); + size =3D audio_be_read(stream->s->audio_be, + stream->voice.in, + buffer->data + buffer->size, + to_read); + if (!size) { + available =3D 0; + break; + } + buffer->size +=3D size; + available -=3D size; + if (buffer->size >=3D stream->params.period_bytes) { + return_rx_buffer(stream, buffer); + break; } if (!available) { break; } } + if (!available) { + break; + } } } =20 @@ -1323,11 +1303,9 @@ static inline void virtio_snd_pcm_flush(VirtIOSoundP= CMStream *stream) (stream->info.direction =3D=3D VIRTIO_SND_D_OUTPUT) ? return_tx_bu= ffer : return_rx_buffer; =20 - WITH_QEMU_LOCK_GUARD(&stream->queue_mutex) { - while (!QSIMPLEQ_EMPTY(&stream->queue)) { - buffer =3D QSIMPLEQ_FIRST(&stream->queue); - cb(stream, buffer); - } + while (!QSIMPLEQ_EMPTY(&stream->queue)) { + buffer =3D QSIMPLEQ_FIRST(&stream->queue); + cb(stream, buffer); } } =20 @@ -1346,14 +1324,12 @@ static void virtio_snd_unrealize(DeviceState *dev) if (stream) { virtio_snd_process_cmdq(stream->s); virtio_snd_pcm_close(stream); - qemu_mutex_destroy(&stream->queue_mutex); g_free(stream); } } g_free(vsnd->pcm.streams); } g_free(vsnd->pcm.pcm_params); - qemu_mutex_destroy(&vsnd->cmdq_mutex); virtio_delete_queue(vsnd->queues[VIRTIO_SND_VQ_CONTROL]); virtio_delete_queue(vsnd->queues[VIRTIO_SND_VQ_EVENT]); virtio_delete_queue(vsnd->queues[VIRTIO_SND_VQ_TX]); @@ -1374,12 +1350,10 @@ static void virtio_snd_reset(VirtIODevice *vdev) */ g_assert(QSIMPLEQ_EMPTY(&vsnd->invalid)); =20 - WITH_QEMU_LOCK_GUARD(&vsnd->cmdq_mutex) { - while (!QTAILQ_EMPTY(&vsnd->cmdq)) { - cmd =3D QTAILQ_FIRST(&vsnd->cmdq); - QTAILQ_REMOVE(&vsnd->cmdq, cmd, next); - virtio_snd_ctrl_cmd_free(cmd); - } + while (!QTAILQ_EMPTY(&vsnd->cmdq)) { + cmd =3D QTAILQ_FIRST(&vsnd->cmdq); + QTAILQ_REMOVE(&vsnd->cmdq, cmd, next); + virtio_snd_ctrl_cmd_free(cmd); } } =20 --=20 =CE=B3=CE=B1=E1=BF=96=CE=B1 =CF=80=CF=85=CF=81=CE=AF =CE=BC=CE=B9=CF=87=CE= =B8=CE=AE=CF=84=CF=89 From nobody Sat Sep 26 20:52:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1789716988; cv=none; d=zohomail.com; s=zohoarc; b=ahtCimfvj39gyNCKVE+NCajTMZ3L/+qHVd3/UVdIeTm3cNu+/PRxdJkEMjFQbvXYZZoSKP/ck9LLnTO4D0T5Zyq+CVg7gcxaoBYA3/REhTKzbGCpp/oZCVYgI98w4U72hOX052Vc+j1J3BX1FBt1svFWaO08c7/QtSlhUFERDXE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789716988; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ro6q4939JlTOoOj5Xj4n/vp5fXJkovksjsh3vzBpvoY=; b=CvJDfgPJBlNHYcZH8JxEAhXy7jTPplg+MDMEkRmhHSbuej3dEudaCf99hr1IfEwmOaUfVVB9FPzwrHxN/q1ttNc3zYkdPRdTUDntQ8OEOAgavTaLK+uVMqIgqCwFGTFlxCpR8Fj5LFQ2HvBUhQNnCNzwY/xA1/QdqcpAYCewnW4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789716988440983.9665337947007; Fri, 18 Sep 2026 00:36:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x7T7t-0005eD-FF; Fri, 18 Sep 2026 03:35:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x7T7o-0005ch-Ag for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:12 -0400 Received: from mail-wm2-x11.google.com ([2a00:1450:4864:31::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x7T7m-0007CP-Hn for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:12 -0400 Received: by mail-wm2-x11.google.com with SMTP id 5b1f17b1804b1-49e66390995so2086655e9.2 for ; Fri, 18 Sep 2026 00:35:10 -0700 (PDT) Received: from localhost.localdomain (athedsl-116222.home.otenet.gr. [85.75.29.157]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fc471b9a2sm23879825e9.0.2026.09.18.00.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 00:35:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789716909; x=1790321709; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=ro6q4939JlTOoOj5Xj4n/vp5fXJkovksjsh3vzBpvoY=; b=Agb60WNnpYOzanjFUJbee4br2F6sCuyE/T3oNqoh2KOWvkyz8vFGXCnEhX1rFNoVN3 va02/YJijmncUntAUoRh1f3MdNfyy0+Lc4Nx4LJ7zELBNRbUChqVkTR6wxhcLAQxW8Ah XWQZmatwyFjPGo8gaKnluisIYz57JlosfPr85GE/DfZib0ZrTvjVScY4iubZ8nTVGNmj UK8AVglszd1VTbIt3eft4C9Gfyu0JRtZI44NZaDgeN0R6olu83yZCBWhda68l3/AkHH3 BojsRT56s2/PwZX5NlcRYJGL1VrS2S4VjtuXzfDEznD9L42e80cr3G+WUWK9TvtMHiZa O2Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789716909; x=1790321709; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ro6q4939JlTOoOj5Xj4n/vp5fXJkovksjsh3vzBpvoY=; b=Kd9775Vjq2wNzXI1GL8ul5ONz7ZJd8I+EuRcMP8O3w9qPzXEbd7B5awDg4A51+oSso ZV21h8hBe6St9ygh8xn9C9RnlFBqrdB9a+0J5QpyezLf1czYXVSoa89Eiv7qtkrOtkcD LHqI3SvvhVN814l2E8Tbv2Jz5QtLHwpadwtma5MYnqhHeqwwX4dcwb1eveeOfqy4vB/h kVrmZjQppjRIVN3nRgfmByS0n2p9GvRG8O1hLNHHrozHza2ynsFDuMZy8T6smaLvPs1C sBm9WUrUEJZG0LG3SQOLizAgmjFGjWhObEkuNZQJaXCk18cGP5DdiQ6hCJY/0ArH59Kc HRUg== X-Gm-Message-State: AFuF++nzCnJFUr7yMfI4snYeg7ciaoQGOGs3j0wfOAxrdrMWf0XYoZiS AWI1BZeJ9jFqiWPiR6/+PCFqkwArhixkRTKxqbvpkM9fTwsRrkuNRsHEICiWrxhkOjQFCKIsM0m +8ntWXhg= X-Gm-Gg: AYBFou0TxdYdnDFb9SYFj/ylQ52z1DuU/CSg0mabvS6DS69hCXXe8Ldwn7wsRPjUcSX 0bnuhkQ+XRJcpZ2apA8eCgv0ru9s6xQ8lArk+sDCQoHduxE+HjMx+WOl2saXpFm5T6XkcTs+Awy TDLspqj8wU9Wd6mBRInvE3wcEFV81NBQmP/HIwSIVWv/TRKutycOlONx3j8vTQmRcvsKp0FcU3g De5WNEOpfUNHpFklREE/8fQYd0FmnPdnvBzFdNZmGNU8CWH4scPtKUdLqf2RinxF3zIwu91FC5h K656LNOIVle3ywbdMWYz6B3PNK0WS6efByg8Qiwp9lGn2T4sJ0M5d7lSlfK6TdFkMmyCfpLjW8X H+KUm5vV/G+APHY0rnjANfyaSWBDI+H7XyoACV3tFVbsiJ6zAxs0bWGFFYawbtMI7vT4PebJsdJ sNqheLyAscUP3tOuwh8BoqZXJ76aY4FSP5dTbKrP12CrUsggsUC7Y6C2aPE6lIaxWH+2WOzQj2K nztMDB5z2mvwHOdybYtLh2IP3wqWYPVtLJTcQRQ49U1QoLWMgKDpmXO5XcIhJVrW488pBlX031W OUuJB3kyfg2pQ9mPMOo29ef6Fxo51cdLBk6lZWeB6elvU81BzM+AVDZlRX+v4PnJHK+F8Qxa2je 3W5AgCC3hxdsT5We38jqSK3mQlk2Yj1EZhg== X-Received: by 2002:a05:600c:3550:b0:49e:7d74:7b7a with SMTP id 5b1f17b1804b1-49fc56db8f3mr16820525e9.6.1789716909049; Fri, 18 Sep 2026 00:35:09 -0700 (PDT) From: Manos Pitsidianakis To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Volker=20R=C3=BCmelin?= , Alexander Mikhalitsyn , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , "Michael S. Tsirkin" Subject: [PULL 04/10] hw/audio/virtio-sound: allocate an array of streams Date: Fri, 18 Sep 2026 10:34:47 +0300 Message-ID: <20260918073502.3265143-5-manos.pitsidianakis@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> References: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::11; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-wm2-x11.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1789716989603158500 From: Volker R=C3=BCmelin It is much easier to migrate an array of structs than individual structs that are accessed via a pointer to a pointer to an array of pointers to struct. For this reason, allocate an array of streams in virtio_snd_realize() and initialise all stream variables that are constant at runtime immediately after allocation. This makes it easier to remove the virtio_snd_set_pcm_params() and virtio_snd_pcm_prepare() calls in the realisation phase and to migrate the audio streams of the virtio sound device after the next few patches. [AM: there were too many conflicts, I did `git checkout --ours -- <.>` and then reimplemented the patch idea /AM] Signed-off-by: Volker R=C3=BCmelin Signed-off-by: Alexander Mikhalitsyn Reviewed-by: Marc-Andr=C3=A9 Lureau Message-ID: <20260803081159.91981-5-alexander@mihalicyn.com> Signed-off-by: Manos Pitsidianakis --- include/hw/audio/virtio-snd.h | 2 +- hw/audio/virtio-snd.c | 33 +++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h index 884c475ffd..97ffaae18b 100644 --- a/include/hw/audio/virtio-snd.h +++ b/include/hw/audio/virtio-snd.h @@ -136,7 +136,6 @@ struct VirtIOSoundPCM { struct VirtIOSoundPCMStream { virtio_snd_pcm_info info; virtio_snd_pcm_set_params params; - uint32_t id; VirtIOSound *s; audsettings as; union { @@ -211,6 +210,7 @@ struct VirtIOSound { VirtQueue *queues[VIRTIO_SND_VQ_MAX]; uint64_t features; VirtIOSoundPCM pcm; + VirtIOSoundPCMStream *streams; AudioBackend *audio_be; VMChangeStateEntry *vmstate; virtio_snd_config snd_conf; diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index cbf739f8a7..84083be882 100644 --- a/hw/audio/virtio-snd.c +++ b/hw/audio/virtio-snd.c @@ -436,12 +436,9 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s,= uint32_t stream_id) =20 stream =3D virtio_snd_pcm_get_stream(s, stream_id); if (stream =3D=3D NULL) { - stream =3D g_new0(VirtIOSoundPCMStream, 1); + stream =3D &s->streams[stream_id]; stream->active =3D false; - stream->id =3D stream_id; - stream->s =3D s; stream->latency_bytes =3D 0; - QSIMPLEQ_INIT(&stream->queue); =20 /* * stream_id >=3D s->snd_conf.streams was checked before so this is @@ -451,14 +448,7 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s,= uint32_t stream_id) } =20 virtio_snd_get_qemu_audsettings(&as, params); - stream->info.direction =3D stream_id < s->snd_conf.streams / 2 + - (s->snd_conf.streams & 1) ? VIRTIO_SND_D_OUTPUT : VIRTIO_SND_D_INP= UT; - stream->info.hdr.hda_fn_nid =3D VIRTIO_SOUND_HDA_FN_NID; - stream->info.features =3D 0; - stream->info.channels_min =3D 1; stream->info.channels_max =3D as.nchannels; - stream->info.formats =3D supported_formats; - stream->info.rates =3D supported_rates; stream->params =3D *params; =20 stream->as =3D as; @@ -1056,6 +1046,24 @@ static void virtio_snd_realize(DeviceState *dev, Err= or **errp) vsnd->vmstate =3D qemu_add_vm_change_state_handler(virtio_snd_vm_state_change, vsnd); =20 + vsnd->streams =3D g_new0(VirtIOSoundPCMStream, vsnd->snd_conf.streams); + + for (uint32_t i =3D 0; i < vsnd->snd_conf.streams; i++) { + VirtIOSoundPCMStream *stream =3D &vsnd->streams[i]; + + stream->s =3D vsnd; + QSIMPLEQ_INIT(&stream->queue); + stream->info.hdr.hda_fn_nid =3D VIRTIO_SOUND_HDA_FN_NID; + stream->info.features =3D 0; + stream->info.formats =3D supported_formats; + stream->info.rates =3D supported_rates; + stream->info.direction =3D + i < vsnd->snd_conf.streams / 2 + (vsnd->snd_conf.streams & 1) + ? VIRTIO_SND_D_OUTPUT : VIRTIO_SND_D_INPUT; + stream->info.channels_min =3D 1; + stream->info.channels_max =3D 2; + } + vsnd->pcm.streams =3D g_new0(VirtIOSoundPCMStream *, vsnd->snd_conf.streams); vsnd->pcm.pcm_params =3D @@ -1324,12 +1332,13 @@ static void virtio_snd_unrealize(DeviceState *dev) if (stream) { virtio_snd_process_cmdq(stream->s); virtio_snd_pcm_close(stream); - g_free(stream); } } g_free(vsnd->pcm.streams); } g_free(vsnd->pcm.pcm_params); + g_free(vsnd->streams); + vsnd->streams =3D NULL; virtio_delete_queue(vsnd->queues[VIRTIO_SND_VQ_CONTROL]); virtio_delete_queue(vsnd->queues[VIRTIO_SND_VQ_EVENT]); virtio_delete_queue(vsnd->queues[VIRTIO_SND_VQ_TX]); --=20 =CE=B3=CE=B1=E1=BF=96=CE=B1 =CF=80=CF=85=CF=81=CE=AF =CE=BC=CE=B9=CF=87=CE= =B8=CE=AE=CF=84=CF=89 From nobody Sat Sep 26 20:52:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1789716987; cv=none; d=zohomail.com; s=zohoarc; b=CwtG+wOM/MLZnNPdYGzRb/WXnrJziWXp/oVOLK4ByV6UUa1TykHUSU2SLSBf7m7009TeTluILWWYrCudLOJxfQ1tuMnkZPpNLoY4x3Z0w5cEeVjpFmIreSh96Frlpz5YfVF526M4PDlLOJLgjuXj3H11o33GK2NCumFzu76n9wA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789716987; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0GWHmPabWSPLaPy4afNz6W8nfAlTeFytEjlJU9wAePc=; b=oEk5HDJI+eeu7fsnAiLV8okD6UUgVMtd4uyxo2jscVuWFR4wzAnWvGhtsG+8XpTeS+rqA3qe9yhydmYStRsQJ/w1NbnVENQTVbu9UFbCVV3XjJFdapHCRgqYYAsAonVWrJTgee2a/i/LAZX06kermDwZJ0TmC1XJ7E3FR9ADszc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178971698765439.02594838609491; Fri, 18 Sep 2026 00:36:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x7T7r-0005dK-8H; Fri, 18 Sep 2026 03:35:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x7T7p-0005d0-0c for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:13 -0400 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x7T7n-0007Cs-JK for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:12 -0400 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49b912d37b5so2512645e9.2 for ; Fri, 18 Sep 2026 00:35:11 -0700 (PDT) Received: from localhost.localdomain (athedsl-116222.home.otenet.gr. [85.75.29.157]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fc471b9a2sm23879825e9.0.2026.09.18.00.35.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 00:35:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789716910; x=1790321710; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=0GWHmPabWSPLaPy4afNz6W8nfAlTeFytEjlJU9wAePc=; b=CInoJ10zO1XvJWSFrHifFHxNfmPClk0A+wpnOSVYLnyBhQoVfO/r5d8ds9K/T+uCB4 YIaeIUsjNkP+ohlPVWkzhmSdqIisSjbgiRNVIAh+YTnKbstCzsLSpq2J99nNOHikyu59 0wzUR1opqX6kMu1+AJQYx33lXoi5s2UaulKAxAbPAwtN1PN4o67Q5gfZXkkO5hSXSdzJ G4ZqySACuKNBUmeXKsgwREiCEwzJql3AXWhRAEazmoRMG98ST55Mq5GKHZ6Z1Zkxpgsv xSf25mizx0tOCGvg3Ouv4tNx52xB8+SIBatuFuJyM/nEi6+clUNDDfE6oiI4Ps2mrxEa RKDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789716910; x=1790321710; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0GWHmPabWSPLaPy4afNz6W8nfAlTeFytEjlJU9wAePc=; b=ZX6aPzwlo9pUGhxLKLBwxDa8PAVVCknsYxZUjWP1mA5hEChyPQSiIVy5HmhFO9hdzk QSFqESM8SFX+XK4Uwd9SAsQjJs8RLg+rjfn6eX2ofOfZwPILMriFVHYMpeD5eT9x6I9i GGNPPo1Zz9AwicMS7y8b6j51+W0eV2B1ETKrslKGbiuVsc1KO8r/Ws7m9BmxYyubNuTY Mb2+mOQW6IhTsbO/Xw6xNx3DsgAoigcJ7H+kwMlk1ROZCBoYFUrnNQUlAZOXjTYe/enT P2lO4UwHbIz/Wz55hulF17pSfqhUeJeWkQuafOm+z9RncodC365y1MN0xDi1XQfCAB0u aR6A== X-Gm-Message-State: AFuF++nezhWyjmh2T3HWz479d/CkWVzobrhsF1NaVtlsdwICGJpWyG1j UTzNt2HLAcC43SjjxBUln/bBONk1uSlILne3caihQV/OPaRx0zbY+Jw9lsas0mOwg4BeLj86uH6 wWKKVMx4= X-Gm-Gg: AYBFou0vHF8E2t32qwv58uH9L8VlEIRu5ybuNP8db5WOZaUkOg7BxReP5OQsF6PMiGI DdLjSrUCH0AZFtqjxSjfkmFbF7/M8gqWFdMRZDdu9PULi/rHA+pHz11hgPTqAP7Xpgqlf6EFvJf rq/tbfYhgxt40sqvD8WUdkUk1tRxF/SgIOU+WddoGhUQW8JGCeT4rTfU2bi4oMdcKILqD+ua2QR c0W59Q/nySQzdsIugdXNhGVmnOJAaizqhHiCBoByiDwaucLm5PMxUpHutp9s6D/LIL8WB6p26YG YH5wIbYHsHvkUf6oZj/iZDEgye7/oJyk8ULvlOyaC2NQwFRinEThOFDOkH9VdyeEHvpqp6MuUzv ym7Lzu3oE5PtUyaqHwvsB7eJbJj0Bjywl5sU6e9ZHFXI9daoP3vl4puwbcP/4sMsk8TOZbdDyOw rh/QUgEx6Eo1iUNymsV/BX0/foOmNJWAg9tynmQWCnLqPe1r7ANXtMLETESD7uGswsurjrzOZ6/ 5qSpTOiRBXz7N8+YEtMP0utbzdsipJBFuPa3sKsoJi5pl5KgRXuuv+I6YoFNEIoh7pn0EHHcl/2 iJIja+qM0Abvu1+WR1fQUP3eHpwLsbF0w76PYRC91J+Z38DC6Inn9gKMM1VGtkXWCy4YRrQdalC Aj7x/nAj/IL/s5f3KPcJID5q8gIxuWAAq7w== X-Received: by 2002:a05:600c:5020:b0:49d:726:cc9f with SMTP id 5b1f17b1804b1-49fc56716f2mr38764935e9.5.1789716910149; Fri, 18 Sep 2026 00:35:10 -0700 (PDT) From: Manos Pitsidianakis To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Volker=20R=C3=BCmelin?= , Alexander Mikhalitsyn , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , "Michael S. Tsirkin" Subject: [PULL 05/10] hw/audio/virtio-sound: free all stream buffers on reset Date: Fri, 18 Sep 2026 10:34:48 +0300 Message-ID: <20260918073502.3265143-6-manos.pitsidianakis@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> References: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::10; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-wm2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1789716989564158500 From: Volker R=C3=BCmelin All remaining stream buffers in the stream queues must be freed after a reset. This is the initial state of the virtio-sound device. Signed-off-by: Volker R=C3=BCmelin [AM: trivial variable rename s -> vsnd] Signed-off-by: Alexander Mikhalitsyn Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Manos Pitsidianakis Message-ID: <20260803081159.91981-6-alexander@mihalicyn.com> Signed-off-by: Manos Pitsidianakis --- hw/audio/virtio-snd.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index 84083be882..f9822fc609 100644 --- a/hw/audio/virtio-snd.c +++ b/hw/audio/virtio-snd.c @@ -1364,6 +1364,16 @@ static void virtio_snd_reset(VirtIODevice *vdev) QTAILQ_REMOVE(&vsnd->cmdq, cmd, next); virtio_snd_ctrl_cmd_free(cmd); } + + for (uint32_t i =3D 0; i < vsnd->snd_conf.streams; i++) { + VirtIOSoundPCMStream *stream =3D &vsnd->streams[i]; + VirtIOSoundPCMBuffer *buffer; + + while ((buffer =3D QSIMPLEQ_FIRST(&stream->queue))) { + QSIMPLEQ_REMOVE_HEAD(&stream->queue, entry); + virtio_snd_pcm_buffer_free(buffer); + } + } } =20 static void virtio_snd_class_init(ObjectClass *klass, const void *data) --=20 =CE=B3=CE=B1=E1=BF=96=CE=B1 =CF=80=CF=85=CF=81=CE=AF =CE=BC=CE=B9=CF=87=CE= =B8=CE=AE=CF=84=CF=89 From nobody Sat Sep 26 20:52:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1789716951; cv=none; d=zohomail.com; s=zohoarc; b=IoO7Rbh4fUQzWArpO1nC9z6I02EWNP7nkuyoVJXK1d8/J08hvEymp30NFqWR9SCex4OkCUnUGP69xhVCKWnNaVHuYGYI6wTxDu7+FW51YIJtFosxhYr1L/9l0Pp0dmOuRojSaCZZ73X2rCkMgF1tw2xydQy3+wJ2u2HjTuboJCE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789716951; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0xxlWberjV/um7rJumsSX31jfpCd1ioF9db9gWnV3gk=; b=bzkPGVk3zkVUl/TRYxc2za+eaygSqYHRSYvgIKxM2XucfV4NXHq90PwaIFO/jIgvn6d0UZOV33PI0pofHRkZhoWZ4Urc5SmruK6qW0JJflXlzAXsLXJnk1rxjhtzbtFL4tGvbbgHXhu3aV9CZet9SKx+/0sZ3q9NM872iQMNBXg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178971695116522.269824459713504; Fri, 18 Sep 2026 00:35:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x7T7w-0005fA-DH; Fri, 18 Sep 2026 03:35:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x7T7q-0005dA-At for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:14 -0400 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x7T7o-0007DG-KU for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:14 -0400 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49ccfd61ecaso3659685e9.3 for ; Fri, 18 Sep 2026 00:35:12 -0700 (PDT) Received: from localhost.localdomain (athedsl-116222.home.otenet.gr. [85.75.29.157]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fc471b9a2sm23879825e9.0.2026.09.18.00.35.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 00:35:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789716911; x=1790321711; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=0xxlWberjV/um7rJumsSX31jfpCd1ioF9db9gWnV3gk=; b=nwfv+6qZwqyUO4QBPFKdbKdYb/Q1QeBVfcogc3SLH9ElmDk2Fo0jXHMI9cRna1NQTh +L2LTEPCNFgNBJH3VbrS3qQvOqsVk1WuIEQe4Uv+jRdk1S1uO0Gs6vDc/6DfdMf2Au2i +EupQLe3iSunoR8QOZp/eARorlnpR3iXmtg1OzlHZDFji7N5K1F4mCAxFidtIx41Iv9k 2snmamQnnsrJY6kQPgrwpXM+GGr5139EOovj5+osQnSZXOmyyeek2jRv3bc/mPDyHPus Nep+T0SYhe4EpoHSpL3/UWelTvG1JL5tF0Nme4UGuQBbOqWRlTpqFNF2bBQPg3U/+K18 8ETA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789716911; x=1790321711; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0xxlWberjV/um7rJumsSX31jfpCd1ioF9db9gWnV3gk=; b=QMD3kVnoIn+cCFWujSkFNw+4Sio5wlyozTO6EaLY7s4o4QtFAqQWnRu9CLBAXv1O9H 0me8K1DUFwcToJWYrNldqEzjhFyhyxD0jK3bBDuupWlCYYTt4S4Pg344X7y7ixzvA09j p/TCrJ5C1W1Mi35CWGGxnVxQX5HXJZHwyHjBRNYqp34KbX04ZGLZd7YT8ZqG+QtBLpC/ Bpjx5pKBzZ3yXQdju+rwe9fnqf3cjRUmgozJAKz3i7dtMQVUSHy+nRf/xKJuSYkhMvkW 3ZkbkSx+vo1LoOFT9dhq3C/DiSDhEuZPW6XOsTHKZLl3Zc4n2EUzwUDVi2cJXbHjx2Ha uisQ== X-Gm-Message-State: AFuF++kMME0eB37IzvH3TAVbecBXXwSoXgvxO+aBhDIgT32JTyO/Lzoa 8eqBakh8vL7gSIpSd6JU8aorKvhdFyrSOV59edQub3F4UokVFq/V3GSas/ubtDwPdjGBA9NRofO I8Vk/7IQ= X-Gm-Gg: AYBFou3AxLSnEnPDcKq7hJy3knbarBrtXEFSvEd8bPUuL5UVLGOlbSoTzB6cf6pXMOE YeSY77bfr7RokCCgBza+F/czogzNGyhMZyJezhDtQDSlrsSQOl3xoGFi+JJ21Hs4OMof9JVI7LB 4oTh9Q5MlqfcvRnpRGkEKUQDyvWxHv50VSBqRDh9ocToWr1SOimlmq6FAukNLdbbMwY4eu1kI1D zq0D5Wu1okZXBPqtpxDopYH2SG/IS0tTRgMk5vk02GZEBbTwYQUhw23eC5NI/QHAWBeCKU5PKkn 6d37oOjxregjinHwNuau8MmPkrG2v/Btrx1bRdUH7Z3gwK8arWEYbkKGQYY8GfknysXKR7UwaIP +rJL3UdstKCdMT/RwxDEQJmaF3frR9wAauM0yve7myWDH72N67LmGmYTKw4hNcb0yh1sWVIj/8M jCq+zLuZxaPDBmYVi5JZmqrT3FePCjp8sE+HKgmvk3Fqm3VEqU0uLLdPyw/ku5gPDL4hhlrcVtV 6SXca0qqWPcZTxyGCDrTsHT1AsRCkx0NKagDbIDUN4aZWz936I0Ia0zMDsIT6dlaJ2GkOBcgY0w z+eAJdLJ9QgEGJmO6VPJhiXrNw42ki390ykVTR7RxtXslc5kfSslwEAK9WnVeruYaV2VBbFkL23 iorYETaxcYDCv2xsTpo/bWdEnMjTUp4mp9l8= X-Received: by 2002:a05:600c:6298:b0:49e:73e7:888c with SMTP id 5b1f17b1804b1-49fc5687acfmr17707205e9.4.1789716911207; Fri, 18 Sep 2026 00:35:11 -0700 (PDT) From: Manos Pitsidianakis To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Volker=20R=C3=BCmelin?= , Alexander Mikhalitsyn , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , Gerd Hoffmann Subject: [PULL 06/10] hw/audio/virtio-sound: split out virtio_snd_pcm_start_stop() Date: Fri, 18 Sep 2026 10:34:49 +0300 Message-ID: <20260918073502.3265143-7-manos.pitsidianakis@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> References: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::10; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-wm2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1789716953329158500 From: Volker R=C3=BCmelin Split out virtio_snd_pcm_start_stop(). This is a preparation for the next patch so that it doesn't become too big. [AM: there were too many conflicts, I did `git checkout --ours -- <.>` and then reimplemented the patch idea /AM] Signed-off-by: Volker R=C3=BCmelin Signed-off-by: Alexander Mikhalitsyn Reviewed-by: Marc-Andr=C3=A9 Lureau Message-ID: <20260803081159.91981-7-alexander@mihalicyn.com> Signed-off-by: Manos Pitsidianakis --- hw/audio/virtio-snd.c | 58 ++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index f9822fc609..46026b8cff 100644 --- a/hw/audio/virtio-snd.c +++ b/hw/audio/virtio-snd.c @@ -520,7 +520,43 @@ static void virtio_snd_handle_pcm_prepare(VirtIOSound = *s, } =20 /* - * Handles VIRTIO_SND_R_PCM_START. + * Starts/Stops a VirtIOSound card stream. + * Returns the response status code. (VIRTIO_SND_S_*). + * + * @s: VirtIOSound device + * @stream_id: stream id + * @start: whether to start or stop the stream + */ +static uint32_t virtio_snd_pcm_start_stop(VirtIOSound *s, + uint32_t stream_id, + bool start) +{ + VirtIOSoundPCMStream *stream; + + trace_virtio_snd_handle_pcm_start_stop(start ? "VIRTIO_SND_R_PCM_START= " : + "VIRTIO_SND_R_PCM_STOP", + stream_id); + + stream =3D virtio_snd_pcm_get_stream(s, stream_id); + if (!stream) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Invalid stream id: %"PRIu32 "\n", + __func__, stream_id); + return cpu_to_le32(VIRTIO_SND_S_BAD_MSG); + } + + stream->active =3D start; + if (stream->info.direction =3D=3D VIRTIO_SND_D_OUTPUT) { + audio_be_set_active_out(s->audio_be, stream->voice.out, start); + } else { + audio_be_set_active_in(s->audio_be, stream->voice.in, start); + } + + return cpu_to_le32(VIRTIO_SND_S_OK); +} + +/* + * Handles VIRTIO_SND_R_PCM_START and VIRTIO_SND_R_PCM_STOP. * * @s: VirtIOSound device * @cmd: The request command queue element from VirtIOSound cmdq field @@ -530,7 +566,6 @@ static void virtio_snd_handle_pcm_start_stop(VirtIOSoun= d *s, virtio_snd_ctrl_command *cmd, bool start) { - VirtIOSoundPCMStream *stream; virtio_snd_pcm_hdr req; uint32_t stream_id; size_t msg_sz =3D iov_to_buf(cmd->elem->out_sg, @@ -548,24 +583,7 @@ static void virtio_snd_handle_pcm_start_stop(VirtIOSou= nd *s, } =20 stream_id =3D le32_to_cpu(req.stream_id); - cmd->resp.code =3D cpu_to_le32(VIRTIO_SND_S_OK); - trace_virtio_snd_handle_pcm_start_stop(start ? "VIRTIO_SND_R_PCM_START= " : - "VIRTIO_SND_R_PCM_STOP", stream_id); - - stream =3D virtio_snd_pcm_get_stream(s, stream_id); - if (stream) { - stream->active =3D start; - if (stream->info.direction =3D=3D VIRTIO_SND_D_OUTPUT) { - audio_be_set_active_out(s->audio_be, stream->voice.out, start); - } else { - audio_be_set_active_in(s->audio_be, stream->voice.in, start); - } - } else { - error_report("Invalid stream id: %"PRIu32, stream_id); - cmd->resp.code =3D cpu_to_le32(VIRTIO_SND_S_BAD_MSG); - return; - } - stream->active =3D start; + cmd->resp.code =3D virtio_snd_pcm_start_stop(s, stream_id, start); } =20 /* --=20 =CE=B3=CE=B1=E1=BF=96=CE=B1 =CF=80=CF=85=CF=81=CE=AF =CE=BC=CE=B9=CF=87=CE= =B8=CE=AE=CF=84=CF=89 From nobody Sat Sep 26 20:52:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1789716931; cv=none; d=zohomail.com; s=zohoarc; b=XQ9wPtagUTXrMBdKsHEmdg0e3AEWR/+LQXLwEX497d1wuBaaW6w2ZB9SiSjSS8niuE0OAf6FZSJRZSw0FjOV7rwBURKp++u137lmnxEtuvZppoYbJIlFM8oSZup9PqI7WqayO4n+HHfoko2SnMvmNZI4Vy7kf3np84HDNwAzzJ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789716931; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GYlLTu5rquxdE3NcE4fe94KC98Y9bqPnIsrGIJD1aLk=; b=coZCg7/afl6OUqOQM8ce1JQO9Ecso+ZgQK0J8FXD7a/E/1tYfGfSeqdbMjnIeUtpOxJuUXrOGDk2NtqbJhOgAMeu/8XvpP5By+s9UMe7RB1lvlBkdpTExjfftPQyzTOOiu3zy7HsACRKJKE2aI+weQiSI6NyrozPADJxAjHTrHE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17897169312816.35803015614249; Fri, 18 Sep 2026 00:35:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x7T7w-0005fO-Q0; Fri, 18 Sep 2026 03:35:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x7T7t-0005dr-1Q for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:17 -0400 Received: from mail-wm2-x11.google.com ([2a00:1450:4864:31::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x7T7q-0007DZ-9z for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:16 -0400 Received: by mail-wm2-x11.google.com with SMTP id 5b1f17b1804b1-49e71cdb22bso3099955e9.2 for ; Fri, 18 Sep 2026 00:35:13 -0700 (PDT) Received: from localhost.localdomain (athedsl-116222.home.otenet.gr. [85.75.29.157]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fc471b9a2sm23879825e9.0.2026.09.18.00.35.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 00:35:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789716913; x=1790321713; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=GYlLTu5rquxdE3NcE4fe94KC98Y9bqPnIsrGIJD1aLk=; b=Qp3VWTGDLgnugPCOI1JhgAjmDHeEfD/OZ4wVzlSnBXFFHc6wppSgE1touAETlnrz+s BlNLDCwaleEwB/rVbJltlR8mz2ghZuHS2JH+56mF3ok4xUeYzRqqijmyuqBZqhADWFNa c/BgbfeGZfXs8xlotiPJ9xVvW91FNw4M7n715wevzQLHqJzSC5C4NPcXn2UUT925duLh vUkrnfqPGsPQJXArCIUWghlvkNJotZeCDOfBI3Tu66ICU2uTIka0i25ssHZr0IJQPQmD 9pNmkGmK8ZhlhP5QjfVWER71FI7ebeL37ApGy0jWNBSudY5OEUuObJfgxIjDGuPcNnVU 3lWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789716913; x=1790321713; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=GYlLTu5rquxdE3NcE4fe94KC98Y9bqPnIsrGIJD1aLk=; b=zKAlP3Fnm6ilYJ7Pk4qMMjupwXUuPPvHaToOt2hlbt/pyarxSd4DyS1G0Yitiw7K7k gSX1Nl6qqUf6sIWrGLI2n9u99By/4sFJDFbE2zTCf4bk26iKYJtMg/awGzsD1ykjyBsp pwEvnzpwKTJJOj0v8pPwcXaImTHVnWNX6s8sNgQ4Hfke7dzzdvz7F23a8xUgmxi0JYO0 lbu70rkEF1PS2wIcutqR3xxCJWPGJiOzA5kjlb/m43qYf7tw3JhN/861PwDklleBoHL9 ezWrLcAVt8v4LNHaJgBZWUyrFZwsp2EhhMGblz/ql4I/hGNkYBhFR3Nt65Zp7ugHKm1h ANMw== X-Gm-Message-State: AFuF++kf6pplReQWG64d5ROK7pS4j/oedq5WW/cEuDbF4tqnRnSDkxX+ tInUxNgmOr5fJjxKUblq3se5iMKYlNZCS7HAMIl6LvRQaitOeVfkV9NkEepWxpwlN/+CRtQR22v DUxdU3gg= X-Gm-Gg: AYBFou1mtsFQP0MXWZU+2HRPmp+KiQJC7ZD23IIlbLVKU9UniXOdUXyxvnrAK0bEyw7 avFidF07QF0BJ/I6DTaH7U4hizZ/LpXwp6NPrV38RuU9saVd/hmyQUGR/TJJhoCR9Tt6wQJIsS9 9z1Es94YEHtR0Az3/Zc+YnJ3QpWOFhxWvGL+wApMpNBxZ4aQwmuaFdahTqSd7JoUZbkCfGsicgi r3a1UL1hhJ1cFPA/Te1yIjCYp74q9xQkwUWR98vXHT79jqGbW71ig3OD/cvw894Q43Fy6DgSNbD P2YSo4BBuwQXmFM7ybg+906aMDAxpnwqsxMSn9wwotTEmnhU6+nDewqHUJgGhEM25ywkoAlS1gY AP4fO3/+fS2UK9PgA3MOGzhhJKPuvNwfZUPVTZ1cLqI7kxKSHwAUW0UA3Rf+MeH6qD8G+QIWyNO dun2Y0ue8xFjPtcUXaB72CmBjZQYZ0t8duNEAo7g3nisXqhcSg4wRVKrvWbrF3q0aHzbVbG5b7Z nskl4WkAT5YzFog7STKxENMmqm5o7fzkLnCejUHqsDWModwYBGKhgl35ggD6k3C2HETJCPXlPYV rWLetf1+Z3uzTv/SRANOtLvGASbBVKbSMMbrh49rFdtdy9QkI0x0Du1SwDSBrIpHIoW/2uvqBVg xxvsThcUdw5gv/YXfO2f9tJhEgFRvC0/15jWa5AQGcydI X-Received: by 2002:a05:600c:4e50:b0:49d:17d8:abec with SMTP id 5b1f17b1804b1-49fc5728fa5mr18318015e9.21.1789716912633; Fri, 18 Sep 2026 00:35:12 -0700 (PDT) From: Manos Pitsidianakis To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Volker=20R=C3=BCmelin?= , Alexander Mikhalitsyn , Gerd Hoffmann , "Michael S. Tsirkin" Subject: [PULL 07/10] hw/audio/virtio-sound: add stream state variable Date: Fri, 18 Sep 2026 10:34:50 +0300 Message-ID: <20260918073502.3265143-8-manos.pitsidianakis@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> References: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::11; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-wm2-x11.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1789716933588158500 From: Volker R=C3=BCmelin So far, only rudimentary checks have been made to ensure that the guest only performs state transitions described in virtio-v1.2-csd01 5.14.6.6.1 PCM Command Lifecycle. While this is not a Device Requirement, let's add a state variable per audio stream and check all state transitions. Because only permitted state transitions are now possible, only one copy of the audio stream parameters is required and these do not need to be initialised with default values. The state variable will also make it easier to restore the audio stream after migration. [AM: there were too many conflicts, I did `git checkout --ours -- <.>` and then reimplemented the patch idea /AM] Signed-off-by: Volker R=C3=BCmelin Signed-off-by: Alexander Mikhalitsyn Reviewed-by: Manos Pitsidianakis Message-ID: <20260803081159.91981-8-alexander@mihalicyn.com> Signed-off-by: Manos Pitsidianakis --- include/hw/audio/virtio-snd.h | 17 +-- hw/audio/virtio-snd.c | 217 ++++++++++++++++++++-------------- 2 files changed, 126 insertions(+), 108 deletions(-) diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h index 97ffaae18b..85d5d7c861 100644 --- a/include/hw/audio/virtio-snd.h +++ b/include/hw/audio/virtio-snd.h @@ -75,8 +75,6 @@ typedef struct VirtIOSoundPCMStream VirtIOSoundPCMStream; =20 typedef struct virtio_snd_ctrl_command virtio_snd_ctrl_command; =20 -typedef struct VirtIOSoundPCM VirtIOSoundPCM; - typedef struct VirtIOSoundPCMBuffer VirtIOSoundPCMBuffer; =20 /* @@ -121,28 +119,16 @@ struct VirtIOSoundPCMBuffer { uint8_t data[]; }; =20 -struct VirtIOSoundPCM { - /* - * PCM parameters are a separate field instead of a VirtIOSoundPCMStre= am - * field, because the operation of PCM control requests is first - * VIRTIO_SND_R_PCM_SET_PARAMS and then VIRTIO_SND_R_PCM_PREPARE; this - * means that some times we get parameters without having an allocated - * stream yet. - */ - virtio_snd_pcm_set_params *pcm_params; - VirtIOSoundPCMStream **streams; -}; - struct VirtIOSoundPCMStream { virtio_snd_pcm_info info; virtio_snd_pcm_set_params params; + uint32_t state; VirtIOSound *s; audsettings as; union { SWVoiceIn *in; SWVoiceOut *out; } voice; - bool active; uint32_t latency_bytes; QSIMPLEQ_HEAD(, VirtIOSoundPCMBuffer) queue; }; @@ -209,7 +195,6 @@ struct VirtIOSound { =20 VirtQueue *queues[VIRTIO_SND_VQ_MAX]; uint64_t features; - VirtIOSoundPCM pcm; VirtIOSoundPCMStream *streams; AudioBackend *audio_be; VMChangeStateEntry *vmstate; diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index 46026b8cff..1c218569cf 100644 --- a/hw/audio/virtio-snd.c +++ b/hw/audio/virtio-snd.c @@ -30,11 +30,26 @@ #define VIRTIO_SOUND_CHMAP_DEFAULT 0 #define VIRTIO_SOUND_HDA_FN_NID 0 =20 +typedef enum virtio_snd_pcm_state { + VIRTIO_SND_PCM_STATE_UNINIT =3D 0, + VIRTIO_SND_PCM_STATE_PARAMS_SET, + VIRTIO_SND_PCM_STATE_PREPARED, + VIRTIO_SND_PCM_STATE_STARTED, + VIRTIO_SND_PCM_STATE_STOPPED, + VIRTIO_SND_PCM_STATE_RELEASED, +} virtio_snd_pcm_state; + +static inline bool virtio_snd_pcm_state_prepared(virtio_snd_pcm_state s) +{ + return s > VIRTIO_SND_PCM_STATE_PARAMS_SET && + s < VIRTIO_SND_PCM_STATE_RELEASED; +} + static void virtio_snd_pcm_out_cb(void *data, int available); static void virtio_snd_process_cmdq(VirtIOSound *s); static void virtio_snd_pcm_flush(VirtIOSoundPCMStream *stream); +static void virtio_snd_pcm_close(VirtIOSoundPCMStream *stream); static void virtio_snd_pcm_in_cb(void *data, int available); -static void virtio_snd_unrealize(DeviceState *dev); =20 static uint32_t supported_formats =3D BIT(VIRTIO_SND_PCM_FMT_S8) | BIT(VIRTIO_SND_PCM_FMT_U8) @@ -129,7 +144,7 @@ static VirtIOSoundPCMStream *virtio_snd_pcm_get_stream(= VirtIOSound *s, uint32_t stream_id) { return stream_id >=3D s->snd_conf.streams ? NULL : - s->pcm.streams[stream_id]; + &s->streams[stream_id]; } =20 /* @@ -141,8 +156,8 @@ static VirtIOSoundPCMStream *virtio_snd_pcm_get_stream(= VirtIOSound *s, static virtio_snd_pcm_set_params *virtio_snd_pcm_get_params(VirtIOSound *s, uint32_t strea= m_id) { - return stream_id >=3D s->snd_conf.streams ? NULL - : &s->pcm.pcm_params[stream_id]; + return stream_id >=3D s->snd_conf.streams ? NULL : + &s->streams[stream_id].params; } =20 /* @@ -245,11 +260,10 @@ static void virtio_snd_handle_pcm_info(VirtIOSound *s, =20 /* * Set the given stream params. - * Called by both virtio_snd_handle_pcm_set_params and during device - * initialization. * Returns the response status code. (VIRTIO_SND_S_*). * * @s: VirtIOSound device + * @stream_id: stream id * @params: The PCM params as defined in the virtio specification */ static @@ -257,14 +271,27 @@ uint32_t virtio_snd_set_pcm_params(VirtIOSound *s, uint32_t stream_id, virtio_snd_pcm_set_params *params) { + VirtIOSoundPCMStream *stream; virtio_snd_pcm_set_params *st_params; =20 - if (stream_id >=3D s->snd_conf.streams || s->pcm.pcm_params =3D=3D NUL= L) { - virtio_error(VIRTIO_DEVICE(s), "Streams have not been initialized.= \n"); + stream =3D virtio_snd_pcm_get_stream(s, stream_id); + if (!stream) { + virtio_error(VIRTIO_DEVICE(s), "invalid stream id: %"PRIu32, + stream_id); return cpu_to_le32(VIRTIO_SND_S_BAD_MSG); } =20 - st_params =3D virtio_snd_pcm_get_params(s, stream_id); + switch (stream->state) { + case VIRTIO_SND_PCM_STATE_UNINIT: + case VIRTIO_SND_PCM_STATE_PARAMS_SET: + case VIRTIO_SND_PCM_STATE_PREPARED: + case VIRTIO_SND_PCM_STATE_RELEASED: + break; + default: + virtio_error(VIRTIO_DEVICE(s), "unexpected stream state: %"PRIu32, + stream->state); + return cpu_to_le32(VIRTIO_SND_S_BAD_MSG); + } =20 if (params->channels < 1 || params->channels > AUDIO_MAX_CHANNELS) { error_report("Number of channels is not supported."); @@ -281,6 +308,8 @@ uint32_t virtio_snd_set_pcm_params(VirtIOSound *s, return cpu_to_le32(VIRTIO_SND_S_NOT_SUPP); } =20 + st_params =3D virtio_snd_pcm_get_params(s, stream_id); + st_params->buffer_bytes =3D le32_to_cpu(params->buffer_bytes); st_params->period_bytes =3D le32_to_cpu(params->period_bytes); st_params->features =3D le32_to_cpu(params->features); @@ -289,6 +318,15 @@ uint32_t virtio_snd_set_pcm_params(VirtIOSound *s, st_params->format =3D params->format; st_params->rate =3D params->rate; =20 + if (virtio_snd_pcm_state_prepared(stream->state)) { + /* implicit VIRTIO_SND_R_PCM_RELEASE */ + virtio_snd_pcm_flush(stream); + } + + virtio_snd_pcm_close(stream); + + stream->state =3D VIRTIO_SND_PCM_STATE_PARAMS_SET; + return cpu_to_le32(VIRTIO_SND_S_OK); } =20 @@ -398,15 +436,12 @@ static void virtio_snd_get_qemu_audsettings(audsettin= gs *as, */ static void virtio_snd_pcm_close(VirtIOSoundPCMStream *stream) { - if (stream) { - virtio_snd_pcm_flush(stream); - if (stream->info.direction =3D=3D VIRTIO_SND_D_OUTPUT) { - audio_be_close_out(stream->s->audio_be, stream->voice.out); - stream->voice.out =3D NULL; - } else if (stream->info.direction =3D=3D VIRTIO_SND_D_INPUT) { - audio_be_close_in(stream->s->audio_be, stream->voice.in); - stream->voice.in =3D NULL; - } + if (stream->info.direction =3D=3D VIRTIO_SND_D_OUTPUT) { + audio_be_close_out(stream->s->audio_be, stream->voice.out); + stream->voice.out =3D NULL; + } else if (stream->info.direction =3D=3D VIRTIO_SND_D_INPUT) { + audio_be_close_in(stream->s->audio_be, stream->voice.in); + stream->voice.in =3D NULL; } } =20 @@ -423,33 +458,26 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s= , uint32_t stream_id) virtio_snd_pcm_set_params *params; VirtIOSoundPCMStream *stream; =20 - if (s->pcm.streams =3D=3D NULL || - s->pcm.pcm_params =3D=3D NULL || - stream_id >=3D s->snd_conf.streams) { + stream =3D virtio_snd_pcm_get_stream(s, stream_id); + if (!stream) { + return cpu_to_le32(VIRTIO_SND_S_BAD_MSG); + } + + switch (stream->state) { + case VIRTIO_SND_PCM_STATE_PARAMS_SET: + case VIRTIO_SND_PCM_STATE_PREPARED: + case VIRTIO_SND_PCM_STATE_RELEASED: + break; + default: + virtio_error(VIRTIO_DEVICE(s), "unexpected stream state: %"PRIu32, + stream->state); return cpu_to_le32(VIRTIO_SND_S_BAD_MSG); } =20 params =3D virtio_snd_pcm_get_params(s, stream_id); - if (params =3D=3D NULL) { - return cpu_to_le32(VIRTIO_SND_S_BAD_MSG); - } - - stream =3D virtio_snd_pcm_get_stream(s, stream_id); - if (stream =3D=3D NULL) { - stream =3D &s->streams[stream_id]; - stream->active =3D false; - stream->latency_bytes =3D 0; - - /* - * stream_id >=3D s->snd_conf.streams was checked before so this is - * in-bounds - */ - s->pcm.streams[stream_id] =3D stream; - } =20 virtio_snd_get_qemu_audsettings(&as, params); stream->info.channels_max =3D as.nchannels; - stream->params =3D *params; =20 stream->as =3D as; =20 @@ -471,6 +499,8 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s, = uint32_t stream_id) audio_be_set_volume_in_lr(s->audio_be, stream->voice.in, 0, 255, 2= 55); } =20 + stream->state =3D VIRTIO_SND_PCM_STATE_PREPARED; + return cpu_to_le32(VIRTIO_SND_S_OK); } =20 @@ -545,7 +575,31 @@ static uint32_t virtio_snd_pcm_start_stop(VirtIOSound = *s, return cpu_to_le32(VIRTIO_SND_S_BAD_MSG); } =20 - stream->active =3D start; + if (start) { + switch (stream->state) { + case VIRTIO_SND_PCM_STATE_PREPARED: + case VIRTIO_SND_PCM_STATE_STOPPED: + break; + default: + virtio_error(VIRTIO_DEVICE(s), "unexpected stream state: %"PRI= u32, + stream->state); + return cpu_to_le32(VIRTIO_SND_S_BAD_MSG); + } + + stream->state =3D VIRTIO_SND_PCM_STATE_STARTED; + } else { + switch (stream->state) { + case VIRTIO_SND_PCM_STATE_STARTED: + break; + default: + virtio_error(VIRTIO_DEVICE(s), "unexpected stream state: %"PRI= u32, + stream->state); + return cpu_to_le32(VIRTIO_SND_S_BAD_MSG); + } + + stream->state =3D VIRTIO_SND_PCM_STATE_STOPPED; + } + if (stream->info.direction =3D=3D VIRTIO_SND_D_OUTPUT) { audio_be_set_active_out(s->audio_be, stream->voice.out, start); } else { @@ -639,6 +693,17 @@ static void virtio_snd_handle_pcm_release(VirtIOSound = *s, return; } =20 + switch (stream->state) { + case VIRTIO_SND_PCM_STATE_PREPARED: + case VIRTIO_SND_PCM_STATE_STOPPED: + break; + default: + virtio_error(VIRTIO_DEVICE(s), "unexpected stream state: %"PRIu32, + stream->state); + cmd->resp.code =3D cpu_to_le32(VIRTIO_SND_S_BAD_MSG); + return; + } + if (virtio_snd_pcm_get_io_msgs_count(stream)) { /* * virtio-v1.2-csd01, 5.14.6.6.5.1, @@ -653,6 +718,10 @@ static void virtio_snd_handle_pcm_release(VirtIOSound = *s, virtio_snd_pcm_flush(stream); } =20 + virtio_snd_pcm_close(stream); + + stream->state =3D VIRTIO_SND_PCM_STATE_RELEASED; + cmd->resp.code =3D cpu_to_le32(VIRTIO_SND_S_OK); } =20 @@ -876,12 +945,11 @@ static void virtio_snd_handle_tx_xfer(VirtIODevice *v= dev, VirtQueue *vq) size =3D iov_size(elem->out_sg, elem->out_num) - msg_sz; stream_id =3D le32_to_cpu(hdr.stream_id); =20 - if (stream_id >=3D vsnd->snd_conf.streams - || vsnd->pcm.streams[stream_id] =3D=3D NULL) { + if (stream_id >=3D vsnd->snd_conf.streams) { goto tx_err; } =20 - stream =3D vsnd->pcm.streams[stream_id]; + stream =3D &vsnd->streams[stream_id]; if (stream->info.direction !=3D VIRTIO_SND_D_OUTPUT) { goto tx_err; } @@ -959,15 +1027,13 @@ static void virtio_snd_handle_rx_xfer(VirtIODevice *= vdev, VirtQueue *vq) } stream_id =3D le32_to_cpu(hdr.stream_id); =20 - if (stream_id >=3D vsnd->snd_conf.streams - || !vsnd->pcm.streams[stream_id]) { + if (stream_id >=3D vsnd->snd_conf.streams) { goto rx_err; } =20 - stream =3D vsnd->pcm.streams[stream_id]; + stream =3D &vsnd->streams[stream_id]; size =3D iov_size(elem->in_sg, elem->in_num); - if (stream =3D=3D NULL - || stream->info.direction !=3D VIRTIO_SND_D_INPUT + if (stream->info.direction !=3D VIRTIO_SND_D_INPUT || size < sizeof(virtio_snd_pcm_status)) { goto rx_err; } @@ -1031,8 +1097,6 @@ static void virtio_snd_realize(DeviceState *dev, Erro= r **errp) ERRP_GUARD(); VirtIOSound *vsnd =3D VIRTIO_SND(dev); VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); - virtio_snd_pcm_set_params default_params =3D { 0 }; - uint32_t status; =20 trace_virtio_snd_realize(vsnd); =20 @@ -1069,6 +1133,7 @@ static void virtio_snd_realize(DeviceState *dev, Erro= r **errp) for (uint32_t i =3D 0; i < vsnd->snd_conf.streams; i++) { VirtIOSoundPCMStream *stream =3D &vsnd->streams[i]; =20 + stream->state =3D VIRTIO_SND_PCM_STATE_UNINIT; stream->s =3D vsnd; QSIMPLEQ_INIT(&stream->queue); stream->info.hdr.hda_fn_nid =3D VIRTIO_SOUND_HDA_FN_NID; @@ -1082,21 +1147,9 @@ static void virtio_snd_realize(DeviceState *dev, Err= or **errp) stream->info.channels_max =3D 2; } =20 - vsnd->pcm.streams =3D - g_new0(VirtIOSoundPCMStream *, vsnd->snd_conf.streams); - vsnd->pcm.pcm_params =3D - g_new0(virtio_snd_pcm_set_params, vsnd->snd_conf.streams); - virtio_init(vdev, VIRTIO_ID_SOUND, sizeof(virtio_snd_config)); virtio_add_feature(&vsnd->features, VIRTIO_F_VERSION_1); =20 - /* set default params for all streams */ - default_params.features =3D 0; - default_params.buffer_bytes =3D cpu_to_le32(8192); - default_params.period_bytes =3D cpu_to_le32(2048); - default_params.channels =3D 2; - default_params.format =3D VIRTIO_SND_PCM_FMT_S16; - default_params.rate =3D VIRTIO_SND_PCM_RATE_48000; vsnd->queues[VIRTIO_SND_VQ_CONTROL] =3D virtio_add_queue(vdev, 64, virtio_snd_handle_ctrl); vsnd->queues[VIRTIO_SND_VQ_EVENT] =3D @@ -1107,28 +1160,6 @@ static void virtio_snd_realize(DeviceState *dev, Err= or **errp) virtio_add_queue(vdev, 64, virtio_snd_handle_rx_xfer); QTAILQ_INIT(&vsnd->cmdq); QSIMPLEQ_INIT(&vsnd->invalid); - - for (uint32_t i =3D 0; i < vsnd->snd_conf.streams; i++) { - status =3D virtio_snd_set_pcm_params(vsnd, i, &default_params); - if (status !=3D cpu_to_le32(VIRTIO_SND_S_OK)) { - error_setg(errp, - "Can't initialize stream params, device responded w= ith %s.", - print_code(status)); - goto error_cleanup; - } - status =3D virtio_snd_pcm_prepare(vsnd, i); - if (status !=3D cpu_to_le32(VIRTIO_SND_S_OK)) { - error_setg(errp, - "Can't prepare streams, device responded with %s.", - print_code(status)); - goto error_cleanup; - } - } - - return; - -error_cleanup: - virtio_snd_unrealize(dev); } =20 static inline void update_latency(VirtIOSoundPCMStream *s, size_t used) @@ -1177,7 +1208,7 @@ static void virtio_snd_pcm_out_cb(void *data, int ava= ilable) if (!virtio_queue_ready(buffer->vq)) { return; } - if (!stream->active) { + if (stream->state !=3D VIRTIO_SND_PCM_STATE_STARTED) { /* Stream has stopped, so do not perform audio_be_write. */ return_tx_buffer(stream, buffer); continue; @@ -1271,7 +1302,7 @@ static void virtio_snd_pcm_in_cb(void *data, int avai= lable) if (!virtio_queue_ready(buffer->vq)) { return; } - if (!stream->active) { + if (stream->state !=3D VIRTIO_SND_PCM_STATE_STARTED) { /* Stream has stopped, so do not perform audio_be_read. */ return_rx_buffer(stream, buffer); continue; @@ -1344,17 +1375,16 @@ static void virtio_snd_unrealize(DeviceState *dev) qemu_del_vm_change_state_handler(vsnd->vmstate); trace_virtio_snd_unrealize(vsnd); =20 - if (vsnd->pcm.streams) { + if (vsnd->streams) { + virtio_snd_process_cmdq(vsnd); for (uint32_t i =3D 0; i < vsnd->snd_conf.streams; i++) { - stream =3D vsnd->pcm.streams[i]; - if (stream) { - virtio_snd_process_cmdq(stream->s); - virtio_snd_pcm_close(stream); + stream =3D &vsnd->streams[i]; + if (virtio_snd_pcm_state_prepared(stream->state)) { + virtio_snd_pcm_flush(stream); } + virtio_snd_pcm_close(stream); } - g_free(vsnd->pcm.streams); } - g_free(vsnd->pcm.pcm_params); g_free(vsnd->streams); vsnd->streams =3D NULL; virtio_delete_queue(vsnd->queues[VIRTIO_SND_VQ_CONTROL]); @@ -1387,6 +1417,9 @@ static void virtio_snd_reset(VirtIODevice *vdev) VirtIOSoundPCMStream *stream =3D &vsnd->streams[i]; VirtIOSoundPCMBuffer *buffer; =20 + virtio_snd_pcm_close(stream); + stream->state =3D VIRTIO_SND_PCM_STATE_UNINIT; + while ((buffer =3D QSIMPLEQ_FIRST(&stream->queue))) { QSIMPLEQ_REMOVE_HEAD(&stream->queue, entry); virtio_snd_pcm_buffer_free(buffer); --=20 =CE=B3=CE=B1=E1=BF=96=CE=B1 =CF=80=CF=85=CF=81=CE=AF =CE=BC=CE=B9=CF=87=CE= =B8=CE=AE=CF=84=CF=89 From nobody Sat Sep 26 20:52:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1789717006; cv=none; d=zohomail.com; s=zohoarc; b=g7XcrBU4JKk+2dhltE3sZu/1We9JUmgqKg14tyXjv5RGL8sFkY7rMQfkixQ5xC4Wbb9U9Auj88kOOEhB013rqTKYlVkDT0glTNiq58Wuh3Up4kvs1WB8CIg626oQjNFBFPQlZjwZaVeHqSJsYkoecOpJ/mTnjlpJ2ZpocXKH9xs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789717006; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=jC5ApYaM6D7JDXls9hD8kZ6TLH9GMRvv40+wb09BZ3s=; b=Lzd3seawFSEMjpHTwSPoAj3LhD7aJamp9h04xlb8Js/D5HKmsXxzg0NmDYf4AzJ/AQBQBC0qYyE1cYOQRinfejQ9EUXiY0W8gWOvmN1XHdWAIYmFTrzSjigU/kUqrpsbZwynJigOInAJGbRf1EAWdDO1RObI21y67D64kWSToDs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178971700665674.55339017979918; Fri, 18 Sep 2026 00:36:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x7T7x-0005fy-UA; Fri, 18 Sep 2026 03:35:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x7T7u-0005ev-K5 for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:19 -0400 Received: from mail-wm2-x11.google.com ([2a00:1450:4864:31::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x7T7s-0007Dl-SP for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:18 -0400 Received: by mail-wm2-x11.google.com with SMTP id 5b1f17b1804b1-49cd38e0f79so2415085e9.3 for ; Fri, 18 Sep 2026 00:35:15 -0700 (PDT) Received: from localhost.localdomain (athedsl-116222.home.otenet.gr. [85.75.29.157]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fc471b9a2sm23879825e9.0.2026.09.18.00.35.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 00:35:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789716915; x=1790321715; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=jC5ApYaM6D7JDXls9hD8kZ6TLH9GMRvv40+wb09BZ3s=; b=QREXjFTNam/QiYlHyodDTfsg7OOvb0dPsdzLjmTWKRn/Pf46YRi2fA847IhNsZqVoJ Rw7x+BHdh5GOC1DN8XiD2hLQQK7HrrNpL1WYNCyohIgDm9H7CXHZP6toMHKxpCGYNtjC x+od0HelAiXtk9d4szR1E+ZM1VJHUG7PBh9mgR9KM+SJlZhE+gJ+MJpBVt7w+ZuK+zOx W40KVZMr1+pRrX4ujstSeoWGZu7b2C3st/K9HQ9sJjz59FImyAcdwmnwdNmbVU/GmWKi hWVwifs2FtRWLMFMfcdloBQd0JZmx/Hx6keEeVGGo/uy3Z3HIYUI2Bqi82ZUs26QB19S huCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789716915; x=1790321715; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=jC5ApYaM6D7JDXls9hD8kZ6TLH9GMRvv40+wb09BZ3s=; b=0tF8CkmVyFyVlDNGi2bA5HZ1MK8zJUQNtzmHXrmkRYlqbwQ1cy9aYSDSLGrQ18asYl sAgnPkSoQqzxji+XhEBmTEzAjubg7oH9jTNUIK/+Bw/0U4G3ixabQK55hOgdVbiG6tx0 +KrOEnx5O/l+62fP0rCqwuol3EOm7BP9gEnVYKoJzKzr+bRcTo+U2x6DFoATzVxo/8/+ z+pQLlEsvwbhTe3F44Ng1L9oLlqxla3x+B6gIjtBFx5YOUQvOekwztEKqHEe4CFId2JM /GOMRB827ziSV6V9WHdww74Sc7V4g7XAl6A+dHQNych0E9IHVWUNMYtg1dCa6cCOfJjx 8yug== X-Gm-Message-State: AFuF++lzJNC/rS6yU6aLmtFEAZdxcehjzf/vIlCqBfmaTCKptQKPqoWT tAK1osbbX1XPxMABiuA6Wnn6rlAxGlXECNzDm/aOj2NVQ5EDmGvyLPrFRxOYIpC8O/wbjGmmH9p YiRJaFlg= X-Gm-Gg: AYBFou3ipYmI0bmXUXZdvjJTI6zRh+icFBwAEDo4t9LQvwWZe+XiknfPlvaO/BEkkRo xhwOMvPIkHmpW/VqnBISjtDVPfKmDlSxWWCjdj8SodU/NnmCyPxOC9lSNjvLFrI/cRVIghRfrte H0CD/4ZUNzYiFmzHL9tzQTB/qc6w9R5VftxJOOk3Jd2FC2cksIcvldO8vcBNhfeV/CZHP30WqFN kOqb9X6l/tt1EPsbr/u6XxnohsdO300/p7+6X3EBRRL5dj/p9pmWPDVLBCqGBb+i63Pdd5eOVrB UPPOL1an7KdJZ+OwEL6kvC6eQs9euoHd5uHXe9lsd6DbLRGy7qd8UGGegUtOxMdGSC7S/dgt020 Zjq3on5jSyIRvhm9vdV8IQWxWiEzQWv+cmaOqe5dQOVe7QK0iY8W+DluukCq624SyJBz4dQoQbc jUBIm58K5+LWPNzW6j3Hk9H1yyERxkizFASSO6r9bO7pv7/jjN4ekd9m1E6bVDgEhf6AZANnk7G b8Y9blF5h8b9vuD+KGhqOyYjSWkvJ/07LCX+9sQUylOgFN7QgceTZXEcNyoqg7EhA7OrAPrjEQb AGYjd4++8/zLT4hnZhLYvknN5LCsIWrIAM5qF/X9r3uxa9DTkNpyg4Ze95DDxssjUcfekF7wWcP Itx1trSRatdRSUuFsrgCc1Uxs0IzNqHnRDQ== X-Received: by 2002:a05:600c:34c7:b0:49c:ff8d:b548 with SMTP id 5b1f17b1804b1-49fc5726cfcmr40504025e9.11.1789716914879; Fri, 18 Sep 2026 00:35:14 -0700 (PDT) From: Manos Pitsidianakis To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Volker=20R=C3=BCmelin?= , Alexander Mikhalitsyn , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , "Michael S. Tsirkin" Subject: [PULL 08/10] hw/audio/virtio-sound: introduce virtio_snd_pcm_open() Date: Fri, 18 Sep 2026 10:34:51 +0300 Message-ID: <20260918073502.3265143-9-manos.pitsidianakis@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> References: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::11; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-wm2-x11.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1789717007442158500 From: Volker R=C3=BCmelin Split out the function virtio_snd_pcm_open() from virtio_snd_pcm_prepare(). A later patch also needs the new function. There is no functional change. Signed-off-by: Volker R=C3=BCmelin [AM: trivial rebase changes] Signed-off-by: Alexander Mikhalitsyn Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Manos Pitsidianakis Message-ID: <20260803081159.91981-9-alexander@mihalicyn.com> Signed-off-by: Manos Pitsidianakis --- hw/audio/virtio-snd.c | 58 ++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index 1c218569cf..7944d2b3b9 100644 --- a/hw/audio/virtio-snd.c +++ b/hw/audio/virtio-snd.c @@ -430,6 +430,37 @@ static void virtio_snd_get_qemu_audsettings(audsetting= s *as, } =20 /* + * Open a stream. + * + * @stream: VirtIOSoundPCMStream *stream + */ +static void virtio_snd_pcm_open(VirtIOSoundPCMStream *stream) +{ + virtio_snd_get_qemu_audsettings(&stream->as, &stream->params); + stream->info.channels_max =3D stream->as.nchannels; + + if (stream->info.direction =3D=3D VIRTIO_SND_D_OUTPUT) { + stream->voice.out =3D audio_be_open_out(stream->s->audio_be, + stream->voice.out, + "virtio-sound.out", + stream, + virtio_snd_pcm_out_cb, + &stream->as); + audio_be_set_volume_out_lr(stream->s->audio_be, + stream->voice.out, 0, 255, 255); + } else { + stream->voice.in =3D audio_be_open_in(stream->s->audio_be, + stream->voice.in, + "virtio-sound.in", + stream, + virtio_snd_pcm_in_cb, + &stream->as); + audio_be_set_volume_in_lr(stream->s->audio_be, + stream->voice.in, 0, 255, 255); + } +} + +/* * Close a stream and free all its resources. * * @stream: VirtIOSoundPCMStream *stream @@ -454,8 +485,6 @@ 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; VirtIOSoundPCMStream *stream; =20 stream =3D virtio_snd_pcm_get_stream(s, stream_id); @@ -474,30 +503,7 @@ static uint32_t virtio_snd_pcm_prepare(VirtIOSound *s,= uint32_t stream_id) return cpu_to_le32(VIRTIO_SND_S_BAD_MSG); } =20 - params =3D virtio_snd_pcm_get_params(s, stream_id); - - virtio_snd_get_qemu_audsettings(&as, params); - stream->info.channels_max =3D as.nchannels; - - stream->as =3D as; - - if (stream->info.direction =3D=3D VIRTIO_SND_D_OUTPUT) { - stream->voice.out =3D audio_be_open_out(s->audio_be, - stream->voice.out, - "virtio-sound.out", - stream, - virtio_snd_pcm_out_cb, - &as); - audio_be_set_volume_out_lr(s->audio_be, stream->voice.out, 0, 255,= 255); - } else { - stream->voice.in =3D audio_be_open_in(s->audio_be, - stream->voice.in, - "virtio-sound.in", - stream, - virtio_snd_pcm_in_cb, - &as); - audio_be_set_volume_in_lr(s->audio_be, stream->voice.in, 0, 255, 2= 55); - } + virtio_snd_pcm_open(stream); =20 stream->state =3D VIRTIO_SND_PCM_STATE_PREPARED; =20 --=20 =CE=B3=CE=B1=E1=BF=96=CE=B1 =CF=80=CF=85=CF=81=CE=AF =CE=BC=CE=B9=CF=87=CE= =B8=CE=AE=CF=84=CF=89 From nobody Sat Sep 26 20:52:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1789716997; cv=none; d=zohomail.com; s=zohoarc; b=WqftXjwkfb0VC3AzrjNirv4LhUfFLDDlcjD4ZOCCOOeRx1ioo/24WUtVSCvyUL3t3PouzZOLUJKcDBHqXdDDO3Y7gnGFWUCh2AS/oqxtFqxf3oERGJn201ZRkQUpX6AOdz/VYkFiUzcHzQH9A4yQKOYSKbOlve4x2TWrmInNW+4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789716997; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=AcYTJx9E4CYdyyMY0Az5kiAEmPZKXqi/EESegL6wNG0=; b=IZnVSp2bPIwgXY8nCkSOsHMregrbONpYIJj9Fpc/3PTG6cI/vci3D6FWa+OZx2jjYGxtPw0tXVigoJWtwerX85vLxjXDSQuBdpY7NtshOEwCmvATSDUCMLSfaATjF3Pnn8lJ8x0u8JlNO4Bcip96V2ymr/WE+Lehus+80pWBKZM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1789716997615742.1189763266095; Fri, 18 Sep 2026 00:36:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x7T80-0005gm-MG; Fri, 18 Sep 2026 03:35:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x7T7v-0005ew-9O for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:19 -0400 Received: from mail-wm2-x10.google.com ([2a00:1450:4864:31::10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x7T7t-0007Ds-MC for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:18 -0400 Received: by mail-wm2-x10.google.com with SMTP id 5b1f17b1804b1-49cd38e0f79so2415325e9.3 for ; Fri, 18 Sep 2026 00:35:17 -0700 (PDT) Received: from localhost.localdomain (athedsl-116222.home.otenet.gr. [85.75.29.157]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fc471b9a2sm23879825e9.0.2026.09.18.00.35.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 00:35:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789716916; x=1790321716; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=AcYTJx9E4CYdyyMY0Az5kiAEmPZKXqi/EESegL6wNG0=; b=ylezZytIC5Iru0Cp7OFSThT7nRUYsjBMZ7PnwjLGap3Eyp7HVB6yx3lFMVP7jc8AHR 18XOT82pz8XSiYYzABcnaMEfKibDB5kMNCBHFSg2p2BZiw3+QagJ8Fi00yZkHQqmsB+E xT8Rhr73O8uU10gC2/UQ+y4o9aruOzY3fE/CRSTqqd2JIEKF2cPVhMd3k4HrxpKUt2UF XxhHufOLMP1w5pc7gg/nmGgPfqWbvjQ/WNcG1nAbsve0OqqLuE+1gaNx0CoWICDkBNNy PZInrckdFYvXLyh+jQh0JQEU8Qm1OIfyWEFx90sEXU9EsEAKh+qbEnMV/5H7j8oH/D81 Fsig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789716916; x=1790321716; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=AcYTJx9E4CYdyyMY0Az5kiAEmPZKXqi/EESegL6wNG0=; b=NMsh+lKhg70kVqQo9J22p9nqleOtIRFD3jD8LEHZbpQu96ubL5bFGJltXc+ZzStTiC D97eP9Yo8kzERRtKT342/JXX0CeXjdrIQUZrha67VNyywgNeBAjxB0JpLsY7vVpqo37T 3hHO7XnXmPC9MbGw4ZLOcNT8IBaPbWEhnIz22hOvY0ZSN/hyNvzr+WnasfTLWwU/fbJ7 94Z4jldpmzsZWpq3W3F99EGwwMe34l0PZeFgmUcmPRQW06BUnqE5ZUjUJQ8Jet/GpKK6 vEmFA7cYYsMYx5eFpzQtOn/jpiCLwjYkl/bzvOQxqjUXO4M88wolECIlS193PjXviLSS mbSQ== X-Gm-Message-State: AFuF++n5mZm1NWFjLtE7QozbCcGZ2A4FDM3xd4zfWqLvJLLmkW6iR66l FHB9XKiqcXgFplh3SoIlqIjUJfh7d8f3yShjLH6gnGKLgzyuaC9qEde+ClpVhya2GHsAoHQqL7o MnNk99mc= X-Gm-Gg: AYBFou0m16ulHwMVfpMJfR6Dz+DclElkBmj7vGKE/T4c+fngC8CyuyWOqGfAa6qBMki FWkuScsDyKrty76pDEjNouR07Hr+zqM9Zy5nLfwvi1vwWj0ETVtf4FX1yBrpl0PHfFiGRdJ1Zmc xmnV0/UxVgzXu95m0zMSC7bsfSTChtE9Tm6gTFTUaOyPMkK3DfwPs4V33Zzbl4iltRUL35e1yE+ LZ4QEbhsC63wxE0R+FTbdAw3MDi12IYKsN9l9qFWkHULLd9VBrvgmQlNm6EmDB0zTiS8seE0O17 yghbge15AvNAkey2J1L1lMP4u6XXo4DWP9286HeHhOi3mnsy1boqDO8wTMSilIRYmuMoPzwWOaP MBKL6BfyJdwyhGdQk15eZ7id6qlq7UsZzYb+PG621TplaR+igQ65AVfQP7pX2KQKT8OfGV4ahtQ 65hL41Wnaj9r+x343FZ1IuIjRv5VPXEkw3WPw6TQndfmPLE4vhdbTHomTVU7pWJh5fAZp2DiRUq xVJybO6s7dN/JwzgQU7+XD7VGHjY6uJSYKaEqJ0sPCEINp5ZE8MD60mi3bqDFYxPXVednjoZK0k ROsEm0hdnIzm6+qGJ4pt0V8Zz3jmR5wHcYjNd8J/seF5yPM6s2JqE+i1iUEyKyylI2LC1f59FqL Qr8lN7+kAA6esli9jXI8Q370GuWOsRnFmbvbIXAw8ISP7 X-Received: by 2002:a05:600c:8709:b0:49d:870:7a69 with SMTP id 5b1f17b1804b1-49fc573514bmr35198795e9.12.1789716916239; Fri, 18 Sep 2026 00:35:16 -0700 (PDT) From: Manos Pitsidianakis To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Volker=20R=C3=BCmelin?= , Alexander Mikhalitsyn , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , Gerd Hoffmann Subject: [PULL 09/10] hw/audio/virtio-sound: introduce virtio_snd_set_active() Date: Fri, 18 Sep 2026 10:34:52 +0300 Message-ID: <20260918073502.3265143-10-manos.pitsidianakis@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> References: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::10; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-wm2-x10.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1789716999425158500 From: Volker R=C3=BCmelin Split out the function virtio_snd_pcm_set_active() from virtio_snd_pcm_start_stop(). A later patch also needs this new funcion. There is no functional change. Signed-off-by: Volker R=C3=BCmelin [AM: trivial rebase changes] Signed-off-by: Alexander Mikhalitsyn Reviewed-by: Marc-Andr=C3=A9 Lureau Message-ID: <20260803081159.91981-10-alexander@mihalicyn.com> Signed-off-by: Manos Pitsidianakis --- hw/audio/virtio-snd.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index 7944d2b3b9..12473862d2 100644 --- a/hw/audio/virtio-snd.c +++ b/hw/audio/virtio-snd.c @@ -461,6 +461,21 @@ static void virtio_snd_pcm_open(VirtIOSoundPCMStream *= stream) } =20 /* + * Activate/deactivate a stream. + * + * @stream: VirtIOSoundPCMStream *stream + * @active: whether to activate or deactivate the stream + */ +static void virtio_snd_pcm_set_active(VirtIOSoundPCMStream *stream, bool a= ctive) +{ + if (stream->info.direction =3D=3D VIRTIO_SND_D_OUTPUT) { + audio_be_set_active_out(stream->s->audio_be, stream->voice.out, ac= tive); + } else { + audio_be_set_active_in(stream->s->audio_be, stream->voice.in, acti= ve); + } +} + +/* * Close a stream and free all its resources. * * @stream: VirtIOSoundPCMStream *stream @@ -606,11 +621,7 @@ static uint32_t virtio_snd_pcm_start_stop(VirtIOSound = *s, stream->state =3D VIRTIO_SND_PCM_STATE_STOPPED; } =20 - if (stream->info.direction =3D=3D VIRTIO_SND_D_OUTPUT) { - audio_be_set_active_out(s->audio_be, stream->voice.out, start); - } else { - audio_be_set_active_in(s->audio_be, stream->voice.in, start); - } + virtio_snd_pcm_set_active(stream, start); =20 return cpu_to_le32(VIRTIO_SND_S_OK); } --=20 =CE=B3=CE=B1=E1=BF=96=CE=B1 =CF=80=CF=85=CF=81=CE=AF =CE=BC=CE=B9=CF=87=CE= =B8=CE=AE=CF=84=CF=89 From nobody Sat Sep 26 20:52:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1789716986; cv=none; d=zohomail.com; s=zohoarc; b=MBFWUTDsmRV5U9sdeX0iW7o0e/Z2naAvI9mJUaz46ry5R/Hpr2jvrGiAxmfA3KMRwjI/DDMHSo02njfZJbBJdf/LBf/4Ua/5C57n/3/TH3ZLz0fmCN1BoNqWkN9//cXRaHHpvwJCBwDuYtN90sNfby/bWu0dawOwlWUCCotNMoM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789716986; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ev1EtVgOCLRng9RIv1gIUfgjXM5TZkVOcIQwbt1kHH4=; b=Tqw9HENRSpd/eQ6MAyR/C+YP1ByKLymQMp6Pi5xPU89rkMYaW6E3ABctkf4pfp4wWcvBeL6ZLoRBsSSssAYqj84a2HzzOFMBQ1FwbvAtxSqv38AvmcrK3zUXCZ/tphGBkreiYJdOD1kcx3C38lMLQaJPXvLxYlHBzbV68M2S8jo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178971698672333.86274796653743; Fri, 18 Sep 2026 00:36:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x7T80-0005gl-CM; Fri, 18 Sep 2026 03:35:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x7T7x-0005g0-Uu for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:21 -0400 Received: from mail-wm2-x11.google.com ([2a00:1450:4864:31::11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1x7T7v-0007E1-R9 for qemu-devel@nongnu.org; Fri, 18 Sep 2026 03:35:21 -0400 Received: by mail-wm2-x11.google.com with SMTP id 5b1f17b1804b1-49e69b9e16aso4584605e9.1 for ; Fri, 18 Sep 2026 00:35:18 -0700 (PDT) Received: from localhost.localdomain (athedsl-116222.home.otenet.gr. [85.75.29.157]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49fc471b9a2sm23879825e9.0.2026.09.18.00.35.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2026 00:35:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1789716918; x=1790321718; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=ev1EtVgOCLRng9RIv1gIUfgjXM5TZkVOcIQwbt1kHH4=; b=oeNizE7nJ9ZYa/M1IQmyuVmuSJ91yt/F0QeoKWA0m3lYOgD3qv5UJKqCleR9VnILrk TuBAk8CcNVsrgVWU59iDleuMKGRg4uFsLfvv/LCo7Q/8UGYHDagiXux68qd5C6q5i9SR sjknGPxiYxaFv/igWg3c3xnEDpPqHr7lS+wZuBAWOUdXKJKFMj8jHxIHyugzHnttplcy qvsFU8cea9z374ESXOsP/XCJX7AfZEE4Bc9lwF8VDRhrSIxl0gSykz9bHj6L+5Mb8OBq Sy+9RpYwF1s42sjBAhklxzvjkMT9RLEWTrfISJBX58iABhNLKQJIP9QP9Xhfx3yvUWHM /11Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789716918; x=1790321718; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ev1EtVgOCLRng9RIv1gIUfgjXM5TZkVOcIQwbt1kHH4=; b=zwGXCHQMmo+YKUpTKkYEXevfcv8eRFE6PSdlGQGHXf6CeBli20NvOAh4180H/DpaK8 /+YG8DlKLc+YWcayUz8VjGhgABK6zrFXrNqr776Qbo5p6KBAHUnvXtcCi3vHJNXTPnn9 FpJjVXbf/2bkndS8emxpbRDFv94/YR2/XdsEnkN/Z3Y5LFMvUIzHn1nTDdaTCEqx4wm1 x/aBdXV90Adi5gHuXE3W48icEZjdQZiZFgmD/OXF/NVlWrxko4o9IxPV43GTAw9gKMWa qPI5LlQydZasod6PO9sfJDT3lqWt29y8cpJ7lvY8PuypVTZuHPNoZnWuJtGCUaq2GfqV 3E4g== X-Gm-Message-State: AFuF++nauF2AwSC3Y5tsVYgbMpwIDCBl07eW93Qnj35XpFD9BsQP6RbH P6ay9AE7UveyIE+qEVSUBxDXnvswrkh1WMC7KLoJ6F6W4C3aDSLNXz9Ks6ckoFNSRxBVTMgSx1F FW1bVD30= X-Gm-Gg: AYBFou0wqPhmkwk4u8wh3R9lUMeEqcrI3JFBHbTgaVOBXhkkV16MZkaBBk0j05rJ4X/ j9blvLLEAInv84U/yUaBjGmhzDUSOrfJy/f89sDmh/dW9tlKwuvNO4pnP4cfvJwKw16qALB4JDx yM8nhcQQZnS0Y2FXxkaWrKgY+3qDewW+0mL/ZWSukzT0CCbDMB2HKEutQbed40/XMj0Lf7dJqe/ +JRKrVkvpZhRmdTZ7rDuqhmY33yucUF4zUf9+gzrJVlhCF8+KLdMhL0OLFdII3ld7DdchvhANgT W8CGts8oYXxNI1Gp+G3DAUEH2Eced83alNDCskxDcS1IHa5i0WDR96gwTpU7MSx7zX2yxbsXsPs 7m6pODdVHqXavCnaq0ue170lnFl/DK8PJSYLHZtWM9t+WA+EFa9VKM8nbj5oJwP11az0hoqrHkM ixO3dcru1IvDxhXD86vfc3M+XTswOQSJmiAenvvVx6bKAEImf3QYxOd8GSf7rs/1eKIS8DOIxts 1YDdoTmlHX2/d+tEz7xK5stHZrSDhFIF5Cer+ULj1yGm7qfW2ewwkgsnJ/XxU3lZXn73lI9S3+w nuKQ6U+5Lle+8nmzbxCe6aOww+eI8S0xinlqE8JDolCq3l9cTlg2Qcv/PS4UB9RTQCmCb1+Aj9c DCku9zK9PkcH661xn2cXL2fm38mxz3H+huMT4D436J2EC X-Received: by 2002:a05:600c:4e16:b0:49e:8377:c880 with SMTP id 5b1f17b1804b1-49fc574a641mr15734825e9.33.1789716917750; Fri, 18 Sep 2026 00:35:17 -0700 (PDT) From: Manos Pitsidianakis To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Volker=20R=C3=BCmelin?= , Alexander Mikhalitsyn , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , Gerd Hoffmann Subject: [PULL 10/10] hw/audio/virtio-sound: add missing vmstate fields Date: Fri, 18 Sep 2026 10:34:53 +0300 Message-ID: <20260918073502.3265143-11-manos.pitsidianakis@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> References: <20260918073502.3265143-1-manos.pitsidianakis@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:31::11; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-wm2-x11.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1789716987382158500 From: Volker R=C3=BCmelin The virtio-sound device is currently not migratable. Add the missing VMSTATE fields, enable migration and reconnect the audio streams after migration. The queue_inuse[] array variables mimic the inuse variable in struct VirtQueue which is private. They are needed to restart the virtio queues after migration. Signed-off-by: Volker R=C3=BCmelin [AM: trivial rebase changes] Signed-off-by: Alexander Mikhalitsyn Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Manos Pitsidianakis Message-ID: <20260803081159.91981-11-alexander@mihalicyn.com> Signed-off-by: Manos Pitsidianakis --- include/hw/audio/virtio-snd.h | 1 + hw/audio/virtio-snd.c | 83 +++++++++++++++++++++++++++++++---- 2 files changed, 76 insertions(+), 8 deletions(-) diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h index 85d5d7c861..384d2868c1 100644 --- a/include/hw/audio/virtio-snd.h +++ b/include/hw/audio/virtio-snd.h @@ -194,6 +194,7 @@ struct VirtIOSound { VirtIODevice parent_obj; =20 VirtQueue *queues[VIRTIO_SND_VQ_MAX]; + uint32_t queue_inuse[VIRTIO_SND_VQ_MAX]; uint64_t features; VirtIOSoundPCMStream *streams; AudioBackend *audio_be; diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index 12473862d2..6df7ea0eb0 100644 --- a/hw/audio/virtio-snd.c +++ b/hw/audio/virtio-snd.c @@ -24,7 +24,6 @@ #include "qapi/error.h" #include "hw/audio/virtio-snd.h" =20 -#define VIRTIO_SOUND_VM_VERSION 1 #define VIRTIO_SOUND_JACK_DEFAULT 0 #define VIRTIO_SOUND_STREAM_DEFAULT 2 #define VIRTIO_SOUND_CHMAP_DEFAULT 0 @@ -74,17 +73,40 @@ static uint32_t supported_rates =3D BIT(VIRTIO_SND_PCM_= RATE_5512) | BIT(VIRTIO_SND_PCM_RATE_192000) | BIT(VIRTIO_SND_PCM_RATE_384000); =20 +static const VMStateDescription vmstate_virtio_snd_stream =3D { + .name =3D "virtio-sound-stream", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT32(state, VirtIOSoundPCMStream), + VMSTATE_UINT32(params.buffer_bytes, VirtIOSoundPCMStream), + VMSTATE_UINT32(params.period_bytes, VirtIOSoundPCMStream), + VMSTATE_UINT32(params.features, VirtIOSoundPCMStream), + VMSTATE_UINT8(params.channels, VirtIOSoundPCMStream), + VMSTATE_UINT8(params.format, VirtIOSoundPCMStream), + VMSTATE_UINT8(params.rate, VirtIOSoundPCMStream), + VMSTATE_UINT32(latency_bytes, VirtIOSoundPCMStream), + VMSTATE_END_OF_LIST() + }, +}; + static const VMStateDescription vmstate_virtio_snd_device =3D { - .name =3D TYPE_VIRTIO_SND, - .version_id =3D VIRTIO_SOUND_VM_VERSION, - .minimum_version_id =3D VIRTIO_SOUND_VM_VERSION, + .name =3D "virtio-sound-device", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT32_ARRAY(queue_inuse, VirtIOSound, VIRTIO_SND_VQ_MAX), + VMSTATE_STRUCT_VARRAY_POINTER_UINT32(streams, VirtIOSound, + snd_conf.streams, + vmstate_virtio_snd_stream, VirtIOSoundPCMStream), + VMSTATE_END_OF_LIST() + }, }; =20 static const VMStateDescription vmstate_virtio_snd =3D { - .name =3D TYPE_VIRTIO_SND, - .unmigratable =3D 1, - .minimum_version_id =3D VIRTIO_SOUND_VM_VERSION, - .version_id =3D VIRTIO_SOUND_VM_VERSION, + .name =3D "virtio-sound", + .version_id =3D 1, + .minimum_version_id =3D 1, .fields =3D (const VMStateField[]) { VMSTATE_VIRTIO_DEVICE, VMSTATE_END_OF_LIST() @@ -813,6 +835,8 @@ process_cmd(VirtIOSound *s, virtio_snd_ctrl_command *cm= d) sizeof(virtio_snd_hdr)); virtqueue_push(cmd->vq, cmd->elem, sizeof(virtio_snd_hdr) + cmd->payload_size); + g_assert(s->queue_inuse[VIRTIO_SND_VQ_CONTROL] > 0); + s->queue_inuse[VIRTIO_SND_VQ_CONTROL] -=3D 1; virtio_notify(VIRTIO_DEVICE(s), cmd->vq); } =20 @@ -859,6 +883,7 @@ static void virtio_snd_handle_ctrl(VirtIODevice *vdev, = VirtQueue *vq) =20 elem =3D virtqueue_pop(vq, sizeof(VirtQueueElement)); while (elem) { + s->queue_inuse[VIRTIO_SND_VQ_CONTROL] +=3D 1; cmd =3D g_new0(virtio_snd_ctrl_command, 1); cmd->elem =3D elem; cmd->vq =3D vq; @@ -976,6 +1001,7 @@ static void virtio_snd_handle_tx_xfer(VirtIODevice *vd= ev, VirtQueue *vq) goto tx_err; } =20 + vsnd->queue_inuse[VIRTIO_SND_VQ_TX] +=3D 1; buffer =3D g_malloc0(sizeof(VirtIOSoundPCMBuffer) + size); buffer->elem =3D elem; buffer->populated =3D false; @@ -1060,6 +1086,7 @@ static void virtio_snd_handle_rx_xfer(VirtIODevice *v= dev, VirtQueue *vq) goto rx_err; } =20 + vsnd->queue_inuse[VIRTIO_SND_VQ_RX] +=3D 1; buffer =3D g_malloc0(sizeof(VirtIOSoundPCMBuffer) + size); buffer->elem =3D elem; buffer->vq =3D vq; @@ -1200,6 +1227,8 @@ static inline void return_tx_buffer(VirtIOSoundPCMStr= eam *stream, virtqueue_push(buffer->vq, buffer->elem, sizeof(virtio_snd_pcm_status)); + g_assert(stream->s->queue_inuse[VIRTIO_SND_VQ_TX] > 0); + stream->s->queue_inuse[VIRTIO_SND_VQ_TX] -=3D 1; virtio_notify(VIRTIO_DEVICE(stream->s), buffer->vq); QSIMPLEQ_REMOVE(&stream->queue, buffer, @@ -1293,6 +1322,8 @@ static inline void return_rx_buffer(VirtIOSoundPCMStr= eam *stream, virtqueue_push(buffer->vq, buffer->elem, sizeof(virtio_snd_pcm_status) + buffer->size); + g_assert(stream->s->queue_inuse[VIRTIO_SND_VQ_RX] > 0); + stream->s->queue_inuse[VIRTIO_SND_VQ_RX] -=3D 1; virtio_notify(VIRTIO_DEVICE(stream->s), buffer->vq); QSIMPLEQ_REMOVE(&stream->queue, buffer, @@ -1411,6 +1442,37 @@ static void virtio_snd_unrealize(DeviceState *dev) virtio_cleanup(vdev); } =20 +static int virtio_snd_post_load(VirtIODevice *vdev) +{ + VirtIOSound *s =3D VIRTIO_SND(vdev); + uint32_t i; + + for (i =3D 0; i < s->snd_conf.streams; i++) { + struct VirtIOSoundPCMStream *stream; + + stream =3D virtio_snd_pcm_get_stream(s, i); + if (virtio_snd_pcm_state_prepared(stream->state)) { + virtio_snd_pcm_open(stream); + + if (stream->state =3D=3D VIRTIO_SND_PCM_STATE_STARTED) { + virtio_snd_pcm_set_active(stream, true); + } + } + } + + for (i =3D 0; i < VIRTIO_SND_VQ_MAX; i++) { + if (s->queue_inuse[i]) { + if (!virtqueue_rewind(s->queues[i], s->queue_inuse[i])) { + error_report( + "virtio-snd: could not rewind %u elements in queue %u", + s->queue_inuse[i], i); + } + s->queue_inuse[i] =3D 0; + } + } + + return 0; +} =20 static void virtio_snd_reset(VirtIODevice *vdev) { @@ -1442,6 +1504,10 @@ static void virtio_snd_reset(VirtIODevice *vdev) virtio_snd_pcm_buffer_free(buffer); } } + + for (uint32_t i =3D 0; i < VIRTIO_SND_VQ_MAX; i++) { + vsnd->queue_inuse[i] =3D 0; + } } =20 static void virtio_snd_class_init(ObjectClass *klass, const void *data) @@ -1455,6 +1521,7 @@ static void virtio_snd_class_init(ObjectClass *klass,= const void *data) =20 dc->vmsd =3D &vmstate_virtio_snd; vdc->vmsd =3D &vmstate_virtio_snd_device; + vdc->post_load =3D virtio_snd_post_load; vdc->realize =3D virtio_snd_realize; vdc->unrealize =3D virtio_snd_unrealize; vdc->get_config =3D virtio_snd_get_config; --=20 =CE=B3=CE=B1=E1=BF=96=CE=B1 =CF=80=CF=85=CF=81=CE=AF =CE=BC=CE=B9=CF=87=CE= =B8=CE=AE=CF=84=CF=89