virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] vdpasim: allow to set MAC address
@ 2020-10-29 12:20 Laurent Vivier
  2020-10-29 12:20 ` [PATCH 1/2] vdpasim: fix MAC address configuration Laurent Vivier
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Laurent Vivier @ 2020-10-29 12:20 UTC (permalink / raw)
  To: linux-kernel; +Cc: Laurent Vivier, virtualization, Michael S. Tsirkin

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(-)

-- 
2.26.2


_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] vdpasim: fix MAC address configuration
  2020-10-29 12:20 [PATCH 0/2] vdpasim: allow to set MAC address Laurent Vivier
@ 2020-10-29 12:20 ` Laurent Vivier
  2020-10-29 12:20 ` [PATCH 2/2] vdpasim: allow to assign a MAC address Laurent Vivier
  2020-10-30  1:24 ` [PATCH 0/2] vdpasim: allow to set " Jason Wang
  2 siblings, 0 replies; 4+ messages in thread
From: Laurent Vivier @ 2020-10-29 12:20 UTC (permalink / raw)
  To: linux-kernel; +Cc: Laurent Vivier, virtualization, Michael S. Tsirkin

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")
Cc: jasowang@redhat.com
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 2629911c29bb..7f8ebc9924ac 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -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 {
-- 
2.26.2

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] vdpasim: allow to assign a MAC address
  2020-10-29 12:20 [PATCH 0/2] vdpasim: allow to set MAC address Laurent Vivier
  2020-10-29 12:20 ` [PATCH 1/2] vdpasim: fix MAC address configuration Laurent Vivier
@ 2020-10-29 12:20 ` Laurent Vivier
  2020-10-30  1:24 ` [PATCH 0/2] vdpasim: allow to set " Jason Wang
  2 siblings, 0 replies; 4+ messages in thread
From: Laurent Vivier @ 2020-10-29 12:20 UTC (permalink / raw)
  To: linux-kernel; +Cc: Laurent Vivier, virtualization, Michael S. Tsirkin

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

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 drivers/vdpa/vdpa_sim/vdpa_sim.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 7f8ebc9924ac..9cf7079ee185 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -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);
-- 
2.26.2

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] vdpasim: allow to set MAC address
  2020-10-29 12:20 [PATCH 0/2] vdpasim: allow to set MAC address Laurent Vivier
  2020-10-29 12:20 ` [PATCH 1/2] vdpasim: fix MAC address configuration Laurent Vivier
  2020-10-29 12:20 ` [PATCH 2/2] vdpasim: allow to assign a MAC address Laurent Vivier
@ 2020-10-30  1:24 ` Jason Wang
  2 siblings, 0 replies; 4+ messages in thread
From: Jason Wang @ 2020-10-30  1:24 UTC (permalink / raw)
  To: Laurent Vivier, linux-kernel; +Cc: virtualization, Michael S. Tsirkin


On 2020/10/29 下午8:20, Laurent Vivier wrote:
> 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(-)
>

Acked-by: Jason Wang <jasowang@redhat.com>


_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-10-30  1:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-29 12:20 [PATCH 0/2] vdpasim: allow to set MAC address Laurent Vivier
2020-10-29 12:20 ` [PATCH 1/2] vdpasim: fix MAC address configuration Laurent Vivier
2020-10-29 12:20 ` [PATCH 2/2] vdpasim: allow to assign a MAC address Laurent Vivier
2020-10-30  1:24 ` [PATCH 0/2] vdpasim: allow to set " Jason Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).