vhost: enforce avail index and desc read ordering
authorMaxime Coquelin <maxime.coquelin@redhat.com>
Wed, 19 Dec 2018 08:21:10 +0000 (09:21 +0100)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 21 Dec 2018 15:22:41 +0000 (16:22 +0100)
commitd4ff2135ebb6c7f55af783846fa8e7ea4379c71b
treee321c56da2b9df7264306301912d545d7cabd0a5
parent6e3339ca07734e59cd0c24594e3014ab49a0ffc0
vhost: enforce avail index and desc read ordering

A read barrier is required to ensure the ordering between
available index and the descriptor reads is enforced.

1. read avail_head = avail->idx
2. read cur_idx = last_avail_idx
if (cur_idx != avail_head) {
    3. read idx = avail->ring[cur_idx]
    4. read desc[idx]
}

There is a control dependency between step 1 and steps 3 & 4,
3 could be speculatively executed before 1, which could result
in 'idx' to not being updated yet.

Fixes: 4796ad63ba1f ("examples/vhost: import userspace vhost application")
Cc: stable@dpdk.org
Reported-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Acked-by: Ilya Maximets <i.maximets@samsung.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Tiwei Bie <tiwei.bie@intel.com>
lib/librte_vhost/virtio_net.c