From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <yskoh@mellanox.com>
Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129])
 by dpdk.org (Postfix) with ESMTP id 2D0E31B517
 for <stable@dpdk.org>; Fri, 30 Nov 2018 00:14:41 +0100 (CET)
Received: from Internal Mail-Server by MTLPINE1 (envelope-from
 yskoh@mellanox.com)
 with ESMTPS (AES256-SHA encrypted); 30 Nov 2018 01:20:31 +0200
Received: from scfae-sc-2.mti.labs.mlnx (scfae-sc-2.mti.labs.mlnx
 [10.101.0.96])
 by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id wATNCW8D032075;
 Fri, 30 Nov 2018 01:14:36 +0200
From: Yongseok Koh <yskoh@mellanox.com>
To: Phil Yang <phil.yang@arm.com>
Cc: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>,
 Gavin Hu <gavin.hu@arm.com>, Ferruh Yigit <ferruh.yigit@intel.com>,
 dpdk stable <stable@dpdk.org>
Date: Thu, 29 Nov 2018 15:11:07 -0800
Message-Id: <20181129231202.30436-73-yskoh@mellanox.com>
X-Mailer: git-send-email 2.11.0
In-Reply-To: <20181129231202.30436-1-yskoh@mellanox.com>
References: <20181129231202.30436-1-yskoh@mellanox.com>
Subject: [dpdk-stable] patch 'kni: fix kernel FIFO synchronization' has been
	queued to LTS release 17.11.5
X-BeenThere: stable@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches for DPDK stable branches <stable.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/stable>,
 <mailto:stable-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/stable/>
List-Post: <mailto:stable@dpdk.org>
List-Help: <mailto:stable-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/stable>,
 <mailto:stable-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Thu, 29 Nov 2018 23:14:41 -0000

Hi,

FYI, your patch has been queued to LTS release 17.11.5

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 12/01/18. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the patch applied
to the branch. If the code is different (ie: not only metadata diffs), due for example to
a change in context or macro names, please double check it.

Thanks.

Yongseok

---
>>From 387058b8788eae484c6a98207870eb73ee04ae97 Mon Sep 17 00:00:00 2001
From: Phil Yang <phil.yang@arm.com>
Date: Mon, 8 Oct 2018 17:11:45 +0800
Subject: [PATCH] kni: fix kernel FIFO synchronization

[ upstream commit 711859cd0d076c7abc0c96ce637129a03280645f ]

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: 3fc5ca2f6352 ("kni: initial import")

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: Ferruh Yigit <ferruh.yigit@intel.com>
---
 .../linuxapp/eal/include/exec-env/rte_kni_common.h       |  1 +
 lib/librte_eal/linuxapp/kni/kni_fifo.h                   | 16 ++++++++++------
 2 files changed, 11 insertions(+), 6 deletions(-)

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 794cd4f78..966fb9f4e 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
@@ -61,6 +61,7 @@
 
 #ifdef __KERNEL__
 #include <linux/if.h>
+#include <asm/barrier.h>
 #define RTE_STD_C11
 #else
 #include <rte_common.h>
diff --git a/lib/librte_eal/linuxapp/kni/kni_fifo.h b/lib/librte_eal/linuxapp/kni/kni_fifo.h
index 14f4141f9..e4edab9f3 100644
--- a/lib/librte_eal/linuxapp/kni/kni_fifo.h
+++ b/lib/librte_eal/linuxapp/kni/kni_fifo.h
@@ -35,7 +35,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++) {
@@ -46,7 +46,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;
 }
@@ -59,7 +59,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)
@@ -68,7 +68,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;
 }
@@ -79,7 +79,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);
 }
 
 /**
@@ -88,7 +90,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_ */
-- 
2.11.0

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2018-11-29 15:01:48.435397824 -0800
+++ 0073-kni-fix-kernel-FIFO-synchronization.patch	2018-11-29 15:01:45.188968000 -0800
@@ -1,29 +1,42 @@
-From 711859cd0d076c7abc0c96ce637129a03280645f Mon Sep 17 00:00:00 2001
+From 387058b8788eae484c6a98207870eb73ee04ae97 Mon Sep 17 00:00:00 2001
 From: Phil Yang <phil.yang@arm.com>
 Date: Mon, 8 Oct 2018 17:11:45 +0800
 Subject: [PATCH] kni: fix kernel FIFO synchronization
 
+[ upstream commit 711859cd0d076c7abc0c96ce637129a03280645f ]
+
 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: 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: Ferruh Yigit <ferruh.yigit@intel.com>
 ---
- kernel/linux/kni/kni_fifo.h                              | 16 ++++++++++------
  .../linuxapp/eal/include/exec-env/rte_kni_common.h       |  1 +
+ lib/librte_eal/linuxapp/kni/kni_fifo.h                   | 16 ++++++++++------
  2 files changed, 11 insertions(+), 6 deletions(-)
 
-diff --git a/kernel/linux/kni/kni_fifo.h b/kernel/linux/kni/kni_fifo.h
-index 9a4762de2..2cb3a4a7b 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)
+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 794cd4f78..966fb9f4e 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
+@@ -61,6 +61,7 @@
+ 
+ #ifdef __KERNEL__
+ #include <linux/if.h>
++#include <asm/barrier.h>
+ #define RTE_STD_C11
+ #else
+ #include <rte_common.h>
+diff --git a/lib/librte_eal/linuxapp/kni/kni_fifo.h b/lib/librte_eal/linuxapp/kni/kni_fifo.h
+index 14f4141f9..e4edab9f3 100644
+--- a/lib/librte_eal/linuxapp/kni/kni_fifo.h
++++ b/lib/librte_eal/linuxapp/kni/kni_fifo.h
+@@ -35,7 +35,7 @@ kni_fifo_put(struct rte_kni_fifo *fifo, void **data, uint32_t num)
  {
  	uint32_t i = 0;
  	uint32_t fifo_write = fifo->write;
@@ -32,7 +45,7 @@
  	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)
+@@ -46,7 +46,7 @@ kni_fifo_put(struct rte_kni_fifo *fifo, void **data, uint32_t num)
  		fifo->buffer[fifo_write] = data[i];
  		fifo_write = new_write;
  	}
@@ -41,7 +54,7 @@
  
  	return i;
  }
-@@ -40,7 +40,7 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, uint32_t num)
+@@ -59,7 +59,7 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, uint32_t num)
  {
  	uint32_t i = 0;
  	uint32_t new_read = fifo->read;
@@ -50,7 +63,7 @@
  
  	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)
+@@ -68,7 +68,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);
  	}
@@ -59,7 +72,7 @@
  
  	return i;
  }
-@@ -60,7 +60,9 @@ kni_fifo_get(struct rte_kni_fifo *fifo, void **data, uint32_t num)
+@@ -79,7 +79,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)
  {
@@ -70,7 +83,7 @@
  }
  
  /**
-@@ -69,7 +71,9 @@ kni_fifo_count(struct rte_kni_fifo *fifo)
+@@ -88,7 +90,9 @@ kni_fifo_count(struct rte_kni_fifo *fifo)
  static inline uint32_t
  kni_fifo_free_count(struct rte_kni_fifo *fifo)
  {
@@ -81,18 +94,6 @@
  }
  
  #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 cfa9448bd..58e8533be 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 <linux/if.h>
-+#include <asm/barrier.h>
- #define RTE_STD_C11
- #else
- #include <rte_common.h>
 -- 
 2.11.0