Bug fixes for ENA Ethernet driver
Subsystems (3)
PATCH v2 4/12 net: ena: fix incorrect default RSS key
In reply to [email protected]From: Arthur Kiyanovski <[email protected]>
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 a random value using netdev_rss_key_fill().
--- drivers/net/ethernet/amazon/ena/ena_com.c | 15 +++++++++++++++ drivers/net/ethernet/amazon/ena/ena_com.h | 1 + 2 files changed, 16 insertions(+)
drivers/net/ethernet/amazon/ena/ena_com.c +15 -0
@@ -1041,6 +1041,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; + +netdev_rss_key_fill (&hash_key->key,sizeof (hash_key->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 (hash_key->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 +2644,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;
drivers/net/ethernet/amazon/ena/ena_com.h +1 -0
@@ -44,6 +44,7 @@#include <linux/spinlock.h> #include <linux/types.h> #include <linux/wait.h> +#include <linux/netdevice.h> #include "ena_common_defs.h" #include "ena_admin_defs.h"
Signature · 1 line
2.24.1.AMZN
PATCH v2 5/12 net: ena: rss: do not allocate key when not supported
In reply to [email protected]From: Sameeh Jubran <[email protected]>
Currently we allocate the key whether the device supports setting the key or not. This commit adds a check to the allocation function and handles the error accordingly.
--- drivers/net/ethernet/amazon/ena/ena_com.c | 24 ++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
drivers/net/ethernet/amazon/ena/ena_com.c +21 -3
@@ -1057,6 +1057,20 @@ static void ena_com_hash_key_fill_default_key(struct ena_com_dev *ena_dev)static int ena_com_hash_key_allocate (struct ena_com_dev *ena_dev) {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; +int rc; + + hash_key = (ena_dev->rss).hash_key; + + rc =ena_com_get_feature_ex (ena_dev, &get_resp, +ENA_ADMIN_RSS_HASH_FUNCTION , + ena_dev->rss.hash_key_dma_addr, +sizeof (ena_dev->rss.hash_key),0 ); +if (unlikely (rc)) { + hash_key =NULL ; +return -EOPNOTSUPP ; + } rss->hash_key = dma_alloc_coherent(ena_dev->dmadev, sizeof(*rss->hash_key),
@@ -2640,11 +2654,15 @@ int ena_com_rss_init(struct ena_com_dev *ena_dev, u16 indr_tbl_log_size)if (unlikely (rc)) goto err_indr_tbl; +/* The following function might return unsupported in case the +* device doesn't support setting the key / hash function. We can safely +* ignore this error and have indirection table support only. +*/ rc =ena_com_hash_key_allocate (ena_dev); -if (unlikely (rc)) +if (unlikely (rc) && rc != -EOPNOTSUPP ) goto err_hash_key; - -ena_com_hash_key_fill_default_key (ena_dev); +else if (rc != -EOPNOTSUPP ) +ena_com_hash_key_fill_default_key (ena_dev); rc =ena_com_hash_ctrl_init (ena_dev);if (unlikely (rc))
Signature · 1 line
2.24.1.AMZN
v2 cover Bug fixes for ENA Ethernet driver
From: Sameeh Jubran <[email protected]>
Difference from V1:
* Started using netdev_rss_key_fill()
* Dropped superflous changes that are not related to bug fixes as requested by Jakub
Arthur Kiyanovski (9):
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: 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 (3):
net: ena: rss: do not allocate key when not supported
net: ena: rss: fix failure to get indirection table
net: ena: ethtool: use correct value for crc32 hash
drivers/net/ethernet/amazon/ena/ena_com.c | 96 +++++++++++-------- drivers/net/ethernet/amazon/ena/ena_com.h | 9 ++ drivers/net/ethernet/amazon/ena/ena_ethtool.c | 46 ++++++++- drivers/net/ethernet/amazon/ena/ena_netdev.c | 6 +- drivers/net/ethernet/amazon/ena/ena_netdev.h | 2 + 5 files changed, 115 insertions(+), 44 deletions(-)
Signature · 1 line
2.24.1.AMZN
PATCH v2 7/12 net: ena: rss: store hash function as values and not bits
From: Arthur Kiyanovski <[email protected]>
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).
--- 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
@@ -2370,7 +2370,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;
Signature · 1 line
2.24.1.AMZN
PATCH v2 2/12 net: ena: fix uses of round_jiffies()
In reply to [email protected]From: Arthur Kiyanovski <[email protected]>
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().
--- drivers/net/ethernet/amazon/ena/ena_netdev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/amazon/ena/ena_netdev.c +3 -3
@@ -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,
Signature · 1 line
2.24.1.AMZN
PATCH v2 8/12 net: ena: fix incorrectly saving queue numbers when setting RSS indirection table
In reply to [email protected]From: Arthur Kiyanovski <[email protected]>
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 uneven 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.
--- drivers/net/ethernet/amazon/ena/ena_ethtool.c | 24 ++++++++++++++++++- drivers/net/ethernet/amazon/ena/ena_netdev.h | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-)
drivers/net/ethernet/amazon/ena/ena_ethtool.c +23 -1
@@ -636,6 +636,28 @@ static u32 ena_get_rxfh_key_size(struct net_device *netdev)return ENA_HASH_KEY_SIZE ; } +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 +666,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;
drivers/net/ethernet/amazon/ena/ena_netdev.h +2 -0
@@ -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
Signature · 1 line
2.24.1.AMZN
PATCH v2 6/12 net: ena: rss: fix failure to get indirection table
In reply to [email protected]From: Sameeh Jubran <[email protected]>
On old hardware, getting / setting the hash function is not supported while gettting / setting the indirection table is.
This commit enables us to still show the indirection table on older hardwares by setting the hash function and key to NULL.
--- drivers/net/ethernet/amazon/ena/ena_ethtool.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/net/ethernet/amazon/ena/ena_ethtool.c +14 -0
@@ -648,7 +648,21 @@ static int ena_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,if (rc)return rc; +/* We call this function in order to check if the device +* supports getting/setting the hash function. +*/ rc =ena_com_get_hash_function (adapter->ena_dev, &ena_func, key); + +if (rc) { +if (rc == -EOPNOTSUPP ) { + key =NULL ; + hfunc =NULL ; + rc =0 ; + } + +return rc; + } +if (rc)return rc;
Signature · 1 line
2.24.1.AMZN
PATCH v2 12/12 net: ena: ena-com.c: prevent NULL pointer dereference
In reply to [email protected]From: Arthur Kiyanovski <[email protected]>
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
--- drivers/net/ethernet/amazon/ena/ena_com.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/ethernet/amazon/ena/ena_com.c +5 -0
@@ -200,6 +200,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);
Signature · 1 line
2.24.1.AMZN
PATCH v2 9/12 net: ena: fix corruption of dev_idx_to_host_tbl
In reply to [email protected]From: Arthur Kiyanovski <[email protected]>
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.
--- drivers/net/ethernet/amazon/ena/ena_com.c | 28 ----------------------- 1 file changed, 28 deletions(-)
drivers/net/ethernet/amazon/ena/ena_com.c +0 -28
@@ -1281,30 +1281,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) {
@@ -2638,10 +2614,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];
Signature · 1 line
2.24.1.AMZN
PATCH v2 3/12 net: ena: add missing ethtool TX timestamping indication
In reply to [email protected]From: Arthur Kiyanovski <[email protected]>
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.
--- drivers/net/ethernet/amazon/ena/ena_ethtool.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/amazon/ena/ena_ethtool.c +1 -0
@@ -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)
Signature · 1 line
2.24.1.AMZN
PATCH v2 1/12 net: ena: fix potential crash when rxfh key is NULL
In reply to [email protected]From: Arthur Kiyanovski <[email protected]>
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.
--- drivers/net/ethernet/amazon/ena/ena_com.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/net/ethernet/amazon/ena/ena_com.c +9 -8
@@ -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;
Signature · 1 line
2.24.1.AMZN
PATCH v2 11/12 net: ena: ethtool: use correct value for crc32 hash
In reply to [email protected]From: Sameeh Jubran <[email protected]>
Up till kernel 4.11 there was no enum defined for crc32 hash in ethtool, thus the xor enum was used for supporting crc32.
--- 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
@@ -693,7 +693,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,
@@ -742,7 +742,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 :
Signature · 1 line
2.24.1.AMZN
PATCH v2 10/12 net: ena: make ena rxfh support ETH_RSS_HASH_NO_CHANGE
In reply to [email protected]From: Arthur Kiyanovski <[email protected]>
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.
--- 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(+)
drivers/net/ethernet/amazon/ena/ena_com.c +5 -0
@@ -1041,6 +1041,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 =
drivers/net/ethernet/amazon/ena/ena_com.h +8 -0
@@ -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)
drivers/net/ethernet/amazon/ena/ena_ethtool.c +3 -0
@@ -736,6 +736,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 ;
Signature · 1 line
2.24.1.AMZN
David Miller
maintainerFrom: <[email protected]>
Date: Tue, 11 Feb 2020 15:17:39 +0000
Quoted 6 lines
From: Sameeh Jubran <[email protected]>
Difference from V1:
* Started usingnetdev_rss_key_fill()
* Dropped superflous changes that are not related to bug fixes as requested by Jakub
Series applied, thank you.