Skip to content

Commit 6e6d398

Browse files
siwliu-kernelmstsirkin
authored andcommitted
vdpa: conditionally read STATUS in config space
The spec says: status only exists if VIRTIO_NET_F_STATUS is set Similar to MAC and MTU, vdpa_dev_net_config_fill() should read STATUS conditionally depending on the feature bits. Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com> Reviewed-by: Parav Pandit <parav@nvidia.com> Reviewed-by: Eli Cohen <elic@nvidia.com> Message-Id: <1675725124-7375-3-git-send-email-si-wei.liu@oracle.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 275487b commit 6e6d398

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

drivers/vdpa/vdpa.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -848,18 +848,25 @@ static int vdpa_dev_net_mac_config_fill(struct sk_buff *msg, u64 features,
848848
sizeof(config->mac), config->mac);
849849
}
850850

851+
static int vdpa_dev_net_status_config_fill(struct sk_buff *msg, u64 features,
852+
const struct virtio_net_config *config)
853+
{
854+
u16 val_u16;
855+
856+
if ((features & BIT_ULL(VIRTIO_NET_F_STATUS)) == 0)
857+
return 0;
858+
859+
val_u16 = __virtio16_to_cpu(true, config->status);
860+
return nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, val_u16);
861+
}
862+
851863
static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *msg)
852864
{
853865
struct virtio_net_config config = {};
854866
u64 features_device;
855-
u16 val_u16;
856867

857868
vdev->config->get_config(vdev, 0, &config, sizeof(config));
858869

859-
val_u16 = __virtio16_to_cpu(true, config.status);
860-
if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, val_u16))
861-
return -EMSGSIZE;
862-
863870
features_device = vdev->config->get_device_features(vdev);
864871

865872
if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_FEATURES, features_device,
@@ -872,6 +879,9 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms
872879
if (vdpa_dev_net_mac_config_fill(msg, features_device, &config))
873880
return -EMSGSIZE;
874881

882+
if (vdpa_dev_net_status_config_fill(msg, features_device, &config))
883+
return -EMSGSIZE;
884+
875885
return vdpa_dev_net_mq_config_fill(msg, features_device, &config);
876886
}
877887

0 commit comments

Comments
 (0)