From fbf69fdadb5d045f0477d173def2e15843140efe Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Mon, 24 Oct 2022 13:31:18 +0100 Subject: [PATCH] lisa._kmod: Workaround broken atomic headers in IKHEADERS FIX Headers found at /sys/kheaders.tar.xz generated when CONFIG_IKHEADERS=y contain a broken version of the include/linux/atomic/*. headers. They embed a sha1sum of the file on their last line, but kernel/gen_kheaders.sh strips some multiline comments from the file, changing the SHA1. Work around the issue by updating the SHA1 in the file. --- lisa/_kmod.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lisa/_kmod.py b/lisa/_kmod.py index 7c767dd5a..40afb2f9f 100644 --- a/lisa/_kmod.py +++ b/lisa/_kmod.py @@ -120,7 +120,6 @@ import re import functools import bisect import threading -import hashlib import itertools import logging import datetime @@ -817,6 +816,7 @@ class KernelTree(Loggable, SerializeViaConstructor): @classmethod def _prepare_tree(cls, path, make_vars, build_env, apply_overlays, overlay_backend): + path = Path(path) logger = cls.get_logger() _make_vars = [ f'{name}={val}' @@ -853,6 +853,26 @@ class KernelTree(Loggable, SerializeViaConstructor): bind_paths = {path: path} + def fixup_kernel_tree(): + # TODO: re-assess + + # The headers in /sys/kheaders.tar.xz generated by + # CONFIG_IKHEADERS=y are broken since kernel/gen_kheaders.sh strip + # some comments from the file. KBuild then proceeds on checking the + # checksum and the check fails. This used to be a simple warning, + # but has now been turned into an error in recent kernels. + # We remove the SHA1 from the file so that the check is skipped. + for _path in (path / 'include' / 'linux' / 'atomic').iterdir(): + content = _path.read_bytes() + lines = [line for line in content.split(b'\n') if line] + if lines and lines[-1].lstrip().startswith(b'//'): + # Remove the last line, containing the sha1 + content = b'\n'.join(lines[:-1]) + b'\n' + sha1 = hashlib.sha1(content).hexdigest() + content += b'// ' + sha1.encode('ascii') + b'\n' + _path.write_bytes(content) + + if build_env == 'alpine': @contextlib.contextmanager def cmd_cm(cmds): @@ -874,11 +894,14 @@ class KernelTree(Loggable, SerializeViaConstructor): # Apply the overlays before running make, so that it sees the # correct headers and conf etc apply_overlays() + fixup_kernel_tree() _subprocess_log(post, logger=logger, level=logging.DEBUG) + # Re-apply the overlays, since we could have overwritten important # things, such as include/linux/vermagic.h apply_overlays() + fixup_kernel_tree() @classmethod -- GitLab