netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V1 net 00/11] Bug fixes for ENA Ethernet driver
@ 2020-01-29 14:04 Sameeh Jubran
  2020-01-29 14:04 ` [PATCH V1 net 01/11] net: ena: fix potential crash when rxfh key is NULL Sameeh Jubran
                   ` (10 more replies)
  0 siblings, 11 replies; 15+ messages in thread
From: Sameeh Jubran @ 2020-01-29 14:04 UTC (permalink / raw)
  To: davem, netdev
  Cc: Sameeh Jubran, dwmw, zorik, matua, saeedb, msw, aliguori, nafea,
	gtzalik, netanel, alisaidi, benh, akiyano, ndagan

This series include multiple bug fixes for the ena driver,
please review.

Arthur Kiyanovski (10):
  net: ena: fix potential crash when rxfh key is NULL
  net: ena: fix uses of round_jiffies()
  net: ena: add missing ethtool TX timestamping indication
  net: ena: fix incorrect default RSS key
  net: ena: rss: store hash function as values and not bits
  net: ena: rss: fix failure to get indirection table
  net: ena: fix incorrectly saving queue numbers when setting RSS
    indirection table
  net: ena: fix corruption of dev_idx_to_host_tbl
  net: ena: make ena rxfh support ETH_RSS_HASH_NO_CHANGE
  net: ena: ena-com.c: prevent NULL pointer dereference

Sameeh Jubran (1):
  net: ena: ethtool: use correct value for crc32 hash

 drivers/net/ethernet/amazon/ena/ena_com.c     | 109 ++++++++++--------
 drivers/net/ethernet/amazon/ena/ena_com.h     |  31 ++++-
 drivers/net/ethernet/amazon/ena/ena_ethtool.c |  90 +++++++++++----
 drivers/net/ethernet/amazon/ena/ena_netdev.c  |   6 +-
 drivers/net/ethernet/amazon/ena/ena_netdev.h  |   2 +
 5 files changed, 160 insertions(+), 78 deletions(-)

-- 
2.24.1.AMZN


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH V1 net 01/11] net: ena: fix potential crash when rxfh key is NULL
  2020-01-29 14:04 [PATCH V1 net 00/11] Bug fixes for ENA Ethernet driver Sameeh Jubran
@ 2020-01-29 14:04 ` Sameeh Jubran
  2020-01-29 14:04 ` [PATCH V1 net 02/11] net: ena: fix uses of round_jiffies() Sameeh Jubran
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Sameeh Jubran @ 2020-01-29 14:04 UTC (permalink / raw)
  To: davem, netdev
  Cc: Arthur Kiyanovski, dwmw, zorik, matua, saeedb, msw, aliguori,
	nafea, gtzalik, netanel, alisaidi, benh, sameehj, ndagan

From: Arthur Kiyanovski <akiyano@amazon.com>

When ethtool -X is called without an hkey, ena_com_fill_hash_function()
is called with key=NULL, which is passed to memcpy causing a crash.

This commit fixes this issue by checking key is not NULL.

Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
Signed-off-by: Sameeh Jubran <sameehj@amazon.com>
Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>
---
 drivers/net/ethernet/amazon/ena/ena_com.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c b/drivers/net/ethernet/amazon/ena/ena_com.c
index ea62604fd..e54c44fdc 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_com.c
@@ -2297,15 +2297,16 @@ int ena_com_fill_hash_function(struct ena_com_dev *ena_dev,
 
 	switch (func) {
 	case ENA_ADMIN_TOEPLITZ:
-		if (key_len > sizeof(hash_key->key)) {
-			pr_err("key len (%hu) is bigger than the max supported (%zu)\n",
-			       key_len, sizeof(hash_key->key));
-			return -EINVAL;
+		if (key) {
+			if (key_len != sizeof(hash_key->key)) {
+				pr_err("key len (%hu) doesn't equal the supported size (%zu)\n",
+				       key_len, sizeof(hash_key->key));
+				return -EINVAL;
+			}
+			memcpy(hash_key->key, key, key_len);
+			rss->hash_init_val = init_val;
+			hash_key->keys_num = key_len >> 2;
 		}
-
-		memcpy(hash_key->key, key, key_len);
-		rss->hash_init_val = init_val;
-		hash_key->keys_num = key_len >> 2;
 		break;
 	case ENA_ADMIN_CRC32:
 		rss->hash_init_val = init_val;
-- 
2.24.1.AMZN


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH V1 net 02/11] net: ena: fix uses of round_jiffies()
  2020-01-29 14:04 [PATCH V1 net 00/11] Bug fixes for ENA Ethernet driver Sameeh Jubran
  2020-01-29 14:04 ` [PATCH V1 net 01/11] net: ena: fix potential crash when rxfh key is NULL Sameeh Jubran
@ 2020-01-29 14:04 ` Sameeh Jubran
  2020-01-29 14:04 ` [PATCH V1 net 03/11] net: ena: add missing ethtool TX timestamping indication Sameeh Jubran
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Sameeh Jubran @ 2020-01-29 14:04 UTC (permalink / raw)
  To: davem, netdev
  Cc: Arthur Kiyanovski, dwmw, zorik, matua, saeedb, msw, aliguori,
	nafea, gtzalik, netanel, alisaidi, benh, sameehj, ndagan

From: Arthur Kiyanovski <akiyano@amazon.com>

From the documentation of round_jiffies():
"Rounds a time delta  in the future (in jiffies) up or down to
(approximately) full seconds. This is useful for timers for which
the exact time they fire does not matter too much, as long as
they fire approximately every X seconds.
By rounding these timers to whole seconds, all such timers will fire
at the same time, rather than at various times spread out. The goal
of this is to have the CPU wake up less, which saves power."

There are 2 parts to this patch:
================================
Part 1:
-------
In our case we need timer_service to be called approximately every
X=1 seconds, and the exact time does not matter, so using round_jiffies()
is the right way to go.

Therefore we add round_jiffies() to the mod_timer() in ena_timer_service().

Part 2:
-------
round_jiffies() is used in check_for_missing_keep_alive() when
getting the jiffies of the expiration of the keep_alive timeout. Here it
is actually a mistake to use round_jiffies() because we want the exact
time when keep_alive should expire and not an approximate rounded time,
which can cause early, false positive, timeouts.

Therefore we remove round_jiffies() in the calculation of
keep_alive_expired() in check_for_missing_keep_alive().

Fixes: 82ef30f13be0 ("net: ena: add hardware hints capability to the driver")
Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index 948583fdc..1c1a41bd1 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -3049,8 +3049,8 @@ static void check_for_missing_keep_alive(struct ena_adapter *adapter)
 	if (adapter->keep_alive_timeout == ENA_HW_HINTS_NO_TIMEOUT)
 		return;
 
-	keep_alive_expired = round_jiffies(adapter->last_keep_alive_jiffies +
-					   adapter->keep_alive_timeout);
+	keep_alive_expired = adapter->last_keep_alive_jiffies +
+			     adapter->keep_alive_timeout;
 	if (unlikely(time_is_before_jiffies(keep_alive_expired))) {
 		netif_err(adapter, drv, adapter->netdev,
 			  "Keep alive watchdog timeout.\n");
@@ -3152,7 +3152,7 @@ static void ena_timer_service(struct timer_list *t)
 	}
 
 	/* Reset the timer */
-	mod_timer(&adapter->timer_service, jiffies + HZ);
+	mod_timer(&adapter->timer_service, round_jiffies(jiffies + HZ));
 }
 
 static int ena_calc_max_io_queue_num(struct pci_dev *pdev,
-- 
2.24.1.AMZN


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH V1 net 03/11] net: ena: add missing ethtool TX timestamping indication
  2020-01-29 14:04 [PATCH V1 net 00/11] Bug fixes for ENA Ethernet driver Sameeh Jubran
  2020-01-29 14:04 ` [PATCH V1 net 01/11] net: ena: fix potential crash when rxfh key is NULL Sameeh Jubran
  2020-01-29 14:04 ` [PATCH V1 net 02/11] net: ena: fix uses of round_jiffies() Sameeh Jubran
@ 2020-01-29 14:04 ` Sameeh Jubran
  2020-01-29 14:04 ` [PATCH V1 net 04/11] net: ena: fix incorrect default RSS key Sameeh Jubran
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Sameeh Jubran @ 2020-01-29 14:04 UTC (permalink / raw)
  To: davem, netdev
  Cc: Arthur Kiyanovski, dwmw, zorik, matua, saeedb, msw, aliguori,
	nafea, gtzalik, netanel, alisaidi, benh, sameehj, ndagan,
	Ezequiel Lara Gomez

From: Arthur Kiyanovski <akiyano@amazon.com>

Current implementation of the driver calls skb_tx_timestamp()to add a
software tx timestamp to the skb, however the software-transmit capability
is not reported in ethtool -T.

This commit updates the ethtool structure to report the software-transmit
capability in ethtool -T using the standard ethtool_op_get_ts_info().
This function reports all software timestamping capabilities (tx and rx),
as well as setting phc_index = -1. phc_index is the index of the PTP
hardware clock device that will be used for hardware timestamps. Since we
don't have such a device in ENA, using the default -1 value is the correct
setting.

Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
Signed-off-by: Ezequiel Lara Gomez <ezegomez@amazon.com>
Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>
---
 drivers/net/ethernet/amazon/ena/ena_ethtool.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/amazon/ena/ena_ethtool.c b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
index fc96c66b4..8b56383b6 100644
--- a/drivers/net/ethernet/amazon/ena/ena_ethtool.c
+++ b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
@@ -812,6 +812,7 @@ static const struct ethtool_ops ena_ethtool_ops = {
 	.set_channels		= ena_set_channels,
 	.get_tunable		= ena_get_tunable,
 	.set_tunable		= ena_set_tunable,
+	.get_ts_info            = ethtool_op_get_ts_info,
 };
 
 void ena_set_ethtool_ops(struct net_device *netdev)
-- 
2.24.1.AMZN


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH V1 net 04/11] net: ena: fix incorrect default RSS key
  2020-01-29 14:04 [PATCH V1 net 00/11] Bug fixes for ENA Ethernet driver Sameeh Jubran
                   ` (2 preceding siblings ...)
  2020-01-29 14:04 ` [PATCH V1 net 03/11] net: ena: add missing ethtool TX timestamping indication Sameeh Jubran
@ 2020-01-29 14:04 ` Sameeh Jubran
  2020-01-29 16:03   ` Jakub Kicinski
  2020-01-29 14:04 ` [PATCH V1 net 05/11] net: ena: rss: store hash function as values and not bits Sameeh Jubran
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 15+ messages in thread
From: Sameeh Jubran @ 2020-01-29 14:04 UTC (permalink / raw)
  To: davem, netdev
  Cc: Arthur Kiyanovski, dwmw, zorik, matua, saeedb, msw, aliguori,
	nafea, gtzalik, netanel, alisaidi, benh, sameehj, ndagan

From: Arthur Kiyanovski <akiyano@amazon.com>

Bug description:
When running "ethtool -x <if_name>" the key shows up as all zeros.

When we use "ethtool -X <if_name> hfunc toeplitz hkey <some:random:key>" to
set the key and then try to retrieve it using "ethtool -x <if_name>" then
we return the correct key because we return the one we saved.

Bug cause:
We don't fetch the key from the device but instead return the key
that we have saved internally which is by default set to zero upon
allocation.

Fix:
This commit fixes the issue by initializing the key to the default key that
is used by the device.

Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
Signed-off-by: Sameeh Jubran <sameehj@amazon.com>
Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>
---
 drivers/net/ethernet/amazon/ena/ena_com.c | 24 +++++++++++++++++++++++
 drivers/net/ethernet/amazon/ena/ena_com.h |  1 +
 2 files changed, 25 insertions(+)

diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c b/drivers/net/ethernet/amazon/ena/ena_com.c
index e54c44fdc..769339043 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_com.c
@@ -64,6 +64,15 @@
 
 #define ENA_POLL_MS	5
 
+/* Default Microsoft RSS key, used for HRSS. */
+static const u8 rss_hash_key[ENA_HASH_KEY_SIZE] = {
+		0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
+		0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0,
+		0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4,
+		0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
+		0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa
+};
+
 /*****************************************************************************/
 /*****************************************************************************/
 /*****************************************************************************/
@@ -1041,6 +1050,19 @@ static int ena_com_get_feature(struct ena_com_dev *ena_dev,
 				      feature_ver);
 }
 
+static void ena_com_hash_key_fill_default_key(struct ena_com_dev *ena_dev)
+{
+	struct ena_admin_feature_rss_flow_hash_control *hash_key =
+		(ena_dev->rss).hash_key;
+
+	memcpy(hash_key->key, rss_hash_key, sizeof(rss_hash_key));
+	/* The key is stored in the device in u32 array
+	 * as well as the API requires the key to be passed in this
+	 * format. Thus the size of our array should be divided by 4
+	 */
+	hash_key->keys_num = sizeof(rss_hash_key) / sizeof(u32);
+}
+
 static int ena_com_hash_key_allocate(struct ena_com_dev *ena_dev)
 {
 	struct ena_rss *rss = &ena_dev->rss;
@@ -2631,6 +2653,8 @@ int ena_com_rss_init(struct ena_com_dev *ena_dev, u16 indr_tbl_log_size)
 	if (unlikely(rc))
 		goto err_hash_key;
 
+	ena_com_hash_key_fill_default_key(ena_dev);
+
 	rc = ena_com_hash_ctrl_init(ena_dev);
 	if (unlikely(rc))
 		goto err_hash_ctrl;
diff --git a/drivers/net/ethernet/amazon/ena/ena_com.h b/drivers/net/ethernet/amazon/ena/ena_com.h
index 0ce37d54e..91c048872 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.h
+++ b/drivers/net/ethernet/amazon/ena/ena_com.h
@@ -75,6 +75,7 @@
 #define ENA_INTR_INITIAL_TX_INTERVAL_USECS		64
 #define ENA_INTR_INITIAL_RX_INTERVAL_USECS		0
 #define ENA_DEFAULT_INTR_DELAY_RESOLUTION		1
+#define ENA_HASH_KEY_SIZE				40
 
 #define ENA_HW_HINTS_NO_TIMEOUT				0xFFFF
 
-- 
2.24.1.AMZN


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH V1 net 05/11] net: ena: rss: store hash function as values and not bits
  2020-01-29 14:04 [PATCH V1 net 00/11] Bug fixes for ENA Ethernet driver Sameeh Jubran
                   ` (3 preceding siblings ...)
  2020-01-29 14:04 ` [PATCH V1 net 04/11] net: ena: fix incorrect default RSS key Sameeh Jubran
@ 2020-01-29 14:04 ` Sameeh Jubran
  2020-01-29 14:04 ` [PATCH V1 net 06/11] net: ena: rss: fix failure to get indirection table Sameeh Jubran
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Sameeh Jubran @ 2020-01-29 14:04 UTC (permalink / raw)
  To: davem, netdev
  Cc: Arthur Kiyanovski, dwmw, zorik, matua, saeedb, msw, aliguori,
	nafea, gtzalik, netanel, alisaidi, benh, sameehj, ndagan

From: Arthur Kiyanovski <akiyano@amazon.com>

The device receives, stores and retrieves the hash function value as bits
and not as their enum value.

The bug:
* In ena_com_set_hash_function() we set
  cmd.u.flow_hash_func.selected_func to the bit value of rss->hash_func.
 (1 << rss->hash_func)
* In ena_com_get_hash_function() we retrieve the hash function and store
  it's bit value in rss->hash_func. (Now the bit value of rss->hash_func
  is stored in rss->hash_func instead of it's enum value)

The fix:
This commit fixes the issue by converting the retrieved hash function
values from the device to the matching enum value of the set bit using
ffs(). ffs() finds the first set bit's index in a word. Since the function
returns 1 for the LSB's index, we need to subtract 1 from the returned
value (note that BIT(0) is 1).

Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
Signed-off-by: Sameeh Jubran <sameehj@amazon.com>
Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>
---
 drivers/net/ethernet/amazon/ena/ena_com.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c b/drivers/net/ethernet/amazon/ena/ena_com.c
index 769339043..9e6c50b97 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_com.c
@@ -2365,7 +2365,11 @@ int ena_com_get_hash_function(struct ena_com_dev *ena_dev,
 	if (unlikely(rc))
 		return rc;
 
-	rss->hash_func = get_resp.u.flow_hash_func.selected_func;
+	/* ffs() returns 1 in case the lsb is set */
+	rss->hash_func = ffs(get_resp.u.flow_hash_func.selected_func);
+	if (rss->hash_func)
+		rss->hash_func--;
+
 	if (func)
 		*func = rss->hash_func;
 
-- 
2.24.1.AMZN


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH V1 net 06/11] net: ena: rss: fix failure to get indirection table
  2020-01-29 14:04 [PATCH V1 net 00/11] Bug fixes for ENA Ethernet driver Sameeh Jubran
                   ` (4 preceding siblings ...)
  2020-01-29 14:04 ` [PATCH V1 net 05/11] net: ena: rss: store hash function as values and not bits Sameeh Jubran
@ 2020-01-29 14:04 ` Sameeh Jubran
  2020-01-29 14:04 ` [PATCH V1 net 07/11] net: ena: fix incorrectly saving queue numbers when setting RSS " Sameeh Jubran
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Sameeh Jubran @ 2020-01-29 14:04 UTC (permalink / raw)
  To: davem, netdev
  Cc: Arthur Kiyanovski, dwmw, zorik, matua, saeedb, msw, aliguori,
	nafea, gtzalik, netanel, alisaidi, benh, sameehj, ndagan

From: Arthur Kiyanovski <akiyano@amazon.com>

Bug:
The get indirection table will fail on older hardware versions. This
happens because getting/setting the hash function is not supported on
this hardware. In short ena_indirection_table_get() succeeds while
the call to ena_com_get_hash_function() fails when ena_get_rxfh() is
executed.

Fix:
Simply set the hash function to the default value - Toeplitz - in case the
error is EOPNOTSUPP.

Also:
* Separate hash and key retrieval
* Fix restoring the hash function in ena_com_fill_hash_function()
* Reverse christmas tree in ena_com_fill_hash_function()

Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
Signed-off-by: Sameeh Jubran <sameehj@amazon.com>
Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>
---
 drivers/net/ethernet/amazon/ena/ena_com.c     | 24 ++++++++++++-------
 drivers/net/ethernet/amazon/ena/ena_com.h     | 22 ++++++++++++-----
 drivers/net/ethernet/amazon/ena/ena_ethtool.c | 10 +++++---
 3 files changed, 39 insertions(+), 17 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c b/drivers/net/ethernet/amazon/ena/ena_com.c
index 9e6c50b97..8bcf76f92 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_com.c
@@ -2295,12 +2295,14 @@ int ena_com_fill_hash_function(struct ena_com_dev *ena_dev,
 			       enum ena_admin_hash_functions func,
 			       const u8 *key, u16 key_len, u32 init_val)
 {
-	struct ena_rss *rss = &ena_dev->rss;
+	struct ena_admin_feature_rss_flow_hash_control *hash_key;
 	struct ena_admin_get_feat_resp get_resp;
-	struct ena_admin_feature_rss_flow_hash_control *hash_key =
-		rss->hash_key;
+	enum ena_admin_hash_functions old_func;
+	struct ena_rss *rss = &ena_dev->rss;
 	int rc;
 
+	hash_key = rss->hash_key;
+
 	/* Make sure size is a mult of DWs */
 	if (unlikely(key_len & 0x3))
 		return -EINVAL;
@@ -2338,24 +2340,22 @@ int ena_com_fill_hash_function(struct ena_com_dev *ena_dev,
 		return -EINVAL;
 	}
 
+	old_func = rss->hash_func;
 	rss->hash_func = func;
 	rc = ena_com_set_hash_function(ena_dev);
 
 	/* Restore the old function */
 	if (unlikely(rc))
-		ena_com_get_hash_function(ena_dev, NULL, NULL);
+		rss->hash_func = old_func;
 
 	return rc;
 }
 
 int ena_com_get_hash_function(struct ena_com_dev *ena_dev,
-			      enum ena_admin_hash_functions *func,
-			      u8 *key)
+			      enum ena_admin_hash_functions *func)
 {
 	struct ena_rss *rss = &ena_dev->rss;
 	struct ena_admin_get_feat_resp get_resp;
-	struct ena_admin_feature_rss_flow_hash_control *hash_key =
-		rss->hash_key;
 	int rc;
 
 	rc = ena_com_get_feature_ex(ena_dev, &get_resp,
@@ -2373,6 +2373,14 @@ int ena_com_get_hash_function(struct ena_com_dev *ena_dev,
 	if (func)
 		*func = rss->hash_func;
 
+	return 0;
+}
+
+int ena_com_get_hash_key(struct ena_com_dev *ena_dev, u8 *key)
+{
+	struct ena_admin_feature_rss_flow_hash_control *hash_key =
+		ena_dev->rss.hash_key;
+
 	if (key)
 		memcpy(key, hash_key->key, (size_t)(hash_key->keys_num) << 2);
 
diff --git a/drivers/net/ethernet/amazon/ena/ena_com.h b/drivers/net/ethernet/amazon/ena/ena_com.h
index 91c048872..ea925bb01 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.h
+++ b/drivers/net/ethernet/amazon/ena/ena_com.h
@@ -687,13 +687,11 @@ int ena_com_fill_hash_function(struct ena_com_dev *ena_dev,
  */
 int ena_com_set_hash_function(struct ena_com_dev *ena_dev);
 
-/* ena_com_get_hash_function - Retrieve the hash function and the hash key
- * from the device.
+/* ena_com_get_hash_function - Retrieve the hash function from the device.
  * @ena_dev: ENA communication layer struct
  * @func: hash function
- * @key: hash key
  *
- * Retrieve the hash function and the hash key from the device.
+ * Retrieve the hash function from the device.
  *
  * @note: If the caller called ena_com_fill_hash_function but didn't flash
  * it to the device, the new configuration will be lost.
@@ -701,8 +699,20 @@ int ena_com_set_hash_function(struct ena_com_dev *ena_dev);
  * @return: 0 on Success and negative value otherwise.
  */
 int ena_com_get_hash_function(struct ena_com_dev *ena_dev,
-			      enum ena_admin_hash_functions *func,
-			      u8 *key);
+			      enum ena_admin_hash_functions *func);
+
+/* ena_com_get_hash_key - Retrieve the hash key
+ * @ena_dev: ENA communication layer struct
+ * @key: hash key
+ *
+ * Retrieve the hash key.
+ *
+ * @note: If the caller called ena_com_fill_hash_key but didn't flash
+ * it to the device, the new configuration will be lost.
+ *
+ * @return: 0 on Success and negative value otherwise.
+ */
+int ena_com_get_hash_key(struct ena_com_dev *ena_dev, u8 *key);
 
 /* ena_com_fill_hash_ctrl - Fill RSS hash control
  * @ena_dev: ENA communication layer struct.
diff --git a/drivers/net/ethernet/amazon/ena/ena_ethtool.c b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
index 8b56383b6..d0d91dbe0 100644
--- a/drivers/net/ethernet/amazon/ena/ena_ethtool.c
+++ b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
@@ -640,7 +640,7 @@ static int ena_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
 			u8 *hfunc)
 {
 	struct ena_adapter *adapter = netdev_priv(netdev);
-	enum ena_admin_hash_functions ena_func;
+	enum ena_admin_hash_functions ena_func = ENA_ADMIN_TOEPLITZ;
 	u8 func;
 	int rc;
 
@@ -648,10 +648,14 @@ static int ena_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
 	if (rc)
 		return rc;
 
-	rc = ena_com_get_hash_function(adapter->ena_dev, &ena_func, key);
+	rc = ena_com_get_hash_key(adapter->ena_dev, key);
 	if (rc)
 		return rc;
 
+	rc = ena_com_get_hash_function(adapter->ena_dev, &ena_func);
+	if (rc && rc != -EOPNOTSUPP)
+		return rc;
+
 	switch (ena_func) {
 	case ENA_ADMIN_TOEPLITZ:
 		func = ETH_RSS_HASH_TOP;
@@ -668,7 +672,7 @@ static int ena_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
 	if (hfunc)
 		*hfunc = func;
 
-	return rc;
+	return 0;
 }
 
 static int ena_set_rxfh(struct net_device *netdev, const u32 *indir,
-- 
2.24.1.AMZN


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH V1 net 07/11] net: ena: fix incorrectly saving queue numbers when setting RSS indirection table
  2020-01-29 14:04 [PATCH V1 net 00/11] Bug fixes for ENA Ethernet driver Sameeh Jubran
                   ` (5 preceding siblings ...)
  2020-01-29 14:04 ` [PATCH V1 net 06/11] net: ena: rss: fix failure to get indirection table Sameeh Jubran
@ 2020-01-29 14:04 ` Sameeh Jubran
  2020-01-29 16:07   ` Jakub Kicinski
  2020-01-29 14:04 ` [PATCH V1 net 08/11] net: ena: fix corruption of dev_idx_to_host_tbl Sameeh Jubran
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 15+ messages in thread
From: Sameeh Jubran @ 2020-01-29 14:04 UTC (permalink / raw)
  To: davem, netdev
  Cc: Arthur Kiyanovski, dwmw, zorik, matua, saeedb, msw, aliguori,
	nafea, gtzalik, netanel, alisaidi, benh, sameehj, ndagan

From: Arthur Kiyanovski <akiyano@amazon.com>

The indirection table has the indices of the Rx queues. When we store it
during set indirection operation, we convert the indices to our internal
representation of the indices.

Our internal representation of the indices is: even indices for Tx and
odd indices for Rx, where every Tx/Rx pair are in a consecutive order
starting from 0. For example if the driver has 3 queues (3 for Tx and 3
for Rx) then the indices are as follows:
0  1  2  3  4  5
Tx Rx Tx Rx Tx Rx

The BUG:
The issue is that when we satisfy a get request for the indirection
table, we don't convert the indices back to the original representation.

The FIX:
Simply apply the inverse function for the indices of the indirection
table after we set it.

Also move the set code to a standalone function for code clarity.

Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
Signed-off-by: Sameeh Jubran <sameehj@amazon.com>
Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>
---
 drivers/net/ethernet/amazon/ena/ena_ethtool.c | 72 ++++++++++++++-----
 drivers/net/ethernet/amazon/ena/ena_netdev.h  |  2 +
 2 files changed, 55 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_ethtool.c b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
index d0d91dbe0..accc4c8d1 100644
--- a/drivers/net/ethernet/amazon/ena/ena_ethtool.c
+++ b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
@@ -636,6 +636,54 @@ static u32 ena_get_rxfh_key_size(struct net_device *netdev)
 	return ENA_HASH_KEY_SIZE;
 }
 
+static int ena_indirection_table_set(struct ena_adapter *adapter,
+				     const u32 *indir)
+{
+	struct ena_com_dev *ena_dev = adapter->ena_dev;
+	int i, rc;
+
+	for (i = 0; i < ENA_RX_RSS_TABLE_SIZE; i++) {
+		rc = ena_com_indirect_table_fill_entry(ena_dev,
+						       i,
+						       ENA_IO_RXQ_IDX(indir[i]));
+		if (unlikely(rc)) {
+			netif_err(adapter, drv, adapter->netdev,
+				  "Cannot fill indirect table (index is too large)\n");
+			return rc;
+		}
+	}
+
+	rc = ena_com_indirect_table_set(ena_dev);
+	if (rc) {
+		netif_err(adapter, drv, adapter->netdev,
+			  "Cannot set indirect table\n");
+		return rc == -EPERM ? -EOPNOTSUPP : rc;
+	}
+	return rc;
+}
+
+static int ena_indirection_table_get(struct ena_adapter *adapter, u32 *indir)
+{
+	struct ena_com_dev *ena_dev = adapter->ena_dev;
+	int i, rc;
+
+	if (!indir)
+		return 0;
+
+	rc = ena_com_indirect_table_get(ena_dev, indir);
+	if (rc)
+		return rc;
+
+	/* Our internal representation of the indices is: even indices
+	 * for Tx and uneven indices for Rx. We need to convert the Rx
+	 * indices to be consecutive
+	 */
+	for (i = 0; i < ENA_RX_RSS_TABLE_SIZE; i++)
+		indir[i] = ENA_IO_RXQ_IDX_TO_COMBINED_IDX(indir[i]);
+
+	return rc;
+}
+
 static int ena_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
 			u8 *hfunc)
 {
@@ -644,7 +692,7 @@ static int ena_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
 	u8 func;
 	int rc;
 
-	rc = ena_com_indirect_table_get(adapter->ena_dev, indir);
+	rc = ena_indirection_table_get(adapter, indir);
 	if (rc)
 		return rc;
 
@@ -681,26 +729,12 @@ static int ena_set_rxfh(struct net_device *netdev, const u32 *indir,
 	struct ena_adapter *adapter = netdev_priv(netdev);
 	struct ena_com_dev *ena_dev = adapter->ena_dev;
 	enum ena_admin_hash_functions func;
-	int rc, i;
+	int rc;
 
 	if (indir) {
-		for (i = 0; i < ENA_RX_RSS_TABLE_SIZE; i++) {
-			rc = ena_com_indirect_table_fill_entry(ena_dev,
-							       i,
-							       ENA_IO_RXQ_IDX(indir[i]));
-			if (unlikely(rc)) {
-				netif_err(adapter, drv, netdev,
-					  "Cannot fill indirect table (index is too large)\n");
-				return rc;
-			}
-		}
-
-		rc = ena_com_indirect_table_set(ena_dev);
-		if (rc) {
-			netif_err(adapter, drv, netdev,
-				  "Cannot set indirect table\n");
-			return rc == -EPERM ? -EOPNOTSUPP : rc;
-		}
+		rc = ena_indirection_table_set(adapter, indir);
+		if (rc)
+			return rc;
 	}
 
 	switch (hfunc) {
diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.h b/drivers/net/ethernet/amazon/ena/ena_netdev.h
index bffd778f2..2fe5eeea6 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.h
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.h
@@ -129,6 +129,8 @@
 
 #define ENA_IO_TXQ_IDX(q)	(2 * (q))
 #define ENA_IO_RXQ_IDX(q)	(2 * (q) + 1)
+#define ENA_IO_TXQ_IDX_TO_COMBINED_IDX(q)	((q) / 2)
+#define ENA_IO_RXQ_IDX_TO_COMBINED_IDX(q)	(((q) - 1) / 2)
 
 #define ENA_MGMNT_IRQ_IDX		0
 #define ENA_IO_IRQ_FIRST_IDX		1
-- 
2.24.1.AMZN


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH V1 net 08/11] net: ena: fix corruption of dev_idx_to_host_tbl
  2020-01-29 14:04 [PATCH V1 net 00/11] Bug fixes for ENA Ethernet driver Sameeh Jubran
                   ` (6 preceding siblings ...)
  2020-01-29 14:04 ` [PATCH V1 net 07/11] net: ena: fix incorrectly saving queue numbers when setting RSS " Sameeh Jubran
@ 2020-01-29 14:04 ` Sameeh Jubran
  2020-01-29 14:04 ` [PATCH V1 net 09/11] net: ena: make ena rxfh support ETH_RSS_HASH_NO_CHANGE Sameeh Jubran
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 15+ messages in thread
From: Sameeh Jubran @ 2020-01-29 14:04 UTC (permalink / raw)
  To: davem, netdev
  Cc: Arthur Kiyanovski, dwmw, zorik, matua, saeedb, msw, aliguori,
	nafea, gtzalik, netanel, alisaidi, benh, sameehj, ndagan

From: Arthur Kiyanovski <akiyano@amazon.com>

The function ena_com_ind_tbl_convert_from_device() has an overflow
bug as explained below. Either way, this function is not needed at
all since we don't retrieve the indirection table from the device
at any point which means that this conversion is not needed.

The bug:
The for loop iterates over all io_sq_queues, when passing the actual
number of used queues the io_sq_queues[i].idx equals 0 since they are
uninitialized which results in the following code to be executed till
the end of the loop:

dev_idx_to_host_tbl[0] = i;

This results dev_idx_to_host_tbl[0] in being equal to
ENA_TOTAL_NUM_QUEUES - 1.

Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
Signed-off-by: Sameeh Jubran <sameehj@amazon.com>
Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>
---
 drivers/net/ethernet/amazon/ena/ena_com.c | 28 -----------------------
 1 file changed, 28 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c b/drivers/net/ethernet/amazon/ena/ena_com.c
index 8bcf76f92..b05c3eb81 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_com.c
@@ -1276,30 +1276,6 @@ static int ena_com_ind_tbl_convert_to_device(struct ena_com_dev *ena_dev)
 	return 0;
 }
 
-static int ena_com_ind_tbl_convert_from_device(struct ena_com_dev *ena_dev)
-{
-	u16 dev_idx_to_host_tbl[ENA_TOTAL_NUM_QUEUES] = { (u16)-1 };
-	struct ena_rss *rss = &ena_dev->rss;
-	u8 idx;
-	u16 i;
-
-	for (i = 0; i < ENA_TOTAL_NUM_QUEUES; i++)
-		dev_idx_to_host_tbl[ena_dev->io_sq_queues[i].idx] = i;
-
-	for (i = 0; i < 1 << rss->tbl_log_size; i++) {
-		if (rss->rss_ind_tbl[i].cq_idx > ENA_TOTAL_NUM_QUEUES)
-			return -EINVAL;
-		idx = (u8)rss->rss_ind_tbl[i].cq_idx;
-
-		if (dev_idx_to_host_tbl[idx] > ENA_TOTAL_NUM_QUEUES)
-			return -EINVAL;
-
-		rss->host_rss_ind_tbl[i] = dev_idx_to_host_tbl[idx];
-	}
-
-	return 0;
-}
-
 static void ena_com_update_intr_delay_resolution(struct ena_com_dev *ena_dev,
 						 u16 intr_delay_resolution)
 {
@@ -2641,10 +2617,6 @@ int ena_com_indirect_table_get(struct ena_com_dev *ena_dev, u32 *ind_tbl)
 	if (!ind_tbl)
 		return 0;
 
-	rc = ena_com_ind_tbl_convert_from_device(ena_dev);
-	if (unlikely(rc))
-		return rc;
-
 	for (i = 0; i < (1 << rss->tbl_log_size); i++)
 		ind_tbl[i] = rss->host_rss_ind_tbl[i];
 
-- 
2.24.1.AMZN


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH V1 net 09/11] net: ena: make ena rxfh support ETH_RSS_HASH_NO_CHANGE
  2020-01-29 14:04 [PATCH V1 net 00/11] Bug fixes for ENA Ethernet driver Sameeh Jubran
                   ` (7 preceding siblings ...)
  2020-01-29 14:04 ` [PATCH V1 net 08/11] net: ena: fix corruption of dev_idx_to_host_tbl Sameeh Jubran
@ 2020-01-29 14:04 ` Sameeh Jubran
  2020-01-29 14:04 ` [PATCH V1 net 10/11] net: ena: ethtool: use correct value for crc32 hash Sameeh Jubran
  2020-01-29 14:04 ` [PATCH V1 net 11/11] net: ena: ena-com.c: prevent NULL pointer dereference Sameeh Jubran
  10 siblings, 0 replies; 15+ messages in thread
From: Sameeh Jubran @ 2020-01-29 14:04 UTC (permalink / raw)
  To: davem, netdev
  Cc: Arthur Kiyanovski, dwmw, zorik, matua, saeedb, msw, aliguori,
	nafea, gtzalik, netanel, alisaidi, benh, sameehj, ndagan

From: Arthur Kiyanovski <akiyano@amazon.com>

As the name suggests ETH_RSS_HASH_NO_CHANGE is received upon changing
the key or indirection table using ethtool while keeping the same hash
function.

Also add a function for retrieving the current hash function from
the ena-com layer.

Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
Signed-off-by: Sameeh Jubran <sameehj@amazon.com>
Signed-off-by: Saeed Bshara <saeedb@amazon.com>
Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>
---
 drivers/net/ethernet/amazon/ena/ena_com.c     | 5 +++++
 drivers/net/ethernet/amazon/ena/ena_com.h     | 8 ++++++++
 drivers/net/ethernet/amazon/ena/ena_ethtool.c | 3 +++
 3 files changed, 16 insertions(+)

diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c b/drivers/net/ethernet/amazon/ena/ena_com.c
index b05c3eb81..43ba30081 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_com.c
@@ -1050,6 +1050,11 @@ static int ena_com_get_feature(struct ena_com_dev *ena_dev,
 				      feature_ver);
 }
 
+int ena_com_get_current_hash_function(struct ena_com_dev *ena_dev)
+{
+	return ena_dev->rss.hash_func;
+}
+
 static void ena_com_hash_key_fill_default_key(struct ena_com_dev *ena_dev)
 {
 	struct ena_admin_feature_rss_flow_hash_control *hash_key =
diff --git a/drivers/net/ethernet/amazon/ena/ena_com.h b/drivers/net/ethernet/amazon/ena/ena_com.h
index ea925bb01..279b06282 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.h
+++ b/drivers/net/ethernet/amazon/ena/ena_com.h
@@ -656,6 +656,14 @@ int ena_com_rss_init(struct ena_com_dev *ena_dev, u16 log_size);
  */
 void ena_com_rss_destroy(struct ena_com_dev *ena_dev);
 
+/* ena_com_get_current_hash_function - Get RSS hash function
+ * @ena_dev: ENA communication layer struct
+ *
+ * Return the current hash function.
+ * @return: 0 or one of the ena_admin_hash_functions values.
+ */
+int ena_com_get_current_hash_function(struct ena_com_dev *ena_dev);
+
 /* ena_com_fill_hash_function - Fill RSS hash function
  * @ena_dev: ENA communication layer struct
  * @func: The hash function (Toeplitz or crc)
diff --git a/drivers/net/ethernet/amazon/ena/ena_ethtool.c b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
index accc4c8d1..170a2c12c 100644
--- a/drivers/net/ethernet/amazon/ena/ena_ethtool.c
+++ b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
@@ -738,6 +738,9 @@ static int ena_set_rxfh(struct net_device *netdev, const u32 *indir,
 	}
 
 	switch (hfunc) {
+	case ETH_RSS_HASH_NO_CHANGE:
+		func = ena_com_get_current_hash_function(ena_dev);
+		break;
 	case ETH_RSS_HASH_TOP:
 		func = ENA_ADMIN_TOEPLITZ;
 		break;
-- 
2.24.1.AMZN


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH V1 net 10/11] net: ena: ethtool: use correct value for crc32 hash
  2020-01-29 14:04 [PATCH V1 net 00/11] Bug fixes for ENA Ethernet driver Sameeh Jubran
                   ` (8 preceding siblings ...)
  2020-01-29 14:04 ` [PATCH V1 net 09/11] net: ena: make ena rxfh support ETH_RSS_HASH_NO_CHANGE Sameeh Jubran
@ 2020-01-29 14:04 ` Sameeh Jubran
  2020-01-29 14:04 ` [PATCH V1 net 11/11] net: ena: ena-com.c: prevent NULL pointer dereference Sameeh Jubran
  10 siblings, 0 replies; 15+ messages in thread
From: Sameeh Jubran @ 2020-01-29 14:04 UTC (permalink / raw)
  To: davem, netdev
  Cc: Sameeh Jubran, dwmw, zorik, matua, saeedb, msw, aliguori, nafea,
	gtzalik, netanel, alisaidi, benh, akiyano, ndagan

Up till kernel 4.11 there was no enum defined for crc32 hash in ethtool,
thus the xor enum was used for supporting crc32.

Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
Signed-off-by: Sameeh Jubran <sameehj@amazon.com>
---
 drivers/net/ethernet/amazon/ena/ena_ethtool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_ethtool.c b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
index 170a2c12c..5e8d0c57e 100644
--- a/drivers/net/ethernet/amazon/ena/ena_ethtool.c
+++ b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
@@ -709,7 +709,7 @@ static int ena_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
 		func = ETH_RSS_HASH_TOP;
 		break;
 	case ENA_ADMIN_CRC32:
-		func = ETH_RSS_HASH_XOR;
+		func = ETH_RSS_HASH_CRC32;
 		break;
 	default:
 		netif_err(adapter, drv, netdev,
@@ -744,7 +744,7 @@ static int ena_set_rxfh(struct net_device *netdev, const u32 *indir,
 	case ETH_RSS_HASH_TOP:
 		func = ENA_ADMIN_TOEPLITZ;
 		break;
-	case ETH_RSS_HASH_XOR:
+	case ETH_RSS_HASH_CRC32:
 		func = ENA_ADMIN_CRC32;
 		break;
 	default:
-- 
2.24.1.AMZN


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH V1 net 11/11] net: ena: ena-com.c: prevent NULL pointer dereference
  2020-01-29 14:04 [PATCH V1 net 00/11] Bug fixes for ENA Ethernet driver Sameeh Jubran
                   ` (9 preceding siblings ...)
  2020-01-29 14:04 ` [PATCH V1 net 10/11] net: ena: ethtool: use correct value for crc32 hash Sameeh Jubran
@ 2020-01-29 14:04 ` Sameeh Jubran
  10 siblings, 0 replies; 15+ messages in thread
From: Sameeh Jubran @ 2020-01-29 14:04 UTC (permalink / raw)
  To: davem, netdev
  Cc: Arthur Kiyanovski, dwmw, zorik, matua, saeedb, msw, aliguori,
	nafea, gtzalik, netanel, alisaidi, benh, sameehj, ndagan

From: Arthur Kiyanovski <akiyano@amazon.com>

comp_ctx can be NULL in a very rare case when an admin command is executed
during the execution of ena_remove().

The bug scenario is as follows:

* ena_destroy_device() sets the comp_ctx to be NULL
* An admin command is executed before executing unregister_netdev(),
  this can still happen because our device can still receive callbacks
  from the netdev infrastructure such as ethtool commands.
* When attempting to access the comp_ctx, the bug occurs since it's set
  to NULL

Fix:
Added a check that comp_ctx is not NULL

Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
Signed-off-by: Sameeh Jubran <sameehj@amazon.com>
Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>
---
 drivers/net/ethernet/amazon/ena/ena_com.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c b/drivers/net/ethernet/amazon/ena/ena_com.c
index 43ba30081..a7061718e 100644
--- a/drivers/net/ethernet/amazon/ena/ena_com.c
+++ b/drivers/net/ethernet/amazon/ena/ena_com.c
@@ -209,6 +209,11 @@ static void comp_ctxt_release(struct ena_com_admin_queue *queue,
 static struct ena_comp_ctx *get_comp_ctxt(struct ena_com_admin_queue *queue,
 					  u16 command_id, bool capture)
 {
+	if (unlikely(!queue->comp_ctx)) {
+		pr_err("Completion context is NULL\n");
+		return NULL;
+	}
+
 	if (unlikely(command_id >= queue->q_depth)) {
 		pr_err("command id is larger than the queue size. cmd_id: %u queue size %d\n",
 		       command_id, queue->q_depth);
-- 
2.24.1.AMZN


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH V1 net 04/11] net: ena: fix incorrect default RSS key
  2020-01-29 14:04 ` [PATCH V1 net 04/11] net: ena: fix incorrect default RSS key Sameeh Jubran
@ 2020-01-29 16:03   ` Jakub Kicinski
  2020-02-03 13:59     ` Jubran, Samih
  0 siblings, 1 reply; 15+ messages in thread
From: Jakub Kicinski @ 2020-01-29 16:03 UTC (permalink / raw)
  To: Sameeh Jubran
  Cc: davem, netdev, Arthur Kiyanovski, dwmw, zorik, matua, saeedb,
	msw, aliguori, nafea, gtzalik, netanel, alisaidi, benh, ndagan

On Wed, 29 Jan 2020 14:04:15 +0000, Sameeh Jubran wrote:
> From: Arthur Kiyanovski <akiyano@amazon.com>
> 
> Bug description:
> When running "ethtool -x <if_name>" the key shows up as all zeros.
> 
> When we use "ethtool -X <if_name> hfunc toeplitz hkey <some:random:key>" to
> set the key and then try to retrieve it using "ethtool -x <if_name>" then
> we return the correct key because we return the one we saved.
> 
> Bug cause:
> We don't fetch the key from the device but instead return the key
> that we have saved internally which is by default set to zero upon
> allocation.
> 
> Fix:
> This commit fixes the issue by initializing the key to the default key that
> is used by the device.
> 
> Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
> Signed-off-by: Sameeh Jubran <sameehj@amazon.com>
> Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>

So is the device actually using that key by default?

Hard coding a default RSS key makes it trivial for DDoS attackers 
to target specific queues, doesn't it?

Please follow the best practice of initializing your key with
netdev_rss_key_fill() and configuring the device with it at startup.

> diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c b/drivers/net/ethernet/amazon/ena/ena_com.c
> index e54c44fdc..769339043 100644
> --- a/drivers/net/ethernet/amazon/ena/ena_com.c
> +++ b/drivers/net/ethernet/amazon/ena/ena_com.c
> @@ -64,6 +64,15 @@
>  
>  #define ENA_POLL_MS	5
>  
> +/* Default Microsoft RSS key, used for HRSS. */
> +static const u8 rss_hash_key[ENA_HASH_KEY_SIZE] = {
> +		0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
> +		0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0,
> +		0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4,
> +		0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
> +		0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa

You also have an extra tab here for no reason.

> +};
> +
>  /*****************************************************************************/
>  /*****************************************************************************/
>  /*****************************************************************************/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH V1 net 07/11] net: ena: fix incorrectly saving queue numbers when setting RSS indirection table
  2020-01-29 14:04 ` [PATCH V1 net 07/11] net: ena: fix incorrectly saving queue numbers when setting RSS " Sameeh Jubran
@ 2020-01-29 16:07   ` Jakub Kicinski
  0 siblings, 0 replies; 15+ messages in thread
From: Jakub Kicinski @ 2020-01-29 16:07 UTC (permalink / raw)
  To: Sameeh Jubran
  Cc: davem, netdev, Arthur Kiyanovski, dwmw, zorik, matua, saeedb,
	msw, aliguori, nafea, gtzalik, netanel, alisaidi, benh, ndagan

On Wed, 29 Jan 2020 14:04:18 +0000, Sameeh Jubran wrote:
> Also move the set code to a standalone function for code clarity.

This is unrelated, and should not be a part of a fix. Fixes are
supposed to be small, please never do code refactoring in them.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* RE: [PATCH V1 net 04/11] net: ena: fix incorrect default RSS key
  2020-01-29 16:03   ` Jakub Kicinski
@ 2020-02-03 13:59     ` Jubran, Samih
  0 siblings, 0 replies; 15+ messages in thread
From: Jubran, Samih @ 2020-02-03 13:59 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: davem, netdev, Kiyanovski, Arthur, Woodhouse, David, Machulsky,
	Zorik, Matushevsky, Alexander, Bshara, Saeed, Wilson, Matt,
	Liguori, Anthony, Bshara, Nafea, Tzalik, Guy, Belgazal, Netanel,
	Saidi, Ali, Herrenschmidt, Benjamin, Dagan, Noam



> -----Original Message-----
> From: Jakub Kicinski <kuba@kernel.org>
> Sent: Wednesday, January 29, 2020 6:03 PM
> To: Jubran, Samih <sameehj@amazon.com>
> Cc: davem@davemloft.net; netdev@vger.kernel.org; Kiyanovski, Arthur
> <akiyano@amazon.com>; Woodhouse, David <dwmw@amazon.co.uk>;
> Machulsky, Zorik <zorik@amazon.com>; Matushevsky, Alexander
> <matua@amazon.com>; Bshara, Saeed <saeedb@amazon.com>; Wilson,
> Matt <msw@amazon.com>; Liguori, Anthony <aliguori@amazon.com>;
> Bshara, Nafea <nafea@amazon.com>; Tzalik, Guy <gtzalik@amazon.com>;
> Belgazal, Netanel <netanel@amazon.com>; Saidi, Ali
> <alisaidi@amazon.com>; Herrenschmidt, Benjamin <benh@amazon.com>;
> Dagan, Noam <ndagan@amazon.com>
> Subject: Re: [PATCH V1 net 04/11] net: ena: fix incorrect default RSS key
> 
> On Wed, 29 Jan 2020 14:04:15 +0000, Sameeh Jubran wrote:
> > From: Arthur Kiyanovski <akiyano@amazon.com>
> >
> > Bug description:
> > When running "ethtool -x <if_name>" the key shows up as all zeros.
> >
> > When we use "ethtool -X <if_name> hfunc toeplitz hkey
> > <some:random:key>" to set the key and then try to retrieve it using
> > "ethtool -x <if_name>" then we return the correct key because we return
> the one we saved.
> >
> > Bug cause:
> > We don't fetch the key from the device but instead return the key that
> > we have saved internally which is by default set to zero upon
> > allocation.
> >
> > Fix:
> > This commit fixes the issue by initializing the key to the default key
> > that is used by the device.
> >
> > Fixes: 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic
> > Network Adapters (ENA)")
> > Signed-off-by: Sameeh Jubran <sameehj@amazon.com>
> > Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>
> 
> So is the device actually using that key by default?
> 
> Hard coding a default RSS key makes it trivial for DDoS attackers to target
> specific queues, doesn't it?
> 
> Please follow the best practice of initializing your key with
> netdev_rss_key_fill() and configuring the device with it at startup.
> 
> > diff --git a/drivers/net/ethernet/amazon/ena/ena_com.c
> > b/drivers/net/ethernet/amazon/ena/ena_com.c
> > index e54c44fdc..769339043 100644
> > --- a/drivers/net/ethernet/amazon/ena/ena_com.c
> > +++ b/drivers/net/ethernet/amazon/ena/ena_com.c
> > @@ -64,6 +64,15 @@
> >
> >  #define ENA_POLL_MS	5
> >
> > +/* Default Microsoft RSS key, used for HRSS. */ static const u8
> > +rss_hash_key[ENA_HASH_KEY_SIZE] = {
> > +		0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2,
> > +		0x41, 0x67, 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0,
> > +		0xd0, 0xca, 0x2b, 0xcb, 0xae, 0x7b, 0x30, 0xb4,
> > +		0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30, 0xf2, 0x0c,
> > +		0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa
> 
> You also have an extra tab here for no reason.
> 
> > +};
> > +
> >
> >
> /**********************************************************
> ***********
> > ********/
> >
> /**********************************************************
> ***********
> > ********/
> >
> /**********************************************************
> ***********
> > ********/

Hi Jakub,

Thanks for your comments,
Will fix ASAP and send v2.

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2020-02-03 13:59 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-29 14:04 [PATCH V1 net 00/11] Bug fixes for ENA Ethernet driver Sameeh Jubran
2020-01-29 14:04 ` [PATCH V1 net 01/11] net: ena: fix potential crash when rxfh key is NULL Sameeh Jubran
2020-01-29 14:04 ` [PATCH V1 net 02/11] net: ena: fix uses of round_jiffies() Sameeh Jubran
2020-01-29 14:04 ` [PATCH V1 net 03/11] net: ena: add missing ethtool TX timestamping indication Sameeh Jubran
2020-01-29 14:04 ` [PATCH V1 net 04/11] net: ena: fix incorrect default RSS key Sameeh Jubran
2020-01-29 16:03   ` Jakub Kicinski
2020-02-03 13:59     ` Jubran, Samih
2020-01-29 14:04 ` [PATCH V1 net 05/11] net: ena: rss: store hash function as values and not bits Sameeh Jubran
2020-01-29 14:04 ` [PATCH V1 net 06/11] net: ena: rss: fix failure to get indirection table Sameeh Jubran
2020-01-29 14:04 ` [PATCH V1 net 07/11] net: ena: fix incorrectly saving queue numbers when setting RSS " Sameeh Jubran
2020-01-29 16:07   ` Jakub Kicinski
2020-01-29 14:04 ` [PATCH V1 net 08/11] net: ena: fix corruption of dev_idx_to_host_tbl Sameeh Jubran
2020-01-29 14:04 ` [PATCH V1 net 09/11] net: ena: make ena rxfh support ETH_RSS_HASH_NO_CHANGE Sameeh Jubran
2020-01-29 14:04 ` [PATCH V1 net 10/11] net: ena: ethtool: use correct value for crc32 hash Sameeh Jubran
2020-01-29 14:04 ` [PATCH V1 net 11/11] net: ena: ena-com.c: prevent NULL pointer dereference Sameeh Jubran

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).