From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.101.70]) by dpdk.org (Postfix) with ESMTP id 8AA003772 for ; Wed, 19 Sep 2018 15:44:22 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 07D1D80D; Wed, 19 Sep 2018 06:44:22 -0700 (PDT) Received: from localhost.localdomain (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 237AE3F703; Wed, 19 Sep 2018 06:44:19 -0700 (PDT) From: Phil Yang To: dev@dpdk.org Cc: nd@arm.com, jerin.jacob@caviumnetworks.com, kkokkilagadda@caviumnetworks.com, Honnappa.Nagarahalli@arm.com, Gavin.Hu@arm.com Date: Wed, 19 Sep 2018 21:42:40 +0800 Message-Id: <1537364560-4124-3-git-send-email-phil.yang@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1537364560-4124-1-git-send-email-phil.yang@arm.com> References: <1537363820-3827-1-git-send-email-phil.yang@arm.com> <1537364560-4124-1-git-send-email-phil.yang@arm.com> Subject: [dpdk-dev] [PATCH v2 3/3] kni: fix kni kernel fifo synchronization X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Sep 2018 13:44:23 -0000 Adding memory barrier to make sure the values being synced before updating fifo_write in kni_fifo_put and fifo_read in kni_fifo_get. Fixes: 3fc5ca2 ("kni: initial import") Signed-off-by: Phil Yang Reviewed-by: Honnappa Nagarahalli Reviewed-by: Gavin Hu --- kernel/linux/kni/kni_fifo.h | 16 ++++++++++------ .../linuxapp/eal/include/exec-env/rte_kni_common.h | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/kernel/linux/kni/kni_fifo.h b/kernel/linux/kni/kni_fifo.h index 9a4762d..2cb3a4a 100644 --- a/kernel/linux/kni/kni_fifo.h +++ b/kernel/linux/kni/kni_fifo.h @@ -16,7 +16,7 @@ kni_fifo_put(struct rte_kni_fifo *fifo, void **data, uint32_t num) { uint32_t i = 0; uint32_t fifo_write = fifo->write; - uint32_t fifo_read = fifo->read; + uint32_t fifo_read = smp_load_acquire(&fifo->read); uint32_t new_write = fifo_write; for (i = 0; i < num; i++) { @@ -27,7 +27,7 @@ kni_fifo_put(struct rte_kni_fifo *fifo, void **data, uint32_t num) fifo->buffer[fifo_write] = data[i]; fifo_write = new_write; } - fifo->write = fifo_write; + smp_store_release(&fifo->write, fifo_write); return i; } @@ -40,7 +40,7 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, uint32_t num) { uint32_t i = 0; uint32_t new_read = fifo->read; - uint32_t fifo_write = fifo->write; + uint32_t fifo_write = smp_load_acquire(&fifo->write); for (i = 0; i < num; i++) { if (new_read == fifo_write) @@ -49,7 +49,7 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, uint32_t num) data[i] = fifo->buffer[new_read]; new_read = (new_read + 1) & (fifo->len - 1); } - fifo->read = new_read; + smp_store_release(&fifo->read, new_read); return i; } @@ -60,7 +60,9 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, uint32_t num) static inline uint32_t kni_fifo_count(struct rte_kni_fifo *fifo) { - return (fifo->len + fifo->write - fifo->read) & (fifo->len - 1); + uint32_t fifo_write = smp_load_acquire(&fifo->write); + uint32_t fifo_read = smp_load_acquire(&fifo->read); + return (fifo->len + fifo_write - fifo_read) & (fifo->len - 1); } /** @@ -69,7 +71,9 @@ kni_fifo_count(struct rte_kni_fifo *fifo) static inline uint32_t kni_fifo_free_count(struct rte_kni_fifo *fifo) { - return (fifo->read - fifo->write - 1) & (fifo->len - 1); + uint32_t fifo_write = smp_load_acquire(&fifo->write); + uint32_t fifo_read = smp_load_acquire(&fifo->read); + return (fifo_read - fifo_write - 1) & (fifo->len - 1); } #endif /* _KNI_FIFO_H_ */ diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h index 1fd713b..5902ae4 100644 --- a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +++ b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h @@ -8,6 +8,7 @@ #ifdef __KERNEL__ #include +#include #define RTE_STD_C11 #else #include -- 2.7.4