Skip to content

Commit 6ec8dcf

Browse files
authored
[linux headers] Update build to support >= 6.3 kernels. Add 6.6 headers to fix ARM Container OS issue (#2036)
Summary: Update linux_headers_image to support kernels >= 6.3. Add 6.6 headers to fix ARM Container OS issue #2035 reported an issue where the socket tracer fails to run on a openSUSE MicroOS instance running a 6.11 kernel. This change updates our header building process to support >= 6.3 kernels since [upstream](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=05e96e96a315fa49faca4da2aedd1761a218b616) broke the source building process from non git trees (binary builds still work outside of git trees). > Going forward, building source packages is only possible in a git-managed tree. Building binary packages does not require git. This also adds 6.6.x linux headers to the build. A recent bug report identified that recent ARM Container OS clusters fail to start the socket tracer without the 6.6.x headers. COS doesn't have a distro provided linux headers package, which means these installs are dependent on the pre-packaged headers. Relevant Issues: #2035 Type of change: /kind compatibility Test Plan: Verified the following - [x] Ran full build without upload - [x] Built x86_64 and arm64 kernels pre and post 6.3 - [x] That the previous dockerfile and pre 6.3 dockerfile is same as before ``` $ git diff main:tools/docker/linux_headers_image/Dockerfile tools/docker/linux_headers_image/Dockerfile.bionic $ ``` --------- Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
1 parent 54f8675 commit 6ec8dcf

File tree

4 files changed

+150
-62
lines changed

4 files changed

+150
-62
lines changed

src/stirling/BUILD.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ pl_cc_library(
6868
# Used by stirling runtime to install linux headers on hosts having no Linux headers pre-installed.
6969
#
7070
# Note that each linux header tarball is ~15MB compressed and ~230MB uncompressed.
71-
# Trimmed versions are ~8MB compressed and ~110MB uncompressed.
72-
# These are all trimmed versions, so we have 8 * 12 = 96 MB of headers.
71+
# Trimmed versions are ~8-11MB (8.6 MB avg) compressed and ~45MB uncompressed.
72+
# These are all trimmed versions, so we have 9MB * 29 = ~250 MB of headers.
7373
stirling_linux_headers_tarballs = select({
7474
"@platforms//cpu:aarch64": ["@linux_headers_merged_arm64_tar_gz//file:file"],
7575
"@platforms//cpu:x86_64": ["@linux_headers_merged_x86_64_tar_gz//file:file"],

tools/docker/Makefile

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -73,40 +73,44 @@ SYSROOT_CREATOR_IMAGE_TAG := sysroot-creator-$(SYSROOT_REV)
7373
## Linux image parameters
7474
LINUX_HEADER_BUILD_DIR := $(BUILD_DIR)/linux_headers
7575
LINUX_HEADER_ASSETS_BUILD_DIR := $(LINUX_HEADER_BUILD_DIR)/assets
76-
LINUX_KERNEL_VERSIONS := 4.14.304 \
76+
LINUX_KERNEL_VERSIONS := 4.14.309 \
7777
4.15.18 \
7878
4.16.18 \
7979
4.17.19 \
8080
4.18.20 \
81-
4.19.271 \
81+
4.19.325 \
8282
4.20.17 \
8383
5.0.21 \
8484
5.1.21 \
8585
5.2.21 \
8686
5.3.18 \
87-
5.4.230 \
87+
5.4.293 \
8888
5.5.19 \
8989
5.6.19 \
9090
5.7.19 \
9191
5.8.18 \
9292
5.9.16 \
93-
5.10.165 \
93+
5.10.237 \
9494
5.11.22 \
9595
5.12.19 \
9696
5.13.19 \
9797
5.14.21 \
98-
5.15.90 \
98+
5.15.181 \
9999
5.16.20 \
100100
5.17.15 \
101101
5.18.19 \
102102
5.19.17 \
103103
6.0.19 \
104-
6.1.8
104+
6.1.137 \
105+
6.6.89
106+
107+
LINUX_HEADER_TEMPLATE := linux-headers-%.tar.gz
108+
LINUX_HEADER_X86_64_TARGETS = $(addprefix $(LINUX_HEADER_ASSETS_BUILD_DIR)/, \
109+
$(patsubst %,$(subst x86_64,%,$(LINUX_HEADER_TEMPLATE)), $(addprefix x86_64-,$(LINUX_KERNEL_VERSIONS))))
110+
111+
LINUX_HEADER_ARM64_TARGETS = $(addprefix $(LINUX_HEADER_ASSETS_BUILD_DIR)/, \
112+
$(patsubst %,$(subst arm64,%,$(LINUX_HEADER_TEMPLATE)), $(addprefix arm64-,$(LINUX_KERNEL_VERSIONS))))
105113

106-
LINUX_HEADER_X86_64_TEMPLATE := linux-headers-x86_64-%.tar.gz
107-
LINUX_HEADER_ARM64_TEMPLATE := linux-headers-arm64-%.tar.gz
108-
LINUX_HEADER_X86_64_TARGETS = $(addprefix $(LINUX_HEADER_ASSETS_BUILD_DIR)/, $(patsubst %,$(LINUX_HEADER_X86_64_TEMPLATE), $(LINUX_KERNEL_VERSIONS)))
109-
LINUX_HEADER_ARM64_TARGETS = $(addprefix $(LINUX_HEADER_ASSETS_BUILD_DIR)/, $(patsubst %,$(LINUX_HEADER_ARM64_TEMPLATE), $(LINUX_KERNEL_VERSIONS)))
110114
LINUX_HEADERS_X86_64_MERGED_FILE := $(LINUX_HEADER_BUILD_DIR)/linux-headers-merged-x86_64-$(LINUX_HEADERS_REV).tar.gz
111115
LINUX_HEADERS_ARM64_MERGED_FILE := $(LINUX_HEADER_BUILD_DIR)/linux-headers-merged-arm64-$(LINUX_HEADERS_REV).tar.gz
112116
LINUX_HEADERS_GS_PATH := gs://pixie-dev-public/linux-headers/$(LINUX_HEADERS_REV)
@@ -205,26 +209,34 @@ upload_graalvm_archive: build_graalvm_archive_image
205209
##############################################
206210
# Linux Headers Build
207211
##############################################
208-
$(LINUX_HEADER_ASSETS_BUILD_DIR)/linux-headers-x86_64-%.tar.gz: linux_headers_image/Dockerfile linux_headers_image/x86_64_config
209-
ifndef LINUX_HEADERS_REV
210-
$(error set LINUX_HEADERS_REV to a valid value)
211-
endif
212-
@mkdir -p $(@D)
213-
linux_headers_image_tag="gcr.io/pixie-oss/pixie-dev-public:$*-$(LINUX_HEADERS_REV)"; \
214-
$(DOCKER) build --build-arg KERN_VERSION=$* --build-arg ARCH=x86_64 linux_headers_image -t "$${linux_headers_image_tag}" && \
215-
$(DOCKER) run --rm -v $(PWD)/$(LINUX_HEADER_ASSETS_BUILD_DIR):/output "$${linux_headers_image_tag}"
216-
217-
$(LINUX_HEADER_ASSETS_BUILD_DIR)/linux-headers-arm64-%.tar.gz: linux_headers_image/Dockerfile linux_headers_image/arm64_config
212+
LINUX_HEADERS_BASE_PRE_v6_3 := ubuntu:18.04@sha256:152dc042452c496007f07ca9127571cb9c29697f42acbfad72324b2bb2e43c98
213+
LINUX_HEADERS_BASE_POST_v6_3 := ubuntu:20.04@sha256:8feb4d8ca5354def3d8fce243717141ce31e2c428701f6682bd2fafe15388214
214+
$(LINUX_HEADER_ASSETS_BUILD_DIR)/linux-headers-%.tar.gz: linux_headers_image/Dockerfile
218215
ifndef LINUX_HEADERS_REV
219216
$(error set LINUX_HEADERS_REV to a valid value)
220217
endif
221218
@mkdir -p $(@D)
222-
linux_headers_image_tag="gcr.io/pixie-oss/pixie-dev-public:$*-$(LINUX_HEADERS_REV)"; \
223-
$(DOCKER) build --build-arg KERN_VERSION=$* \
224-
--build-arg ARCH=arm64 \
225-
--build-arg CROSS_COMPILE=aarch64-linux-gnu- \
226-
linux_headers_image -t "$${linux_headers_image_tag}" && \
227-
$(DOCKER) run --rm -v $(PWD)/$(LINUX_HEADER_ASSETS_BUILD_DIR):/output "$${linux_headers_image_tag}"
219+
# Linux 6.3 and later has differences in the build process.
220+
# We need to use a different base image for these versions.
221+
ARCH=$$(echo $* | cut -d- -f1); \
222+
KVER=$$(echo $* | cut -d- -f2-); \
223+
KERN_MAJ=$$(echo $$KVER | cut -d. -f1); \
224+
KERN_MIN=$$(echo $$KVER | cut -d. -f2); \
225+
BASE_IMAGE=$$(echo $(LINUX_HEADERS_BASE_POST_v6_3)); \
226+
if [ $${KERN_MAJ} -lt 6 ] || { [ $${KERN_MAJ} -le 6 ] && [ $${KERN_MIN} -lt 3 ]; }; then \
227+
BASE_IMAGE=$$(echo $(LINUX_HEADERS_BASE_PRE_v6_3)); \
228+
fi; \
229+
CONFIG_FILE=$$(echo linux_headers_image/"$$ARCH"_config); \
230+
if [ ! -f $$CONFIG_FILE ]; then \
231+
echo "Unsupported ARCH=$$ARCH. Missing $$CONFIG_FILE"; exit 1; \
232+
fi; \
233+
linux_headers_image_tag="gcr.io/pixie-oss/pixie-dev-public:$$KVER-$(LINUX_HEADERS_REV)"; \
234+
$(DOCKER) build --build-arg BASE_IMAGE=$${BASE_IMAGE} linux_headers_image \
235+
-t "$${linux_headers_image_tag}" && \
236+
$(DOCKER) run --rm --env ARCH=$$ARCH \
237+
--env KERN_VERSION=$$KVER \
238+
$$( [ "$$ARCH" = "arm64" ] && echo "--env CROSS_COMPILE=aarch64-linux-gnu-" ) \
239+
-v $(PWD)/$(LINUX_HEADER_ASSETS_BUILD_DIR):/output "$${linux_headers_image_tag}"
228240

229241
$(LINUX_HEADERS_X86_64_MERGED_FILE): $(LINUX_HEADER_X86_64_TARGETS)
230242
tar -czf $@ -C $(LINUX_HEADER_ASSETS_BUILD_DIR) $(^F)

tools/docker/linux_headers_image/Dockerfile

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@
1414
#
1515
# SPDX-License-Identifier: Apache-2.0
1616

17-
FROM ubuntu:18.04@sha256:8aa9c2798215f99544d1ce7439ea9c3a6dfd82de607da1cec3a8a2fae005931b
17+
ARG BASE_IMAGE
18+
FROM ${BASE_IMAGE}
1819

1920
# Install required packages
21+
ENV DEBIAN_FRONTEND=noninteractive
22+
ENV KERN_VERSION=${KERN_VERSION}
23+
ENV ARCH=${ARCH}
24+
ENV CROSS_COMPILE=${CROSS_COMPILE}
25+
2026
RUN apt-get update
2127
RUN apt-get upgrade -y -q
2228
RUN apt-get install -y -q build-essential \
@@ -32,47 +38,18 @@ RUN apt-get install -y -q build-essential \
3238
binutils-aarch64-linux-gnu \
3339
gcc-aarch64-linux-gnu \
3440
dwarves \
41+
debhelper \
3542
python3
3643

37-
ARG KERN_VERSION
38-
39-
# Download Linux sources
40-
WORKDIR /px/src
41-
RUN KERN_MAJ="$(echo "${KERN_VERSION}" | cut -d'.' -f1)"; \
42-
wget -nv http://mirrors.edge.kernel.org/pub/linux/kernel/v${KERN_MAJ}.x/linux-${KERN_VERSION}.tar.gz
43-
RUN tar zxf linux-${KERN_VERSION}.tar.gz
44-
4544
WORKDIR /configs
4645
ADD x86_64_config /configs/x86_64
4746
ADD arm64_config /configs/arm64
4847

49-
ARG ARCH
50-
ARG CROSS_COMPILE
51-
52-
# Build Linux kernel
53-
WORKDIR /px/src/linux-${KERN_VERSION}
54-
RUN cp /configs/${ARCH} .config
55-
RUN make ARCH=${ARCH} olddefconfig
56-
RUN make ARCH=${ARCH} clean
57-
RUN make ARCH=${ARCH} -j $(nproc) deb-pkg LOCALVERSION=-pl
58-
59-
# Extract headers into a tarball
6048
WORKDIR /px
61-
RUN DEB_ARCH=$(echo ${ARCH} | sed 's/x86_64/amd64/g'); dpkg -x src/linux-headers-${KERN_VERSION}-pl_${KERN_VERSION}-pl-1_${DEB_ARCH}.deb .
6249

63-
# Remove broken symlinks
64-
RUN find usr/src/linux-headers-${KERN_VERSION}-pl -xtype l -exec rm {} +
50+
ADD build_linux_headers.sh /px/build_linux_headers.sh
6551

66-
# Remove uneeded files to reduce size
67-
# Keep only:
68-
# - usr/src/linux-headers-x.x.x-pl/include
69-
# - usr/src/linux-headers-x.x.x-pl/arch/${ARCH}
70-
# This reduces the size by a little over 2x.
71-
RUN rm -rf usr/share
72-
RUN find usr/src/linux-headers-${KERN_VERSION}-pl -maxdepth 1 -mindepth 1 ! -name include ! -name arch -type d \
73-
-exec rm -rf {} +
74-
RUN find usr/src/linux-headers-${KERN_VERSION}-pl/arch -maxdepth 1 -mindepth 1 ! -name $(echo ${ARCH} | sed 's/x86_64/x86/g') -type d -exec rm -rf {} +
75-
RUN tar zcf linux-headers-${ARCH}-${KERN_VERSION}.tar.gz usr
52+
RUN chmod +x /px/build_linux_headers.sh
7653

7754
VOLUME /output
78-
CMD ["sh", "-c", "cp linux-headers-*.tar.gz /output/"]
55+
CMD ["sh", "-c", "/px/build_linux_headers.sh /px ${KERN_VERSION} ${ARCH} /output"]
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/bin/bash
2+
3+
# Copyright 2018- The Pixie Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# SPDX-License-Identifier: Apache-2.0
18+
19+
usage() {
20+
echo "Usage: $0 [workspace] [kernel_version] [arch] [output_dir]"
21+
echo "Example: $0 /px 5.4.0-42-generic x86_64 /output"
22+
echo "If cross-compiling, set the CROSS_COMPILE environment variable to the cross-compiler prefix."
23+
}
24+
25+
if [ "$#" -ne 4 ]; then
26+
echo "Invalid number of arguments. Expected 4, but received $# ($*)"
27+
usage
28+
exit 1
29+
fi
30+
31+
WORKSPACE=$1
32+
KERN_VERSION=$2
33+
ARCH=$3
34+
OUTPUT_DIR=$4
35+
36+
if [ -z "${WORKSPACE}" ] || [ -z "${KERN_VERSION}" ] || [ -z "${ARCH}" ] || [ -z "${OUTPUT_DIR}" ]; then
37+
usage
38+
exit 1
39+
fi
40+
41+
if [ "${ARCH}" != "$(uname -m)" ]; then
42+
if [ -z "${CROSS_COMPILE}" ]; then
43+
echo "CROSS_COMPILE is not set. Please set it to the cross-compiler prefix."
44+
exit 1
45+
fi
46+
fi
47+
48+
mkdir -p "${WORKSPACE}"/src
49+
pushd "${WORKSPACE}"/src || exit
50+
51+
KERN_MAJ=$(echo "${KERN_VERSION}" | cut -d'.' -f1);
52+
KERN_MIN=$(echo "${KERN_VERSION}" | cut -d'.' -f2);
53+
wget -nv http://mirrors.edge.kernel.org/pub/linux/kernel/v"${KERN_MAJ}".x/linux-"${KERN_VERSION}".tar.gz
54+
55+
tar zxf linux-"${KERN_VERSION}".tar.gz
56+
57+
pushd linux-"${KERN_VERSION}" || exit
58+
59+
cp /configs/"${ARCH}" .config
60+
make ARCH="${ARCH}" olddefconfig
61+
make ARCH="${ARCH}" clean
62+
63+
LOCALVERSION="-pl"
64+
65+
DEB_ARCH="${ARCH//x86_64/amd64}"
66+
# binary builds are required for non git trees after linux v6.3 (inclusive).
67+
# The .deb file suffix is also different.
68+
TARGET='bindeb-pkg'
69+
DEB_SUFFIX="-1_${DEB_ARCH}.deb"
70+
if [ "${KERN_MAJ}" -lt 6 ] || { [ "${KERN_MAJ}" -le 6 ] && [ "${KERN_MIN}" -lt 3 ]; }; then
71+
TARGET='deb-pkg'
72+
DEB_SUFFIX="${LOCALVERSION}-1_${DEB_ARCH}.deb"
73+
fi
74+
echo "Building ${TARGET} for ${KERN_VERSION}${LOCALVERSION} (${ARCH})"
75+
76+
make ARCH="${ARCH}" -j "$(nproc)" "${TARGET}" LOCALVERSION="${LOCALVERSION}"
77+
78+
popd || exit
79+
popd || exit
80+
81+
# Extract headers into a tarball
82+
dpkg -x src/linux-headers-"${KERN_VERSION}${LOCALVERSION}_${KERN_VERSION}${DEB_SUFFIX}" .
83+
84+
# Remove broken symlinks
85+
find usr/src/linux-headers-"${KERN_VERSION}${LOCALVERSION}" -xtype l -exec rm {} +
86+
87+
# Remove uneeded files to reduce size
88+
# Keep only:
89+
# - usr/src/linux-headers-x.x.x-pl/include
90+
# - usr/src/linux-headers-x.x.x-pl/arch/${ARCH}
91+
# This reduces the size by a little over 2x.
92+
rm -rf usr/share
93+
find usr/src/linux-headers-"${KERN_VERSION}${LOCALVERSION}" -maxdepth 1 -mindepth 1 ! -name include ! -name arch -type d \
94+
-exec rm -rf {} +
95+
find usr/src/linux-headers-"${KERN_VERSION}${LOCALVERSION}"/arch -maxdepth 1 -mindepth 1 ! -name "${ARCH//x86_64/x86}" -type d -exec rm -rf {} +
96+
97+
tar zcf linux-headers-"${ARCH}"-"${KERN_VERSION}".tar.gz usr
98+
99+
cp linux-headers-*.tar.gz "${OUTPUT_DIR}"/

0 commit comments

Comments
 (0)