Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp96242pxb; Tue, 2 Mar 2021 20:36:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJw36iPiUkMKpalE83gRYFpFnt6KAi5QqrnmjwUWdyHFamOa7nkXoGGO+YmbGT9RGjWWmh2S X-Received: by 2002:a17:906:6487:: with SMTP id e7mr23919392ejm.181.1614746178475; Tue, 02 Mar 2021 20:36:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614746178; cv=none; d=google.com; s=arc-20160816; b=M/5HgaO9bj1/3/ozhAkuJp2kLTRmbc/mVlMU7dOEkFvYrK/spodI8mOD9diqmDiRBw EyJwUKjKmA/ZLV/X9SwNfTod+8irmjOETxwJe8mcdmLaVYTUCaEaf7oFDuhW465iNuM8 5O7kexQS2HdbRhTmMfusOY6qe6xHP+f5SXaXSwG897WOuU6CfZ5hEf8cEpRV2cW8vLGS rjnoZ+2eHkKbHD+but9Od0xTxUBgRTnFgbZHfD0B6uDCI+Y29HawobmxhSTFObBzjqUi h4Mw1lPT7hNiCPYhQk68rOAs2AyW1e8vLZKKvg5bofutv8hlLz8BThPDPdXGA2U5N+fq rBxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date; bh=L2I0rlVFaJPLFN82tcepRhFaZEzzcZJxYz3uQcsVOTg=; b=eqjx7XEi4JP8/2Iw1UHeryzeQoAmP/JdVviojQduoAHDdXCywPKm6iECv8rKKVWDCz 7zRvDidgQLrKpe3aapwNggAvFwUFrbqdVX0IkK0UZkGv7tov+mrvm1A4QGFULCrUXtlR iFBam6oz/3xyfxmAyEwde1uiCXDHJNJXvKdn/5yZe7qWwld2jRMY1xAgraOGUmLVCaAM +r6fFnyTBumu6vFsO7ZaIH5x1XYEt0XRPrm1XcU8bJarlbbb73v9c8ESKFfBE++P/Gn7 epZv0ZyqCJPVfV439uMg+mv52A0vkLxBMd69gOgVne24yN4UctAVNIdDM1HJPWnBT4Zc q1UA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cf25si14455082ejb.636.2021.03.02.20.35.56; Tue, 02 Mar 2021 20:36:18 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237041AbhCAPbe (ORCPT + 99 others); Mon, 1 Mar 2021 10:31:34 -0500 Received: from mx2.suse.de ([195.135.220.15]:44502 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237231AbhCAPbS (ORCPT ); Mon, 1 Mar 2021 10:31:18 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 6387FAF54; Mon, 1 Mar 2021 15:30:36 +0000 (UTC) Date: Mon, 01 Mar 2021 16:30:36 +0100 Message-ID: From: Takashi Iwai To: Anton Yakovlev Cc: , , , "Michael S. Tsirkin" , Jaroslav Kysela , Takashi Iwai , Subject: Re: [PATCH v6 5/9] ALSA: virtio: handling control and I/O messages for the PCM device In-Reply-To: References: <20210227085956.1700687-1-anton.yakovlev@opensynergy.com> <20210227085956.1700687-6-anton.yakovlev@opensynergy.com> <85bbc067-e7ec-903a-1518-5aab01577655@opensynergy.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 01 Mar 2021 16:24:00 +0100, Anton Yakovlev wrote: > > On 01.03.2021 15:56, Takashi Iwai wrote: > > On Mon, 01 Mar 2021 15:47:46 +0100, > > Anton Yakovlev wrote: > >> > >> On 01.03.2021 14:32, Takashi Iwai wrote: > >>> On Mon, 01 Mar 2021 10:25:05 +0100, > >>> Anton Yakovlev wrote: > >>>> > >>>> On 28.02.2021 12:27, Takashi Iwai wrote: > >>>>> On Sat, 27 Feb 2021 09:59:52 +0100, > >>>>> Anton Yakovlev wrote: > >>>>>> +/** > >>>>>> + * virtsnd_pcm_event() - Handle the PCM device event notification. > >>>>>> + * @snd: VirtIO sound device. > >>>>>> + * @event: VirtIO sound event. > >>>>>> + * > >>>>>> + * Context: Interrupt context. > >>>>> > >>>>> OK, then nonatomic PCM flag is invalid... > >>>> > >>>> Well, no. Here, events are kind of independent entities. PCM-related > >>>> events are just a special case of more generic events, which can carry > >>>> any kind of notification/payload. (And at the moment, only XRUN > >>>> notification is supported for PCM substreams.) So it has nothing to do > >>>> with the atomicity of the PCM device itself. > >>> > >>> OK, thanks. > >>> > >>> Basically the only question is how snd_pcm_period_elapsed() is called. > >>> And I see that it's called inside queue->lock, and this already > >>> invalidates the nonatomic PCM mode. So the code needs the fix: either > >>> fix this locking (and the context is guaranteed not to be an irq > >>> context), or change to the normal PCM mode without nonatomic flag. > >>> Both would bring some side-effect, and we need further changes, I > >>> suppose... > >> > >> Ok, I understood the problem. Well, I would say the nonatomic PCM mode > >> is more important option, since in this mode we can guarantee the > >> correct operation of the device. > > > > Which operation (except for the resume) in the trigger and the pointer > > callbacks need the action that need to sleep? I thought the sync with > > the command queue is done in the sync_stop. And most of others seem > > already taking the spinlock in themselves, so the non-atomic operation > > has little merit for them. > > All three commands from the beginning of that switch in trigger op: > ops->trigger(START) > ops->trigger(PAUSE_RELEASE) > ops->trigger(RESUME) > > They all result in > virtsnd_ctl_msg_send_sync(VIRTIO_SND_R_PCM_START) > > And that command must be sync, i.e. we need to wait/sleep until device > sent response. There are two major reasons for that: we need to be sure, > that substream has been actually started (i.e. device said OK). And we > need to take into account the virtualization overhead as well. Since > substream starting on device side may take some time, we can not > return from the trigger op until it actually happened. In atomic mode > all these nuances are lost, and it may lead to incorrect application > behavior. I see, then the nonatomic mode is the only way to go, indeed. Takashi