]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
locking/atomics: Check atomic headers with sha1sum
authorMark Rutland <mark.rutland@arm.com>
Mon, 11 Feb 2019 13:20:35 +0000 (13:20 +0000)
committerIngo Molnar <mingo@kernel.org>
Wed, 13 Feb 2019 07:07:31 +0000 (08:07 +0100)
We currently check the atomic headers at build-time to ensure they
haven't been modified directly, and these checks require regenerating
the headers in full. As this takes a few seconds, even when
parallelized, this is too slow to run for every kernel build.

Instead, we can generate a hash of each header as we generate them,
which we can cheaply check at build time (~0.16s for all headers).

This patch does so, updating headers with their hashes using the new
gen-atomics.sh script. As some users apparently build the kernel wihout
coreutils, lacking sha1sum, the checks are skipped in this case.
Presumably, most developers have a working coreutils installation.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Will Deacon <will.deacon@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: anders.roxell@linaro.org
Cc: linux-kernel@vger.kernel.rg
Cc: naresh.kamboju@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
include/asm-generic/atomic-instrumented.h
include/asm-generic/atomic-long.h
include/linux/atomic-fallback.h
scripts/atomic/check-atomics.sh
scripts/atomic/gen-atomics.sh [new file with mode: 0644]

index b8f5b35216e1963f4a98d9f9cb10346a238416e2..e8730c6b9fe2cf62d03652b5e92bf37461f9f05e 100644 (file)
@@ -1785,3 +1785,4 @@ atomic64_dec_if_positive(atomic64_t *v)
 })
 
 #endif /* _ASM_GENERIC_ATOMIC_INSTRUMENTED_H */
+// b29b625d5de9280f680e42c7be859b55b15e5f6a
index a833d385a70b9ed43a03c3f68eefab5827ebd530..881c7e27af284e46d6fa5c057d93316be2796faf 100644 (file)
@@ -1010,3 +1010,4 @@ atomic_long_dec_if_positive(atomic_long_t *v)
 
 #endif /* CONFIG_64BIT */
 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
+// 77558968132ce4f911ad53f6f52ce423006f6268
index 1c02c0112fbb738b321d186cd23fa61158fb644e..a7d240e465c07f2c060a3c1d2e1cc363ce6aee9a 100644 (file)
@@ -2292,3 +2292,4 @@ atomic64_dec_if_positive(atomic64_t *v)
 #define atomic64_cond_read_relaxed(v, c) smp_cond_load_relaxed(&(v)->counter, (c))
 
 #endif /* _LINUX_ATOMIC_FALLBACK_H */
+// 25de4a2804d70f57e994fe3b419148658bb5378a
index c30101cddf2d2fd6a69286120c25a5c39f69b118..cfa0c2f71c84685669d4985752d519afa504a968 100755 (executable)
@@ -7,13 +7,27 @@ ATOMICDIR=$(dirname $0)
 ATOMICTBL=${ATOMICDIR}/atomics.tbl
 LINUXDIR=${ATOMICDIR}/../..
 
+echo '' | sha1sum - > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+       printf "sha1sum not available, skipping atomic header checks.\n"
+       exit 0
+fi
+
 cat <<EOF |
-gen-atomic-instrumented.sh      asm-generic/atomic-instrumented.h
-gen-atomic-long.sh              asm-generic/atomic-long.h
-gen-atomic-fallback.sh          linux/atomic-fallback.h
+asm-generic/atomic-instrumented.h
+asm-generic/atomic-long.h
+linux/atomic-fallback.h
 EOF
-while read script header; do
-       if ! (${ATOMICDIR}/${script} ${ATOMICTBL} | diff - ${LINUXDIR}/include/${header} > /dev/null); then
-               printf "warning: include/${header} is out-of-date.\n"
+while read header; do
+       OLDSUM="$(tail -n 1 ${LINUXDIR}/include/${header})"
+       OLDSUM="${OLDSUM#// }"
+
+       NEWSUM="$(head -n -1 ${LINUXDIR}/include/${header} | sha1sum)"
+       NEWSUM="${NEWSUM%% *}"
+
+       if [ "${OLDSUM}" != "${NEWSUM}" ]; then
+               printf "warning: generated include/${header} has been modified.\n"
        fi
 done
+
+exit 0
diff --git a/scripts/atomic/gen-atomics.sh b/scripts/atomic/gen-atomics.sh
new file mode 100644 (file)
index 0000000..27400b0
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+#
+# Generate atomic headers
+
+ATOMICDIR=$(dirname $0)
+ATOMICTBL=${ATOMICDIR}/atomics.tbl
+LINUXDIR=${ATOMICDIR}/../..
+
+cat <<EOF |
+gen-atomic-instrumented.sh      asm-generic/atomic-instrumented.h
+gen-atomic-long.sh              asm-generic/atomic-long.h
+gen-atomic-fallback.sh          linux/atomic-fallback.h
+EOF
+while read script header; do
+       ${ATOMICDIR}/${script} ${ATOMICTBL} > ${LINUXDIR}/include/${header}
+       HASH="$(sha1sum ${LINUXDIR}/include/${header})"
+       HASH="${HASH%% *}"
+       printf "// %s\n" "${HASH}" >> ${LINUXDIR}/include/${header}
+done