Commit db9adcbf authored by Gautam Dawar's avatar Gautam Dawar Committed by Michael S. Tsirkin
Browse files

vdpa: multiple address spaces support



This patches introduces the multiple address spaces support for vDPA
device. This idea is to identify a specific address space via an
dedicated identifier - ASID.

During vDPA device allocation, vDPA device driver needs to report the
number of address spaces supported by the device then the DMA mapping
ops of the vDPA device needs to be extended to support ASID.

This helps to isolate the environments for the virtqueue that will not
be assigned directly. E.g in the case of virtio-net, the control
virtqueue will not be assigned directly to guest.

As a start, simply claim 1 virtqueue groups and 1 address spaces for
all vDPA devices. And vhost-vDPA will simply reject the device with
more than 1 virtqueue groups or address spaces.

Signed-off-by: default avatarJason Wang <jasowang@redhat.com>
Signed-off-by: default avatarGautam Dawar <gdawar@xilinx.com>
Message-Id: <20220330180436.24644-7-gdawar@xilinx.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent d4821902
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -470,7 +470,7 @@ static int eni_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id)
		return ret;

	eni_vdpa = vdpa_alloc_device(struct eni_vdpa, vdpa,
				     dev, &eni_vdpa_ops, 1, NULL, false);
				     dev, &eni_vdpa_ops, 1, 1, NULL, false);
	if (IS_ERR(eni_vdpa)) {
		ENI_ERR(pdev, "failed to allocate vDPA structure\n");
		return PTR_ERR(eni_vdpa);
+1 −1
Original line number Diff line number Diff line
@@ -764,7 +764,7 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
	pdev = ifcvf_mgmt_dev->pdev;
	dev = &pdev->dev;
	adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa,
				    dev, &ifc_vdpa_ops, 1, name, false);
				    dev, &ifc_vdpa_ops, 1, 1, name, false);
	if (IS_ERR(adapter)) {
		IFCVF_ERR(pdev, "Failed to allocate vDPA structure");
		return PTR_ERR(adapter);
+3 −2
Original line number Diff line number Diff line
@@ -2409,7 +2409,8 @@ static u32 mlx5_vdpa_get_generation(struct vdpa_device *vdev)
	return mvdev->generation;
}

static int mlx5_vdpa_set_map(struct vdpa_device *vdev, struct vhost_iotlb *iotlb)
static int mlx5_vdpa_set_map(struct vdpa_device *vdev, unsigned int asid,
			     struct vhost_iotlb *iotlb)
{
	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
	struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
@@ -2823,7 +2824,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
	}

	ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device, &mlx5_vdpa_ops,
				 1, name, false);
				 1, 1, name, false);
	if (IS_ERR(ndev))
		return PTR_ERR(ndev);

+3 −1
Original line number Diff line number Diff line
@@ -159,6 +159,7 @@ static void vdpa_release_dev(struct device *d)
 * @parent: the parent device
 * @config: the bus operations that is supported by this device
 * @ngroups: number of groups supported by this device
 * @nas: number of address spaces supported by this device
 * @size: size of the parent structure that contains private data
 * @name: name of the vdpa device; optional.
 * @use_va: indicate whether virtual address must be used by this device
@@ -171,7 +172,7 @@ static void vdpa_release_dev(struct device *d)
 */
struct vdpa_device *__vdpa_alloc_device(struct device *parent,
					const struct vdpa_config_ops *config,
					unsigned int ngroups,
					unsigned int ngroups, unsigned int nas,
					size_t size, const char *name,
					bool use_va)
{
@@ -205,6 +206,7 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent,
	vdev->features_valid = false;
	vdev->use_va = use_va;
	vdev->ngroups = ngroups;
	vdev->nas = nas;

	if (name)
		err = dev_set_name(&vdev->dev, "%s", name);
+6 −4
Original line number Diff line number Diff line
@@ -251,7 +251,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr)
		ops = &vdpasim_config_ops;

	vdpasim = vdpa_alloc_device(struct vdpasim, vdpa, NULL, ops, 1,
				    dev_attr->name, false);
				    1, dev_attr->name, false);
	if (IS_ERR(vdpasim)) {
		ret = PTR_ERR(vdpasim);
		goto err_alloc;
@@ -539,7 +539,7 @@ static struct vdpa_iova_range vdpasim_get_iova_range(struct vdpa_device *vdpa)
	return range;
}

static int vdpasim_set_map(struct vdpa_device *vdpa,
static int vdpasim_set_map(struct vdpa_device *vdpa, unsigned int asid,
			   struct vhost_iotlb *iotlb)
{
	struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
@@ -566,7 +566,8 @@ static int vdpasim_set_map(struct vdpa_device *vdpa,
	return ret;
}

static int vdpasim_dma_map(struct vdpa_device *vdpa, u64 iova, u64 size,
static int vdpasim_dma_map(struct vdpa_device *vdpa, unsigned int asid,
			   u64 iova, u64 size,
			   u64 pa, u32 perm, void *opaque)
{
	struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
@@ -580,7 +581,8 @@ static int vdpasim_dma_map(struct vdpa_device *vdpa, u64 iova, u64 size,
	return ret;
}

static int vdpasim_dma_unmap(struct vdpa_device *vdpa, u64 iova, u64 size)
static int vdpasim_dma_unmap(struct vdpa_device *vdpa, unsigned int asid,
			     u64 iova, u64 size)
{
	struct vdpasim *vdpasim = vdpa_to_sim(vdpa);

Loading