Commit d7e19bd882c23109853ac67f414024c816edc8b9
Exists in
ti-lsk-linux-4.1.y
and in
10 other branches
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
Showing 2 changed files Side-by-side Diff
drivers/vhost/vhost.c
... | ... | @@ -713,9 +713,13 @@ |
713 | 713 | r = -EFAULT; |
714 | 714 | break; |
715 | 715 | } |
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))) { | |
719 | 723 | r = -EINVAL; |
720 | 724 | break; |
721 | 725 | } |
include/uapi/linux/virtio_ring.h
... | ... | @@ -101,6 +101,13 @@ |
101 | 101 | struct vring_used *used; |
102 | 102 | }; |
103 | 103 | |
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 | + | |
104 | 111 | /* The standard layout for the ring is a continuous chunk of memory which looks |
105 | 112 | * like this. We assume num is a power of 2. |
106 | 113 | * |