diff options
author | Mark Rutland <mark.rutland@arm.com> | 2019-02-11 08:20:35 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2019-02-13 02:07:31 -0500 |
commit | 0cf264b3133dce56a60ca8b4335d1f76fe26870a (patch) | |
tree | 9afbe4db4847974c5f357fde4fd76f92aaa37b01 | |
parent | b14e77f89aca1c2763f65dc274b5837a185ab13f (diff) |
locking/atomics: Check atomic headers with sha1sum
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>
-rw-r--r-- | include/asm-generic/atomic-instrumented.h | 1 | ||||
-rw-r--r-- | include/asm-generic/atomic-long.h | 1 | ||||
-rw-r--r-- | include/linux/atomic-fallback.h | 1 | ||||
-rwxr-xr-x | scripts/atomic/check-atomics.sh | 26 | ||||
-rw-r--r-- | scripts/atomic/gen-atomics.sh | 20 |
5 files changed, 43 insertions, 6 deletions
diff --git a/include/asm-generic/atomic-instrumented.h b/include/asm-generic/atomic-instrumented.h index b8f5b35216e1..e8730c6b9fe2 100644 --- a/include/asm-generic/atomic-instrumented.h +++ b/include/asm-generic/atomic-instrumented.h | |||
@@ -1785,3 +1785,4 @@ atomic64_dec_if_positive(atomic64_t *v) | |||
1785 | }) | 1785 | }) |
1786 | 1786 | ||
1787 | #endif /* _ASM_GENERIC_ATOMIC_INSTRUMENTED_H */ | 1787 | #endif /* _ASM_GENERIC_ATOMIC_INSTRUMENTED_H */ |
1788 | // b29b625d5de9280f680e42c7be859b55b15e5f6a | ||
diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h index a833d385a70b..881c7e27af28 100644 --- a/include/asm-generic/atomic-long.h +++ b/include/asm-generic/atomic-long.h | |||
@@ -1010,3 +1010,4 @@ atomic_long_dec_if_positive(atomic_long_t *v) | |||
1010 | 1010 | ||
1011 | #endif /* CONFIG_64BIT */ | 1011 | #endif /* CONFIG_64BIT */ |
1012 | #endif /* _ASM_GENERIC_ATOMIC_LONG_H */ | 1012 | #endif /* _ASM_GENERIC_ATOMIC_LONG_H */ |
1013 | // 77558968132ce4f911ad53f6f52ce423006f6268 | ||
diff --git a/include/linux/atomic-fallback.h b/include/linux/atomic-fallback.h index 1c02c0112fbb..a7d240e465c0 100644 --- a/include/linux/atomic-fallback.h +++ b/include/linux/atomic-fallback.h | |||
@@ -2292,3 +2292,4 @@ atomic64_dec_if_positive(atomic64_t *v) | |||
2292 | #define atomic64_cond_read_relaxed(v, c) smp_cond_load_relaxed(&(v)->counter, (c)) | 2292 | #define atomic64_cond_read_relaxed(v, c) smp_cond_load_relaxed(&(v)->counter, (c)) |
2293 | 2293 | ||
2294 | #endif /* _LINUX_ATOMIC_FALLBACK_H */ | 2294 | #endif /* _LINUX_ATOMIC_FALLBACK_H */ |
2295 | // 25de4a2804d70f57e994fe3b419148658bb5378a | ||
diff --git a/scripts/atomic/check-atomics.sh b/scripts/atomic/check-atomics.sh index c30101cddf2d..cfa0c2f71c84 100755 --- a/scripts/atomic/check-atomics.sh +++ b/scripts/atomic/check-atomics.sh | |||
@@ -7,13 +7,27 @@ ATOMICDIR=$(dirname $0) | |||
7 | ATOMICTBL=${ATOMICDIR}/atomics.tbl | 7 | ATOMICTBL=${ATOMICDIR}/atomics.tbl |
8 | LINUXDIR=${ATOMICDIR}/../.. | 8 | LINUXDIR=${ATOMICDIR}/../.. |
9 | 9 | ||
10 | echo '' | sha1sum - > /dev/null 2>&1 | ||
11 | if [ $? -ne 0 ]; then | ||
12 | printf "sha1sum not available, skipping atomic header checks.\n" | ||
13 | exit 0 | ||
14 | fi | ||
15 | |||
10 | cat <<EOF | | 16 | cat <<EOF | |
11 | gen-atomic-instrumented.sh asm-generic/atomic-instrumented.h | 17 | asm-generic/atomic-instrumented.h |
12 | gen-atomic-long.sh asm-generic/atomic-long.h | 18 | asm-generic/atomic-long.h |
13 | gen-atomic-fallback.sh linux/atomic-fallback.h | 19 | linux/atomic-fallback.h |
14 | EOF | 20 | EOF |
15 | while read script header; do | 21 | while read header; do |
16 | if ! (${ATOMICDIR}/${script} ${ATOMICTBL} | diff - ${LINUXDIR}/include/${header} > /dev/null); then | 22 | OLDSUM="$(tail -n 1 ${LINUXDIR}/include/${header})" |
17 | printf "warning: include/${header} is out-of-date.\n" | 23 | OLDSUM="${OLDSUM#// }" |
24 | |||
25 | NEWSUM="$(head -n -1 ${LINUXDIR}/include/${header} | sha1sum)" | ||
26 | NEWSUM="${NEWSUM%% *}" | ||
27 | |||
28 | if [ "${OLDSUM}" != "${NEWSUM}" ]; then | ||
29 | printf "warning: generated include/${header} has been modified.\n" | ||
18 | fi | 30 | fi |
19 | done | 31 | done |
32 | |||
33 | exit 0 | ||
diff --git a/scripts/atomic/gen-atomics.sh b/scripts/atomic/gen-atomics.sh new file mode 100644 index 000000000000..27400b0cd732 --- /dev/null +++ b/scripts/atomic/gen-atomics.sh | |||
@@ -0,0 +1,20 @@ | |||
1 | #!/bin/sh | ||
2 | # SPDX-License-Identifier: GPL-2.0 | ||
3 | # | ||
4 | # Generate atomic headers | ||
5 | |||
6 | ATOMICDIR=$(dirname $0) | ||
7 | ATOMICTBL=${ATOMICDIR}/atomics.tbl | ||
8 | LINUXDIR=${ATOMICDIR}/../.. | ||
9 | |||
10 | cat <<EOF | | ||
11 | gen-atomic-instrumented.sh asm-generic/atomic-instrumented.h | ||
12 | gen-atomic-long.sh asm-generic/atomic-long.h | ||
13 | gen-atomic-fallback.sh linux/atomic-fallback.h | ||
14 | EOF | ||
15 | while read script header; do | ||
16 | ${ATOMICDIR}/${script} ${ATOMICTBL} > ${LINUXDIR}/include/${header} | ||
17 | HASH="$(sha1sum ${LINUXDIR}/include/${header})" | ||
18 | HASH="${HASH%% *}" | ||
19 | printf "// %s\n" "${HASH}" >> ${LINUXDIR}/include/${header} | ||
20 | done | ||