Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3124711pxb; Mon, 1 Mar 2021 02:08:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJwZTa+bc2AIhgrH4RQwBmS2DZDlCrwX1w8OQVy5SgmXTJSyOxREi2YWc5+CpN+xzkEBjgRF X-Received: by 2002:a50:ef0a:: with SMTP id m10mr14563960eds.261.1614593313754; Mon, 01 Mar 2021 02:08:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614593313; cv=none; d=google.com; s=arc-20160816; b=x4u0mEFH3ekpLI6DKqQq1YJCpopfYB5v20IumvUp7b5JO6IogcnBPYuturQW0GjFar 9X/H1/Z0vcR13bHpvxad8TyUWPL2Sm5YU9x3TdaFcGC/tPKSXDIMAJgjoNxFJJp9lzXh N3Lk1aLQKKzS2QC+MPD7lLhrO6xC7V6ddfZVfm9v5ZIP4PlWPIJGhTONP19K7ihAYf0n I60F6d4siHosXJSo3LLAR1JgWU/K+IcbHWlW30ps6nFlUl/lS0sCCA9Ur17fXoJdQqmL sfGAg1UmgzU2SM2AYvfCHfm7aI3MGIHQqCut0aakmn8R4XmB3Zac4a2bRFKEHkYdJHxj zHVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:date:message-id:from:references:cc:to :subject:dkim-signature; bh=TYThy1gXWt2NGLWZE4+BNvfDquT8rOEI1kVicn0HVsg=; b=jnUNbxAMPS1UqeosPMykhWCWvUgS3+2wnCJlm8iNg1+fBm2qcp2nfCqlOWq4ojdUeD YkqZA6cRUfQL0zV0dZ5XLqFx/RW++Lp5xLjuOFE6Uvpr0germxrPhcvg6gcamIDBctdG 0+fgpWkbghO7NUYlDO7Wv0qg4QT2MMtvypvROb4/kP/br8UwWiqf3kUyc+qSyM8yW4nY 8OzwDwAlC97l5d3V2AjFq+bAbt2iiQyhnxdFvUSJKgDgh+00QdD44MjsipKMkRuTk1Vi 2GqznTd6x+E+lCe1MboIoVSGo5qF3yQoPkL6fa3jOIz61VeGUHA57tH0nCFVi3/MIRMd 5CxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@opensynergy.com header.s=srmailgate02 header.b=y+hHA5oy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=opensynergy.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r16si11076884ejc.439.2021.03.01.02.08.10; Mon, 01 Mar 2021 02:08:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@opensynergy.com header.s=srmailgate02 header.b=y+hHA5oy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=opensynergy.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231785AbhCAKGB (ORCPT + 99 others); Mon, 1 Mar 2021 05:06:01 -0500 Received: from mx1.opensynergy.com ([217.66.60.4]:17017 "EHLO mx1.opensynergy.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231830AbhCAKD6 (ORCPT ); Mon, 1 Mar 2021 05:03:58 -0500 Received: from SR-MAILGATE-02.opensynergy.com (localhost.localdomain [127.0.0.1]) by mx1.opensynergy.com (Proxmox) with ESMTP id 84EF2A1344; Mon, 1 Mar 2021 11:03:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=opensynergy.com; h=cc:cc:content-transfer-encoding:content-type:content-type :date:from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=srmailgate02; bh=TYThy1gXWt2N GLWZE4+BNvfDquT8rOEI1kVicn0HVsg=; b=y+hHA5oyvhs9pArzHttMuyoKdxP1 Fwlbcir93mQ/6UUIuo+Ic+uw7QoZBRETjmBckBQT2dbKzSu1eTdQmrf8S6/mpmv7 mMEIknuE/CU/jezBM/VLDdDgSqiCggLP8iPwWnLfGBPLAlIg8vdsqEjjrqn8p9wY yvZLGk+qhwhmzvATxARQSyAPebd142F+ve1d0HyZ+q09n4HzhZ/lRy/Lgwxj6wB/ aBwAkiW6/G3XqPE4DgEWh5V5dpfd5LA6IfwyJhUnHfwIKObPXChG5vsWdjBNNV1h d7BogU8h562dy0T9lSWv6/M+agyifUWIv/XhelwNk/RYqwbsZ7QttVLNhg== Subject: Re: [PATCH v6 9/9] ALSA: virtio: introduce device suspend/resume support To: Takashi Iwai CC: , , , "Michael S. Tsirkin" , Jaroslav Kysela , Takashi Iwai , References: <20210227085956.1700687-1-anton.yakovlev@opensynergy.com> <20210227085956.1700687-10-anton.yakovlev@opensynergy.com> From: Anton Yakovlev Message-ID: <54854cb9-99c3-4c05-3b43-f41d89a29aec@opensynergy.com> Date: Mon, 1 Mar 2021 11:03:04 +0100 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-01.open-synergy.com (10.26.10.21) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 28.02.2021 13:05, Takashi Iwai wrote: > On Sat, 27 Feb 2021 09:59:56 +0100, > Anton Yakovlev wrote: >> >> All running PCM substreams are stopped on device suspend and restarted >> on device resume. >> >> Signed-off-by: Anton Yakovlev >> --- >> sound/virtio/virtio_card.c | 56 +++++++++++++++++++++++++++++++++++ >> sound/virtio/virtio_pcm.c | 1 + >> sound/virtio/virtio_pcm_ops.c | 41 ++++++++++++++++++++----- >> 3 files changed, 90 insertions(+), 8 deletions(-) >> >> diff --git a/sound/virtio/virtio_card.c b/sound/virtio/virtio_card.c >> index 59455a562018..c7ae8801991d 100644 >> --- a/sound/virtio/virtio_card.c >> +++ b/sound/virtio/virtio_card.c >> @@ -323,6 +323,58 @@ static void virtsnd_remove(struct virtio_device *vdev) >> kfree(snd->event_msgs); >> } >> >> +#ifdef CONFIG_PM_SLEEP >> +/** >> + * virtsnd_freeze() - Suspend device. >> + * @vdev: VirtIO parent device. >> + * >> + * Context: Any context. >> + * Return: 0 on success, -errno on failure. >> + */ >> +static int virtsnd_freeze(struct virtio_device *vdev) >> +{ >> + struct virtio_snd *snd = vdev->priv; >> + >> + virtsnd_ctl_msg_cancel_all(snd); >> + >> + vdev->config->del_vqs(vdev); >> + vdev->config->reset(vdev); >> + >> + kfree(snd->event_msgs); >> + >> + /* >> + * If the virtsnd_restore() fails before re-allocating events, then we >> + * get a dangling pointer here. >> + */ >> + snd->event_msgs = NULL; >> + >> + return 0; > > I suppose some cancel of inflight works is needed? > Ditto for the device removal, too. It's not necessary here, since the device is reset and all of this are happened automatically. But in the device remove it makes sense also to disable events before calling snd_card_free(), since the device is still able to send notifications at that moment. Thanks! >> --- a/sound/virtio/virtio_pcm.c >> +++ b/sound/virtio/virtio_pcm.c >> @@ -109,6 +109,7 @@ static int virtsnd_pcm_build_hw(struct virtio_pcm_substream *vss, >> SNDRV_PCM_INFO_BATCH | >> SNDRV_PCM_INFO_BLOCK_TRANSFER | >> SNDRV_PCM_INFO_INTERLEAVED | >> + SNDRV_PCM_INFO_RESUME | >> SNDRV_PCM_INFO_PAUSE; > > Actually you don't need to set SNDRV_PCM_INFO_RESUME. > This flag means that the driver supports the full resume procedure, > which isn't often the case; with this, the driver is supposed to > resume the stream exactly from the suspended position. If I understood you right, that's exactly how resume is implemented now in the driver. Although we fully restart substream on the device side, from an application point of view it is resumed exactly at the same position. > Most drivers don't set this but implement only the suspend-stop > action. Then the application (or the sound backend) will re-setup the > stream and restart accordingly. And an application must be aware of such possible situation? Since I have no doubt in alsa-lib, but I don't think that for example tinyalsa can handle this right. >> @@ -309,6 +318,21 @@ static int virtsnd_pcm_trigger(struct snd_pcm_substream *substream, int command) >> int rc; >> >> switch (command) { >> + case SNDRV_PCM_TRIGGER_RESUME: { >> + /* >> + * We restart the substream by executing the standard command >> + * sequence. >> + */ >> + rc = virtsnd_pcm_hw_params(substream, NULL); >> + if (rc) >> + return rc; >> + >> + rc = virtsnd_pcm_prepare(substream); >> + if (rc) >> + return rc; > > And this won't work at all unless nonatomic PCM ops. > > > thanks, > > Takashi > -- Anton Yakovlev Senior Software Engineer OpenSynergy GmbH Rotherstr. 20, 10245 Berlin