Skip to content

Commit 477f719

Browse files
jasowangmstsirkin
authored andcommitted
vdpa_sim_net: support feature provisioning
This patch implements features provisioning for vdpa_sim_net. 1) validating the provisioned features to be a subset of the parent features. 2) clearing the features that is not wanted by the userspace For example: vdpasim_net: supported_classes net max_supported_vqs 3 dev_features MTU MAC CTRL_VQ CTRL_MAC_ADDR ANY_LAYOUT VERSION_1 ACCESS_PLATFORM 1) provision vDPA device with all features that are supported by the net simulator dev1: mac 00:00:00:00:00:00 link up link_announce false mtu 1500 negotiated_features MTU MAC CTRL_VQ CTRL_MAC_ADDR VERSION_1 ACCESS_PLATFORM 2) provision vDPA device with a subset of the features dev1: mac 00:00:00:00:00:00 link up link_announce false mtu 1500 negotiated_features CTRL_VQ VERSION_1 ACCESS_PLATFORM Reviewed-by: Eli Cohen <elic@nvidia.com> Signed-off-by: Jason Wang <jasowang@redhat.com> Message-Id: <20220927074810.28627-3-jasowang@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
1 parent 90fea5a commit 477f719

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

drivers/vdpa/vdpa_sim/vdpa_sim.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/vdpa.h>
1919
#include <linux/vhost_iotlb.h>
2020
#include <linux/iova.h>
21+
#include <uapi/linux/vdpa.h>
2122

2223
#include "vdpa_sim.h"
2324

@@ -245,13 +246,22 @@ static const struct dma_map_ops vdpasim_dma_ops = {
245246
static const struct vdpa_config_ops vdpasim_config_ops;
246247
static const struct vdpa_config_ops vdpasim_batch_config_ops;
247248

248-
struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr)
249+
struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr,
250+
const struct vdpa_dev_set_config *config)
249251
{
250252
const struct vdpa_config_ops *ops;
251253
struct vdpasim *vdpasim;
252254
struct device *dev;
253255
int i, ret = -ENOMEM;
254256

257+
if (config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) {
258+
if (config->device_features &
259+
~dev_attr->supported_features)
260+
return ERR_PTR(-EINVAL);
261+
dev_attr->supported_features =
262+
config->device_features;
263+
}
264+
255265
if (batch_mapping)
256266
ops = &vdpasim_batch_config_ops;
257267
else

drivers/vdpa/vdpa_sim/vdpa_sim.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ struct vdpasim {
7171
spinlock_t iommu_lock;
7272
};
7373

74-
struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *attr);
74+
struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *attr,
75+
const struct vdpa_dev_set_config *config);
7576

7677
/* TODO: cross-endian support */
7778
static inline bool vdpasim_is_little_endian(struct vdpasim *vdpasim)

drivers/vdpa/vdpa_sim/vdpa_sim_blk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ static int vdpasim_blk_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
383383
dev_attr.work_fn = vdpasim_blk_work;
384384
dev_attr.buffer_size = VDPASIM_BLK_CAPACITY << SECTOR_SHIFT;
385385

386-
simdev = vdpasim_create(&dev_attr);
386+
simdev = vdpasim_create(&dev_attr, config);
387387
if (IS_ERR(simdev))
388388
return PTR_ERR(simdev);
389389

drivers/vdpa/vdpa_sim/vdpa_sim_net.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
254254
dev_attr.work_fn = vdpasim_net_work;
255255
dev_attr.buffer_size = PAGE_SIZE;
256256

257-
simdev = vdpasim_create(&dev_attr);
257+
simdev = vdpasim_create(&dev_attr, config);
258258
if (IS_ERR(simdev))
259259
return PTR_ERR(simdev);
260260

@@ -294,7 +294,8 @@ static struct vdpa_mgmt_dev mgmt_dev = {
294294
.id_table = id_table,
295295
.ops = &vdpasim_net_mgmtdev_ops,
296296
.config_attr_mask = (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR |
297-
1 << VDPA_ATTR_DEV_NET_CFG_MTU),
297+
1 << VDPA_ATTR_DEV_NET_CFG_MTU |
298+
1 << VDPA_ATTR_DEV_FEATURES),
298299
.max_supported_vqs = VDPASIM_NET_VQ_NUM,
299300
.supported_features = VDPASIM_NET_FEATURES,
300301
};

0 commit comments

Comments
 (0)