Skip to content

Commit 8944521

Browse files
mcoquelinmstsirkin
authored andcommitted
vduse: enable Virtio-net device type
This patch adds Virtio-net device type to the supported devices types. Initialization fails if the device does not support VIRTIO_F_VERSION_1 feature, in order to guarantee the configuration space is read-only. It also fails with -EPERM if the CAP_NET_ADMIN is missing. Acked-by: Jason Wang <[email protected]> Reviewed-by: Eugenio Pérez <[email protected]> Signed-off-by: Maxime Coquelin <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Reviewed-by: Xie Yongji <[email protected]>
1 parent 56e7188 commit 8944521

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drivers/vdpa/vdpa_user/vduse_dev.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ static struct workqueue_struct *vduse_irq_bound_wq;
143143

144144
static u32 allowed_device_id[] = {
145145
VIRTIO_ID_BLOCK,
146+
VIRTIO_ID_NET,
146147
};
147148

148149
static inline struct vduse_dev *vdpa_to_vduse(struct vdpa_device *vdpa)
@@ -1720,6 +1721,10 @@ static bool features_is_valid(struct vduse_dev_config *config)
17201721
(config->features & BIT_ULL(VIRTIO_NET_F_CTRL_VQ)))
17211722
return false;
17221723

1724+
if ((config->device_id == VIRTIO_ID_NET) &&
1725+
!(config->features & BIT_ULL(VIRTIO_F_VERSION_1)))
1726+
return false;
1727+
17231728
return true;
17241729
}
17251730

@@ -1827,6 +1832,10 @@ static int vduse_create_dev(struct vduse_dev_config *config,
18271832
int ret;
18281833
struct vduse_dev *dev;
18291834

1835+
ret = -EPERM;
1836+
if ((config->device_id == VIRTIO_ID_NET) && !capable(CAP_NET_ADMIN))
1837+
goto err;
1838+
18301839
ret = -EEXIST;
18311840
if (vduse_find_dev(config->name))
18321841
goto err;
@@ -2070,6 +2079,7 @@ static const struct vdpa_mgmtdev_ops vdpa_dev_mgmtdev_ops = {
20702079

20712080
static struct virtio_device_id id_table[] = {
20722081
{ VIRTIO_ID_BLOCK, VIRTIO_DEV_ANY_ID },
2082+
{ VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID },
20732083
{ 0 },
20742084
};
20752085

0 commit comments

Comments
 (0)