From: Mikko Rapeli <mikko.rapeli@linaro.org>
To: Bruce Ashfield <bruce.ashfield@gmail.com>
Cc: Richard Purdie <richard.purdie@linuxfoundation.org>,
openembedded-core@lists.openembedded.org
Subject: Re: [OE-core] [PATCH v3 03/11] kernel.bbclass: add kernel-initrd-modules meta package
Date: Fri, 11 Apr 2025 10:48:47 +0300 [thread overview]
Message-ID: <Z_jJX05RuRTcFf4P@nuoska> (raw)
In-Reply-To: <CADkTA4MamOxjfPE8uHhFDmZ12OhxpJ9dfhxbsxKGZxwQ4_cCkQ@mail.gmail.com>
Hi,
On Thu, Apr 10, 2025 at 09:15:02AM -0400, Bruce Ashfield wrote:
> On Thu, Apr 10, 2025 at 9:00 AM Mikko Rapeli via lists.openembedded.org
> <mikko.rapeli=linaro.org@lists.openembedded.org> wrote:
>
> > On Thu, Apr 10, 2025 at 01:42:12PM +0100, Richard Purdie wrote:
> > > On Fri, 2025-04-04 at 19:29 +0300, Mikko Rapeli via
> > lists.openembedded.org wrote:
> > > > At the moment linux-yocto kernels for various architectures
> > > > are not very modular and a lot of drivers are built into the kernel
> > > > even when they are not needed at runtime. These make the main kernel
> > > > binary big and slow to boot. This also impacts udev in userspace
> > > > which takes a long time processing events from all these built in
> > drivers,
> > > > for example when udev runs in initrd.
> > > >
> > > > Then constructing the initrd is very device and kernel configuration
> > specific.
> > > > initrd image needs explicitly define which binary packages to install
> > > > to avoid pulling in complex dependencies. A full set of kernel modules
> > > > via kernel-modules meta package is too big for initrd and most of the
> > > > drivers are not needed for use cases like "just load modules to mount
> > > > main rootfs". Then the initrd configuration breaks if kernel driver
> > > > is built into the kernel since the binary package doesn't exist.
> > > >
> > > > Introduce kernel-initrd-modules meta package to solve these problems.
> > > > The meta package adds dependencies to real kernel modules based on
> > > > the kernel module file paths so that it will include several
> > > > kernel subsystems and their drivers which are often needed to find
> > > > main rootfs from some block device. This works when drivers are built
> > > > as modules but does not break if drivers are built into the kernel.
> > > >
> > > > The resulting initrd is also smaller since only a subset of drivers
> > > > are needed for "mount the rootfs" usecase. Tested on genericarm64
> > > > kernel and qemu and AMD KV260 HW.
> > > >
> > > > Signed-off-by: Mikko Rapeli <mikko.rapeli@linaro.org>
> > > > ---
> > > > .../kernel-module-split.bbclass | 48 +++++++++++++++++++
> > > > meta/classes-recipe/kernel.bbclass | 5 +-
> > > > meta/classes-recipe/module.bbclass | 37 ++++++++++++++
> > > > 3 files changed, 89 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/meta/classes-recipe/kernel-module-split.bbclass
> > b/meta/classes-recipe/kernel-module-split.bbclass
> > > > index 9487365eb7..101c5cd959 100644
> > > > --- a/meta/classes-recipe/kernel-module-split.bbclass
> > > > +++ b/meta/classes-recipe/kernel-module-split.bbclass
> > > > @@ -42,6 +42,40 @@ KERNEL_MODULE_PACKAGE_PREFIX ?= ""
> > > > KERNEL_MODULE_PACKAGE_SUFFIX ?= "-${KERNEL_VERSION}"
> > > > KERNEL_MODULE_PROVIDE_VIRTUAL ?= "1"
> > > >
> > > > +# subset of kernel modules needed in initrd, to e.g. mount rootfs
> > from block device
> > > > +KERNEL_INITRD_MODULES_META_PACKAGE ?= "${@
> > d.getVar("KERNEL_PACKAGE_NAME") or "kernel" }-initrd-modules"
> > > > +
> > > > +# match regex to path or file name. E.g. include all drivers with
> > files in path /drivers/ata/
> > > > +KERNEL_INITRD_MODULES_REGEX ?= "(.*)(\
> > > > +/drivers/acpi/|\
> > > > +/drivers/ata/|\
> > > > +/drivers/block/|\
> > > > +/drivers/cdrom/|\
> > > > +/drivers/char/hw_random/|\
> > > > +/drivers/char/tpm/|\
> > > > +/drivers/char/|\
> > > > +/drivers/crypto/|\
> > > > +/drivers/dax/|\
> > > > +/drivers/firmware/arm_scmi/|\
> > > > +/drivers/gpu/drm/|\
> > > > +/drivers/md/|\
> > > > +/drivers/mmc/|\
> > > > +/drivers/mtd/|\
> > > > +/drivers/nvdimm/|\
> > > > +/drivers/nvme/|\
> > > > +/drivers/pci/|\
> > > > +/drivers/scsi/|\
> > > > +/drivers/tee/|\
> > > > +/drivers/tty/serial/|\
> > > > +/drivers/virtio/|\
> > > > +/drivers/watchdog/|\
> > > > +/kernel/arch/|\
> > > > +/kernel/block/|\
> > > > +/kernel/crypto/|\
> > > > +/kernel/fs/|\
> > > > +/kernel/lib/\
> > > > +)(.*)"
> > > > +
> > > > python split_kernel_module_packages () {
> > > > import re
> > > >
> > > > @@ -183,6 +217,20 @@ python split_kernel_module_packages () {
> > > > modules = do_split_packages(d,
> > root='${nonarch_base_libdir}/modules', file_regex=module_regex,
> > output_pattern=module_pattern, description='%s kernel module',
> > postinst=postinst, postrm=postrm, recursive=True, hook=frob_metadata,
> > extra_depends='%s-%s' % (kernel_package_name, kernel_version))
> > > > if modules:
> > > > d.appendVar('RDEPENDS:' + metapkg, ' '+' '.join(modules))
> > > > +
> > > > + initrd_metapkg = d.getVar('KERNEL_INITRD_MODULES_META_PACKAGE')
> > or ""
> > > > + initrd_module_regex = d.getVar('KERNEL_INITRD_MODULES_REGEX') or
> > ""
> > > > + if (initrd_metapkg != "") and (initrd_module_regex != ""):
> > > > + initrd_module_regex = re.compile(initrd_module_regex)
> > > > + initrd_modules = []
> > > > + for module in modules:
> > > > + files = d.getVar('FILES:' + module)
> > > > + m = re.match(initrd_module_regex, files)
> > > > + if m:
> > > > + initrd_modules.append(module)
> > > > +
> > > > + if initrd_modules:
> > > > + d.appendVar('RDEPENDS:' + initrd_metapkg, ' '+'
> > '.join(initrd_modules))
> > > > }
> > > >
> > > > do_package[vardeps] += '${@" ".join(map(lambda s: "module_conf_" + s,
> > (d.getVar("KERNEL_MODULE_PROBECONF") or "").split()))}'
> > > > diff --git a/meta/classes-recipe/kernel.bbclass
> > b/meta/classes-recipe/kernel.bbclass
> > > > index 36ce659762..3dcaebcaed 100644
> > > > --- a/meta/classes-recipe/kernel.bbclass
> > > > +++ b/meta/classes-recipe/kernel.bbclass
> > > > @@ -695,13 +695,14 @@ EXPORT_FUNCTIONS do_compile do_transform_kernel
> > do_transform_bundled_initramfs d
> > > >
> > > > # kernel-base becomes kernel-${KERNEL_VERSION}
> > > > # kernel-image becomes kernel-image-${KERNEL_VERSION}
> > > > -PACKAGES = "${KERNEL_PACKAGE_NAME} ${KERNEL_PACKAGE_NAME}-base
> > ${KERNEL_PACKAGE_NAME}-vmlinux ${KERNEL_PACKAGE_NAME}-image
> > ${KERNEL_PACKAGE_NAME}-dev ${KERNEL_PACKAGE_NAME}-modules
> > ${KERNEL_PACKAGE_NAME}-dbg"
> > > > +PACKAGES = "${KERNEL_PACKAGE_NAME} ${KERNEL_PACKAGE_NAME}-base
> > ${KERNEL_PACKAGE_NAME}-vmlinux ${KERNEL_PACKAGE_NAME}-image
> > ${KERNEL_PACKAGE_NAME}-dev ${KERNEL_PACKAGE_NAME}-modules
> > ${KERNEL_PACKAGE_NAME}-initrd-modules ${KERNEL_PACKAGE_NAME}-dbg"
> > > > FILES:${PN} = ""
> > > > FILES:${KERNEL_PACKAGE_NAME}-base =
> > "${nonarch_base_libdir}/modules/${KERNEL_VERSION}/modules.order
> > ${nonarch_base_libdir}/modules/${KERNEL_VERSION}/modules.builtin
> > ${nonarch_base_libdir}/modules/${KERNEL_VERSION}/modules.builtin.modinfo"
> > > > FILES:${KERNEL_PACKAGE_NAME}-image = ""
> > > > FILES:${KERNEL_PACKAGE_NAME}-dev = "/${KERNEL_IMAGEDEST}/System.map*
> > /${KERNEL_IMAGEDEST}/Module.symvers* /${KERNEL_IMAGEDEST}/config*
> > ${KERNEL_SRC_PATH} ${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build"
> > > > FILES:${KERNEL_PACKAGE_NAME}-vmlinux =
> > "/${KERNEL_IMAGEDEST}/vmlinux-${KERNEL_VERSION_NAME}"
> > > > FILES:${KERNEL_PACKAGE_NAME}-modules = ""
> > > > +FILES:${KERNEL_PACKAGE_NAME}-initrd-modules = ""
> > > > FILES:${KERNEL_PACKAGE_NAME}-dbg = "/usr/lib/debug /usr/src/debug"
> > > > RDEPENDS:${KERNEL_PACKAGE_NAME} = "${KERNEL_PACKAGE_NAME}-base (=
> > ${EXTENDPKGV})"
> > > > # Allow machines to override this dependency if kernel image files are
> > > > @@ -716,7 +717,9 @@ ALLOW_EMPTY:${KERNEL_PACKAGE_NAME} = "1"
> > > > ALLOW_EMPTY:${KERNEL_PACKAGE_NAME}-base = "1"
> > > > ALLOW_EMPTY:${KERNEL_PACKAGE_NAME}-image = "1"
> > > > ALLOW_EMPTY:${KERNEL_PACKAGE_NAME}-modules = "1"
> > > > +ALLOW_EMPTY:${KERNEL_PACKAGE_NAME}-initrd-modules = "1"
> > > > DESCRIPTION:${KERNEL_PACKAGE_NAME}-modules = "Kernel modules meta
> > package"
> > > > +DESCRIPTION:${KERNEL_PACKAGE_NAME}-initrd-modules = "Kernel initrd
> > modules meta package"
> > > >
> > > > pkg_postinst:${KERNEL_PACKAGE_NAME}-base () {
> > > > if [ ! -e "$D/lib/modules/${KERNEL_VERSION}" ]; then
> > > > diff --git a/meta/classes-recipe/module.bbclass
> > b/meta/classes-recipe/module.bbclass
> > > > index f2f0b25a2d..51f864f1f9 100644
> > > > --- a/meta/classes-recipe/module.bbclass
> > > > +++ b/meta/classes-recipe/module.bbclass
> > > > @@ -86,3 +86,40 @@ EXPORT_FUNCTIONS do_compile do_install
> > > > KERNEL_MODULES_META_PACKAGE = "${PN}"
> > > > FILES:${PN} = ""
> > > > ALLOW_EMPTY:${PN} = "1"
> > > > +
> > > > +# subset of kernel modules needed in initrd, to e.g. mount rootfs
> > from block device
> > > > +KERNEL_INITRD_MODULES_META_PACKAGE ?= "${@
> > d.getVar("KERNEL_PACKAGE_NAME") or "kernel" }-initrd-modules"
> > > > +
> > > > +# match regex to path or file name. E.g. include all drivers with
> > files in path /drivers/ata/
> > > > +KERNEL_INITRD_MODULES_REGEX ?= "(.*)(\
> > > > +/drivers/acpi/|\
> > > > +/drivers/ata/|\
> > > > +/drivers/block/|\
> > > > +/drivers/cdrom/|\
> > > > +/drivers/char/hw_random/|\
> > > > +/drivers/char/tpm/|\
> > > > +/drivers/char/|\
> > > > +/drivers/crypto/|\
> > > > +/drivers/dax/|\
> > > > +/drivers/firmware/arm_scmi/|\
> > > > +/drivers/gpu/drm/|\
> > > > +/drivers/md/|\
> > > > +/drivers/mmc/|\
> > > > +/drivers/mtd/|\
> > > > +/drivers/nvdimm/|\
> > > > +/drivers/nvme/|\
> > > > +/drivers/pci/|\
> > > > +/drivers/scsi/|\
> > > > +/drivers/tee/|\
> > > > +/drivers/tty/serial/|\
> > > > +/drivers/virtio/|\
> > > > +/drivers/watchdog/|\
> > > > +/kernel/arch/|\
> > > > +/kernel/block/|\
> > > > +/kernel/crypto/|\
> > > > +/kernel/fs/|\
> > > > +/kernel/lib/\
> > > > +)(.*)"
> > > > +
> > > > +FILES:${PN}-initrd = ""
> > > > +ALLOW_EMPTY:${PN}-initrd = "1"
> > >
> > > What is the difference between the variable defined in kernel-module-
> > > split.bbclass and this one in module.bbclass? Do we need/want to
> > > separate but seemingly similar definitions?
> >
> > One is for kernel compilation and in-tree drivers, the other is for
> > out-of-tree modules.
> >
> > The "kernel-modules" meta package is handled this way too, with
> > duplication in both.
> >
> > Bruce says this should be moved to linux-yocto kernel recipe,
> > which IMO breaks the use of kernel-initrd-modules for vendor kernel recipes
> > outside of oe-core. I'd rather support them too to e.g. more easily boot
> > qemu or run oeqa selftests with qemu.
> >
>
> That's not quite what I said (but it is close), I said it shouldn't be
> defined
> at the base with no requirement opt-in from a recipe (even if this way
> of constructing an initrd with the modules is not the default). It is a (
> weak)
> binding to specific kernel versions and directory layouts, but it is a
> binding
> none the less. If it sits at the base in the classes no one will ever look
> at
> it or even know that it should be considered.
>
> My suggestion was not that it should only be in linux-yocto (but I'd
> insist on overriding it or doing it slightly differently in linux-yocto),
> I was saying that it I think that the two definitions are far to similar
> and even if there remain two definitions, they should be moved
> into a .inc file.
Actually the duplication is a bug. All duplication in module.bbclass can be
removed since it includes kernel-module-split.bbclass. Both kernel.bbclass and
module.bbclass include kernel-module-split.bbclass. Sorry about this.
I must have stopped half way when moving things there.
Sending v4 with this fixed soon.
> Any kernel recipe that wants to build an initrd like this can opt-in by
> including the .inc, and/or creating their own definition.
This I don't get. I think the kernel.bbclass and module.bbclass should
work out of the box with sane defaults. The kernel recipes can override
and adjust these as they see fit. Yes there is a dependency to some kernel
APIs (kernel module install paths) which can change, but those have been
stable for, over 25 years (as long as I have been compiling kernels)?
For full control, initrd recipe maintainers can define the exact set
of kernel and other binary packages to install which makes the recipe
kernel config and machine specific.
I don't think moving the definitions to a linux-yocto side .inc file
and then using that as basis in non-core kernel recipes is good. The
kernel.bbclass and module.bbclass would not work independently anymore
and require meta/recipes-kernel/linux/ side .inc file for working defaults.
Or should the .inc file live in meta/conf/distro/include?
I think the defaults belong to kernel-module-split.bbclass used by both
kernel and modules bbclasses.
Cheers,
-Mikko
next prev parent reply other threads:[~2025-04-11 7:48 UTC|newest]
Thread overview: 76+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-04 16:29 [PATCH v3 00/11] systemd based initrd and modular kernel support Mikko Rapeli
2025-04-04 16:29 ` [PATCH v3 01/11] systemd: enable efi support by default Mikko Rapeli
2025-04-10 10:16 ` [OE-core] " Adrian Freihofer
2025-04-10 11:12 ` Mikko Rapeli
2025-04-10 11:45 ` Ilias Apalodimas
2025-04-10 12:12 ` Ilias Apalodimas
2025-04-10 17:44 ` Alexander Kanavin
2025-04-10 17:48 ` Ilias Apalodimas
2025-04-10 19:19 ` Alexander Kanavin
2025-04-11 10:56 ` Ilias Apalodimas
2025-04-10 20:53 ` Adrian Freihofer
2025-04-11 10:38 ` Ilias Apalodimas
2025-04-10 12:13 ` Alexander Kanavin
2025-04-10 12:54 ` Ilias Apalodimas
2025-04-10 14:20 ` Alexander Kanavin
2025-04-10 14:38 ` Ilias Apalodimas
2025-04-10 14:51 ` Alexander Kanavin
2025-04-10 15:16 ` Ilias Apalodimas
2025-04-10 15:27 ` Mikko Rapeli
2025-04-11 8:40 ` Mike Looijmans
2025-04-11 10:45 ` Mikko Rapeli
2025-04-11 11:08 ` mike.looijmans
2025-04-14 16:28 ` Adrian Freihofer
2025-04-15 9:51 ` Mikko Rapeli
2025-04-15 10:39 ` Jose Quaresma
2025-04-15 16:20 ` Peter Kjellerstedt
2025-04-16 6:08 ` Mikko Rapeli
2025-04-16 9:07 ` Koen Kooi
2025-04-16 10:10 ` Adrian Freihofer
2025-04-16 12:54 ` Peter Kjellerstedt
2025-04-04 16:29 ` [PATCH v3 02/11] uki.bbclass: drop serial console from kernel command line Mikko Rapeli
2025-04-04 16:29 ` [PATCH v3 03/11] kernel.bbclass: add kernel-initrd-modules meta package Mikko Rapeli
2025-04-08 3:42 ` [OE-core] " Bruce Ashfield
2025-04-10 12:42 ` Richard Purdie
2025-04-10 13:00 ` Mikko Rapeli
2025-04-10 13:15 ` Bruce Ashfield
2025-04-11 7:48 ` Mikko Rapeli [this message]
2025-04-11 12:52 ` Bruce Ashfield
2025-04-11 13:12 ` Mikko Rapeli
2025-04-11 13:39 ` Bruce Ashfield
2025-04-11 13:45 ` Richard Purdie
2025-04-22 10:18 ` Mikko Rapeli
2025-04-23 12:48 ` Bruce Ashfield
[not found] ` <1834F69070219745.7383@lists.openembedded.org>
2025-04-11 8:07 ` Mikko Rapeli
2025-04-04 16:29 ` [PATCH v3 04/11] core-image-initramfs-boot: add option to build systemd based initrd Mikko Rapeli
2025-04-07 6:01 ` [OE-core] " Koen Kooi
2025-04-07 6:12 ` Mikko Rapeli
2025-04-07 8:58 ` Koen Kooi
2025-04-07 9:08 ` Mikko Rapeli
2025-04-10 12:45 ` Richard Purdie
2025-04-10 13:05 ` Mikko Rapeli
2025-04-04 16:29 ` [PATCH v3 05/11] core-image-initramfs-boot: don't install RRECOMMENDS to reduce size Mikko Rapeli
2025-04-10 12:47 ` [OE-core] " Richard Purdie
2025-04-10 13:09 ` Mikko Rapeli
2025-04-04 16:29 ` [PATCH v3 06/11] core-image-initramfs-boot: install kernel-initrd-modules by default Mikko Rapeli
2025-04-04 16:29 ` [PATCH v3 07/11] oeqa selftest uki.py: add aarch64/arm test with systemd based initrd Mikko Rapeli
2025-04-04 16:29 ` [PATCH v3 08/11] test_efi_plugin_plain_systemd-boot: don't set console Mikko Rapeli
2025-04-04 16:29 ` [PATCH v3 09/11] image_types_wic.bbclass: capture verbose wic output by default Mikko Rapeli
2025-04-14 20:43 ` [OE-core] " Trevor Woerner
2025-04-15 5:19 ` Mikko Rapeli
2025-04-22 14:25 ` Alexander Kanavin
2025-04-04 16:29 ` [PATCH v3 10/11] wic bootimg-efi.py: fail build if no binaries installed Mikko Rapeli
2025-04-14 20:51 ` [OE-core] " Trevor Woerner
2025-04-15 5:03 ` Mikko Rapeli
2025-04-04 16:29 ` [PATCH v3 11/11] image_types_wic.bbclass: depend on grub-efi and systemd-boot on aarch64, systemd-boot on arm Mikko Rapeli
2025-04-14 20:48 ` [OE-core] " Trevor Woerner
2025-04-15 5:01 ` Mikko Rapeli
2025-04-07 7:53 ` [OE-core] [PATCH v3 00/11] systemd based initrd and modular kernel support Mathieu Dubois-Briand
2025-04-07 8:10 ` Mikko Rapeli
2025-04-07 8:51 ` Mathieu Dubois-Briand
2025-04-07 9:24 ` Mikko Rapeli
2025-04-07 9:52 ` Mathieu Dubois-Briand
2025-04-07 10:26 ` Mikko Rapeli
[not found] ` <18340261181AE46F.21691@lists.openembedded.org>
2025-04-07 11:13 ` Mikko Rapeli
2025-04-08 11:26 ` Mathieu Dubois-Briand
2025-04-08 11:39 ` Mikko Rapeli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z_jJX05RuRTcFf4P@nuoska \
--to=mikko.rapeli@linaro.org \
--cc=bruce.ashfield@gmail.com \
--cc=openembedded-core@lists.openembedded.org \
--cc=richard.purdie@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox