Skip to content

kernel: include metadata for built-in modules#14218

Merged
openwrt-bot merged 2 commits intoopenwrt:mainfrom
guidosarducci:master-update-kmodloader
Jan 6, 2024
Merged

kernel: include metadata for built-in modules#14218
openwrt-bot merged 2 commits intoopenwrt:mainfrom
guidosarducci:master-update-kmodloader

Conversation

@guidosarducci
Copy link
Copy Markdown
Contributor

@guidosarducci guidosarducci commented Dec 14, 2023

Description

Add modules.builtin and modules.builtin.modinfo to the kernel package for improved handling of built-in modules. As with other distros, this enables modprobe <module> to consistently return success for both loaded/built-in modules, a useful feature for presence-testing. and allows modinfo to print related module details.

Given OpenWrt's few built-in modules, this change and the related kmodloader support only add ~2.5 KB to a compressed filesystem image size.

Related

A separate PR updates kmodloader to parse and use these files: openwrt/ubox#1
These PRs are complementary but independent since kmodloader will still work without the files above.

Examples

Some samples of new and changed functionality (with updated kmodloader) are below.

# Print parameters for existing loadable modules:

root@OpenWrt:/# modinfo mac80211
filename:       /lib/modules/6.1.65/mac80211.ko
license:        GPL
depends:        cfg80211,compat
name:           mac80211
vermagic:       6.1.65 SMP mod_unload MIPS32_R2 32BIT
parm:           minstrel_vht_only (bool)
parm:           max_nullfunc_tries (int)
parm:           max_probe_tries (int)
parm:           beacon_loss_count (int)
parm:           probe_wait_ms (int)
parm:           ieee80211_default_rc_algo (charp)


# Recognize built-in modules, treat consistent with loadable ones

root@OpenWrt:/# rmmod sch_fq_codel
module is builtin

root@OpenWrt:/# modinfo sch_cake
filename:       /lib/modules/6.1.65/sch_cake.ko
license:        Dual BSD/GPL
depends:
intree:         Y
name:           sch_cake
vermagic:       6.1.65 SMP mod_unload MIPS32_R2 32BIT

root@OpenWrt:/# modprobe sch_fq_codel && echo SUCCESS || echo FAIL
SUCCESS
root@OpenWrt:/# modprobe sch_cake && echo SUCCESS || echo FAIL
SUCCESS


# Recognize aliases for built-in modules, treat consistent with loadable ones

root@OpenWrt:/# modinfo unix
name:           unix
filename:       (builtin)
alias:          net-pf-1
license:        GPL

root@OpenWrt:/# modprobe net-pf-1 && echo SUCCESS || echo FAIL
SUCCESS

Testing

  • Compile and run-tested against master on malta/mipseb32.
  • Confirmed kmodloader continues to function with or without modules.builtin and modules.builtin.modinfo.
  • Checked size impact of changes: updates to kmodloader, with inclusion of modules.builtin and modules.builtin.modinfo, increased OpenWrt compressed filesystem image size by ~2.5 KB.
  • Additional testing details in related kmodloader PR above.

Review

CC previous contributors: @blogic @nbd168 @hauke @Ansuel @neheb @yousong
Thanks in advance for your feedback...

@github-actions github-actions bot added kernel pull request/issue with Linux kernel related changes core packages pull request/issue for core (in-tree) packages labels Dec 14, 2023
@Ansuel
Copy link
Copy Markdown
Member

Ansuel commented Dec 14, 2023

@guidosarducci From what I'm reading this seems optional... Wonder if an idea might be make this configurable, enable by default and disable for tiny targets?

@guidosarducci
Copy link
Copy Markdown
Contributor Author

guidosarducci commented Dec 15, 2023

@guidosarducci From what I'm reading this seems optional... Wonder if an idea might be make this configurable, enable by default and disable for tiny targets?

@Ansuel Hmmm, I considered doing that but concluded it wasn't worth it and simply caused more problems.

  • Total 2.5 KB size increase of all compressed files (modules.builtin, modules.builtin.modinfo, /sbin/kmodloader) doesn't seem to justify a SMALL_FLASH variant, and likewise having a "tiny" variant of ubox/kmodloader feels overcomlicated.
  • For programs/scripts to rely on these changes (e.g. for presence-testing) they do need to be universal and not optional. On most Linux distros, modprobe -q <builtin-module> just works and confirms a built-in module is available, but otherwise people resort to using terrible kludges such as trying to use a module and checking for failure (e.g. https://github.com/tohojo/sqm-scripts/blob/master/src/functions.sh#L388 on OpenWrt).
  • Past feature/size trade-offs that employ SMALL_FLASH conditionals typically deal with much larger sizes than 2.5 KB (e.g. 3d66f55). Also, these changes are on user filesystem flash, and face less constraints than would on kernel partitions.

Are there other major considerations? What would be your idea of a negligible size increase? Maybe mine doesn't align...

@Ansuel
Copy link
Copy Markdown
Member

Ansuel commented Dec 16, 2023

Are there other major considerations? What would be your idea of a negligible size increase? Maybe mine doesn't align...

All good point and correct. My idea wasn't of a tiny variant of ubox, just a config to disable the inclusion of these additional files in the final image. If it does add major complication and it's not worth it... Totally ok with this.

Anyway aside from this small thing the change looks good to me. I think we first have to merge ubox before this correct?

I would love some feedback from @hauke or @ynezz on this topic.

@guidosarducci
Copy link
Copy Markdown
Contributor Author

guidosarducci commented Dec 16, 2023 via email

@guidosarducci
Copy link
Copy Markdown
Contributor Author

guidosarducci commented Dec 16, 2023 via email

@guidosarducci guidosarducci force-pushed the master-update-kmodloader branch from 812dc89 to 70ed367 Compare December 17, 2023 04:43
@guidosarducci
Copy link
Copy Markdown
Contributor Author

Rebased against master and fixed wrong handle for @nbd168 .

@guidosarducci guidosarducci force-pushed the master-update-kmodloader branch from 70ed367 to 2722ea7 Compare December 19, 2023 02:25
@guidosarducci
Copy link
Copy Markdown
Contributor Author

Rebased against master again.

@guidosarducci guidosarducci force-pushed the master-update-kmodloader branch from 2722ea7 to fe68769 Compare December 20, 2023 21:46
@guidosarducci
Copy link
Copy Markdown
Contributor Author

And another rebase.

@guidosarducci guidosarducci force-pushed the master-update-kmodloader branch 5 times, most recently from 80dee83 to ea89f18 Compare January 4, 2024 00:27
@guidosarducci
Copy link
Copy Markdown
Contributor Author

Thanks @Ansuel for reviewing this. Could you also please take a look and comment @nbd168 @hauke and @blogic ? Best in the New Year to all...

@Ansuel
Copy link
Copy Markdown
Member

Ansuel commented Jan 5, 2024

@guidosarducci I want to merge this... can you rebase?

@guidosarducci guidosarducci force-pushed the master-update-kmodloader branch from ea89f18 to 4e9f9d9 Compare January 6, 2024 10:24
@guidosarducci
Copy link
Copy Markdown
Contributor Author

guidosarducci commented Jan 6, 2024

@Ansuel OK, rebased again. Thanks for reviewing and merging! Would you have a chance to look at openwrt/ubox#1 as well?

Add modules.builtin to the kernel package for improved handling of loadable
and builtin modules. As with other distros, this allows 'modprobe <module>'
to consistently return success for both loaded/built-in modules, a useful
feature for presence-testing.

Given OpenWrt's few built-in modules, this change and related kmodloader
support add ~1 KB to the compressed image size.

Using sch_fq_codel (builtin) and sch_cake (loadable) for example:

     root@OpenWrt:/# modprobe sch_fq_codel && echo SUCCESS || echo FAIL
     SUCCESS
     root@OpenWrt:/# modprobe sch_cake && echo SUCCESS || echo FAIL
     SUCCESS

     root@OpenWrt:/# rmmod sch_fq_codel
     module is builtin

Signed-off-by: Tony Ambardar <itugrok@yahoo.com>
Add modules.builtin.modinfo to the kernel package, to support presence
testing using module aliases and printing module details with 'modinfo'.

With related kmodloader changes this adds ~2 KB to compressed image sizes.

     root@OpenWrt:/# modinfo unix
     name:           unix
     filename:       (builtin)
     alias:          net-pf-1
     license:        GPL

     root@OpenWrt:/# modprobe net-pf-1 && echo SUCCESS || echo FAIL
     SUCCESS

Signed-off-by: Tony Ambardar <itugrok@yahoo.com>
@guidosarducci guidosarducci force-pushed the master-update-kmodloader branch from 4e9f9d9 to e1d8e57 Compare January 6, 2024 16:36
@openwrt-bot openwrt-bot merged commit e1d8e57 into openwrt:main Jan 6, 2024
@guidosarducci guidosarducci deleted the master-update-kmodloader branch January 6, 2024 16:42
@j4cbo
Copy link
Copy Markdown
Contributor

j4cbo commented Jan 7, 2024

I think this may be breaking the build for me when CONFIG_COLLECT_KERNEL_DEBUG is set. Specifically, this line fails:

$(FIND) $(KERNEL_BUILD_DIR)/debug -type f | $(XARGS) $(KERNEL_CROSS)strip --only-keep-debug

find /[...]/openwrt/build_dir/target-mips_4kec_musl/linux-realtek_rtl838x/debug -type f | xargs -r mips-openwrt-linux-musl-strip --only-keep-debug
mips-openwrt-linux-musl-strip: /[...]/openwrt/build_dir/target-mips_4kec_musl/linux-realtek_rtl838x/debug/modules/modules.builtin.modinfo: file format not recognized
mips-openwrt-linux-musl-strip: /[...]/openwrt/build_dir/target-mips_4kec_musl/linux-realtek_rtl838x/debug/modules/modules.builtin: file format not recognized
make[4]: *** [Makefile:62: /[...]/openwrt/build_dir/target-mips_4kec_musl/linux-realtek_rtl838x/linux-5.15.146/.image] Error 123

@ynezz
Copy link
Copy Markdown
Member

ynezz commented Jan 7, 2024

I think this may be breaking the build for me when CONFIG_COLLECT_KERNEL_DEBUG is set. Specifically, this line fails:

$(FIND) $(KERNEL_BUILD_DIR)/debug -type f | $(XARGS) $(KERNEL_CROSS)strip --only-keep-debug

find /[...]/openwrt/build_dir/target-mips_4kec_musl/linux-realtek_rtl838x/debug -type f | xargs -r mips-openwrt-linux-musl-strip --only-keep-debug
mips-openwrt-linux-musl-strip: /[...]/openwrt/build_dir/target-mips_4kec_musl/linux-realtek_rtl838x/debug/modules/modules.builtin.modinfo: file format not recognized
mips-openwrt-linux-musl-strip: /[...]/openwrt/build_dir/target-mips_4kec_musl/linux-realtek_rtl838x/debug/modules/modules.builtin: file format not recognized
make[4]: *** [Makefile:62: /[...]/openwrt/build_dir/target-mips_4kec_musl/linux-realtek_rtl838x/linux-5.15.146/.image] Error 123

@j4cbo can you check @981213 's fix 066b0fe ?

ynezz added a commit to openwrt/actions-shared-workflows that referenced this pull request Jan 7, 2024
Merging pull request #14218 (with all 190 CI checks green) resulted in
buildbot failures in `Kernel/CollectDebug` step, likely due to the fact,
that CI builds don't use same config options as on buildbot,
specifically CI builds currently don't have `COLLECT_KERNEL_DEBUG`
config option enabled.

So lets try to prevent those regressions in the future by aligning the
CI build process with the build config options used later on the
buildbots.

References: 066b0fee7668 ("kernel: copy only *.ko for debug info")
References: openwrt/openwrt#14218
Signed-off-by: Petr Štetiar <ynezz@true.cz>
@j4cbo
Copy link
Copy Markdown
Contributor

j4cbo commented Jan 7, 2024

Yep, that fixes it, thanks!

@guidosarducci
Copy link
Copy Markdown
Contributor Author

@981213 @ynezz Thanks for investigating. Any reason not to keep the modinfo files for debug purposes in 066b0fe? Changing the find in

$(FIND) $(KERNEL_BUILD_DIR)/debug -type f | $(XARGS) $(KERNEL_CROSS)strip --only-keep-debug

to include -name '*.ko' would target only modules for stripping.

@981213
Copy link
Copy Markdown
Member

981213 commented Jan 8, 2024

Any reason not to keep the modinfo files for debug purposes in 066b0fe?

We need this separated debug info archive because we strip debug info out of modules in firmwares.
The files added here are available in the final firmware and we can just grab it there if it's needed.

ynezz added a commit to openwrt/actions-shared-workflows that referenced this pull request Nov 6, 2024
Merging pull request #14218 (with all 190 CI checks green) resulted in
buildbot failures in `Kernel/CollectDebug` step, likely due to the fact,
that CI builds don't use same config options as on buildbot,
specifically CI builds currently don't have `COLLECT_KERNEL_DEBUG`
config option enabled.

So lets try to prevent those regressions in the future by aligning the
CI build process with the build config options used later on the
buildbots.

References: 066b0fee7668 ("kernel: copy only *.ko for debug info")
References: openwrt/openwrt#14218
Signed-off-by: Petr Štetiar <ynezz@true.cz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core packages pull request/issue for core (in-tree) packages kernel pull request/issue with Linux kernel related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants