summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPhil Yang <phil.yang@arm.com>2018-10-08 17:11:44 +0800
committerThomas Monjalon <thomas@monjalon.net>2018-10-26 18:10:14 +0200
commit0b05abe7bf9a46915bc1823753fc29c0a7b99ed1 (patch)
tree453610ed1f481320e6d4e5421175e0251ad2f50e /lib
parentede56cc18dba2db0d261b15815063394dcb2035a (diff)
downloaddpdk-0b05abe7bf9a46915bc1823753fc29c0a7b99ed1.zip
dpdk-0b05abe7bf9a46915bc1823753fc29c0a7b99ed1.tar.gz
dpdk-0b05abe7bf9a46915bc1823753fc29c0a7b99ed1.tar.xz
kni: fix FIFO synchronization
With existing code in kni_fifo_put, rx_q values are not being updated before updating fifo_write. While reading rx_q in kni_net_rx_normal, This is causing the sync issue on other core. The same situation happens in kni_fifo_get as well. So syncing the values by adding memory barriers to make sure the values being synced before updating fifo_write and fifo_read. Fixes: 3fc5ca2f6352 ("kni: initial import") Cc: stable@dpdk.org Signed-off-by: Phil Yang <phil.yang@arm.com> Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com> Reviewed-by: Gavin Hu <gavin.hu@arm.com> Reviewed-by: Ola Liljedahl <ola.liljedahl@arm.com> Reviewed-by: Jerin Jacob <jerin.jacob@caviumnetworks.com> Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/librte_kni/rte_kni_fifo.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/librte_kni/rte_kni_fifo.h b/lib/librte_kni/rte_kni_fifo.h
index ac26a8c..70ac14e 100644
--- a/lib/librte_kni/rte_kni_fifo.h
+++ b/lib/librte_kni/rte_kni_fifo.h
@@ -28,8 +28,9 @@ kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num)
{
unsigned i = 0;
unsigned fifo_write = fifo->write;
- unsigned fifo_read = fifo->read;
unsigned new_write = fifo_write;
+ rte_smp_rmb();
+ unsigned fifo_read = fifo->read;
for (i = 0; i < num; i++) {
new_write = (new_write + 1) & (fifo->len - 1);
@@ -39,6 +40,7 @@ kni_fifo_put(struct rte_kni_fifo *fifo, void **data, unsigned num)
fifo->buffer[fifo_write] = data[i];
fifo_write = new_write;
}
+ rte_smp_wmb();
fifo->write = fifo_write;
return i;
}
@@ -51,7 +53,9 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num)
{
unsigned i = 0;
unsigned new_read = fifo->read;
+ rte_smp_rmb();
unsigned fifo_write = fifo->write;
+
for (i = 0; i < num; i++) {
if (new_read == fifo_write)
break;
@@ -59,6 +63,7 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num)
data[i] = fifo->buffer[new_read];
new_read = (new_read + 1) & (fifo->len - 1);
}
+ rte_smp_rmb();
fifo->read = new_read;
return i;
}
@@ -69,5 +74,8 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, unsigned num)
static inline uint32_t
kni_fifo_count(struct rte_kni_fifo *fifo)
{
- return (fifo->len + fifo->write - fifo->read) & (fifo->len - 1);
+ unsigned fifo_write = fifo->write;
+ rte_smp_rmb();
+ unsigned fifo_read = fifo->read;
+ return (fifo->len + fifo_write - fifo_read) & (fifo->len - 1);
}