提交 531295e6 编写于 作者: A Amit Shah 提交者: Linus Torvalds

virtio: console: Don't block entire guest if host doesn't read data

If the host is slow in reading data or doesn't read data at all,
blocking write calls not only blocked the program that called write()
but the entire guest itself.

To overcome this, let's not block till the host signals it has given
back the virtio ring element we passed it.  Instead, send the buffer to
the host and return to userspace.  This operation then becomes similar
to how non-blocking writes work, so let's use the existing code for this
path as well.

This code change also ensures blocking write calls do get blocked if
there's not enough room in the virtio ring as well as they don't return
-EAGAIN to userspace.
Signed-off-by: NAmit Shah <amit.shah@redhat.com>
Acked-by: NHans de Goede <hdegoede@redhat.com>
CC: stable@kernel.org
Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 30c27819
...@@ -459,9 +459,12 @@ static ssize_t send_buf(struct port *port, void *in_buf, size_t in_count, ...@@ -459,9 +459,12 @@ static ssize_t send_buf(struct port *port, void *in_buf, size_t in_count,
/* /*
* Wait till the host acknowledges it pushed out the data we * Wait till the host acknowledges it pushed out the data we
* sent. This is done for ports in blocking mode or for data * sent. This is done for data from the hvc_console; the tty
* from the hvc_console; the tty operations are performed with * operations are performed with spinlocks held so we can't
* spinlocks held so we can't sleep here. * sleep here. An alternative would be to copy the data to a
* buffer and relax the spinning requirement. The downside is
* we need to kmalloc a GFP_ATOMIC buffer each time the
* console driver writes something out.
*/ */
while (!virtqueue_get_buf(out_vq, &len)) while (!virtqueue_get_buf(out_vq, &len))
cpu_relax(); cpu_relax();
...@@ -626,6 +629,14 @@ static ssize_t port_fops_write(struct file *filp, const char __user *ubuf, ...@@ -626,6 +629,14 @@ static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
goto free_buf; goto free_buf;
} }
/*
* We now ask send_buf() to not spin for generic ports -- we
* can re-use the same code path that non-blocking file
* descriptors take for blocking file descriptors since the
* wait is already done and we're certain the write will go
* through to the host.
*/
nonblock = true;
ret = send_buf(port, buf, count, nonblock); ret = send_buf(port, buf, count, nonblock);
if (nonblock && ret > 0) if (nonblock && ret > 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册