From nobody Wed Apr 8 23:37:50 2026 Received: from mail-oo1-f74.google.com (mail-oo1-f74.google.com [209.85.161.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 7E2FD3E1237 for ; Thu, 2 Apr 2026 17:31:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775151071; cv=none; b=b3JB2E+xCyiPteq6D3TUlYFR4h2URTSN4n3qM2m4oOjiVZ/puI17zuFgTxFg7kzzXBJAH40/sC79L4u0SNqRWuW19ov2u+zlzb4dNlLPXSZW1FyKw7+f8BdluQM3KqjgtiFRTEG7PwFEQ4I8LBf6fLfk6P17LHyhgfzxWc1qOFs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775151071; c=relaxed/simple; bh=fKGrqOe7/gcHbceYdJgmC+BFNKB4nT/qhL7SRADHx9U=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=K9RTIK+9eeh9K41lMYwkbbTCwuCFwpE1TJ6oCHHC3v4qEziUNC08UVcPWr5R3ff99xRwUufeI9wOs3TAy7CLKumwWhZDNvIk31d/6GqwDSb9ez+4mMq26rg+8Y8nlIirldgmAuB19AS4Ded9MsWEuzbYS/6laJdcT3TGiXZG2HM= 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=GlvIcSWu; arc=none smtp.client-ip=209.85.161.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="GlvIcSWu" Received: by mail-oo1-f74.google.com with SMTP id 006d021491bc7-66b612efb4aso2390239eaf.0 for ; Thu, 02 Apr 2026 10:31:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1775151069; x=1775755869; 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=Qy6Cj7fcucn9v9YQ8Oo1NV9Ds993VMVKePqjlbtzguo=; b=GlvIcSWuQ/1C8PYWVB2sSlBR+++fr/TbMKnexsum7NfMaYyJzzkKlPDR0g277Gl4ES r7A5OX4ZA5jiYC8FEvKHuvYmYX0BAbdBRFFquOJX1sGe/loLnRzGmeST+MfjD+Ie6ShM JJlUPUNICvF8XbNZN5zxLB5vEUdbslr+/JXobz3kOwxc442rmz5mf8oWra/NjArR38U3 ZG6rUeb8XFy/E5caDZjFJkajZoAc61sZiDwK94/EGYMMdrrqltLvU0YRc4/W5SuHDLFp b57T/poCSj3EE9Z3p2/r/1ii31Xsho/+ztjqiofPtOWr3H2BoDny15hdE+SnT8w75XLb n3bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775151069; x=1775755869; 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=Qy6Cj7fcucn9v9YQ8Oo1NV9Ds993VMVKePqjlbtzguo=; b=FRvN1vqon7GTbQKP1ndK1s9yCw4AyT1X24KrYoKWypKI/gHkJE4xdyMGIQAtUjY4/P S+4Opr1VDWF7gScv4vOHKEYx24JDJ4PX3bmXEmqqayza6EjuaUvip9+FyuaAsdC+MhMO 30qD21/xbgNOOJ/kkw26Vpue/UmuRJ9qgZ9x6h75c22B1Hg5GYYpifRKlq76TinZWlAe okg39b3Orzckw8Zdxno0pvAqqi+Cg/7kwG6rwgLsHblRVZP39Fv34O9pR53/b920nngd oqjJUAZtf3IWstUuZ/lq7z5t+C3AVdvUPk4mseRKcwdEJvwi1i+1riiaRDor5OZxhct6 VekQ== X-Forwarded-Encrypted: i=1; AJvYcCXdxO40IgLwZdBjiGUxiWaas0tI7BbsLDcQMi4h7z8hnyYylAxR6TolxYpbTL3RZFyCaoJXxnAEtHBhgcw=@vger.kernel.org X-Gm-Message-State: AOJu0YzcBScbRQz/UOkgCxsnTASq0QDtPDmvUzt84/vSP8oKzIMywy0H lC88en/z8UVVNPy8QkgfljTLFaCmQhSNOYPvqEGm0RUltlACUm7+8tmw2ch+EWB8qbnw7J6luOz +ZCkbVt2IsA== X-Received: from ilnp16.prod.google.com ([2002:a92:d690:0:b0:4f8:9187:e599]) (user=rananta job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6820:a089:b0:682:1c53:89fc with SMTP id 006d021491bc7-6821c538eb5mr29264eaf.8.1775151069353; Thu, 02 Apr 2026 10:31:09 -0700 (PDT) Date: Thu, 2 Apr 2026 17:30:57 +0000 In-Reply-To: <20260402173059.1018805-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: <20260402173059.1018805-1-rananta@google.com> X-Mailer: git-send-email 2.53.0.1213.gd9a14994de-goog Message-ID: <20260402173059.1018805-7-rananta@google.com> Subject: [PATCH v7 6/8] vfio: selftests: Add helper to set/override a vf_token From: Raghavendra Rao Ananta To: David Matlack , Alex Williamson Cc: Vipin Sharma , 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 Reviewed-by: David Matlack --- .../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 898de032fed5a..4ebdc00e20fca 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_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 3123ba591f088..4673b148f8c44 100644 --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c @@ -113,6 +113,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.53.0.1213.gd9a14994de-goog