Skip to content

kpatch-build: fix find_parent_obj KVM shortcut for all arches - #1520

Open
jexbow wants to merge 1 commit into
dynup:masterfrom
jexbow:fix/kvm-parent-find-all-arches
Open

kpatch-build: fix find_parent_obj KVM shortcut for all arches#1520
jexbow wants to merge 1 commit into
dynup:masterfrom
jexbow:fix/kvm-parent-find-all-arches

Conversation

@jexbow

@jexbow jexbow commented Aug 19, 2026

Copy link
Copy Markdown

Summary

The find_parent_obj() shortcut for virt/kvm/* files hardcodes arch/x86/kvm, which only works when the target arch is x86. On every other architecture the parent-object lookup for KVM files misses the shortcut and falls through to a deep (and slow) full-tree search — and as reported in #1519, on arm64 it can even miss the parent entirely.

Instead of adding per-arch if blocks, derive the arch-specific KVM directory from $TARGET_ARCH. The kpatch TARGET_ARCH values don't always match the kernel arch directory names, so a small mapping is needed:

kpatch TARGET_ARCH kernel arch dir
x86_64 arch/x86/kvm
aarch64 arch/arm64/kvm
ppc64le arch/powerpc/kvm
s390x arch/s390/kvm
loongarch64 arch/loongarch/kvm

Verification

All kpatch-supported arches build the common KVM code from virt/kvm/ (v4.19: arm64/x86/s390/powerpc use KVM=../../../virt/kvm in their KVM Makefiles; modern kernels set KVM ?= ../../../virt/kvm in virt/kvm/Makefile.kvm; loongarch follows the same pattern). So the virt/kvm/* shortcut now correctly maps to the right arch directory on every supported arch.

Tested only on arm64 (4.19 kernel, gcc 8.2) — I don't have hardware for the other arches, but the change is mechanical and the mapping table above is complete.

Fixes: #1519

@joe-lawrence

Copy link
Copy Markdown
Contributor

Thanks, @jexbow two really small nits:

  • Can you add your "Signed-off-by: " line to the commit?
  • The code looks like it would work, but how about:
    • Consolidating into the existing kernel_make_arch() -> rename to kernel_src_arch()
    • Add the arches
    • Then the fix becomes: find_parent_obj_in_dir "$file" "arch/$(kernel_make_arch "$TARGET_ARCH")/kvm"

The find_parent_obj() shortcut for virt/kvm files hardcoded arch/x86/kvm,
which only worked when targeting x86. On other architectures the parent
object lookup for KVM files would fail, falling through to a deep (and
slow) search.

Instead of adding per-arch if blocks, consolidate the TARGET_ARCH ->
kernel source arch mapping into the existing helper, renaming it to
kernel_src_arch() and extending it to cover all kpatch-supported
architectures (x86, arm64, powerpc, s390, loongarch). The shortcut then
simplifies to:

  find_parent_obj_in_dir "$file" "arch/$(kernel_src_arch "$TARGET_ARCH")/kvm"

This also fixes a latent issue in the old helper, which only mapped
aarch64 -> arm64 and passed x86_64/ppc64le/s390x/loongarch64 through
unchanged (kernel "make ARCH=" expects the source arch name).

Fixes: dynup#1519
Signed-off-by: liangliang luo <11797624+jexbow@users.noreply.github.com>
@jexbow
jexbow force-pushed the fix/kvm-parent-find-all-arches branch from 1468511 to 035562b Compare August 20, 2026 06:11
@jexbow

jexbow commented Aug 20, 2026

Copy link
Copy Markdown
Author

Thanks @joe-lawrence, both make sense.

  1. Signed-off-by — added.

  2. Consolidate into kernel_make_arch() — good call. The current kernel_make_arch() only maps aarch64arm64 and passes the rest through unchanged, which is also a latent bug for x86_64/ppc64le/s390x/loongarch64 (kernel make ARCH= expects the source arch name). I renamed it to kernel_src_arch(), extended it to handle all kpatch-supported arches, and updated both call sites (the KARCH= one and the new find_parent_obj shortcut), which simplifies the fix to:

    find_parent_obj_in_dir "$file" "arch/$(kernel_src_arch "$TARGET_ARCH")/kvm"

Just force-pushed the update (amended commit) with the Signed-off-by line.

@jexbow

jexbow commented Aug 21, 2026

Copy link
Copy Markdown
Author

Thanks @jpoimboe for the review! And thanks again @joe-lawrence for the suggestion to consolidate the arch mapping — that made the fix much cleaner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kpatch-build: add arm64 KVM to known deep finds

3 participants