Re: [PATCH v11 1/3] selftests/vfio: Add memcpy chunking and PCI command helpers

David Matlack
2026-04-03T22:42:38Z

On 2026-03-31 10:22 AM, Rubin Du wrote:

> --- a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h
> +++ b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h
> @@ -122,4 +122,14 @@ static inline bool vfio_pci_device_match(struct vfio_pci_device *device,
>
> const char *vfio_pci_get_cdev_path(const char *bdf);
>
> +#define vfio_pci_cmd_set(_device, _bits) do { \
> + u16 __cmd = vfio_pci_config_readw((_device), PCI_COMMAND); \
> + vfio_pci_config_writew((_device), PCI_COMMAND, __cmd | (_bits));\
> +} while (0)
> +
> +#define vfio_pci_cmd_clear(_device, _bits) do { \
> + u16 __cmd = vfio_pci_config_readw((_device), PCI_COMMAND); \
> + vfio_pci_config_writew((_device), PCI_COMMAND, __cmd & ~(_bits));\
> +} while (0)

Please add these in their own commit, and also put them up next to the
other vfio_pci_config_*() routines.

> @@ -221,13 +221,15 @@ TEST_F_TIMEOUT(vfio_pci_driver_test, memcpy_storm, 60)
> * will take too long.
> */
> total_size = 250UL * SZ_1G;
> - count = min(total_size / self->size, driver->max_memcpy_count);
> + count = min(total_size / driver->max_memcpy_size,
> + driver->max_memcpy_count);
>
> - printf("Kicking off %lu memcpys of size 0x%lx\n", count, self->size);
> + printf("Kicking off %lu memcpys of size 0x%lx\n", count,
> + driver->max_memcpy_size);
> vfio_pci_driver_memcpy_start(self->device,
> self->src_iova,
> self->dst_iova,
> - self->size, count);
> + driver->max_memcpy_size, count);

The memcpy size needs to capped at self->memcpy_region.size / 2 (here
and in the calculation above for count).