Skip to content

Commit f1781be

Browse files
Michael Qiumstsirkin
authored andcommitted
vdpa/mlx5: re-create forwarding rules after mac modified
When MAC Address has been modified in guest, we only re-add the Mac to mpfs, it is not enough, because the guest network will not work correctly: the reply package from outside will go straight away to the host VF net interface. This patch recreate the flow rules, and make it work correctly. Signed-off-by: Michael Qiu <qiudayu@archeros.com> Link: https://lore.kernel.org/r/1648446492-17614-1-git-send-email-08005325@163.com Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Eli Cohen <elic@nvidia.com>
1 parent 3f63a1d commit f1781be

1 file changed

Lines changed: 44 additions & 1 deletion

File tree

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd)
14751475
virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
14761476
struct mlx5_core_dev *pfmdev;
14771477
size_t read;
1478-
u8 mac[ETH_ALEN];
1478+
u8 mac[ETH_ALEN], mac_back[ETH_ALEN];
14791479

14801480
pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev));
14811481
switch (cmd) {
@@ -1489,6 +1489,9 @@ static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd)
14891489
break;
14901490
}
14911491

1492+
if (is_zero_ether_addr(mac))
1493+
break;
1494+
14921495
if (!is_zero_ether_addr(ndev->config.mac)) {
14931496
if (mlx5_mpfs_del_mac(pfmdev, ndev->config.mac)) {
14941497
mlx5_vdpa_warn(mvdev, "failed to delete old MAC %pM from MPFS table\n",
@@ -1503,7 +1506,47 @@ static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd)
15031506
break;
15041507
}
15051508

1509+
/* backup the original mac address so that if failed to add the forward rules
1510+
* we could restore it
1511+
*/
1512+
memcpy(mac_back, ndev->config.mac, ETH_ALEN);
1513+
15061514
memcpy(ndev->config.mac, mac, ETH_ALEN);
1515+
1516+
/* Need recreate the flow table entry, so that the packet could forward back
1517+
*/
1518+
remove_fwd_to_tir(ndev);
1519+
1520+
if (add_fwd_to_tir(ndev)) {
1521+
mlx5_vdpa_warn(mvdev, "failed to insert forward rules, try to restore\n");
1522+
1523+
/* Although it hardly run here, we still need double check */
1524+
if (is_zero_ether_addr(mac_back)) {
1525+
mlx5_vdpa_warn(mvdev, "restore mac failed: Original MAC is zero\n");
1526+
break;
1527+
}
1528+
1529+
/* Try to restore original mac address to MFPS table, and try to restore
1530+
* the forward rule entry.
1531+
*/
1532+
if (mlx5_mpfs_del_mac(pfmdev, ndev->config.mac)) {
1533+
mlx5_vdpa_warn(mvdev, "restore mac failed: delete MAC %pM from MPFS table failed\n",
1534+
ndev->config.mac);
1535+
}
1536+
1537+
if (mlx5_mpfs_add_mac(pfmdev, mac_back)) {
1538+
mlx5_vdpa_warn(mvdev, "restore mac failed: insert old MAC %pM into MPFS table failed\n",
1539+
mac_back);
1540+
}
1541+
1542+
memcpy(ndev->config.mac, mac_back, ETH_ALEN);
1543+
1544+
if (add_fwd_to_tir(ndev))
1545+
mlx5_vdpa_warn(mvdev, "restore forward rules failed: insert forward rules failed\n");
1546+
1547+
break;
1548+
}
1549+
15071550
status = VIRTIO_NET_OK;
15081551
break;
15091552

0 commit comments

Comments
 (0)