Skip to content

Commit 41a2ad9

Browse files
ls-zhumstsirkin
authored andcommitted
vDPA: conditionally read MTU and MAC in dev cfg space
The spec says: mtu only exists if VIRTIO_NET_F_MTU is set The mac address field always exists (though is only valid if VIRTIO_NET_F_MAC is set) So vdpa_dev_net_config_fill() should read MTU and MAC conditionally on the feature bits. Signed-off-by: Zhu Lingshan <lingshan.zhu@intel.com> Acked-by: Jason Wang <jasowang@redhat.com> Message-Id: <20220929014555.112323-7-lingshan.zhu@intel.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 35b37c3 commit 41a2ad9

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

drivers/vdpa/vdpa.c

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,29 @@ static int vdpa_dev_net_mq_config_fill(struct sk_buff *msg, u64 features,
818818
return nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MAX_VQP, val_u16);
819819
}
820820

821+
static int vdpa_dev_net_mtu_config_fill(struct sk_buff *msg, u64 features,
822+
const struct virtio_net_config *config)
823+
{
824+
u16 val_u16;
825+
826+
if ((features & BIT_ULL(VIRTIO_NET_F_MTU)) == 0)
827+
return 0;
828+
829+
val_u16 = __virtio16_to_cpu(true, config->mtu);
830+
831+
return nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, val_u16);
832+
}
833+
834+
static int vdpa_dev_net_mac_config_fill(struct sk_buff *msg, u64 features,
835+
const struct virtio_net_config *config)
836+
{
837+
if ((features & BIT_ULL(VIRTIO_NET_F_MAC)) == 0)
838+
return 0;
839+
840+
return nla_put(msg, VDPA_ATTR_DEV_NET_CFG_MACADDR,
841+
sizeof(config->mac), config->mac);
842+
}
843+
821844
static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *msg)
822845
{
823846
struct virtio_net_config config = {};
@@ -826,24 +849,22 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms
826849

827850
vdev->config->get_config(vdev, 0, &config, sizeof(config));
828851

829-
if (nla_put(msg, VDPA_ATTR_DEV_NET_CFG_MACADDR, sizeof(config.mac),
830-
config.mac))
831-
return -EMSGSIZE;
832-
833852
val_u16 = __virtio16_to_cpu(true, config.status);
834853
if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, val_u16))
835854
return -EMSGSIZE;
836855

837-
val_u16 = __virtio16_to_cpu(true, config.mtu);
838-
if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, val_u16))
839-
return -EMSGSIZE;
840-
841856
features_device = vdev->config->get_device_features(vdev);
842857

843858
if (nla_put_u64_64bit(msg, VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES, features_device,
844859
VDPA_ATTR_PAD))
845860
return -EMSGSIZE;
846861

862+
if (vdpa_dev_net_mtu_config_fill(msg, features_device, &config))
863+
return -EMSGSIZE;
864+
865+
if (vdpa_dev_net_mac_config_fill(msg, features_device, &config))
866+
return -EMSGSIZE;
867+
847868
return vdpa_dev_net_mq_config_fill(msg, features_device, &config);
848869
}
849870

0 commit comments

Comments
 (0)