Skip to content

Commit 0c320f2

Browse files
brettcreeleyAlex Williamson
authored andcommitted
vfio/pds: Move seq/ack bitmaps into region struct
Since the host seq/ack bitmaps are part of a region move them into struct pds_vfio_region. Also, make use of the bmp_bytes value for validation purposes. Signed-off-by: Brett Creeley <brett.creeley@amd.com> Signed-off-by: Shannon Nelson <shannon.nelson@amd.com> Link: https://lore.kernel.org/r/20231117001207.2793-6-brett.creeley@amd.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent 87bdf98 commit 0c320f2

2 files changed

Lines changed: 25 additions & 20 deletions

File tree

drivers/vfio/pci/pds/dirty.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,20 @@ static int pds_vfio_dirty_alloc_bitmaps(struct pds_vfio_dirty *dirty,
8585
return -ENOMEM;
8686
}
8787

88-
dirty->region.host_seq.bmp = host_seq_bmp;
89-
dirty->region.host_ack.bmp = host_ack_bmp;
88+
dirty->region.host_seq = host_seq_bmp;
89+
dirty->region.host_ack = host_ack_bmp;
90+
dirty->region.bmp_bytes = bytes;
9091

9192
return 0;
9293
}
9394

9495
static void pds_vfio_dirty_free_bitmaps(struct pds_vfio_dirty *dirty)
9596
{
96-
vfree(dirty->region.host_seq.bmp);
97-
vfree(dirty->region.host_ack.bmp);
98-
dirty->region.host_seq.bmp = NULL;
99-
dirty->region.host_ack.bmp = NULL;
97+
vfree(dirty->region.host_seq);
98+
vfree(dirty->region.host_ack);
99+
dirty->region.host_seq = NULL;
100+
dirty->region.host_ack = NULL;
101+
dirty->region.bmp_bytes = 0;
100102
}
101103

102104
static void __pds_vfio_dirty_free_sgl(struct pds_vfio_pci_device *pds_vfio,
@@ -301,8 +303,8 @@ void pds_vfio_dirty_disable(struct pds_vfio_pci_device *pds_vfio, bool send_cmd)
301303

302304
static int pds_vfio_dirty_seq_ack(struct pds_vfio_pci_device *pds_vfio,
303305
struct pds_vfio_region *region,
304-
struct pds_vfio_bmp_info *bmp_info,
305-
u32 offset, u32 bmp_bytes, bool read_seq)
306+
unsigned long *seq_ack_bmp, u32 offset,
307+
u32 bmp_bytes, bool read_seq)
306308
{
307309
const char *bmp_type_str = read_seq ? "read_seq" : "write_ack";
308310
u8 dma_dir = read_seq ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
@@ -319,7 +321,7 @@ static int pds_vfio_dirty_seq_ack(struct pds_vfio_pci_device *pds_vfio,
319321
int err;
320322
int i;
321323

322-
bmp = (void *)((u64)bmp_info->bmp + offset);
324+
bmp = (void *)((u64)seq_ack_bmp + offset);
323325
page_offset = offset_in_page(bmp);
324326
bmp -= page_offset;
325327

@@ -387,15 +389,15 @@ static int pds_vfio_dirty_write_ack(struct pds_vfio_pci_device *pds_vfio,
387389
u32 offset, u32 len)
388390
{
389391

390-
return pds_vfio_dirty_seq_ack(pds_vfio, region, &region->host_ack,
392+
return pds_vfio_dirty_seq_ack(pds_vfio, region, region->host_ack,
391393
offset, len, WRITE_ACK);
392394
}
393395

394396
static int pds_vfio_dirty_read_seq(struct pds_vfio_pci_device *pds_vfio,
395397
struct pds_vfio_region *region,
396398
u32 offset, u32 len)
397399
{
398-
return pds_vfio_dirty_seq_ack(pds_vfio, region, &region->host_seq,
400+
return pds_vfio_dirty_seq_ack(pds_vfio, region, region->host_seq,
399401
offset, len, READ_SEQ);
400402
}
401403

@@ -411,8 +413,8 @@ static int pds_vfio_dirty_process_bitmaps(struct pds_vfio_pci_device *pds_vfio,
411413
int dword_count;
412414

413415
dword_count = len_bytes / sizeof(u64);
414-
seq = (__le64 *)((u64)region->host_seq.bmp + bmp_offset);
415-
ack = (__le64 *)((u64)region->host_ack.bmp + bmp_offset);
416+
seq = (__le64 *)((u64)region->host_seq + bmp_offset);
417+
ack = (__le64 *)((u64)region->host_ack + bmp_offset);
416418
bmp_offset_bit = bmp_offset * 8;
417419

418420
for (int i = 0; i < dword_count; i++) {
@@ -479,6 +481,13 @@ static int pds_vfio_dirty_sync(struct pds_vfio_pci_device *pds_vfio,
479481
return -EINVAL;
480482
}
481483

484+
if (bmp_bytes > region->bmp_bytes) {
485+
dev_err(dev,
486+
"Calculated bitmap bytes %llu larger than region's cached bmp_bytes %llu\n",
487+
bmp_bytes, region->bmp_bytes);
488+
return -EINVAL;
489+
}
490+
482491
bmp_offset = DIV_ROUND_UP((iova - region->start) /
483492
region->page_size, sizeof(u64));
484493

drivers/vfio/pci/pds/dirty.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44
#ifndef _DIRTY_H_
55
#define _DIRTY_H_
66

7-
struct pds_vfio_bmp_info {
8-
unsigned long *bmp;
9-
u32 bmp_bytes;
10-
};
11-
127
struct pds_vfio_region {
13-
struct pds_vfio_bmp_info host_seq;
14-
struct pds_vfio_bmp_info host_ack;
8+
unsigned long *host_seq;
9+
unsigned long *host_ack;
10+
u64 bmp_bytes;
1511
u64 size;
1612
u64 start;
1713
u64 page_size;

0 commit comments

Comments
 (0)