Skip to content

Commit 06fddc7

Browse files
committed
Merge tag 'common_phys_vec_via_vfio' into HEAD
* Reuse common phys_vec, phase out dma_buf_phys_vec Signed-off-by: Alex Williamson <alex@shazbot.org> * tag 'common_phys_vec_via_vfio': types: reuse common phys_vec type instead of DMABUF open‑coded variant types: move phys_vec definition to common header nvme-pci: Use size_t for length fields to handle larger sizes
2 parents 14ab3da + b703b31 commit 06fddc7

13 files changed

Lines changed: 33 additions & 41 deletions

File tree

block/blk-mq-dma.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
#include <linux/blk-mq-dma.h>
77
#include "blk.h"
88

9-
struct phys_vec {
10-
phys_addr_t paddr;
11-
u32 len;
12-
};
13-
149
static bool __blk_map_iter_next(struct blk_map_iter *iter)
1510
{
1611
if (iter->iter.bi_size)
@@ -112,8 +107,8 @@ static bool blk_rq_dma_map_iova(struct request *req, struct device *dma_dev,
112107
struct phys_vec *vec)
113108
{
114109
enum dma_data_direction dir = rq_dma_dir(req);
115-
unsigned int mapped = 0;
116110
unsigned int attrs = 0;
111+
size_t mapped = 0;
117112
int error;
118113

119114
iter->addr = state->addr;
@@ -297,6 +292,8 @@ int __blk_rq_map_sg(struct request *rq, struct scatterlist *sglist,
297292
blk_rq_map_iter_init(rq, &iter);
298293
while (blk_map_iter_next(rq, &iter, &vec)) {
299294
*last_sg = blk_next_sg(last_sg, sglist);
295+
296+
WARN_ON_ONCE(overflows_type(vec.len, unsigned int));
300297
sg_set_page(*last_sg, phys_to_page(vec.paddr), vec.len,
301298
offset_in_page(vec.paddr));
302299
nsegs++;
@@ -417,6 +414,8 @@ int blk_rq_map_integrity_sg(struct request *rq, struct scatterlist *sglist)
417414

418415
while (blk_map_iter_next(rq, &iter, &vec)) {
419416
sg = blk_next_sg(&sg, sglist);
417+
418+
WARN_ON_ONCE(overflows_type(vec.len, unsigned int));
420419
sg_set_page(sg, phys_to_page(vec.paddr), vec.len,
421420
offset_in_page(vec.paddr));
422421
segments++;

drivers/dma-buf/dma-buf-mapping.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ static struct scatterlist *fill_sg_entry(struct scatterlist *sgl, size_t length,
3333
}
3434

3535
static unsigned int calc_sg_nents(struct dma_iova_state *state,
36-
struct dma_buf_phys_vec *phys_vec,
37-
size_t nr_ranges, size_t size)
36+
struct phys_vec *phys_vec, size_t nr_ranges,
37+
size_t size)
3838
{
3939
unsigned int nents = 0;
4040
size_t i;
@@ -91,7 +91,7 @@ struct dma_buf_dma {
9191
*/
9292
struct sg_table *dma_buf_phys_vec_to_sgt(struct dma_buf_attachment *attach,
9393
struct p2pdma_provider *provider,
94-
struct dma_buf_phys_vec *phys_vec,
94+
struct phys_vec *phys_vec,
9595
size_t nr_ranges, size_t size,
9696
enum dma_data_direction dir)
9797
{

drivers/iommu/iommufd/io_pagetable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ struct iopt_pages_dmabuf_track {
202202

203203
struct iopt_pages_dmabuf {
204204
struct dma_buf_attachment *attach;
205-
struct dma_buf_phys_vec phys;
205+
struct phys_vec phys;
206206
/* Always PAGE_SIZE aligned */
207207
unsigned long start;
208208
struct list_head tracker;

drivers/iommu/iommufd/iommufd_private.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ struct iommu_group;
2020
struct iommu_option;
2121
struct iommufd_device;
2222
struct dma_buf_attachment;
23-
struct dma_buf_phys_vec;
2423

2524
struct iommufd_sw_msi_map {
2625
struct list_head sw_msi_item;
@@ -718,7 +717,7 @@ int __init iommufd_test_init(void);
718717
void iommufd_test_exit(void);
719718
bool iommufd_selftest_is_mock_dev(struct device *dev);
720719
int iommufd_test_dma_buf_iommufd_map(struct dma_buf_attachment *attachment,
721-
struct dma_buf_phys_vec *phys);
720+
struct phys_vec *phys);
722721
#else
723722
static inline void iommufd_test_syz_conv_iova_id(struct iommufd_ucmd *ucmd,
724723
unsigned int ioas_id,
@@ -742,7 +741,7 @@ static inline bool iommufd_selftest_is_mock_dev(struct device *dev)
742741
}
743742
static inline int
744743
iommufd_test_dma_buf_iommufd_map(struct dma_buf_attachment *attachment,
745-
struct dma_buf_phys_vec *phys)
744+
struct phys_vec *phys)
746745
{
747746
return -EOPNOTSUPP;
748747
}

drivers/iommu/iommufd/pages.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ static int pfn_reader_user_update_pinned(struct pfn_reader_user *user,
10771077
}
10781078

10791079
struct pfn_reader_dmabuf {
1080-
struct dma_buf_phys_vec phys;
1080+
struct phys_vec phys;
10811081
unsigned long start_offset;
10821082
};
10831083

@@ -1460,7 +1460,7 @@ static struct dma_buf_attach_ops iopt_dmabuf_attach_revoke_ops = {
14601460
*/
14611461
static int
14621462
sym_vfio_pci_dma_buf_iommufd_map(struct dma_buf_attachment *attachment,
1463-
struct dma_buf_phys_vec *phys)
1463+
struct phys_vec *phys)
14641464
{
14651465
typeof(&vfio_pci_dma_buf_iommufd_map) fn;
14661466
int rc;

drivers/iommu/iommufd/selftest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,7 @@ static const struct dma_buf_ops iommufd_test_dmabuf_ops = {
20022002
};
20032003

20042004
int iommufd_test_dma_buf_iommufd_map(struct dma_buf_attachment *attachment,
2005-
struct dma_buf_phys_vec *phys)
2005+
struct phys_vec *phys)
20062006
{
20072007
struct iommufd_test_dma_buf *priv = attachment->dmabuf->priv;
20082008

drivers/nvme/host/pci.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,14 @@ struct nvme_iod {
290290
u8 flags;
291291
u8 nr_descriptors;
292292

293-
unsigned int total_len;
293+
size_t total_len;
294294
struct dma_iova_state dma_state;
295295
void *descriptors[NVME_MAX_NR_DESCRIPTORS];
296296
struct nvme_dma_vec *dma_vecs;
297297
unsigned int nr_dma_vecs;
298298

299299
dma_addr_t meta_dma;
300-
unsigned int meta_total_len;
300+
size_t meta_total_len;
301301
struct dma_iova_state meta_dma_state;
302302
struct nvme_sgl_desc *meta_descriptor;
303303
};

drivers/vfio/pci/nvgrace-gpu/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ nvgrace_gpu_write(struct vfio_device *core_vdev,
784784
static int nvgrace_get_dmabuf_phys(struct vfio_pci_core_device *core_vdev,
785785
struct p2pdma_provider **provider,
786786
unsigned int region_index,
787-
struct dma_buf_phys_vec *phys_vec,
787+
struct phys_vec *phys_vec,
788788
struct vfio_region_dma_range *dma_ranges,
789789
size_t nr_ranges)
790790
{

drivers/vfio/pci/vfio_pci_dmabuf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct vfio_pci_dma_buf {
1414
struct vfio_pci_core_device *vdev;
1515
struct list_head dmabufs_elm;
1616
size_t size;
17-
struct dma_buf_phys_vec *phys_vec;
17+
struct phys_vec *phys_vec;
1818
struct p2pdma_provider *provider;
1919
u32 nr_ranges;
2020
u8 revoked : 1;
@@ -94,7 +94,7 @@ static const struct dma_buf_ops vfio_pci_dmabuf_ops = {
9494
* will fail if it is currently revoked
9595
*/
9696
int vfio_pci_dma_buf_iommufd_map(struct dma_buf_attachment *attachment,
97-
struct dma_buf_phys_vec *phys)
97+
struct phys_vec *phys)
9898
{
9999
struct vfio_pci_dma_buf *priv;
100100

@@ -116,7 +116,7 @@ int vfio_pci_dma_buf_iommufd_map(struct dma_buf_attachment *attachment,
116116
}
117117
EXPORT_SYMBOL_FOR_MODULES(vfio_pci_dma_buf_iommufd_map, "iommufd");
118118

119-
int vfio_pci_core_fill_phys_vec(struct dma_buf_phys_vec *phys_vec,
119+
int vfio_pci_core_fill_phys_vec(struct phys_vec *phys_vec,
120120
struct vfio_region_dma_range *dma_ranges,
121121
size_t nr_ranges, phys_addr_t start,
122122
phys_addr_t len)
@@ -148,7 +148,7 @@ EXPORT_SYMBOL_GPL(vfio_pci_core_fill_phys_vec);
148148
int vfio_pci_core_get_dmabuf_phys(struct vfio_pci_core_device *vdev,
149149
struct p2pdma_provider **provider,
150150
unsigned int region_index,
151-
struct dma_buf_phys_vec *phys_vec,
151+
struct phys_vec *phys_vec,
152152
struct vfio_region_dma_range *dma_ranges,
153153
size_t nr_ranges)
154154
{

include/linux/dma-buf-mapping.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
struct sg_table *dma_buf_phys_vec_to_sgt(struct dma_buf_attachment *attach,
1111
struct p2pdma_provider *provider,
12-
struct dma_buf_phys_vec *phys_vec,
12+
struct phys_vec *phys_vec,
1313
size_t nr_ranges, size_t size,
1414
enum dma_data_direction dir);
1515
void dma_buf_free_sgt(struct dma_buf_attachment *attach, struct sg_table *sgt,

0 commit comments

Comments
 (0)