]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
vdpa: introduce map ops
authorJason Wang <jasowang@redhat.com>
Wed, 24 Sep 2025 07:00:44 +0000 (15:00 +0800)
committerMichael S. Tsirkin <mst@redhat.com>
Wed, 1 Oct 2025 11:24:55 +0000 (07:24 -0400)
Virtio core allows the transport to provide device or transport
specific mapping functions. This patch adds this support to vDPA. We
can simply do this by allowing the vDPA parent to register a
virtio_map_ops.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Message-Id: <20250924070045.10361-2-jasowang@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Eugenio Pérez <eperezma@redhat.com>
12 files changed:
drivers/vdpa/alibaba/eni_vdpa.c
drivers/vdpa/ifcvf/ifcvf_main.c
drivers/vdpa/mlx5/net/mlx5_vnet.c
drivers/vdpa/octeon_ep/octep_vdpa_main.c
drivers/vdpa/pds/vdpa_dev.c
drivers/vdpa/solidrun/snet_main.c
drivers/vdpa/vdpa.c
drivers/vdpa/vdpa_sim/vdpa_sim.c
drivers/vdpa/vdpa_user/vduse_dev.c
drivers/vdpa/virtio_pci/vp_vdpa.c
drivers/virtio/virtio_vdpa.c
include/linux/vdpa.h

index 54aea086d08c36f1e402544e4c99b34b189a2da5..e476504db0c82da2f41545407f5a86782a05038e 100644 (file)
@@ -478,7 +478,8 @@ 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, 1, NULL, false);
+                                    dev, &eni_vdpa_ops, NULL,
+                                    1, 1, NULL, false);
        if (IS_ERR(eni_vdpa)) {
                ENI_ERR(pdev, "failed to allocate vDPA structure\n");
                return PTR_ERR(eni_vdpa);
index 979d188d74ee85d19b76d04f71c2b7af330b158e..6658dc74d9150d2863aa2fb62ec5edf8815b184e 100644 (file)
@@ -705,7 +705,8 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
        vf = &ifcvf_mgmt_dev->vf;
        pdev = vf->pdev;
        adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa,
-                                   &pdev->dev, &ifc_vdpa_ops, 1, 1, NULL, false);
+                                   &pdev->dev, &ifc_vdpa_ops,
+                                   NULL, 1, 1, NULL, false);
        if (IS_ERR(adapter)) {
                IFCVF_ERR(pdev, "Failed to allocate vDPA structure");
                return PTR_ERR(adapter);
index a7e76f1759142bacfe193bfaafc3768839aa0ae6..82034efb74fc7cecb9fe378b430b6c1109f59d7e 100644 (file)
@@ -3882,7 +3882,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, &mgtdev->vdpa_ops,
-                                MLX5_VDPA_NUMVQ_GROUPS, MLX5_VDPA_NUM_AS, name, false);
+                                NULL, MLX5_VDPA_NUMVQ_GROUPS, MLX5_VDPA_NUM_AS, name, false);
        if (IS_ERR(ndev))
                return PTR_ERR(ndev);
 
index 5818dae133a3e2c6328f4a2b32e06a20ac6721f5..9e8d07078606f3f5b51ada397907d26ad9fbec83 100644 (file)
@@ -508,8 +508,8 @@ static int octep_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
        u64 device_features;
        int ret;
 
-       oct_vdpa = vdpa_alloc_device(struct octep_vdpa, vdpa, &pdev->dev, &octep_vdpa_ops, 1, 1,
-                                    NULL, false);
+       oct_vdpa = vdpa_alloc_device(struct octep_vdpa, vdpa, &pdev->dev, &octep_vdpa_ops,
+                                    NULL, 1, 1, NULL, false);
        if (IS_ERR(oct_vdpa)) {
                dev_err(&pdev->dev, "Failed to allocate vDPA structure for octep vdpa device");
                return PTR_ERR(oct_vdpa);
index 63d82263fb521ff5c1ac0fd89bcc7464d2ca1c32..36f61cc96e2110488b6aa4d2a500569dc0191ef4 100644 (file)
@@ -632,7 +632,8 @@ static int pds_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
        }
 
        pdsv = vdpa_alloc_device(struct pds_vdpa_device, vdpa_dev,
-                                dev, &pds_vdpa_ops, 1, 1, name, false);
+                                dev, &pds_vdpa_ops, NULL,
+                                1, 1, name, false);
        if (IS_ERR(pdsv)) {
                dev_err(dev, "Failed to allocate vDPA structure: %pe\n", pdsv);
                return PTR_ERR(pdsv);
index 39050aab147f1121096c326b552682fae0b5041a..4588211d57ebc6448bdcca7c818d8640d60bd6b7 100644 (file)
@@ -1008,8 +1008,8 @@ static int snet_vdpa_probe_vf(struct pci_dev *pdev)
        }
 
        /* Allocate vdpa device */
-       snet = vdpa_alloc_device(struct snet, vdpa, &pdev->dev, &snet_config_ops, 1, 1, NULL,
-                                false);
+       snet = vdpa_alloc_device(struct snet, vdpa, &pdev->dev, &snet_config_ops,
+                                NULL, 1, 1, NULL, false);
        if (!snet) {
                SNET_ERR(pdev, "Failed to allocate a vdpa device\n");
                ret = -ENOMEM;
index c71debeb8471b6a1ba097c135a2b45cc50f9aafd..34874beb0152eec89312468485aba189e2024913 100644 (file)
@@ -142,6 +142,7 @@ static void vdpa_release_dev(struct device *d)
  * initialized but before registered.
  * @parent: the parent device
  * @config: the bus operations that is supported by this device
+ * @map: the map 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
@@ -156,6 +157,7 @@ static void vdpa_release_dev(struct device *d)
  */
 struct vdpa_device *__vdpa_alloc_device(struct device *parent,
                                        const struct vdpa_config_ops *config,
+                                       const struct virtio_map_ops *map,
                                        unsigned int ngroups, unsigned int nas,
                                        size_t size, const char *name,
                                        bool use_va)
@@ -187,6 +189,7 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent,
        vdev->dev.release = vdpa_release_dev;
        vdev->index = err;
        vdev->config = config;
+       vdev->map = map;
        vdev->features_valid = false;
        vdev->use_va = use_va;
        vdev->ngroups = ngroups;
index 22ee53538444ccd1f569f2b65f028ff1baf55c57..c1c6431950e1b1917af981d400639e40daa0aaef 100644 (file)
@@ -215,7 +215,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr,
        else
                ops = &vdpasim_config_ops;
 
-       vdpa = __vdpa_alloc_device(NULL, ops,
+       vdpa = __vdpa_alloc_device(NULL, ops, NULL,
                                   dev_attr->ngroups, dev_attr->nas,
                                   dev_attr->alloc_size,
                                   dev_attr->name, use_va);
index f68ed569394cbeb25c7939716e29adf738a9cea2..ad782d20a8ed5283ee1bcbd81c9ba0a3ea5399bd 100644 (file)
@@ -2009,7 +2009,8 @@ static int vduse_dev_init_vdpa(struct vduse_dev *dev, const char *name)
                return -EEXIST;
 
        vdev = vdpa_alloc_device(struct vduse_vdpa, vdpa, dev->dev,
-                                &vduse_vdpa_config_ops, 1, 1, name, true);
+                                &vduse_vdpa_config_ops, NULL,
+                                1, 1, name, true);
        if (IS_ERR(vdev))
                return PTR_ERR(vdev);
 
index 242641c0f2bde36f2642247c486468a95fad6cad..17a19a728c9cb29ad1757b49db16b15427090664 100644 (file)
@@ -511,7 +511,8 @@ static int vp_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
        int ret, i;
 
        vp_vdpa = vdpa_alloc_device(struct vp_vdpa, vdpa,
-                                   dev, &vp_vdpa_ops, 1, 1, name, false);
+                                   dev, &vp_vdpa_ops, NULL,
+                                   1, 1, name, false);
 
        if (IS_ERR(vp_vdpa)) {
                dev_err(dev, "vp_vdpa: Failed to allocate vDPA structure\n");
index 8b27c6e8eebbcadd8036fa0bf465e19676f69ef1..2464fa655f09425b9839955ed811bbcd40c6019b 100644 (file)
@@ -466,9 +466,11 @@ static int virtio_vdpa_probe(struct vdpa_device *vdpa)
        if (!vd_dev)
                return -ENOMEM;
 
-       vd_dev->vdev.dev.parent = vdpa_get_map(vdpa).dma_dev;
+       vd_dev->vdev.dev.parent = vdpa->map ? &vdpa->dev :
+                                 vdpa_get_map(vdpa).dma_dev;
        vd_dev->vdev.dev.release = virtio_vdpa_release_dev;
        vd_dev->vdev.config = &virtio_vdpa_config_ops;
+       vd_dev->vdev.map = vdpa->map;
        vd_dev->vdpa = vdpa;
 
        vd_dev->vdev.id.device = ops->get_device_id(vdpa);
index ae04519458519d5ddc965719fc29b2e37afac5f1..4cf21d6e9cfde269742048899f0b0cff4c4a1ae7 100644 (file)
@@ -76,6 +76,7 @@ struct vdpa_mgmt_dev;
  *                   because core frees it; use driver_set_override() to
  *                   set or clear it.
  * @config: the configuration ops for this device.
+ * @map: the map ops for this device
  * @cf_lock: Protects get and set access to configuration layout.
  * @index: device index
  * @features_valid: were features initialized? for legacy guests
@@ -91,6 +92,7 @@ struct vdpa_device {
        union virtio_map vmap;
        const char *driver_override;
        const struct vdpa_config_ops *config;
+       const struct virtio_map_ops *map;
        struct rw_semaphore cf_lock; /* Protects get/set config */
        unsigned int index;
        bool features_valid;
@@ -447,6 +449,7 @@ struct vdpa_config_ops {
 
 struct vdpa_device *__vdpa_alloc_device(struct device *parent,
                                        const struct vdpa_config_ops *config,
+                                       const struct virtio_map_ops *map,
                                        unsigned int ngroups, unsigned int nas,
                                        size_t size, const char *name,
                                        bool use_va);
@@ -458,6 +461,7 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent,
  * @member: the name of struct vdpa_device within the @dev_struct
  * @parent: the parent device
  * @config: the bus operations that is supported by this device
+ * @map: the map operations that is supported by this device
  * @ngroups: the number of virtqueue groups supported by this device
  * @nas: the number of address spaces
  * @name: name of the vdpa device
@@ -465,10 +469,10 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent,
  *
  * Return allocated data structure or ERR_PTR upon error
  */
-#define vdpa_alloc_device(dev_struct, member, parent, config, ngroups, nas, \
-                         name, use_va) \
+#define vdpa_alloc_device(dev_struct, member, parent, config, map, \
+                         ngroups, nas, name, use_va)              \
                          container_of((__vdpa_alloc_device( \
-                                      parent, config, ngroups, nas, \
+                                      parent, config, map, ngroups, nas, \
                                       (sizeof(dev_struct) + \
                                       BUILD_BUG_ON_ZERO(offsetof( \
                                       dev_struct, member))), name, use_va)), \