Skip to content

Commit d7e19bd

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull vhost cleanup and virtio bugfix "There's a single change here, fixing a vhost bug where vhost initialization fails due to used ring alignment check being too strict" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: vhost: relax used address alignment virtio_ring: document alignment requirements
2 parents 5e0f872 + 5d9a07b commit d7e19bd

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

drivers/vhost/vhost.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -713,9 +713,13 @@ long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp)
713713
r = -EFAULT;
714714
break;
715715
}
716-
if ((a.avail_user_addr & (sizeof *vq->avail->ring - 1)) ||
717-
(a.used_user_addr & (sizeof *vq->used->ring - 1)) ||
718-
(a.log_guest_addr & (sizeof *vq->used->ring - 1))) {
716+
717+
/* Make sure it's safe to cast pointers to vring types. */
718+
BUILD_BUG_ON(__alignof__ *vq->avail > VRING_AVAIL_ALIGN_SIZE);
719+
BUILD_BUG_ON(__alignof__ *vq->used > VRING_USED_ALIGN_SIZE);
720+
if ((a.avail_user_addr & (VRING_AVAIL_ALIGN_SIZE - 1)) ||
721+
(a.used_user_addr & (VRING_USED_ALIGN_SIZE - 1)) ||
722+
(a.log_guest_addr & (sizeof(u64) - 1))) {
719723
r = -EINVAL;
720724
break;
721725
}

include/uapi/linux/virtio_ring.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ struct vring {
101101
struct vring_used *used;
102102
};
103103

104+
/* Alignment requirements for vring elements.
105+
* When using pre-virtio 1.0 layout, these fall out naturally.
106+
*/
107+
#define VRING_AVAIL_ALIGN_SIZE 2
108+
#define VRING_USED_ALIGN_SIZE 4
109+
#define VRING_DESC_ALIGN_SIZE 16
110+
104111
/* The standard layout for the ring is a continuous chunk of memory which looks
105112
* like this. We assume num is a power of 2.
106113
*

0 commit comments

Comments
 (0)