summaryrefslogtreecommitdiff
path: root/drivers/vdpa
diff options
context:
space:
mode:
authorMaxime Coquelin <maxime.coquelin@redhat.com>2024-01-09 14:10:25 +0300
committerMichael S. Tsirkin <mst@redhat.com>2024-03-19 15:19:15 +0300
commit894452180d732413fd29fa95a4820560fa44ca4a (patch)
treee3363026623f490191cbd3bf5b5518b560da82c4 /drivers/vdpa
parent56e71885b0349241c07631a7b979b61e81afab6a (diff)
downloadlinux-894452180d732413fd29fa95a4820560fa44ca4a.tar.xz
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 <jasowang@redhat.com> Reviewed-by: Eugenio PĂ©rez <eperezma@redhat.com> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com> Message-Id: <20240109111025.1320976-4-maxime.coquelin@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Xie Yongji <xieyongji@bytedance.com>
Diffstat (limited to 'drivers/vdpa')
-rw-r--r--drivers/vdpa/vdpa_user/vduse_dev.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
index ac8b5b52e3dc..7ae99691efdf 100644
--- a/drivers/vdpa/vdpa_user/vduse_dev.c
+++ b/drivers/vdpa/vdpa_user/vduse_dev.c
@@ -143,6 +143,7 @@ static struct workqueue_struct *vduse_irq_bound_wq;
static u32 allowed_device_id[] = {
VIRTIO_ID_BLOCK,
+ VIRTIO_ID_NET,
};
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)
(config->features & BIT_ULL(VIRTIO_NET_F_CTRL_VQ)))
return false;
+ if ((config->device_id == VIRTIO_ID_NET) &&
+ !(config->features & BIT_ULL(VIRTIO_F_VERSION_1)))
+ return false;
+
return true;
}
@@ -1827,6 +1832,10 @@ static int vduse_create_dev(struct vduse_dev_config *config,
int ret;
struct vduse_dev *dev;
+ ret = -EPERM;
+ if ((config->device_id == VIRTIO_ID_NET) && !capable(CAP_NET_ADMIN))
+ goto err;
+
ret = -EEXIST;
if (vduse_find_dev(config->name))
goto err;
@@ -2070,6 +2079,7 @@ static const struct vdpa_mgmtdev_ops vdpa_dev_mgmtdev_ops = {
static struct virtio_device_id id_table[] = {
{ VIRTIO_ID_BLOCK, VIRTIO_DEV_ANY_ID },
+ { VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID },
{ 0 },
};