From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33CF1C8CE for ; Wed, 7 Jan 2026 22:55:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.193 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767826512; cv=none; b=syVChl9z03JgHejQxhKuTv4bmTUnyaHpMTBx18881MC85RxJjqB6/dtBcAAWXnTsqgBB+nqG5wewhfEa25J4lbAqYQAan6noYiMt+DFOu8UF2MkqWgFrhA+tWv8MkLxNkKC17Qe8G+mDcRbnOJuGIuIb2dZWVL5zpiWCqVKOuFc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767826512; c=relaxed/simple; bh=QlnNM8G33LFHAv4E4QupmC52vbBOTPva1B/8FJM7PdQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qWTdOsq0NEITrcf6JZJS1Wf0NFnkqV3ue9Eg1IBU33F8NnNJvMwJ/x9DnBDptH6WLy7DqNrRhFpCB3jhNRp3E+WQJxuR3sFooURSK6Xa9D5EXEzck81KbXrUkF7uRs1a5BItls2dTzcQ+ppkDdE1BC3qopdr90gk8Tdu5N7WZD4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ajmSN0Zk; arc=none smtp.client-ip=209.85.214.193 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ajmSN0Zk" Received: by mail-pl1-f193.google.com with SMTP id d9443c01a7336-2a0c09bb78cso11398825ad.0 for ; Wed, 07 Jan 2026 14:55:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767826510; x=1768431310; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=gQYEwEgO5HZdvBOkI6YyFS22il1EyH344FtZtud2KFo=; b=ajmSN0Zkksl4QYCQw8IZCUd1nMMlsYk6aQBzXza4XLHKRKOskyjir8nWQrV9vZsntZ EbgvUQz7DNDPXgZIr4zl+BlNKejDtPtMgzMVJHuBF0YOzLTVuzLGm98PlwXm2DZR1iII 7l4y2TiT6cEllVwhsyN0qVDjVt+rz6Yoo2yLtreiavOjGIS+Mfsg+czJ4Q2/3QtTK+TU Q1b+vSv8KaSqYMk1/xS8UZcBsH/u0nhy+zUuloLC5EZsEMkWUHp8GAerXJjNX8jdO540 7UR59Ee2YUCNBAGD4/lOAlXC96wz063/BEHauZ/bTqotccq1WxhM/CwssogSrCPs9luZ Ivvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767826510; x=1768431310; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gQYEwEgO5HZdvBOkI6YyFS22il1EyH344FtZtud2KFo=; b=W5jvZAKHtW8BKZEKoRFQcjq/J8Ew5UcBC6bET1gL7NL5AEZpT/FarAQ5WZvdF61LmB yc0j7Az0fq4j/ujLx3DwX/xUPqeIy+EVf9sQjRbGAOqgMkMWShW4H0H6cyS9UHUwfcwe HjzxShhZmxrlbiV1TjURwXGySWmUlyr5w1VAI34jqtgQHzgr+/a1mWT8J+zHK8voMeax WpfEGfbYUhgjc0x5yk5KuS+7NMMl37p+Rg2Fgzq9WL4tV6koJIgiOZszzfKUTXlRWP/J PYyWCMkpIG4kCJIe9J79yQoO3YId4U630KcuEOS3YUBFsc3HpciA5M+NFtilme7Pocik bz6Q== X-Forwarded-Encrypted: i=1; AJvYcCWPVTgaN2jYtlWixz0v65PK4jnZ+uFTUy8NzM503Xq+bagv1GTO/WlJuevLhKmlUNATWsE7evhOPQzH89k=@vger.kernel.org X-Gm-Message-State: AOJu0YyJ+gYFlB6Y3DTJKIhki9gATB92M3BhWFzrEUiDeihBM5zEdXdS lD7T4jU3YwdTvpuleyjKjgSXuGstweXUwyXzQbaMnVDjq6+VMljU5HG8pn2tw3jy9g== X-Gm-Gg: AY/fxX7QmRkwl5jlKQgDu1MJWGRBfmGji3b+N6+oI3XpMIxrTo3oiOfwHhEsDzu9VKz v5cnetZ9DSISIs75fWsg0JyWftYNfULneBowmYmYDSz9nj3h3qXU6sLoPOahKxoAvOXmv+vqZK/ aSzsQSe2xsL8VMHNl27nea5gR6O7t7s3JrJf0T5WsUGdLR9L5jdsKpYsHaogCjU6ST8IkNCirFC OlzTq7Ub56U9QQngzkOUsx8q0ieSlk0ilMl8Ms8Xh1r0KNAre5Yt12DedmP9nWpWbuHulofiB3A /8/x652pdbc7aJ2cx9y//1JlTBKvyqketcO6lJuZtY/BH4Usr5eO/WPcbFDBFcE1JhII5qum0d2 u/+FtwmV1RNw8oZxuJ+r3x1H7EY7ftA7AfDpR6XbQJr0u1/EAC9C98wnNQX0a5ydEZAvQwb9IYs T/PolWeQ3N5Or8VFI9aqOUGuEnZLSUCbik1rzDLAQ89Mexmwte7r1imt8= X-Google-Smtp-Source: AGHT+IFx94sMczoLItqDdXs+++flnqgrkUGzxLw3zDHUIQw+ApmOkqsT364ITtTyiGLA9l6rYKk9WA== X-Received: by 2002:a17:903:acc:b0:295:134:9ae5 with SMTP id d9443c01a7336-2a3edb8bf35mr36244995ad.24.1767826510241; Wed, 07 Jan 2026 14:55:10 -0800 (PST) Received: from google.com (76.9.127.34.bc.googleusercontent.com. [34.127.9.76]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a3e3cc8ddfsm59173505ad.74.2026.01.07.14.55.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 14:55:09 -0800 (PST) Date: Wed, 7 Jan 2026 22:55:05 +0000 From: David Matlack To: Raghavendra Rao Ananta Cc: Alex Williamson , Alex Williamson , Josh Hilke , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 4/6] vfio: selftests: Export more vfio_pci functions Message-ID: References: <20251210181417.3677674-1-rananta@google.com> <20251210181417.3677674-5-rananta@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20251210181417.3677674-5-rananta@google.com> On 2025-12-10 06:14 PM, Raghavendra Rao Ananta wrote: shotlog nit: "Expose more vfio_pci_device functions" > Refactor and make the functions called under device initialization > public. A later patch adds a test that calls these functions to validate > the UAPI of SR-IOV devices. Opportunistically, to test the success > and failure cases of the UAPI, split the functions dealing with > VFIO_GROUP_GET_DEVICE_FD and VFIO_DEVICE_BIND_IOMMUFD into a core > function and another one that asserts the ioctl. The former will be > used for testing the SR-IOV UAPI, hence only export these. > > Signed-off-by: Raghavendra Rao Ananta > --- > .../lib/include/libvfio/vfio_pci_device.h | 7 +++ > .../selftests/vfio/lib/vfio_pci_device.c | 44 ++++++++++++++----- > 2 files changed, 39 insertions(+), 12 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 2858885a89bbb..6186ca463ca6e 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 > @@ -122,4 +122,11 @@ static inline bool vfio_pci_device_match(struct vfio_pci_device *device, > > const char *vfio_pci_get_cdev_path(const char *bdf); > > +void vfio_pci_group_setup(struct vfio_pci_device *device, const char *bdf); > +void __vfio_pci_group_get_device_fd(struct vfio_pci_device *device, > + const char *bdf, const char *vf_token); > +void vfio_container_set_iommu(struct vfio_pci_device *device); > +void vfio_pci_iommufd_cdev_open(struct vfio_pci_device *device, const char *bdf); > +int __vfio_device_bind_iommufd(int device_fd, int iommufd, const char *vf_token); > + > #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 ac9a5244ddc46..208da2704d9e2 100644 > --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c > +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c > @@ -180,7 +180,7 @@ void vfio_pci_device_reset(struct vfio_pci_device *device) > ioctl_assert(device->fd, VFIO_DEVICE_RESET, NULL); > } > > -static void vfio_pci_group_setup(struct vfio_pci_device *device, const char *bdf) > +void vfio_pci_group_setup(struct vfio_pci_device *device, const char *bdf) > { > struct vfio_group_status group_status = { > .argsz = sizeof(group_status), > @@ -200,8 +200,8 @@ 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_group_get_device_fd(struct vfio_pci_device *device, > - const char *bdf, const char *vf_token) > +void __vfio_pci_group_get_device_fd(struct vfio_pci_device *device, > + const char *bdf, const char *vf_token) > { > char arg[64] = {0}; > > @@ -216,18 +216,21 @@ static void vfio_pci_group_get_device_fd(struct vfio_pci_device *device, > snprintf(arg, ARRAY_SIZE(arg), "%s", bdf); > > device->fd = ioctl(device->group_fd, VFIO_GROUP_GET_DEVICE_FD, arg); > +} > + > +static void vfio_pci_group_get_device_fd(struct vfio_pci_device *device, > + const char *bdf, const char *vf_token) > +{ > + __vfio_pci_group_get_device_fd(device, bdf, vf_token); > VFIO_ASSERT_GE(device->fd, 0); > } > > -static void vfio_pci_container_setup(struct vfio_pci_device *device, > - const char *bdf, const char *vf_token) > +void vfio_container_set_iommu(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); > > @@ -237,7 +240,13 @@ static void vfio_pci_container_setup(struct vfio_pci_device *device, > * because the IOMMU type is already set. > */ > (void)ioctl(iommu->container_fd, VFIO_SET_IOMMU, (void *)iommu_type); > +} > > +static void vfio_pci_container_setup(struct vfio_pci_device *device, > + const char *bdf, const char *vf_token) > +{ > + vfio_pci_group_setup(device, bdf); > + vfio_container_set_iommu(device); > vfio_pci_group_get_device_fd(device, bdf, vf_token); > } > > @@ -299,8 +308,7 @@ const char *vfio_pci_get_cdev_path(const char *bdf) > return cdev_path; > } > > -static void vfio_device_bind_iommufd(int device_fd, int iommufd, > - const char *vf_token) > +int __vfio_device_bind_iommufd(int device_fd, int iommufd, const char *vf_token) > { > struct vfio_device_bind_iommufd args = { > .argsz = sizeof(args), > @@ -314,7 +322,15 @@ static void vfio_device_bind_iommufd(int device_fd, int iommufd, > args.token_uuid_ptr = (u64)token_uuid; > } > > - ioctl_assert(device_fd, VFIO_DEVICE_BIND_IOMMUFD, &args); > + return ioctl(device_fd, VFIO_DEVICE_BIND_IOMMUFD, &args); > +} > + > +static void vfio_device_bind_iommufd(int device_fd, int iommufd, > + const char *vf_token) > +{ > + int ret = __vfio_device_bind_iommufd(device_fd, iommufd, vf_token); > + > + VFIO_ASSERT_EQ(ret, 0, "Failed VFIO_DEVICE_BIND_IOMMUFD ioctl\n"); > } > > static void vfio_device_attach_iommufd_pt(int device_fd, u32 pt_id) > @@ -327,15 +343,19 @@ static void vfio_device_attach_iommufd_pt(int device_fd, u32 pt_id) > ioctl_assert(device_fd, VFIO_DEVICE_ATTACH_IOMMUFD_PT, &args); > } > > -static void vfio_pci_iommufd_setup(struct vfio_pci_device *device, > - const char *bdf, const char *vf_token) > +void vfio_pci_iommufd_cdev_open(struct vfio_pci_device *device, const char *bdf) nit: vfio_pci_cdev_open() Opening the cdev doesn't interact with iommufd in the kernel in any way. It's a pure VFIO operation. So having iommufd in the name here might be confusing. > { > const char *cdev_path = vfio_pci_get_cdev_path(bdf); > > device->fd = open(cdev_path, O_RDWR); > VFIO_ASSERT_GE(device->fd, 0); > free((void *)cdev_path); > +} > > +static void vfio_pci_iommufd_setup(struct vfio_pci_device *device, > + const char *bdf, const char *vf_token) > +{ > + vfio_pci_iommufd_cdev_open(device, bdf); > vfio_device_bind_iommufd(device->fd, device->iommu->iommufd, vf_token); > vfio_device_attach_iommufd_pt(device->fd, device->iommu->ioas_id); > } > -- > 2.52.0.239.gd5f0c6e74e-goog >