Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2495172pxb; Sun, 28 Feb 2021 03:13:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJxkP3I2GwFVlwJ2svyZs8SU/9VjTtBrZJbljcmTk8BociAuhjRwHm1kwbjpKvD7p/XVl+CI X-Received: by 2002:a50:bec3:: with SMTP id e3mr11586660edk.290.1614510792397; Sun, 28 Feb 2021 03:13:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614510792; cv=none; d=google.com; s=arc-20160816; b=d9EPDDPqBHxjMolFmh/H+qRINs3yehKAgY0Pb7eQv4DgNIAp8066fjzduenRNgGDns tL4vYzADzcOdV2cOysS+yzBOhHFbQb+XE9/klMYpI7G+WN/+k+ZHY+jBkV9nvYEGQ9tb k/kne6G7BDLr1n67CDZe4ObCfJLpQRxenj7lseR+OE0UI2n+fvikoDNUDKhwCRF0E8uK vbR5urOXVi9/y7999mvoQ3bHQ9mYeYWCeHGOuLQG6rqYOBSJva46z7erVNWoxDwxBjGW KzJGmMZkKXKKJDXfLo+Qr03p1KdBElY9yCNbWvcGtdkAmmddKO7eVvS31z3JP5w7ikVe v+9g== 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=u+dscHieELrtU7zWFLOWpFwNEi17183vRpC/rtHiXSc=; b=KTnRB1eXp9DOaSLzRZGwVDBYqTEDEjLI3IYiwxKWXFE9xVCcRxGc373bhSnRP57/VW 8sVQ50qYUMFeSArtdMzmzpNpRehiwJx8EAPdZpYunYm3cHM1KeDJcwUlzcdLpj2kgt7q IrkiC4Ja3kFu6NZcY9d9lSyt3RL8/jrpAKFlPYVmC7E8zN2gikjvydYCtn8fR7sUGuyN SadCN8HBdtUOibIsPvnI6+6mViGfpWHjvh5eLE0cObxx4TqS3VzNfFeKHAx1+ZmZ8EpT 18tpaF1gXMcWBchDYrIRa/T1NQHSO6vY8iWzKDYUZH+OLDcm6s3saDa1amdPcnY7ZeGN zFoQ== 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 y8si8882710edw.240.2021.02.28.03.12.37; Sun, 28 Feb 2021 03:13:12 -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 S230402AbhB1LFk (ORCPT + 99 others); Sun, 28 Feb 2021 06:05:40 -0500 Received: from mx2.suse.de ([195.135.220.15]:37454 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230019AbhB1LFk (ORCPT ); Sun, 28 Feb 2021 06:05:40 -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 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 Cc: , , , "Michael S. Tsirkin" , Jaroslav Kysela , Takashi Iwai , 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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