Skip to contentSkip to conversation

vdpasim: allow to set MAC address

PATCH In review Laurent Vivier 2 participants 4 messages Oct 29, 2020 – Oct 30, 2020 virtio core

lore
Share & tools
lore
#0 lore raw

cover vdpasim: allow to set MAC address

This series starts by fixing a bug:
vdpa_sim generates a MAC address that is never show to upper layer, and thus virtio-net generates another random MAC address, that changes each time virtio-net is loaded (even if vdpa_sim is not unloaded).

Then it adds a parameter to vpa_sim module to allow the user to set the MAC address. With that we use vdpa_sim with a stable MAC addres, that doesn't change between reboots.

Laurent Vivier (2):
vdpasim: fix MAC address configuration
vdpasim: allow to assign a MAC address

 drivers/vdpa/vdpa_sim/vdpa_sim.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
Signature · 7 lines
2.26.2


_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#1 lore raw

PATCH 1/2 vdpasim: fix MAC address configuration

vdpa_sim generates a ramdom MAC address but it is never used by upper layers because the VIRTIO_NET_F_MAC bit is not set in the features list.

Because of that, virtio-net always regenerates a random MAC address each time it is loaded whereas the address should only change on vdpa_sim load/unload.

Fix that by adding VIRTIO_NET_F_MAC in the features list of vdpa_sim.

Fixes 2c53d0f64c06 ("vdpasim: vDPA device simulator")
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa_sim/vdpa_sim.c +2 -1
index 2629911c29bb..7f8ebc9924ac 100644
@@ -60,7 +60,8 @@ struct vdpasim_virtqueue {
 
 static u64 vdpasim_features = (1ULL << VIRTIO_F_ANY_LAYOUT) |
 			      (1ULL << VIRTIO_F_VERSION_1)  |
-			      (1ULL << VIRTIO_F_ACCESS_PLATFORM);
+			      (1ULL << VIRTIO_F_ACCESS_PLATFORM) |
+			      (1ULL << VIRTIO_NET_F_MAC);
 
 /* State of each vdpasim device */
 struct vdpasim {
Signature · 6 lines
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#2 lore raw

PATCH 2/2 vdpasim: allow to assign a MAC address

In reply to Laurent Vivier

Add macaddr parameter to the module to set the MAC address to use

---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa_sim/vdpa_sim.c +13 -1
index 7f8ebc9924ac..9cf7079ee185 100644
@@ -38,6 +38,10 @@ static int batch_mapping = 1;
 module_param(batch_mapping, int, 0444);
 MODULE_PARM_DESC(batch_mapping, "Batched mapping 1 -Enable; 0 - Disable");
 
+static char *macaddr;
+module_param(macaddr, charp, 0);
+MODULE_PARM_DESC(macaddr, "Ethernet MAC address");
+
 struct vdpasim_virtqueue {
 	struct vringh vring;
 	struct vringh_kiov iov;
@@ -373,7 +377,15 @@ static struct vdpasim *vdpasim_create(void)
 	if (!vdpasim->buffer)
 		goto err_iommu;
 
-	eth_random_addr(vdpasim->config.mac);
+	if (macaddr) {
+		mac_pton(macaddr, vdpasim->config.mac);
+		if (!is_valid_ether_addr(vdpasim->config.mac)) {
+			ret = -EADDRNOTAVAIL;
+			goto err_iommu;
+		}
+	} else {
+		eth_random_addr(vdpasim->config.mac);
+	}
 
 	vringh_set_iotlb(&vdpasim->vqs[0].vring, vdpasim->iommu);
 	vringh_set_iotlb(&vdpasim->vqs[1].vring, vdpasim->iommu);
Signature · 6 lines
2.26.2

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Acked-by on the v1 series
#3 lore raw
In reply to Laurent Vivier
Quoted 10 lines · Laurent Vivier

This series starts by fixing a bug:
vdpa_sim generates a MAC address that is never show to upper layer, and thus virtio-net generates another random MAC address, that changes each time virtio-net is loaded (even if vdpa_sim is not unloaded).

Then it adds a parameter to vpa_sim module to allow the user to set the MAC address. With that we use vdpa_sim with a stable MAC addres, that doesn't change between reboots.

Quoted 7 lines

Laurent Vivier (2):
vdpasim: fix MAC address configuration
vdpasim: allow to assign a MAC address

  drivers/vdpa/vdpa_sim/vdpa_sim.c | 17 +++++++++++++++--
  1 file changed, 15 insertions(+), 2 deletions(-)