Skip to content

build_library: Fix depmod issues with sysext kmods #2976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

danzatt
Copy link
Contributor

@danzatt danzatt commented May 29, 2025

build_library: Fix depmod issues with sysext kmods

OS-dependent sysexts that ship kernel modules, usually also ship the files in /usr/lib/modules/*-flatcar/modules.XXX When multiple such sysexts get activated, depmod files from just one sysext win and other kernel modules cannot be loaded using modprobe. We get around this by removing the depmod files from every sysext with kernel modules. Instead, we set up modprobe hook, which dynamically runs depmod in a temporary directory on every sysext kernel module activation.

Fixes: Flatcar #1576

Testing done

[Describe the testing you have done before submitting this PR. Please include both the commands you issued as well as the output you got.]

  • Changelog entries added in the respective changelog/ directory (user-facing change, bug fix, security fix, update)
  • Inspected CI output for image differences: /boot and /usr size, packages, list files for any missing binaries, kernel modules, config files, kernel modules, etc.

@danzatt danzatt requested a review from a team May 29, 2025 14:07
Copy link
Contributor

@chewi chewi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than have a lot of duplicate scripts, they could just be symlinks and would work just the same.

I have a suggestion for how the hook could be much cleaner and simpler. I'd normally use bubblewrap for this. We don't have it in Flatcar, but this is basically what it would do:

KMOD_PATH=/usr/lib/modules/$(uname -r)
TMP_DIR=$(mktemp -d)
trap "rm -rv -- '${TMP_DIR}'" EXIT
mkdir "${TMP_DIR}"/{upper,work}

unshare -m bash -s -- "${@}" <<EOF
set -euo pipefail
mount -t overlay overlay -o lowerdir="${KMOD_PATH}",upperdir="${TMP_DIR}"/upper,workdir="${TMP_DIR}"/work "${KMOD_PATH}"
depmod
modprobe --ignore-install "\${@}"
EOF

Copy link
Contributor

@chewi chewi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better, thank you. We're still missing the symlinks, but other than that, it's looking good. Please check whether the remove hook is actually needed.

@danzatt
Copy link
Contributor Author

danzatt commented Jun 3, 2025

Forgot the symlinks, thanks for checking.

For the remove hook, I've just checked without it, and it works (removing ZFS module removes the SPL module even without the hook). The dependencies of an already loaded kmods seems to be tracked in kernel, so I've removed the remove hook.

Copy link

github-actions bot commented Jun 3, 2025

Build action triggered: https://github.com/flatcar/scripts/actions/runs/15446425256

Copy link
Contributor

@chewi chewi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@jepio
Copy link
Member

jepio commented Jun 3, 2025

@danzatt Why do we do this at runtime, instead of generating the modules.dep file for all available kmod sysexts during image build?

@chewi
Copy link
Contributor

chewi commented Jun 3, 2025

@danzatt Why do we do this at runtime, instead of generating the modules.dep file for all available kmod sysexts during image build?

I guess that would only work if we didn't have multiple different versions of the same modules. Maybe they produce the same depmod results, but we cannot always assume that.

@danzatt
Copy link
Contributor Author

danzatt commented Jun 3, 2025

@jepio Yes, Chewi is right. That was my reasoning. We currently ship sysexts with different versions (and different useflags) of nvidia kmods. I have checked all nvidia sysexts from the latest alpha (4344) and the modules.dep is indeed the same for all of them, but this might change accross versions in the future.

@jepio
Copy link
Member

jepio commented Jun 3, 2025

alright - can you test this with the GPU operator? It runs modprobe from the host, i want to make sure that still works.

OS-dependent sysexts that ship kernel modules, usually also ship the
files in /usr/lib/modules/*-flatcar/modules.XXX When multiple such
sysexts get activated, depmod files from just one sysext win and other
kernel modules cannot be loaded using modprobe. We get around this by
removing the depmod files from every sysext with kernel modules.
Instead, we set up modprobe hook, which dynamically runs depmod in a
temporary directory on every sysext kernel module activation.

Signed-off-by: Daniel Zatovic <[email protected]>
@danzatt
Copy link
Contributor Author

danzatt commented Jun 4, 2025

@jepio Just run the operator tests on Azure NC instance and it is passing

@chewi Turns out my testing was wrong. The remove hook is needed, I tested with the latest build without the remove hook and unloading ZFS didn't unload SPL. After adding the remove hook it works as expected, so I added the hook back.

EOF
done

mkdir -p ./usr/local/bin/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized /use/libexec would be a better location for these internal helpers.

There are scenarios where /ust/local needs to be writeable and that is accomplished by using a sysext that redirects /usr/local to a different path using a symlink. Using the same path would conflict with those scenarios.

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.

nvidia-driver sysext hides zfs modules
3 participants