From: Mikko Rapeli <hidden> Date: 2017-08-06 17:08:39
v6:
Addressed v5 review comments.
Dropped patches already applied from other developers for same problems:
thanks Christoph Hellwig, Nicolas Dichtel, Arnd Bergmann, Dmitry V. Levin,
Leon Romanovsky, David Lebrun, Jason Gunthorpe, Jonas Gorski, Stephen
Hemminger, Davide Caratti and others!
Moved glibc compatibility fix to a separate patch set to focus on these.
Minor tuning to scripts/headers_compile_test.sh.
Since several patches are not getting any review comments from lkml or from
people and lists added by scripts/get_maintainer.pl, added manually crafted
Cc:'s to the patches.
v5:
https://lkml.org/lkml/2016/8/22/661
two years now from v1 to v5 though some of the patches have been applied
with these changes all uapi headers compile stand alone in users space
added myself to MAINTAINERS for the test script
tried to fix all v04 review findings
due to regression in one of the accepted patches, added a glibc compatibility test
fixed some glibc compatibility issues, which are hopefully on the right path
v4:
https://lkml.org/lkml/2015/10/15/22
tried to fix v03 review findings
tried to fix all hack patches
v3:
https://lkml.org/lkml/2015/5/30/96
tried to fix all v2 review findings
tried to guess how to fix a few more issue
with a few hacks, 0 files fail and 760 files pass the compile test on 32bit x86
v2:
https://lkml.org/lkml/2015/2/16/521
added cross compiler support with CROSS_COMPILE,
detecting libc and GCC headers from compiler,
more header file fixes
v1:
https://lkml.org/lkml/2014/8/21/665
Users of kernel header files would be happier if they did not contain
kernel specific parts and would contain #include statements for all
other header files that they depend on, and in general would compile.
This patch set introduces a compile test for headers exported to userspace
and then fixes all 42 of the remaining userspace header compilation
failures. Some of the fixes may change include order and thus may expose
incompatibilities between kernel and libc and other userspace library
headers which include incompatible copies of kernel uapi header definitions.
Changes are also available in headers_test_v06 branch at github:
https://github.com/mcfrisk/linux/tree/headers_test_v06
Here's how to run the userspace compile tests and example output with these
patches applied on top of v4.13-rc3-216-g0a23ea65ce9f:
$ make headers_install
$ cd usr/include
$ ../../scripts/headers_compile_test.sh
...
Kernel header compile test statistics:
0 files failed the kernel header compile test.
863 files passed the kernel header compile test.
Compile tested with the test itself on 32bit x86 and armhf and
with allmodconfig on x86 i586.
Would be nice when various Linux kernel subsystem maintainers would
pick and apply patches from this series to their queues, and comment
if there are problems with any of them.
Mikko Rapeli (36):
Add scripts/headers_compile_test.sh: compile test for exported uapi
headers
uapi scsi/scsi_bsg_fc.h: use __u8, __u32 and __u64 from linux/types.h
uapi scsi/scsi_netlink.h: use __u8, __u16 and __u64 from linux/types.h
uapi scsi/scsi_netlink_fc.h: use __u16, __u32 and __u64 from
linux/types.h
uapi linux/sysctl.h: use __kernel_size_t instead of size_t
uapi asm-generic/ipcbuf.h: include linux/posix_types.h
uapi asm-generic/msgbuf.h: include asm/ipcbuf.h
uapi asm-generic/shmbuf.h: include fixes
uapi asm-generic/sembuf.h: include asm/posix_types.h and asm/ipcbuf.h
uapi asm-generic/signal.h: use __kernel_size_t instead of size_t
uapi asm-generic/ucontext.h: include asm/signal.h and asm/sigcontext.h
x86 uapi asm/signal.h: use __kernel_size_t instead of size_t
x86 uapi asm/sembuf.h: include linux/types.h and linux/ipc.h
arm uapi asm/signal.h: include <stddef.h> for size_t in userspace
uapi linux/socket.h: include sys/socket.h in user space
uapi linux/dlm_netlink.h: include linux/dlmconstants.h
uapi linux/sctp.h: use __u8, __u16 and __u32 from linux/types.h
uapi linux/errqueue.h: include linux/time.h in user space
uapi linux/omapfb.h: use __kernel_size_t instead of size_t
uapi linux/scc.h: include linux/sockios.h
uapi linux/kexec.h: use __kernel_size_t instead of size_t
uapi linux/reiserfs_xattr.h: use __kernel_size_t instead of size_t
uapi linux/coda.h: use __kernel_pid_t and add u_short etc definitions
for userspace
uapi linux/coda_psdev.h: move upc_req definition from uapi to kernel
side headers
uapi linux/android/binder.h: use __kernel_pid_t and __kernel_uid_t
uapi xen/privcmd.h: fix compilation in userspace
uapi xen/gntdev.h: include xen/privcmd.h and define grant_ref_t
uapi xen/evtchn.h: include xen/privcmd.h
uapi linux/elfcore.h: remove non-compiling userspace parts
uapi rdma/rdma_user_rxe.h: include in.h and in6.h
uapi linux/patchkey.h: change #error to #warning if file included
directly
uapi drm/armada_drm.h: use __u32 and __u64 instead of uint32_t and
uint64_t
uapi linux/fsmap.h: use __kernel_size_t instead of size_t
uapi: break dependency loop between <linux/hdlc/ioctl.h> and
<linux/if.h>
uapi linux/tls.h: don't include <net/tcp.h> in user space
uapi linux/kfd_ioctl.h: use __u32 and __u64 instead of uint32_t and
uint64_t
MAINTAINERS | 5 +
arch/arm/include/uapi/asm/signal.h | 2 +
arch/x86/include/uapi/asm/sembuf.h | 3 +
arch/x86/include/uapi/asm/signal.h | 2 +-
include/linux/coda_psdev.h | 11 +
include/uapi/asm-generic/ipcbuf.h | 2 +
include/uapi/asm-generic/msgbuf.h | 2 +
include/uapi/asm-generic/sembuf.h | 2 +
include/uapi/asm-generic/shmbuf.h | 4 +-
include/uapi/asm-generic/signal.h | 2 +-
include/uapi/asm-generic/ucontext.h | 3 +
include/uapi/drm/armada_drm.h | 22 +-
include/uapi/linux/android/binder.h | 4 +-
include/uapi/linux/coda.h | 11 +-
include/uapi/linux/coda_psdev.h | 13 -
include/uapi/linux/dlm_netlink.h | 1 +
include/uapi/linux/elfcore.h | 21 +-
include/uapi/linux/errqueue.h | 6 +
include/uapi/linux/fsmap.h | 2 +-
include/uapi/linux/hdlc/ioctl.h | 17 +-
include/uapi/linux/if.h | 23 +-
include/uapi/linux/kexec.h | 4 +-
include/uapi/linux/kfd_ioctl.h | 172 ++++++------
include/uapi/linux/omapfb.h | 2 +-
include/uapi/linux/patchkey.h | 2 +-
include/uapi/linux/reiserfs_xattr.h | 2 +-
include/uapi/linux/scc.h | 1 +
include/uapi/linux/sctp.h | 20 +-
include/uapi/linux/socket.h | 4 +
include/uapi/linux/sysctl.h | 4 +-
include/uapi/linux/tls.h | 2 +
include/uapi/rdma/rdma_user_rxe.h | 2 +
include/uapi/scsi/scsi_bsg_fc.h | 54 ++--
include/uapi/scsi/scsi_netlink.h | 22 +-
include/uapi/scsi/scsi_netlink_fc.h | 16 +-
include/uapi/xen/evtchn.h | 2 +
include/uapi/xen/gntdev.h | 6 +
include/uapi/xen/privcmd.h | 14 +-
include/xen/interface/grant_table.h | 6 +-
scripts/headers_compile_test.sh | 507 ++++++++++++++++++++++++++++++++++++
40 files changed, 784 insertions(+), 216 deletions(-)
create mode 100755 scripts/headers_compile_test.sh
--
2.13.3
You should be extremely careful when replacing size_t with __kernel_size_t
because e.g. on x32 you have sizeof(size_t) < sizeof(__kernel_size_t).
In case of sysctl.h this replacement would be wrong.
I submitted an alternative fix for this bug some time ago, see
http://lkml.kernel.org/r/20170222230652.GA14373-u2l5PoMzF/Vg9hUCZPvPmw@public.gmane.org
--
ldv
From: Mikko Rapeli <hidden> Date: 2017-08-06 17:06:27
It is not needed and not part of uapi headers, but causes
user space compilation error:
fatal error: net/tcp.h: No such file or directory
#include <net/tcp.h>
^
Signed-off-by: Mikko Rapeli <redacted>
Cc: Dave Watson <redacted>
Cc: Ilya Lesokhin <redacted>
Cc: Aviad Yehezkel <redacted>
---
include/uapi/linux/tls.h | 2 ++
1 file changed, 2 insertions(+)
From: Dmitry V. Levin <hidden> Date: 2017-08-08 23:25:57
On Sun, Aug 06, 2017 at 06:44:26PM +0200, Mikko Rapeli wrote:
quoted hunk
It is not needed and not part of uapi headers, but causes
user space compilation error:
fatal error: net/tcp.h: No such file or directory
#include <net/tcp.h>
^
Signed-off-by: Mikko Rapeli <redacted>
Cc: Dave Watson <redacted>
Cc: Ilya Lesokhin <redacted>
Cc: Aviad Yehezkel <redacted>
---
include/uapi/linux/tls.h | 2 ++
1 file changed, 2 insertions(+)
From: Dmitry V. Levin <hidden> Date: 2017-09-04 16:15:14
On Wed, Aug 09, 2017 at 02:25:54AM +0300, Dmitry V. Levin wrote:
On Sun, Aug 06, 2017 at 06:44:26PM +0200, Mikko Rapeli wrote:
quoted
It is not needed and not part of uapi headers, but causes
user space compilation error:
fatal error: net/tcp.h: No such file or directory
#include <net/tcp.h>
^
Signed-off-by: Mikko Rapeli <redacted>
Cc: Dave Watson <redacted>
Cc: Ilya Lesokhin <redacted>
Cc: Aviad Yehezkel <redacted>
---
include/uapi/linux/tls.h | 2 ++
1 file changed, 2 insertions(+)
From: Mikko Rapeli <hidden> Date: 2017-09-18 12:57:45
On Mon, Sep 04, 2017 at 07:15:11PM +0300, Dmitry V. Levin wrote:
On Wed, Aug 09, 2017 at 02:25:54AM +0300, Dmitry V. Levin wrote:
quoted
On Sun, Aug 06, 2017 at 06:44:26PM +0200, Mikko Rapeli wrote:
quoted
It is not needed and not part of uapi headers, but causes
user space compilation error:
fatal error: net/tcp.h: No such file or directory
#include <net/tcp.h>
^
Signed-off-by: Mikko Rapeli <redacted>
Cc: Dave Watson <redacted>
Cc: Ilya Lesokhin <ilyal-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Cc: Aviad Yehezkel <aviadye-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
include/uapi/linux/tls.h | 2 ++
1 file changed, 2 insertions(+)
From: Mikko Rapeli <hidden> Date: 2017-08-06 17:06:32
This libc header has sockaddr definition in user space.
Fixes user space compilation errors like these from kernel headers including
only linux/socket.h:
error: field ‘ifru_addr’ has incomplete type
struct sockaddr ifru_addr;
error: field ‘_sockaddr’ has incomplete type
struct sockaddr _sockaddr;
error: invalid application of ‘sizeof’ to incomplete type ‘struct sockaddr’
With this following uapi headers now compile in user space:
rdma/rdma_user_rxe.h
linux/vm_sockets.h
linux/ncp_fs.h
linux/nfc.h
linux/phonet.h
Signed-off-by: Mikko Rapeli <redacted>
Cc: netdev@vger.kernel.org
Cc: Dmitry V. Levin <redacted>
---
include/uapi/linux/socket.h | 4 ++++
1 file changed, 4 insertions(+)
From: Dmitry V. Levin <hidden> Date: 2017-08-08 23:00:45
On Sun, Aug 06, 2017 at 06:44:06PM +0200, Mikko Rapeli wrote:
quoted hunk
This libc header has sockaddr definition in user space.
Fixes user space compilation errors like these from kernel headers including
only linux/socket.h:
error: field ‘ifru_addr’ has incomplete type
struct sockaddr ifru_addr;
error: field ‘_sockaddr’ has incomplete type
struct sockaddr _sockaddr;
error: invalid application of ‘sizeof’ to incomplete type ‘struct sockaddr’
With this following uapi headers now compile in user space:
rdma/rdma_user_rxe.h
linux/vm_sockets.h
linux/ncp_fs.h
linux/nfc.h
linux/phonet.h
Signed-off-by: Mikko Rapeli <redacted>
Cc: netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Dmitry V. Levin <ldv-u2l5PoMzF/Vg9hUCZPvPmw@public.gmane.org>
---
include/uapi/linux/socket.h | 4 ++++
1 file changed, 4 insertions(+)
On Wed, Aug 9, 2017 at 1:00 AM, Dmitry V. Levin [off-list ref] wrote:
On Sun, Aug 06, 2017 at 06:44:06PM +0200, Mikko Rapeli wrote:
quoted
This libc header has sockaddr definition in user space.
Fixes user space compilation errors like these from kernel headers including
only linux/socket.h:
error: field ‘ifru_addr’ has incomplete type
struct sockaddr ifru_addr;
error: field ‘_sockaddr’ has incomplete type
struct sockaddr _sockaddr;
error: invalid application of ‘sizeof’ to incomplete type ‘struct sockaddr’
With this following uapi headers now compile in user space:
rdma/rdma_user_rxe.h
linux/vm_sockets.h
linux/ncp_fs.h
linux/nfc.h
linux/phonet.h
This is scary because of infamous libc vs uapi interoperability issues.
Couldn't we fix affected headers instead?
Yes, I think that would be better. Maybe we can introduce a
'struct __kernel_sockaddr' in include/uapi/linux/socket.h to
go along with __kernel_sa_family_t and __kernel_sockaddr_storage,
and then use those types in the other kernel headers?
Arnd
From: Mikko Rapeli <hidden> Date: 2017-08-06 17:06:38
Users of kernel uapi header files would be happier if they did not
contain kernel specific parts and would contain #include statements
for all other header files that they depend on, and in general would
compile also in user space. If Linux kernal uapi headers compile in
user space, then they can also be used to do ABI and API compatibility
checks against different kernel versions. ABI checks can also be used
by Linux distribution build systems like yocto/bitbake to avoid
recompiling dependencies if changes are ABI compatible.
For each header file exported to userspace, this script tries to
compile it together with minimal header files from GCC and libc, and
reports results.
In the test execution environment, libc and GCC header file locations
are parsed from gcc compiler configuration.
Some gcc and kernel headers depend on libc headers which are made available
by copying from the compiler default location to a temporary location and
removing possibly existing kernel headers from this directory. This is a bit
of a hack but seems to work in multiple environments so test can be
executed without installing headers to /usr/include and compiling a full
Linux distribution on top.
Tested natively on:
Debian unstable, i586-linux-gnu and gcc 4.9.2
Raspbian Wheezy, arm-linux-gnueabihf and gcc 4.6.3
Ubuntu 12.04 LTS, x86_64-linux-gnu and gcc 4.6.3
Tested cross compilation using standard CROSS_COMPILE=/path/to/gcc with:
arm-linux-gnueabihf-gcc (crosstool-NG linaro-1.13.1-4.9-2014.09 - Linaro GCC 4.9-2014.09) 4.9.2 20140904 (prerelease)
Execute the script in the directory where kernel header files are installed.
For example with kernel tree from v4.13-rc3-216-g0a23ea65ce9f on x86 i586:
$ make headers_install
$ cd usr/include
$ ../../scripts/headers_compile_test.sh
...
Kernel header compile test statistics:
42 files failed the kernel header compile test.
821 files passed the kernel header compile test.
Once all these errors have been fixed, this test could be added to
'make headers_check'.
In addition to plain compile test, there is also a glibc header
compatibility test, which compiles all kernel uapi headers against a
non-conflicting set of all GNU libc headers. The test covers
variants where kernel header is included before libc header
and libc header before kernel header.
Tested in Debian unstable with libc6 version 2.24-14.
Example execution with output:
$ make headers_install
$ cd usr/include
$ ../../scripts/headers_compile_test.sh -lk
Testing that /home/mcfrisk/src/linux-2.6/usr/headers_compile_test_include.qd5RuE/libc_headers.h compiles
cc -Wall -c -nostdinc -I /usr/lib/gcc/i686-linux-gnu/6/include -I /usr/lib/gcc/i686-linux-gnu/6/include-fixed -I . -I /home/mcfrisk/src/linux-2.6/usr/headers_compile_test_include.qd5RuE -I /home/mcfrisk/src/linux-2.6/usr/headers_compile_test_include.qd5RuE/i686-linux-gnu -o /dev/null /home/mcfrisk/src/linux-2.6/usr/include/drm/i810_drm.h
PASSED: drm/i810_drm.h
cc -Wall -c -nostdinc -I /usr/lib/gcc/i686-linux-gnu/6/include -I /usr/lib/gcc/i686-linux-gnu/6/include-fixed -I . -I /home/mcfrisk/src/linux-2.6/usr/headers_compile_test_include.qd5RuE -I /home/mcfrisk/src/linux-2.6/usr/headers_compile_test_include.qd5RuE/i686-linux-gnu -o /dev/null /home/mcfrisk/src/linux-2.6/usr/include/drm/i810_drm.h_libc_before_kernel.h
...
In file included from /home/mcfrisk/src/linux-2.6/usr/include/asm/sigcontext.h_l
ibc_before_kernel.h:2:0:
./asm/sigcontext.h:291:8: error: redefinition of ‘struct sigcontext’
struct sigcontext {
^~~~~~~~~~
In file included from /home/mcfrisk/src/linux-2.6/usr/headers_compile_test_inclu
de.qd5RuE/signal.h:306:0,
from /home/mcfrisk/src/linux-2.6/usr/headers_compile_test_inclu
de.qd5RuE/sys/param.h:28,
from /home/mcfrisk/src/linux-2.6/usr/headers_compile_test_inclu
de.qd5RuE/resolv.h:62,
from /home/mcfrisk/src/linux-2.6/usr/headers_compile_test_inclu
de.qd5RuE/libc_headers.h:103,
from /home/mcfrisk/src/linux-2.6/usr/include/asm/sigcontext.h_l
ibc_before_kernel.h:1:
/home/mcfrisk/src/linux-2.6/usr/headers_compile_test_include.qd5RuE/bits/sigcont
ext.h:93:8: note: originally defined here
struct sigcontext
^~~~~~~~~~
FAILED libc before kernel test: asm/sigcontext.h
...
Kernel header compile test statistics:
42 files failed the kernel header compile test.
821 files passed the kernel header compile test.
libc and kernel header compatibility test statistics:
73 files failed libc before kernel include test.
790 files passed libc before kernel include test.
Since I've been stubborn enough to work with this script and fixes to the
test failures for a few years, I added my self to MAINTAINERS.
Signed-off-by: Mikko Rapeli <redacted>
Cc: Alexander Stein <redacted>
Cc: Gabriel Laskar <redacted>
Cc: Dmitry V. Levin <redacted>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: netdev@vger.kernel.org
Cc: linux-api@vger.kernel.org
---
MAINTAINERS | 5 +
scripts/headers_compile_test.sh | 507 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 512 insertions(+)
create mode 100755 scripts/headers_compile_test.sh
@@ -0,0 +1,507 @@+#!/bin/bash++help(){+cat<< EOF_HELP+Userspacecompiletestforexportedkernelheaders.++Copyright(C)2015MikkoRapeli<mikko.rapeli@iki.fi>++Thisprogramisfreesoftware;youcanredistributeitand/or+modifyitunderthetermsoftheGNUGeneralPublicLicense+aspublishedbytheFreeSoftwareFoundation;version2+oftheLicense.++ExecuteinrootdirectoryofexportedkernelheadersinLinuxkernelsource+tree.Setsupgccandlibcheaderswithoutexistingkernelheadersto+atemporaryenvironmentandtriestocompileallexportedheaderfiles+fromcurrentdirectoryagainstthem.Returnvalueiszeroifalltestspass,+non-zeroifsomethinggoeswrongduringexecutionorifanyfilefailed+thecompiletests.++Supportedarguments:++-h|--helpprinthelp+-k|--keepdon'tcleanuptemporaryheaderfilesanddirectories+-lk|--libc-kerneltestforconflictsbetweenkernelandlibcheaders+whenlibcheadersareincludedbeforekernelheaders+-kl|--kernel-libctestforconflictsbetweenkernelandlibcheaders+whenkernelheadersareincludedbeforelibcheaders+-l|--libctestboth-lkand-kl+-v|--verboseprintmoreverboseoutput++ExampleinLinuxkernelsourcetree:++\$makeheaders_install+\$cdusr/include+\$$(readlink-f"$0")++EOF_HELP+}++# bash due to arithmetics and pipefail+set-euopipefail++KEEP=0+HELP=0+LIBC_TEST=0+LIBC_KERNEL_TEST=0+KERNEL_LIBC_TEST=0++# command line arguments+forpin"$@";do+case"$p"in+-k|--keep)+KEEP=1+;;+-l|--libc)+LIBC_TEST=1+LIBC_KERNEL_TEST=1+KERNEL_LIBC_TEST=1+;;+-lk|--libc-kernel)+LIBC_TEST=1+LIBC_KERNEL_TEST=1+;;+-kl|--kernel-libc)+LIBC_TEST=1+KERNEL_LIBC_TEST=1+;;+-h|--help)+HELP=1+;;+-v|--verbose)+set-x+;;+*)+help+echo"Unknown argument: $p"+exit1+;;+esac+done++if["$HELP"!="0"];thenhelp;exit0;fi++# sanity test+if[!-d./linux];then+echoSanitycheckerror:./linuxdirectorynotfound+echoShouldbecalledinusr/includeafter\'makeheaders_install\'.+echoReturnsnumberoffailedfiles,0ifnone.+exit1+fi++# Support CC variable for compiler and ccache, and cross compiling.+# CC is used without quotes to support CC="ccache gcc".+set+u+if["$CC"foobar=="foobar"];then+CC=cc+fi++if["$CROSS_COMPILE"foobar!="foobar"];then+# Using gcc name since some cross compiler tool chains don't provide+# the cc symlink. Using eval to expand ~ to $HOME.+CC="$(evalecho"$CROSS_COMPILE"gcc)"+fi+set-u++# Kernel headers refer to some gcc and libc headers so make them available.+set+u+if["$ARCH_TRIPLET"foobar=="foobar"];then+# Taking triplet from gcc/cpp+ARCH_TRIPLET="$($CC-v-xc-E-</dev/null2>&1|\+grepTarget|sed-e's/Target: //')"+fi++if["$LIBC"foobar=="foobar"];then+# trying to grep libc includes from gcc/cpp defaults+_TEMP="$($CC-v-xc-E-</dev/null2>&1|\+sed-n-e'/^#include <...> search starts here:$/,/^End of search list.$/{//!p}'|\+sed-e's/^\ \//\//g'|\+grep'/usr/include')"++# sanity check and prepare LIBC dirs+fordin$_TEMP;do+if[!-d"$d"];then+echo"$d not a directory"+exit1+fi+LIBC="$LIBC$d"+done+fi+set-u++# Copy libc include files to temp directory for the tests.+COMPILE_TEST_INC="$(readlink-f\+"$(mktemp-d../headers_compile_test_include.XXXXXX)")"++# cleanup if keep not set+if["$KEEP"="0"];then+trap'rm -rf "$COMPILE_TEST_INC"'EXIT+else+trap'printf\+"Temporary directory not cleaned up! Remove manually:\n${COMPILE_TEST_INC}\n"'\+EXIT+fi++fordin$LIBC;do+# check if last part of dir is the arch triplet, cross compile paths+# can have it also elsewhere so just the last one counts.+if!(echo"$d"|egrep"$ARCH_TRIPLET$">/dev/null);then+# hopefully just main libc dir, e.g. /usr/include,+# follow symlinks from e.g. /usr/include/bits+cp-aL"$d"/*"$COMPILE_TEST_INC"/+elif(echo"$d"|egrep"$ARCH_TRIPLET$">/dev/null);then+# hopefully the arch specific dir, e.g. /usr/include/x86_64-linux-gnu+cp-ar"$d"/*"$COMPILE_TEST_INC/"+else+echo"$d unexpected, bailing out"+exit1+fi+done++# A single header with all non-conflicting libc headers to test kernel+# headers against libc headers for conflicts.+if["$LIBC_TEST"!=0];then+# List taken from Debian unstable libc6 version 2.21-9.+# Some glibc headers conflict with each other so they+# are filtered out. Not perfect but better than nothing.+#+# $ for f in $( egrep "\.h$" /var/lib/dpkg/info/libc6-dev\:i386.list | sed -e 's|/usr/include/||'| sort | grep -v arpa | grep -v linux-gnu | grep -v rpcsvc | grep -v regexp.h | grep -v rpc | grep -v scsi | grep -v talkd ); do echo "#include <$f>"; done > libc_headers.h++cat>"$COMPILE_TEST_INC/libc_headers.h"<< EOF_LIBC_HEADERS+#include <aio.h>+#include <aliases.h>+#include <alloca.h>+#include <argp.h>+#include <argz.h>+#include <ar.h>+#include <assert.h>+#include <byteswap.h>+#include <complex.h>+#include <cpio.h>+#include <crypt.h>+#include <ctype.h>+#include <dirent.h>+#include <dlfcn.h>+#include <elf.h>+#include <endian.h>+#include <envz.h>+#include <err.h>+#include <errno.h>+#include <error.h>+#include <execinfo.h>+#include <fcntl.h>+#include <features.h>+#include <fenv.h>+#include <fmtmsg.h>+#include <fnmatch.h>+#include <fstab.h>+#include <fts.h>+#include <ftw.h>+#include <_G_config.h>+#include <gconv.h>+#include <getopt.h>+#include <glob.h>+#include <gnu-versions.h>+#include <grp.h>+#include <gshadow.h>+#include <iconv.h>+#include <ifaddrs.h>+#include <inttypes.h>+#include <langinfo.h>+#include <lastlog.h>+#include <libgen.h>+#include <libintl.h>+#include <libio.h>+#include <limits.h>+#include <link.h>+#include <locale.h>+#include <malloc.h>+#include <math.h>+#include <mcheck.h>+#include <memory.h>+#include <mntent.h>+#include <monetary.h>+#include <mqueue.h>+#include <netash/ash.h>+#include <netatalk/at.h>+#include <netax25/ax25.h>+#include <netdb.h>+#include <neteconet/ec.h>+#include <net/ethernet.h>+#include <net/if_arp.h>+#include <net/if.h>+#include <net/if_packet.h>+#include <net/if_ppp.h>+#include <net/if_shaper.h>+#include <net/if_slip.h>+#include <netinet/ether.h>+#include <netinet/icmp6.h>+#include <netinet/if_ether.h>+#include <netinet/if_fddi.h>+#include <netinet/if_tr.h>+#include <netinet/igmp.h>+#include <netinet/in.h>+#include <netinet/in_systm.h>+#include <netinet/ip6.h>+#include <netinet/ip.h>+#include <netinet/ip_icmp.h>+#include <netinet/tcp.h>+#include <netinet/udp.h>+#include <netipx/ipx.h>+#include <netiucv/iucv.h>+#include <netpacket/packet.h>+#include <net/ppp-comp.h>+#include <net/ppp_defs.h>+#include <netrom/netrom.h>+#include <netrose/rose.h>+#include <net/route.h>+#include <nfs/nfs.h>+#include <nl_types.h>+#include <nss.h>+#include <obstack.h>+#include <paths.h>+#include <poll.h>+#include <printf.h>+#include <protocols/routed.h>+#include <protocols/rwhod.h>+#include <protocols/timed.h>+#include <pthread.h>+#include <pty.h>+#include <pwd.h>+#include <re_comp.h>+#include <regex.h>+#include <resolv.h>+#include <sched.h>+#include <search.h>+#include <semaphore.h>+#include <setjmp.h>+#include <sgtty.h>+#include <shadow.h>+#include <signal.h>+#include <spawn.h>+#include <stab.h>+#include <stdc-predef.h>+#include <stdint.h>+#include <stdio_ext.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <strings.h>+#include <stropts.h>+#include <syscall.h>+#include <sysexits.h>+#include <syslog.h>+#include <tar.h>+#include <termio.h>+#include <termios.h>+#include <tgmath.h>+#include <thread_db.h>+#include <time.h>+#include <ttyent.h>+#include <uchar.h>+#include <ucontext.h>+#include <ulimit.h>+#include <unistd.h>+#include <ustat.h>+#include <utime.h>+#include <utmp.h>+#include <utmpx.h>+#include <values.h>+#include <wait.h>+#include <wchar.h>+#include <wctype.h>+#include <wordexp.h>+#include <xlocale.h>+EOF_LIBC_HEADERS++fi# LIBC_TEST++# Simulate libc headers without kernel headers by removing+# all known kernel header dirs from the copied libc ones.+# This seems to magically work.+_KERNEL_DIRS="$(find.-typed|grep-v'^\.$')"+(cd"$COMPILE_TEST_INC"&&rm-rf$_KERNEL_DIRS)++# GCC headers+set+u+if["$GCC_INC"foobar=="foobar"];then+# Take from $CC default system include paths, filter out+# /usr/local/include and /usr/include stuff first, then try to match+# for gcc.+_TEMP="$($CC-v-xc-E-</dev/null2>&1|\+sed-n-e'/^#include <...> search starts here:$/,/^End of search list.$/{//!p}'|\+sed-e's/^\ \//\//g'|\+egrep-v'/usr/local/include'|\+egrep-v'/usr/include'|\+grepgcc|\+xargs)"++# merge and prepare for use with $CC+fordin$_TEMP;do+# sanity test+if[!-d"$d"];then+echo"$d: is not a directory"+exit1+fi+GCC_INC="$GCC_INC -I $d"+done+fi+set-u++# sanity check: test that plain libc headers compile+if["$LIBC_TEST"!=0];then+echo"Testing that $COMPILE_TEST_INC/libc_headers.h compiles"+$CC-Wall-c-nostdinc$GCC_INC-I.\+-I"$COMPILE_TEST_INC"\+-I"$COMPILE_TEST_INC/$ARCH_TRIPLET"\+-o/dev/null\+"$COMPILE_TEST_INC/libc_headers.h"+fi++# Summary counters:+_FAILED=0+_PASSED=0+_LIBC_FAILED=0+_LIBC_PASSED=0+_LIBC_BEFORE_KERNEL_FAILED=0+_LIBC_BEFORE_KERNEL_PASSED=0+_KERNEL_BEFORE_LIBC_FAILED=0+_KERNEL_BEFORE_LIBC_PASSED=0++# For each header file, try to compile it using the headers we prepared.+forfin$(find.-name"*\.h"-printf"%P\n");do+_FAIL=0+_FAIL_LIBC=0+_FAIL_LIBC_BEFORE_KERNEL=0+_FAIL_KERNEL_BEFORE_LIBC=0++# compile test, CC not quoted to support ccache+echo$CC-Wall-c-nostdinc$GCC_INC-I.-I"$COMPILE_TEST_INC"-I"$COMPILE_TEST_INC/$ARCH_TRIPLET"-o/dev/null"$PWD/$f"+$CC-Wall-c-nostdinc$GCC_INC-I.-I"$COMPILE_TEST_INC"-I"$COMPILE_TEST_INC/$ARCH_TRIPLET"-o/dev/null"$PWD/$f"\+||_FAIL=1++# report errors+if["$_FAIL"-gt0];then+echo"FAILED: $f"+_FAILED="$((_FAILED+1))"+else+echo"PASSED: $f"+_PASSED="$((_PASSED+1))"+fi++# libc header conflict tests+if["$LIBC_TEST"!=0];then+_LIBC_BEFORE_KERNEL="$PWD/$f"_libc_before_kernel.h+_KERNEL_BEFORE_LIBC="$PWD/$f"_kernel_before_libc.h++# libc header included before kernel header+if["$LIBC_KERNEL_TEST"!=0];then+cat>"$_LIBC_BEFORE_KERNEL"<< EOF_LIBC_BEFORE_KERNEL+#include <libc_headers.h>+#include <$f>+EOF_LIBC_BEFORE_KERNEL+echo\+$CC-Wall-c-nostdinc$GCC_INC\+-I.-I"$COMPILE_TEST_INC"\+-I"$COMPILE_TEST_INC/$ARCH_TRIPLET"\+-o/dev/null"$_LIBC_BEFORE_KERNEL"+$CC-Wall-c-nostdinc$GCC_INC\+-I.-I"$COMPILE_TEST_INC"\+-I"$COMPILE_TEST_INC/$ARCH_TRIPLET"\+-o/dev/null"$_LIBC_BEFORE_KERNEL"\+||_FAIL_LIBC_BEFORE_KERNEL=1++# report errors+if["$_FAIL_LIBC_BEFORE_KERNEL"-gt0];then+echo"FAILED libc before kernel test: $f"+_LIBC_BEFORE_KERNEL_FAILED="$((_LIBC_BEFORE_KERNEL_FAILED+1))"+else+echo"PASSED libc before kernel test: $f"+_LIBC_BEFORE_KERNEL_PASSED="$((_LIBC_BEFORE_KERNEL_PASSED+1))"+fi+fi++# kernel header included before libc+if["$KERNEL_LIBC_TEST"!=0];then+cat>"$_KERNEL_BEFORE_LIBC"<< EOF_KERNEL_BEFORE_LIBC+#include <$f>+#include <libc_headers.h>+EOF_KERNEL_BEFORE_LIBC+echo\+$CC-Wall-c-nostdinc$GCC_INC\+-I.-I"$COMPILE_TEST_INC"\+-I"$COMPILE_TEST_INC/$ARCH_TRIPLET"\+-o/dev/null"$_KERNEL_BEFORE_LIBC"+$CC-Wall-c-nostdinc$GCC_INC\+-I.-I"$COMPILE_TEST_INC"\+-I"$COMPILE_TEST_INC/$ARCH_TRIPLET"\+-o/dev/null"$_KERNEL_BEFORE_LIBC"\+||_FAIL_KERNEL_BEFORE_LIBC=1++# report errors+if["$_FAIL_KERNEL_BEFORE_LIBC"-gt0];then+echo"FAILED kernel before libc test: $f"+_KERNEL_BEFORE_LIBC_FAILED="$((_KERNEL_BEFORE_LIBC_FAILED+1))"+else+echo"PASSED kernel before libc test: $f"+_KERNEL_BEFORE_LIBC_PASSED="$((_KERNEL_BEFORE_LIBC_PASSED+1))"+fi+fi++# libc summary+if["$_FAIL_LIBC_BEFORE_KERNEL"-gt0-o"$_FAIL_KERNEL_BEFORE_LIBC"-gt0];then+_LIBC_FAILED="$((_LIBC_FAILED+1))"+else+_LIBC_PASSED="$((_LIBC_PASSED+1))"+fi++if["$KEEP"="0"];then+rm-f"$_LIBC_BEFORE_KERNEL""$_KERNEL_BEFORE_LIBC"+fi+fi# LIBC_TEST+done++cat<<EOF_STATS++Kernelheadercompileteststatistics:++$_FAILEDfilesfailedthekernelheadercompiletest.+$_PASSEDfilespassedthekernelheadercompiletest.++EOF_STATS++if["$LIBC_TEST"!=0];then+cat<<EOF_LIBC_STATS+libcandkernelheadercompatibilityteststatistics:+EOF_LIBC_STATS++if["$LIBC_KERNEL_TEST"!=0]&&["$KERNEL_LIBC_TEST"!=0];then+cat<< EOF_LIBC_COMBINED+$_LIBC_FAILEDfilesfailedthelibccompatibilitytest.+$_LIBC_PASSEDfilespassedthelibccompatibilitytest.+EOF_LIBC_COMBINED+fi++if["$LIBC_KERNEL_TEST"!=0];then+cat<< EOF_LIBC_KERNEL+$_LIBC_BEFORE_KERNEL_FAILEDfilesfailedlibcbeforekernelincludetest.+$_LIBC_BEFORE_KERNEL_PASSEDfilespassedlibcbeforekernelincludetest.+EOF_LIBC_KERNEL+fi++if["$KERNEL_LIBC_TEST"!=0];then+cat<< EOF_KERNEL_LIBC+$_KERNEL_BEFORE_LIBC_FAILEDfilesfailedkernelbeforelibcincludetest.+$_KERNEL_BEFORE_LIBC_PASSEDfilespassedkernelbeforelibcincludetest.+EOF_KERNEL_LIBC+fi++fi# LIBC_TEST++# return value, summary of all failures.+if["$(($_FAILED+$_LIBC_BEFORE_KERNEL_FAILED+$_KERNEL_BEFORE_LIBC_FAILED))"!=0];then+exit1+else+exit0+fi
@@ -89,10 +89,10 @@ struct scsi_nl_hdr {*/structscsi_nl_host_vendor_msg{structscsi_nl_hdrsnlh;/* must be 1st element ! */-uint64_tvendor_id;-uint16_thost_no;-uint16_tvmsg_datalen;-}__attribute__((aligned(sizeof(uint64_t))));+__u64vendor_id;+__u16host_no;+__u16vmsg_datalen;+}__attribute__((aligned(sizeof(__u64))));/*
On Sun, Aug 6, 2017 at 6:44 PM, Mikko Rapeli [off-list ref] wrote:
Fixes userspace compilation error:
error: unknown type name ‘size_t’
Signed-off-by: Mikko Rapeli <redacted>
Cc: linux-omap@vger.kernel.org
Cc: Tomi Valkeinen <redacted>
Cc: Aaro Koskinen <aaro.koskinen@iki.fi>
You generally cannot replace size_t with __kernel_size_t in a header that
affects x32, but this case is really bad one: the kernel treats
struct omapfb_memory_read.buffer_size as __kernel_size_t, while
x32 userspace treats it as size_t. As result, the offset of
struct omapfb_memory_read.buffer on x32 is different between the kernel
and userspace.
In other words, the whole thing seems to be totally broken on x32 already
and it's not important whether you use __kernel_size_t or
__kernel_uapi_size_t as a type of struct omapfb_memory_read.buffer_size.
This deserves a word in the commit message, though.
--
ldv
From: Mikko Rapeli <hidden> Date: 2017-08-06 17:07:02
Name structs in linux/hdlc/ioctl.h and forward declare and use them in
linux/if.h. Then include linux/if.h in linux/hdlc/ioctl.h to fix
user space compilation problem:
hdlc/ioctl.h:73:14: error: ‘IFNAMSIZ’ undeclared here (not in a function)
char master[IFNAMSIZ]; /* Name of master FRAD device */
^~~~~~~~
This approach for suggested by Frans Klaver [off-list ref]
in lkml message
[off-list ref].
Signed-off-by: Mikko Rapeli <redacted>
Cc: Frans Klaver <redacted>
Cc: David Miller <davem@davemloft.net>
---
include/uapi/linux/hdlc/ioctl.h | 17 +++++++++--------
include/uapi/linux/if.h | 23 ++++++++++++++++-------
2 files changed, 25 insertions(+), 15 deletions(-)
@@ -1,6 +1,7 @@#ifndef __HDLC_IOCTL_H__#define __HDLC_IOCTL_H__+#include<linux/if.h>#define GENERIC_HDLC_VERSION 4 /* For synchronization with sethdlc utility */
@@ -36,25 +37,25 @@#ifndef __ASSEMBLY__-typedefstruct{+typedefstructsync_serial_settings{unsignedintclock_rate;/* bits per second */unsignedintclock_type;/* internal, external, TX-internal etc. */unsignedshortloopback;}sync_serial_settings;/* V.35, V.24, X.21 */-typedefstruct{+typedefstructte1_settings{unsignedintclock_rate;/* bits per second */unsignedintclock_type;/* internal, external, TX-internal etc. */unsignedshortloopback;unsignedintslot_map;}te1_settings;/* T1, E1 */-typedefstruct{+typedefstructraw_hdlc_proto{unsignedshortencoding;unsignedshortparity;}raw_hdlc_proto;-typedefstruct{+typedefstructfr_proto{unsignedintt391;unsignedintt392;unsignedintn391;
@@ -64,16 +65,16 @@ typedef struct {unsignedshortdce;/* 1 for DCE (network side) operation */}fr_proto;-typedefstruct{+typedefstructfr_proto_pvc{unsignedintdlci;}fr_proto_pvc;/* for creating/deleting FR PVCs */-typedefstruct{+typedefstructfr_proto_pvc_info{unsignedintdlci;charmaster[IFNAMSIZ];/* Name of master FRAD device */-}fr_proto_pvc_info;/* for returning PVC information only */+}fr_proto_pvc_info;/* for returning PVC information only */-typedefstruct{+typedefstructcisco_proto{unsignedintinterval;unsignedinttimeout;}cisco_proto;
@@ -34,6 +34,15 @@#define IFALIASZ 256#include<linux/hdlc/ioctl.h>+/* Forward declarations to break dependency loop with <linux/hdlc/ioctl.h> */+structsync_serial_settings;+structae1_settings;+structraw_hdlc_proto;+structfr_proto;+structfr_proto_pvc;+structfr_proto_pvc_info;+structcisco_proto;+/* For glibc compatibility. An empty enum does not compile. */#if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO != 0 || \__UAPI_DEF_IF_NET_DEVICE_FLAGS!=0
@@ -206,15 +215,15 @@ struct if_settings {unsignedintsize;/* Size of the data allocated by the caller */union{/* {atm/eth/dsl}_settings anyone ? */-raw_hdlc_proto__user*raw_hdlc;-cisco_proto__user*cisco;-fr_proto__user*fr;-fr_proto_pvc__user*fr_pvc;-fr_proto_pvc_info__user*fr_pvc_info;+structraw_hdlc_proto__user*raw_hdlc;+structcisco_proto__user*cisco;+structfr_proto__user*fr;+structfr_proto_pvc__user*fr_pvc;+structfr_proto_pvc_info__user*fr_pvc_info;/* interface settings */-sync_serial_settings__user*sync;-te1_settings__user*te1;+structsync_serial_settings__user*sync;+structte1_settings__user*te1;}ifs_ifsu;};
From: Mikko Rapeli <hidden> Date: 2017-08-06 17:07:10
Include linux/types.h and asm/msgbuf.h and use __kernel_size_t instead
of size_t.
Fixes userspace compilation errors like:
error: field ‘shm_perm’ has incomplete type
struct ipc64_perm shm_perm; /* operation perms */
error: unknown type name ‘size_t’
error: unknown type name ‘__kernel_time_t’
Signed-off-by: Mikko Rapeli <redacted>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Cc: H.J. Lu <redacted>
Cc: H. Peter Anvin <hpa@zytor.com>
---
include/uapi/asm-generic/shmbuf.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
From: Dmitry V. Levin <hidden> Date: 2017-08-08 22:42:58
On Sun, Aug 06, 2017 at 06:43:59PM +0200, Mikko Rapeli wrote:
quoted hunk
Include linux/types.h and asm/msgbuf.h and use __kernel_size_t instead
of size_t.
Fixes userspace compilation errors like:
error: field ‘shm_perm’ has incomplete type
struct ipc64_perm shm_perm; /* operation perms */
error: unknown type name ‘size_t’
error: unknown type name ‘__kernel_time_t’
Signed-off-by: Mikko Rapeli <redacted>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Cc: H.J. Lu <redacted>
Cc: H. Peter Anvin <hpa@zytor.com>
---
include/uapi/asm-generic/shmbuf.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
@@ -100,7 +100,14 @@ typedef unsigned long long u_quad_t;#if defined(__linux__)#include<linux/time.h>#define cdev_t u_quad_t+#ifndef __KERNEL__+typedefunsignedlongu_long;+typedefunsignedintu_int;+typedefunsignedshortu_short;+typedefu_longino_t;+typedefu_longdev_t;+typedefvoid*caddr_t;
This looks suspicious: obviously anyone who is including this
header today has to define those types somewhere. If you add
another definition, that will clash with the existing one.
Have you tried replacing the custom types with the regular
kernel types instead?
I would not worry about breaking other operating systems here,
in fact it may be better to remove the #ifdef for those altogether.
quoted hunk
#if !defined(_UQUAD_T_) && (!defined(__GLIBC__) || __GLIBC__ < 2)
#define _UQUAD_T_ 1
typedef unsigned long long u_quad_t;
This looks like an actual bugfix: pid_t might differ between libc and
the kernel, so the kernel interface has to use types that the kernel
defines. This is probably ok on any supported version of glibc,
so it's unlikely to have caused runtime problems, but it should be
fixed nonetheless.
Arnd
@@ -57,14 +57,14 @@*/structfc_nl_event{structscsi_nl_hdrsnlh;/* must be 1st element ! */-uint64_tseconds;-uint64_tvendor_id;-uint16_thost_no;-uint16_tevent_datalen;-uint32_tevent_num;-uint32_tevent_code;-uint32_tevent_data;-}__attribute__((aligned(sizeof(uint64_t))));+__u64seconds;+__u64vendor_id;+__u16host_no;+__u16event_datalen;+__u32event_num;+__u32event_code;+__u32event_data;+}__attribute__((aligned(sizeof(__u64))));#endif /* SCSI_NETLINK_FC_H */
Rather than patching the kernel, why not #include <stdint.h> in your
userspace programme?
The userspace program is actually a test which checks that uapi headers
compile alone because several headers are not compiling at all and/or
require special tricks. The test is available here:
http://marc.info/?l=linux-kernel&m=150203944104544&w=2
I have tried that approach before but then:
https://lkml.org/lkml/2015/6/1/160
For some subsystems like fuse the above message was not enough and they
are including stdint.h in userspace. What shall we do with this old
scsi header file?
-Mikko
From: James Bottomley <James.Bottomley@HansenPartnership.com> Date: 2017-08-06 22:10:15
On Sun, 2017-08-06 at 23:42 +0300, Mikko Rapeli wrote:
Hi,
On Sun, Aug 06, 2017 at 11:22:53AM -0700, James Bottomley wrote:
quoted
On Sun, 2017-08-06 at 18:43 +0200, Mikko Rapeli wrote:
quoted
Fixes userspace compilation errors like:
scsi/scsi_netlink_fc.h:60:2: error: expected specifier-qualifier-
list before ‘uint64_t’
Rather than patching the kernel, why not #include <stdint.h> in
your userspace programme?
The userspace program is actually a test which checks that uapi
headers compile alone because several headers are not compiling at
all and/or require special tricks. The test is available here:
http://marc.info/?l=linux-kernel&m=150203944104544&w=2
But you don't seem to be detecting or fixing an existing problem.
These types are width unambiguous and all current consumers of these
headers include stdint.h so you're churning the kernel for a problem
which doesn't currently exist for any consumer of this header.
I can agree not adding any more external uint<x>_t types for newly
exported headers so new consumers don't depend on an external standard
is reasonable, so checkpatch should warn if someone tries to add them;
I just don't see the benefit of going over the whole kernel changing
stuff that has worked fine for years. Now if you can tell me there's
an actual bug somewhere, that's different ...
James
From: Mikko Rapeli <hidden> Date: 2017-08-07 06:08:54
On Sun, Aug 06, 2017 at 03:09:21PM -0700, James Bottomley wrote:
On Sun, 2017-08-06 at 23:42 +0300, Mikko Rapeli wrote:
quoted
Hi,
On Sun, Aug 06, 2017 at 11:22:53AM -0700, James Bottomley wrote:
quoted
On Sun, 2017-08-06 at 18:43 +0200, Mikko Rapeli wrote:
quoted
Fixes userspace compilation errors like:
scsi/scsi_netlink_fc.h:60:2: error: expected specifier-qualifier-
list before ‘uint64_t’
Rather than patching the kernel, why not #include <stdint.h> in
your userspace programme?
The userspace program is actually a test which checks that uapi
headers compile alone because several headers are not compiling at
all and/or require special tricks. The test is available here:
http://marc.info/?l=linux-kernel&m=150203944104544&w=2
But you don't seem to be detecting or fixing an existing problem.
These types are width unambiguous and all current consumers of these
headers include stdint.h so you're churning the kernel for a problem
which doesn't currently exist for any consumer of this header.
The header file dependencies of scsi/scsi_netlink_fc.h are not explicit.
I will propose a patch which includes <stdint.h> in userspace then.
I can agree not adding any more external uint<x>_t types for newly
exported headers so new consumers don't depend on an external standard
is reasonable, so checkpatch should warn if someone tries to add them;
I just don't see the benefit of going over the whole kernel changing
stuff that has worked fine for years. Now if you can tell me there's
an actual bug somewhere, that's different ...
Tools parsing and checking uapi headers need to be able to compile them
and thus need the explicit list of dependencies. If <stdint.h> is a
required dependency, then scsi/scsi_netlink_fc.h should include it.
scsi/scsi_netlink_fc.h is one of 42 problematic headers left in current
kernel and I want to fix it one way or the other.
-Mikko
From: Mikko Rapeli <hidden> Date: 2017-08-06 17:08:20
Arnd Bergmann [off-list ref] doubts that __kernel_size_t could be used here
so trying to fall back to gcc's <stddef.h>.
Fixes uapi header compilation error from userspace on ARCH=arm:
asm/signal.h:112:2: error: unknown type name ‘size_t’
size_t ss_size;
Signed-off-by: Mikko Rapeli <redacted>
Cc: Arnd Bergmann <arnd@arndb.de>
---
arch/arm/include/uapi/asm/signal.h | 2 ++
1 file changed, 2 insertions(+)
From: Dmitry V. Levin <hidden> Date: 2017-08-08 22:57:42
On Sun, Aug 06, 2017 at 06:44:05PM +0200, Mikko Rapeli wrote:
Arnd Bergmann [off-list ref] doubts that __kernel_size_t could be used here
so trying to fall back to gcc's <stddef.h>.
The only architecture where you cannot do this safely is x86 family
because of x32 exception. If there is no chance that the change will
affect x32, feel free to replace size_t with __kernel_size_t like I did
some time ago, see
http://lkml.kernel.org/r/20170302002022.GB27097@altlinux.org
--
ldv
There is another problem: on some 32-bit architectures, size_t is
defined as 'unsigned int', while '__kernel_size_t' is defined as 'unsigned
long'. These obviously have the same size, but the man page
explicitly defines it as 'size_t ss_size'.
If a user space program accesses the field in a way requires an
exact type match, it gets a warning or error, e.g.
1. printf("signal with %zd bytes\n", stack->ss_size);
2. size_t *pointer_to_size_t = &stack->ss_size;
3. assert(__builtin_types_compatible_p(size_t, typeof(stack->ss_size)))
Not sure how important those are, but I think there is at least a risk
of any of those showing up in user space.
Arnd
There is another problem: on some 32-bit architectures, size_t is
defined as 'unsigned int', while '__kernel_size_t' is defined as 'unsigned
long'. These obviously have the same size, but the man page
explicitly defines it as 'size_t ss_size'.
If a user space program accesses the field in a way requires an
exact type match, it gets a warning or error, e.g.
1. printf("signal with %zd bytes\n", stack->ss_size);
2. size_t *pointer_to_size_t = &stack->ss_size;
3. assert(__builtin_types_compatible_p(size_t, typeof(stack->ss_size)))
Not sure how important those are, but I think there is at least a risk
of any of those showing up in user space.
Agreed, one has to take this issue into consideration when replacing
size_t with __kernel_size_t.
--
ldv
In patch 14, you took a different approach based on an earlier comment
of mine, for the same structure. I think we should definitely take the same
approach for signal.h across all architectures, whichever we end up using.
Arnd
From: Mikko Rapeli <hidden> Date: 2017-08-06 17:08:27
Would be nice to be able to compile all userspace header files also alone.
Signed-off-by: Mikko Rapeli <redacted>
Cc: alsa-devel@alsa-project.org
Cc: Andrew Veliath <redacted>
Cc: Riccardo Facchetti <redacted>
---
include/uapi/linux/patchkey.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Mikko Rapeli <hidden> Date: 2017-08-06 17:08:41
Remove typedef elf_greg_t greg_t and friends from userspace.
Remove struct elf_prstatus completely from userspace.
elfcore.h as such does not compile in userspace. All userspace users
of <linux/elfcore.h> like gcc/gdb and linux-tools contain their own modified
versions of the file. With these changes the file compiles but is generally
not usable for things like core dump parsing but luckily userspace users
already know this and have their own modified version of the needed
definitions and headers. But at least this compiles now.
Signed-off-by: Mikko Rapeli <redacted>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Roland McGrath <redacted>
---
include/uapi/linux/elfcore.h | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
@@ -48,10 +40,10 @@ struct elf_prstatusstructsigaltstackpr_altstack;/* Alternate stack info */structsigactionpr_action;/* Signal action for current sig */#endif-pid_tpr_pid;-pid_tpr_ppid;-pid_tpr_pgrp;-pid_tpr_sid;+__kernel_pid_tpr_pid;+__kernel_pid_tpr_ppid;+__kernel_pid_tpr_pgrp;+__kernel_pid_tpr_sid;structtimevalpr_utime;/* User time */structtimevalpr_stime;/* System time */structtimevalpr_cutime;/* Cumulative user time */
@@ -72,6 +64,7 @@ struct elf_prstatus#endifintpr_fpvalid;/* True if math co-processor being used. */};+#endif /* __KERNEL__ */#define ELF_PRARGSZ (80) /* Number of chars for args */
@@ -84,7 +77,7 @@ struct elf_prpsinfounsignedlongpr_flag;/* flags */__kernel_uid_tpr_uid;__kernel_gid_tpr_gid;-pid_tpr_pid,pr_ppid,pr_pgrp,pr_sid;+__kernel_pid_tpr_pid,pr_ppid,pr_pgrp,pr_sid;/* Lots missing */charpr_fname[16];/* filename of executable */charpr_psargs[ELF_PRARGSZ];/* initial part of arg list */
From: Mikko Rapeli <hidden> Date: 2017-08-06 17:09:55
These are defined in linux/types.h or drm/drm.h. Fixes
user space compilation errors like:
drm/armada_drm.h:26:2: error: unknown type name ‘uint32_t’
uint32_t handle;
^~~~~~~~
Signed-off-by: Mikko Rapeli <redacted>
Cc: Emil Velikov <redacted>
Cc: Gabriel Laskar <redacted>
Cc: Russell King <redacted>
Cc: Rob Clark <redacted>
---
include/uapi/drm/armada_drm.h | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
From: Daniel Vetter <hidden> Date: 2017-08-07 09:47:40
On Sun, Aug 06, 2017 at 06:44:23PM +0200, Mikko Rapeli wrote:
These are defined in linux/types.h or drm/drm.h. Fixes
user space compilation errors like:
drm/armada_drm.h:26:2: error: unknown type name ‘uint32_t’
uint32_t handle;
^~~~~~~~
Signed-off-by: Mikko Rapeli <redacted>
Cc: Emil Velikov <redacted>
Cc: Gabriel Laskar <redacted>
Cc: Russell King <rmk+kernel-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org>
Cc: Rob Clark <redacted>
@@ -68,7 +68,7 @@ struct fsmap_head {};/* Size of an fsmap_head with room for nr records. */-staticinlinesize_t+staticinline__kernel_size_tfsmap_sizeof(unsignedintnr){
@@ -68,7 +68,7 @@ struct fsmap_head {};/* Size of an fsmap_head with room for nr records. */-staticinlinesize_t+staticinline__kernel_size_t
This is a static inline helper to assist in malloc calls. We don't pass
size_t to the kernel, so why is this necessary over, say,
#include <sys/types.h>
--D
@@ -68,7 +68,7 @@ struct fsmap_head {};/* Size of an fsmap_head with room for nr records. */-staticinlinesize_t+staticinline__kernel_size_t
This is a static inline helper to assist in malloc calls. We don't pass
size_t to the kernel, so why is this necessary over, say,
#include <sys/types.h>
Either way works, but including a system header from a kernel header
requires an additional "#ifndef __KERNEL__" check, so I think Miko's
variant is a little nicer.
Generally speaking, you also want to avoid including system headers
indirectly from kernel headers, as POSIX requires that including one
system header should not indirectly make symbols from other system
headers visible. I think this is not a problem here though, as no system
header should include linux/fsmap.h.
Arnd
@@ -68,7 +68,7 @@ struct fsmap_head {};/* Size of an fsmap_head with room for nr records. */-staticinlinesize_t+staticinline__kernel_size_t
This is a static inline helper to assist in malloc calls. We don't pass
size_t to the kernel, so why is this necessary over, say,
#include <sys/types.h>
Either way works, but including a system header from a kernel header
requires an additional "#ifndef __KERNEL__" check, so I think Miko's
variant is a little nicer.
Generally speaking, you also want to avoid including system headers
indirectly from kernel headers, as POSIX requires that including one
system header should not indirectly make symbols from other system
headers visible. I think this is not a problem here though, as no system
header should include linux/fsmap.h.
Sorry, I guess I was a little unclear about what I was asking -- I was
wondering why can't the userspace program include sys/types.h prior to
linux/fsmap.h? I wasn't proposing including C library headers in kernel
headers.
I think the patch author is pushing towards kernel headers never relying
on /anything/ in the system headers. For data structures being
exchanged with the kernel I agree, but the fsmap_sizeof result is never
passed to or received from the kernel; it exists purely for malloc
convenience.
--D
Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-api" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Mon, Aug 7, 2017 at 6:45 PM, Darrick J. Wong [off-list ref] wrote:
On Mon, Aug 07, 2017 at 06:01:43PM +0200, Arnd Bergmann wrote:
quoted
On Mon, Aug 7, 2017 at 5:54 PM, Darrick J. Wong [off-list ref] wrote:
quoted
On Sun, Aug 06, 2017 at 06:44:24PM +0200, Mikko Rapeli wrote:
Either way works, but including a system header from a kernel header
requires an additional "#ifndef __KERNEL__" check, so I think Miko's
variant is a little nicer.
Generally speaking, you also want to avoid including system headers
indirectly from kernel headers, as POSIX requires that including one
system header should not indirectly make symbols from other system
headers visible. I think this is not a problem here though, as no system
header should include linux/fsmap.h.
Sorry, I guess I was a little unclear about what I was asking -- I was
wondering why can't the userspace program include sys/types.h prior to
linux/fsmap.h? I wasn't proposing including C library headers in kernel
headers.
I think the patch author is pushing towards kernel headers never relying
on /anything/ in the system headers.
Right, and I think that is a good thing to have, because it allows us to
do better compile-time testing of the exported kernel headers.
For data structures being
exchanged with the kernel I agree, but the fsmap_sizeof result is never
passed to or received from the kernel; it exists purely for malloc
convenience.
Would you prefer making fsmap_sizeof a macro? That would also
make it possible to do static checking on the header without having
to resort to odd types.
Arnd
From: Darrick J. Wong <hidden> Date: 2017-08-08 23:08:51
On Mon, Aug 07, 2017 at 10:20:58PM +0200, Arnd Bergmann wrote:
On Mon, Aug 7, 2017 at 6:45 PM, Darrick J. Wong [off-list ref] wrote:
quoted
On Mon, Aug 07, 2017 at 06:01:43PM +0200, Arnd Bergmann wrote:
quoted
On Mon, Aug 7, 2017 at 5:54 PM, Darrick J. Wong [off-list ref] wrote:
quoted
On Sun, Aug 06, 2017 at 06:44:24PM +0200, Mikko Rapeli wrote:
Either way works, but including a system header from a kernel header
requires an additional "#ifndef __KERNEL__" check, so I think Miko's
variant is a little nicer.
Generally speaking, you also want to avoid including system headers
indirectly from kernel headers, as POSIX requires that including one
system header should not indirectly make symbols from other system
headers visible. I think this is not a problem here though, as no system
header should include linux/fsmap.h.
Sorry, I guess I was a little unclear about what I was asking -- I was
wondering why can't the userspace program include sys/types.h prior to
linux/fsmap.h? I wasn't proposing including C library headers in kernel
headers.
I think the patch author is pushing towards kernel headers never relying
on /anything/ in the system headers.
Right, and I think that is a good thing to have, because it allows us to
do better compile-time testing of the exported kernel headers.
quoted
For data structures being
exchanged with the kernel I agree, but the fsmap_sizeof result is never
passed to or received from the kernel; it exists purely for malloc
convenience.
Would you prefer making fsmap_sizeof a macro? That would also
make it possible to do static checking on the header without having
to resort to odd types.
Ick, no macros, please. :)
How about just change it to unsigned long long and call it a day?
--D
Arnd
--
To unsubscribe from this list: send the line "unsubscribe linux-api" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, Aug 9, 2017 at 1:08 AM, Darrick J. Wong [off-list ref] wrote:
On Mon, Aug 07, 2017 at 10:20:58PM +0200, Arnd Bergmann wrote:
quoted
On Mon, Aug 7, 2017 at 6:45 PM, Darrick J. Wong [off-list ref] wrote:
quoted
On Mon, Aug 07, 2017 at 06:01:43PM +0200, Arnd Bergmann wrote:
quoted
On Mon, Aug 7, 2017 at 5:54 PM, Darrick J. Wong [off-list ref] wrote:
quoted
On Sun, Aug 06, 2017 at 06:44:24PM +0200, Mikko Rapeli wrote:
Either way works, but including a system header from a kernel header
requires an additional "#ifndef __KERNEL__" check, so I think Miko's
variant is a little nicer.
Generally speaking, you also want to avoid including system headers
indirectly from kernel headers, as POSIX requires that including one
system header should not indirectly make symbols from other system
headers visible. I think this is not a problem here though, as no system
header should include linux/fsmap.h.
Sorry, I guess I was a little unclear about what I was asking -- I was
wondering why can't the userspace program include sys/types.h prior to
linux/fsmap.h? I wasn't proposing including C library headers in kernel
headers.
I think the patch author is pushing towards kernel headers never relying
on /anything/ in the system headers.
Right, and I think that is a good thing to have, because it allows us to
do better compile-time testing of the exported kernel headers.
quoted
For data structures being
exchanged with the kernel I agree, but the fsmap_sizeof result is never
passed to or received from the kernel; it exists purely for malloc
convenience.
Would you prefer making fsmap_sizeof a macro? That would also
make it possible to do static checking on the header without having
to resort to odd types.
Ick, no macros, please. :)
How about just change it to unsigned long long and call it a day?