diff --git a/meta/recipes-kernel/linux/kernel-devsrc.bb b/meta/recipes-kernel/linux/kernel-devsrc.bb
index 46337bd79b..c2021002d4 100644
--- a/meta/recipes-kernel/linux/kernel-devsrc.bb
+++ b/meta/recipes-kernel/linux/kernel-devsrc.bb
@@ -59,6 +59,14 @@ KERNELDEV_SOURCE_SPINE ?= "block certs crypto fs include init io_uring ipc kerne
 
 KERNEL_BUILD_ROOT = "${nonarch_base_libdir}/modules/"
 
+# Set to "1" to package the tree as kernel-devsrc-<kernel version>, so the
+# trees of two kernel versions can be installed side by side. kernel-devsrc
+# then only holds the /usr/src/kernel link and depends on the version it
+# points at, like the kernel's own kernel-image/kernel-modules packages.
+# Installing or upgrading kernel-devsrc moves the link to that version, and
+# anything that looks for kernel-devsrc by name still finds it.
+KERNELDEV_VERSIONED_PACKAGE ?= ""
+
 # The 'build' level: what is needed to build out of tree modules against the
 # kernel ('make scripts prepare' on target), and what kernel-devsrc has
 # always contained.
@@ -566,6 +574,15 @@ do_install[lockfiles] = "${TMPDIR}/kernel-scripts.lock"
 
 FILES:${PN} = "${KERNEL_BUILD_ROOT} ${KERNEL_SRC_PATH} /usr/src/kernel-source-*.tar.bz2"
 
+# The versioned tree (KERNELDEV_VERSIONED_PACKAGE). It is ahead of ${PN} in
+# PACKAGES, so it takes everything but the /usr/src/kernel link.
+PACKAGES =+ "${@'${PN}-tree' if d.getVar('KERNELDEV_VERSIONED_PACKAGE') == '1' else ''}"
+PKG:${PN}-tree = "${PN}-${@legitimize_package_name(d.getVar('KERNEL_VERSION') or '')}"
+FILES:${PN}-tree = "${KERNEL_BUILD_ROOT} /usr/src/kernel-source-*.tar.bz2"
+RDEPENDS:${PN}-tree = "${@bb.utils.contains('PACKAGECONFIG', 'build', '${KERNELDEV_BUILD_RDEPENDS}', '', d)}"
+SKIP_FILEDEPS:${PN}-tree = "${SKIP_FILEDEPS:${PN}}"
+RDEPENDS:${PN} += "${@'${PN}-tree (= ${EXTENDPKGV})' if d.getVar('KERNELDEV_VERSIONED_PACKAGE') == '1' else ''}"
+
 # Added to RDEPENDS:${PN} by the 'build' PACKAGECONFIG
 KERNELDEV_BUILD_RDEPENDS = "bc python3-core flex bison ${TCLIBC}-utils gawk"
 # 4.15+ needs these next two RDEPENDS
