From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) (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 5D0A127F017 for ; Wed, 7 Jan 2026 22:49:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.196 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767826161; cv=none; b=PLVePIGVRVdcXHLhAVbfkbZCAuFKuVY5A0e1awSOnJYIo+OPiuQl5V6BXtHld0EKjL8fk0M/LklQ6BcX2tCcI84n5t2MwBFgC4gmW+IB3w3axneLviKxrUhl/tOwhGgoPd3SWJxdn7stsXcAsN6Gp0pfkek4HwOi0U0465Y0TQI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767826161; c=relaxed/simple; bh=2kKpvI6ZFSKHORTpkWXd4AljDkhpjfHIoY5AyWZsWqM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MYol09s79WZDugtWk93qua/sASYB/bkT5LRitB5ZgPV+P7dl12bIwPf/1y0qPiv1e9aYXpPSGUMtD90rPqQUO8rx0+a+xXuZyCc9xYZ+6BC6xlPr9gnVCo17AHNhYyHpU310l/Td0RIceiTCsHxHjpznYGakLexJmiRllK9R1VE= 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=nRMWCIOl; arc=none smtp.client-ip=209.85.214.196 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="nRMWCIOl" Received: by mail-pl1-f196.google.com with SMTP id d9443c01a7336-2a12ebe4b74so27411365ad.0 for ; Wed, 07 Jan 2026 14:49:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1767826157; x=1768430957; 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=JnVLVYG1IRfpUlm6+VrOi9vquCcu14DZdquCNFExRV0=; b=nRMWCIOlHo7+haceAc4yTeQJi7GbnNRqhPNa6l+vRrsaQpuMtUbkvZ0KryMRcEev2Z g8Uhy5rUB8kdIgZ7m68O8tbSQCGwx2pp2seozI6FTgZfhoH1nKSqgiW+Bb8VjRh1INtp gElTT3pXbIHxPdGhI/DNjPYQT2uBsy04vKnss9ljQaFoq3Pa9nMGVXDQmnqU2DFbWoM+ i2YVu6G5Fu6i6DJP26mPsux4UkBn5KWf2CPf//1Pa6kcsHXzSKkEzemrmbw7CJQo+fsW EILjDIlH3NEPVVwtFnqA3h1xiCovndF5mGwAlgiD5FLTAJKzZiY+MXKwNhIo1jHjGste lxEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767826157; x=1768430957; 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=JnVLVYG1IRfpUlm6+VrOi9vquCcu14DZdquCNFExRV0=; b=P/xNH/POySRlEy/VqiwmK3R5tX3hMoldA7SOq08L5q55XqE7TOSLqzxq73BtNjhE4P QR5adEzqp177MmpgQ12wP+PKOCuOYo9FRC6gzTvXP1bYaQNW8l54sE3xrzokJus/CQS2 sVrjTJTHjsboMYxMBsZpy4JttP8inD/pXbDOH3tmf4mgTGwv26o5WRZmbb0xf0FFMVEH qMV955Fo52mzKp0gL7/2xWN7X90Hu0Aujf95C3GQUAoy7yWuhRjMO4yM8vaWGDKF8JPs WNtbzR8FN7FxIxBv+UfkEVU8kY16kwnxedFi9LA2HENTnfcjVHvvOldgHhLVaJ8xA3Q8 3tVA== X-Forwarded-Encrypted: i=1; AJvYcCUf8AaoMM2NgGs8QPnSlzj1RbFC5Wu0ftCZVeYxOmOodqMakAqB3am3qPiPrPte1szHKh5Ypqxk+i3WdyE=@vger.kernel.org X-Gm-Message-State: AOJu0Yw9N2e0NioW059M3xkS9a1bt99R4AFOhxGuRJYxxAqOuSIR5how Obm0auP+BWrr3S/h++8KL7MM/7ClkucwWj7FcTMwoF2Xek5F7g4b0F6Z+DIY4qQaPQ== X-Gm-Gg: AY/fxX5VdSs1tvQWyzp2c6HyTQUtmGbd1oIwS7b0VamQPWab/Wyi0KVfNahGl/6AL4w Qm47CpaEMiZjMgm1BH574tW7kUbBGCxmEEP+jR9CxsruEBT7vgFQtftpz0Pu0q/LfN/pkoMYuZ2 ddHl5Ucg/Xkn8h76zmca/2DGR5K1Hkd65hq2SFJ/8FX2+xkcdbfP8klM/EEIqyZho5qKaqXziJw V/8SVD9G+WK1LqqfiSKJqXDQ3m0rxGQUckHx7eV41aB28gVUz+J4S81hD2sqRky9Uk1cbnY/8ku +QEJhR/YPZFwDutbjuyhiQtsk/+LKfb2sO0Qkf74mi/5UJ7jZMEGVgePJwhFUYGyJn09Ho6jWHG C6Pp6FBmRNzz0oWANtgtwu2BNoinUleda+ufxfUOHWYbfBC6/LGEBkFkCFN6Yclb/qTzfAagsjL TnreCbmdxyKUZu1b6I0gzE11DEO3YfSQldFgtdRHCUWe59 X-Google-Smtp-Source: AGHT+IERoVyKgTh/iF+e5eqgPhiHGb2vF1b2fNZbwYe3hAIlTypkzbgNZaLRgU/AO3Bjg8Kp9EBkxQ== X-Received: by 2002:a17:902:f70e:b0:2a0:a0cc:9997 with SMTP id d9443c01a7336-2a3ee4b4c12mr36133335ad.50.1767826157041; Wed, 07 Jan 2026 14:49:17 -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-2a3e3c3a560sm58824415ad.21.2026.01.07.14.49.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jan 2026 14:49:16 -0800 (PST) Date: Wed, 7 Jan 2026 22:49:12 +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 3/6] vfio: selftests: Extend container/iommufd setup for passing vf_token Message-ID: References: <20251210181417.3677674-1-rananta@google.com> <20251210181417.3677674-4-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-4-rananta@google.com> On 2025-12-10 06:14 PM, Raghavendra Rao Ananta wrote: > A UUID is normally set as a vf_token to correspond the VFs with the > PFs, if they are both bound by the vfio-pci driver. This is true for > iommufd-based approach and container-based approach. The token can be > set either during device creation (VFIO_GROUP_GET_DEVICE_FD) in > container-based approach or during iommu bind (VFIO_DEVICE_BIND_IOMMUFD) > in the iommu-fd case. Hence extend the functions, iommufd > vfio_pci_iommufd_setup() and vfio_pci_container_setup(), to accept > vf_token as an (optional) argument and handle the necessary setup. > > No functional changes are expected. > > Signed-off-by: Raghavendra Rao Ananta > --- > tools/testing/selftests/vfio/lib/libvfio.mk | 4 +- > .../selftests/vfio/lib/vfio_pci_device.c | 45 +++++++++++++++---- > 2 files changed, 40 insertions(+), 9 deletions(-) > > diff --git a/tools/testing/selftests/vfio/lib/libvfio.mk b/tools/testing/selftests/vfio/lib/libvfio.mk > index b7857319c3f1f..459b14c6885a8 100644 > --- a/tools/testing/selftests/vfio/lib/libvfio.mk > +++ b/tools/testing/selftests/vfio/lib/libvfio.mk > @@ -15,6 +15,8 @@ LIBVFIO_C += drivers/ioat/ioat.c > LIBVFIO_C += drivers/dsa/dsa.c > endif > > +LDLIBS += -luuid > + > LIBVFIO_OUTPUT := $(OUTPUT)/libvfio > > LIBVFIO_O := $(patsubst %.c, $(LIBVFIO_OUTPUT)/%.o, $(LIBVFIO_C)) > @@ -25,6 +27,6 @@ $(shell mkdir -p $(LIBVFIO_O_DIRS)) > CFLAGS += -I$(LIBVFIO_SRCDIR)/include > > $(LIBVFIO_O): $(LIBVFIO_OUTPUT)/%.o : $(LIBVFIO_SRCDIR)/%.c > - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ > + $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< $(LDLIBS) -o $@ Do we need $(LDLIBS) when compiling the intermediate .o files? I thought we would only need it when linking the selftests binaries. > > EXTRA_CLEAN += $(LIBVFIO_OUTPUT) > diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c > index 9b2a123cee5fc..ac9a5244ddc46 100644 > --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c > +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c > @@ -12,6 +12,7 @@ > #include > > #include > +#include > #include > #include > #include > @@ -199,7 +200,27 @@ 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) > +static void vfio_pci_group_get_device_fd(struct vfio_pci_device *device, > + const char *bdf, const char *vf_token) > +{ > + char arg[64] = {0}; unnecessary intitialization > + > + /* > + * If a vf_token exists, argument to VFIO_GROUP_GET_DEVICE_FD > + * will be in the form of the following example: > + * "0000:04:10.0 vf_token=bd8d9d2b-5a5f-4f5a-a211-f591514ba1f3" > + */ > + if (vf_token) > + snprintf(arg, ARRAY_SIZE(arg), "%s vf_token=%s", bdf, vf_token); snprintf_assert() :) > + else > + snprintf(arg, ARRAY_SIZE(arg), "%s", bdf); > + > + device->fd = ioctl(device->group_fd, VFIO_GROUP_GET_DEVICE_FD, arg); > + VFIO_ASSERT_GE(device->fd, 0); > +} > + > +static void vfio_pci_container_setup(struct vfio_pci_device *device, > + const char *bdf, const char *vf_token) > { > struct iommu *iommu = device->iommu; > unsigned long iommu_type = iommu->mode->iommu_type; > @@ -217,8 +238,7 @@ static void vfio_pci_container_setup(struct vfio_pci_device *device, const char > */ > (void)ioctl(iommu->container_fd, VFIO_SET_IOMMU, (void *)iommu_type); > > - device->fd = ioctl(device->group_fd, VFIO_GROUP_GET_DEVICE_FD, bdf); > - VFIO_ASSERT_GE(device->fd, 0); > + vfio_pci_group_get_device_fd(device, bdf, vf_token); > } > > static void vfio_pci_device_setup(struct vfio_pci_device *device) > @@ -279,12 +299,20 @@ const char *vfio_pci_get_cdev_path(const char *bdf) > return cdev_path; > } > > -static void vfio_device_bind_iommufd(int device_fd, int iommufd) > +static void vfio_device_bind_iommufd(int device_fd, int iommufd, > + const char *vf_token) > { > struct vfio_device_bind_iommufd args = { > .argsz = sizeof(args), > .iommufd = iommufd, > }; > + uuid_t token_uuid = {0}; unnecessary intitialization > + > + if (vf_token) { > + VFIO_ASSERT_EQ(uuid_parse(vf_token, token_uuid), 0); > + args.flags |= VFIO_DEVICE_BIND_FLAG_TOKEN; > + args.token_uuid_ptr = (u64)token_uuid; > + } > > ioctl_assert(device_fd, VFIO_DEVICE_BIND_IOMMUFD, &args); > } > @@ -299,7 +327,8 @@ 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) > +static void vfio_pci_iommufd_setup(struct vfio_pci_device *device, > + const char *bdf, const char *vf_token) > { > const char *cdev_path = vfio_pci_get_cdev_path(bdf); > > @@ -307,7 +336,7 @@ static void vfio_pci_iommufd_setup(struct vfio_pci_device *device, const char *b > VFIO_ASSERT_GE(device->fd, 0); > free((void *)cdev_path); > > - vfio_device_bind_iommufd(device->fd, device->iommu->iommufd); > + vfio_device_bind_iommufd(device->fd, device->iommu->iommufd, vf_token); > vfio_device_attach_iommufd_pt(device->fd, device->iommu->ioas_id); > } > > @@ -323,9 +352,9 @@ struct vfio_pci_device *vfio_pci_device_init(const char *bdf, struct iommu *iomm > device->bdf = bdf; > > if (iommu->mode->container_path) > - vfio_pci_container_setup(device, bdf); > + vfio_pci_container_setup(device, bdf, NULL); > else > - vfio_pci_iommufd_setup(device, bdf); > + vfio_pci_iommufd_setup(device, bdf, NULL); > > vfio_pci_device_setup(device); > vfio_pci_driver_probe(device); > -- > 2.52.0.239.gd5f0c6e74e-goog >