From: Takashi Iwai <tiwai@suse.de> To: Anton Yakovlev <anton.yakovlev@opensynergy.com> Cc: <virtualization@lists.linux-foundation.org>, <alsa-devel@alsa-project.org>, <virtio-dev@lists.oasis-open.org>, "Michael S. Tsirkin" <mst@redhat.com>, Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>, <linux-kernel@vger.kernel.org> Subject: Re: [PATCH v6 3/9] ALSA: virtio: handling control messages Date: Sun, 28 Feb 2021 12:04:41 +0100 [thread overview] Message-ID: <s5hv9acjvw6.wl-tiwai@suse.de> (raw) In-Reply-To: <20210227085956.1700687-4-anton.yakovlev@opensynergy.com> 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
WARNING: multiple messages have this Message-ID (diff)
From: Takashi Iwai <tiwai@suse.de> To: Anton Yakovlev <anton.yakovlev@opensynergy.com> Cc: virtio-dev@lists.oasis-open.org, alsa-devel@alsa-project.org, "Michael S. Tsirkin" <mst@redhat.com>, linux-kernel@vger.kernel.org, Takashi Iwai <tiwai@suse.com>, virtualization@lists.linux-foundation.org Subject: Re: [PATCH v6 3/9] ALSA: virtio: handling control messages Date: Sun, 28 Feb 2021 12:04:41 +0100 [thread overview] Message-ID: <s5hv9acjvw6.wl-tiwai@suse.de> (raw) In-Reply-To: <20210227085956.1700687-4-anton.yakovlev@opensynergy.com> 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
next prev parent reply other threads:[~2021-02-28 11:06 UTC|newest] Thread overview: 103+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-02-27 8:59 [PATCH v6 0/9] ALSA: add virtio sound driver Anton Yakovlev 2021-02-27 8:59 ` [virtio-dev] " Anton Yakovlev 2021-02-27 8:59 ` Anton Yakovlev 2021-02-27 8:59 ` [PATCH v6 1/9] uapi: virtio_ids: add a sound device type ID from OASIS spec Anton Yakovlev 2021-02-27 8:59 ` [virtio-dev] " Anton Yakovlev 2021-02-27 8:59 ` Anton Yakovlev 2021-02-27 8:59 ` Anton Yakovlev 2021-02-27 8:59 ` [PATCH v6 2/9] ALSA: virtio: add virtio sound driver Anton Yakovlev 2021-02-27 8:59 ` [virtio-dev] " Anton Yakovlev 2021-02-27 8:59 ` Anton Yakovlev 2021-02-27 8:59 ` Anton Yakovlev 2021-02-27 8:59 ` [PATCH v6 3/9] ALSA: virtio: handling control messages Anton Yakovlev 2021-02-27 8:59 ` [virtio-dev] " Anton Yakovlev 2021-02-27 8:59 ` Anton Yakovlev 2021-02-27 8:59 ` Anton Yakovlev 2021-02-28 11:04 ` Takashi Iwai [this message] 2021-02-28 11:04 ` Takashi Iwai 2021-02-28 18:39 ` Anton Yakovlev 2021-02-28 18:39 ` [virtio-dev] " Anton Yakovlev 2021-02-28 18:39 ` Anton Yakovlev 2021-02-28 18:39 ` Anton Yakovlev 2021-02-27 8:59 ` [PATCH v6 4/9] ALSA: virtio: build PCM devices and substream hardware descriptors Anton Yakovlev 2021-02-27 8:59 ` [virtio-dev] " Anton Yakovlev 2021-02-27 8:59 ` Anton Yakovlev 2021-02-27 8:59 ` Anton Yakovlev 2021-02-28 11:15 ` Takashi Iwai 2021-02-28 11:15 ` Takashi Iwai 2021-02-27 8:59 ` [PATCH v6 5/9] ALSA: virtio: handling control and I/O messages for the PCM device Anton Yakovlev 2021-02-27 8:59 ` [virtio-dev] " Anton Yakovlev 2021-02-27 8:59 ` Anton Yakovlev 2021-02-27 8:59 ` Anton Yakovlev 2021-02-28 11:27 ` Takashi Iwai 2021-02-28 11:27 ` Takashi Iwai 2021-03-01 9:25 ` Anton Yakovlev 2021-03-01 9:25 ` [virtio-dev] " Anton Yakovlev 2021-03-01 9:25 ` Anton Yakovlev 2021-03-01 9:25 ` Anton Yakovlev 2021-03-01 13:32 ` Takashi Iwai 2021-03-01 13:32 ` Takashi Iwai 2021-03-01 14:47 ` Anton Yakovlev 2021-03-01 14:47 ` [virtio-dev] " Anton Yakovlev 2021-03-01 14:47 ` Anton Yakovlev 2021-03-01 14:47 ` Anton Yakovlev 2021-03-01 14:56 ` Takashi Iwai 2021-03-01 14:56 ` Takashi Iwai 2021-03-01 15:24 ` Anton Yakovlev 2021-03-01 15:24 ` [virtio-dev] " Anton Yakovlev 2021-03-01 15:24 ` Anton Yakovlev 2021-03-01 15:24 ` Anton Yakovlev 2021-03-01 15:30 ` Takashi Iwai 2021-03-01 15:30 ` Takashi Iwai 2021-02-27 8:59 ` [PATCH v6 6/9] ALSA: virtio: PCM substream operators Anton Yakovlev 2021-02-27 8:59 ` [virtio-dev] " Anton Yakovlev 2021-02-27 8:59 ` Anton Yakovlev 2021-02-27 8:59 ` Anton Yakovlev 2021-02-28 11:32 ` Takashi Iwai 2021-02-28 11:32 ` Takashi Iwai 2021-03-01 9:29 ` Anton Yakovlev 2021-03-01 9:29 ` [virtio-dev] " Anton Yakovlev 2021-03-01 9:29 ` Anton Yakovlev 2021-03-01 9:29 ` Anton Yakovlev 2021-03-01 13:33 ` Takashi Iwai 2021-03-01 13:33 ` Takashi Iwai 2021-02-27 8:59 ` [PATCH v6 7/9] ALSA: virtio: introduce jack support Anton Yakovlev 2021-02-27 8:59 ` [virtio-dev] " Anton Yakovlev 2021-02-27 8:59 ` Anton Yakovlev 2021-02-27 8:59 ` Anton Yakovlev 2021-02-27 8:59 ` [PATCH v6 8/9] ALSA: virtio: introduce PCM channel map support Anton Yakovlev 2021-02-27 8:59 ` [virtio-dev] " Anton Yakovlev 2021-02-27 8:59 ` Anton Yakovlev 2021-02-27 8:59 ` Anton Yakovlev 2021-02-27 8:59 ` [PATCH v6 9/9] ALSA: virtio: introduce device suspend/resume support Anton Yakovlev 2021-02-27 8:59 ` [virtio-dev] " Anton Yakovlev 2021-02-27 8:59 ` Anton Yakovlev 2021-02-27 8:59 ` Anton Yakovlev 2021-02-28 12:05 ` Takashi Iwai 2021-02-28 12:05 ` Takashi Iwai 2021-03-01 10:03 ` Anton Yakovlev 2021-03-01 10:03 ` [virtio-dev] " Anton Yakovlev 2021-03-01 10:03 ` Anton Yakovlev 2021-03-01 10:03 ` Anton Yakovlev 2021-03-01 13:38 ` Takashi Iwai 2021-03-01 13:38 ` Takashi Iwai 2021-03-01 15:30 ` Anton Yakovlev 2021-03-01 15:30 ` [virtio-dev] " Anton Yakovlev 2021-03-01 15:30 ` Anton Yakovlev 2021-03-01 15:30 ` Anton Yakovlev 2021-03-02 6:29 ` Anton Yakovlev 2021-03-02 6:29 ` [virtio-dev] " Anton Yakovlev 2021-03-02 6:29 ` Anton Yakovlev 2021-03-02 6:29 ` Anton Yakovlev 2021-03-02 6:48 ` Takashi Iwai 2021-03-02 6:48 ` Takashi Iwai 2021-03-02 8:09 ` Anton Yakovlev 2021-03-02 8:09 ` [virtio-dev] " Anton Yakovlev 2021-03-02 8:09 ` Anton Yakovlev 2021-03-02 8:09 ` Anton Yakovlev 2021-03-02 9:11 ` Takashi Iwai 2021-03-02 9:11 ` Takashi Iwai 2021-03-02 15:35 ` Anton Yakovlev 2021-03-02 15:35 ` [virtio-dev] " Anton Yakovlev 2021-03-02 15:35 ` Anton Yakovlev 2021-03-02 15:35 ` Anton Yakovlev
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=s5hv9acjvw6.wl-tiwai@suse.de \ --to=tiwai@suse.de \ --cc=alsa-devel@alsa-project.org \ --cc=anton.yakovlev@opensynergy.com \ --cc=linux-kernel@vger.kernel.org \ --cc=mst@redhat.com \ --cc=perex@perex.cz \ --cc=tiwai@suse.com \ --cc=virtio-dev@lists.oasis-open.org \ --cc=virtualization@lists.linux-foundation.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.