Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sfc: Change VF mac via PF as first preference if available.

Changing a VF's mac address through the VF (rather than via the PF)
fails with EPERM because the latter part of efx_ef10_set_mac_address
attempts to change the vport mac address list as the VF.
Even with this fixed it still fails with EBUSY because the vadaptor
is still assigned on the VF - the vadaptor reassignment must be within
a section where the VF has torn down its state.

A major reason this has broken is because we have two functions that
ostensibly do the same thing - have a PF and VF cooperate to change a
VF mac address. Rather than do this, if we are changing the mac of a VF
that has a link to the PF in the same VM then simply call
sriov_set_vf_mac instead, which is a proven working function that does
that.

If there is no PF available, or that fails non-fatally, then attempt to
change the VF's mac address as we would a PF, without updating the PF's
data.

Test case:
Create a VF:
echo 1 > /sys/class/net/<if>/device/sriov_numvfs
Set the mac address of the VF directly:
ip link set <vf> addr 00:11:22:33:44:55
Set the MAC address of the VF via the PF:
ip link set <pf> vf 0 mac 00:11:22:33:44:66
Without this patch the last command will fail with ENOENT.

Signed-off-by: Jonathan Cooper <jonathan.s.cooper@amd.com>
Reported-by: Íñigo Huguet <ihuguet@redhat.com>
Fixes: 910c8789a777 ("set the MAC address using MC_CMD_VADAPTOR_SET_MAC")
Acked-by: Edward Cree <ecree.xilinx@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jonathan Cooper and committed by
David S. Miller
a8aed7b3 0c934117

+24 -34
+24 -34
drivers/net/ethernet/sfc/ef10.c
··· 3277 3277 bool was_enabled = efx->port_enabled; 3278 3278 int rc; 3279 3279 3280 + #ifdef CONFIG_SFC_SRIOV 3281 + /* If this function is a VF and we have access to the parent PF, 3282 + * then use the PF control path to attempt to change the VF MAC address. 3283 + */ 3284 + if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) { 3285 + struct efx_nic *efx_pf = pci_get_drvdata(efx->pci_dev->physfn); 3286 + struct efx_ef10_nic_data *nic_data = efx->nic_data; 3287 + u8 mac[ETH_ALEN]; 3288 + 3289 + /* net_dev->dev_addr can be zeroed by efx_net_stop in 3290 + * efx_ef10_sriov_set_vf_mac, so pass in a copy. 3291 + */ 3292 + ether_addr_copy(mac, efx->net_dev->dev_addr); 3293 + 3294 + rc = efx_ef10_sriov_set_vf_mac(efx_pf, nic_data->vf_index, mac); 3295 + if (!rc) 3296 + return 0; 3297 + 3298 + netif_dbg(efx, drv, efx->net_dev, 3299 + "Updating VF mac via PF failed (%d), setting directly\n", 3300 + rc); 3301 + } 3302 + #endif 3303 + 3280 3304 efx_device_detach_sync(efx); 3281 3305 efx_net_stop(efx->net_dev); 3282 3306 ··· 3321 3297 efx_net_open(efx->net_dev); 3322 3298 efx_device_attach_if_not_resetting(efx); 3323 3299 3324 - #ifdef CONFIG_SFC_SRIOV 3325 - if (efx->pci_dev->is_virtfn && efx->pci_dev->physfn) { 3326 - struct efx_ef10_nic_data *nic_data = efx->nic_data; 3327 - struct pci_dev *pci_dev_pf = efx->pci_dev->physfn; 3328 - 3329 - if (rc == -EPERM) { 3330 - struct efx_nic *efx_pf; 3331 - 3332 - /* Switch to PF and change MAC address on vport */ 3333 - efx_pf = pci_get_drvdata(pci_dev_pf); 3334 - 3335 - rc = efx_ef10_sriov_set_vf_mac(efx_pf, 3336 - nic_data->vf_index, 3337 - efx->net_dev->dev_addr); 3338 - } else if (!rc) { 3339 - struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf); 3340 - struct efx_ef10_nic_data *nic_data = efx_pf->nic_data; 3341 - unsigned int i; 3342 - 3343 - /* MAC address successfully changed by VF (with MAC 3344 - * spoofing) so update the parent PF if possible. 3345 - */ 3346 - for (i = 0; i < efx_pf->vf_count; ++i) { 3347 - struct ef10_vf *vf = nic_data->vf + i; 3348 - 3349 - if (vf->efx == efx) { 3350 - ether_addr_copy(vf->mac, 3351 - efx->net_dev->dev_addr); 3352 - return 0; 3353 - } 3354 - } 3355 - } 3356 - } else 3357 - #endif 3358 3300 if (rc == -EPERM) { 3359 3301 netif_err(efx, drv, efx->net_dev, 3360 3302 "Cannot change MAC address; use sfboot to enable"