[PATCH] vfio: selftests: Remove libuuid dependency
From: Samiullah Khawaja
Date: Thu Sep 24 2026 - 21:31:25 EST
Libvfio depends on an external dependency libuuid for parsing vf_tokens.
Building it in cross compilation environments gives the following error,
ld: cannot find -luuid: No such file or directory
As it is only used for parsing vf_tokens, remove the dependency by open
coding the parser where it is required.
Tested by running vfio_pci_sriov_uapi_test selftest.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Samiullah Khawaja <skhawaja@xxxxxxxxxx>
---
tools/testing/selftests/vfio/lib/libvfio.mk | 2 -
.../selftests/vfio/lib/vfio_pci_device.c | 57 ++++++++++++++++---
2 files changed, 50 insertions(+), 9 deletions(-)
diff --git a/tools/testing/selftests/vfio/lib/libvfio.mk b/tools/testing/selftests/vfio/lib/libvfio.mk
index bcfa74ae040e..7d6916ca3940 100644
--- a/tools/testing/selftests/vfio/lib/libvfio.mk
+++ b/tools/testing/selftests/vfio/lib/libvfio.mk
@@ -29,8 +29,6 @@ $(LIBVFIO_O_DIRS):
CFLAGS += -I$(LIBVFIO_SRCDIR)/include
-LDLIBS += -luuid
-
$(LIBVFIO_O): $(LIBVFIO_OUTPUT)/%.o : $(LIBVFIO_SRCDIR)/%.c | $(LIBVFIO_O_DIRS)
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
index 4063a0e2b3df..774d1e90ec0e 100644
--- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c
+++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
@@ -23,11 +23,54 @@
#include <linux/types.h>
#include <linux/vfio.h>
-#include <uuid/uuid.h>
-
#include "kselftest.h"
#include <libvfio.h>
+/*
+ * Minimal replacement for libuuid's uuid_parse(). libuuid is part of
+ * util-linux and is routinely absent from cross-compilation sysroots, which
+ * makes the vfio selftests unbuildable for non-native architectures. The only
+ * thing needed from it is parsing a VF token, so open-code that instead.
+ */
+#define VFIO_UUID_LEN 16
+#define VFIO_UUID_STR_LEN 36
+
+static int vfio_uuid_hexval(char c)
+{
+ if (c >= '0' && c <= '9')
+ return c - '0';
+ if (c >= 'a' && c <= 'f')
+ return c - 'a' + 10;
+ if (c >= 'A' && c <= 'F')
+ return c - 'A' + 10;
+ return -1;
+}
+
+static int vfio_uuid_parse(const char *in, unsigned char uu[VFIO_UUID_LEN])
+{
+ const char *p = in;
+ int i, hi, lo;
+
+ if (strlen(in) != VFIO_UUID_STR_LEN)
+ return -1;
+
+ for (i = 0; i < VFIO_UUID_LEN; i++) {
+ if (i == 4 || i == 6 || i == 8 || i == 10) {
+ if (*p++ != '-')
+ return -1;
+ }
+
+ hi = vfio_uuid_hexval(*p++);
+ lo = vfio_uuid_hexval(*p++);
+ if (hi < 0 || lo < 0)
+ return -1;
+
+ uu[i] = (hi << 4) | lo;
+ }
+
+ return 0;
+}
+
static void vfio_pci_irq_set(struct vfio_pci_device *device,
u32 index, u32 vector, u32 count, int *fds)
{
@@ -167,13 +210,13 @@ static void vfio_device_feature_set(int fd, u16 feature, void *data, size_t data
void vfio_device_set_vf_token(int fd, const char *vf_token)
{
- uuid_t token_uuid = {0};
+ unsigned char token_uuid[VFIO_UUID_LEN] = {0};
VFIO_ASSERT_NOT_NULL(vf_token, "vf_token is NULL");
- VFIO_ASSERT_EQ(uuid_parse(vf_token, token_uuid), 0);
+ VFIO_ASSERT_EQ(vfio_uuid_parse(vf_token, token_uuid), 0);
vfio_device_feature_set(fd, VFIO_DEVICE_FEATURE_PCI_VF_TOKEN,
- token_uuid, sizeof(uuid_t));
+ token_uuid, sizeof(token_uuid));
}
static void vfio_pci_region_get(struct vfio_pci_device *device, int index,
@@ -415,10 +458,10 @@ int __vfio_device_bind_iommufd(int device_fd, int iommufd, const char *vf_token)
.argsz = sizeof(args),
.iommufd = iommufd,
};
- uuid_t token_uuid;
+ unsigned char token_uuid[VFIO_UUID_LEN];
if (vf_token) {
- VFIO_ASSERT_EQ(uuid_parse(vf_token, token_uuid), 0);
+ VFIO_ASSERT_EQ(vfio_uuid_parse(vf_token, token_uuid), 0);
args.flags |= VFIO_DEVICE_BIND_FLAG_TOKEN;
args.token_uuid_ptr = (u64)token_uuid;
}
base-commit: 3d7783543c2646af69ad65825e810060494bea21
--
2.56.0.rc1.315.gc6ed9934b7-goog