Skip to content

Commit c0a7233

Browse files
committed
Merge tag 'stable/vduse-virtio-net' into vhost
This adds support for virtio-net to vduse. Signed-off-by: Michael S. Tsirkin <[email protected]>
2 parents 8987515 + 8944521 commit c0a7233

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

drivers/vdpa/vdpa_user/vduse_dev.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*
99
*/
1010

11+
#include "linux/virtio_net.h"
1112
#include <linux/init.h>
1213
#include <linux/module.h>
1314
#include <linux/cdev.h>
@@ -28,6 +29,7 @@
2829
#include <uapi/linux/virtio_config.h>
2930
#include <uapi/linux/virtio_ids.h>
3031
#include <uapi/linux/virtio_blk.h>
32+
#include <uapi/linux/virtio_ring.h>
3133
#include <linux/mod_devicetable.h>
3234

3335
#include "iova_domain.h"
@@ -141,6 +143,7 @@ static struct workqueue_struct *vduse_irq_bound_wq;
141143

142144
static u32 allowed_device_id[] = {
143145
VIRTIO_ID_BLOCK,
146+
VIRTIO_ID_NET,
144147
};
145148

146149
static inline struct vduse_dev *vdpa_to_vduse(struct vdpa_device *vdpa)
@@ -1705,13 +1708,21 @@ static bool device_is_allowed(u32 device_id)
17051708
return false;
17061709
}
17071710

1708-
static bool features_is_valid(u64 features)
1711+
static bool features_is_valid(struct vduse_dev_config *config)
17091712
{
1710-
if (!(features & (1ULL << VIRTIO_F_ACCESS_PLATFORM)))
1713+
if (!(config->features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)))
17111714
return false;
17121715

17131716
/* Now we only support read-only configuration space */
1714-
if (features & (1ULL << VIRTIO_BLK_F_CONFIG_WCE))
1717+
if ((config->device_id == VIRTIO_ID_BLOCK) &&
1718+
(config->features & BIT_ULL(VIRTIO_BLK_F_CONFIG_WCE)))
1719+
return false;
1720+
else if ((config->device_id == VIRTIO_ID_NET) &&
1721+
(config->features & BIT_ULL(VIRTIO_NET_F_CTRL_VQ)))
1722+
return false;
1723+
1724+
if ((config->device_id == VIRTIO_ID_NET) &&
1725+
!(config->features & BIT_ULL(VIRTIO_F_VERSION_1)))
17151726
return false;
17161727

17171728
return true;
@@ -1738,7 +1749,7 @@ static bool vduse_validate_config(struct vduse_dev_config *config)
17381749
if (!device_is_allowed(config->device_id))
17391750
return false;
17401751

1741-
if (!features_is_valid(config->features))
1752+
if (!features_is_valid(config))
17421753
return false;
17431754

17441755
return true;
@@ -1821,6 +1832,10 @@ static int vduse_create_dev(struct vduse_dev_config *config,
18211832
int ret;
18221833
struct vduse_dev *dev;
18231834

1835+
ret = -EPERM;
1836+
if ((config->device_id == VIRTIO_ID_NET) && !capable(CAP_NET_ADMIN))
1837+
goto err;
1838+
18241839
ret = -EEXIST;
18251840
if (vduse_find_dev(config->name))
18261841
goto err;
@@ -2064,6 +2079,7 @@ static const struct vdpa_mgmtdev_ops vdpa_dev_mgmtdev_ops = {
20642079

20652080
static struct virtio_device_id id_table[] = {
20662081
{ VIRTIO_ID_BLOCK, VIRTIO_DEV_ANY_ID },
2082+
{ VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID },
20672083
{ 0 },
20682084
};
20692085

0 commit comments

Comments
 (0)