linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ricardo Koller <ricarkol@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Sean Christopherson <seanjc@google.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com,
	Ricardo Koller <ricarkol@google.com>
Subject: [PATCH v2 1/6] KVM: selftests: Add kernel headers sync check
Date: Wed, 28 Apr 2021 12:37:51 -0700	[thread overview]
Message-ID: <20210428193756.2110517-2-ricarkol@google.com> (raw)
In-Reply-To: <20210428193756.2110517-1-ricarkol@google.com>

Add a script that checks if header files under /tools match their
original version in the kernel. Perform the check at the end of the
make, so warnings are shown after all tests are built.  Note that
the build is _not_ aborted if any diff check fails.

The list of header files to check was obtained from the union of the
output of these (at tools/testing/selftests/kvm):

  CFLAGS="-H" make ARCH=x86_64 2>&1 | grep '.h$' | grep 'tools'
  CFLAGS="-H" make ARCH=arm64 CC=aarch64-linux-gnu-gcc-10 2>&1 | grep '.h$' | grep 'tools'

and then by manually removing the header files that were updated on the
tools/ side but not on the kernel side. There is no point in checking
for these as their changes will not be synced back to the kernel. Here
are the removed headers and the first commit that made them drift apart
from their original copies:

  tools/include/linux/kernel.h
  d0761e37fe3 perf tools: Uninline scnprintf() and vscnprint()

  tools/include/linux/list.h
  5602ea09c19 tools include: Add compiler.h to list.h

  tools/include/linux/poison.h
  6ae8eefc6c8 tools include: Do not use poison with C++

  tools/include/linux/types.h
  70ba6b8f975 tools include: add __aligned_u64 to types.h

  tools/include/asm-generic/bitsperlong.h
  2a00f026a15 tools: Fix up BITS_PER_LONG setting

Based on tools/perf/check-headers.sh.

Signed-off-by: Ricardo Koller <ricarkol@google.com>
---
 tools/testing/selftests/kvm/Makefile         |  2 +
 tools/testing/selftests/kvm/check-headers.sh | 55 ++++++++++++++++++++
 2 files changed, 57 insertions(+)
 create mode 100755 tools/testing/selftests/kvm/check-headers.sh

diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
index ea5c42841307..69dc4f5e9ee3 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -147,6 +147,8 @@ $(OUTPUT)/libkvm.a: $(LIBKVM_OBJS)
 
 x := $(shell mkdir -p $(sort $(dir $(TEST_GEN_PROGS))))
 all: $(STATIC_LIBS)
+	@./check-headers.sh
+
 $(TEST_GEN_PROGS): $(STATIC_LIBS)
 
 cscope: include_paths = $(LINUX_TOOL_INCLUDE) $(LINUX_HDR_PATH) include lib ..
diff --git a/tools/testing/selftests/kvm/check-headers.sh b/tools/testing/selftests/kvm/check-headers.sh
new file mode 100755
index 000000000000..c21a69b52bcd
--- /dev/null
+++ b/tools/testing/selftests/kvm/check-headers.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+#
+# Adapted from tools/perf/check-headers.sh
+
+FILES='
+arch/x86/include/asm/msr-index.h
+include/linux/bits.h
+include/linux/const.h
+include/uapi/asm-generic/bitsperlong.h
+include/uapi/linux/const.h
+include/vdso/bits.h
+include/vdso/const.h
+'
+
+check_2 () {
+  file1=$1
+  file2=$2
+
+  shift
+  shift
+
+  cmd="diff $* $file1 $file2 > /dev/null"
+
+  test -f $file2 && {
+    eval $cmd || {
+      echo "Warning: Kernel header at '$file1' differs from latest version at '$file2'" >&2
+      echo diff -u $file1 $file2
+    }
+  }
+}
+
+check () {
+  file=$1
+
+  shift
+
+  check_2 tools/$file $file $*
+}
+
+# Check if we are at the right place (we have the kernel headers)
+# (tools/testing/selftests/kvm/../../../../include)
+test -d ../../../../include || exit 0
+
+cd ../../../..
+
+# simple diff check
+for i in $FILES; do
+  check $i -B
+done
+
+# diff with extra ignore lines
+check include/linux/build_bug.h       '-I "^#\(ifndef\|endif\)\( \/\/\)* static_assert$"'
+
+cd tools/testing/selftests/kvm
-- 
2.31.1.498.g6c1eba8ee3d-goog


  reply	other threads:[~2021-04-28 19:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-28 19:37 [PATCH v2 0/6] KVM: x86: Use kernel x86 cpuid utilities in KVM selftests Ricardo Koller
2021-04-28 19:37 ` Ricardo Koller [this message]
2021-04-28 19:37 ` [PATCH v2 2/6] tools headers x86: Update bitsperlong.h in tools Ricardo Koller
2021-04-28 19:37 ` [PATCH v2 3/6] x86/cpu: Expose CPUID regs, leaf and index definitions to tools Ricardo Koller
2021-04-28 19:37 ` [PATCH v2 4/6] tools headers x86: Copy cpuid helpers from the kernel Ricardo Koller
2021-04-28 19:37 ` [PATCH v2 5/6] KVM: selftests: Introduce utilities for checking x86 features Ricardo Koller
2021-04-28 19:37 ` [PATCH v2 6/6] KVM: selftests: Use kernel x86 cpuid features format Ricardo Koller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210428193756.2110517-2-ricarkol@google.com \
    --to=ricarkol@google.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=hpa@zytor.com \
    --cc=jmattson@google.com \
    --cc=jolsa@redhat.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).