2020-10-29 12:24:49

by Laurent Vivier

[permalink] [raw]
Subject: [PATCH 0/2] 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(-)



--

2.26.2





2020-10-29 12:26:14

by Laurent Vivier

[permalink] [raw]
Subject: [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")
Cc: [email protected]
Signed-off-by: Laurent Vivier <[email protected]>
---
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

2020-10-29 12:29:44

by Laurent Vivier

[permalink] [raw]
Subject: [PATCH 2/2] vdpasim: allow to assign a MAC address

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

Signed-off-by: Laurent Vivier <[email protected]>
---
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

2020-10-30 01:27:06

by Jason Wang

[permalink] [raw]
Subject: Re: [PATCH 0/2] vdpasim: allow to set MAC address


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 <[email protected]>