Skip to contentSkip to conversation

Bug fixes for ENA Ethernet driver

PATCH In review [email protected] 2 participants 10 messages May 1, 2019 – May 4, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Bug fixes for ENA Ethernet driver

From: Sameeh Jubran <[email protected]>

Sameeh Jubran (8):
net: ena: fix swapped parameters when calling
ena_com_indirect_table_fill_entry
net: ena: fix: set freed objects to NULL to avoid failing future
allocations
net: ena: fix: Free napi resources when ena_up() fails
net: ena: fix incorrect test of supported hash function
net: ena: fix return value of ena_com_config_llq_info()
net: ena: improve latency by disabling adaptive interrupt moderation
by default
net: ena: fix ena_com_fill_hash_function() implementation
net: ena: gcc 8: fix compilation warning

 drivers/net/ethernet/amazon/ena/ena_com.c     | 11 ++++++--
 drivers/net/ethernet/amazon/ena/ena_ethtool.c |  4 +--
 drivers/net/ethernet/amazon/ena/ena_netdev.c  | 28 +++++++++++--------
 3 files changed, 27 insertions(+), 16 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/8 net: ena: fix swapped parameters when calling ena_com_indirect_table_fill_entry

From: Sameeh Jubran <[email protected]>

second parameter should be the index of the table rather than the value.

Fixes 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
---
 drivers/net/ethernet/amazon/ena/ena_ethtool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/amazon/ena/ena_ethtool.c +2 -2
index f3a5a384e6e8..fe596bc30a96 100644
@@ -697,8 +697,8 @@ static int ena_set_rxfh(struct net_device *netdev, const u32 *indir,
 	if (indir) {
 		for (i = 0; i < ENA_RX_RSS_TABLE_SIZE; i++) {
 			rc = ena_com_indirect_table_fill_entry(ena_dev,
-							       ENA_IO_RXQ_IDX(indir[i]),
-							       i);
+							       i,
+							       ENA_IO_RXQ_IDX(indir[i]));
 			if (unlikely(rc)) {
 				netif_err(adapter, drv, netdev,
 					  "Cannot fill indirect table (index is too large)\n");
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/8 net: ena: fix: set freed objects to NULL to avoid failing future allocations

In reply to [email protected]

From: Sameeh Jubran <[email protected]>

In some cases when a queue related allocation fails, successful past allocations are freed but the pointer that pointed to them is not set to NULL. This is a problem for 2 reasons:
1. This is generally a bad practice since this pointer might be accidentally accessed in the future.
2. Future allocations using the same pointer check if the pointer is NULL and fail if it is not.

Fixed this by setting such pointers to NULL in the allocation of queue related objects.

Also refactored the code of ena_setup_tx_resources() to goto-style error handling to avoid code duplication of resource freeing.

Fixes 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 25 ++++++++++++--------
 1 file changed, 15 insertions(+), 10 deletions(-)
drivers/net/ethernet/amazon/ena/ena_netdev.c +15 -10
index a6eacf2099c3..dbcd58ebd0a9 100644
@@ -224,28 +224,23 @@ static int ena_setup_tx_resources(struct ena_adapter *adapter, int qid)
 	if (!tx_ring->tx_buffer_info) {
 		tx_ring->tx_buffer_info = vzalloc(size);
 		if (!tx_ring->tx_buffer_info)
-			return -ENOMEM;
+			goto err_tx_buffer_info;
 	}
 
 	size = sizeof(u16) * tx_ring->ring_size;
 	tx_ring->free_tx_ids = vzalloc_node(size, node);
 	if (!tx_ring->free_tx_ids) {
 		tx_ring->free_tx_ids = vzalloc(size);
-		if (!tx_ring->free_tx_ids) {
-			vfree(tx_ring->tx_buffer_info);
-			return -ENOMEM;
-		}
+		if (!tx_ring->free_tx_ids)
+			goto err_free_tx_ids;
 	}
 
 	size = tx_ring->tx_max_header_size;
 	tx_ring->push_buf_intermediate_buf = vzalloc_node(size, node);
 	if (!tx_ring->push_buf_intermediate_buf) {
 		tx_ring->push_buf_intermediate_buf = vzalloc(size);
-		if (!tx_ring->push_buf_intermediate_buf) {
-			vfree(tx_ring->tx_buffer_info);
-			vfree(tx_ring->free_tx_ids);
-			return -ENOMEM;
-		}
+		if (!tx_ring->push_buf_intermediate_buf)
+			goto err_push_buf_intermediate_buf;
 	}
 
 	/* Req id ring for TX out of order completions */
@@ -259,6 +254,15 @@ static int ena_setup_tx_resources(struct ena_adapter *adapter, int qid)
 	tx_ring->next_to_clean = 0;
 	tx_ring->cpu = ena_irq->cpu;
 	return 0;
+
+err_push_buf_intermediate_buf:
+	vfree(tx_ring->free_tx_ids);
+	tx_ring->free_tx_ids = NULL;
+err_free_tx_ids:
+	vfree(tx_ring->tx_buffer_info);
+	tx_ring->tx_buffer_info = NULL;
+err_tx_buffer_info:
+	return -ENOMEM;
 }
 
 /* ena_free_tx_resources - Free I/O Tx Resources per Queue
@@ -378,6 +382,7 @@ static int ena_setup_rx_resources(struct ena_adapter *adapter,
 		rx_ring->free_rx_ids = vzalloc(size);
 		if (!rx_ring->free_rx_ids) {
 			vfree(rx_ring->rx_buffer_info);
+			rx_ring->rx_buffer_info = NULL;
 			return -ENOMEM;
 		}
 	}
Signature · 1 line
2.17.1
#3 lore raw

PATCH 3/8 net: ena: fix: Free napi resources when ena_up() fails

In reply to [email protected]

From: Sameeh Jubran <[email protected]>

ena_up() calls ena_init_napi() but does not call ena_del_napi() in case of failure. This causes a segmentation fault upon rmmod when netif_napi_del() is called. Fix this bug by calling ena_del_napi() before returning error from ena_up().

Fixes 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/amazon/ena/ena_netdev.c +1 -0
index dbcd58ebd0a9..03244155f74c 100644
@@ -1825,6 +1825,7 @@ static int ena_up(struct ena_adapter *adapter)
 err_setup_tx:
 	ena_free_io_irq(adapter);
 err_req_irq:
+	ena_del_napi(adapter);
 
 	return rc;
 }
Signature · 1 line
2.17.1
#4 lore raw

PATCH 4/8 net: ena: fix incorrect test of supported hash function

In reply to [email protected]

From: Sameeh Jubran <[email protected]>

ena_com_set_hash_function() tests if a hash function is supported by the device before setting it.
The test returns the opposite result than needed. Reverse the condition to return the correct value.
Also use the BIT macro instead of inline shift.

Fixes 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
---
 drivers/net/ethernet/amazon/ena/ena_com.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/amazon/ena/ena_com.c +1 -1
index b17d435de09f..f9bc0b831a1a 100644
@@ -2195,7 +2195,7 @@ int ena_com_set_hash_function(struct ena_com_dev *ena_dev)
 	if (unlikely(ret))
 		return ret;
 
-	if (get_resp.u.flow_hash_func.supported_func & (1 << rss->hash_func)) {
+	if (!(get_resp.u.flow_hash_func.supported_func & BIT(rss->hash_func))) {
 		pr_err("Func hash %d isn't supported by device, abort\n",
 		       rss->hash_func);
 		return -EOPNOTSUPP;
Signature · 1 line
2.17.1
#5 lore raw

PATCH 5/8 net: ena: fix return value of ena_com_config_llq_info()

In reply to [email protected]

From: Sameeh Jubran <[email protected]>

ena_com_config_llq_info() returns 0 even if ena_com_set_llq() fails. Return the failure code of ena_com_set_llq() in case it fails.

Fixes 689b2bdaaa14 ("net: ena: add functions for handling Low Latency Queues in ena_com")
---
 drivers/net/ethernet/amazon/ena/ena_com.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/amazon/ena/ena_com.c +1 -1
index f9bc0b831a1a..4fe437fe771b 100644
@@ -731,7 +731,7 @@ static int ena_com_config_llq_info(struct ena_com_dev *ena_dev,
 	if (rc)
 		pr_err("Cannot set LLQ configuration: %d\n", rc);
 
-	return 0;
+	return rc;
 }
 
 static int ena_com_wait_and_process_admin_cq_interrupts(struct ena_comp_ctx *comp_ctx,
Signature · 1 line
2.17.1
#6 lore raw

PATCH 6/8 net: ena: improve latency by disabling adaptive interrupt moderation by default

In reply to [email protected]

From: Sameeh Jubran <[email protected]>

Adaptive interrupt moderation was erroneously enabled by default in the driver.

In case the device supports adaptive interrupt moderation it will be automatically used, which may potentially increase latency.

The adaptive moderation can be enabled from ethtool command in case the feature is supported by the device.

Fixes 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
---
 drivers/net/ethernet/amazon/ena/ena_com.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/ethernet/amazon/ena/ena_com.c +5 -1
index 4fe437fe771b..677d31abf214 100644
@@ -2802,7 +2802,11 @@ int ena_com_init_interrupt_moderation(struct ena_com_dev *ena_dev)
 	/* if moderation is supported by device we set adaptive moderation */
 	delay_resolution = get_resp.u.intr_moderation.intr_delay_resolution;
 	ena_com_update_intr_delay_resolution(ena_dev, delay_resolution);
-	ena_com_enable_adaptive_moderation(ena_dev);
+
+	/* Disable adaptive moderation by default - can be enabled from
+	 * ethtool
+	 */
+	ena_com_disable_adaptive_moderation(ena_dev);
 
 	return 0;
 err:
Signature · 1 line
2.17.1
#7 lore raw

PATCH 7/8 net: ena: fix ena_com_fill_hash_function() implementation

In reply to [email protected]

From: Sameeh Jubran <[email protected]>

ena_com_fill_hash_function() didn't configure the rss->hash_func.

Fixes 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
---
 drivers/net/ethernet/amazon/ena/ena_com.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/ethernet/amazon/ena/ena_com.c +1 -0
index 677d31abf214..4cdd8459c37e 100644
@@ -2280,6 +2280,7 @@ int ena_com_fill_hash_function(struct ena_com_dev *ena_dev,
 		return -EINVAL;
 	}
 
+	rss->hash_func = func;
 	rc = ena_com_set_hash_function(ena_dev);
 
 	/* Restore the old function */
Signature · 1 line
2.17.1
#8 lore raw

PATCH 8/8 net: ena: gcc 8: fix compilation warning

In reply to [email protected]

From: Sameeh Jubran <[email protected]>

GCC 8 contains a number of new warnings as well as enhancements to existing checkers. The warning - Wstringop-truncation - warns for calls to bounded string manipulation functions such as strncat, strncpy, and stpncpy that may either truncate the copied string or leave the destination unchanged.

In our case the destination string length (32 bytes) is much shorter than the source string (64 bytes) which causes this warning to show up. In general the destination has to be at least a byte larger than the length of the source string with strncpy for this warning not to showup.

This can be easily fixed by using strlcpy instead which already does the truncation to the string. Documentation for this function can be found here:

https://elixir.bootlin.com/linux/latest/source/lib/string.c#L141

Fixes 1738cd3ed342 ("net: ena: Add a driver for Amazon Elastic Network Adapters (ENA)")
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/amazon/ena/ena_netdev.c +1 -1
index 03244155f74c..bc5997a5f809 100644
@@ -2298,7 +2298,7 @@ static void ena_config_host_info(struct ena_com_dev *ena_dev,
 	host_info->bdf = (pdev->bus->number << 8) | pdev->devfn;
 	host_info->os_type = ENA_ADMIN_OS_LINUX;
 	host_info->kernel_ver = LINUX_VERSION_CODE;
-	strncpy(host_info->kernel_ver_str, utsname()->version,
+	strlcpy(host_info->kernel_ver_str, utsname()->version,
 		sizeof(host_info->kernel_ver_str) - 1);
 	host_info->os_dist = 0;
 	strncpy(host_info->os_dist_str, utsname()->release,
Signature · 1 line
2.17.1
maintainer
#9 lore raw
In reply to [email protected]

From: <[email protected]>
Date: Wed, 1 May 2019 16:47:02 +0300

Quoted 14 lines

From: Sameeh Jubran <[email protected]>

Sameeh Jubran (8):
net: ena: fix swapped parameters when calling
ena_com_indirect_table_fill_entry
net: ena: fix: set freed objects to NULL to avoid failing future
allocations
net: ena: fix: Free napi resources when ena_up() fails
net: ena: fix incorrect test of supported hash function
net: ena: fix return value of ena_com_config_llq_info()
net: ena: improve latency by disabling adaptive interrupt moderation
by default
net: ena: fix ena_com_fill_hash_function() implementation
net: ena: gcc 8: fix compilation warning

Series applied.

Please provide a real commit message in your header posting next time, rather than just the shortlog.

Thank you.