Skip to content

Commit 5e59d9a

Browse files
amlutomstsirkin
authored andcommitted
virtio_console: Stop doing DMA on the stack
virtio_console uses a small DMA buffer for control requests. Move that buffer into heap memory. Doing virtio DMA on the stack is normally okay on non-DMA-API virtio systems (which is currently most of them), but it breaks completely if the stack is virtually mapped. Tested by typing both directions using picocom aimed at /dev/hvc0. Signed-off-by: Andy Lutomirski <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Reviewed-by: Amit Shah <[email protected]>
1 parent af7c1be commit 5e59d9a

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

drivers/char/virtio_console.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ struct ports_device {
165165
*/
166166
struct virtqueue *c_ivq, *c_ovq;
167167

168+
/*
169+
* A control packet buffer for guest->host requests, protected
170+
* by c_ovq_lock.
171+
*/
172+
struct virtio_console_control cpkt;
173+
168174
/* Array of per-port IO virtqueues */
169175
struct virtqueue **in_vqs, **out_vqs;
170176

@@ -560,28 +566,29 @@ static ssize_t __send_control_msg(struct ports_device *portdev, u32 port_id,
560566
unsigned int event, unsigned int value)
561567
{
562568
struct scatterlist sg[1];
563-
struct virtio_console_control cpkt;
564569
struct virtqueue *vq;
565570
unsigned int len;
566571

567572
if (!use_multiport(portdev))
568573
return 0;
569574

570-
cpkt.id = cpu_to_virtio32(portdev->vdev, port_id);
571-
cpkt.event = cpu_to_virtio16(portdev->vdev, event);
572-
cpkt.value = cpu_to_virtio16(portdev->vdev, value);
573-
574575
vq = portdev->c_ovq;
575576

576-
sg_init_one(sg, &cpkt, sizeof(cpkt));
577-
578577
spin_lock(&portdev->c_ovq_lock);
579-
if (virtqueue_add_outbuf(vq, sg, 1, &cpkt, GFP_ATOMIC) == 0) {
578+
579+
portdev->cpkt.id = cpu_to_virtio32(portdev->vdev, port_id);
580+
portdev->cpkt.event = cpu_to_virtio16(portdev->vdev, event);
581+
portdev->cpkt.value = cpu_to_virtio16(portdev->vdev, value);
582+
583+
sg_init_one(sg, &portdev->cpkt, sizeof(struct virtio_console_control));
584+
585+
if (virtqueue_add_outbuf(vq, sg, 1, &portdev->cpkt, GFP_ATOMIC) == 0) {
580586
virtqueue_kick(vq);
581587
while (!virtqueue_get_buf(vq, &len)
582588
&& !virtqueue_is_broken(vq))
583589
cpu_relax();
584590
}
591+
585592
spin_unlock(&portdev->c_ovq_lock);
586593
return 0;
587594
}

0 commit comments

Comments
 (0)