From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D10FC433E0 for ; Sun, 28 Feb 2021 11:05:41 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4710D64DBD for ; Sun, 28 Feb 2021 11:05:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4710D64DBD Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 427881660; Sun, 28 Feb 2021 12:04:47 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 427881660 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1614510337; bh=hDttNxuUfi1CdRuWh4EDJzq9IDHiwhQq4PC1MM5eJYY=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=CVcSkbJXWQgqAsD6pow4U7hQ6EhuXgTG/QsQ9pwlQeHk29WXuC3fsLOaczP9HkBHK NJJ5OoYXPxXchc/xFj/QFmPLGVYb9npkJQbv+CXdW3/xNPYfzNRmrcGBHmn66m3taA JuWqe+SMplIMnkdz6pPleQFkC7zOepwOwm96v3o8= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id AEDEBF80227; Sun, 28 Feb 2021 12:04:46 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 3DEF6F8025B; Sun, 28 Feb 2021 12:04:45 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id DD4ECF8010B for ; Sun, 28 Feb 2021 12:04:42 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz DD4ECF8010B 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 0BF60AB7D; Sun, 28 Feb 2021 11:04:42 +0000 (UTC) Date: Sun, 28 Feb 2021 12:04:41 +0100 Message-ID: From: Takashi Iwai To: Anton Yakovlev Subject: Re: [PATCH v6 3/9] ALSA: virtio: handling control messages In-Reply-To: <20210227085956.1700687-4-anton.yakovlev@opensynergy.com> References: <20210227085956.1700687-1-anton.yakovlev@opensynergy.com> <20210227085956.1700687-4-anton.yakovlev@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 Cc: virtio-dev@lists.oasis-open.org, alsa-devel@alsa-project.org, "Michael S. Tsirkin" , linux-kernel@vger.kernel.org, Takashi Iwai , virtualization@lists.linux-foundation.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Sat, 27 Feb 2021 09:59:50 +0100, Anton Yakovlev wrote: > > --- a/sound/virtio/virtio_card.c > +++ b/sound/virtio/virtio_card.c > @@ -11,6 +11,10 @@ > > #include "virtio_card.h" > > +int msg_timeout_ms = MSEC_PER_SEC; > +module_param(msg_timeout_ms, int, 0644); > +MODULE_PARM_DESC(msg_timeout_ms, "Message completion timeout in milliseconds"); If it's a global variable, better to set a prefix to make it unique, and use module_param_named(). And, it should be unsigned int, no? (unless a negative value has any meaning) Otherwise... > + if (!msg_timeout_ms) { > + dev_err(&vdev->dev, "msg_timeout_ms value cannot be zero\n"); > + return -EINVAL; Here a negative value would pass. (snip) > +int virtsnd_ctl_msg_send(struct virtio_snd *snd, struct virtio_snd_msg *msg, > + struct scatterlist *out_sgs, > + struct scatterlist *in_sgs, bool nowait) > +{ > + struct virtio_device *vdev = snd->vdev; > + struct virtio_snd_queue *queue = virtsnd_control_queue(snd); > + unsigned int js = msecs_to_jiffies(msg_timeout_ms); > + struct virtio_snd_hdr *request = virtsnd_ctl_msg_request(msg); > + struct virtio_snd_hdr *response = virtsnd_ctl_msg_response(msg); > + unsigned int nouts = 0; > + unsigned int nins = 0; > + struct scatterlist *psgs[4]; > + bool notify = false; > + unsigned long flags; > + int rc; > + > + virtsnd_ctl_msg_ref(msg); > + > + /* Set the default status in case the message was canceled. */ > + response->code = cpu_to_le32(VIRTIO_SND_S_IO_ERR); > + > + psgs[nouts++] = &msg->sg_request; > + if (out_sgs) > + psgs[nouts++] = out_sgs; > + > + psgs[nouts + nins++] = &msg->sg_response; > + if (in_sgs) > + psgs[nouts + nins++] = in_sgs; > + > + spin_lock_irqsave(&queue->lock, flags); > + rc = virtqueue_add_sgs(queue->vqueue, psgs, nouts, nins, msg, > + GFP_ATOMIC); It's a bit pity that we have to use GFP_ATOMIC always here... As long as it's in spinlock, it's the only way. However, this reminds me of another question: may the virtio event be handled in an atomic context, e.g. the period elapsed or xrun events? If so, the current implementation with non-atomic PCM mode is wrong. Since the non-atomic PCM uses mutex instead of spinlock, it'll lead to a sleep-in-atomic in snd_pcm_period_elapsed() handling. I suggested the non-atomic PCM *iff* the all contexts are sleepable; then the sync can be done in each callback, which makes the code much simpler usually. But you've already implemented the sync via sync_stop call, hence the non-atomic PCM has little benefit by its own. thanks, Takashi