[PATCH 7/9] vdpa: rename dma_dev to map_token

Jason Wang posted 9 patches 3 months, 1 week ago
There is a newer version of this series
[PATCH 7/9] vdpa: rename dma_dev to map_token
Posted by Jason Wang 3 months, 1 week ago
Virtio core switches from DMA device to mapping token, let's do that
as well for vDPA.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 drivers/vdpa/alibaba/eni_vdpa.c          |  2 +-
 drivers/vdpa/ifcvf/ifcvf_main.c          |  2 +-
 drivers/vdpa/octeon_ep/octep_vdpa_main.c |  2 +-
 drivers/vdpa/vdpa.c                      |  2 +-
 drivers/vdpa/vdpa_sim/vdpa_sim.c         |  2 +-
 drivers/vdpa/vdpa_user/vduse_dev.c       |  2 +-
 drivers/vdpa/virtio_pci/vp_vdpa.c        |  2 +-
 drivers/vhost/vdpa.c                     |  4 ++--
 drivers/virtio/virtio_vdpa.c             | 12 ++++++------
 include/linux/vdpa.h                     | 12 ++++++------
 10 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/drivers/vdpa/alibaba/eni_vdpa.c b/drivers/vdpa/alibaba/eni_vdpa.c
index ad7f3447fe90..34bf726dc660 100644
--- a/drivers/vdpa/alibaba/eni_vdpa.c
+++ b/drivers/vdpa/alibaba/eni_vdpa.c
@@ -496,7 +496,7 @@ static int eni_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	pci_set_master(pdev);
 	pci_set_drvdata(pdev, eni_vdpa);
 
-	eni_vdpa->vdpa.dma_dev = &pdev->dev;
+	eni_vdpa->vdpa.map_token = &pdev->dev;
 	eni_vdpa->queues = eni_vdpa_get_num_queues(eni_vdpa);
 
 	eni_vdpa->vring = devm_kcalloc(&pdev->dev, eni_vdpa->queues,
diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c
index ccf64d7bbfaa..64d28ec97136 100644
--- a/drivers/vdpa/ifcvf/ifcvf_main.c
+++ b/drivers/vdpa/ifcvf/ifcvf_main.c
@@ -713,7 +713,7 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
 
 	ifcvf_mgmt_dev->adapter = adapter;
 	adapter->pdev = pdev;
-	adapter->vdpa.dma_dev = &pdev->dev;
+	adapter->vdpa.map_token = &pdev->dev;
 	adapter->vdpa.mdev = mdev;
 	adapter->vf = vf;
 	vdpa_dev = &adapter->vdpa;
diff --git a/drivers/vdpa/octeon_ep/octep_vdpa_main.c b/drivers/vdpa/octeon_ep/octep_vdpa_main.c
index 9b49efd24391..42a4df4613dd 100644
--- a/drivers/vdpa/octeon_ep/octep_vdpa_main.c
+++ b/drivers/vdpa/octeon_ep/octep_vdpa_main.c
@@ -516,7 +516,7 @@ static int octep_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
 	}
 
 	oct_vdpa->pdev = pdev;
-	oct_vdpa->vdpa.dma_dev = &pdev->dev;
+	oct_vdpa->vdpa.map_token = &pdev->dev;
 	oct_vdpa->vdpa.mdev = mdev;
 	oct_vdpa->oct_hw = oct_hw;
 	vdpa_dev = &oct_vdpa->vdpa;
diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c
index 8a372b51c21a..1cc4285ebd67 100644
--- a/drivers/vdpa/vdpa.c
+++ b/drivers/vdpa/vdpa.c
@@ -151,7 +151,7 @@ static void vdpa_release_dev(struct device *d)
  * Driver should use vdpa_alloc_device() wrapper macro instead of
  * using this directly.
  *
- * Return: Returns an error when parent/config/dma_dev is not set or fail to get
+ * Return: Returns an error when parent/config/map_token is not set or fail to get
  *	   ida.
  */
 struct vdpa_device *__vdpa_alloc_device(struct device *parent,
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index c204fc8e471a..7c8e468f2f8c 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -272,7 +272,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr,
 		vringh_set_iotlb(&vdpasim->vqs[i].vring, &vdpasim->iommu[0],
 				 &vdpasim->iommu_lock);
 
-	vdpasim->vdpa.dma_dev = dev;
+	vdpasim->vdpa.map_token = dev;
 
 	return vdpasim;
 
diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
index 6a9a37351310..7420e90488ef 100644
--- a/drivers/vdpa/vdpa_user/vduse_dev.c
+++ b/drivers/vdpa/vdpa_user/vduse_dev.c
@@ -2022,7 +2022,7 @@ static int vduse_dev_init_vdpa(struct vduse_dev *dev, const char *name)
 		return ret;
 	}
 	set_dma_ops(&vdev->vdpa.dev, &vduse_dev_dma_ops);
-	vdev->vdpa.dma_dev = &vdev->vdpa.dev;
+	vdev->vdpa.map_token = &vdev->vdpa.dev;
 	vdev->vdpa.mdev = &vduse_mgmt->mgmt_dev;
 
 	return 0;
diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c
index 8787407f75b0..6e22e95245fa 100644
--- a/drivers/vdpa/virtio_pci/vp_vdpa.c
+++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
@@ -520,7 +520,7 @@ static int vp_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
 
 	vp_vdpa_mgtdev->vp_vdpa = vp_vdpa;
 
-	vp_vdpa->vdpa.dma_dev = &pdev->dev;
+	vp_vdpa->vdpa.map_token = &pdev->dev;
 	vp_vdpa->queues = vp_modern_get_num_queues(mdev);
 	vp_vdpa->mdev = mdev;
 
diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index 5a49b5a6d496..732ed118c138 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -1320,7 +1320,7 @@ static int vhost_vdpa_alloc_domain(struct vhost_vdpa *v)
 {
 	struct vdpa_device *vdpa = v->vdpa;
 	const struct vdpa_config_ops *ops = vdpa->config;
-	struct device *dma_dev = vdpa_get_dma_dev(vdpa);
+	struct device *dma_dev = vdpa_get_map_token(vdpa);
 	int ret;
 
 	/* Device want to do DMA by itself */
@@ -1355,7 +1355,7 @@ static int vhost_vdpa_alloc_domain(struct vhost_vdpa *v)
 static void vhost_vdpa_free_domain(struct vhost_vdpa *v)
 {
 	struct vdpa_device *vdpa = v->vdpa;
-	struct device *dma_dev = vdpa_get_dma_dev(vdpa);
+	struct device *dma_dev = vdpa_get_map_token(vdpa);
 
 	if (v->domain) {
 		iommu_detach_device(v->domain, dma_dev);
diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c
index 59b53032f1e2..cb68458cd809 100644
--- a/drivers/virtio/virtio_vdpa.c
+++ b/drivers/virtio/virtio_vdpa.c
@@ -147,7 +147,6 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
 {
 	struct virtio_vdpa_device *vd_dev = to_virtio_vdpa_device(vdev);
 	struct vdpa_device *vdpa = vd_get_vdpa(vdev);
-	struct device *dma_dev;
 	const struct vdpa_config_ops *ops = vdpa->config;
 	struct virtio_vdpa_vq_info *info;
 	bool (*notify)(struct virtqueue *vq) = virtio_vdpa_notify;
@@ -159,6 +158,7 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
 	unsigned long flags;
 	u32 align, max_num, min_num = 1;
 	bool may_reduce_num = true;
+	void *map_token;
 	int err;
 
 	if (!name)
@@ -201,13 +201,13 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
 	/* Create the vring */
 	align = ops->get_vq_align(vdpa);
 
-	if (ops->get_vq_dma_dev)
-		dma_dev = ops->get_vq_dma_dev(vdpa, index);
+	if (ops->get_vq_map_token)
+		map_token = ops->get_vq_map_token(vdpa, index);
 	else
-		dma_dev = vdpa_get_dma_dev(vdpa);
+		map_token = vdpa_get_map_token(vdpa);
 	vq = vring_create_virtqueue_map(index, max_num, align, vdev,
 					true, may_reduce_num, ctx,
-					notify, callback, name, dma_dev);
+					notify, callback, name, map_token);
 	if (!vq) {
 		err = -ENOMEM;
 		goto error_new_virtqueue;
@@ -497,7 +497,7 @@ static int virtio_vdpa_probe(struct vdpa_device *vdpa)
 	if (!vd_dev)
 		return -ENOMEM;
 
-	vd_dev->vdev.dev.parent = vdpa_get_dma_dev(vdpa);
+	vd_dev->vdev.dev.parent = vdpa_get_map_token(vdpa);
 	vd_dev->vdev.dev.release = virtio_vdpa_release_dev;
 	vd_dev->vdev.config = &virtio_vdpa_config_ops;
 	vd_dev->vdpa = vdpa;
diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h
index 2e7a30fe6b92..352ca5609c9a 100644
--- a/include/linux/vdpa.h
+++ b/include/linux/vdpa.h
@@ -70,7 +70,7 @@ struct vdpa_mgmt_dev;
 /**
  * struct vdpa_device - representation of a vDPA device
  * @dev: underlying device
- * @dma_dev: the actual device that is performing DMA
+ * @map_token: the token passed to upper layer to be used for mappping
  * @driver_override: driver name to force a match; do not set directly,
  *                   because core frees it; use driver_set_override() to
  *                   set or clear it.
@@ -87,7 +87,7 @@ struct vdpa_mgmt_dev;
  */
 struct vdpa_device {
 	struct device dev;
-	struct device *dma_dev;
+	void *map_token;
 	const char *driver_override;
 	const struct vdpa_config_ops *config;
 	struct rw_semaphore cf_lock; /* Protects get/set config */
@@ -352,7 +352,7 @@ struct vdpa_map_file {
  *				@vdev: vdpa device
  *				@asid: address space identifier
  *				Returns integer: success (0) or error (< 0)
- * @get_vq_dma_dev:		Get the dma device for a specific
+ * @get_vq_map_token:		Get the map token for a specific
  *				virtqueue (optional)
  *				@vdev: vdpa device
  *				@idx: virtqueue index
@@ -436,7 +436,7 @@ struct vdpa_config_ops {
 	int (*reset_map)(struct vdpa_device *vdev, unsigned int asid);
 	int (*set_group_asid)(struct vdpa_device *vdev, unsigned int group,
 			      unsigned int asid);
-	struct device *(*get_vq_dma_dev)(struct vdpa_device *vdev, u16 idx);
+	struct device *(*get_vq_map_token)(struct vdpa_device *vdev, u16 idx);
 	int (*bind_mm)(struct vdpa_device *vdev, struct mm_struct *mm);
 	void (*unbind_mm)(struct vdpa_device *vdev);
 
@@ -520,9 +520,9 @@ static inline void vdpa_set_drvdata(struct vdpa_device *vdev, void *data)
 	dev_set_drvdata(&vdev->dev, data);
 }
 
-static inline struct device *vdpa_get_dma_dev(struct vdpa_device *vdev)
+static inline void *vdpa_get_map_token(struct vdpa_device *vdev)
 {
-	return vdev->dma_dev;
+	return vdev->map_token;
 }
 
 static inline int vdpa_reset(struct vdpa_device *vdev, u32 flags)
-- 
2.34.1
Re: [PATCH 7/9] vdpa: rename dma_dev to map_token
Posted by kernel test robot 3 months, 1 week ago
Hi Jason,

kernel test robot noticed the following build errors:

[auto build test ERROR on mst-vhost/linux-next]
[also build test ERROR on linus/master v6.16-rc4 next-20250701]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jason-Wang/virtio_ring-constify-virtqueue-pointer-for-DMA-helpers/20250701-091746
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost.git linux-next
patch link:    https://lore.kernel.org/r/20250701011401.74851-8-jasowang%40redhat.com
patch subject: [PATCH 7/9] vdpa: rename dma_dev to map_token
config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20250702/202507020521.PEt0EuaY-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14+deb12u1) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250702/202507020521.PEt0EuaY-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202507020521.PEt0EuaY-lkp@intel.com/

All error/warnings (new ones prefixed by >>):

   drivers/vdpa/mlx5/net/mlx5_vnet.c: In function 'mlx5_get_vq_dma_dev':
   drivers/vdpa/mlx5/net/mlx5_vnet.c:3405:28: error: 'struct vdpa_device' has no member named 'dma_dev'; did you mean 'mdev'?
    3405 |         return mvdev->vdev.dma_dev;
         |                            ^~~~~~~
         |                            mdev
   drivers/vdpa/mlx5/net/mlx5_vnet.c: At top level:
   drivers/vdpa/mlx5/net/mlx5_vnet.c:3687:10: error: 'const struct vdpa_config_ops' has no member named 'get_vq_dma_dev'; did you mean 'get_vq_ready'?
    3687 |         .get_vq_dma_dev = mlx5_get_vq_dma_dev,
         |          ^~~~~~~~~~~~~~
         |          get_vq_ready
>> drivers/vdpa/mlx5/net/mlx5_vnet.c:3687:27: error: positional initialization of field in 'struct' declared with 'designated_init' attribute [-Werror=designated-init]
    3687 |         .get_vq_dma_dev = mlx5_get_vq_dma_dev,
         |                           ^~~~~~~~~~~~~~~~~~~
   drivers/vdpa/mlx5/net/mlx5_vnet.c:3687:27: note: (near initialization for 'mlx5_vdpa_ops')
   drivers/vdpa/mlx5/net/mlx5_vnet.c:3687:27: error: initialization of 'void (*)(struct vdpa_device *)' from incompatible pointer type 'struct device * (*)(struct vdpa_device *, u16)' {aka 'struct device * (*)(struct vdpa_device *, short unsigned int)'} [-Werror=incompatible-pointer-types]
   drivers/vdpa/mlx5/net/mlx5_vnet.c:3687:27: note: (near initialization for 'mlx5_vdpa_ops.unbind_mm')
   drivers/vdpa/mlx5/net/mlx5_vnet.c: In function 'mlx5_vdpa_dev_add':
   drivers/vdpa/mlx5/net/mlx5_vnet.c:3966:21: error: 'struct vdpa_device' has no member named 'dma_dev'; did you mean 'mdev'?
    3966 |         mvdev->vdev.dma_dev = &mdev->pdev->dev;
         |                     ^~~~~~~
         |                     mdev
   drivers/vdpa/mlx5/net/mlx5_vnet.c: In function 'mlx5_get_vq_dma_dev':
>> drivers/vdpa/mlx5/net/mlx5_vnet.c:3406:1: warning: control reaches end of non-void function [-Wreturn-type]
    3406 | }
         | ^
   cc1: some warnings being treated as errors


vim +3687 drivers/vdpa/mlx5/net/mlx5_vnet.c

8fcd20c307042b Eli Cohen          2022-07-14  3652  
1a86b377aa2147 Eli Cohen          2020-08-04  3653  static const struct vdpa_config_ops mlx5_vdpa_ops = {
1a86b377aa2147 Eli Cohen          2020-08-04  3654  	.set_vq_address = mlx5_vdpa_set_vq_address,
1a86b377aa2147 Eli Cohen          2020-08-04  3655  	.set_vq_num = mlx5_vdpa_set_vq_num,
1a86b377aa2147 Eli Cohen          2020-08-04  3656  	.kick_vq = mlx5_vdpa_kick_vq,
1a86b377aa2147 Eli Cohen          2020-08-04  3657  	.set_vq_cb = mlx5_vdpa_set_vq_cb,
1a86b377aa2147 Eli Cohen          2020-08-04  3658  	.set_vq_ready = mlx5_vdpa_set_vq_ready,
1a86b377aa2147 Eli Cohen          2020-08-04  3659  	.get_vq_ready = mlx5_vdpa_get_vq_ready,
1a86b377aa2147 Eli Cohen          2020-08-04  3660  	.set_vq_state = mlx5_vdpa_set_vq_state,
1a86b377aa2147 Eli Cohen          2020-08-04  3661  	.get_vq_state = mlx5_vdpa_get_vq_state,
1892a3d425bf52 Eli Cohen          2022-05-18  3662  	.get_vendor_vq_stats = mlx5_vdpa_get_vendor_vq_stats,
1a86b377aa2147 Eli Cohen          2020-08-04  3663  	.get_vq_notification = mlx5_get_vq_notification,
1a86b377aa2147 Eli Cohen          2020-08-04  3664  	.get_vq_irq = mlx5_get_vq_irq,
1a86b377aa2147 Eli Cohen          2020-08-04  3665  	.get_vq_align = mlx5_vdpa_get_vq_align,
d4821902e43453 Gautam Dawar       2022-03-30  3666  	.get_vq_group = mlx5_vdpa_get_vq_group,
03dd63c8fae459 Dragos Tatulea     2023-10-18  3667  	.get_vq_desc_group = mlx5_vdpa_get_vq_desc_group, /* Op disabled if not supported. */
a64917bc2e9b1e Eli Cohen          2022-01-05  3668  	.get_device_features = mlx5_vdpa_get_device_features,
c695964474f3a8 Eugenio Pérez      2023-07-03  3669  	.get_backend_features = mlx5_vdpa_get_backend_features,
a64917bc2e9b1e Eli Cohen          2022-01-05  3670  	.set_driver_features = mlx5_vdpa_set_driver_features,
a64917bc2e9b1e Eli Cohen          2022-01-05  3671  	.get_driver_features = mlx5_vdpa_get_driver_features,
1a86b377aa2147 Eli Cohen          2020-08-04  3672  	.set_config_cb = mlx5_vdpa_set_config_cb,
1a86b377aa2147 Eli Cohen          2020-08-04  3673  	.get_vq_num_max = mlx5_vdpa_get_vq_num_max,
1a86b377aa2147 Eli Cohen          2020-08-04  3674  	.get_device_id = mlx5_vdpa_get_device_id,
1a86b377aa2147 Eli Cohen          2020-08-04  3675  	.get_vendor_id = mlx5_vdpa_get_vendor_id,
1a86b377aa2147 Eli Cohen          2020-08-04  3676  	.get_status = mlx5_vdpa_get_status,
1a86b377aa2147 Eli Cohen          2020-08-04  3677  	.set_status = mlx5_vdpa_set_status,
0686082dbf7a20 Xie Yongji         2021-08-31  3678  	.reset = mlx5_vdpa_reset,
2eacf4b5e3ebe7 Si-Wei Liu         2023-10-21  3679  	.compat_reset = mlx5_vdpa_compat_reset,
442706f9f94d28 Stefano Garzarella 2021-03-15  3680  	.get_config_size = mlx5_vdpa_get_config_size,
1a86b377aa2147 Eli Cohen          2020-08-04  3681  	.get_config = mlx5_vdpa_get_config,
1a86b377aa2147 Eli Cohen          2020-08-04  3682  	.set_config = mlx5_vdpa_set_config,
1a86b377aa2147 Eli Cohen          2020-08-04  3683  	.get_generation = mlx5_vdpa_get_generation,
1a86b377aa2147 Eli Cohen          2020-08-04  3684  	.set_map = mlx5_vdpa_set_map,
2eacf4b5e3ebe7 Si-Wei Liu         2023-10-21  3685  	.reset_map = mlx5_vdpa_reset_map,
8fcd20c307042b Eli Cohen          2022-07-14  3686  	.set_group_asid = mlx5_set_group_asid,
36871fb92b7059 Jason Wang         2023-01-19 @3687  	.get_vq_dma_dev = mlx5_get_vq_dma_dev,
1a86b377aa2147 Eli Cohen          2020-08-04  3688  	.free = mlx5_vdpa_free,
cae15c2ed8e6e0 Eli Cohen          2022-07-14  3689  	.suspend = mlx5_vdpa_suspend,
145096937b8a6a Dragos Tatulea     2023-12-25  3690  	.resume = mlx5_vdpa_resume, /* Op disabled if not supported. */
1a86b377aa2147 Eli Cohen          2020-08-04  3691  };
1a86b377aa2147 Eli Cohen          2020-08-04  3692  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki