Skip to content

Commit c6dac2e

Browse files
ls-zhumstsirkin
authored andcommitted
vDPA: only report driver features if FEATURES_OK is set
This commit reports driver features to user space only after FEATURES_OK is features negotiation is done. Signed-off-by: Zhu Lingshan <lingshan.zhu@intel.com> Message-Id: <20220929014555.112323-3-lingshan.zhu@intel.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 2285651 commit c6dac2e

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

drivers/vdpa/vdpa.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ static int vdpa_dev_net_mq_config_fill(struct vdpa_device *vdev,
820820
static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *msg)
821821
{
822822
struct virtio_net_config config = {};
823-
u64 features_device, features_driver;
823+
u64 features_device;
824824
u16 val_u16;
825825

826826
vdev->config->get_config(vdev, 0, &config, sizeof(config));
@@ -837,11 +837,6 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms
837837
if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, val_u16))
838838
return -EMSGSIZE;
839839

840-
features_driver = vdev->config->get_driver_features(vdev);
841-
if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES, features_driver,
842-
VDPA_ATTR_PAD))
843-
return -EMSGSIZE;
844-
845840
features_device = vdev->config->get_device_features(vdev);
846841

847842
if (nla_put_u64_64bit(msg, VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES, features_device,
@@ -855,6 +850,8 @@ static int
855850
vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid, u32 seq,
856851
int flags, struct netlink_ext_ack *extack)
857852
{
853+
u64 features_driver;
854+
u8 status = 0;
858855
u32 device_id;
859856
void *hdr;
860857
int err;
@@ -878,6 +875,17 @@ vdpa_dev_config_fill(struct vdpa_device *vdev, struct sk_buff *msg, u32 portid,
878875
goto msg_err;
879876
}
880877

878+
/* only read driver features after the feature negotiation is done */
879+
status = vdev->config->get_status(vdev);
880+
if (status & VIRTIO_CONFIG_S_FEATURES_OK) {
881+
features_driver = vdev->config->get_driver_features(vdev);
882+
if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES, features_driver,
883+
VDPA_ATTR_PAD)) {
884+
err = -EMSGSIZE;
885+
goto msg_err;
886+
}
887+
}
888+
881889
switch (device_id) {
882890
case VIRTIO_ID_NET:
883891
err = vdpa_dev_net_config_fill(vdev, msg);

0 commit comments

Comments
 (0)