On Wed, 30 Sept 2026 at 17:37, Maxime Coquelin
<[email protected]> wrote:
> On Wed, Sep 30, 2026 at 5:26 PM Stephen Hemminger
> <[email protected]> wrote:
>>
>> On Wed, 30 Sep 2026 11:57:59 +0200
>> Maxime Coquelin <[email protected]> wrote:
>>
>> > This patch adds a compatibility define for __counted_by attribute,
>> > which is not present in older compilers but required for recent UAPI
>> > headers like vfio.h.
>> >
>> > Signed-off-by: Maxime Coquelin <[email protected]>
>> > ---
>> > config/rte_config.h | 9 +++++++++
>> > 1 file changed, 9 insertions(+)
>> >
>> > diff --git a/config/rte_config.h b/config/rte_config.h
>> > index 0447cdf2ad..307e7dac62 100644
>> > --- a/config/rte_config.h
>> > +++ b/config/rte_config.h
>> > @@ -25,6 +25,15 @@
>> > #define RTE_TOOLCHAIN_MSVC 1
>> > #endif
>> >
>> > +/*
>> > + * Compatibility define for Linux kernel UAPI headers that may use
>> > __counted_by
>> > + * attribute for bounds checking. This attribute is not understood by
>> > userspace
>> > + * compilers, so define it as empty if not already provided.
>> > + */
>> > +#ifndef __counted_by
>> > +#define __counted_by(m)
>> > +#endif
>> > +
>> > /* legacy defines */
>> > #ifdef RTE_EXEC_ENV_LINUX
>> > #define RTE_EXEC_ENV_LINUXAPP 1
>>
>> NAK this is best done by keeping up to date stddef over in virtio headers.
>
> This is for VFIO, not Virtio but that does not change the issue.
>
> Problem is importing stddef in UAPI as currently done, does not work,
> because the system version is included first so the imported one is discarded.
>
> An alternative solution I tested would be to include the imported headers
> first,
> but it means imported headers get silently intermixed, which worked in my test
> but could lead to hard to debug issues.
I don't like the alternative, for the reason you listed, plus the fact
that this intermixing is invisible.
At the moment, using an imported uapi header is opt-in, and I prefer
it like this.
> While not ideal, the solution proposed in this patch is harmless, we are
> talking
> about an attribute defined as empty.
Your solution of wrapping __counted_by is simple.
On the other hand, fixing the existing import script would require
relying on an external tool (unifef), which could be acceptable.
I tried some:
diff --git a/devtools/linux-uapi.sh b/devtools/linux-uapi.sh
index dbf3163bc8..189164928c 100755
--- a/devtools/linux-uapi.sh
+++ b/devtools/linux-uapi.sh
@@ -13,6 +13,9 @@ file=""
check_headers=false
quiet=false
+# Require unifdef
+unifdef -h 2>&1 >/dev/null || { echo "This script requires unifdef."; exit 1; }
+
print_usage()
{
echo "Usage: $(basename $0) [-h] [-i FILE] [-u VERSION] [-c] [-q]"
@@ -85,6 +88,9 @@ fixup_includes()
sed -i 's|#\(define\)[[:space:]]*_UAPI|#\1 |' $path
sed -i 's|#\(endif[[:space:]]*/[*]\)[[:space:]]*_UAPI|#\1 |' $path
+ unifdef -U__KERNEL__ -D__EXPORTED_HEADERS__ -o ${path}.tmp
$path || [ $? -lt 2 ]
+ mv -f ${path}.tmp $path
+
# Prepend include path with "uapi/" if the header is imported
for include in $(sed -ne 's/^#include <\(.*\)>$/\1/p' $path); do
if [ -f "$base_path$include" ]; then
diff --git a/doc/guides/contributing/linux_uapi.rst
b/doc/guides/contributing/linux_uapi.rst
index b8febfc420..a3490bfbb6 100644
--- a/doc/guides/contributing/linux_uapi.rst
+++ b/doc/guides/contributing/linux_uapi.rst
@@ -27,6 +27,8 @@ Importing or updating an uAPI header file
To ensure that imported uAPI headers are unmodified
and sourced from an official Linux kernel release,
a helper script is provided and must be used.
+This script requires the ``unifdef`` tool.
+
Below is an example to import ``linux/vduse.h`` file from Linux ``v6.10``:
.. code-block:: console
Then imported linux/types.h, linux/posix_types.h and linux/stddef.h.
And net/nbl needs some fixing... as it includes uapi/linux/vfio.h too late...
Only occurence in the whole DPDK tree:
$ git grep -l '# *include.*uapi' :^devtools/linux-uapi.sh
:^doc/guides/contributing/linux_uapi.rst | while read file; do [ $(git
grep -B100 '# *include.*uapi' $file | grep '# *include' | wc -l) = 1 ]
|| echo $file; done
drivers/net/nbl/nbl_common/nbl_userdev.c
--
David Marchand