* [PATCH] vfio: selftests: Remove libuuid dependency
@ 2026-09-25 1:30 Samiullah Khawaja
2026-09-25 20:55 ` David Matlack
0 siblings, 1 reply; 2+ messages in thread
From: Samiullah Khawaja @ 2026-09-25 1:30 UTC (permalink / raw)
To: David Matlack, Alex Williamson, Shuah Khan
Cc: Samiullah Khawaja, Raghavendra Rao Ananta, Alex Mastro,
Sean Christopherson, Rubin Du, Josh Hilke, Vipin Sharma, kvm,
linux-kselftest, linux-kernel
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@google.com>
---
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] vfio: selftests: Remove libuuid dependency
2026-09-25 1:30 [PATCH] vfio: selftests: Remove libuuid dependency Samiullah Khawaja
@ 2026-09-25 20:55 ` David Matlack
0 siblings, 0 replies; 2+ messages in thread
From: David Matlack @ 2026-09-25 20:55 UTC (permalink / raw)
To: Samiullah Khawaja
Cc: Alex Williamson, Shuah Khan, Raghavendra Rao Ananta, Alex Mastro,
Sean Christopherson, Rubin Du, Josh Hilke, Vipin Sharma, kvm,
linux-kselftest, linux-kernel, Hisam Mehboob
On 2026-09-25 01:30 AM, Samiullah Khawaja wrote:
> 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
It also complicates compiling with glibc alternatives like musl. See
https://lore.kernel.org/kvm/c2f7e904-2646-4b01-864d-d185221c7f56@gmail.com/
Please mention that as well for historical context.
> 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@google.com>
> ---
> 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])
Do we need the vfio_/VFIO_ prefixes now that we aren't linking libuuid?
> +{
> + 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;
> +}
Please move the uuid changes into lib/uuid.c and
lib/include/libvfio/uuid.h in case we want to use them elsewhere in the
future.
> +
> 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};
Any reason not to define a uuid_t?
>
> 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
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-25 20:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-25 1:30 [PATCH] vfio: selftests: Remove libuuid dependency Samiullah Khawaja
2026-09-25 20:55 ` David Matlack
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®