Skip to contentSkip to conversation

iavf: check for null in iavf_fix_features

PATCH New Tony Nguyen 2 participants 16 messages Jun 4, 2021 – Nov 1, 2021

Subsystems (2)
lore
Share & tools
lore

Tony Nguyen

author maintainer
#0 lore raw

PATCH 1/8 iavf: check for null in iavf_fix_features

From: Nicholas Nunley <[email protected]>

If the driver has lost contact with the PF then it enters a disabled state and frees adapter->vf_res. However, ndo_fix_features can still be called on the interface, so we need to check for this condition first. Since we have no information on the features at this time simply leave them unmodified and return.

Fixes c4445aedfe09 ("i40evf: Fix VLAN features")
---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +2 -1
index fb4e3fe5cd1b..ad3f804f0e14 100644
@@ -3437,7 +3437,8 @@ static netdev_features_t iavf_fix_features(struct net_device *netdev,
 {
 	struct iavf_adapter *adapter = netdev_priv(netdev);
 
-	if (!(adapter->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
+	if (adapter->vf_res &&
+	    !(adapter->vf_res->vf_cap_flags & VIRTCHNL_VF_OFFLOAD_VLAN))
 		features &= ~(NETIF_F_HW_VLAN_CTAG_TX |
 			      NETIF_F_HW_VLAN_CTAG_RX |
 			      NETIF_F_HW_VLAN_CTAG_FILTER);
Signature · 1 line
2.20.1
author maintainer
#1 lore raw

PATCH 2/8 iavf: free q_vectors before queues in iavf_disable_vf

From: Nicholas Nunley <[email protected]>

iavf_free_queues() clears adapter->num_active_queues, which iavf_free_q_vectors() relies on, so swap the order of these two function calls in iavf_disable_vf(). This resolves a panic encountered when the interface is disabled and then later brought up again after PF communication is restored.

Fixes 65c7006f234c ("i40evf: assign num_active_queues inside i40evf_alloc_queues")
---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +1 -1
index ad3f804f0e14..989de52658dc 100644
@@ -2067,8 +2067,8 @@ static void iavf_disable_vf(struct iavf_adapter *adapter)
 
 	iavf_free_misc_irq(adapter);
 	iavf_reset_interrupt_capability(adapter);
-	iavf_free_queues(adapter);
 	iavf_free_q_vectors(adapter);
+	iavf_free_queues(adapter);
 	memset(adapter->vf_res, 0, IAVF_VIRTCHNL_VF_RESOURCE_SIZE);
 	iavf_shutdown_adminq(&adapter->hw);
 	adapter->netdev->flags &= ~IFF_UP;
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/8 iavf: free q_vectors before queues in iavf_disable_vf

Quoted 15 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Nguyen, Anthony L
Sent: Friday, June 4, 2021 9:49 AM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH net 2/8] iavf: free q_vectors before queues in iavf_disable_vf

From: Nicholas Nunley <[email protected]>

iavf_free_queues() clears adapter->num_active_queues, which iavf_free_q_vectors() relies on, so swap the order of these two function calls in iavf_disable_vf(). This resolves a panic encountered when the interface is disabled and then later brought up again after PF communication is restored.

Quoted 7 lines
Fixes 65c7006f234c ("i40evf: assign num_active_queues inside

i40evf_alloc_queues")

---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
author maintainer
#3 lore raw

PATCH 3/8 iavf: don't clear a lock we don't hold

In reply to Tony Nguyen

From: Nicholas Nunley <[email protected]>

In iavf_configure_clsflower() the function will bail out if it is unable to obtain the crit_section lock in a reasonable time. However, it will clear the lock when exiting, so fix this.

Fixes 640a8af5841f ("i40evf: Reorder configure_clsflower to avoid deadlock on error")
---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +4 -2
index 989de52658dc..58624be64010 100644
@@ -3027,8 +3027,10 @@ static int iavf_configure_clsflower(struct iavf_adapter *adapter,
 
 	while (test_and_set_bit(__IAVF_IN_CRITICAL_TASK,
 				&adapter->crit_section)) {
-		if (--count == 0)
-			goto err;
+		if (--count == 0) {
+			kfree(filter);
+			return err;
+		}
 		udelay(1);
 	}
 
Signature · 1 line
2.20.1
#4 lore raw

PATCH 3/8 iavf: don't clear a lock we don't hold

Quoted 14 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Nguyen, Anthony L
Sent: Friday, June 4, 2021 9:49 AM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH net 3/8] iavf: don't clear a lock we don't hold

From: Nicholas Nunley <[email protected]>

In iavf_configure_clsflower() the function will bail out if it is unable to obtain the crit_section lock in a reasonable time. However, it will clear the lock when exiting, so fix this.

Quoted 7 lines
Fixes 640a8af5841f ("i40evf: Reorder configure_clsflower to avoid deadlock

on error")

---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
author maintainer
#5 lore raw

PATCH 4/8 iavf: Fix failure to exit out from last all-multicast mode

In reply to Tony Nguyen

From: Piotr Marczak <[email protected]>

The driver could only quit allmulti when allmulti and promisc modes are turn on at the same time. If promisc had been off there was no way to turn off allmulti mode.
The patch corrects this behavior. Switching allmulti does not depends on promisc state mode anymore

Fixes f42a5c74da99 ("i40e: Add allmulti support for the VF")
---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +1 -2
index 58624be64010..ffffb6e0a6c1 100644
@@ -1613,8 +1613,7 @@ static int iavf_process_aq_command(struct iavf_adapter *adapter)
 		iavf_set_promiscuous(adapter, FLAG_VF_MULTICAST_PROMISC);
 		return 0;
 	}
-
-	if ((adapter->aq_required & IAVF_FLAG_AQ_RELEASE_PROMISC) &&
+	if ((adapter->aq_required & IAVF_FLAG_AQ_RELEASE_PROMISC) ||
 	    (adapter->aq_required & IAVF_FLAG_AQ_RELEASE_ALLMULTI)) {
 		iavf_set_promiscuous(adapter, 0);
 		return 0;
Signature · 1 line
2.20.1
#6 lore raw

PATCH 4/8 iavf: Fix failure to exit out from last all-multicast mode

Quoted 16 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Nguyen, Anthony L
Sent: Friday, June 4, 2021 9:49 AM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH net 4/8] iavf: Fix failure to exit out from last all-multicast mode

From: Piotr Marczak <[email protected]>

The driver could only quit allmulti when allmulti and promisc modes are turn on at the same time. If promisc had been off there was no way to turn off allmulti mode.
The patch corrects this behavior. Switching allmulti does not depends on promisc state mode anymore

Quoted 6 lines
Fixes f42a5c74da99 ("i40e: Add allmulti support for the VF")
---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
author maintainer
#7 lore raw

PATCH 5/8 iavf: prevent accidental free of filter structure

In reply to Tony Nguyen

From: Jacob Keller <[email protected]>

In iavf_config_clsflower, the filter structure could be accidentally released at the end, if iavf_parse_cls_flower or iavf_handle_tclass ever return a non-zero but positive value.

In this case, the function continues through to the end, and will call kfree() on the filter structure even though it has been added to the linked list.

This can actually happen because iavf_parse_cls_flower will return a positive IAVF_ERR_CONFIG value instead of the traditional negative error codes.

Fix this by ensuring that the kfree() check and error checks are similar. Use the more idiomatic "if (err)" to catch all non-zero error codes.

Fixes 0075fa0fadd0 ("i40evf: Add support to apply cloud filters")
---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +2 -2
index ffffb6e0a6c1..bb533e9781ee 100644
@@ -3040,11 +3040,11 @@ static int iavf_configure_clsflower(struct iavf_adapter *adapter,
 	/* start out with flow type and eth type IPv4 to begin with */
 	filter->f.flow_type = VIRTCHNL_TCP_V4_FLOW;
 	err = iavf_parse_cls_flower(adapter, cls_flower, filter);
-	if (err < 0)
+	if (err)
 		goto err;
 
 	err = iavf_handle_tclass(adapter, tc, filter);
-	if (err < 0)
+	if (err)
 		goto err;
 
 	/* add filter to the list */
Signature · 1 line
2.20.1
#8 lore raw

PATCH 5/8 iavf: prevent accidental free of filter structure

Quoted 24 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Nguyen, Anthony L
Sent: Friday, June 4, 2021 9:49 AM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH net 5/8] iavf: prevent accidental free of filter structure

From: Jacob Keller <[email protected]>

In iavf_config_clsflower, the filter structure could be accidentally released at the end, if iavf_parse_cls_flower or iavf_handle_tclass ever return a non- zero but positive value.

In this case, the function continues through to the end, and will call kfree() on the filter structure even though it has been added to the linked list.

This can actually happen because iavf_parse_cls_flower will return a positive IAVF_ERR_CONFIG value instead of the traditional negative error codes.

Fix this by ensuring that the kfree() check and error checks are similar. Use the more idiomatic "if (err)" to catch all non-zero error codes.

Quoted 6 lines
Fixes 0075fa0fadd0 ("i40evf: Add support to apply cloud filters")
---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
author maintainer
#9 lore raw

PATCH 6/8 iavf: validate pointers

In reply to Tony Nguyen

From: Mitch Williams <[email protected]>

In some cases, the ethtool get_rxfh handler may be called with a null key or indir parameter. So check these pointers, or you will have a very bad day.

Fixes 43a3d9ba34c9 ("i40evf: Allow PF driver to configure RSS")
---
 drivers/net/ethernet/intel/iavf/iavf_ethtool.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_ethtool.c +6 -7
index 0d22a5275218..77a8a15c5410 100644
@@ -1853,14 +1853,13 @@ static int iavf_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
 
 	if (hfunc)
 		*hfunc = ETH_RSS_HASH_TOP;
-	if (!indir)
-		return 0;
-
-	memcpy(key, adapter->rss_key, adapter->rss_key_size);
+	if (key)
+		memcpy(key, adapter->rss_key, adapter->rss_key_size);
 
-	/* Each 32 bits pointed by 'indir' is stored with a lut entry */
-	for (i = 0; i < adapter->rss_lut_size; i++)
-		indir[i] = (u32)adapter->rss_lut[i];
+	if (indir)
+		/* Each 32 bits pointed by 'indir' is stored with a lut entry */
+		for (i = 0; i < adapter->rss_lut_size; i++)
+			indir[i] = (u32)adapter->rss_lut[i];
 
 	return 0;
 }
Signature · 1 line
2.20.1
#10 lore raw

PATCH 6/8 iavf: validate pointers

Quoted 12 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Nguyen, Anthony L
Sent: Friday, June 4, 2021 9:49 AM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH net 6/8] iavf: validate pointers

From: Mitch Williams <[email protected]>

In some cases, the ethtool get_rxfh handler may be called with a null key or indir parameter. So check these pointers, or you will have a very bad day.

Quoted 6 lines
Fixes 43a3d9ba34c9 ("i40evf: Allow PF driver to configure RSS")
---
 drivers/net/ethernet/intel/iavf/iavf_ethtool.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
author maintainer
#11 lore raw

PATCH 7/8 iavf: Fix for the false positive ASQ/ARQ errors while issuing VF reset

In reply to Tony Nguyen

From: Surabhi Boob <[email protected]>

While issuing VF Reset from the guest OS, the VF driver prints logs about critical / Overflow error detection. This is not an actual error since the VF_MBX_ARQLEN register is set to all FF's for a short period of time and the VF would catch the bits set if it was reading the register during that spike of time. This patch introduces an additional check to ignore this condition since the VF is in reset.

Fixes 19b73d8efaa4 ("i40evf: Add additional check for reset")
---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +1 -1
index bb533e9781ee..2b1f034ca5fc 100644
@@ -2340,7 +2340,7 @@ static void iavf_adminq_task(struct work_struct *work)
 
 	/* check for error indications */
 	val = rd32(hw, hw->aq.arq.len);
-	if (val == 0xdeadbeef) /* indicates device in reset */
+	if (val == 0xdeadbeef || val == 0xffffffff) /* device in reset */
 		goto freedom;
 	oldval = val;
 	if (val & IAVF_VF_ARQLEN1_ARQVFE_MASK) {
Signature · 1 line
2.20.1
#12 lore raw

PATCH 7/8 iavf: Fix for the false positive ASQ/ARQ errors while issuing VF reset

Quoted 18 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Nguyen, Anthony L
Sent: Friday, June 4, 2021 9:49 AM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH net 7/8] iavf: Fix for the false positive ASQ/ARQ errors while issuing VF reset

From: Surabhi Boob <[email protected]>

While issuing VF Reset from the guest OS, the VF driver prints logs about critical / Overflow error detection. This is not an actual error since the VF_MBX_ARQLEN register is set to all FF's for a short period of time and the VF would catch the bits set if it was reading the register during that spike of time.
This patch introduces an additional check to ignore this condition since the VF is in reset.

Quoted 6 lines
Fixes 19b73d8efaa4 ("i40evf: Add additional check for reset")
---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
author maintainer
#13 lore raw

PATCH 8/8 iavf: Fix for setting queues to 0

In reply to Tony Nguyen

From: Grzegorz Szczurek <[email protected]>

Now setting combine to 0 will be rejected with the appropriate error code.
This has been implemented by adding a condition that checks the value of combine equal to zero.
Without this patch, when the user requested it, no error was returned and combine was set to the default value for VF.

Fixes 5520deb15326 ("iavf: Enable support for up to 16 queues")
---
 drivers/net/ethernet/intel/iavf/iavf_ethtool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/iavf/iavf_ethtool.c +1 -1
index 77a8a15c5410..0885fb0f0d4b 100644
@@ -1781,7 +1781,7 @@ static int iavf_set_channels(struct net_device *netdev,
 	/* All of these should have already been checked by ethtool before this
 	 * even gets to us, but just to be sure.
 	 */
-	if (num_req > adapter->vsi_res->num_queue_pairs)
+	if (num_req == 0 || num_req > adapter->vsi_res->num_queue_pairs)
 		return -EINVAL;
 
 	if (num_req == adapter->num_active_queues)
Signature · 1 line
2.20.1
#14 lore raw

PATCH 8/8 iavf: Fix for setting queues to 0

Quoted 15 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Nguyen, Anthony L
Sent: Friday, June 4, 2021 9:49 AM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH net 8/8] iavf: Fix for setting queues to 0

From: Grzegorz Szczurek <[email protected]>

Now setting combine to 0 will be rejected with the appropriate error code. This has been implemented by adding a condition that checks the value of combine equal to zero.
Without this patch, when the user requested it, no error was returned and combine was set to the default value for VF.

Quoted 6 lines
Fixes 5520deb15326 ("iavf: Enable support for up to 16 queues")
---
 drivers/net/ethernet/intel/iavf/iavf_ethtool.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#15 lore raw

PATCH 1/8 iavf: check for null in iavf_fix_features

In reply to Tony Nguyen
Quoted 16 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Nguyen, Anthony L
Sent: Friday, June 4, 2021 9:49 AM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH net 1/8] iavf: check for null in iavf_fix_features

From: Nicholas Nunley <[email protected]>

If the driver has lost contact with the PF then it enters a disabled state and frees adapter->vf_res. However, ndo_fix_features can still be called on the interface, so we need to check for this condition first. Since we have no information on the features at this time simply leave them unmodified and return.

Quoted 6 lines
Fixes c4445aedfe09 ("i40evf: Fix VLAN features")
---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)