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.
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
drivers/vdpa/alibaba/eni_vdpa.c | 3 ++-
drivers/vdpa/ifcvf/ifcvf_main.c | 3 ++-
drivers/vdpa/octeon_ep/octep_vdpa_main.c | 4 ++--
drivers/vdpa/pds/vdpa_dev.c | 3 ++-
drivers/vdpa/solidrun/snet_main.c | 4 ++--
drivers/vdpa/vdpa.c | 3 +++
drivers/vdpa/vdpa_sim/vdpa_sim.c | 2 +-
drivers/vdpa/vdpa_user/iova_domain.c | 6 ++++++
drivers/vdpa/vdpa_user/iova_domain.h | 3 +++
drivers/vdpa/vdpa_user/vduse_dev.c | 3 ++-
drivers/vdpa/virtio_pci/vp_vdpa.c | 3 ++-
drivers/vhost/vdpa.c | 9 ++++++++-
drivers/virtio/virtio_vdpa.c | 1 +
include/linux/vdpa.h | 10 +++++++---
14 files changed, 43 insertions(+), 14 deletions(-)
diff --git a/drivers/vdpa/alibaba/eni_vdpa.c b/drivers/vdpa/alibaba/eni_vdpa.c
index 34bf726dc660..4ddf23065087 100644
--- a/drivers/vdpa/alibaba/eni_vdpa.c
+++ b/drivers/vdpa/alibaba/eni_vdpa.c
@@ -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);
diff --git a/drivers/vdpa/ifcvf/ifcvf_main.c b/drivers/vdpa/ifcvf/ifcvf_main.c
index 64d28ec97136..1bc22020d0cc 100644
--- a/drivers/vdpa/ifcvf/ifcvf_main.c
+++ b/drivers/vdpa/ifcvf/ifcvf_main.c
@@ -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);
diff --git a/drivers/vdpa/octeon_ep/octep_vdpa_main.c b/drivers/vdpa/octeon_ep/octep_vdpa_main.c
index 42a4df4613dd..bb4a68b6cce5 100644
--- a/drivers/vdpa/octeon_ep/octep_vdpa_main.c
+++ b/drivers/vdpa/octeon_ep/octep_vdpa_main.c
@@ -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);
diff --git a/drivers/vdpa/pds/vdpa_dev.c b/drivers/vdpa/pds/vdpa_dev.c
index 301d95e08596..d2a017697827 100644
--- a/drivers/vdpa/pds/vdpa_dev.c
+++ b/drivers/vdpa/pds/vdpa_dev.c
@@ -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);
diff --git a/drivers/vdpa/solidrun/snet_main.c b/drivers/vdpa/solidrun/snet_main.c
index 55ec51c17ab3..46f1743eb9f5 100644
--- a/drivers/vdpa/solidrun/snet_main.c
+++ b/drivers/vdpa/solidrun/snet_main.c
@@ -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;
diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c
index 1cc4285ebd67..2715ffcda585 100644
--- a/drivers/vdpa/vdpa.c
+++ b/drivers/vdpa/vdpa.c
@@ -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 opeartions 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;
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index 7c8e468f2f8c..89a795e2a44b 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -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);
diff --git a/drivers/vdpa/vdpa_user/iova_domain.c b/drivers/vdpa/vdpa_user/iova_domain.c
index 58116f89d8da..019f3305c0ac 100644
--- a/drivers/vdpa/vdpa_user/iova_domain.c
+++ b/drivers/vdpa/vdpa_user/iova_domain.c
@@ -506,6 +506,12 @@ void vduse_domain_free_coherent(struct vduse_iova_domain *domain, size_t size,
free_pages_exact(phys_to_virt(pa), size);
}
+bool vduse_domain_need_sync(struct vduse_iova_domain *domain,
+ dma_addr_t dma_addr)
+{
+ return dma_addr < domain->bounce_size;
+}
+
static vm_fault_t vduse_domain_mmap_fault(struct vm_fault *vmf)
{
struct vduse_iova_domain *domain = vmf->vma->vm_private_data;
diff --git a/drivers/vdpa/vdpa_user/iova_domain.h b/drivers/vdpa/vdpa_user/iova_domain.h
index 7f3f0928ec78..846572b95c23 100644
--- a/drivers/vdpa/vdpa_user/iova_domain.h
+++ b/drivers/vdpa/vdpa_user/iova_domain.h
@@ -70,6 +70,9 @@ void vduse_domain_free_coherent(struct vduse_iova_domain *domain, size_t size,
void *vaddr, dma_addr_t dma_addr,
unsigned long attrs);
+bool vduse_domain_need_sync(struct vduse_iova_domain *domain,
+ dma_addr_t dma_addr);
+
void vduse_domain_reset_bounce_map(struct vduse_iova_domain *domain);
int vduse_domain_add_user_bounce_pages(struct vduse_iova_domain *domain,
diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
index 7420e90488ef..64bc39722007 100644
--- a/drivers/vdpa/vdpa_user/vduse_dev.c
+++ b/drivers/vdpa/vdpa_user/vduse_dev.c
@@ -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);
diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c
index 6e22e95245fa..395996ec4608 100644
--- a/drivers/vdpa/virtio_pci/vp_vdpa.c
+++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
@@ -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");
diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index 732ed118c138..4932271899ea 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -1320,13 +1320,20 @@ 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_map_token(vdpa);
+ const struct virtio_map_ops *map = vdpa->map;
+ struct device *dma_dev;
int ret;
/* Device want to do DMA by itself */
if (ops->set_map || ops->dma_map)
return 0;
+ if (map) {
+ dev_warn(&v->dev, "Can't allocate a domian, device use vendor specific mappings\n");
+ return -EINVAL;
+ }
+
+ dma_dev = vdpa_get_map_token(vdpa);
if (!device_iommu_capable(dma_dev, IOMMU_CAP_CACHE_COHERENCY)) {
dev_warn_once(&v->dev,
"Failed to allocate domain, device is not IOMMU cache coherent capable\n");
diff --git a/drivers/virtio/virtio_vdpa.c b/drivers/virtio/virtio_vdpa.c
index cb68458cd809..286b60ce3637 100644
--- a/drivers/virtio/virtio_vdpa.c
+++ b/drivers/virtio/virtio_vdpa.c
@@ -500,6 +500,7 @@ static int virtio_vdpa_probe(struct vdpa_device *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->vdev.map = vdpa->map;
vd_dev->vdpa = vdpa;
INIT_LIST_HEAD(&vd_dev->virtqueues);
spin_lock_init(&vd_dev->lock);
diff --git a/include/linux/vdpa.h b/include/linux/vdpa.h
index 352ca5609c9a..cb51b7e2e569 100644
--- a/include/linux/vdpa.h
+++ b/include/linux/vdpa.h
@@ -75,6 +75,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
@@ -90,6 +91,7 @@ struct vdpa_device {
void *map_token;
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;
@@ -446,6 +448,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);
@@ -457,6 +460,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
@@ -464,10 +468,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)), \
--
2.34.1
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-9-jasowang%40redhat.com patch subject: [PATCH 8/9] vdpa: introduce map ops config: x86_64-randconfig-073-20250702 (https://download.01.org/0day-ci/archive/20250702/202507021212.rhQmuuvi-lkp@intel.com/config) compiler: clang version 20.1.7 (https://github.com/llvm/llvm-project 6146a88f60492b520a36f8f8f3231e15f3cc6082) rustc: rustc 1.78.0 (9b00956e5 2024-04-29) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250702/202507021212.rhQmuuvi-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/202507021212.rhQmuuvi-lkp@intel.com/ All errors (new ones prefixed by >>): drivers/vdpa/mlx5/net/mlx5_vnet.c:3405:21: error: no member named 'dma_dev' in 'struct vdpa_device' 3405 | return mvdev->vdev.dma_dev; | ~~~~~~~~~~~ ^ drivers/vdpa/mlx5/net/mlx5_vnet.c:3687:3: error: field designator 'get_vq_dma_dev' does not refer to any field in type 'const struct vdpa_config_ops' 3687 | .get_vq_dma_dev = mlx5_get_vq_dma_dev, | ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> drivers/vdpa/mlx5/net/mlx5_vnet.c:3880:59: error: too few arguments provided to function-like macro invocation 3880 | MLX5_VDPA_NUMVQ_GROUPS, MLX5_VDPA_NUM_AS, name, false); | ^ include/linux/vdpa.h:471:9: note: macro 'vdpa_alloc_device' defined here 471 | #define vdpa_alloc_device(dev_struct, member, parent, config, map, \ | ^ >> drivers/vdpa/mlx5/net/mlx5_vnet.c:3879:9: error: use of undeclared identifier 'vdpa_alloc_device'; did you mean '__vdpa_alloc_device'? 3879 | ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device, &mgtdev->vdpa_ops, | ^~~~~~~~~~~~~~~~~ | __vdpa_alloc_device include/linux/vdpa.h:449:21: note: '__vdpa_alloc_device' declared here 449 | struct vdpa_device *__vdpa_alloc_device(struct device *parent, | ^ drivers/vdpa/mlx5/net/mlx5_vnet.c:3966:14: error: no member named 'dma_dev' in 'struct vdpa_device' 3966 | mvdev->vdev.dma_dev = &mdev->pdev->dev; | ~~~~~~~~~~~ ^ 5 errors generated. vim +3879 drivers/vdpa/mlx5/net/mlx5_vnet.c bc9a2b3e686e32 Eli Cohen 2023-06-07 3817 d8ca2fa5be1bdb Parav Pandit 2021-10-26 3818 static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, d8ca2fa5be1bdb Parav Pandit 2021-10-26 3819 const struct vdpa_dev_set_config *add_config) 1a86b377aa2147 Eli Cohen 2020-08-04 3820 { 58926c8aab104d Eli Cohen 2021-04-08 3821 struct mlx5_vdpa_mgmtdev *mgtdev = container_of(v_mdev, struct mlx5_vdpa_mgmtdev, mgtdev); 1a86b377aa2147 Eli Cohen 2020-08-04 3822 struct virtio_net_config *config; 7c9f131f366ab4 Eli Cohen 2021-04-22 3823 struct mlx5_core_dev *pfmdev; 1a86b377aa2147 Eli Cohen 2020-08-04 3824 struct mlx5_vdpa_dev *mvdev; 1a86b377aa2147 Eli Cohen 2020-08-04 3825 struct mlx5_vdpa_net *ndev; 58926c8aab104d Eli Cohen 2021-04-08 3826 struct mlx5_core_dev *mdev; deeacf35c922da Si-Wei Liu 2023-02-06 3827 u64 device_features; 1a86b377aa2147 Eli Cohen 2020-08-04 3828 u32 max_vqs; 246fd1caf0f442 Eli Cohen 2021-09-09 3829 u16 mtu; 1a86b377aa2147 Eli Cohen 2020-08-04 3830 int err; 1a86b377aa2147 Eli Cohen 2020-08-04 3831 58926c8aab104d Eli Cohen 2021-04-08 3832 if (mgtdev->ndev) 58926c8aab104d Eli Cohen 2021-04-08 3833 return -ENOSPC; 58926c8aab104d Eli Cohen 2021-04-08 3834 58926c8aab104d Eli Cohen 2021-04-08 3835 mdev = mgtdev->madev->mdev; deeacf35c922da Si-Wei Liu 2023-02-06 3836 device_features = mgtdev->mgtdev.supported_features; deeacf35c922da Si-Wei Liu 2023-02-06 3837 if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) { deeacf35c922da Si-Wei Liu 2023-02-06 3838 if (add_config->device_features & ~device_features) { deeacf35c922da Si-Wei Liu 2023-02-06 3839 dev_warn(mdev->device, deeacf35c922da Si-Wei Liu 2023-02-06 3840 "The provisioned features 0x%llx are not supported by this device with features 0x%llx\n", deeacf35c922da Si-Wei Liu 2023-02-06 3841 add_config->device_features, device_features); deeacf35c922da Si-Wei Liu 2023-02-06 3842 return -EINVAL; deeacf35c922da Si-Wei Liu 2023-02-06 3843 } deeacf35c922da Si-Wei Liu 2023-02-06 3844 device_features &= add_config->device_features; 791a1cb7b8591e Eli Cohen 2023-03-21 3845 } else { 791a1cb7b8591e Eli Cohen 2023-03-21 3846 device_features &= ~BIT_ULL(VIRTIO_NET_F_MRG_RXBUF); deeacf35c922da Si-Wei Liu 2023-02-06 3847 } deeacf35c922da Si-Wei Liu 2023-02-06 3848 if (!(device_features & BIT_ULL(VIRTIO_F_VERSION_1) && deeacf35c922da Si-Wei Liu 2023-02-06 3849 device_features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM))) { deeacf35c922da Si-Wei Liu 2023-02-06 3850 dev_warn(mdev->device, deeacf35c922da Si-Wei Liu 2023-02-06 3851 "Must provision minimum features 0x%llx for this device", deeacf35c922da Si-Wei Liu 2023-02-06 3852 BIT_ULL(VIRTIO_F_VERSION_1) | BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)); deeacf35c922da Si-Wei Liu 2023-02-06 3853 return -EOPNOTSUPP; deeacf35c922da Si-Wei Liu 2023-02-06 3854 } deeacf35c922da Si-Wei Liu 2023-02-06 3855 879753c816dbbd Eli Cohen 2021-08-11 3856 if (!(MLX5_CAP_DEV_VDPA_EMULATION(mdev, virtio_queue_type) & 879753c816dbbd Eli Cohen 2021-08-11 3857 MLX5_VIRTIO_EMULATION_CAP_VIRTIO_QUEUE_TYPE_SPLIT)) { 879753c816dbbd Eli Cohen 2021-08-11 3858 dev_warn(mdev->device, "missing support for split virtqueues\n"); 879753c816dbbd Eli Cohen 2021-08-11 3859 return -EOPNOTSUPP; 879753c816dbbd Eli Cohen 2021-08-11 3860 } 879753c816dbbd Eli Cohen 2021-08-11 3861 acde3929492bcb Eli Cohen 2022-05-16 3862 max_vqs = min_t(int, MLX5_CAP_DEV_VDPA_EMULATION(mdev, max_num_virtio_queues), acde3929492bcb Eli Cohen 2022-05-16 3863 1 << MLX5_CAP_GEN(mdev, log_max_rqt_size)); 75560522eaef2f Eli Cohen 2022-01-05 3864 if (max_vqs < 2) { 75560522eaef2f Eli Cohen 2022-01-05 3865 dev_warn(mdev->device, 75560522eaef2f Eli Cohen 2022-01-05 3866 "%d virtqueues are supported. At least 2 are required\n", 75560522eaef2f Eli Cohen 2022-01-05 3867 max_vqs); 75560522eaef2f Eli Cohen 2022-01-05 3868 return -EAGAIN; 75560522eaef2f Eli Cohen 2022-01-05 3869 } 75560522eaef2f Eli Cohen 2022-01-05 3870 75560522eaef2f Eli Cohen 2022-01-05 3871 if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP)) { 75560522eaef2f Eli Cohen 2022-01-05 3872 if (add_config->net.max_vq_pairs > max_vqs / 2) 75560522eaef2f Eli Cohen 2022-01-05 3873 return -EINVAL; 75560522eaef2f Eli Cohen 2022-01-05 3874 max_vqs = min_t(u32, max_vqs, 2 * add_config->net.max_vq_pairs); 75560522eaef2f Eli Cohen 2022-01-05 3875 } else { 75560522eaef2f Eli Cohen 2022-01-05 3876 max_vqs = 2; 75560522eaef2f Eli Cohen 2022-01-05 3877 } 1a86b377aa2147 Eli Cohen 2020-08-04 3878 03dd63c8fae459 Dragos Tatulea 2023-10-18 @3879 ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device, &mgtdev->vdpa_ops, 8fcd20c307042b Eli Cohen 2022-07-14 @3880 MLX5_VDPA_NUMVQ_GROUPS, MLX5_VDPA_NUM_AS, name, false); 1a86b377aa2147 Eli Cohen 2020-08-04 3881 if (IS_ERR(ndev)) 74c9729dd892a1 Leon Romanovsky 2020-10-04 3882 return PTR_ERR(ndev); 1a86b377aa2147 Eli Cohen 2020-08-04 3883 1a86b377aa2147 Eli Cohen 2020-08-04 3884 ndev->mvdev.max_vqs = max_vqs; 1a86b377aa2147 Eli Cohen 2020-08-04 3885 mvdev = &ndev->mvdev; 1a86b377aa2147 Eli Cohen 2020-08-04 3886 mvdev->mdev = mdev; 439252e167ac45 Konstantin Shkolnyy 2025-02-04 3887 /* cpu_to_mlx5vdpa16() below depends on this flag */ 439252e167ac45 Konstantin Shkolnyy 2025-02-04 3888 mvdev->actual_features = 439252e167ac45 Konstantin Shkolnyy 2025-02-04 3889 (device_features & BIT_ULL(VIRTIO_F_VERSION_1)); 75560522eaef2f Eli Cohen 2022-01-05 3890 75560522eaef2f Eli Cohen 2022-01-05 3891 ndev->vqs = kcalloc(max_vqs, sizeof(*ndev->vqs), GFP_KERNEL); 75560522eaef2f Eli Cohen 2022-01-05 3892 ndev->event_cbs = kcalloc(max_vqs + 1, sizeof(*ndev->event_cbs), GFP_KERNEL); 75560522eaef2f Eli Cohen 2022-01-05 3893 if (!ndev->vqs || !ndev->event_cbs) { 75560522eaef2f Eli Cohen 2022-01-05 3894 err = -ENOMEM; 75560522eaef2f Eli Cohen 2022-01-05 3895 goto err_alloc; 75560522eaef2f Eli Cohen 2022-01-05 3896 } 1835ed4a5d49d2 Dragos Tatulea 2024-06-26 3897 ndev->cur_num_vqs = MLX5V_DEFAULT_VQ_COUNT; 75560522eaef2f Eli Cohen 2022-01-05 3898 4a19f2942a0fe5 Dragos Tatulea 2024-06-26 3899 mvqs_set_defaults(ndev); bc9a2b3e686e32 Eli Cohen 2023-06-07 3900 allocate_irqs(ndev); 759ae7f9bf1e6b Eli Cohen 2022-05-18 3901 init_rwsem(&ndev->reslock); 1a86b377aa2147 Eli Cohen 2020-08-04 3902 config = &ndev->config; 1e00e821e4ca63 Eli Cohen 2022-02-21 3903 1e00e821e4ca63 Eli Cohen 2022-02-21 3904 if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU)) { 1e00e821e4ca63 Eli Cohen 2022-02-21 3905 err = config_func_mtu(mdev, add_config->net.mtu); 1e00e821e4ca63 Eli Cohen 2022-02-21 3906 if (err) 759ae7f9bf1e6b Eli Cohen 2022-05-18 3907 goto err_alloc; 1e00e821e4ca63 Eli Cohen 2022-02-21 3908 } 1e00e821e4ca63 Eli Cohen 2022-02-21 3909 deeacf35c922da Si-Wei Liu 2023-02-06 3910 if (device_features & BIT_ULL(VIRTIO_NET_F_MTU)) { 246fd1caf0f442 Eli Cohen 2021-09-09 3911 err = query_mtu(mdev, &mtu); 1a86b377aa2147 Eli Cohen 2020-08-04 3912 if (err) 759ae7f9bf1e6b Eli Cohen 2022-05-18 3913 goto err_alloc; 1a86b377aa2147 Eli Cohen 2020-08-04 3914 246fd1caf0f442 Eli Cohen 2021-09-09 3915 ndev->config.mtu = cpu_to_mlx5vdpa16(mvdev, mtu); 033779a708f0b0 Si-Wei Liu 2023-02-06 3916 } 1a86b377aa2147 Eli Cohen 2020-08-04 3917 deeacf35c922da Si-Wei Liu 2023-02-06 3918 if (device_features & BIT_ULL(VIRTIO_NET_F_STATUS)) { edf747affc41a1 Eli Cohen 2021-09-09 3919 if (get_link_state(mvdev)) edf747affc41a1 Eli Cohen 2021-09-09 3920 ndev->config.status |= cpu_to_mlx5vdpa16(mvdev, VIRTIO_NET_S_LINK_UP); edf747affc41a1 Eli Cohen 2021-09-09 3921 else edf747affc41a1 Eli Cohen 2021-09-09 3922 ndev->config.status &= cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP); 033779a708f0b0 Si-Wei Liu 2023-02-06 3923 } edf747affc41a1 Eli Cohen 2021-09-09 3924 a007d940040c0b Eli Cohen 2021-10-26 3925 if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) { a007d940040c0b Eli Cohen 2021-10-26 3926 memcpy(ndev->config.mac, add_config->net.mac, ETH_ALEN); deeacf35c922da Si-Wei Liu 2023-02-06 3927 /* No bother setting mac address in config if not going to provision _F_MAC */ deeacf35c922da Si-Wei Liu 2023-02-06 3928 } else if ((add_config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) == 0 || deeacf35c922da Si-Wei Liu 2023-02-06 3929 device_features & BIT_ULL(VIRTIO_NET_F_MAC)) { 1a86b377aa2147 Eli Cohen 2020-08-04 3930 err = mlx5_query_nic_vport_mac_address(mdev, 0, 0, config->mac); 1a86b377aa2147 Eli Cohen 2020-08-04 3931 if (err) 759ae7f9bf1e6b Eli Cohen 2022-05-18 3932 goto err_alloc; a007d940040c0b Eli Cohen 2021-10-26 3933 } 1a86b377aa2147 Eli Cohen 2020-08-04 3934 7c9f131f366ab4 Eli Cohen 2021-04-22 3935 if (!is_zero_ether_addr(config->mac)) { 7c9f131f366ab4 Eli Cohen 2021-04-22 3936 pfmdev = pci_get_drvdata(pci_physfn(mdev->pdev)); 7c9f131f366ab4 Eli Cohen 2021-04-22 3937 err = mlx5_mpfs_add_mac(pfmdev, config->mac); 7c9f131f366ab4 Eli Cohen 2021-04-22 3938 if (err) 759ae7f9bf1e6b Eli Cohen 2022-05-18 3939 goto err_alloc; deeacf35c922da Si-Wei Liu 2023-02-06 3940 } else if ((add_config->mask & BIT_ULL(VDPA_ATTR_DEV_FEATURES)) == 0) { deeacf35c922da Si-Wei Liu 2023-02-06 3941 /* deeacf35c922da Si-Wei Liu 2023-02-06 3942 * We used to clear _F_MAC feature bit if seeing deeacf35c922da Si-Wei Liu 2023-02-06 3943 * zero mac address when device features are not deeacf35c922da Si-Wei Liu 2023-02-06 3944 * specifically provisioned. Keep the behaviour deeacf35c922da Si-Wei Liu 2023-02-06 3945 * so old scripts do not break. deeacf35c922da Si-Wei Liu 2023-02-06 3946 */ deeacf35c922da Si-Wei Liu 2023-02-06 3947 device_features &= ~BIT_ULL(VIRTIO_NET_F_MAC); deeacf35c922da Si-Wei Liu 2023-02-06 3948 } else if (device_features & BIT_ULL(VIRTIO_NET_F_MAC)) { deeacf35c922da Si-Wei Liu 2023-02-06 3949 /* Don't provision zero mac address for _F_MAC */ deeacf35c922da Si-Wei Liu 2023-02-06 3950 mlx5_vdpa_warn(&ndev->mvdev, deeacf35c922da Si-Wei Liu 2023-02-06 3951 "No mac address provisioned?\n"); deeacf35c922da Si-Wei Liu 2023-02-06 3952 err = -EINVAL; deeacf35c922da Si-Wei Liu 2023-02-06 3953 goto err_alloc; 7c9f131f366ab4 Eli Cohen 2021-04-22 3954 } 7c9f131f366ab4 Eli Cohen 2021-04-22 3955 1e8dac7bb6ca9c Dragos Tatulea 2024-06-26 3956 if (device_features & BIT_ULL(VIRTIO_NET_F_MQ)) { acde3929492bcb Eli Cohen 2022-05-16 3957 config->max_virtqueue_pairs = cpu_to_mlx5vdpa16(mvdev, max_vqs / 2); 1e8dac7bb6ca9c Dragos Tatulea 2024-06-26 3958 ndev->rqt_size = max_vqs / 2; 1e8dac7bb6ca9c Dragos Tatulea 2024-06-26 3959 } else { 1e8dac7bb6ca9c Dragos Tatulea 2024-06-26 3960 ndev->rqt_size = 1; 1e8dac7bb6ca9c Dragos Tatulea 2024-06-26 3961 } deeacf35c922da Si-Wei Liu 2023-02-06 3962 1fcdf43ea69e97 Dragos Tatulea 2024-08-16 3963 mlx5_cmd_init_async_ctx(mdev, &mvdev->async_ctx); 1fcdf43ea69e97 Dragos Tatulea 2024-08-16 3964 deeacf35c922da Si-Wei Liu 2023-02-06 3965 ndev->mvdev.mlx_features = device_features; 7d23dcdf213c2e Eli Cohen 2021-06-06 3966 mvdev->vdev.dma_dev = &mdev->pdev->dev; 1a86b377aa2147 Eli Cohen 2020-08-04 3967 err = mlx5_vdpa_alloc_resources(&ndev->mvdev); 1a86b377aa2147 Eli Cohen 2020-08-04 3968 if (err) 83e445e64f48bd Dragos Tatulea 2024-11-05 3969 goto err_alloc; 1a86b377aa2147 Eli Cohen 2020-08-04 3970 f30a1232b6979c Dragos Tatulea 2024-08-30 3971 err = mlx5_vdpa_init_mr_resources(mvdev); f30a1232b6979c Dragos Tatulea 2024-08-30 3972 if (err) 83e445e64f48bd Dragos Tatulea 2024-11-05 3973 goto err_alloc; f16d65124380ac Dragos Tatulea 2023-12-25 3974 6f5312f801836e Eli Cohen 2021-06-02 3975 if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) { 049cbeab861ef4 Dragos Tatulea 2023-10-18 3976 err = mlx5_vdpa_create_dma_mr(mvdev); 1a86b377aa2147 Eli Cohen 2020-08-04 3977 if (err) 83e445e64f48bd Dragos Tatulea 2024-11-05 3978 goto err_alloc; 6f5312f801836e Eli Cohen 2021-06-02 3979 } 6f5312f801836e Eli Cohen 2021-06-02 3980 1f5d6476f12152 Dragos Tatulea 2024-06-26 3981 err = alloc_fixed_resources(ndev); 6f5312f801836e Eli Cohen 2021-06-02 3982 if (err) 83e445e64f48bd Dragos Tatulea 2024-11-05 3983 goto err_alloc; 1a86b377aa2147 Eli Cohen 2020-08-04 3984 55ebf0d60e3cc6 Jason Wang 2022-03-29 3985 ndev->cvq_ent.mvdev = mvdev; 55ebf0d60e3cc6 Jason Wang 2022-03-29 3986 INIT_WORK(&ndev->cvq_ent.work, mlx5_cvq_kick_handler); 218bdd20e56cab Eli Cohen 2021-09-09 3987 mvdev->wq = create_singlethread_workqueue("mlx5_vdpa_wq"); 5262912ef3cfc5 Eli Cohen 2021-08-23 3988 if (!mvdev->wq) { 5262912ef3cfc5 Eli Cohen 2021-08-23 3989 err = -ENOMEM; 83e445e64f48bd Dragos Tatulea 2024-11-05 3990 goto err_alloc; 5262912ef3cfc5 Eli Cohen 2021-08-23 3991 } 5262912ef3cfc5 Eli Cohen 2021-08-23 3992 58926c8aab104d Eli Cohen 2021-04-08 3993 mvdev->vdev.mdev = &mgtdev->mgtdev; acde3929492bcb Eli Cohen 2022-05-16 3994 err = _vdpa_register_device(&mvdev->vdev, max_vqs + 1); 1a86b377aa2147 Eli Cohen 2020-08-04 3995 if (err) 1a86b377aa2147 Eli Cohen 2020-08-04 3996 goto err_reg; 1a86b377aa2147 Eli Cohen 2020-08-04 3997 58926c8aab104d Eli Cohen 2021-04-08 3998 mgtdev->ndev = ndev; ffb1aae43ed507 Dragos Tatulea 2024-06-26 3999 ffb1aae43ed507 Dragos Tatulea 2024-06-26 4000 /* For virtio-vdpa, the device was set up during device register. */ ffb1aae43ed507 Dragos Tatulea 2024-06-26 4001 if (ndev->setup) ffb1aae43ed507 Dragos Tatulea 2024-06-26 4002 return 0; ffb1aae43ed507 Dragos Tatulea 2024-06-26 4003 ffb1aae43ed507 Dragos Tatulea 2024-06-26 4004 down_write(&ndev->reslock); ffb1aae43ed507 Dragos Tatulea 2024-06-26 4005 err = setup_vq_resources(ndev, false); ffb1aae43ed507 Dragos Tatulea 2024-06-26 4006 up_write(&ndev->reslock); ffb1aae43ed507 Dragos Tatulea 2024-06-26 4007 if (err) ffb1aae43ed507 Dragos Tatulea 2024-06-26 4008 goto err_setup_vq_res; ffb1aae43ed507 Dragos Tatulea 2024-06-26 4009 74c9729dd892a1 Leon Romanovsky 2020-10-04 4010 return 0; 1a86b377aa2147 Eli Cohen 2020-08-04 4011 ffb1aae43ed507 Dragos Tatulea 2024-06-26 4012 err_setup_vq_res: ffb1aae43ed507 Dragos Tatulea 2024-06-26 4013 _vdpa_unregister_device(&mvdev->vdev); 1a86b377aa2147 Eli Cohen 2020-08-04 4014 err_reg: 5262912ef3cfc5 Eli Cohen 2021-08-23 4015 destroy_workqueue(mvdev->wq); 75560522eaef2f Eli Cohen 2022-01-05 4016 err_alloc: 1a86b377aa2147 Eli Cohen 2020-08-04 4017 put_device(&mvdev->vdev.dev); 74c9729dd892a1 Leon Romanovsky 2020-10-04 4018 return err; 1a86b377aa2147 Eli Cohen 2020-08-04 4019 } 1a86b377aa2147 Eli Cohen 2020-08-04 4020 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
On Wed, Jul 2, 2025 at 1:21 PM kernel test robot <lkp@intel.com> wrote: > > 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-9-jasowang%40redhat.com > patch subject: [PATCH 8/9] vdpa: introduce map ops > config: x86_64-randconfig-073-20250702 (https://download.01.org/0day-ci/archive/20250702/202507021212.rhQmuuvi-lkp@intel.com/config) > compiler: clang version 20.1.7 (https://github.com/llvm/llvm-project 6146a88f60492b520a36f8f8f3231e15f3cc6082) > rustc: rustc 1.78.0 (9b00956e5 2024-04-29) > reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250702/202507021212.rhQmuuvi-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/202507021212.rhQmuuvi-lkp@intel.com/ > > All errors (new ones prefixed by >>): > > drivers/vdpa/mlx5/net/mlx5_vnet.c:3405:21: error: no member named 'dma_dev' in 'struct vdpa_device' > 3405 | return mvdev->vdev.dma_dev; > | ~~~~~~~~~~~ ^ It seems I forgot to convert mlx5 divers. Will do that in the next version (if we agree this is the right direction). Thanks
© 2016 - 2025 Red Hat, Inc.