From: Asias He <asias@redhat.com>
To: Amit Shah <amit.shah@redhat.com>
Cc: Virtualization List <virtualization@lists.linux-foundation.org>
Subject: Re: [PATCH 2/2] virtio: console: add locking around c_ovq operations
Date: Fri, 29 Mar 2013 08:29:01 +0800 [thread overview]
Message-ID: <20130329002901.GA22450@hj.localdomain> (raw)
In-Reply-To: <7020cea46a2e01d7205e6af0faffcebbed032003.1364469955.git.amit.shah@redhat.com>
On Thu, Mar 28, 2013 at 04:58:33PM +0530, Amit Shah wrote:
> When multiple ovq operations are being performed (lots of open/close
> operations on virtio_console fds), the __send_control_msg() function can
> get confused without locking.
>
> A simple recipe to cause badness is:
> * create a QEMU VM with two virtio-serial ports
> * in the guest, do
> while true;do echo abc >/dev/vport0p1;done
> while true;do echo edf >/dev/vport0p2;done
>
> In one run, this caused a panic in __send_control_msg(). In another, I
> got
>
> virtio_console virtio0: control-o:id 0 is not a head!
>
> This also results repeated messages similar to these on the host:
>
> qemu-kvm: virtio-serial-bus: Unexpected port id 478762112 for device virtio-serial-bus.0
> qemu-kvm: virtio-serial-bus: Unexpected port id 478762368 for device virtio-serial-bus.0
>
> Reported-by: FuXiangChun <xfu@redhat.com>
> Signed-off-by: Amit Shah <amit.shah@redhat.com>
So, probably this will not apply on virtio-next because of the
virtqueue_add_outbuf change.
Anyway, Reviewed-by: Asias He <asias@redhat.com>
> ---
> drivers/char/virtio_console.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
> index 7e9bc1d..410866c 100644
> --- a/drivers/char/virtio_console.c
> +++ b/drivers/char/virtio_console.c
> @@ -150,6 +150,7 @@ struct ports_device {
>
> /* To protect the vq operations for the control channel */
> spinlock_t c_ivq_lock;
> + spinlock_t c_ovq_lock;
>
> /* The current config space is stored here */
> struct virtio_console_config config;
> @@ -569,11 +570,14 @@ static ssize_t __send_control_msg(struct ports_device *portdev, u32 port_id,
> vq = portdev->c_ovq;
>
> sg_init_one(sg, &cpkt, sizeof(cpkt));
> +
> + spin_lock_irq(&portdev->c_ovq_lock);
> if (virtqueue_add_buf(vq, sg, 1, 0, &cpkt, GFP_ATOMIC) == 0) {
> virtqueue_kick(vq);
> while (!virtqueue_get_buf(vq, &len))
> cpu_relax();
> }
> + spin_unlock_irq(&portdev->c_ovq_lock);
> return 0;
> }
>
> @@ -1987,6 +1991,7 @@ static int virtcons_probe(struct virtio_device *vdev)
> unsigned int nr_added_bufs;
>
> spin_lock_init(&portdev->c_ivq_lock);
> + spin_lock_init(&portdev->c_ovq_lock);
> INIT_WORK(&portdev->control_work, &control_work_handler);
>
> nr_added_bufs = fill_queue(portdev->c_ivq,
> --
> 1.8.1.4
>
> _______________________________________________
> Virtualization mailing list
> Virtualization@lists.linux-foundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/virtualization
--
Asias
next prev parent reply other threads:[~2013-03-29 0:29 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-28 11:28 [PATCH 0/2] virtio: console: add locking around control out-vq Amit Shah
2013-03-28 11:28 ` [PATCH 1/2] virtio: console: rename cvq_lock to c_ivq_lock Amit Shah
2013-03-29 0:30 ` Asias He
2013-03-29 0:56 ` Wanlong Gao
2013-03-28 11:28 ` [PATCH 2/2] virtio: console: add locking around c_ovq operations Amit Shah
2013-03-29 0:29 ` Asias He [this message]
2013-03-29 11:00 ` Amit Shah
2013-03-29 0:57 ` Wanlong Gao
2013-03-29 10:39 ` Amit Shah
2013-03-29 0:38 ` [PATCH 0/2] virtio: console: add locking around control out-vq Asias He
2013-03-29 10:35 ` Amit Shah
2013-04-01 2:35 ` Asias He
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=20130329002901.GA22450@hj.localdomain \
--to=asias@redhat.com \
--cc=amit.shah@redhat.com \
--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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox