Skip to content

Commit 2285651

Browse files
ls-zhumstsirkin
authored andcommitted
vDPA: allow userspace to query features of a vDPA device
This commit adds a new vDPA netlink attribution VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES. Userspace can query features of vDPA devices through this new attr. This commit invokes vdpa_config_ops.get_config() rather than vdpa_get_config_unlocked() to read the device config spcae, so no races in vdpa_set_features_unlocked() Userspace tool iproute2 example: $ vdpa dev config show vdpa0 vdpa0: mac 00:e8:ca:11:be:05 link up link_announce false max_vq_pairs 4 mtu 1500 negotiated_features MRG_RXBUF CTRL_VQ MQ VERSION_1 ACCESS_PLATFORM dev_features MTU MAC MRG_RXBUF CTRL_VQ MQ ANY_LAYOUT VERSION_1 ACCESS_PLATFORM Signed-off-by: Zhu Lingshan <lingshan.zhu@intel.com> Message-Id: <20220929014555.112323-2-lingshan.zhu@intel.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent e60d640 commit 2285651

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

drivers/vdpa/vdpa.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -820,10 +820,10 @@ 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;
823+
u64 features_device, features_driver;
824824
u16 val_u16;
825825

826-
vdpa_get_config_unlocked(vdev, 0, &config, sizeof(config));
826+
vdev->config->get_config(vdev, 0, &config, sizeof(config));
827827

828828
if (nla_put(msg, VDPA_ATTR_DEV_NET_CFG_MACADDR, sizeof(config.mac),
829829
config.mac))
@@ -837,12 +837,18 @@ 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 = vdev->config->get_driver_features(vdev);
841-
if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES, features,
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+
845+
features_device = vdev->config->get_device_features(vdev);
846+
847+
if (nla_put_u64_64bit(msg, VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES, features_device,
842848
VDPA_ATTR_PAD))
843849
return -EMSGSIZE;
844850

845-
return vdpa_dev_net_mq_config_fill(vdev, msg, features, &config);
851+
return vdpa_dev_net_mq_config_fill(vdev, msg, features_driver, &config);
846852
}
847853

848854
static int

include/uapi/linux/vdpa.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ enum vdpa_attr {
4646

4747
VDPA_ATTR_DEV_NEGOTIATED_FEATURES, /* u64 */
4848
VDPA_ATTR_DEV_MGMTDEV_MAX_VQS, /* u32 */
49+
/* virtio features that are supported by the vDPA management device */
4950
VDPA_ATTR_DEV_SUPPORTED_FEATURES, /* u64 */
5051

5152
VDPA_ATTR_DEV_QUEUE_INDEX, /* u32 */
@@ -54,6 +55,9 @@ enum vdpa_attr {
5455

5556
VDPA_ATTR_DEV_FEATURES, /* u64 */
5657

58+
/* virtio features that are supported by the vDPA device */
59+
VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES, /* u64 */
60+
5761
/* new attributes must be added above here */
5862
VDPA_ATTR_MAX,
5963
};

0 commit comments

Comments
 (0)