From be85dfda692bf8c72377223a3a3f716f31300fd1 Mon Sep 17 00:00:00 2001 From: Luis Chamberlain Date: Wed, 23 Apr 2025 17:09:41 -0700 Subject: [PATCH] bootlinux: add bisection support This adds automatic bisection support first through the CLI by using simple command line options. The first target goal to test is very simple, check if the kernel boots or not. There is no need for a custom workflow for this. We just enable the user to set the values through the command line interface like this: git clone git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git \ --reference /mirror/linux-next.git linux make defconfig-bisection \ GOOD=v6.15-rc2 \ BAD=next-20250422 \ KDEVOPS_HOSTS_PREFIX="bisect" \ LINUX_TREE="git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git" -j128 make -j128 make bringup make linux # Boots to good at first make linux-bisection # Runs the bisection script For now confine this feature to BOOTLINUX_9P as its not clear what to do about terraform yet. We can add that support later. Signed-off-by: Luis Chamberlain --- defconfigs/bisection | 9 +++ playbooks/roles/bootlinux/defaults/main.yml | 6 ++ playbooks/roles/bootlinux/tasks/main.yml | 45 +++++++++++ .../bootlinux/templates/bisect-boot.sh.j2 | 7 ++ workflows/linux/Kconfig | 80 ++++++++++++++++++- workflows/linux/Makefile | 15 ++++ 6 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 defconfigs/bisection create mode 100755 playbooks/roles/bootlinux/templates/bisect-boot.sh.j2 diff --git a/defconfigs/bisection b/defconfigs/bisection new file mode 100644 index 000000000..1c3112a06 --- /dev/null +++ b/defconfigs/bisection @@ -0,0 +1,9 @@ +CONFIG_GUESTFS=y +CONFIG_LIBVIRT=y + +CONFIG_WORKFLOW_LINUX_CUSTOM=y +CONFIG_BOOTLINUX=y +CONFIG_BOOTLINUX_9P=y +CONFIG_BOOTLINUX_BISECT_ENABLE=y + +CONFIG_DEVCONFIG_ENABLE_SYSTEMD_JOURNAL_REMOTE=y diff --git a/playbooks/roles/bootlinux/defaults/main.yml b/playbooks/roles/bootlinux/defaults/main.yml index fd5674b5f..245ae43c5 100644 --- a/playbooks/roles/bootlinux/defaults/main.yml +++ b/playbooks/roles/bootlinux/defaults/main.yml @@ -52,3 +52,9 @@ kdevops_workflow_enable_cxl: False bootlinux_cxl_test: False bootlinux_tree_set_by_cli: False +bootlinux_bisect_enable: False +bootlinux_bisect_enable_cli: False +bootlinux_bisect_ref_good_cli: False +bootlinux_bisect_ref_bad_cli: False +bootlinux_bisect_script_boot: False +bootlinux_bisect_script_custom: False diff --git a/playbooks/roles/bootlinux/tasks/main.yml b/playbooks/roles/bootlinux/tasks/main.yml index 9ad675b3f..afa533c01 100644 --- a/playbooks/roles/bootlinux/tasks/main.yml +++ b/playbooks/roles/bootlinux/tasks/main.yml @@ -650,3 +650,48 @@ vars: running_kernel: "{{ uname_cmd.stdout_lines.0 }}" tags: [ 'linux', 'git', 'config', 'uname' ] + +- name: Copy git bisection script over + template: + src: "{{ bootlinux_bisect_script }}.j2" + dest: "{{ bootlinux_9p_host_path }}/{{ bootlinux_bisect_script }}" + mode: 0644 + tags: [ 'bisect' ] + when: + - bootlinux_bisect_enable|bool + run_once: true + delegate_to: localhost + +- name: Set up bisection for git + command: "git bisect start {{ bootlinux_bisect_ref_bad }} {{ bootlinux_bisect_ref_good }}" + register: build + changed_when: "build.rc == 0" + args: + chdir: "{{ bootlinux_9p_host_path }}" + tags: [ 'bisect' ] + when: + - bootlinux_bisect_enable|bool + run_once: true + delegate_to: localhost + +- name: Ensure bisection script is executable + file: + path: "{{ bootlinux_9p_host_path }}/{{ bootlinux_bisect_script }}" + mode: '0755' + state: file + when: bootlinux_bisect_enable | bool + delegate_to: localhost + run_once: true + tags: [ 'bisect' ] + +- name: Run the the bisection script + command: "git bisect run {{ bootlinux_9p_host_path }}/{{ bootlinux_bisect_script }}" + register: build + changed_when: "build.rc == 0" + args: + chdir: "{{ bootlinux_9p_host_path }}" + tags: [ 'bisect' ] + when: + - bootlinux_bisect_enable|bool + run_once: true + delegate_to: localhost diff --git a/playbooks/roles/bootlinux/templates/bisect-boot.sh.j2 b/playbooks/roles/bootlinux/templates/bisect-boot.sh.j2 new file mode 100755 index 000000000..10dbacd30 --- /dev/null +++ b/playbooks/roles/bootlinux/templates/bisect-boot.sh.j2 @@ -0,0 +1,7 @@ +#!/bin/bash +# SPDX-License-Identifier: copyleft-next-0.3.1 +# +# If make linux-deploy fails for reasons unrelated to the bug we're tracking +# (e.g., a build error) we bail with exit code 125 to allow git to skip that +# commit. +make linux-deploy || exit 125 diff --git a/workflows/linux/Kconfig b/workflows/linux/Kconfig index 797469e60..b30187c80 100644 --- a/workflows/linux/Kconfig +++ b/workflows/linux/Kconfig @@ -10,6 +10,21 @@ config BOOTLINUX_TREE_REF_SET_BY_CLI output yaml default $(shell, scripts/check-cli-set-var.sh LINUX_TREE_REF) +config BOOTLINUX_BISECT_ENABLE_CLI + bool + output yaml + default $(shell, scripts/check-cli-set-var.sh LINUX_BISECT) + +config BOOTLINUX_BISECT_REF_GOOD_CLI + bool + output yaml + default $(shell, scripts/check-cli-set-var.sh GOOD) + +config BOOTLINUX_BISECT_REF_BAD_CLI + bool + output yaml + default $(shell, scripts/check-cli-set-var.sh BAD) + config BOOTLINUX_HAS_PURE_IOMAP_CONFIG bool @@ -173,7 +188,8 @@ config BOOTLINUX_TREE_CUSTOM_URL config BOOTLINUX_TREE_CUSTOM_REF string "Custom Linux kernel tag or branch to use" - default $(shell, ./scripts/append-makefile-vars.sh $(LINUX_TREE_REF)) if BOOTLINUX_TREE_REF_SET_BY_CLI + default $(shell, ./scripts/append-makefile-vars.sh $(GOOD)) if BOOTLINUX_BISECT_REF_GOOD_CLI && !BOOTLINUX_TREE_REF_SET_BY_CLI + default $(shell, ./scripts/append-makefile-vars.sh $(LINUX_TREE_REF)) if BOOTLINUX_TREE_REF_SET_BY_CLI && !BOOTLINUX_BISECT_REF_GOOD_CLI default "master" if !BOOTLINUX_TREE_REF_SET_BY_CLI help The git ID or branch name to check out to compile linux. @@ -278,9 +294,71 @@ config BOOTLINUX_TREE_LOCALVERSION help The Linux local version to use (for uname). +config BOOTLINUX_BISECT_ENABLE + bool "Do you want to bisect a broken kernel?" + default y + depends on BOOTLINUX_9P + output yaml + help + Do you need to automate bisecting some broken kernel? + +if BOOTLINUX_BISECT_ENABLE + +choice + prompt "Bisection script to use" + default BOOTLINUX_BISECT_SCRIPT_BOOT + +config BOOTLINUX_BISECT_SCRIPT_BOOT + bool "Ensures we can at least boot" + help + This helps ensure we can at laest boot into the host. That's it. + +config BOOTLINUX_BISECT_SCRIPT_CUSTOM + bool "You will provide your own bisection script" + help + If you to test a new bisection script you can use this. + +endchoice + +config BOOTLINUX_BISECT_SCRIPT_CUSTOM_PATH + string "Custom path to git bisection script to use" + depends on BOOTLINUX_BISECT_SCRIPT_CUSTOM + default "" + output yaml + help + The custom path to the bisect script we will use. Instead of building + the kernel and booting it, 'make linux' will do the bisection + automatically for you based on the script. + +config BOOTLINUX_BISECT_SCRIPT + string + output yaml + default "bisect-boot.sh" if BOOTLINUX_BISECT_SCRIPT_BOOT + default BOOTLINUX_BISECT_SCRIPT_CUSTOM_PATH if BOOTLINUX_BISECT_SCRIPT_BOOT + + +config BOOTLINUX_BISECT_REF_GOOD + string "The last known good commit" + default BOOTLINUX_TREE_REF if !BOOTLINUX_BISECT_REF_GOOD_CLI + default $(shell, ./scripts/append-makefile-vars.sh $(GOOD)) if BOOTLINUX_BISECT_REF_GOOD_CLI + output yaml + help + The known kernel commit to be good. + +config BOOTLINUX_BISECT_REF_BAD + string "The known broken commit" + default BOOTLINUX_TREE_STABLE_REF if !BOOTLINUX_BISECT_REF_BAD_CLI + default $(shell, ./scripts/append-makefile-vars.sh $(BAD)) if BOOTLINUX_BISECT_REF_BAD_CLI + output yaml + help + The first broken tag. + +endif # BOOTLINUX_BISECT_ENABLE + config BOOTLINUX_SHALLOW_CLONE bool "Shallow git clone" default y + depends on !BOOTLINUX_BISECT_ENABLE help If enabled the git tree cloned with be cloned using a shallow tree with history truncated. You want to enable this if you really don't diff --git a/workflows/linux/Makefile b/workflows/linux/Makefile index ecce273a4..00ec13db7 100644 --- a/workflows/linux/Makefile +++ b/workflows/linux/Makefile @@ -104,6 +104,13 @@ linux-mount: --tags vars,9p_mount \ --extra-vars="$(BOOTLINUX_ARGS)" $(LIMIT_HOSTS) +PHONY += linux-bisect +linux-bisect: + $(Q)ansible-playbook $(ANSIBLE_VERBOSE) -i \ + $(KDEVOPS_HOSTFILE) $(KDEVOPS_PLAYBOOKS_DIR)/bootlinux.yml \ + --tags vars,bisect \ + --extra-vars="$(BOOTLINUX_ARGS)" $(LIMIT_HOSTS) + PHONY += linux-deploy linux-deploy: $(Q)ansible-playbook $(ANSIBLE_VERBOSE) -i \ @@ -176,6 +183,14 @@ linux-help-cxl: LINUX_HELP_EXTRA += linux-help-cxl endif +ifeq (y,$(CONFIG_BOOTLINUX_BISECTION)) +PHONY += linux-help-bisection +linux-help-bisection: + @echo "linux-bisection - Bisects the kernel automatically for you" + +LINUX_HELP_EXTRA += linux-help-bisection +endif + HELP_TARGETS+=linux-help-menu HELP_TARGETS+=$(LINUX_HELP_EXTRA) HELP_TARGETS+=linux-help-end