From nobody Sat Jul 25 22:03:30 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=quarantine dis=none) header.from=mihalicyn.com ARC-Seal: i=1; a=rsa-sha256; t=1783932202; cv=none; d=zohomail.com; s=zohoarc; b=jaWqO+xn44b+YNxJbcZoeFA2MaN/DqLAtbqlIYznQdfg59BklemWcj/QIkV2QpM6MTFFHncS/7pCO14ZovihZga3dArpHvJOeK0G47sHJkoDJ0Sb+IMKHXOworaXv3vMTbuPR6jxylDKVdXbq+HQPEAfCc9JEgYiIETr0YiE4eA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783932202; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KgVJglLfRPcfZ9RgHwLGDt0Bgq9N6mNRsXg9oN3NnKk=; b=Ix9h63AsUSA/16WoixObHc24BwYkUwDp6HBiVBE8ruo9KEJ9xq2hK/Inx51B1d9I16n0gr9adm9FfUelloHyS8TQ23+ObzP9yHHunau6Lgu9N+fvKwcguiKtxQVT+CKa1XFonJ9p3VBfUQnuN9nzWaXZylQZ2A9mKE5K55gQ088= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783932202749190.56539398580276; Mon, 13 Jul 2026 01:43:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjCFw-0004PU-Qq; Mon, 13 Jul 2026 04:43:16 -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 1wjCFv-0004Ou-17 for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:15 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wjCFs-0003B7-TO for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:14 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-493b1710405so14387805e9.2 for ; Mon, 13 Jul 2026 01:43:11 -0700 (PDT) Received: from alex-laptop.lan (p200300cf574a7200912ca59176a42017.dip0.t-ipconnect.de. [2003:cf:574a:7200:912c:a591:76a4:2017]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493f2d97527sm287254815e9.2.2026.07.13.01.43.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 01:43:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mihalicyn.com; s=mihalicyn; t=1783932190; x=1784536990; 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=KgVJglLfRPcfZ9RgHwLGDt0Bgq9N6mNRsXg9oN3NnKk=; b=Q3CBhxI9G2N4/igynj+g38SWKP9ihEWr6irktCr7XMH9xI7uTcY8Eh+vTr5ZLemZhM Ezjn4T+R3ywKToCurm7ZCMDv4G5jpM5tUi8OkRvtYU1TVj40LSX644KLSj/wOacbYO+H vjNG8Q0vpZkFjiG9rFNmvvZzM4llRX5ZoK9hw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783932190; x=1784536990; 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=KgVJglLfRPcfZ9RgHwLGDt0Bgq9N6mNRsXg9oN3NnKk=; b=pUJ4NUZ2gAk3ymjSewyc1EJQdgRcwzYRyeAf4x21qpoYdWUmMOwBHHK6yvlX1CiT3t 7GA7uTThotzR19zhAdjASDtjkxdakIhkJF9trk90P6tiBT0R/w0YlI2IC4NNJRpRgEfH qusNbBju4FZ4+4Y0w6Jr5lCtACzUEb3cIQbeS90HRn9PeJWqYK/gvpTqc3YBFXNYo7qK xu4wk2srchQFXDHuOfbZmWXTAa2ikU8MDGmTt+GQ5IRAkEDIhFBBE0urPsZTUZrQvxwj QZ9BSf9tiLGpvjEt4KyKgsCoF0QrtGvRyvAY7D8EPiI1yKxuGZhAXFttBWYKLO/2UlBz Wtjw== X-Gm-Message-State: AOJu0Yx/QMOHfhbElbn/76MtFqLGoij4OmVW1YSDvyaZl5suC7BCyOPX o2TAmcKUAtSY9fIbdt+uK7SrCKsi/E34TQHMXKSGBP0kPgwVbC94cxc9xefaU5nn6/DtaZ22vVV VsR0qnEsVqw== X-Gm-Gg: AfdE7cmSOMEb4otlzWv3vYlcyXSBbcwQepzooBlWJTdhmQOdBNPDtY4aFSIR0Zmg3Ke bOMi/GKEBmOxqt/Ts2X8NBSmTjbv48pG3PG1TK9deEcASyNBEzskG9zjpoCcPgeIZclriBRMtry 0HbwieUKBYZlbtr4NGtHp9Xqr+R88UwvH8r16xZSDqHkjVkqJzloSWMUbl9Rfbpg4rF7+E4KPGy 6xj4Wmoi64cZWEySungza/4m8/+ulBCju58ohCZkUWESZK+Kms0QCysY4al51k4svnilBXZ3rdP 2Z9bKIqg9jB7cpKCxSMdBy3WoRJxgmK9KzLRSLyDjFJOMjQVuHgEJlLMFp9Dn0Xxo6/xm+Ji8kj /ZDWfzTlhiPmP6Qr2nFoat9lmB8JX/js3dpyny0vjZICb4Dto4LDpjxLyi3VYCgsXQr0wM/u1la ykJuZnpxclIQAvzlgHuAV462A0Ua7vKF0pqm86HG5J6o97bLe8URUBkNnzb8Q5zKn6egxav6K4/ /QtQ58niPvr X-Received: by 2002:a05:600c:8b05:b0:493:e4cd:def1 with SMTP id 5b1f17b1804b1-493f87e9ba7mr97459825e9.11.1783932190266; Mon, 13 Jul 2026 01:43:10 -0700 (PDT) From: Alexander Mikhalitsyn To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , Manos Pitsidianakis , "Michael S. Tsirkin" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , =?UTF-8?q?Volker=20R=C3=BCmelin?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?St=C3=A9phane=20Graber?= , Alexander Mikhalitsyn Subject: [PATCH v4 01/10] hw/audio/virtio-sound: remove channel positions field from VirtIOSoundPCMStream Date: Mon, 13 Jul 2026 10:42:58 +0200 Message-ID: <20260713084307.79593-2-alexander@mihalicyn.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260713084307.79593-1-alexander@mihalicyn.com> References: <20260713084307.79593-1-alexander@mihalicyn.com> 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:20::336; envelope-from=alexander@mihalicyn.com; helo=mail-wm1-x336.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 @mihalicyn.com) X-ZM-MESSAGEID: 1783932204736158500 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 --- v4: - moved this patch to the beginning of the series (suggested by Manos Pitsidianakis) v3: - this patch was added --- hw/audio/virtio-snd.c | 2 -- include/hw/audio/virtio-snd.h | 2 -- 2 files changed, 4 deletions(-) diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index fb5cff38660..82b6dabac89 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) { diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h index e28f1be5db9..f8bb5c95b97 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; --=20 2.47.3 From nobody Sat Jul 25 22:03:30 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=quarantine dis=none) header.from=mihalicyn.com ARC-Seal: i=1; a=rsa-sha256; t=1783932272; cv=none; d=zohomail.com; s=zohoarc; b=GpO59NpDS+ogG+bKyhfOYi61PImjkQKQnXJN26XyCIv23Xk31SZTLDlI1kI1Py+06jL5DF/ZZHP8kjhIoHwCOhfUclKW9pthtO6QI/AFiMwcufOYkTFN0Gb9BHCpG/KPyA13YZsFl4ziWlzw7rj51UeS3yEDxRtJH0fdCPdeFmQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783932272; h=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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=RQcfPLP+WmCrV3chpWc0PkIedqlYZbmbzhMvhOR7Jag=; b=IVMwUS9lPQ3TgKpNfBXJAckM9Y9zeH2+U16pAyslDAWpiHl7UCAmN5wtAj5x0PaPG2vRa/ndvad94nWifYefhesHpRYojy7XEXPFiYefpsJmNx2FexBI8/rM/HORpRY6vK89EsJQ+g4nbh02gyBvqIGBpX4FvLPrLltfTiUp4yc= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178393227274197.89133517280459; Mon, 13 Jul 2026 01:44:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjCFw-0004PQ-HW; Mon, 13 Jul 2026 04:43:16 -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 1wjCFv-0004Ot-0o for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:15 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wjCFs-0003BD-Te for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:14 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-493c2c0b9a8so23711885e9.1 for ; Mon, 13 Jul 2026 01:43:12 -0700 (PDT) Received: from alex-laptop.lan (p200300cf574a7200912ca59176a42017.dip0.t-ipconnect.de. [2003:cf:574a:7200:912c:a591:76a4:2017]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493f2d97527sm287254815e9.2.2026.07.13.01.43.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 01:43:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mihalicyn.com; s=mihalicyn; t=1783932191; x=1784536991; darn=nongnu.org; h=content-transfer-encoding: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=RQcfPLP+WmCrV3chpWc0PkIedqlYZbmbzhMvhOR7Jag=; b=KTXCOH7uGeDCAftQn2eIMEKvcftE+SlKHa6kBxMTc2gbhvxPj7epl5KOdgW00DwD8G PZ5XJQyqwS5X4t7+nUbdYpeSXKH4QmQrB8TsYBWggWJGBqx8OnG+Zdj97eXx1l5yMEKX rFKyqdQr0d+lW/VvOJnL8S+6T+BW79RP9wLm0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783932191; x=1784536991; h=content-transfer-encoding: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=RQcfPLP+WmCrV3chpWc0PkIedqlYZbmbzhMvhOR7Jag=; b=P2X6lVuiOlee07uWV3w2qM7GoNtZLLGRdyQz4g9GdUy/6l1XV/ScbONSnjtFmDXU77 YlfGP61yatfXWxAxZxD+VALznf3WIlMfzxr9283APbLfLz3C/FnkVkYwzs5HHdeVdDbG ql2hd9Id2iwQ72F/TlPVlwUIyyKfuIWGOd02xKVpy0M7eOA2Sl2+qTUfxfWdnmAmIdXF +J3DI3gue5VOtVrROUm3ZTo71u4HozNgrTqKaV5HQ/A4SONcGYR8kwccTUgmjlULnM0s LVyl3etEeMGkUnAOVhueCeXMML8OOz3e3LVWS3QxaoCtzFYBMWyMGX0Nf9vHf4JabVvd TcjA== X-Gm-Message-State: AOJu0YyDvoOw1FAHuQkSzsQ3i+WSktdgKvmyg0ZYSTJnUCE2KGNG3wIj uZ9JlZO/nXS6UDSISmZPAIZybVzHwTXzB43IocGuhN2w4gUoTdiq7ZSPIqbBFVZaYSyl1SdnL0W /+4u2dzTdKQ== X-Gm-Gg: AfdE7cnjzvqDWz3+zTDA1HWez0SSILdi4G9FSCHdKlnb58GXQVcuZkgh3QiFq4ygIA8 paOmu6x3qS8BxEt80d4zBjVFJWpEp2aT3mRNWt8Up+QrgJfVjME8f9fz5yBoBlDbL0GtMPxb65d 1n6Imm7UPwTFZGlCrB2ZUOA7KVc+LvW6VH7hj1X+ztemsQln6keX1M4SNGivnXNEwRGnLJIwlZm 3stwed8CMXJxD+fGngGDutGaDqevMnWUttnk4JlR4uTg0/nWsahcinzsmzC4zOMC7BgK+My9Hbt XXDiC/NFyRq182D/e/+g4M05VNdw4dTFguCGUMCrDgZFA+EvYndT58IcBgNLZ7IP9NtfA3Icpm9 sy4vodtYSOgEk8LcxkeEPbQ7IN6BefIH14Ey5mJeDHZzzbbFCYo0oeVRPdo+7x0G99sE5UVgw/h zZ7UvP8K1zXZLl08Zhu8MGPjE8G3e04TvNvhl9tbloErVDidXK5HqGErOSV9KCx7/VXHBvFR2tF aHIXxaDPkfs X-Received: by 2002:a05:600c:4ece:b0:493:f8b8:7ebf with SMTP id 5b1f17b1804b1-493f8b880d5mr77695705e9.32.1783932191166; Mon, 13 Jul 2026 01:43:11 -0700 (PDT) From: Alexander Mikhalitsyn To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , Manos Pitsidianakis , "Michael S. Tsirkin" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , =?UTF-8?q?Volker=20R=C3=BCmelin?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?St=C3=A9phane=20Graber?= , Alexander Mikhalitsyn Subject: [PATCH v4 02/10] hw/audio/virtio-sound: drop unused struct VirtIOSoundPCMStream.flushing field Date: Mon, 13 Jul 2026 10:42:59 +0200 Message-ID: <20260713084307.79593-3-alexander@mihalicyn.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260713084307.79593-1-alexander@mihalicyn.com> References: <20260713084307.79593-1-alexander@mihalicyn.com> MIME-Version: 1.0 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:20::32c; envelope-from=alexander@mihalicyn.com; helo=mail-wm1-x32c.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 @mihalicyn.com) X-ZM-MESSAGEID: 1783932274672158500 Content-Type: text/plain; charset="utf-8" From: Alexander Mikhalitsyn Signed-off-by: Alexander Mikhalitsyn Reviewed-by: Manos Pitsidianakis --- v4: - this commit was split from "hw/audio/virtio-sound: add stream state variable" (suggested 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 f8bb5c95b97..b60b098ccd8 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 2.47.3 From nobody Sat Jul 25 22:03:30 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=quarantine dis=none) header.from=mihalicyn.com ARC-Seal: i=1; a=rsa-sha256; t=1783932292; cv=none; d=zohomail.com; s=zohoarc; b=L0ARng2Oe0ehfZX0H/kcuwYPaAM8WPOdew80FLiIA/LfBREGrNtm44Lb26XOdXcJVK7uOsuIqhH2lxCIKj7cjxg/+zipYEA+8u7nquhCqXIVJqzSkMVLn5G4DjK0cdOjSFjb3CSqRHC3vsNUycB0TuODmmpanxvd6+zayCWJfaQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783932292; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CoiX3AkoQfEaEDjWQ5NbxeW2v726cSYjIdNAYVmf5XA=; b=lhQggU0ec7xa8/5K9saUctZTsCzr8stJB08dt1mSjr6SQ7Mtemqcdr2QSz4IeKDBnkGuAa3TvXUz9xNBT+wjV2e0/g/rA2S8QMR5iibvnU05zgvP2JLJFkBKAoBanZQvWzVU+0tJatZXTs1/nS3Q5M0zV01UTzcw2ASfnG0UEbc= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783932292627870.446671676942; Mon, 13 Jul 2026 01:44:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjCFz-0004Qa-Jr; Mon, 13 Jul 2026 04:43:19 -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 1wjCFw-0004PR-Kb for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:16 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wjCFu-0003BN-2V for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:16 -0400 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-493f60208a5so24519165e9.3 for ; Mon, 13 Jul 2026 01:43:13 -0700 (PDT) Received: from alex-laptop.lan (p200300cf574a7200912ca59176a42017.dip0.t-ipconnect.de. [2003:cf:574a:7200:912c:a591:76a4:2017]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493f2d97527sm287254815e9.2.2026.07.13.01.43.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 01:43:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mihalicyn.com; s=mihalicyn; t=1783932192; x=1784536992; 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=CoiX3AkoQfEaEDjWQ5NbxeW2v726cSYjIdNAYVmf5XA=; b=iM9k+g8V5BV3gEAbUk49NVEhiVS5gLCtACHg2UEaBh6QG2bR3J08HFjtTnrMmU2Pgp jyHln9dXOPv0vLrwhJDOiQr4pBDD4YOnuXIsfbVNHWBFd6ipQGHWKyTib6BY4YwHFYcO aO2YN5rs1Cy1R8lk7tEF/RL96T4sx0NB8gvDk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783932192; x=1784536992; 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=CoiX3AkoQfEaEDjWQ5NbxeW2v726cSYjIdNAYVmf5XA=; b=pkbvlBbUaQygyyqdjcE9hLVpWft1ljpjKoSBoikJAc6DpdSWWJZeyQAIo5TyGmzgzp 3eUe5amBOZ80oL3tUHsmo+tlj2o0qDqBv80IzFl9L3UEPkHjjnS4dnJjoREH3VR9yXRt DCXqF6ptiqw3OmhJOpCSOeZAEzf3C55eR1Z7ORwiEghuM3S9PyfFFNU4ZgChWJ/3uG8T YUXynwRJk3sPh+nEDxyJtDgkLqIFcqdKh+NND1h460/goeQ2n0XUVxakCuGsdotnRzv5 KA8DJYWwJtiykgXYvyO9wFYRD6jFOUCXiZZxecoVm9H2gA5dFU8VSXUeSJ6dLlzgKTMA sSYg== X-Gm-Message-State: AOJu0YxT1PKORHGcUshz/A8HVqlEkzoCCDKv2CBObigWUBGRBSZr4AAr R2Ftnbl7WxgrTFuNPl83mNz6swVhZOV9rAFz5rdUw8u8s013Xx47nChkJUC1S0CrGPxQKvy2Y8g TnbcR/oMGbw== X-Gm-Gg: AfdE7cnHA95wddycL5L2d5At3VkRkV2R+m+z4IC5LcNWXoxXBV3kUrhDMfG8I5pHZJM +YmSn3iLKFrGk8xpmDszXOZExTxFH6JHBBRLd+sBQPlNQqIbPKGzKv+zF9kIKJq8hO2iPJMB7n2 I3SCNbY24Kc7JS/oDvctWlcSSs5Oj3Ng6jjkQTh8VIvgzuFqGEj0F2eS5SzvA2QnWQSVZZroXVR fDq0xrtVr6zPbT9Tq/wLHntOGxo1Nh6IaJ4OGiFxS1RSGIHDJIqhHH4oUCy8HbB2d50Qt5rymbG shsX+2gMfwyxuft8pLfoYAzUW1FZNsp3/39jsNTe0f90g/91Q8axBovMo3fi/cCan3rdXZn83cf KuMK0oT+icOWzYlG04siEPDwUWFHCtuSEsKMYqLyU3qcrYtdg1D3tv7r3WHV4jv4MtokTbRuQyQ qq4HU8sCGo1+iB+mlHkrVVcZMlewDr3O6WO4YsvfaajCQyL7WmiZERTcv0Ljov2kcJLGb4ueS24 o1S+EoKsvX1 X-Received: by 2002:a05:600c:2247:b0:493:e79e:da63 with SMTP id 5b1f17b1804b1-493f8834ea6mr59072105e9.34.1783932192235; Mon, 13 Jul 2026 01:43:12 -0700 (PDT) From: Alexander Mikhalitsyn To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , Manos Pitsidianakis , "Michael S. Tsirkin" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , =?UTF-8?q?Volker=20R=C3=BCmelin?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?St=C3=A9phane=20Graber?= , Alexander Mikhalitsyn Subject: [PATCH v4 03/10] hw/audio/virtio-sound: remove command and stream mutexes Date: Mon, 13 Jul 2026 10:43:00 +0200 Message-ID: <20260713084307.79593-4-alexander@mihalicyn.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260713084307.79593-1-alexander@mihalicyn.com> References: <20260713084307.79593-1-alexander@mihalicyn.com> 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:20::32f; envelope-from=alexander@mihalicyn.com; helo=mail-wm1-x32f.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 @mihalicyn.com) X-ZM-MESSAGEID: 1783932294949158500 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. Signed-off-by: Volker R=C3=BCmelin [AM: there were too many conflicts, I did `git checkout --ours -- <.>` and then reimplemented the patch idea /AM] Signed-off-by: Alexander Mikhalitsyn Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Manos Pitsidianakis --- hw/audio/virtio-snd.c | 248 +++++++++++++++------------------- include/hw/audio/virtio-snd.h | 3 - 2 files changed, 110 insertions(+), 141 deletions(-) diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index 82b6dabac89..27018df8485 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; - } - - WITH_QEMU_LOCK_GUARD(&s->cmdq_mutex) { - qatomic_set(&s->processing_cmdq, true); - while (!QTAILQ_EMPTY(&s->cmdq)) { - cmd =3D QTAILQ_FIRST(&s->cmdq); + while (!QTAILQ_EMPTY(&s->cmdq)) { + cmd =3D QTAILQ_FIRST(&s->cmdq); =20 - /* process command */ - process_cmd(s, cmd); + /* process command */ + process_cmd(s, cmd); =20 - QTAILQ_REMOVE(&s->cmdq, cmd, next); + QTAILQ_REMOVE(&s->cmdq, cmd, next); =20 - virtio_snd_ctrl_cmd_free(cmd); - } - qatomic_set(&s->processing_cmdq, false); + virtio_snd_ctrl_cmd_free(cmd); } } =20 @@ -890,19 +876,17 @@ static void virtio_snd_handle_tx_xfer(VirtIODevice *v= dev, VirtQueue *vq) goto tx_err; } =20 - WITH_QEMU_LOCK_GUARD(&stream->queue_mutex) { - size =3D iov_size(elem->out_sg, elem->out_num) - msg_sz; + size =3D iov_size(elem->out_sg, elem->out_num) - msg_sz; =20 - 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; + 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); - } + QSIMPLEQ_INSERT_TAIL(&stream->queue, buffer, entry); continue; =20 tx_err: @@ -971,16 +955,15 @@ static void virtio_snd_handle_rx_xfer(VirtIODevice *v= dev, VirtQueue *vq) if (stream =3D=3D NULL || stream->info.direction !=3D VIRTIO_SND_D= _INPUT) { goto rx_err; } - WITH_QEMU_LOCK_GUARD(&stream->queue_mutex) { - size =3D iov_size(elem->in_sg, elem->in_num) - - sizeof(virtio_snd_pcm_status); - 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); - } + + size =3D iov_size(elem->in_sg, elem->in_num) - + sizeof(virtio_snd_pcm_status); + 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: @@ -1084,7 +1067,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 @@ -1152,52 +1134,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 @@ -1248,55 +1228,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 @@ -1313,11 +1291,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 @@ -1336,14 +1312,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]); @@ -1364,12 +1338,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 diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h index b60b098ccd8..884c475ffd9 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. --=20 2.47.3 From nobody Sat Jul 25 22:03:30 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=quarantine dis=none) header.from=mihalicyn.com ARC-Seal: i=1; a=rsa-sha256; t=1783932278; cv=none; d=zohomail.com; s=zohoarc; b=eOfaih9nUiw78XLRkDgo3k/q4Fozv0TEIINgC3VFdzqvctNRHcfCHWhUwryvYIJoDWAyzpBjqdCOf0RHigDGBPfgXZlZ1bjsqfERdCtmw42GrySnA1ggIDYI4LW+JpHcXoAMEAQIK/8GZgM6ZdP1/XvobcjU6Yw9rTE1ot9gRCU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783932278; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ogc16JUbVnYmLt9FW0jIh4XHU0HGfMQjrBdoB+HO0eY=; b=cX9MZe51o2zYr6pkaPOazN90L+f1PvbtrxE3Kxf4nb+bzwE1XETt/2ThO46GKjIwWD6zja9HJ/93UJ6XU568jjmnM4qpAz2x2mJmt1Lz2pkd0h5LpoSLXiHfTMaUpE0KV0A1gSRWsCIZDHQ4EgFGnD5vVKJr66LRn/VRShIG7vo= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783932278767847.6663305336205; Mon, 13 Jul 2026 01:44:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjCFz-0004QX-3p; Mon, 13 Jul 2026 04:43:19 -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 1wjCFw-0004Pf-UC for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:16 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wjCFv-0003Be-2S for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:16 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-493ec555a26so18710555e9.0 for ; Mon, 13 Jul 2026 01:43:14 -0700 (PDT) Received: from alex-laptop.lan (p200300cf574a7200912ca59176a42017.dip0.t-ipconnect.de. [2003:cf:574a:7200:912c:a591:76a4:2017]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493f2d97527sm287254815e9.2.2026.07.13.01.43.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 01:43:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mihalicyn.com; s=mihalicyn; t=1783932193; x=1784536993; 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=ogc16JUbVnYmLt9FW0jIh4XHU0HGfMQjrBdoB+HO0eY=; b=hoe+dEljohmHv0gCu/8baWmbMaUfJltRXJmD5bzntwCMc6c1S19GP1tXO2DEiw7+30 bGogCdipT3stafGa6Qnh9FiiclUru8sOp/2XcM2aYC4M9jdL9gmaqz0HYIiUjsaCwbp6 ezsItfs35zaGBniaiDrXuzJ0NU35Z2+Y7TEbI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783932193; x=1784536993; 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=ogc16JUbVnYmLt9FW0jIh4XHU0HGfMQjrBdoB+HO0eY=; b=EcxqGBCdMfRC6o4YXpNJtGzQII9gBek4RYZWHXQGWUJm5jEqPJgHAH1Xxezayu8b/Y /pGpiCN3DBGMYHbNmhsGOU65KoGBOpaf1D3zBE4dWgTvKgjLn2BGZvMxdSIqgqm2svjg FvrmeCAKRWCDqFvFSM9r7Ov7bnfTmSyV9wLjff/9+nxo2USWXUniOg4LgYLpvCYmyqP0 id9ugRazlrL2RhhkdyfT/qDZJvQR4gyHt/8HjzQ8zStjaFxLsV7EG7o+2+iN1UqtR0I6 gEgasPEU8SldY8FPjMQBqojregEMDnAMflHHu0lKMyU4jjYpiMR6WJWe1DHe57t6kEy8 Wb6w== X-Gm-Message-State: AOJu0Yw9xWxntF7XH36Frw+9JcIpRrzROkhUqGHJRKJW5Z2tLlDeQcBp rGQs9KoX1tEWl4THmhZUc67B9/0+KyawlMiBgUi33u5oc4bc/W6vM/RQgCHq9QTui56GveKAtZo 5AQjbrybglQ== X-Gm-Gg: AfdE7cnhjbXTWVTv7kVh16LKcseveziZsNuqbLNMtZYzYq9xaa0Q4DxTAvtEtBJIlXj 6TC2j39+u5CCsCdelu+MtdRLsW/qV+xqyuWqI8ZtvPUHvU3XurlCFSmY1e7/ChruaTX6Abjv4w/ 7dqAGbrMH/F0BVIhQ9gPD2zJehFrA6sktZYUZA4JPNcE8xhh3n3D1kTfcbJONCYWeSqFENlpC1J h4fGrZviiDUP5rzyUCMGHPDjiZLPC0+apCuA0iE1IgbVFUGdmHZDjyCcs+ZCGk4CvUGtQtIpvX/ Uo/gbA+f2+/nUWbWcK2j1y1W73HEtO2KEznQHWiu1XK83bfCKUTTPCpWb/z2VKqze/Z3Ptng/WV B7fY22pbwE9yov8f3Wm5kbSI9kifSG/gXoTn6zXWWe9ngB4rK32OXVE1r8iR0vfa1MH+eCpICim lKpsYDQThCkZfk3KxnM8HWTUikhXtMa/7pJvsMTQuqc77cRUsgQKSIuXh8i3t77WGzlCpD+6d+P BCI3WDZTouiQ7r17GxY2Dg= X-Received: by 2002:a05:600c:348e:b0:493:bd37:1cdf with SMTP id 5b1f17b1804b1-493f87d6219mr84108355e9.2.1783932193202; Mon, 13 Jul 2026 01:43:13 -0700 (PDT) From: Alexander Mikhalitsyn To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , Manos Pitsidianakis , "Michael S. Tsirkin" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , =?UTF-8?q?Volker=20R=C3=BCmelin?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?St=C3=A9phane=20Graber?= , Alexander Mikhalitsyn Subject: [PATCH v4 04/10] hw/audio/virtio-sound: allocate an array of streams Date: Mon, 13 Jul 2026 10:43:01 +0200 Message-ID: <20260713084307.79593-5-alexander@mihalicyn.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260713084307.79593-1-alexander@mihalicyn.com> References: <20260713084307.79593-1-alexander@mihalicyn.com> 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:20::32d; envelope-from=alexander@mihalicyn.com; helo=mail-wm1-x32d.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 @mihalicyn.com) X-ZM-MESSAGEID: 1783932280663158500 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. Signed-off-by: Volker R=C3=BCmelin [AM: there were too many conflicts, I did `git checkout --ours -- <.>` and then reimplemented the patch idea /AM] Signed-off-by: Alexander Mikhalitsyn Reviewed-by: Marc-Andr=C3=A9 Lureau --- v4: - fixed stream->info.channels_max value (problem was noticed by Manos Pitsidianakis) v3: As suggested by Marc-Andr=C3=A9 Lureau: - drop VirtIOSoundPCMStream's id field --- hw/audio/virtio-snd.c | 33 +++++++++++++++++++++------------ include/hw/audio/virtio-snd.h | 2 +- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index 27018df8485..b2b711457bb 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; @@ -1044,6 +1034,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 @@ -1312,12 +1320,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]); diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h index 884c475ffd9..97ffaae18be 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; --=20 2.47.3 From nobody Sat Jul 25 22:03:30 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=quarantine dis=none) header.from=mihalicyn.com ARC-Seal: i=1; a=rsa-sha256; t=1783932292; cv=none; d=zohomail.com; s=zohoarc; b=IY78pOVPvYeIYAz4CxgKWhX4qRoWUZtGPsl8i5TppzKCRMrJHOt7IPHl8btawZiPiUBW0MQMsu4oA3k7IBsmL5BQaKAo4ctENt9yDw1kakLKdnGI/4j2O+FOruQN/99ZBOxljiidIwzsl2+o3/f7GQREwPetsB3ljzF9GIp7FIY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783932292; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JUpFAaA/MW806h78l6jk6bGX0Ax9ZtQC7KOXHk9noao=; b=EbELSny6eidwR42GktC9//fnse9swz0JhdioRK4ndMz+cWqhV9F2uH7/rjbRoX11MYsIBbDnOmVk6qOZcSD4nlFN7/3G5WqE0Y3CxKh8KAe3k44bECCy0XgnAtcXRHk5+9SfUQUs1I47qunZmha0F3fJy8jhXd15GUv2w157WX8= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783932292445275.50211761053845; Mon, 13 Jul 2026 01:44:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjCFz-0004QZ-FC; Mon, 13 Jul 2026 04:43:19 -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 1wjCFx-0004Pr-2G for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:17 -0400 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wjCFv-0003Bm-II for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:16 -0400 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-493e4cccd8dso12360395e9.2 for ; Mon, 13 Jul 2026 01:43:15 -0700 (PDT) Received: from alex-laptop.lan (p200300cf574a7200912ca59176a42017.dip0.t-ipconnect.de. [2003:cf:574a:7200:912c:a591:76a4:2017]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493f2d97527sm287254815e9.2.2026.07.13.01.43.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 01:43:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mihalicyn.com; s=mihalicyn; t=1783932194; x=1784536994; 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=JUpFAaA/MW806h78l6jk6bGX0Ax9ZtQC7KOXHk9noao=; b=PSxrjy0UGqFwxQAf4Bo771jz5tZWFwFZCK4CQ+QV7LZxiYBWFBJOQ3g5lh6lZjnUSh SICVyPdgO0YU8g8zXdAmPMFFNRuZNdBFEpEbWxWjLI+gNDCbl/6DxJlAe0amg9DPo0XJ Ra05mw0xHHmcDjWMsz5sxWAVZRD2Db5LDcSWI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783932194; x=1784536994; 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=JUpFAaA/MW806h78l6jk6bGX0Ax9ZtQC7KOXHk9noao=; b=Z7LMZeEzST1GsOcUbvrK5ZbfUGy5Dt0oVl/3j3C7ISUyJe5Euyn1UfDlzUKkFC/q0D 08ekS0OdswaPuPuU6PGSRAg5QoXg+P3m1Hjn25Git5ZHYkLsjYblySU1LY6vXcAVYwQ2 VfvgLkoAF0PuFzZG3b6xZQKf34t+3gylakXfZ6WlM2unbRTRUirHaqPH/cUoFubgB8M2 w+6hMf0WMegtZPchyMNdaasgKdoBssOMhfx+Y5F5wj1Qh9DL5rh2aq2iNxk9+hTj2aBd hF5q/BuzSIqvppwU//Ph+829uSuC7U8Ay04dAsww3mu2kl3Qf0yc16hvA9i32bHeVGBa LKgg== X-Gm-Message-State: AOJu0YzwcTloXiUGtvzX9n4ECDPXidRtiws9P817WNM6zfHzQZpWMjJJ tXAQyMAPyxKSSOj0/hU4of4HLjBTdi5B1iHsMl0Li87Z0FRo0XDaIWelRLZT2GIxNBEsxhWvnee Bm8VLKmDY0w== X-Gm-Gg: AfdE7ckgrA+iFRAF18U0x5WkPbj0Q0MSi70EgaJ7nwH2GQcMIy6pAOeB2/q4F3oR0WU na7bSnPp9WQbUPGrtjYsVlHMus2vqBZZ34AQB41UNbye+zOXvMSy5181LZ7GsQHjIrOgu7C2RGO 2lsBFFGWvwwhKXEQfRfM0zdmMJRVC3vgjzVYxIZ/mJ9FYYU8jRSx5+kaWxYMdF3MV8wHrJO4ul2 1+NYlxZDGRFycAK4cZs7NVdz9hdPly0E8ZMRpKzG5LHshniGVHfTkgb7Sb2anZIdefYkJYWvWGY sw8+NFSqRQHenK8knE6K5XWSudf3h/s/FwYWG1IAeS479BXgbecSwu1wvnkBa6oL7dP6pbAg5bU wtttE8YfxDrep9sXLQg82eSPV1vqL1+yeuj2Q1vOr2Pu3rUfrZVe9miN5OF0gOov4bsTR4wYL9u v7MYnRezpnAyiF2k3t1SYeIXlLpZ0Ybm1BzwKBQ4Cn5eMaqTzyCBj1Ba61o9WzJ6LSzokCz0Yx/ K9b2J7AauMtgJftQq93zp8= X-Received: by 2002:a05:600c:3b0e:b0:490:c032:ae92 with SMTP id 5b1f17b1804b1-493f882a31amr74707075e9.33.1783932194097; Mon, 13 Jul 2026 01:43:14 -0700 (PDT) From: Alexander Mikhalitsyn To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , Manos Pitsidianakis , "Michael S. Tsirkin" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , =?UTF-8?q?Volker=20R=C3=BCmelin?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?St=C3=A9phane=20Graber?= , Alexander Mikhalitsyn Subject: [PATCH v4 05/10] hw/audio/virtio-sound: free all stream buffers on reset Date: Mon, 13 Jul 2026 10:43:02 +0200 Message-ID: <20260713084307.79593-6-alexander@mihalicyn.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260713084307.79593-1-alexander@mihalicyn.com> References: <20260713084307.79593-1-alexander@mihalicyn.com> 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:20::32c; envelope-from=alexander@mihalicyn.com; helo=mail-wm1-x32c.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 @mihalicyn.com) X-ZM-MESSAGEID: 1783932292685158500 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 --- v4: - reduced a scope of loop counter variable in virtio_snd_reset (as suggested 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 b2b711457bb..d51fc386593 100644 --- a/hw/audio/virtio-snd.c +++ b/hw/audio/virtio-snd.c @@ -1352,6 +1352,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 2.47.3 From nobody Sat Jul 25 22:03:30 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=quarantine dis=none) header.from=mihalicyn.com ARC-Seal: i=1; a=rsa-sha256; t=1783932230; cv=none; d=zohomail.com; s=zohoarc; b=b0EXLDcX1FdFO7iPp4edOlfFvgWx/UqyFJGVyn3/GgYZmEVsY7TDO78Ou6moC8Ah50ern1ZxGFxJCkzNsfZYBWsg+Or8R3j6AXMYsgGJAMAA/BzmFYCQB35dEvuwrVlx5N/Rc6q99PqOJ/8srCaETBB2bV2Y/VyIghEToIoFM0A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783932230; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/nTAnPlce3PEAulqjgSLun7hRTB1dh5U84U7OuA1BCs=; b=hszCJY7OkDMVBXbAAaMoVnHLaASWd7xNmEWFQQr1NGTDIA2812BCNKg6vI1FJGV1M9mF94zj4bRfkjJBAaiXYEcJe5juBMLVj2HGfKCWbS+Sq+UxW4HMSZsA38l7O3tNl97ClxGRHaBGkG7nCu4CTiD7dhC5tx5jFO2MaCSen28= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783932230680325.3289999934642; Mon, 13 Jul 2026 01:43:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjCG0-0004Qd-1v; Mon, 13 Jul 2026 04:43: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 1wjCFy-0004QQ-PB for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:18 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wjCFw-0003C4-UM for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:18 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-493bf73ec2aso20078395e9.2 for ; Mon, 13 Jul 2026 01:43:16 -0700 (PDT) Received: from alex-laptop.lan (p200300cf574a7200912ca59176a42017.dip0.t-ipconnect.de. [2003:cf:574a:7200:912c:a591:76a4:2017]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493f2d97527sm287254815e9.2.2026.07.13.01.43.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 01:43:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mihalicyn.com; s=mihalicyn; t=1783932195; x=1784536995; 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=/nTAnPlce3PEAulqjgSLun7hRTB1dh5U84U7OuA1BCs=; b=LjJzDlnxQuB7GT6enTQlGzvxvzBvCNgLBlgvxPEqR/soqZAWnh7QhmfrC6MYiIbCyA rhBN2MRi4arU7Rcr/2wpkYmhYY0//8tBsVs1cjxqaI2gFNbdronA9Cb6w0CcxTdi1+Ij cAcATNCPdPfS85IcY54IrUnQOEc42sDyoqf3Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783932195; x=1784536995; 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=/nTAnPlce3PEAulqjgSLun7hRTB1dh5U84U7OuA1BCs=; b=Ps4S3jZpTHiUaAKF9sAWldWLQJTQ1t5Z6KjEBF75bkbCMS7c/r+2olvSRpKhyc4KM3 sY434gj8KE13meS5IOkjBHeH7ltFAzrJLTrWEUmXzhjsymg63nZiuKb9bSReH1vYwyKt FxvCD7HX497Pto8Qx7GTyFAZcXMqyUpRN7rCOlsWB1v7H0orvKNHe85l48zEtmvE/x5R EqmuQwtUgbcK7Gd5fgAZG8prC6sgJOeMp8vN3ncn5K39xXxRh05gAEPKOP/pnypbdsZS e1Wy0v654dU9A0cKK/U1zjk5pSMim7Sp0OZfCti3xPSYE4vNEl4cOB/vNU+y/876mfxO VoKw== X-Gm-Message-State: AOJu0YzokERA1lYRRIg5+/mfbNBPhjcRdp1mXIU2LWhooNph0Bpdr8B9 +Y1QQAxUaQAVSKYcBVplaRfhIOR3GJ+i4vC+RTM0BHdTW4quvL9l9FTZ3U7TLXA4f2p3PdQ073p Nvygvcn0EUA== X-Gm-Gg: AfdE7clCWp9t8n4lsZHOtTfM3TF6KFSPmeW51VFGYdNkKtdKySSHOcWJShPg8wxmWao EJEPimkmSeFLKUrrVGx68nvqI5q2pG0C/PdSAxT8xTISpF3Bgj2QJFb+AbmFdWDh0QTE7ZEbXe+ k3HLidXCnfdvv5AO4urqzspIZZxbeg5Y3kFjFPYYGphbJCm1vA/apoi8Wc+nGxwekaBqGuOKx+I /ZMvXCKGEJA1QU9cYPTtWLr9F46qi4Kw7iL8WdAnrytrFyeX4t8TCufA8EGdiOoyrzwI4iFfbX0 OYTvm59NOWVaSckBcO3A9jmJiUbdF8t/JXKut0dmz2BNPm1zLDyI8blVo/W83DpxtV4Xhl/+uPD iXdgl3MuVInjYe2IwQjhz6D3XKUBch8/aVr//nV2KFIXLCLH6blvpsc6EgKq5ZBL4Wc+ObLp2rP qajfH5mDTsIsHr9+dT38DEJt2OL1KLd4MKYbidR4NzADhzDifdTeahRoodRVjCaLxf1Xvs1Cxhe J16bHkzjFjk X-Received: by 2002:a05:600c:1f91:b0:493:e79e:daa6 with SMTP id 5b1f17b1804b1-493f8826e69mr78408575e9.33.1783932195013; Mon, 13 Jul 2026 01:43:15 -0700 (PDT) From: Alexander Mikhalitsyn To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , Manos Pitsidianakis , "Michael S. Tsirkin" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , =?UTF-8?q?Volker=20R=C3=BCmelin?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?St=C3=A9phane=20Graber?= , Alexander Mikhalitsyn Subject: [PATCH v4 06/10] hw/audio/virtio-sound: split out virtio_snd_pcm_start_stop() Date: Mon, 13 Jul 2026 10:43:03 +0200 Message-ID: <20260713084307.79593-7-alexander@mihalicyn.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260713084307.79593-1-alexander@mihalicyn.com> References: <20260713084307.79593-1-alexander@mihalicyn.com> 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:20::336; envelope-from=alexander@mihalicyn.com; helo=mail-wm1-x336.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 @mihalicyn.com) X-ZM-MESSAGEID: 1783932232471158501 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. Signed-off-by: Volker R=C3=BCmelin [AM: there were too many conflicts, I did `git checkout --ours -- <.>` and then reimplemented the patch idea /AM] Signed-off-by: Alexander Mikhalitsyn Reviewed-by: Marc-Andr=C3=A9 Lureau --- v4: - minor formatting change in qemu_log_mask() - moved the trace_*() calls at the start of the function (as suggested by Manos Pitsidianakis) v3: - resurrected error_report(..) as suggested by Marc-Andr=C3=A9 Lureau --- 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 d51fc386593..d3fc4c30877 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 2.47.3 From nobody Sat Jul 25 22:03:30 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=quarantine dis=none) header.from=mihalicyn.com ARC-Seal: i=1; a=rsa-sha256; t=1783932272; cv=none; d=zohomail.com; s=zohoarc; b=eQieENPccZVZ44OO5wAolOc60zQpYFs5pa4QPrv0iYIiRsw1Waky8eH+lrkDqZAccyLByF94k1FPgKQ3djmP7N27iDHZ7me7B0IDJiIu3qHPBnAHCJSfcwyFiymw2mEkLsqtJc30aaCa7cR+qxoFT7U6FcEZ2bydAm6vMYsuwvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783932272; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vPQ3FlS3yTT+HXB5gOZk8BQRO5GzOakOVc4WXAXjm/4=; b=CjqZlEn9Q4yL0yUrmUQfft4OtW9t4Db01Rdl1tLxYggbJVl9GcIgBIz1V7VKiYwdufe7Upz/vJ31cvozlJAKGCE7S0YTiRPTZkHQBJadRpgbgJ3ux6U6q7A016Lp1Rl+y5l+/NCOHcFMXy5JQcYrxp8dx9O7gmoixf8LwVTS5lg= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783932272320229.55125967766617; Mon, 13 Jul 2026 01:44:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjCG3-0004Us-9G; Mon, 13 Jul 2026 04:43:23 -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 1wjCG0-0004Qe-8R for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:20 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wjCFx-0003CI-LU for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:19 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-493e4ccccc2so18551955e9.2 for ; Mon, 13 Jul 2026 01:43:17 -0700 (PDT) Received: from alex-laptop.lan (p200300cf574a7200912ca59176a42017.dip0.t-ipconnect.de. [2003:cf:574a:7200:912c:a591:76a4:2017]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493f2d97527sm287254815e9.2.2026.07.13.01.43.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 01:43:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mihalicyn.com; s=mihalicyn; t=1783932196; x=1784536996; 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=vPQ3FlS3yTT+HXB5gOZk8BQRO5GzOakOVc4WXAXjm/4=; b=CTk2Paz3y79EWHea9qerjEdYhz4L+nZyir5JoaQuMtlC80Tmy5yUanSFSWeSXcr7Kc fke+UUQylMnyQVqNrLytxN9VLHmR+p3TtkzETAjcI/g0dNV8PbNFb/Mdpxmaezp9rV6/ 81FyCsQheBv2+Fwu9eoagW0A1JAqRgwxrZ+wU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783932196; x=1784536996; 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=vPQ3FlS3yTT+HXB5gOZk8BQRO5GzOakOVc4WXAXjm/4=; b=ZcFtTyebWYX/vxMktr5sNuRz2oVX6yD49IA6dkxWd2WLa/BgWLKMPcZv75ckvujz1l zankbc842sBHYGwu3gtYJsefinDp9eSQu3JdBBgWHf/yqW/VT/d9KscgBYSUhqidaFPU WZfW/jt+0o6cplWASKjKScYcr6RjyNMCqRNEmVOztRWybqLECXc6kh6Ox67loBHJkukt zRV6kLZgCnbsLMR2zwc32c63vcvyD1egPQe/V+ltVlW1YydjaNj9LXaLxPdj1nnIqrJe qNzWt88eh5fO+FqrekKoXj+Ya143vrtIpO9PLI+7ydo+5D3xUvopOS4uVvnf65/Mq8UC MuDA== X-Gm-Message-State: AOJu0Yx6ssGFuyR5MLtH5FVpX9sa+NtTMCOcTZ1Pm9+dNg88l8ass9A9 79DDy4fGE8QYzRdqS+mxTlJLCg4Tnt2z5H5BTk3w64+DcqLK/oLcqMqjrD6w1darrnUBlnVdtW8 wkzBhGry+NA== X-Gm-Gg: AfdE7cnn2apfeG8qGGqrEE5FmLG0ztPZa4SBKKSS2p+r8GaI7yF/9iW+DpbDI/HPgTe GR0THwMhB2ZIUk1E3WGini+soUP+G9KwQxh7CtNJaH1yF3ab4NeSTVGxLazPIugTBbc6HtZ4zPW KNT+I6L3JV2gW3jHEWl/zO6FBxI+Bm02sPLwf80MUJfbCmk0DGMu5L1ItDo2x/LLHLOfs8P8wJO xKcSGLP0UYWyWRFmZQXQRiKFeUW9350sqCJzSOGkfJWmTkJi8i4CFycmNOlzAe+N5ielPAfZG/i HmHHg7OI20Fw3rkKAubL40P2X1/lRLQ0Mxjk3pfkvm3m3a1Ka8vHOL1gefMRmBmUHMdWyh5W/j1 3rlTK/CH161C3r7QGDNbeMCWNoJ5g4uNSiXUjaqaC6vVHemW72FusIAAa88F7QxP/SnhdqRAMm1 2fapaGu3h9PJan2Eoh6Z+68hi+tpvLrF/1rJld86kIBvfIWVOO4phWmL6UFpXvyHq/FgY2qYi/M h9no5BGOgMR X-Received: by 2002:a05:600c:8718:b0:492:4363:e7eb with SMTP id 5b1f17b1804b1-493f8827705mr73515835e9.32.1783932196061; Mon, 13 Jul 2026 01:43:16 -0700 (PDT) From: Alexander Mikhalitsyn To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , Manos Pitsidianakis , "Michael S. Tsirkin" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , =?UTF-8?q?Volker=20R=C3=BCmelin?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?St=C3=A9phane=20Graber?= , Alexander Mikhalitsyn Subject: [PATCH v4 07/10] hw/audio/virtio-sound: add stream state variable Date: Mon, 13 Jul 2026 10:43:04 +0200 Message-ID: <20260713084307.79593-8-alexander@mihalicyn.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260713084307.79593-1-alexander@mihalicyn.com> References: <20260713084307.79593-1-alexander@mihalicyn.com> 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:20::32d; envelope-from=alexander@mihalicyn.com; helo=mail-wm1-x32d.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 @mihalicyn.com) X-ZM-MESSAGEID: 1783932272709158500 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. Signed-off-by: Volker R=C3=BCmelin [AM: there were too many conflicts, I did `git checkout --ours -- <.>` and then reimplemented the patch idea /AM] Signed-off-by: Alexander Mikhalitsyn --- v4: - switched to enum virtio_snd_pcm_state (suggested by Manos Pitsidianakis) - call virtio_snd_pcm_close() when switching to VSND_PCMSTREAM_STATE_PARAMS_SET and VSND_PCMSTREAM_STATE_RELEASED states - added virtio_error() in case when stream->state is unexpected - fixed an error message text in virtio_snd_set_pcm_params (suggestions from Marc-Andr=C3=A9 Lureau) v3: - explicitly call virtio_snd_pcm_close() from unrealize - remove a call to virtio_snd_pcm_flush() from virtio_snd_pcm_close() [ ^ this was my rebase mistake ] --- hw/audio/virtio-snd.c | 211 ++++++++++++++++++++-------------- include/hw/audio/virtio-snd.h | 17 +-- 2 files changed, 123 insertions(+), 105 deletions(-) diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index d3fc4c30877..9505e478e91 100644 --- a/hw/audio/virtio-snd.c +++ b/hw/audio/virtio-snd.c @@ -30,11 +30,25 @@ #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 +143,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 +155,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 +259,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 +270,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 +307,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 +317,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 +435,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 +457,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); } =20 - params =3D virtio_snd_pcm_get_params(s, stream_id); - if (params =3D=3D NULL) { + 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 - 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; - } + params =3D virtio_snd_pcm_get_params(s, stream_id); =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 +498,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 +574,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 +692,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 +717,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 @@ -874,12 +942,11 @@ static void virtio_snd_handle_tx_xfer(VirtIODevice *v= dev, 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] =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; } @@ -954,13 +1021,12 @@ 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]; - if (stream =3D=3D NULL || stream->info.direction !=3D VIRTIO_SND_D= _INPUT) { + stream =3D &vsnd->streams[stream_id]; + if (stream->info.direction !=3D VIRTIO_SND_D_INPUT) { goto rx_err; } =20 @@ -1019,8 +1085,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 @@ -1057,6 +1121,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; @@ -1070,21 +1135,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 @@ -1095,28 +1148,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) @@ -1165,7 +1196,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; @@ -1259,7 +1290,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; @@ -1332,17 +1363,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]); @@ -1375,6 +1405,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); diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h index 97ffaae18be..85d5d7c8619 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; --=20 2.47.3 From nobody Sat Jul 25 22:03:30 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=quarantine dis=none) header.from=mihalicyn.com ARC-Seal: i=1; a=rsa-sha256; t=1783932280; cv=none; d=zohomail.com; s=zohoarc; b=clASaH9xuFcv2LkUkUYkjkVAOVPNlape3UG55V2f/aq5q3yz9Ia0tF9CWdjPp02pZrGAFH/wfC76SqTWrmYPNodpzOWrfwJX1xv/1zyQfF9841TulE/G8NRfjdaUbd1mSK51qp+T4imc2XElUoB7CZlnaV+RhEaE2RP7up4FyoA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783932280; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=grKqIq319Vp7GavJNr9NRlJdcT2STtYLsl9rv45lrJw=; b=HUNQQFgm0bqUWpwwjHPtNjbe4mDqx9NSv6fqXHBd2zqjpqkvEExexVmzlNmkakEE/2PmEaFtW9wDXcRhLRDBP/Kus6lLP13pIA2vuUSQgYxZH3PV6ynNNbtzM+WeK5vTVYdQZiVfp/xCGBdVLcBwYOGKjVNBwFsc/d8bhm/D5sw= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783932280916787.8969154251935; Mon, 13 Jul 2026 01:44:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjCG4-0004V3-9A; Mon, 13 Jul 2026 04:43: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 1wjCG0-0004Qf-Cg for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:20 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wjCFy-0003CT-ON for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:20 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-493ae59eca6so13172805e9.1 for ; Mon, 13 Jul 2026 01:43:18 -0700 (PDT) Received: from alex-laptop.lan (p200300cf574a7200912ca59176a42017.dip0.t-ipconnect.de. [2003:cf:574a:7200:912c:a591:76a4:2017]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493f2d97527sm287254815e9.2.2026.07.13.01.43.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 01:43:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mihalicyn.com; s=mihalicyn; t=1783932197; x=1784536997; 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=grKqIq319Vp7GavJNr9NRlJdcT2STtYLsl9rv45lrJw=; b=Qjgnz+XusZxnAoTNS3/l0/BCWuprnl76R4JRu4COlNihGfRDLJ6WjQatPh2QqIikca MmfCmKfIhEZiKsUs64lbq8TbHtY/omX7cDWFiKLayPLdfrwocLbUU4QVHYAgpqiqISoK orbMCePXPgl/y2Mwzy2umyBIHqlAseJMjN9AU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783932197; x=1784536997; 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=grKqIq319Vp7GavJNr9NRlJdcT2STtYLsl9rv45lrJw=; b=fGVI4WpdXSHdo/z5906nw9fQU5F3d4TMF5gqftFEywWZ8e25lqBVMx+vNsKwX0Va+w TewfCAbTJTr4qzytDRnwnJzoeyffwv1GNaFSRdmbcxXOOJPCFpV4jejO0oLmCukGO+lL Vb19FVFN9li6wD43FKG7Iwn6eENiwG1hdWWvyLJ4wI3og6ZEOFFGtkyfCv+4c2IC5LCb s65kzoWIpcJnB8PoZ1TQu2rKlodehnLBCY5spmwTBfLguPHnGq+Ar7JVgxe3ST4DD3x8 1pTa1HgL+IjMX5TyfEbB+MQTuZn5serRMmxD+z694eGKM7UZDhdSdusLChlRn7n/MBlz QPFw== X-Gm-Message-State: AOJu0Yzq7aaNY8IxFnt9+711dl3iDYgRsFd5Qfg7AftQrE9Cwauzd7YI BtHOoX38IUYI3DFzMZNd70PfZ6DTNZanQ+6jYdIksIUCYqa43yNi64JUmUkExawjvcq8EPuDi5W xZBh1oGndyQ== X-Gm-Gg: AfdE7cl+LKPRGKKJ9cQ0lAVM82OXuea5rpm63uOM3I1QXfbwXEc2e9A5l5egKa7ezj2 z6wqCRjqYEP8V7nvze/t/k0HgP8qd7w2e0uDwn5ccFzp7C+2XwbS6it+hjtvD0QKQHQceU5/RyX Z8M/SYa+NCvcwdMhll/W2iWk37OTQmpaOXF4hFwNlk/pEMSRVk04Wzc00ga1Y8AK5WT6Y4USwhE s4DKZIQuGe25M9vxHAh8kHr/AvQp5z2FNQyiI/D3KHP9flwm0noDmhjrAEAlBRn/z34L7CbtZRx 3OVklywQQlUzhjmxt5hroTRDggTIT/1B17e+ykmqCTKw+kKGG5B7fkswZAoi0t7qXZnlNrvLSrk ZpteEqc7e+dqeOjAj6HI0z5k6TVWHejAEps9hpuqF/9YSyq+eNzg7Te3mUFrRK26Za1CJbXiDBv 8g71jIK3umHnCbfTH9kyraF75Z72yJQSnt6Glwosc6WGLdg4dXO6WNaNsaFpAe41nvzYFWCJYL2 7Mq/1nUZz83 X-Received: by 2002:a05:600c:4ed0:b0:493:b3ba:84b4 with SMTP id 5b1f17b1804b1-493f882998cmr82963345e9.29.1783932197173; Mon, 13 Jul 2026 01:43:17 -0700 (PDT) From: Alexander Mikhalitsyn To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , Manos Pitsidianakis , "Michael S. Tsirkin" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , =?UTF-8?q?Volker=20R=C3=BCmelin?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?St=C3=A9phane=20Graber?= , Alexander Mikhalitsyn Subject: [PATCH v4 08/10] hw/audio/virtio-sound: introduce virtio_snd_pcm_open() Date: Mon, 13 Jul 2026 10:43:05 +0200 Message-ID: <20260713084307.79593-9-alexander@mihalicyn.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260713084307.79593-1-alexander@mihalicyn.com> References: <20260713084307.79593-1-alexander@mihalicyn.com> 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:20::336; envelope-from=alexander@mihalicyn.com; helo=mail-wm1-x336.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 @mihalicyn.com) X-ZM-MESSAGEID: 1783932282632158500 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 --- 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 9505e478e91..af50ab4c14a 100644 --- a/hw/audio/virtio-snd.c +++ b/hw/audio/virtio-snd.c @@ -428,6 +428,37 @@ static void virtio_snd_get_qemu_audsettings(audsetting= s *as, as->big_endian =3D false; /* Conforming to VIRTIO 1.0: always little e= ndian. */ } =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. * @@ -453,8 +484,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); @@ -473,30 +502,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 2.47.3 From nobody Sat Jul 25 22:03:30 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=quarantine dis=none) header.from=mihalicyn.com ARC-Seal: i=1; a=rsa-sha256; t=1783932244; cv=none; d=zohomail.com; s=zohoarc; b=mFaC0gChBRKG/cQ1zjqKqkm6PzHg4O9iE00aVE4Y6RByieNMfhRpgw3xswHtkQZTcYJJwWCyf3w6QxPJJCjKNl5Qaej8fdR7k/lN89UNyRmDhtM5dC5sm6FzDTvWzVo6oh8Ol49gfrcIdlNZ7qf+fHLO5PU+dh8YY1+Csl5+zv0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783932244; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Z40N7IFAqv4R1i4Jwz+zlPB/t3WRplA9W3n4ztoBvbo=; b=bH1Gpam0iKdjv9U45wYry1GjvrcKn1WFAFjLPlbjEong7J/g4IMZOdxnShwN/quOMV0HZuwHfe3O1So+xFyZyP8xJRLhvZnRQHPBcGWNkER9FEyio+kjAj8jN3+NCC4FZygycCDZYKdvKrN+8SCYHPn4vENafTi2UCBSZDHPwiQ= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1783932244721950.8293384873219; Mon, 13 Jul 2026 01:44:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjCG2-0004U9-Ok; Mon, 13 Jul 2026 04:43:22 -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 1wjCG1-0004RS-CZ for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:21 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wjCFz-0003Cd-K6 for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:21 -0400 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-4921eed3fa2so26741905e9.0 for ; Mon, 13 Jul 2026 01:43:19 -0700 (PDT) Received: from alex-laptop.lan (p200300cf574a7200912ca59176a42017.dip0.t-ipconnect.de. [2003:cf:574a:7200:912c:a591:76a4:2017]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493f2d97527sm287254815e9.2.2026.07.13.01.43.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 01:43:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mihalicyn.com; s=mihalicyn; t=1783932198; x=1784536998; 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=Z40N7IFAqv4R1i4Jwz+zlPB/t3WRplA9W3n4ztoBvbo=; b=HAyRcn03Ow+SkrVu9MbxQFEkM+L/6eANl6YK6Q4A9521+GzNRKL74PhPrRJUBGQfRr UOx2u79lwBvTtbesfJzVe9VC8Ubwf84gn3IPNTd5ZbY2wADkcPmalra/99WOqj0eK4hN WMuDqYUA5giNxYaqm/SHmHHCp2cSq3oCHpVds= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783932198; x=1784536998; 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=Z40N7IFAqv4R1i4Jwz+zlPB/t3WRplA9W3n4ztoBvbo=; b=jZMX6vk3m/0tApnm5CN7PQ5QzzZJKyUTl7ogLpc5ATy+wL0bs/OGi5Hrjoe/xzcdGq mrhXrXSzj/24XiImtVR0mVBJbWAmdSox15eGNc75j5/NvDAFXQ3p2Jr5k+CbIf6RBpWG rDDHv8eS9mby5kHfP0aZvyRKzfb4U5ti6r2E/LkvObWO3EauxFFf27xZmK6alUIxeL1Z o77bdxgBhnkVu9HE9FnlUn9vjls/fSk7kcUUgbpsff3XADi8k3g38GQwoftaws8ViR9r ecVzTHhv+WSpJa2e+TgiTiL/87b2uajr2W9Qvmu62aheLrMWaZxUqxDoGWZ7wjun5289 sE0g== X-Gm-Message-State: AOJu0YwQIX7cXdS8ScIFdh4al5zSXGqnF4TD40WJad18ODtOcePtsN+E iQfftZWxpqvXdZzsapPK+kFK4glW0bw88yNZaorZ3r1O0JF+wamdYuWgUj3Xm33JknREUUGgchp NS7lDDy7a1w== X-Gm-Gg: AfdE7cnC/OUkegweOA2Wjvh5ATpJEdfVvrWmHFKvXIYY6nOG6agBlJmdTBNFDPLV6on InCzVjtVoaoWOBWijt2Ke1yjxGP5WMPFJyWPENf0ukCTx+7kAqdx7uXDxdvFF3uunsmoNojBxq1 uYDEOLffD1IBhMNlo4+kmc9wDd5iXAMs64b35DAqoxBrd0Lfc1QKieDog+oh9CSqWzEtyybxjjZ oL5kT7zQFLiVJm8WhszRTbxK0ZC8kIos9uSpSZpeQFPavSFlz7qBEWK794GboKScOmgyyotnDhB 9touL7NsjQCF1sS6MVzWlRugTaEnXP9jjfLY0Tp8RlT+SaKgaKYWclT3z9l6DZNE1mJfrM6KL0K lNhr7xXi0SFGl7igcR9as9L5Ve2GwRRdeIjB2vD6eoM+JTTllqDrjJJ5LU9u4yyQ+2gzUKFyzvQ PQPA1LXANqUII2LuOto7OfnG5wl1Z6bENsK/icxnqS1LOCGqK7TASdtyuuk9XV5hM0EHtnxBB4j H96nFaIBXXLHs+nQgGtTA0= X-Received: by 2002:a05:600c:c042:b0:493:f7d9:8183 with SMTP id 5b1f17b1804b1-493f8834eb1mr54275495e9.39.1783932198081; Mon, 13 Jul 2026 01:43:18 -0700 (PDT) From: Alexander Mikhalitsyn To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , Manos Pitsidianakis , "Michael S. Tsirkin" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , =?UTF-8?q?Volker=20R=C3=BCmelin?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?St=C3=A9phane=20Graber?= , Alexander Mikhalitsyn Subject: [PATCH v4 09/10] hw/audio/virtio-sound: introduce virtio_snd_set_active() Date: Mon, 13 Jul 2026 10:43:06 +0200 Message-ID: <20260713084307.79593-10-alexander@mihalicyn.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260713084307.79593-1-alexander@mihalicyn.com> References: <20260713084307.79593-1-alexander@mihalicyn.com> 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:20::334; envelope-from=alexander@mihalicyn.com; helo=mail-wm1-x334.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 @mihalicyn.com) X-ZM-MESSAGEID: 1783932246471158500 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 --- 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 af50ab4c14a..5efedd6896a 100644 --- a/hw/audio/virtio-snd.c +++ b/hw/audio/virtio-snd.c @@ -459,6 +459,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. * @@ -605,11 +620,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 2.47.3 From nobody Sat Jul 25 22:03:30 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=quarantine dis=none) header.from=mihalicyn.com ARC-Seal: i=1; a=rsa-sha256; t=1783932292; cv=none; d=zohomail.com; s=zohoarc; b=P8Tl3EpbfG+LOE0/N/HDSrLb0cBKUBg2xEyK1eKVye+mcmAUtrFMpwWEaiA/W2zAcWGWASfBVAyomXqF7/HFys8RQh1er1SFB93OcxCBfYTJ5tvC1Xtk61tBm4dZbIakhv7vp/vSxFbBjlJ2OptzncMLOixO0VTQF2ZdGw/gCo0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1783932292; 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:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BpiGqXL48R6JF3fqQewK9hUyJ1JhTS7ckkKnhiB/cn8=; b=aWykm2iw/Dd7f4wH94Fjl80uvyRcclK9PPxzz/+Zsf4MH0x03eCK5UFwxG+vRLLbhXV7yNzMbXOdUY4hgsiWPxI9h2htDSY3lJeKLKK90dq/NI2VWcPsgPVsTnln4fN0ZvSb7lLKCH2V4I+NtUDGpRrbxMsQygW2vCr0xHJ0lUs= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17839322925931002.6290260817414; Mon, 13 Jul 2026 01:44:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjCG4-0004Vh-Ju; Mon, 13 Jul 2026 04:43: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 1wjCG2-0004UA-Nh for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:22 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wjCG0-0003Cn-PX for qemu-devel@nongnu.org; Mon, 13 Jul 2026 04:43:22 -0400 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-47f3e6cc44aso737593f8f.3 for ; Mon, 13 Jul 2026 01:43:20 -0700 (PDT) Received: from alex-laptop.lan (p200300cf574a7200912ca59176a42017.dip0.t-ipconnect.de. [2003:cf:574a:7200:912c:a591:76a4:2017]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493f2d97527sm287254815e9.2.2026.07.13.01.43.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 01:43:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mihalicyn.com; s=mihalicyn; t=1783932199; x=1784536999; 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=BpiGqXL48R6JF3fqQewK9hUyJ1JhTS7ckkKnhiB/cn8=; b=glGdYzYHkewzuRXYnYKPHnSPE9LVif8b58trhbSFpjqNckvGAMTSMLZ5CiWRUppJQM vj4YpXL4GiEX0VyxsSFY4fprFbTjIx7Pkt+wyj0DnQo0ppl5vBHGzDWcJmeKP53xJ7uB 1979JuXgrU1uziG+0NS3niQWnrJN75GzP/zYY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783932199; x=1784536999; 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=BpiGqXL48R6JF3fqQewK9hUyJ1JhTS7ckkKnhiB/cn8=; b=ZHzcWcY3IRq4lKjUVb5yj2BeTEVVEyyf0knp8eBxRK6PSlpTo+cfKCci79slAh6J78 aFqEeaJuDNt5ghzh9a9FPULGHHtFnkRocJ0sj3PMK7iwALsqF1KdJFoANXgbmwj3C68X 6RHeRHkM1Qx/KfXxogSQJidJp6M+GwvUfwAiAcM5u06Xs49aeZelleuJ6ljp61Otu0M0 Uti7NcljtVr/XS+1X3JUrxGhUKgM9sd5pm+3JOW9taHU01JJuF8NSEmUN4BiQJsLjWe7 ES/tG1wwAi8/NKUW41GahP1a286wy2yVjjKnmQWoJuJpygjpnxU4h7UEbDXAYmuaH3Ii bDJw== X-Gm-Message-State: AOJu0YyhMHGi+6mjnY7wmauE3szHr3yOZutBc5NVuKDOXKy3uCPeNOuY u2XNn3p9pIrbq+1Khw6NotVNv5YjXHNtYRsaKYKwgsPywFHanFVxMSbPYuzAmB+cW1XH3TCAwwl zbY+E7FLQ7A== X-Gm-Gg: AfdE7cl8GTCreea1h3viZ1ghAYbuEwMTtoAye50d2p4UiubjQ5MpTOZVNNabHqqlnp7 gbaAaKOlIeCXpOgf6m0DUhYkjO4fGGIWNRXGEjiyjRRJIiwmBqTtrz/saeUdwugnWlTdRjCPrNS R/21SXeAEX3RgChzLWloAccBMz1nQSZW+E2mui2xVN6WNlFki1qe0JpdmFo4nzIkhlvaW4qWlVY ijp84EHvUsCxRpBukurHO5WHxojAdXxQ2WAwUs/TrnPwcG3WRpIANXbQib4lA0JZVgjFU9Qj5wA a1Glx0fPdWQuFdtervGqHqBTg+BLQy7r1BbH/9L10apXXheo0uJg4u3MA+kCY1fW3YkKGIS0mXC jwj1fdJeediehjDwm+YCWUDtrEo4E2j9FM6wi2aJ/Y13LbT4T3B2HYIIkc1qiZhOWHOwBqbGAjc JFHPmdpUTxFp7XKNlj3yokdvZrJ/7q7laOs5BpU7W+GSGCJoszgrWRpgZkw7OQIkc0H/UYIT4tb ChMPCvtTcur X-Received: by 2002:a05:600c:154d:b0:493:e504:cbef with SMTP id 5b1f17b1804b1-493f8782509mr88420205e9.0.1783932199202; Mon, 13 Jul 2026 01:43:19 -0700 (PDT) From: Alexander Mikhalitsyn To: qemu-devel@nongnu.org Cc: Alexander Mikhalitsyn , Manos Pitsidianakis , "Michael S. Tsirkin" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Gerd Hoffmann , =?UTF-8?q?Volker=20R=C3=BCmelin?= , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?St=C3=A9phane=20Graber?= , Alexander Mikhalitsyn Subject: [PATCH v4 10/10] hw/audio/virtio-sound: add missing vmstate fields Date: Mon, 13 Jul 2026 10:43:07 +0200 Message-ID: <20260713084307.79593-11-alexander@mihalicyn.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260713084307.79593-1-alexander@mihalicyn.com> References: <20260713084307.79593-1-alexander@mihalicyn.com> 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:20::42f; envelope-from=alexander@mihalicyn.com; helo=mail-wr1-x42f.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 @mihalicyn.com) X-ZM-MESSAGEID: 1783932294810158500 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 --- v4: - added assert(. > 0) before decremeting s->queue_inuse[.] (suggested by Manos Pitsidianakis) v3: - added latency_bytes field to VMStateDescription As suggested by Marc-Andr=C3=A9 Lureau: - removed the "rc" variable from virtio_snd_post_load() - dropped info field from VMStateDescription, because it can't be modified by guest and initialized only from realize - added minimum_version_id/version_id so we can extend VMStateDescription without breaking compatibility in the future --- hw/audio/virtio-snd.c | 83 +++++++++++++++++++++++++++++++---- include/hw/audio/virtio-snd.h | 1 + 2 files changed, 76 insertions(+), 8 deletions(-) diff --git a/hw/audio/virtio-snd.c b/hw/audio/virtio-snd.c index 5efedd6896a..23b2e5e502e 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 @@ -73,17 +72,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() @@ -812,6 +834,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 @@ -858,6 +882,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; @@ -968,6 +993,7 @@ static void virtio_snd_handle_tx_xfer(VirtIODevice *vde= v, VirtQueue *vq) goto tx_err; } =20 + vsnd->queue_inuse[VIRTIO_SND_VQ_TX] +=3D 1; size =3D iov_size(elem->out_sg, elem->out_num) - msg_sz; =20 buffer =3D g_malloc0(sizeof(VirtIOSoundPCMBuffer) + size); @@ -1047,6 +1073,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; size =3D iov_size(elem->in_sg, elem->in_num) - sizeof(virtio_snd_pcm_status); buffer =3D g_malloc0(sizeof(VirtIOSoundPCMBuffer) + size); @@ -1188,6 +1215,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, @@ -1281,6 +1310,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, @@ -1399,6 +1430,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) { @@ -1430,6 +1492,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) @@ -1443,6 +1509,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; diff --git a/include/hw/audio/virtio-snd.h b/include/hw/audio/virtio-snd.h index 85d5d7c8619..384d2868c19 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; --=20 2.47.3