Skip to contentSkip to conversation

close uapi header copies w.r.t. include

PATCH New Michal Kubecek 1 participant 4 messages Apr 18, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover close uapi header copies w.r.t. include

On multiple occasion, build on older systems with system <linux/...> headers missing definitions or later changes failed which we either worked around by adding conditional defines or fixed by adding a sanitized copy of such header to uapi/ directory.

To prevent these problems, add sanitized copies of all uapi headers that we include from any source file or from an already present uapi header copy (and repeat the process recursively). For this purpose, add the update scripts to the repository, update it to add missing files automatically and run the update.

Michal Kubecek (3):
scripts: add ethtool-import-uapi
scripts: add all included uapi files on update
update UAPI header copies

 scripts/ethtool-import-uapi |  67 +++++++++
 uapi/linux/const.h          |  36 +++++
 uapi/linux/if_addr.h        |  77 +++++++++++
 uapi/linux/if_ether.h       | 181 ++++++++++++++++++++++++
 uapi/linux/libc-compat.h    | 267 ++++++++++++++++++++++++++++++++++++
 uapi/linux/neighbour.h      | 224 ++++++++++++++++++++++++++++++
 uapi/linux/posix_types.h    |  38 +++++
 uapi/linux/rtnetlink.h      |   1 +
 uapi/linux/socket.h         |  38 +++++
 uapi/linux/stddef.h         |  47 +++++++
 uapi/linux/types.h          |  53 +++++++
 11 files changed, 1029 insertions(+)
 create mode 100755 scripts/ethtool-import-uapi
 create mode 100644 uapi/linux/const.h
 create mode 100644 uapi/linux/if_addr.h
 create mode 100644 uapi/linux/if_ether.h
 create mode 100644 uapi/linux/libc-compat.h
 create mode 100644 uapi/linux/neighbour.h
 create mode 100644 uapi/linux/posix_types.h
 create mode 100644 uapi/linux/socket.h
 create mode 100644 uapi/linux/stddef.h
 create mode 100644 uapi/linux/types.h
Signature · 1 line
2.40.0
#1 lore raw

PATCH 1/3 scripts: add ethtool-import-uapi

Add script to update sanitized uapi header copies. This script has been available on kernel.org ethtool web for some time, adding it into the repository is going to make it more at hand and will allow tracking its history publicly.

---
 scripts/ethtool-import-uapi | 41 +++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100755 scripts/ethtool-import-uapi
scripts/ethtool-import-uapi new file +41 -0
new file mode 100755
index 000000000000..8e48332cfcc8
@@ -0,0 +1,41 @@
+#!/bin/bash -e
+#
+# ethtool-import-uapi [commit]
+#
+# Imports sanitized copies of kernel uapi headers from <commit> (can be
+# a commit id, a tag or a branch name). If the argument is omitted,
+# commit currently checked out in the kernel repository is used.
+
+sn="${0##*/}"
+export ARCH="x86_64"
+mkopt="-j$(nproc)" || mkopt=''
+
+if [ ! -d "$LINUX_GIT" ]; then
+    echo "${sn}: please set LINUX_GIT to the location of kernel git" >&2
+    exit 1
+fi
+
+pushd "$LINUX_GIT"
+if [ -n "$1" ]; then
+    git checkout "$1"
+fi
+desc=$(git describe --exact-match 2>/dev/null \
+       || git show -s --abbrev=12 --pretty='commit %h')
+kobj=$(mktemp -d)
+make $mkopt O="$kobj" allmodconfig
+make $mkopt O="$kobj" prepare
+make $mkopt O="$kobj" INSTALL_HDR_PATH="${kobj}/hdr" headers_install
+popd
+
+pushd uapi
+find . -type f -name '*.h' -exec cp -v "${kobj}/hdr/include/{}" {} \;
+popd
+rm -rf "$kobj"
+
+git add uapi
+git commit -s -F - <<EOT
+update UAPI header copies
+
+Update to kernel ${desc}.
+
+EOT
Signature · 1 line
2.40.0
#2 lore raw

PATCH 2/3 scripts: add all included uapi files on update

In reply to Michal Kubecek

On multiple occasions, we had to add another uapi header copy to fix build on older system where system <linux/...> headers in /usr/include lacked recent definitions or changes. To prevent these problems, update the ethtool-import-uapi script to add all uapi headers included either from a source file or from already copied uapi header which are not present yet.

Omit <asm/...> headers as those are architecture dependent so that we cannot pick one random version depending on architecture a developer runs the script on and having all versions and selecting the right one would be too complicated.

---
 scripts/ethtool-import-uapi | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
scripts/ethtool-import-uapi +26 -0
index 8e48332cfcc8..a04a9c971a01 100755
@@ -29,6 +29,32 @@ popd
 
 pushd uapi
 find . -type f -name '*.h' -exec cp -v "${kobj}/hdr/include/{}" {} \;
+
+go_on=true
+while $go_on; do
+    go_on=false
+    while read f; do
+        if [ "${f#asm/}" != "$f" ]; then
+            # skip architecture dependent asm/ headers
+            continue
+        fi
+        if [ -f "$f" ]; then
+            # already present
+            continue
+        fi
+	if [ ! -f "${kobj}/hdr/include/${f}" ]; then
+            # not a kernel header
+            continue
+        fi
+        echo "+ add $f"
+        go_on=true
+        mkdir -p "${f%/*}"
+        cp "${kobj}/hdr/include/${f}" "${f}"
+    done < <(
+        find . -type f -name '*.[ch]' -exec sed -nre '\_^[[:blank:]]*#include[[:blank:]]<.+>_ { s_^[[:blank:]]*#include[[:blank:]]<([^>]*)>.*$_\1_ ; p }' {} \; \
+            | LC_ALL=C sort -u
+    )
+done
 popd
 rm -rf "$kobj"
 
Signature · 1 line
2.40.0
#3 lore raw

PATCH 3/3 update UAPI header copies

In reply to Michal Kubecek

Update to kernel v6.3-rc7.

---
 uapi/linux/const.h       |  36 ++++++
 uapi/linux/if_addr.h     |  77 +++++++++++
 uapi/linux/if_ether.h    | 181 ++++++++++++++++++++++++++
 uapi/linux/libc-compat.h | 267 +++++++++++++++++++++++++++++++++++++++
 uapi/linux/neighbour.h   | 224 ++++++++++++++++++++++++++++++++
 uapi/linux/posix_types.h |  38 ++++++
 uapi/linux/rtnetlink.h   |   1 +
 uapi/linux/socket.h      |  38 ++++++
 uapi/linux/stddef.h      |  47 +++++++
 uapi/linux/types.h       |  53 ++++++++
 10 files changed, 962 insertions(+)
 create mode 100644 uapi/linux/const.h
 create mode 100644 uapi/linux/if_addr.h
 create mode 100644 uapi/linux/if_ether.h
 create mode 100644 uapi/linux/libc-compat.h
 create mode 100644 uapi/linux/neighbour.h
 create mode 100644 uapi/linux/posix_types.h
 create mode 100644 uapi/linux/socket.h
 create mode 100644 uapi/linux/stddef.h
 create mode 100644 uapi/linux/types.h
uapi/linux/const.h new file +36 -0
new file mode 100644
index 000000000000..5e4898725168
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/* const.h: Macros for dealing with constants.  */
+
+#ifndef _LINUX_CONST_H
+#define _LINUX_CONST_H
+
+/* Some constant macros are used in both assembler and
+ * C code.  Therefore we cannot annotate them always with
+ * 'UL' and other type specifiers unilaterally.  We
+ * use the following macros to deal with this.
+ *
+ * Similarly, _AT() will cast an expression with a type in C, but
+ * leave it unchanged in asm.
+ */
+
+#ifdef __ASSEMBLY__
+#define _AC(X,Y)	X
+#define _AT(T,X)	X
+#else
+#define __AC(X,Y)	(X##Y)
+#define _AC(X,Y)	__AC(X,Y)
+#define _AT(T,X)	((T)(X))
+#endif
+
+#define _UL(x)		(_AC(x, UL))
+#define _ULL(x)		(_AC(x, ULL))
+
+#define _BITUL(x)	(_UL(1) << (x))
+#define _BITULL(x)	(_ULL(1) << (x))
+
+#define __ALIGN_KERNEL(x, a)		__ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1)
+#define __ALIGN_KERNEL_MASK(x, mask)	(((x) + (mask)) & ~(mask))
+
+#define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
+
+#endif /* _LINUX_CONST_H */
uapi/linux/if_addr.h new file +77 -0

77 lines not on this page · raw message

uapi/linux/if_ether.h new file +181 -0

181 lines not on this page · raw message

uapi/linux/libc-compat.h new file +267 -0

267 lines not on this page · raw message

uapi/linux/neighbour.h new file +224 -0

224 lines not on this page · raw message

uapi/linux/posix_types.h new file +38 -0
new file mode 100644
index 000000000000..9a7a740b35a2
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _LINUX_POSIX_TYPES_H
+#define _LINUX_POSIX_TYPES_H
+
+#include <linux/stddef.h>
+
+/*
+ * This allows for 1024 file descriptors: if NR_OPEN is ever grown
+ * beyond that you'll have to change this too. But 1024 fd's seem to be
+ * enough even for such "real" unices like OSF/1, so hopefully this is
+ * one limit that doesn't have to be changed [again].
+ *
+ * Note that POSIX wants the FD_CLEAR(fd,fdsetp) defines to be in
+ * <sys/time.h> (and thus <linux/time.h>) - but this is a more logical
+ * place for them. Solved by having dummy defines in <sys/time.h>.
+ */
+
+/*
+ * This macro may have been defined in <gnu/types.h>. But we always
+ * use the one here.
+ */
+#undef __FD_SETSIZE
+#define __FD_SETSIZE	1024
+
+typedef struct {
+	unsigned long fds_bits[__FD_SETSIZE / (8 * sizeof(long))];
+} __kernel_fd_set;
+
+/* Type of a signal handler.  */
+typedef void (*__kernel_sighandler_t)(int);
+
+/* Type of a SYSV IPC key.  */
+typedef int __kernel_key_t;
+typedef int __kernel_mqd_t;
+
+#include <asm/posix_types.h>
+
+#endif /* _LINUX_POSIX_TYPES_H */
uapi/linux/rtnetlink.h +1 -0
index 217b25b963f5..2132e941b93a 100644
@@ -787,6 +787,7 @@ enum {
 	TCA_ROOT_FLAGS,
 	TCA_ROOT_COUNT,
 	TCA_ROOT_TIME_DELTA, /* in msecs */
+	TCA_ROOT_EXT_WARN_MSG,
 	__TCA_ROOT_MAX,
 #define	TCA_ROOT_MAX (__TCA_ROOT_MAX - 1)
 };
uapi/linux/socket.h new file +38 -0
new file mode 100644
index 000000000000..89c227f3d4cd
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _LINUX_SOCKET_H
+#define _LINUX_SOCKET_H
+
+/*
+ * Desired design of maximum size and alignment (see RFC2553)
+ */
+#define _K_SS_MAXSIZE	128	/* Implementation specific max size */
+
+typedef unsigned short __kernel_sa_family_t;
+
+/*
+ * The definition uses anonymous union and struct in order to control the
+ * default alignment.
+ */
+struct __kernel_sockaddr_storage {
+	union {
+		struct {
+			__kernel_sa_family_t	ss_family; /* address family */
+			/* Following field(s) are implementation specific */
+			char __data[_K_SS_MAXSIZE - sizeof(unsigned short)];
+				/* space to achieve desired size, */
+				/* _SS_MAXSIZE value minus size of ss_family */
+		};
+		void *__align; /* implementation specific desired alignment */
+	};
+};
+
+#define SOCK_SNDBUF_LOCK	1
+#define SOCK_RCVBUF_LOCK	2
+
+#define SOCK_BUF_LOCK_MASK (SOCK_SNDBUF_LOCK | SOCK_RCVBUF_LOCK)
+
+#define SOCK_TXREHASH_DEFAULT	255
+#define SOCK_TXREHASH_DISABLED	0
+#define SOCK_TXREHASH_ENABLED	1
+
+#endif /* _LINUX_SOCKET_H */
uapi/linux/stddef.h new file +47 -0

47 lines not on this page · raw message

uapi/linux/types.h new file +53 -0

53 lines not on this page · raw message

Signature · 1 line
2.40.0