Skip to contentSkip to conversation

iavf: Fix change VF's mac address

PATCH Superseded Mateusz Palczewski 3 participants 3 messages Aug 31, 2022 – Sep 6, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iavf: Fix change VF's mac address

From: Sylwester Dziedziuch <[email protected]>

Previously changing mac address gives false negative because ip link set <interface> address <MAC> return with
RTNLINK: Permission denied.
In iavf_set_mac check, if mac was handled by PF, was on start of iavf_set_mac even before mac was added to adapter's list of mac. Because this check returns always true and it never waits for PF's response.

Move iavf_is_mac_handled to wait_event_interruptible_timeout instead of false. Now it will wait for PF's response and then check if address was added or rejected.

Fixes 35a2443d0910 ("iavf: Add waiting for response from PF in set mac")
---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +4 -6
index f39440ad5c50..94e4cc4011f3 100644
@@ -1077,7 +1077,6 @@ static int iavf_set_mac(struct net_device *netdev, void *p)
 {
 	struct iavf_adapter *adapter = netdev_priv(netdev);
 	struct sockaddr *addr = p;
-	bool handle_mac = iavf_is_mac_set_handled(netdev, addr->sa_data);
 	int ret;
 
 	if (!is_valid_ether_addr(addr->sa_data))
@@ -1094,10 +1093,10 @@ static int iavf_set_mac(struct net_device *netdev, void *p)
 		return 0;
 	}
 
-	if (handle_mac)
-		goto done;
-
-	ret = wait_event_interruptible_timeout(adapter->vc_waitqueue, false, msecs_to_jiffies(2500));
+	ret = wait_event_interruptible_timeout
+			(adapter->vc_waitqueue,
+			 iavf_is_mac_set_handled(netdev, addr->sa_data),
+			 msecs_to_jiffies(2500));
 
 	/* If ret < 0 then it means wait was interrupted.
 	 * If ret == 0 then it means we got a timeout.
@@ -1111,7 +1110,6 @@ static int iavf_set_mac(struct net_device *netdev, void *p)
 	if (!ret)
 		return -EAGAIN;
 
-done:
 	if (!ether_addr_equal(netdev->dev_addr, addr->sa_data))
 		return -EACCES;
 
Signature · 6 lines
2.27.0

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan
maintainer
#1 lore raw
Quoted 7 lines · Mateusz Palczewski

From: Sylwester Dziedziuch <[email protected]>

Previously changing mac address gives false negative because ip link set <interface> address <MAC> return with
RTNLINK: Permission denied.
In iavf_set_mac check, if mac was handled by PF, was on start of iavf_set_mac even before mac was added to adapter's list of mac.

I don't understand this statement, can you reword this?

Quoted 10 lines

Because this check returns always true and it never waits for PF's response.

Move iavf_is_mac_handled to wait_event_interruptible_timeout instead of false. Now it will wait for PF's response and then check if address was added or rejected.

Fixes 35a2443d0910 ("iavf: Add waiting for response from PF in set mac")

Need Sign-off from co-developer.

Quoted 18 lines
---
  drivers/net/ethernet/intel/iavf/iavf_main.c | 10 ++++------
  1 file changed, 4 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +0 -1
index f39440ad5c50..94e4cc4011f3 100644
@@ -1077,7 +1077,6 @@ static int iavf_set_mac(struct net_device *netdev, void *p)
  {
  	struct iavf_adapter *adapter = netdev_priv(netdev);
  	struct sockaddr *addr = p;
-	bool handle_mac = iavf_is_mac_set_handled(netdev, addr->sa_data);
  	int ret;
 
  	if (!is_valid_ether_addr(addr->sa_data))

drivers/net/ethernet/intel/iavf/iavf_main.c static int iavf_set_mac(struct net_device *netdev, void *p) · line 1097

Quoted 9 lines
drivers/net/ethernet/intel/iavf/iavf_main.c +2 -4
@@ -1094,10 +1093,10 @@ static int iavf_set_mac(struct net_device *netdev, void *p)
  		return 0;
  	}
 
-	if (handle_mac)
-		goto done;
-
-	ret = wait_event_interruptible_timeout(adapter->vc_waitqueue, false, msecs_to_jiffies(2500));
+	ret = wait_event_interruptible_timeout
+			(adapter->vc_waitqueue,

Parenthesis should stay on previous line. I assume you did this to avoid checkpatch issues. I'd rather you go long line to keep other things styled correctly.

i.e.
ret = wait_event_interruptible_timeout(adapter->vc_waitqueue,
iavf_is_mac_set_handled(netdev,
addr->sa_data),

                                       msecs_to_jiffies(2500));

drivers/net/ethernet/intel/iavf/iavf_main.c static int iavf_set_mac(struct net_device *netdev, void *p) · line 1115

Quoted 13 lines
drivers/net/ethernet/intel/iavf/iavf_main.c +2 -1
+			 iavf_is_mac_set_handled(netdev, addr->sa_data),
+			 msecs_to_jiffies(2500));
 
  	/* If ret < 0 then it means wait was interrupted.
  	 * If ret == 0 then it means we got a timeout.
@@ -1111,7 +1110,6 @@ static int iavf_set_mac(struct net_device *netdev, void *p)
  	if (!ret)
  		return -EAGAIN;
 
-done:
  	if (!ether_addr_equal(netdev->dev_addr, addr->sa_data))
  		return -EACCES;
 

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

Tested-by on v1 1/1
#2 lore raw
In reply to Mateusz Palczewski

drivers/net/ethernet/intel/iavf/iavf_main.c static int iavf_set_mac(struct net_device *netdev,

Quoted 38 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Mateusz Palczewski
Sent: Wednesday, August 31, 2022 3:53 PM
To: [email protected]
Cc: Dziedziuch, SylwesterX <[email protected]>; Zulinski, NorbertX <[email protected]>
Subject: [Intel-wired-lan] [PATCH net v1] iavf: Fix change VF's mac address

From: Sylwester Dziedziuch <[email protected]>

Previously changing mac address gives false negative because ip link set <interface> address <MAC> return with
RTNLINK: Permission denied.
In iavf_set_mac check, if mac was handled by PF, was on start of iavf_set_mac even before mac was added to adapter's list of mac. Because this check returns always true and it never waits for PF's response.

Move iavf_is_mac_handled to wait_event_interruptible_timeout instead of false. Now it will wait for PF's response and then check if address was added or rejected.

Fixes 35a2443d0910 ("iavf: Add waiting for response from PF in set mac")
---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +0 -0
index f39440ad5c50..94e4cc4011f3 100644
@@ -1077,7 +1077,6 @@ static int iavf_set_mac(struct net_device *netdev,

_______________________________________________
Intel-wired-lan mailing list
[email protected]
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan