| 1 |
# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
|
| 4 |
|
| 5 |
import dataclasses |
| 6 |
import inspect |
| 7 |
import os |
| 8 |
from pathlib import Path |
| 9 |
import subprocess |
| 10 |
from typing import Dict, Mapping, NamedTuple, Optional, Sequence, Union |
| 11 |
|
| 12 |
from _drgn_util.platform import NORMALIZED_MACHINE_NAME |
| 13 |
from util import KernelVersion, out_of_date |
| 14 |
|
| 15 |
# Kernel versions that we run tests on and therefore support. Keep this in sync |
| 16 |
# with docs/support_matrix.rst. |
| 17 |
SUPPORTED_KERNEL_VERSIONS = ( |
| 18 |
"7.1", |
| 19 |
"7.0", |
| 20 |
"6.19", |
| 21 |
"6.18", |
| 22 |
"6.17", |
| 23 |
"6.16", |
| 24 |
"6.15", |
| 25 |
"6.14", |
| 26 |
"6.13", |
| 27 |
"6.12", |
| 28 |
"6.11", |
| 29 |
"6.10", |
| 30 |
"6.9", |
| 31 |
"6.8", |
| 32 |
"6.7", |
| 33 |
"6.6", |
| 34 |
"6.5", |
| 35 |
"6.4", |
| 36 |
"6.3", |
| 37 |
"6.2", |
| 38 |
"6.1", |
| 39 |
"6.0", |
| 40 |
"5.19", |
| 41 |
"5.18", |
| 42 |
"5.17", |
| 43 |
"5.16", |
| 44 |
"5.15", |
| 45 |
"5.14", |
| 46 |
"5.13", |
| 47 |
"5.12", |
| 48 |
"5.11", |
| 49 |
"5.10", |
| 50 |
"5.4", |
| 51 |
"4.19", |
| 52 |
"4.14", |
| 53 |
"4.9", |
| 54 |
) |
| 55 |
|
| 56 |
KERNEL_ORG_COMPILER_VERSION = "12.5.0" |
| 57 |
|
| 58 |
|
| 59 |
BASE_KCONFIG = """ |
| 60 |
CONFIG_EXPERT=y |
| 61 |
CONFIG_MODULES=y |
| 62 |
CONFIG_MODULE_UNLOAD=y |
| 63 |
CONFIG_CC_OPTIMIZE_FOR_SIZE=y |
| 64 |
|
| 65 |
# We run the tests in KVM. |
| 66 |
CONFIG_HYPERVISOR_GUEST=y |
| 67 |
CONFIG_KVM_GUEST=y |
| 68 |
CONFIG_PARAVIRT=y |
| 69 |
CONFIG_PARAVIRT_SPINLOCKS=y |
| 70 |
|
| 71 |
# Minimum requirements for vmtest. |
| 72 |
CONFIG_9P_FS=y |
| 73 |
CONFIG_DEVTMPFS=y |
| 74 |
CONFIG_INET=y |
| 75 |
CONFIG_NET=y |
| 76 |
CONFIG_NETWORK_FILESYSTEMS=y |
| 77 |
CONFIG_NET_9P=y |
| 78 |
CONFIG_NET_9P_VIRTIO=y |
| 79 |
CONFIG_OVERLAY_FS=y |
| 80 |
CONFIG_PCI=y |
| 81 |
CONFIG_PROC_FS=y |
| 82 |
CONFIG_SYSFS=y |
| 83 |
CONFIG_TMPFS=y |
| 84 |
CONFIG_TMPFS_XATTR=y |
| 85 |
CONFIG_VIRTIO_BLK=y |
| 86 |
CONFIG_VIRTIO_CONSOLE=y |
| 87 |
CONFIG_VIRTIO_PCI=y |
| 88 |
CONFIG_HW_RANDOM=m |
| 89 |
CONFIG_HW_RANDOM_VIRTIO=m |
| 90 |
|
| 91 |
# Lots of things expect Unix sockets. |
| 92 |
CONFIG_UNIX=y |
| 93 |
|
| 94 |
# drgn needs debug info. |
| 95 |
CONFIG_DEBUG_KERNEL=y |
| 96 |
CONFIG_DEBUG_INFO=y |
| 97 |
CONFIG_DEBUG_INFO_DWARF4=y |
| 98 |
|
| 99 |
# For testing live kernel debugging with /proc/kcore. |
| 100 |
CONFIG_PROC_KCORE=y |
| 101 |
# drgn needs /proc/kallsyms in some cases. Some test cases also need it. |
| 102 |
CONFIG_KALLSYMS=y |
| 103 |
CONFIG_KALLSYMS_ALL=y |
| 104 |
|
| 105 |
# For testing kernel core dumps with /proc/vmcore. |
| 106 |
CONFIG_CRASH_DUMP=y |
| 107 |
CONFIG_PROC_VMCORE=y |
| 108 |
CONFIG_KEXEC=y |
| 109 |
CONFIG_KEXEC_FILE=y |
| 110 |
# Needed for CONFIG_KEXEC_FILE. |
| 111 |
CONFIG_CRYPTO=y |
| 112 |
CONFIG_CRYPTO_SHA256=y |
| 113 |
|
| 114 |
# So that we can trigger a crash with /proc/sysrq-trigger. |
| 115 |
CONFIG_MAGIC_SYSRQ=y |
| 116 |
|
| 117 |
# For testing kernel core dumps from QEMU's dump-guest-memory command. |
| 118 |
CONFIG_FW_CFG_SYSFS=y |
| 119 |
|
| 120 |
# kmodify breakpoints need kprobes. |
| 121 |
CONFIG_KPROBES=y |
| 122 |
|
| 123 |
# For BPF tests. |
| 124 |
CONFIG_BPF_SYSCALL=y |
| 125 |
CONFIG_BPF_JIT=y |
| 126 |
CONFIG_BPF_JIT_ALWAYS_ON=y |
| 127 |
CONFIG_CGROUP_BPF=y |
| 128 |
CONFIG_DEBUG_INFO_BTF=y |
| 129 |
CONFIG_DEBUG_INFO_BTF_MODULES=y |
| 130 |
|
| 131 |
# For cgroup tests. |
| 132 |
CONFIG_CGROUPS=y |
| 133 |
# To select CONFIG_SOCK_CGROUP_DATA. (CONFIG_CGROUP_BPF also selects |
| 134 |
# CONFIG_SOCK_CGROUP_DATA, but that's only present since Linux kernel commit |
| 135 |
# 3007098494be ("cgroup: add support for eBPF programs") (in v4.10)). |
| 136 |
CONFIG_CGROUP_NET_CLASSID=y |
| 137 |
|
| 138 |
# For ipc tests. |
| 139 |
CONFIG_SYSVIPC=y |
| 140 |
|
| 141 |
# For kconfig tests. |
| 142 |
CONFIG_IKCONFIG=m |
| 143 |
CONFIG_IKCONFIG_PROC=y |
| 144 |
|
| 145 |
# For filesystem tests. |
| 146 |
CONFIG_BTRFS_FS=m |
| 147 |
# Don't waste time benchmarking in raid6_pq just to load the Btrfs module. |
| 148 |
CONFIG_RAID6_PQ_BENCHMARK=n |
| 149 |
CONFIG_EXT4_FS=m |
| 150 |
CONFIG_XFS_FS=m |
| 151 |
|
| 152 |
# For mm tests. |
| 153 |
CONFIG_ANON_VMA_NAME=y |
| 154 |
CONFIG_HUGETLBFS=y |
| 155 |
CONFIG_MEMORY_HOTPLUG=y |
| 156 |
CONFIG_MEMORY_HOTREMOVE=y |
| 157 |
|
| 158 |
# For net tests. |
| 159 |
CONFIG_NAMESPACES=y |
| 160 |
|
| 161 |
# For nodemask tests. |
| 162 |
CONFIG_NUMA=y |
| 163 |
|
| 164 |
# For sched tests. |
| 165 |
CONFIG_CGROUP_SCHED=y |
| 166 |
CONFIG_FAIR_GROUP_SCHED=y |
| 167 |
CONFIG_SCHEDSTATS=y |
| 168 |
|
| 169 |
# For slab allocator tests. |
| 170 |
CONFIG_SLAB_FREELIST_HARDENED=y |
| 171 |
|
| 172 |
# For Traffic Control tests. |
| 173 |
CONFIG_NET_SCHED=y |
| 174 |
CONFIG_NET_SCH_PRIO=m |
| 175 |
CONFIG_NET_SCH_SFQ=m |
| 176 |
CONFIG_NET_SCH_TBF=m |
| 177 |
CONFIG_NET_SCH_INGRESS=m |
| 178 |
CONFIG_NET_CLS_ACT=y |
| 179 |
CONFIG_NETDEVICES=y |
| 180 |
CONFIG_DUMMY=m |
| 181 |
|
| 182 |
# To enable CONFIG_XARRAY_MULTI for xarray tests. |
| 183 |
CONFIG_TRANSPARENT_HUGEPAGE=y |
| 184 |
CONFIG_READ_ONLY_THP_FOR_FS=y |
| 185 |
|
| 186 |
# For tools/fsrefs.py tests. |
| 187 |
CONFIG_BINFMT_MISC=m |
| 188 |
CONFIG_BLK_DEV_LOOP=m |
| 189 |
CONFIG_DNOTIFY=y |
| 190 |
CONFIG_FANOTIFY=y |
| 191 |
CONFIG_INOTIFY_USER=y |
| 192 |
CONFIG_PERF_EVENTS=y |
| 193 |
CONFIG_SWAP=y |
| 194 |
# We need to try two names here because of Linux kernel commit 6b0b7551428e |
| 195 |
# ("perf/core: Rename CONFIG_[UK]PROBE_EVENT to CONFIG_[UK]PROBE_EVENTS") (in |
| 196 |
# v4.11). |
| 197 |
CONFIG_UPROBE_EVENT=y |
| 198 |
CONFIG_UPROBE_EVENTS=y |
| 199 |
CONFIG_USER_NS=y |
| 200 |
""" |
| 201 |
|
| 202 |
|
| 203 |
@dataclasses.dataclass(frozen=True, eq=False) |
| 204 |
class KernelFlavor: |
| 205 |
name: str |
| 206 |
description: str |
| 207 |
config: str |
| 208 |
|
| 209 |
|
| 210 |
KERNEL_FLAVORS = { |
| 211 |
flavor.name: flavor |
| 212 |
for flavor in ( |
| 213 |
KernelFlavor( |
| 214 |
name="default", |
| 215 |
description="Default configuration", |
| 216 |
config=""" |
| 217 |
CONFIG_SMP=y |
| 218 |
CONFIG_SLUB=y |
| 219 |
# For slab tests. |
| 220 |
CONFIG_SLUB_DEBUG=y |
| 221 |
CONFIG_RANDOMIZE_BASE=y |
| 222 |
""", |
| 223 |
), |
| 224 |
KernelFlavor( |
| 225 |
name="alternative", |
| 226 |
description="SLAB allocator, module versioning, no KASLR", |
| 227 |
config=""" |
| 228 |
CONFIG_SMP=y |
| 229 |
CONFIG_SLAB=y |
| 230 |
# Linux kernel commit eb07c4f39c3e ("mm/slab: rename |
| 231 |
# CONFIG_SLAB to CONFIG_SLAB_DEPRECATED") (in v6.5) renamed the |
| 232 |
# option for SLAB. |
| 233 |
CONFIG_SLAB_DEPRECATED=y |
| 234 |
# Linux kernel commit 16a1d968358a ("mm/slab: remove mm/slab.c |
| 235 |
# and slab_def.h") (in v6.8) removed SLAB. Test this |
| 236 |
# non-default SLUB option instead. |
| 237 |
CONFIG_SLUB_CPU_PARTIAL=n |
| 238 |
CONFIG_RANDOMIZE_BASE=n |
| 239 |
|
| 240 |
# Options that require additional metadata for kmodify. |
| 241 |
CONFIG_MEM_ALLOC_PROFILING=y |
| 242 |
CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT=y |
| 243 |
CONFIG_MODVERSIONS=y |
| 244 |
""", |
| 245 |
), |
| 246 |
KernelFlavor( |
| 247 |
name="tiny", |
| 248 |
description="no SMP, no PREEMPT, no KASLR, and SLUB_TINY or SLOB allocator", |
| 249 |
config=""" |
| 250 |
CONFIG_SMP=n |
| 251 |
CONFIG_SLOB=y |
| 252 |
# Linux kernel commit 149b6fa228ed ("mm, slob: rename CONFIG_SLOB to |
| 253 |
# CONFIG_SLOB_DEPRECATED") (in v6.2) renamed the option for SLOB. |
| 254 |
CONFIG_SLOB_DEPRECATED=y |
| 255 |
# Linux kernel commit c9929f0e344a ("mm/slob: remove |
| 256 |
# CONFIG_SLOB") (in v6.4) removed SLOB. Use SLUB_TINY instead, |
| 257 |
# which was introduced in Linux kernel commit e240e53ae0ab |
| 258 |
# ("mm, slub: add CONFIG_SLUB_TINY") (in v6.2). |
| 259 |
CONFIG_SLUB_TINY=y |
| 260 |
# Cover the case of disabling this feature on kernel versions |
| 261 |
# that support it. |
| 262 |
CONFIG_ANON_VMA_NAME=n |
| 263 |
# CONFIG_PREEMPT_DYNAMIC is not set |
| 264 |
CONFIG_PREEMPT_NONE=y |
| 265 |
# !PREEMPTION && !SMP will also select TINY_RCU. |
| 266 |
CONFIG_RANDOMIZE_BASE=n |
| 267 |
""", |
| 268 |
), |
| 269 |
) |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
@dataclasses.dataclass(frozen=True, eq=False) |
| 274 |
class Architecture: |
| 275 |
# Architecture name. This matches the names used by |
| 276 |
# _drgn_util.platform.NORMALIZED_MACHINE_NAME and qemu-system-$arch_name. |
| 277 |
name: str |
| 278 |
# Value of ARCH variable to build the Linux kernel. |
| 279 |
kernel_arch: str |
| 280 |
# Directory under arch/ in the Linux kernel source tree. |
| 281 |
kernel_srcarch: str |
| 282 |
# Name of the architecture in Debian. |
| 283 |
debian_arch: str |
| 284 |
# GCC target triplet on Debian. |
| 285 |
debian_gcc_target: str |
| 286 |
# Linux kernel configuration options. |
| 287 |
kernel_config: str |
| 288 |
# Flavor-specific Linux kernel configuration options. |
| 289 |
kernel_flavor_configs: Mapping[str, str] |
| 290 |
# Name of compiler host on |
| 291 |
# https://mirrors.kernel.org/pub/tools/crosstool/. |
| 292 |
kernel_org_compiler_host_name: Optional[str] |
| 293 |
# Name of compiler target on |
| 294 |
# https://mirrors.kernel.org/pub/tools/crosstool/. |
| 295 |
kernel_org_compiler_target_name: str |
| 296 |
# Options to pass to QEMU. |
| 297 |
qemu_options: Sequence[str] |
| 298 |
# Console device when using QEMU. |
| 299 |
qemu_console: str |
| 300 |
# Minimum supported kernel version. |
| 301 |
min_kernel_version: Optional[KernelVersion] = None |
| 302 |
|
| 303 |
def kernel_version_supported(self, version: Union[KernelVersion, str]) -> bool: |
| 304 |
if self.min_kernel_version is None: |
| 305 |
return True |
| 306 |
if not isinstance(version, KernelVersion): |
| 307 |
version = KernelVersion(version) |
| 308 |
return version >= self.min_kernel_version |
| 309 |
|
| 310 |
|
| 311 |
ARCHITECTURES = { |
| 312 |
arch.name: arch |
| 313 |
for arch in ( |
| 314 |
Architecture( |
| 315 |
name="aarch64", |
| 316 |
kernel_arch="arm64", |
| 317 |
kernel_srcarch="arm64", |
| 318 |
debian_arch="arm64", |
| 319 |
debian_gcc_target="aarch64-linux-gnu", |
| 320 |
kernel_config=""" |
| 321 |
CONFIG_PCI_HOST_GENERIC=y |
| 322 |
CONFIG_RTC_CLASS=y |
| 323 |
CONFIG_RTC_DRV_PL031=y |
| 324 |
CONFIG_SERIAL_AMBA_PL011=y |
| 325 |
CONFIG_SERIAL_AMBA_PL011_CONSOLE=y |
| 326 |
""", |
| 327 |
kernel_flavor_configs={ |
| 328 |
"default": """ |
| 329 |
CONFIG_ARM64_4K_PAGES=y |
| 330 |
""", |
| 331 |
"alternative": """ |
| 332 |
CONFIG_ARM64_64K_PAGES=y |
| 333 |
""", |
| 334 |
"tiny": """ |
| 335 |
CONFIG_ARM64_16K_PAGES=y |
| 336 |
""", |
| 337 |
}, |
| 338 |
kernel_org_compiler_host_name="arm64", |
| 339 |
kernel_org_compiler_target_name="aarch64-linux", |
| 340 |
qemu_options=("-M", "virt", "-cpu", "cortex-a76"), |
| 341 |
qemu_console="ttyAMA0", |
| 342 |
# /proc/kcore is broken on older versions. |
| 343 |
min_kernel_version=KernelVersion("4.19"), |
| 344 |
), |
| 345 |
Architecture( |
| 346 |
name="arm", |
| 347 |
kernel_arch="arm", |
| 348 |
kernel_srcarch="arm", |
| 349 |
debian_arch="armhf", |
| 350 |
debian_gcc_target="arm-linux-gnueabihf", |
| 351 |
kernel_config=""" |
| 352 |
CONFIG_NR_CPUS=8 |
| 353 |
# Debian armhf userspace assumes EABI and VFP. |
| 354 |
CONFIG_AEABI=y |
| 355 |
CONFIG_VFP=y |
| 356 |
CONFIG_ARCH_VIRT=y |
| 357 |
CONFIG_PCI_HOST_GENERIC=y |
| 358 |
CONFIG_RTC_CLASS=y |
| 359 |
CONFIG_RTC_DRV_PL031=y |
| 360 |
CONFIG_SERIAL_AMBA_PL011=y |
| 361 |
CONFIG_SERIAL_AMBA_PL011_CONSOLE=y |
| 362 |
# Before Linux kernel commit f05eb1d24eb5 ("ARM: |
| 363 |
# stackprotector: prefer compiler for TLS based per-task |
| 364 |
# protector") (in v5.18), this enables the |
| 365 |
# arm_ssp_per_task_plugin GCC plugin, which fails to build with |
| 366 |
# the kernel.org cross compiler. |
| 367 |
CONFIG_STACKPROTECTOR_PER_TASK=n |
| 368 |
""", |
| 369 |
kernel_flavor_configs={ |
| 370 |
"default": """ |
| 371 |
CONFIG_VMSPLIT_2G=y |
| 372 |
CONFIG_HIGHMEM=n |
| 373 |
CONFIG_ARM_LPAE=n |
| 374 |
""", |
| 375 |
"alternative": """ |
| 376 |
CONFIG_VMSPLIT_2G=y |
| 377 |
CONFIG_HIGHMEM=n |
| 378 |
CONFIG_ARM_LPAE=y |
| 379 |
""", |
| 380 |
"tiny": """ |
| 381 |
CONFIG_VMSPLIT_3G=y |
| 382 |
CONFIG_HIGHMEM=y |
| 383 |
CONFIG_ARM_LPAE=n |
| 384 |
""", |
| 385 |
}, |
| 386 |
kernel_org_compiler_host_name=None, |
| 387 |
kernel_org_compiler_target_name="arm-linux-gnueabi", |
| 388 |
qemu_options=("-M", "virt,highmem=off"), |
| 389 |
qemu_console="ttyAMA0", |
| 390 |
# /proc/kcore is broken on older versions. |
| 391 |
min_kernel_version=KernelVersion("4.19"), |
| 392 |
), |
| 393 |
Architecture( |
| 394 |
name="ppc64", |
| 395 |
kernel_arch="powerpc", |
| 396 |
kernel_srcarch="powerpc", |
| 397 |
debian_arch="ppc64el", |
| 398 |
debian_gcc_target="powerpc64le-linux-gnu", |
| 399 |
kernel_config=""" |
| 400 |
CONFIG_PPC64=y |
| 401 |
CONFIG_CPU_LITTLE_ENDIAN=y |
| 402 |
# Debian ppc64el userspace assumes AltiVec and VSX support. |
| 403 |
CONFIG_ALTIVEC=y |
| 404 |
CONFIG_VSX=y |
| 405 |
CONFIG_RTC_CLASS=y |
| 406 |
CONFIG_RTC_DRV_GENERIC=y |
| 407 |
CONFIG_HVC_CONSOLE=y |
| 408 |
# This has a missing dependency in v6.5-rc1 that causes a build |
| 409 |
# failure, and we don't need it. |
| 410 |
CONFIG_CRYPTO_AES_GCM_P10=n |
| 411 |
""", |
| 412 |
kernel_flavor_configs={}, |
| 413 |
kernel_org_compiler_host_name="ppc64le", |
| 414 |
kernel_org_compiler_target_name="powerpc64-linux", |
| 415 |
qemu_options=(), |
| 416 |
qemu_console="hvc0", |
| 417 |
# Need an implementation of |
| 418 |
# linux_kernel_live_direct_mapping_fallback in libdrgn. |
| 419 |
min_kernel_version=KernelVersion("4.11"), |
| 420 |
), |
| 421 |
Architecture( |
| 422 |
name="riscv64", |
| 423 |
kernel_arch="riscv", |
| 424 |
kernel_srcarch="riscv", |
| 425 |
debian_arch="riscv64", |
| 426 |
debian_gcc_target="riscv64-linux-gnu", |
| 427 |
kernel_config=""" |
| 428 |
CONFIG_ARCH_RV64I=y |
| 429 |
CONFIG_KERNEL_UNCOMPRESSED=y |
| 430 |
CONFIG_PCI_HOST_GENERIC=y |
| 431 |
CONFIG_SERIAL_8250=y |
| 432 |
CONFIG_SERIAL_8250_CONSOLE=y |
| 433 |
CONFIG_SERIAL_OF_PLATFORM=y |
| 434 |
# For some reason, tests run significantly slower on a |
| 435 |
# relocatable kernel. Additionally, as of Linux 6.19, the KASLR |
| 436 |
# offset is not in VMCOREINFO: |
| 437 |
# https://lore.kernel.org/linux-riscv/aXiF55y5D49gcpUg@adminpc-PowerEdge-R7525/. |
| 438 |
# So, disable KASLR for now. |
| 439 |
CONFIG_RANDOMIZE_BASE=n |
| 440 |
""", |
| 441 |
kernel_flavor_configs={}, |
| 442 |
kernel_org_compiler_host_name=None, |
| 443 |
kernel_org_compiler_target_name="riscv64-linux", |
| 444 |
qemu_options=("-M", "virt"), |
| 445 |
qemu_console="ttyS0", |
| 446 |
# RISC-V support was added in Linux 4.15. Linux 6.11 and older need |
| 447 |
# patches to handle more relocation types in kexec_file_load(), and |
| 448 |
# even after patching, 6.7-6.11 hang on kexec. Linux 6.6 and older |
| 449 |
# need a backport of Linux kernel commit e0c0a7c35f67 ("riscv: |
| 450 |
# select ARCH_PROC_KCORE_TEXT"). Linux 6.2 is the oldest version |
| 451 |
# that I can get to boot in QEMU so far. Linux 5.15 is the oldest |
| 452 |
# version that will build without additional patches. |
| 453 |
min_kernel_version=KernelVersion("6.12"), |
| 454 |
), |
| 455 |
Architecture( |
| 456 |
name="s390x", |
| 457 |
kernel_arch="s390", |
| 458 |
kernel_srcarch="s390", |
| 459 |
debian_arch="s390x", |
| 460 |
debian_gcc_target="s390x-linux-gnu", |
| 461 |
kernel_config=""" |
| 462 |
# Needed for CONFIG_KEXEC_FILE. |
| 463 |
CONFIG_CRYPTO_SHA256_S390=y |
| 464 |
|
| 465 |
# Before Linux kernel commit e950d1f84d3c ("s390/percpu: Get |
| 466 |
# rid of ARCH_MODULE_NEEDS_WEAK_PER_CPU") (in v6.19), memory |
| 467 |
# allocation profiling triggers a bunch of |
| 468 |
# WARN_ON(tag->counters) warnings on s390x. It's not worth |
| 469 |
# dealing with. |
| 470 |
CONFIG_MEM_ALLOC_PROFILING=n |
| 471 |
""", |
| 472 |
kernel_flavor_configs={}, |
| 473 |
kernel_org_compiler_host_name=None, |
| 474 |
kernel_org_compiler_target_name="s390-linux", |
| 475 |
qemu_options=(), |
| 476 |
qemu_console="ttysclp0", |
| 477 |
# Need an implementation of |
| 478 |
# linux_kernel_live_direct_mapping_fallback in libdrgn. |
| 479 |
min_kernel_version=KernelVersion("4.11"), |
| 480 |
), |
| 481 |
Architecture( |
| 482 |
name="x86_64", |
| 483 |
kernel_arch="x86_64", |
| 484 |
kernel_srcarch="x86", |
| 485 |
debian_arch="amd64", |
| 486 |
debian_gcc_target="x86_64-linux-gnu", |
| 487 |
kernel_config=""" |
| 488 |
CONFIG_RTC_CLASS=y |
| 489 |
CONFIG_RTC_DRV_CMOS=y |
| 490 |
CONFIG_SERIAL_8250=y |
| 491 |
CONFIG_SERIAL_8250_CONSOLE=y |
| 492 |
""", |
| 493 |
kernel_flavor_configs={ |
| 494 |
"alternative": """ |
| 495 |
CONFIG_UNWINDER_FRAME_POINTER=y |
| 496 |
# Before Linux kernel commit 11af847446ed ("x86/unwind: |
| 497 |
# Rename unwinder config options to 'CONFIG_UNWINDER_*'") |
| 498 |
# (in v4.15). |
| 499 |
CONFIG_FRAME_POINTER_UNWINDER=y |
| 500 |
""", |
| 501 |
}, |
| 502 |
kernel_org_compiler_host_name="x86_64", |
| 503 |
kernel_org_compiler_target_name="x86_64-linux", |
| 504 |
qemu_options=("-nodefaults",), |
| 505 |
qemu_console="ttyS0", |
| 506 |
), |
| 507 |
) |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
HOST_ARCHITECTURE = ARCHITECTURES.get(NORMALIZED_MACHINE_NAME) |
| 512 |
|
| 513 |
|
| 514 |
class Kernel(NamedTuple): |
| 515 |
arch: Architecture |
| 516 |
release: str |
| 517 |
path: Path |
| 518 |
|
| 519 |
|
| 520 |
def local_kernel(arch: Architecture, path: Path) -> Kernel: |
| 521 |
return Kernel( |
| 522 |
arch=arch, |
| 523 |
release=(path / "build/include/config/kernel.release").read_text().strip(), |
| 524 |
path=path, |
| 525 |
) |
| 526 |
|
| 527 |
|
| 528 |
class Compiler(NamedTuple): |
| 529 |
target: Architecture |
| 530 |
bin: Path |
| 531 |
prefix: str |
| 532 |
|
| 533 |
def env(self) -> Dict[str, str]: |
| 534 |
path = str(self.bin.resolve()) |
| 535 |
try: |
| 536 |
path += ":" + os.environ["PATH"] |
| 537 |
except KeyError: |
| 538 |
pass |
| 539 |
return { |
| 540 |
"PATH": path, |
| 541 |
"CROSS_COMPILE": self.prefix, |
| 542 |
} |
| 543 |
|
| 544 |
|
| 545 |
def compiler_name(host_name: str, target_name: str) -> str: |
| 546 |
return f"{host_name}-gcc-{KERNEL_ORG_COMPILER_VERSION}-nolibc-{target_name}" |
| 547 |
|
| 548 |
|
| 549 |
def compiler_url(host_name: str, target_name: str) -> str: |
| 550 |
return f"https://github.com/osandov/drgn/releases/download/vmtest-compilers/{compiler_name(host_name, target_name)}.tar.xz" |
| 551 |
|
| 552 |
|
| 553 |
def kconfig_localversion(arch: Architecture, flavor: KernelFlavor, version: str) -> str: |
| 554 |
vmtest_kernel_version = [ |
| 555 |
# Increment the major version to rebuild every |
| 556 |
# architecture/flavor/version combination. |
| 557 |
40, |
| 558 |
# The minor version makes the default flavor the "latest" version. |
| 559 |
1 if flavor.name == "default" else 0, |
| 560 |
] |
| 561 |
patch_level = 0 |
| 562 |
# If only specific architecture/flavor/version combinations need to be |
| 563 |
# rebuilt, conditionally increment the patch level here. |
| 564 |
if flavor.name == "alternative" and KernelVersion(version) >= KernelVersion("6.10"): |
| 565 |
patch_level += 1 |
| 566 |
if arch.name == "s390x": |
| 567 |
patch_level += 1 |
| 568 |
if patch_level: |
| 569 |
vmtest_kernel_version.append(patch_level) |
| 570 |
|
| 571 |
return "-vmtest" + ".".join(str(n) for n in vmtest_kernel_version) + flavor.name |
| 572 |
|
| 573 |
|
| 574 |
def kconfig(arch: Architecture, flavor: KernelFlavor) -> str: |
| 575 |
return f"""\ |
| 576 |
# Minimal Linux kernel configuration for booting into vmtest and running drgn |
| 577 |
# tests ({arch.name} {flavor.name} flavor). |
| 578 |
|
| 579 |
CONFIG_LOCALVERSION="" |
| 580 |
CONFIG_LOCALVERSION_AUTO=n |
| 581 |
|
| 582 |
# base options |
| 583 |
|
| 584 |
{inspect.cleandoc(BASE_KCONFIG)} |
| 585 |
|
| 586 |
# {flavor.name} flavor options |
| 587 |
|
| 588 |
{inspect.cleandoc(flavor.config)} |
| 589 |
|
| 590 |
# {arch.name} options |
| 591 |
|
| 592 |
{inspect.cleandoc(arch.kernel_config)} |
| 593 |
|
| 594 |
# {arch.name} {flavor.name} flavor options |
| 595 |
|
| 596 |
{inspect.cleandoc(arch.kernel_flavor_configs.get(flavor.name, ""))} |
| 597 |
""" |
| 598 |
|
| 599 |
|
| 600 |
def _run_autoreconf() -> None: |
| 601 |
if out_of_date( |
| 602 |
"libdrgn/Makefile.in", "libdrgn/Makefile.am", "libdrgn/configure.ac" |
| 603 |
) or out_of_date("libdrgn/configure", "libdrgn/configure.ac"): |
| 604 |
try: |
| 605 |
subprocess.check_call(["autoreconf", "-i", "libdrgn"]) |
| 606 |
except BaseException: |
| 607 |
try: |
| 608 |
os.remove("libdrgn/configure") |
| 609 |
except FileNotFoundError: |
| 610 |
pass |
| 611 |
try: |
| 612 |
os.remove("libdrgn/Makefile.in") |
| 613 |
except FileNotFoundError: |
| 614 |
pass |
| 615 |
raise |