lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <f0439348-dca7-4f1b-9d96-b5a596c9407d@linux.dev>
Date: Sat, 27 Dec 2025 20:03:44 -0800
From: Zhu Yanjun <yanjun.zhu@...ux.dev>
To: David Matlack <dmatlack@...gle.com>, Alex Williamson <alex@...zbot.org>
Cc: Adithya Jayachandran <ajayachandra@...dia.com>,
 Alex Mastro <amastro@...com>, Alistair Popple <apopple@...dia.com>,
 Andrew Morton <akpm@...ux-foundation.org>,
 Bjorn Helgaas <bhelgaas@...gle.com>, Chris Li <chrisl@...nel.org>,
 David Rientjes <rientjes@...gle.com>,
 Jacob Pan <jacob.pan@...ux.microsoft.com>, Jason Gunthorpe <jgg@...dia.com>,
 Jason Gunthorpe <jgg@...pe.ca>, Josh Hilke <jrhilke@...gle.com>,
 Kevin Tian <kevin.tian@...el.com>, kvm@...r.kernel.org,
 Leon Romanovsky <leonro@...dia.com>, linux-kernel@...r.kernel.org,
 linux-kselftest@...r.kernel.org, linux-pci@...r.kernel.org,
 Lukas Wunner <lukas@...ner.de>, Mike Rapoport <rppt@...nel.org>,
 Parav Pandit <parav@...dia.com>, Pasha Tatashin <pasha.tatashin@...een.com>,
 Philipp Stanner <pstanner@...hat.com>, Pratyush Yadav <pratyush@...nel.org>,
 Saeed Mahameed <saeedm@...dia.com>, Samiullah Khawaja <skhawaja@...gle.com>,
 Shuah Khan <shuah@...nel.org>, Tomita Moeko <tomitamoeko@...il.com>,
 Vipin Sharma <vipinsh@...gle.com>, William Tu <witu@...dia.com>,
 Yi Liu <yi.l.liu@...el.com>, Yunxiang Li <Yunxiang.Li@....com>
Subject: Re: [PATCH 19/21] vfio: selftests: Expose low-level helper routines
 for setting up struct vfio_pci_device


在 2025/11/26 11:36, David Matlack 写道:
> Expose a few low-level helper routings for setting up vfio_pci_device
> structs. These routines will be used in a subsequent commit to assert
> that VFIO_GROUP_GET_DEVICE_FD fails under certain conditions.
>
> Signed-off-by: David Matlack <dmatlack@...gle.com>
> ---
>   .../lib/include/libvfio/vfio_pci_device.h     |  5 +++
>   .../selftests/vfio/lib/vfio_pci_device.c      | 33 +++++++++++++------
>   2 files changed, 28 insertions(+), 10 deletions(-)
>
> diff --git a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h
> index 896dfde88118..2389c7698335 100644
> --- a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h
> +++ b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h
> @@ -125,4 +125,9 @@ static inline bool vfio_pci_device_match(struct vfio_pci_device *device,
>   
>   const char *vfio_pci_get_cdev_path(const char *bdf);
>   
> +/* Low-level routines for setting up a struct vfio_pci_device */
> +struct vfio_pci_device *vfio_pci_device_alloc(const char *bdf, struct iommu *iommu);
> +void vfio_pci_group_setup(struct vfio_pci_device *device);
> +void vfio_pci_iommu_setup(struct vfio_pci_device *device);
> +
>   #endif /* SELFTESTS_VFIO_LIB_INCLUDE_LIBVFIO_VFIO_PCI_DEVICE_H */
> diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> index e9423dc3864a..c1a3886dee30 100644
> --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> @@ -199,7 +199,7 @@ static unsigned int vfio_pci_get_group_from_dev(const char *bdf)
>   	return group;
>   }
>   
> -static void vfio_pci_group_setup(struct vfio_pci_device *device, const char *bdf)
> +void vfio_pci_group_setup(struct vfio_pci_device *device)
>   {
>   	struct vfio_group_status group_status = {
>   		.argsz = sizeof(group_status),
> @@ -207,7 +207,7 @@ static void vfio_pci_group_setup(struct vfio_pci_device *device, const char *bdf
>   	char group_path[32];
>   	int group;
>   
> -	group = vfio_pci_get_group_from_dev(bdf);
> +	group = vfio_pci_get_group_from_dev(device->bdf);
>   	snprintf(group_path, sizeof(group_path), "/dev/vfio/%d", group);
>   
>   	device->group_fd = open(group_path, O_RDWR);
> @@ -219,14 +219,12 @@ static void vfio_pci_group_setup(struct vfio_pci_device *device, const char *bdf
>   	ioctl_assert(device->group_fd, VFIO_GROUP_SET_CONTAINER, &device->iommu->container_fd);
>   }
>   
> -static void vfio_pci_container_setup(struct vfio_pci_device *device, const char *bdf)
> +void vfio_pci_iommu_setup(struct vfio_pci_device *device)
>   {
>   	struct iommu *iommu = device->iommu;
>   	unsigned long iommu_type = iommu->mode->iommu_type;
>   	int ret;
>   
> -	vfio_pci_group_setup(device, bdf);
> -
>   	ret = ioctl(iommu->container_fd, VFIO_CHECK_EXTENSION, iommu_type);
>   	VFIO_ASSERT_GT(ret, 0, "VFIO IOMMU type %lu not supported\n", iommu_type);
>   
> @@ -236,8 +234,14 @@ static void vfio_pci_container_setup(struct vfio_pci_device *device, const char
>   	 * because the IOMMU type is already set.
>   	 */
>   	(void)ioctl(iommu->container_fd, VFIO_SET_IOMMU, (void *)iommu_type);
> +}
>   
> -	device->fd = ioctl(device->group_fd, VFIO_GROUP_GET_DEVICE_FD, bdf);
> +static void vfio_pci_container_setup(struct vfio_pci_device *device)
> +{
> +	vfio_pci_group_setup(device);
> +	vfio_pci_iommu_setup(device);
> +
> +	device->fd = ioctl(device->group_fd, VFIO_GROUP_GET_DEVICE_FD, device->bdf);
>   	VFIO_ASSERT_GE(device->fd, 0);
>   }
>   
> @@ -337,9 +341,7 @@ static void vfio_pci_iommufd_setup(struct vfio_pci_device *device,
>   	vfio_device_attach_iommufd_pt(device->fd, device->iommu->ioas_id);
>   }
>   
> -struct vfio_pci_device *__vfio_pci_device_init(const char *bdf,
> -					       struct iommu *iommu,
> -					       int device_fd)
> +struct vfio_pci_device *vfio_pci_device_alloc(const char *bdf, struct iommu *iommu)
>   {
>   	struct vfio_pci_device *device;
>   
> @@ -349,9 +351,20 @@ struct vfio_pci_device *__vfio_pci_device_init(const char *bdf,
>   	device->bdf = bdf;
>   	device->iommu = iommu;
>   
> +	return device;
> +}
> +

In the latest kernel, this part changes too much.

Yanjun.Zhu

> +struct vfio_pci_device *__vfio_pci_device_init(const char *bdf,
> +					       struct iommu *iommu,
> +					       int device_fd)
> +{
> +	struct vfio_pci_device *device;
> +
> +	device = vfio_pci_device_alloc(bdf, iommu);
> +
>   	if (device->iommu->mode->container_path) {
>   		VFIO_ASSERT_EQ(device_fd, -1);
> -		vfio_pci_container_setup(device, bdf);
> +		vfio_pci_container_setup(device);
>   	} else {
>   		vfio_pci_iommufd_setup(device, bdf, device_fd);
>   	}

-- 
Best Regards,
Yanjun.Zhu


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ