From nobody Tue Dec 16 20:33:32 2025 Received: from mail-ot1-f74.google.com (mail-ot1-f74.google.com [209.85.210.74]) (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 9A407329C41 for ; Wed, 10 Dec 2025 18:14:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765390468; cv=none; b=H3AubeOYIpogejuxtzwrF1vSJ4ihOvXp6FQMPZOdoY2ue2aCzVDpRcDb8zvdhzY+5ARjnYrGneJN/zq7YeVMIFOEDh09MnZta6r9eDbqMbWhbN9rp6wzTaecHnZ2Hy1xgO0pjT7fI5y48/q16adXZ0XoetZGZe3oK8odo8Iqw0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765390468; c=relaxed/simple; bh=pwlFgeh1zV9BNL0tvm8yEEyE54pw7ioKi1EzIbT/3Hk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MI3MKYUoNa0pt8cz8+EJ9hPG+d2xME6g+LPTPJivXVtEU1NuR1KWrpv2mDqlLHwOJ8xmkVqjV3EFhVPmUJK/DsaFK5Wnc9Oqf4I7xeIMBXGiuMTjJAgesMZZG3f6zM5FMfb2ObYZH53gzfvmwIDWGcW60wLh4E/4kpvnNKvjh3g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--rananta.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=xXi10Tcp; arc=none smtp.client-ip=209.85.210.74 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=flex--rananta.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="xXi10Tcp" Received: by mail-ot1-f74.google.com with SMTP id 46e09a7af769-7c72ccd60f5so359670a34.0 for ; Wed, 10 Dec 2025 10:14:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1765390466; x=1765995266; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4gUwEMI4CPC8nG6DpXhg5Tl6v8j6U1PzBCdzq7Inos8=; b=xXi10TcpFHB83Uay3V25poivP7UPmNooomxicHJjAhe2BuMMNRc1vjRKVtXGbVoScU HQTJvEj9hd4+T9toWvOi3EBM7gpP6toIIe5N0YDEL3mu0AKcP+oQF1Ot3nH0JA06zbcR 7ZPzlGJU0otoqDgYSfLu8tEqrSPK6Nrkr4UjZjaqs8ReBZjYUaVHutQqYxz7TJgaSnJf wP8zAZzcIlwaoVpmyUqlcxRS3ZFmjaBKAcqPs9nA8Vf7VA9e9LsYcHmbIxzEomYYEDpA OBgmj01JC25kfBskcmXdnOef8OoOPFajBy4Ra+W8nq5+Z9CMnkxxis926DH6NbwFYjzt 6EZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765390466; x=1765995266; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4gUwEMI4CPC8nG6DpXhg5Tl6v8j6U1PzBCdzq7Inos8=; b=dp84e3CNaK359t7e4BWHzZqomBsntj3+OIu5+nzlqdi/p89tLxQ7fMOzPF0vK/LIsA OzYW81qbRYNRuy2CPI9g3FiWgkdDjVPhfZIH7G5ciRxhiVwRGRW673oz3Ks/dLK/jPSE FlSDOSAE7jN0XtbbSYFG0V338RYZzlL1zko91Neu7EhM6FKJTvVgNkCZY2PNw2mw2gSu QKd12mMz+DbM4xptY6X+TQ1PDG8M5tawxUStgK9vf1E97lZk2TTTe8nh07Y9KsnSkbW9 86LjtdNFZ2GzWRL60zAwRWsbKXH29V8KhHiJYWMG3m5ZqH5XK0IlBYuc1QU6WlHbZMlY 9VPg== X-Forwarded-Encrypted: i=1; AJvYcCUrt+kXUpC0onwiqKXdNchzHo94hmcsymJvJgdK4TfiCJnxU2fF84j0ljrRNbKUQHr8bFfLkTo3dv4lAv4=@vger.kernel.org X-Gm-Message-State: AOJu0YwAp/jSJnqpVwrzNkDOwugq/FX9U/tmUjKIlU9b59zXWNjf2xt0 H3cYtBuVhQo87jW4xuSJYaen5ZXOfzt1ApKSR/mGIuPcDDYNFXhi9Z6tIkombrm2I1F2CUYZz7J DlpK53JtD0Q== X-Google-Smtp-Source: AGHT+IHG44j9+i0T0oJH5qztj8QDLXfbSZEMuigfmk9lH3MjDr9iEI8CBWmAD9bZ6oOzQ/GYCPP3dTlLaWN7 X-Received: from iomw16.prod.google.com ([2002:a5e:d610:0:b0:949:68d:8b40]) (user=rananta job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6820:f008:b0:65b:257b:a885 with SMTP id 006d021491bc7-65b2ac3ec9fmr2171394eaf.25.1765390465579; Wed, 10 Dec 2025 10:14:25 -0800 (PST) Date: Wed, 10 Dec 2025 18:14:16 +0000 In-Reply-To: <20251210181417.3677674-1-rananta@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251210181417.3677674-1-rananta@google.com> X-Mailer: git-send-email 2.52.0.239.gd5f0c6e74e-goog Message-ID: <20251210181417.3677674-6-rananta@google.com> Subject: [PATCH v2 5/6] vfio: selftests: Add helper to set/override a vf_token From: Raghavendra Rao Ananta To: David Matlack , Alex Williamson , Alex Williamson Cc: Josh Hilke , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Raghavendra Rao Ananta Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a helper function, vfio_device_set_vf_token(), to set or override a vf_token. Not only at init, but a vf_token can also be set via the VFIO_DEVICE_FEATURE ioctl, by setting the VFIO_DEVICE_FEATURE_PCI_VF_TOKEN flag. Hence, add an API to utilize this functionality from the test code. The subsequent commit will use this to test the functionality of this method to set the vf_token. Signed-off-by: Raghavendra Rao Ananta --- .../lib/include/libvfio/vfio_pci_device.h | 2 ++ .../selftests/vfio/lib/vfio_pci_device.c | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_devi= ce.h b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h index 6186ca463ca6e..b370aa6a74d0b 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 @@ -129,4 +129,6 @@ void vfio_container_set_iommu(struct vfio_pci_device *d= evice); 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); =20 +void vfio_device_set_vf_token(int fd, 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/tes= ting/selftests/vfio/lib/vfio_pci_device.c index 208da2704d9e2..7725ecc62b024 100644 --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c @@ -109,6 +109,40 @@ static void vfio_pci_irq_get(struct vfio_pci_device *d= evice, u32 index, ioctl_assert(device->fd, VFIO_DEVICE_GET_IRQ_INFO, irq_info); } =20 +static int vfio_device_feature_ioctl(int fd, u32 flags, void *data, + size_t data_size) +{ + u8 buffer[sizeof(struct vfio_device_feature) + data_size] =3D {}; + struct vfio_device_feature *feature =3D (void *)buffer; + + memcpy(feature->data, data, data_size); + + feature->argsz =3D sizeof(buffer); + feature->flags =3D flags; + + return ioctl(fd, VFIO_DEVICE_FEATURE, feature); +} + +static void vfio_device_feature_set(int fd, u16 feature, void *data, size_= t data_size) +{ + u32 flags =3D VFIO_DEVICE_FEATURE_SET | feature; + int ret; + + ret =3D vfio_device_feature_ioctl(fd, flags, data, data_size); + VFIO_ASSERT_EQ(ret, 0, "Failed to set feature %u\n", feature); +} + +void vfio_device_set_vf_token(int fd, const char *vf_token) +{ + uuid_t token_uuid =3D {0}; + + VFIO_ASSERT_NOT_NULL(vf_token, "vf_token is NULL"); + VFIO_ASSERT_EQ(uuid_parse(vf_token, token_uuid), 0); + + vfio_device_feature_set(fd, VFIO_DEVICE_FEATURE_PCI_VF_TOKEN, + token_uuid, sizeof(uuid_t)); +} + static void vfio_pci_region_get(struct vfio_pci_device *device, int index, struct vfio_region_info *info) { --=20 2.52.0.239.gd5f0c6e74e-goog