From: Samiullah Khawaja <skhawaja@google.com>
To: David Matlack <dmatlack@google.com>,
Alex Williamson <alex@shazbot.org>, Shuah Khan <shuah@kernel.org>
Cc: Samiullah Khawaja <skhawaja@google.com>,
Raghavendra Rao Ananta <rananta@google.com>,
Alex Mastro <amastro@fb.com>,
Sean Christopherson <seanjc@google.com>,
Rubin Du <rubind@nvidia.com>, Josh Hilke <jrhilke@google.com>,
Vipin Sharma <vipinsh@google.com>,
kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] vfio: selftests: Remove libuuid dependency
Date: Fri, 25 Sep 2026 01:30:55 +0000 [thread overview]
Message-ID: <20260925013110.3447626-1-skhawaja@google.com> (raw)
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
next reply other threads:[~2026-09-25 1:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 1:30 Samiullah Khawaja [this message]
2026-09-25 20:55 ` David Matlack
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260925013110.3447626-1-skhawaja@google.com \
--to=skhawaja@google.com \
--cc=alex@shazbot.org \
--cc=amastro@fb.com \
--cc=dmatlack@google.com \
--cc=jrhilke@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=rananta@google.com \
--cc=rubind@nvidia.com \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=vipinsh@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®