aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Wang <jasowang@redhat.com>2017-07-26 23:22:05 -0400
committerDavid S. Miller <davem@davemloft.net>2017-07-29 17:15:56 -0400
commit8d65843c44269c21e95c98090d9bb4848d473853 (patch)
tree2750e3949f94e9c424a97fe8165c50f6c893dcba
parent90fecc145e49ba0e910173e8b9fe94a458ef3024 (diff)
Revert "vhost: cache used event for better performance"
This reverts commit 809ecb9bca6a9424ccd392d67e368160f8b76c92. Since it was reported to break vhost_net. We want to cache used event and use it to check for notification. The assumption was that guest won't move the event idx back, but this could happen in fact when 16 bit index wraps around after 64K entries. Signed-off-by: Jason Wang <jasowang@redhat.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/vhost/vhost.c28
-rw-r--r--drivers/vhost/vhost.h3
2 files changed, 6 insertions, 25 deletions
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index e4613a3c362d..9cb3f722dce1 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -308,7 +308,6 @@ static void vhost_vq_reset(struct vhost_dev *dev,
308 vq->avail = NULL; 308 vq->avail = NULL;
309 vq->used = NULL; 309 vq->used = NULL;
310 vq->last_avail_idx = 0; 310 vq->last_avail_idx = 0;
311 vq->last_used_event = 0;
312 vq->avail_idx = 0; 311 vq->avail_idx = 0;
313 vq->last_used_idx = 0; 312 vq->last_used_idx = 0;
314 vq->signalled_used = 0; 313 vq->signalled_used = 0;
@@ -1402,7 +1401,7 @@ long vhost_vring_ioctl(struct vhost_dev *d, int ioctl, void __user *argp)
1402 r = -EINVAL; 1401 r = -EINVAL;
1403 break; 1402 break;
1404 } 1403 }
1405 vq->last_avail_idx = vq->last_used_event = s.num; 1404 vq->last_avail_idx = s.num;
1406 /* Forget the cached index value. */ 1405 /* Forget the cached index value. */
1407 vq->avail_idx = vq->last_avail_idx; 1406 vq->avail_idx = vq->last_avail_idx;
1408 break; 1407 break;
@@ -2241,6 +2240,10 @@ static bool vhost_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
2241 __u16 old, new; 2240 __u16 old, new;
2242 __virtio16 event; 2241 __virtio16 event;
2243 bool v; 2242 bool v;
2243 /* Flush out used index updates. This is paired
2244 * with the barrier that the Guest executes when enabling
2245 * interrupts. */
2246 smp_mb();
2244 2247
2245 if (vhost_has_feature(vq, VIRTIO_F_NOTIFY_ON_EMPTY) && 2248 if (vhost_has_feature(vq, VIRTIO_F_NOTIFY_ON_EMPTY) &&
2246 unlikely(vq->avail_idx == vq->last_avail_idx)) 2249 unlikely(vq->avail_idx == vq->last_avail_idx))
@@ -2248,10 +2251,6 @@ static bool vhost_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
2248 2251
2249 if (!vhost_has_feature(vq, VIRTIO_RING_F_EVENT_IDX)) { 2252 if (!vhost_has_feature(vq, VIRTIO_RING_F_EVENT_IDX)) {
2250 __virtio16 flags; 2253 __virtio16 flags;
2251 /* Flush out used index updates. This is paired
2252 * with the barrier that the Guest executes when enabling
2253 * interrupts. */
2254 smp_mb();
2255 if (vhost_get_avail(vq, flags, &vq->avail->flags)) { 2254 if (vhost_get_avail(vq, flags, &vq->avail->flags)) {
2256 vq_err(vq, "Failed to get flags"); 2255 vq_err(vq, "Failed to get flags");
2257 return true; 2256 return true;
@@ -2266,26 +2265,11 @@ static bool vhost_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
2266 if (unlikely(!v)) 2265 if (unlikely(!v))
2267 return true; 2266 return true;
2268 2267
2269 /* We're sure if the following conditions are met, there's no
2270 * need to notify guest:
2271 * 1) cached used event is ahead of new
2272 * 2) old to new updating does not cross cached used event. */
2273 if (vring_need_event(vq->last_used_event, new + vq->num, new) &&
2274 !vring_need_event(vq->last_used_event, new, old))
2275 return false;
2276
2277 /* Flush out used index updates. This is paired
2278 * with the barrier that the Guest executes when enabling
2279 * interrupts. */
2280 smp_mb();
2281
2282 if (vhost_get_avail(vq, event, vhost_used_event(vq))) { 2268 if (vhost_get_avail(vq, event, vhost_used_event(vq))) {
2283 vq_err(vq, "Failed to get used event idx"); 2269 vq_err(vq, "Failed to get used event idx");
2284 return true; 2270 return true;
2285 } 2271 }
2286 vq->last_used_event = vhost16_to_cpu(vq, event); 2272 return vring_need_event(vhost16_to_cpu(vq, event), new, old);
2287
2288 return vring_need_event(vq->last_used_event, new, old);
2289} 2273}
2290 2274
2291/* This actually signals the guest, using eventfd. */ 2275/* This actually signals the guest, using eventfd. */
diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
index f72095868b93..bb7c29b8b9fc 100644
--- a/drivers/vhost/vhost.h
+++ b/drivers/vhost/vhost.h
@@ -115,9 +115,6 @@ struct vhost_virtqueue {
115 /* Last index we used. */ 115 /* Last index we used. */
116 u16 last_used_idx; 116 u16 last_used_idx;
117 117
118 /* Last used evet we've seen */
119 u16 last_used_event;
120
121 /* Used flags */ 118 /* Used flags */
122 u16 used_flags; 119 u16 used_flags;
123 120