[PATCH v3 01/10] uapi: fix include guards in VDUSE imported header
David Marchand
david.marchand at redhat.com
Fri Sep 19 10:37:58 CEST 2025
One issue with the currently imported header is that if a header
(external to DPDK) starts including the equivalent system installed uapi
header, then when DPDK code later includes its own uapi/ header,
the header guard won't match, which may result in DPDK build failure.
To address this issue, adjust the include guards in our imported uapi
header and make sure those headers are included first before any
external header.
Update the documentation accordingly.
Fixes: cf97dfd12eaf ("uapi: import Linux kernel uAPI headers")
Fixes: 67b79f6314ae ("vhost: use imported VDUSE uAPI header")
Signed-off-by: David Marchand <david.marchand at redhat.com>
---
devtools/linux-uapi.sh | 3 +++
doc/guides/contributing/linux_uapi.rst | 6 ++++++
kernel/linux/uapi/linux/vduse.h | 6 +++---
lib/vhost/vduse.c | 4 ++--
4 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/devtools/linux-uapi.sh b/devtools/linux-uapi.sh
index c09c43ab6b..dbf3163bc8 100755
--- a/devtools/linux-uapi.sh
+++ b/devtools/linux-uapi.sh
@@ -81,6 +81,9 @@ fixup_includes()
sed -i "s|^#include <linux/compiler.h>||g" $path
sed -i "s|\<__user[[:space:]]||" $path
+ sed -i 's|#\(ifndef\)[[:space:]]*_UAPI|#\1 |' $path
+ sed -i 's|#\(define\)[[:space:]]*_UAPI|#\1 |' $path
+ sed -i 's|#\(endif[[:space:]]*/[*]\)[[:space:]]*_UAPI|#\1 |' $path
# Prepend include path with "uapi/" if the header is imported
for include in $(sed -ne 's/^#include <\(.*\)>$/\1/p' $path); do
diff --git a/doc/guides/contributing/linux_uapi.rst b/doc/guides/contributing/linux_uapi.rst
index 79bedb478e..a1bc0ba604 100644
--- a/doc/guides/contributing/linux_uapi.rst
+++ b/doc/guides/contributing/linux_uapi.rst
@@ -62,9 +62,15 @@ Header inclusion into library or driver
The library or driver willing to make use of imported uAPI headers needs to
explicitly include the header file with ``uapi/`` prefix in C files.
+
+This inclusion must be done before any header external to DPDK is included,
+to prevent inclusion of this system uAPI header in any of those external headers.
+
For example to include VDUSE uAPI:
.. code-block:: c
#include <uapi/linux/vduse.h>
+ #include <stdint.h>
+ ...
diff --git a/kernel/linux/uapi/linux/vduse.h b/kernel/linux/uapi/linux/vduse.h
index 68a627d04a..f46269af34 100644
--- a/kernel/linux/uapi/linux/vduse.h
+++ b/kernel/linux/uapi/linux/vduse.h
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */
-#ifndef _UAPI_VDUSE_H_
-#define _UAPI_VDUSE_H_
+#ifndef _VDUSE_H_
+#define _VDUSE_H_
#include <linux/types.h>
@@ -350,4 +350,4 @@ struct vduse_dev_response {
};
};
-#endif /* _UAPI_VDUSE_H_ */
+#endif /* _VDUSE_H_ */
diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c
index 9de7f04a4f..2015ae9f21 100644
--- a/lib/vhost/vduse.c
+++ b/lib/vhost/vduse.c
@@ -2,13 +2,13 @@
* Copyright (c) 2023 Red Hat, Inc.
*/
+#include <uapi/linux/vduse.h>
+
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
-
-#include <uapi/linux/vduse.h>
#include <linux/virtio_net.h>
#include <sys/ioctl.h>
--
2.51.0
More information about the dev
mailing list