Commit f59281dafb832b161133743fcf3dc29051e6fdb8
Committed by
Michael S. Tsirkin
1 parent
81fc70d865
Exists in
master
and in
4 other branches
vhost: init used ring after backend was set
Move the used ring initialization after backend was set. This makes it possible to disable the backend and tweak the used ring, then restart. This will also make it possible to log the used ring write correctly. Signed-off-by: Jason Wang <jasowang@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Showing 4 changed files with 16 additions and 8 deletions Side-by-side Diff
drivers/vhost/net.c
drivers/vhost/test.c
... | ... | @@ -195,7 +195,12 @@ |
195 | 195 | lockdep_is_held(&vq->mutex)); |
196 | 196 | rcu_assign_pointer(vq->private_data, priv); |
197 | 197 | |
198 | + r = vhost_init_used(&n->vqs[index]); | |
199 | + | |
198 | 200 | mutex_unlock(&vq->mutex); |
201 | + | |
202 | + if (r) | |
203 | + goto err; | |
199 | 204 | |
200 | 205 | if (oldpriv) { |
201 | 206 | vhost_test_flush_vq(n, index); |
drivers/vhost/vhost.c
... | ... | @@ -629,15 +629,17 @@ |
629 | 629 | return 0; |
630 | 630 | } |
631 | 631 | |
632 | -static int init_used(struct vhost_virtqueue *vq, | |
633 | - struct vring_used __user *used) | |
632 | +int vhost_init_used(struct vhost_virtqueue *vq) | |
634 | 633 | { |
635 | - int r = put_user(vq->used_flags, &used->flags); | |
634 | + int r; | |
635 | + if (!vq->private_data) | |
636 | + return 0; | |
636 | 637 | |
638 | + r = put_user(vq->used_flags, &vq->used->flags); | |
637 | 639 | if (r) |
638 | 640 | return r; |
639 | 641 | vq->signalled_used_valid = false; |
640 | - return get_user(vq->last_used_idx, &used->idx); | |
642 | + return get_user(vq->last_used_idx, &vq->used->idx); | |
641 | 643 | } |
642 | 644 | |
643 | 645 | static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp) |
... | ... | @@ -752,10 +754,6 @@ |
752 | 754 | } |
753 | 755 | } |
754 | 756 | |
755 | - r = init_used(vq, (struct vring_used __user *)(unsigned long) | |
756 | - a.used_user_addr); | |
757 | - if (r) | |
758 | - break; | |
759 | 757 | vq->log_used = !!(a.flags & (0x1 << VHOST_VRING_F_LOG)); |
760 | 758 | vq->desc = (void __user *)(unsigned long)a.desc_user_addr; |
761 | 759 | vq->avail = (void __user *)(unsigned long)a.avail_user_addr; |
drivers/vhost/vhost.h
... | ... | @@ -174,6 +174,7 @@ |
174 | 174 | struct vhost_log *log, unsigned int *log_num); |
175 | 175 | void vhost_discard_vq_desc(struct vhost_virtqueue *, int n); |
176 | 176 | |
177 | +int vhost_init_used(struct vhost_virtqueue *); | |
177 | 178 | int vhost_add_used(struct vhost_virtqueue *, unsigned int head, int len); |
178 | 179 | int vhost_add_used_n(struct vhost_virtqueue *, struct vring_used_elem *heads, |
179 | 180 | unsigned count); |