From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f45.google.com (mail-dl1-f45.google.com [74.125.82.45]) (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 6621F3A16AA for ; Tue, 12 May 2026 22:29:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778624987; cv=none; b=nkhfGOupfIeQIyZ4mYhj4Rhx4fxQz3Rqd4tE3PIR2/Iu80NJxMhm95IvTgVW+ND6TOTt007PIJ01d39aOakJbvMzOJIiVefeLXlB2Ff4pl2ndMd5+qneMoNURsKy82S1h8jThxQZDz23m+M8Z7keyI+MVnTWzpxf5pKuBk+GIrY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778624987; c=relaxed/simple; bh=Q3BSnpQjjo24GYH+K8YZfJrIUBzm8VwHg2FJ+gC1p5M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qDPO6FqWFER15pVXWUdUqJOr8bimJegwMuWWw7bXNwi11B36GSqmpToRUbwI1GZumeLjhVS9gi18r9DzV8InxSCNV0TMncEnp51vqhKTVodAeNZqr7zXB2LsaAKsFcZmfe3hCOSv/aKIknSc45nvxLy06izmOj8cZL+KjScMyDw= 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=isPwlTwr; arc=none smtp.client-ip=74.125.82.45 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="isPwlTwr" Received: by mail-dl1-f45.google.com with SMTP id a92af1059eb24-133362c30cfso8c88.0 for ; Tue, 12 May 2026 15:29:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778624986; x=1779229786; 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=A91sQDiDjkh+GXesefXA7O5mW+fBVnqghfkdmyiPV8o=; b=isPwlTwrq9pxaQ0IKtoYT8+klOCRcdaKL+l0Sk/W1RXARemQdD2eEi0b2DcktM3g7N y73cFFD8Xmf0OVJb4N6DGpNBEFuhDDvSsOeI9vFoIXzRo7/adBwUQToMXsb3SBkT3ZyH GTs6AszTIAVj+sJB+hhWuFbEkf98+ENSnLpKXak9Wy4rLmfA1nZGxu+eaFlUpjjmmy/9 xzyL7BnWT1lAqg0bpfYkfNhd3MQslTaVm4J3yOQi3IZJ6/8p/1aBmxrSIUarIxbsY2sn sW5FiKH7BdLyyIQaGROLg7J8ai2YIIU/14gHMuwYWN/hDx3D4wBKybeCNerWfIduqw2Y l2lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778624986; x=1779229786; 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=A91sQDiDjkh+GXesefXA7O5mW+fBVnqghfkdmyiPV8o=; b=UygNd0S7eMWK9I/uDjYEF+MxQovaCMsFM1X0YW3autjSWJyrDoF3ozc73EvCTZ8+6o UZ/K/rv2l8fP6nGsQBqR5ag/t4A/qU+/F5hoBI+JIrxI1phbrg4i4p7cJPBphMs9cvV4 dZ453qdtAQn1EkdWQWxBWylZ/4lV/kWH3PoI6dk6dfyRAXrLflKl7iG9XaHxS7NG8jSD itdZcH236KGhe5qohNuvDsE0WiyOrUnzqLGgnvSbQBbRDIxR9SYMfzzXVNrG4UuW0QDs EUW0xDJUPVdOlc3tQPiNsa6ce1KeeJmSXscuxiK5cb1kc+iKEU7JFLFaUGjajtpLAt/o mkKg== X-Forwarded-Encrypted: i=1; AFNElJ8ajkEY//QjEnu10jgsqux3sNi3fuvEa57/7kKQbywpidPWrWHg08hWQXkUKsxKDK+QykqVKY6+0hXLQzI=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/lNWpdlIuEnSYni9ypxVAN3raS9sMOGs3l8OmQqoHlYAeBHoe xeZB52Dt2THS+a0jHLDbjZTAUVOfQtnJ79j4vneEDKcj1jLFBn7LzfH3IEkeD4EGXA== X-Gm-Gg: Acq92OEPqGsbOrA1UZEWlQZpWdqthKnwjgaduOF9zRlTEnY4+mTG2Do7UPc1VtJXAs+ v1T6RpvXPy5ng+HiwSe2DqzBxe47DBi5/zdi3CGLdfWzLRLVUAaXSJdZnXOw/66QD06wr7o/1LZ Mri2sfgVMKrsJ0pmVLSfFDGmrOlUN3lCJdD01MdwsH+6EoV4RVIUxuf2zpmyZ+uA2d+vfcZarWx yZk9hB2qQ5AxmqAnY470RERQHb0nk7o+MdEcXgDjauA7qw8JQd2bN+mAGATo/AaEYljXMmlL6mT uZP3ShOhgnQ0NOObMdP50J3giuSkWcYPpZjJ1hhWNSnehOtk8lh4+27cQZnotYkG8l0+wqjw7oN qquqn0DfiUN2AIeIe5d+duAs68PkszcRJ0IYJJF06v7UFyT1yeledRvNsj6xiXqAT4Tw7ryXxwQ nTeHyAaGiOoyk8BUh2UGevtPFH1ryuAONxeCfEHhKL96WmtqlG5o/t7dcxgNtWp3tG4fXM3szts T9Eu5IQ X-Received: by 2002:a05:7022:613:b0:12c:912f:7d1e with SMTP id a92af1059eb24-13489ba2ee7mr46570c88.7.1778624984910; Tue, 12 May 2026 15:29:44 -0700 (PDT) Received: from google.com (60.89.247.35.bc.googleusercontent.com. [35.247.89.60]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13278210d40sm25341631c88.4.2026.05.12.15.29.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 15:29:44 -0700 (PDT) Date: Tue, 12 May 2026 15:29:40 -0700 From: Vipin Sharma To: Raghavendra Rao Ananta Cc: David Matlack , Alex Williamson , Josh Hilke , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v8 5/8] vfio: selftests: Expose more vfio_pci_device functions Message-ID: <20260512222919.GE3046123.vipinsh@google.com> References: <20260505212838.1698034-1-rananta@google.com> <20260505212838.1698034-6-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: <20260505212838.1698034-6-rananta@google.com> On Tue, May 05, 2026 at 09:28:35PM +0000, Raghavendra Rao Ananta wrote: > 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 > Reviewed-by: David Matlack > --- > .../lib/include/libvfio/vfio_pci_device.h | 7 +++ > .../selftests/vfio/lib/vfio_pci_device.c | 47 ++++++++++++++----- > 2 files changed, 42 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..898de032fed5a 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_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 e59b6689f4576..53e01cdb2b4e5 100644 > --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c > +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c > @@ -204,7 +204,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), > @@ -224,8 +224,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]; > > @@ -240,18 +240,21 @@ static void vfio_pci_group_get_device_fd(struct vfio_pci_device *device, > snprintf_assert(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); > > @@ -261,7 +264,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); > } > > @@ -323,8 +332,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), > @@ -338,7 +346,18 @@ 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); > + if (ioctl(device_fd, VFIO_DEVICE_BIND_IOMMUFD, &args)) > + return -errno; > + > + return 0; > +} > + > +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) > @@ -351,15 +370,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_cdev_open(struct vfio_pci_device *device, const char *bdf) > { > 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_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.54.0.545.g6539524ca2-goog > Reviewed-by: Vipin Sharma