Skip to content

Commit 5d9a07b

Browse files
committed
vhost: relax used address alignment
virtio 1.0 only requires used address to be 4 byte aligned, vhost required 8 bytes (size of vring_used_elem). Fix up vhost to match that. Additionally, while vhost correctly requires 8 byte alignment for log, it's unconnected to used ring: it's a consequence that log has u64 entries. Tweak code to make that clearer. Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent b28e050 commit 5d9a07b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-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
}

0 commit comments

Comments
 (0)