Skip to content

Commit bf897d2

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio updates from Michael Tsirkin: "Just fixes and cleanups this time around. The mapping cleanups are preparing the ground for new features, though" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: virtio-vdpa: Drop redundant conversion to bool vduse: Use fixed 4KB bounce pages for non-4KB page size vduse: switch to use virtio map API instead of DMA API vdpa: introduce map ops vdpa: support virtio_map virtio: introduce map ops in virtio core virtio_ring: rename dma_handle to map_handle virtio: introduce virtio_map container union virtio: rename dma helpers virtio_ring: switch to use dma_{map|unmap}_page() virtio_ring: constify virtqueue pointer for DMA helpers virtio_balloon: Remove redundant __GFP_NOWARN vhost: vringh: Fix copy_to_iter return value check vhost: vringh: Modify the return value check
2 parents 55a42f7 + ed9f3ab commit bf897d2

File tree

24 files changed

+632
-332
lines changed

24 files changed

+632
-332
lines changed

drivers/net/virtio_net.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -962,16 +962,16 @@ static void virtnet_rq_unmap(struct receive_queue *rq, void *buf, u32 len)
962962
if (dma->need_sync && len) {
963963
offset = buf - (head + sizeof(*dma));
964964

965-
virtqueue_dma_sync_single_range_for_cpu(rq->vq, dma->addr,
965+
virtqueue_map_sync_single_range_for_cpu(rq->vq, dma->addr,
966966
offset, len,
967967
DMA_FROM_DEVICE);
968968
}
969969

970970
if (dma->ref)
971971
return;
972972

973-
virtqueue_dma_unmap_single_attrs(rq->vq, dma->addr, dma->len,
974-
DMA_FROM_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
973+
virtqueue_unmap_single_attrs(rq->vq, dma->addr, dma->len,
974+
DMA_FROM_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
975975
put_page(page);
976976
}
977977

@@ -1038,13 +1038,13 @@ static void *virtnet_rq_alloc(struct receive_queue *rq, u32 size, gfp_t gfp)
10381038

10391039
dma->len = alloc_frag->size - sizeof(*dma);
10401040

1041-
addr = virtqueue_dma_map_single_attrs(rq->vq, dma + 1,
1042-
dma->len, DMA_FROM_DEVICE, 0);
1043-
if (virtqueue_dma_mapping_error(rq->vq, addr))
1041+
addr = virtqueue_map_single_attrs(rq->vq, dma + 1,
1042+
dma->len, DMA_FROM_DEVICE, 0);
1043+
if (virtqueue_map_mapping_error(rq->vq, addr))
10441044
return NULL;
10451045

10461046
dma->addr = addr;
1047-
dma->need_sync = virtqueue_dma_need_sync(rq->vq, addr);
1047+
dma->need_sync = virtqueue_map_need_sync(rq->vq, addr);
10481048

10491049
/* Add a reference to dma to prevent the entire dma from
10501050
* being released during error handling. This reference
@@ -5942,9 +5942,9 @@ static int virtnet_xsk_pool_enable(struct net_device *dev,
59425942
if (!rq->xsk_buffs)
59435943
return -ENOMEM;
59445944

5945-
hdr_dma = virtqueue_dma_map_single_attrs(sq->vq, &xsk_hdr, vi->hdr_len,
5946-
DMA_TO_DEVICE, 0);
5947-
if (virtqueue_dma_mapping_error(sq->vq, hdr_dma)) {
5945+
hdr_dma = virtqueue_map_single_attrs(sq->vq, &xsk_hdr, vi->hdr_len,
5946+
DMA_TO_DEVICE, 0);
5947+
if (virtqueue_map_mapping_error(sq->vq, hdr_dma)) {
59485948
err = -ENOMEM;
59495949
goto err_free_buffs;
59505950
}
@@ -5973,8 +5973,8 @@ static int virtnet_xsk_pool_enable(struct net_device *dev,
59735973
err_rq:
59745974
xsk_pool_dma_unmap(pool, 0);
59755975
err_xsk_map:
5976-
virtqueue_dma_unmap_single_attrs(rq->vq, hdr_dma, vi->hdr_len,
5977-
DMA_TO_DEVICE, 0);
5976+
virtqueue_unmap_single_attrs(rq->vq, hdr_dma, vi->hdr_len,
5977+
DMA_TO_DEVICE, 0);
59785978
err_free_buffs:
59795979
kvfree(rq->xsk_buffs);
59805980
return err;
@@ -6001,8 +6001,8 @@ static int virtnet_xsk_pool_disable(struct net_device *dev, u16 qid)
60016001

60026002
xsk_pool_dma_unmap(pool, 0);
60036003

6004-
virtqueue_dma_unmap_single_attrs(sq->vq, sq->xsk_hdr_dma_addr,
6005-
vi->hdr_len, DMA_TO_DEVICE, 0);
6004+
virtqueue_unmap_single_attrs(sq->vq, sq->xsk_hdr_dma_addr,
6005+
vi->hdr_len, DMA_TO_DEVICE, 0);
60066006
kvfree(rq->xsk_buffs);
60076007

60086008
return err;

drivers/vdpa/Kconfig

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,7 @@ config VDPA_SIM_BLOCK
3434

3535
config VDPA_USER
3636
tristate "VDUSE (vDPA Device in Userspace) support"
37-
depends on EVENTFD && MMU && HAS_DMA
38-
#
39-
# This driver incorrectly tries to override the dma_ops. It should
40-
# never have done that, but for now keep it working on architectures
41-
# that use dma ops
42-
#
43-
depends on ARCH_HAS_DMA_OPS
37+
depends on EVENTFD && MMU
4438
select VHOST_IOTLB
4539
select IOMMU_IOVA
4640
help

drivers/vdpa/alibaba/eni_vdpa.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,8 @@ static int eni_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id)
478478
return ret;
479479

480480
eni_vdpa = vdpa_alloc_device(struct eni_vdpa, vdpa,
481-
dev, &eni_vdpa_ops, 1, 1, NULL, false);
481+
dev, &eni_vdpa_ops, NULL,
482+
1, 1, NULL, false);
482483
if (IS_ERR(eni_vdpa)) {
483484
ENI_ERR(pdev, "failed to allocate vDPA structure\n");
484485
return PTR_ERR(eni_vdpa);
@@ -496,7 +497,7 @@ static int eni_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id)
496497
pci_set_master(pdev);
497498
pci_set_drvdata(pdev, eni_vdpa);
498499

499-
eni_vdpa->vdpa.dma_dev = &pdev->dev;
500+
eni_vdpa->vdpa.vmap.dma_dev = &pdev->dev;
500501
eni_vdpa->queues = eni_vdpa_get_num_queues(eni_vdpa);
501502

502503
eni_vdpa->vring = devm_kcalloc(&pdev->dev, eni_vdpa->queues,

drivers/vdpa/ifcvf/ifcvf_main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,15 +705,16 @@ static int ifcvf_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
705705
vf = &ifcvf_mgmt_dev->vf;
706706
pdev = vf->pdev;
707707
adapter = vdpa_alloc_device(struct ifcvf_adapter, vdpa,
708-
&pdev->dev, &ifc_vdpa_ops, 1, 1, NULL, false);
708+
&pdev->dev, &ifc_vdpa_ops,
709+
NULL, 1, 1, NULL, false);
709710
if (IS_ERR(adapter)) {
710711
IFCVF_ERR(pdev, "Failed to allocate vDPA structure");
711712
return PTR_ERR(adapter);
712713
}
713714

714715
ifcvf_mgmt_dev->adapter = adapter;
715716
adapter->pdev = pdev;
716-
adapter->vdpa.dma_dev = &pdev->dev;
717+
adapter->vdpa.vmap.dma_dev = &pdev->dev;
717718
adapter->vdpa.mdev = mdev;
718719
adapter->vf = vf;
719720
vdpa_dev = &adapter->vdpa;

drivers/vdpa/mlx5/core/mr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ static int map_direct_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_direct_mr
378378
u64 pa, offset;
379379
u64 paend;
380380
struct scatterlist *sg;
381-
struct device *dma = mvdev->vdev.dma_dev;
381+
struct device *dma = mvdev->vdev.vmap.dma_dev;
382382

383383
for (map = vhost_iotlb_itree_first(iotlb, mr->start, mr->end - 1);
384384
map; map = vhost_iotlb_itree_next(map, mr->start, mr->end - 1)) {
@@ -432,7 +432,7 @@ static int map_direct_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_direct_mr
432432

433433
static void unmap_direct_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_direct_mr *mr)
434434
{
435-
struct device *dma = mvdev->vdev.dma_dev;
435+
struct device *dma = mvdev->vdev.vmap.dma_dev;
436436

437437
destroy_direct_mr(mvdev, mr);
438438
dma_unmap_sg_attrs(dma, mr->sg_head.sgl, mr->nsg, DMA_BIDIRECTIONAL, 0);

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3395,14 +3395,17 @@ static int mlx5_vdpa_reset_map(struct vdpa_device *vdev, unsigned int asid)
33953395
return err;
33963396
}
33973397

3398-
static struct device *mlx5_get_vq_dma_dev(struct vdpa_device *vdev, u16 idx)
3398+
static union virtio_map mlx5_get_vq_map(struct vdpa_device *vdev, u16 idx)
33993399
{
34003400
struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
3401+
union virtio_map map;
34013402

34023403
if (is_ctrl_vq_idx(mvdev, idx))
3403-
return &vdev->dev;
3404+
map.dma_dev = &vdev->dev;
3405+
else
3406+
map.dma_dev = mvdev->vdev.vmap.dma_dev;
34043407

3405-
return mvdev->vdev.dma_dev;
3408+
return map;
34063409
}
34073410

34083411
static void free_irqs(struct mlx5_vdpa_net *ndev)
@@ -3686,7 +3689,7 @@ static const struct vdpa_config_ops mlx5_vdpa_ops = {
36863689
.set_map = mlx5_vdpa_set_map,
36873690
.reset_map = mlx5_vdpa_reset_map,
36883691
.set_group_asid = mlx5_set_group_asid,
3689-
.get_vq_dma_dev = mlx5_get_vq_dma_dev,
3692+
.get_vq_map = mlx5_get_vq_map,
36903693
.free = mlx5_vdpa_free,
36913694
.suspend = mlx5_vdpa_suspend,
36923695
.resume = mlx5_vdpa_resume, /* Op disabled if not supported. */
@@ -3879,7 +3882,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
38793882
}
38803883

38813884
ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device, &mgtdev->vdpa_ops,
3882-
MLX5_VDPA_NUMVQ_GROUPS, MLX5_VDPA_NUM_AS, name, false);
3885+
NULL, MLX5_VDPA_NUMVQ_GROUPS, MLX5_VDPA_NUM_AS, name, false);
38833886
if (IS_ERR(ndev))
38843887
return PTR_ERR(ndev);
38853888

@@ -3965,7 +3968,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
39653968
}
39663969

39673970
ndev->mvdev.mlx_features = device_features;
3968-
mvdev->vdev.dma_dev = &mdev->pdev->dev;
3971+
mvdev->vdev.vmap.dma_dev = &mdev->pdev->dev;
39693972
err = mlx5_vdpa_alloc_resources(&ndev->mvdev);
39703973
if (err)
39713974
goto err_alloc;

drivers/vdpa/octeon_ep/octep_vdpa_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,15 +508,15 @@ static int octep_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
508508
u64 device_features;
509509
int ret;
510510

511-
oct_vdpa = vdpa_alloc_device(struct octep_vdpa, vdpa, &pdev->dev, &octep_vdpa_ops, 1, 1,
512-
NULL, false);
511+
oct_vdpa = vdpa_alloc_device(struct octep_vdpa, vdpa, &pdev->dev, &octep_vdpa_ops,
512+
NULL, 1, 1, NULL, false);
513513
if (IS_ERR(oct_vdpa)) {
514514
dev_err(&pdev->dev, "Failed to allocate vDPA structure for octep vdpa device");
515515
return PTR_ERR(oct_vdpa);
516516
}
517517

518518
oct_vdpa->pdev = pdev;
519-
oct_vdpa->vdpa.dma_dev = &pdev->dev;
519+
oct_vdpa->vdpa.vmap.dma_dev = &pdev->dev;
520520
oct_vdpa->vdpa.mdev = mdev;
521521
oct_vdpa->oct_hw = oct_hw;
522522
vdpa_dev = &oct_vdpa->vdpa;

drivers/vdpa/pds/vdpa_dev.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,8 @@ static int pds_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
632632
}
633633

634634
pdsv = vdpa_alloc_device(struct pds_vdpa_device, vdpa_dev,
635-
dev, &pds_vdpa_ops, 1, 1, name, false);
635+
dev, &pds_vdpa_ops, NULL,
636+
1, 1, name, false);
636637
if (IS_ERR(pdsv)) {
637638
dev_err(dev, "Failed to allocate vDPA structure: %pe\n", pdsv);
638639
return PTR_ERR(pdsv);
@@ -643,7 +644,7 @@ static int pds_vdpa_dev_add(struct vdpa_mgmt_dev *mdev, const char *name,
643644

644645
pdev = vdpa_aux->padev->vf_pdev;
645646
dma_dev = &pdev->dev;
646-
pdsv->vdpa_dev.dma_dev = dma_dev;
647+
pdsv->vdpa_dev.vmap.dma_dev = dma_dev;
647648

648649
status = pds_vdpa_get_status(&pdsv->vdpa_dev);
649650
if (status == 0xff) {

drivers/vdpa/solidrun/snet_main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,8 +1008,8 @@ static int snet_vdpa_probe_vf(struct pci_dev *pdev)
10081008
}
10091009

10101010
/* Allocate vdpa device */
1011-
snet = vdpa_alloc_device(struct snet, vdpa, &pdev->dev, &snet_config_ops, 1, 1, NULL,
1012-
false);
1011+
snet = vdpa_alloc_device(struct snet, vdpa, &pdev->dev, &snet_config_ops,
1012+
NULL, 1, 1, NULL, false);
10131013
if (!snet) {
10141014
SNET_ERR(pdev, "Failed to allocate a vdpa device\n");
10151015
ret = -ENOMEM;
@@ -1052,8 +1052,8 @@ static int snet_vdpa_probe_vf(struct pci_dev *pdev)
10521052
*/
10531053
snet_reserve_irq_idx(pf_irqs ? pdev_pf : pdev, snet);
10541054

1055-
/*set DMA device*/
1056-
snet->vdpa.dma_dev = &pdev->dev;
1055+
/* set map metadata */
1056+
snet->vdpa.vmap.dma_dev = &pdev->dev;
10571057

10581058
/* Register VDPA device */
10591059
ret = vdpa_register_device(&snet->vdpa, snet->cfg->vq_num);

drivers/vdpa/vdpa.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ static void vdpa_release_dev(struct device *d)
142142
* initialized but before registered.
143143
* @parent: the parent device
144144
* @config: the bus operations that is supported by this device
145+
* @map: the map operations that is supported by this device
145146
* @ngroups: number of groups supported by this device
146147
* @nas: number of address spaces supported by this device
147148
* @size: size of the parent structure that contains private data
@@ -151,11 +152,12 @@ static void vdpa_release_dev(struct device *d)
151152
* Driver should use vdpa_alloc_device() wrapper macro instead of
152153
* using this directly.
153154
*
154-
* Return: Returns an error when parent/config/dma_dev is not set or fail to get
155+
* Return: Returns an error when parent/config/map is not set or fail to get
155156
* ida.
156157
*/
157158
struct vdpa_device *__vdpa_alloc_device(struct device *parent,
158159
const struct vdpa_config_ops *config,
160+
const struct virtio_map_ops *map,
159161
unsigned int ngroups, unsigned int nas,
160162
size_t size, const char *name,
161163
bool use_va)
@@ -187,6 +189,7 @@ struct vdpa_device *__vdpa_alloc_device(struct device *parent,
187189
vdev->dev.release = vdpa_release_dev;
188190
vdev->index = err;
189191
vdev->config = config;
192+
vdev->map = map;
190193
vdev->features_valid = false;
191194
vdev->use_va = use_va;
192195
vdev->ngroups = ngroups;

0 commit comments

Comments
 (0)