Commit c0a7233f authored by Michael S. Tsirkin's avatar Michael S. Tsirkin

Merge tag 'stable/vduse-virtio-net' into vhost

This adds support for virtio-net to vduse.
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parents 89875151 89445218
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
* *
*/ */
#include "linux/virtio_net.h"
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/cdev.h> #include <linux/cdev.h>
...@@ -28,6 +29,7 @@ ...@@ -28,6 +29,7 @@
#include <uapi/linux/virtio_config.h> #include <uapi/linux/virtio_config.h>
#include <uapi/linux/virtio_ids.h> #include <uapi/linux/virtio_ids.h>
#include <uapi/linux/virtio_blk.h> #include <uapi/linux/virtio_blk.h>
#include <uapi/linux/virtio_ring.h>
#include <linux/mod_devicetable.h> #include <linux/mod_devicetable.h>
#include "iova_domain.h" #include "iova_domain.h"
...@@ -141,6 +143,7 @@ static struct workqueue_struct *vduse_irq_bound_wq; ...@@ -141,6 +143,7 @@ static struct workqueue_struct *vduse_irq_bound_wq;
static u32 allowed_device_id[] = { static u32 allowed_device_id[] = {
VIRTIO_ID_BLOCK, VIRTIO_ID_BLOCK,
VIRTIO_ID_NET,
}; };
static inline struct vduse_dev *vdpa_to_vduse(struct vdpa_device *vdpa) static inline struct vduse_dev *vdpa_to_vduse(struct vdpa_device *vdpa)
...@@ -1705,13 +1708,21 @@ static bool device_is_allowed(u32 device_id) ...@@ -1705,13 +1708,21 @@ static bool device_is_allowed(u32 device_id)
return false; return false;
} }
static bool features_is_valid(u64 features) static bool features_is_valid(struct vduse_dev_config *config)
{ {
if (!(features & (1ULL << VIRTIO_F_ACCESS_PLATFORM))) if (!(config->features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
return false; return false;
/* Now we only support read-only configuration space */ /* Now we only support read-only configuration space */
if (features & (1ULL << VIRTIO_BLK_F_CONFIG_WCE)) if ((config->device_id == VIRTIO_ID_BLOCK) &&
(config->features & BIT_ULL(VIRTIO_BLK_F_CONFIG_WCE)))
return false;
else if ((config->device_id == VIRTIO_ID_NET) &&
(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 false;
return true; return true;
...@@ -1738,7 +1749,7 @@ static bool vduse_validate_config(struct vduse_dev_config *config) ...@@ -1738,7 +1749,7 @@ static bool vduse_validate_config(struct vduse_dev_config *config)
if (!device_is_allowed(config->device_id)) if (!device_is_allowed(config->device_id))
return false; return false;
if (!features_is_valid(config->features)) if (!features_is_valid(config))
return false; return false;
return true; return true;
...@@ -1821,6 +1832,10 @@ static int vduse_create_dev(struct vduse_dev_config *config, ...@@ -1821,6 +1832,10 @@ static int vduse_create_dev(struct vduse_dev_config *config,
int ret; int ret;
struct vduse_dev *dev; struct vduse_dev *dev;
ret = -EPERM;
if ((config->device_id == VIRTIO_ID_NET) && !capable(CAP_NET_ADMIN))
goto err;
ret = -EEXIST; ret = -EEXIST;
if (vduse_find_dev(config->name)) if (vduse_find_dev(config->name))
goto err; goto err;
...@@ -2064,6 +2079,7 @@ static const struct vdpa_mgmtdev_ops vdpa_dev_mgmtdev_ops = { ...@@ -2064,6 +2079,7 @@ static const struct vdpa_mgmtdev_ops vdpa_dev_mgmtdev_ops = {
static struct virtio_device_id id_table[] = { static struct virtio_device_id id_table[] = {
{ VIRTIO_ID_BLOCK, VIRTIO_DEV_ANY_ID }, { VIRTIO_ID_BLOCK, VIRTIO_DEV_ANY_ID },
{ VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID },
{ 0 }, { 0 },
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment