mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] vfio: selftests: Remove libuuid dependency
@ 2026-11-03 22:03 Samiullah Khawaja
  2026-11-10 21:13 ` Sean Christopherson
  2026-11-26  5:49 ` Alex Williamson
  0 siblings, 2 replies; 3+ messages in thread
From: Samiullah Khawaja @ 2026-11-03 22:03 UTC (permalink / raw)
  To: Alex Williamson, David Matlack
  Cc: Shuah Khan, kvm, linux-kselftest, linux-kernel, Samiullah Khawaja

Replace libuuid with a minimal uuid_t and uuid_parse() in libvfio, and
drop -luuid from the build. libvfio only uses libuuid to parse VF
tokens, so pulling in an external library is not worth it.

libuuid is often missing from cross-compilation sysroots, which causes
the VFIO selftests to fail to link:

  ld: cannot find -luuid: No such file or directory

It also complicates building against glibc alternatives such as musl, see
https://lore.kernel.org/kvm/c2f7e904-2646-4b01-864d-d185221c7f56@gmail.com/

Reviewed-by: David Matlack <dmatlack@google.com>
Signed-off-by: Samiullah Khawaja <skhawaja@google.com>
---

v3:
- Reword the changelog and drop the testing note from it (David)
- Move the libuuid comment to uuid.h and explain how it differs from
  the kernel API (David)

v2: https://lore.kernel.org/all/20261102200624.1570562-1-skhawaja@google.com/
- Move the parser to lib/uuid.c and lib/include/libvfio/uuid.h (David)
- Drop the vfio_ prefixes and add a uuid_t (David)
- Mention musl in the commit message (David)

v1: https://lore.kernel.org/all/20260925013110.3447626-1-skhawaja@google.com/
---
 .../selftests/vfio/lib/include/libvfio.h      |  1 +
 .../selftests/vfio/lib/include/libvfio/uuid.h | 16 +++++++
 tools/testing/selftests/vfio/lib/libvfio.mk   |  3 +-
 tools/testing/selftests/vfio/lib/uuid.c       | 42 +++++++++++++++++++
 .../selftests/vfio/lib/vfio_pci_device.c      |  2 -
 5 files changed, 60 insertions(+), 4 deletions(-)
 create mode 100644 tools/testing/selftests/vfio/lib/include/libvfio/uuid.h
 create mode 100644 tools/testing/selftests/vfio/lib/uuid.c

diff --git a/tools/testing/selftests/vfio/lib/include/libvfio.h b/tools/testing/selftests/vfio/lib/include/libvfio.h
index 07862b470777..e9d513c3a08e 100644
--- a/tools/testing/selftests/vfio/lib/include/libvfio.h
+++ b/tools/testing/selftests/vfio/lib/include/libvfio.h
@@ -6,6 +6,7 @@
 #include <libvfio/iommu.h>
 #include <libvfio/iova_allocator.h>
 #include <libvfio/sysfs.h>
+#include <libvfio/uuid.h>
 #include <libvfio/vfio_pci_device.h>
 #include <libvfio/vfio_pci_driver.h>
 
diff --git a/tools/testing/selftests/vfio/lib/include/libvfio/uuid.h b/tools/testing/selftests/vfio/lib/include/libvfio/uuid.h
new file mode 100644
index 000000000000..5c4ebe5ae3d3
--- /dev/null
+++ b/tools/testing/selftests/vfio/lib/include/libvfio/uuid.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef SELFTESTS_VFIO_LIB_INCLUDE_LIBVFIO_UUID_H
+#define SELFTESTS_VFIO_LIB_INCLUDE_LIBVFIO_UUID_H
+
+/*
+ * Minimal replacement for libuuid's uuid_t and uuid_parse(). These mirror
+ * the libuuid API, not the kernel's: uuid_t is a byte array (not a struct)
+ * and uuid_parse() fills it in place (it does not take a uuid_t pointer).
+ */
+#define UUID_SIZE	16
+
+typedef unsigned char uuid_t[UUID_SIZE];
+
+int uuid_parse(const char *in, uuid_t uu);
+
+#endif /* SELFTESTS_VFIO_LIB_INCLUDE_LIBVFIO_UUID_H */
diff --git a/tools/testing/selftests/vfio/lib/libvfio.mk b/tools/testing/selftests/vfio/lib/libvfio.mk
index eff95828719e..d1d1b2b05af1 100644
--- a/tools/testing/selftests/vfio/lib/libvfio.mk
+++ b/tools/testing/selftests/vfio/lib/libvfio.mk
@@ -7,6 +7,7 @@ LIBVFIO_C := iommu.c
 LIBVFIO_C += iova_allocator.c
 LIBVFIO_C += libvfio.c
 LIBVFIO_C += sysfs.c
+LIBVFIO_C += uuid.c
 LIBVFIO_C += vfio_pci_device.c
 LIBVFIO_C += vfio_pci_driver.c
 
@@ -30,8 +31,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/uuid.c b/tools/testing/selftests/vfio/lib/uuid.c
new file mode 100644
index 000000000000..906a5db70ce1
--- /dev/null
+++ b/tools/testing/selftests/vfio/lib/uuid.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <string.h>
+
+#include <libvfio.h>
+
+#define UUID_STRING_LEN	36
+
+static int 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;
+}
+
+int uuid_parse(const char *in, uuid_t uu)
+{
+	const char *p = in;
+	int i, hi, lo;
+
+	if (strlen(in) != UUID_STRING_LEN)
+		return -1;
+
+	for (i = 0; i < UUID_SIZE; i++) {
+		if (i == 4 || i == 6 || i == 8 || i == 10) {
+			if (*p++ != '-')
+				return -1;
+		}
+
+		hi = hexval(*p++);
+		lo = hexval(*p++);
+		if (hi < 0 || lo < 0)
+			return -1;
+
+		uu[i] = (hi << 4) | lo;
+	}
+
+	return 0;
+}
diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
index 4063a0e2b3df..4ae6ac1f8ed8 100644
--- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c
+++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
@@ -23,8 +23,6 @@
 #include <linux/types.h>
 #include <linux/vfio.h>
 
-#include <uuid/uuid.h>
-
 #include "kselftest.h"
 #include <libvfio.h>
 

base-commit: 2637bdec0535a2044cd830eba9a79363651d9043
-- 
2.56.0.385.gac671c819a-goog


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] vfio: selftests: Remove libuuid dependency
  2026-11-03 22:03 [PATCH v3] vfio: selftests: Remove libuuid dependency Samiullah Khawaja
@ 2026-11-10 21:13 ` Sean Christopherson
  2026-11-26  5:49 ` Alex Williamson
  1 sibling, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2026-11-10 21:13 UTC (permalink / raw)
  To: Samiullah Khawaja
  Cc: Alex Williamson, David Matlack, Shuah Khan, kvm, linux-kselftest,
	linux-kernel

On Tue, Nov 03, 2026, Samiullah Khawaja wrote:
> Replace libuuid with a minimal uuid_t and uuid_parse() in libvfio, and
> drop -luuid from the build. libvfio only uses libuuid to parse VF
> tokens, so pulling in an external library is not worth it.
> 
> libuuid is often missing from cross-compilation sysroots, which causes
> the VFIO selftests to fail to link:
> 
>   ld: cannot find -luuid: No such file or directory
> 
> It also complicates building against glibc alternatives such as musl, see
> https://lore.kernel.org/kvm/c2f7e904-2646-4b01-864d-d185221c7f56@gmail.com/
> 
> Reviewed-by: David Matlack <dmatlack@google.com>
> Signed-off-by: Samiullah Khawaja <skhawaja@google.com>
> ---

Tested-by: Sean Christopherson <seanjc@google.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] vfio: selftests: Remove libuuid dependency
  2026-11-03 22:03 [PATCH v3] vfio: selftests: Remove libuuid dependency Samiullah Khawaja
  2026-11-10 21:13 ` Sean Christopherson
@ 2026-11-26  5:49 ` Alex Williamson
  1 sibling, 0 replies; 3+ messages in thread
From: Alex Williamson @ 2026-11-26  5:49 UTC (permalink / raw)
  To: Samiullah Khawaja
  Cc: David Matlack, Shuah Khan, kvm, linux-kselftest, linux-kernel, alex

On Tue,  3 Nov 2026 22:03:37 +0000
Samiullah Khawaja <skhawaja@google.com> wrote:

> Replace libuuid with a minimal uuid_t and uuid_parse() in libvfio, and
> drop -luuid from the build. libvfio only uses libuuid to parse VF
> tokens, so pulling in an external library is not worth it.
> 
> libuuid is often missing from cross-compilation sysroots, which causes
> the VFIO selftests to fail to link:
> 
>   ld: cannot find -luuid: No such file or directory
> 
> It also complicates building against glibc alternatives such as musl, see
> https://lore.kernel.org/kvm/c2f7e904-2646-4b01-864d-d185221c7f56@gmail.com/
> 
> Reviewed-by: David Matlack <dmatlack@google.com>
> Signed-off-by: Samiullah Khawaja <skhawaja@google.com>
> ---
> 
> v3:

Applied to vfio next branch for v7.5.  Thanks,

Alex


> - Reword the changelog and drop the testing note from it (David)
> - Move the libuuid comment to uuid.h and explain how it differs from
>   the kernel API (David)
> 
> v2: https://lore.kernel.org/all/20261102200624.1570562-1-skhawaja@google.com/
> - Move the parser to lib/uuid.c and lib/include/libvfio/uuid.h (David)
> - Drop the vfio_ prefixes and add a uuid_t (David)
> - Mention musl in the commit message (David)
> 
> v1: https://lore.kernel.org/all/20260925013110.3447626-1-skhawaja@google.com/
> ---
>  .../selftests/vfio/lib/include/libvfio.h      |  1 +
>  .../selftests/vfio/lib/include/libvfio/uuid.h | 16 +++++++
>  tools/testing/selftests/vfio/lib/libvfio.mk   |  3 +-
>  tools/testing/selftests/vfio/lib/uuid.c       | 42 +++++++++++++++++++
>  .../selftests/vfio/lib/vfio_pci_device.c      |  2 -
>  5 files changed, 60 insertions(+), 4 deletions(-)
>  create mode 100644 tools/testing/selftests/vfio/lib/include/libvfio/uuid.h
>  create mode 100644 tools/testing/selftests/vfio/lib/uuid.c
> 
> diff --git a/tools/testing/selftests/vfio/lib/include/libvfio.h b/tools/testing/selftests/vfio/lib/include/libvfio.h
> index 07862b470777..e9d513c3a08e 100644
> --- a/tools/testing/selftests/vfio/lib/include/libvfio.h
> +++ b/tools/testing/selftests/vfio/lib/include/libvfio.h
> @@ -6,6 +6,7 @@
>  #include <libvfio/iommu.h>
>  #include <libvfio/iova_allocator.h>
>  #include <libvfio/sysfs.h>
> +#include <libvfio/uuid.h>
>  #include <libvfio/vfio_pci_device.h>
>  #include <libvfio/vfio_pci_driver.h>
>  
> diff --git a/tools/testing/selftests/vfio/lib/include/libvfio/uuid.h b/tools/testing/selftests/vfio/lib/include/libvfio/uuid.h
> new file mode 100644
> index 000000000000..5c4ebe5ae3d3
> --- /dev/null
> +++ b/tools/testing/selftests/vfio/lib/include/libvfio/uuid.h
> @@ -0,0 +1,16 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +#ifndef SELFTESTS_VFIO_LIB_INCLUDE_LIBVFIO_UUID_H
> +#define SELFTESTS_VFIO_LIB_INCLUDE_LIBVFIO_UUID_H
> +
> +/*
> + * Minimal replacement for libuuid's uuid_t and uuid_parse(). These mirror
> + * the libuuid API, not the kernel's: uuid_t is a byte array (not a struct)
> + * and uuid_parse() fills it in place (it does not take a uuid_t pointer).
> + */
> +#define UUID_SIZE	16
> +
> +typedef unsigned char uuid_t[UUID_SIZE];
> +
> +int uuid_parse(const char *in, uuid_t uu);
> +
> +#endif /* SELFTESTS_VFIO_LIB_INCLUDE_LIBVFIO_UUID_H */
> diff --git a/tools/testing/selftests/vfio/lib/libvfio.mk b/tools/testing/selftests/vfio/lib/libvfio.mk
> index eff95828719e..d1d1b2b05af1 100644
> --- a/tools/testing/selftests/vfio/lib/libvfio.mk
> +++ b/tools/testing/selftests/vfio/lib/libvfio.mk
> @@ -7,6 +7,7 @@ LIBVFIO_C := iommu.c
>  LIBVFIO_C += iova_allocator.c
>  LIBVFIO_C += libvfio.c
>  LIBVFIO_C += sysfs.c
> +LIBVFIO_C += uuid.c
>  LIBVFIO_C += vfio_pci_device.c
>  LIBVFIO_C += vfio_pci_driver.c
>  
> @@ -30,8 +31,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/uuid.c b/tools/testing/selftests/vfio/lib/uuid.c
> new file mode 100644
> index 000000000000..906a5db70ce1
> --- /dev/null
> +++ b/tools/testing/selftests/vfio/lib/uuid.c
> @@ -0,0 +1,42 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +#include <string.h>
> +
> +#include <libvfio.h>
> +
> +#define UUID_STRING_LEN	36
> +
> +static int 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;
> +}
> +
> +int uuid_parse(const char *in, uuid_t uu)
> +{
> +	const char *p = in;
> +	int i, hi, lo;
> +
> +	if (strlen(in) != UUID_STRING_LEN)
> +		return -1;
> +
> +	for (i = 0; i < UUID_SIZE; i++) {
> +		if (i == 4 || i == 6 || i == 8 || i == 10) {
> +			if (*p++ != '-')
> +				return -1;
> +		}
> +
> +		hi = hexval(*p++);
> +		lo = hexval(*p++);
> +		if (hi < 0 || lo < 0)
> +			return -1;
> +
> +		uu[i] = (hi << 4) | lo;
> +	}
> +
> +	return 0;
> +}
> diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> index 4063a0e2b3df..4ae6ac1f8ed8 100644
> --- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> +++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
> @@ -23,8 +23,6 @@
>  #include <linux/types.h>
>  #include <linux/vfio.h>
>  
> -#include <uuid/uuid.h>
> -
>  #include "kselftest.h"
>  #include <libvfio.h>
>  
> 
> base-commit: 2637bdec0535a2044cd830eba9a79363651d9043


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-26  5:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03 22:03 [PATCH v3] vfio: selftests: Remove libuuid dependency Samiullah Khawaja
2026-11-10 21:13 ` Sean Christopherson
2026-11-26  5:49 ` Alex Williamson

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®