Skip to content

FIx looping kernel-devsrc postinst on systems living in the past.#240

Merged
amstewart merged 7 commits intoni:nilrt/master/sumofrom
amstewart:dev/sumo/kernel-devsrc
Sep 14, 2021
Merged

FIx looping kernel-devsrc postinst on systems living in the past.#240
amstewart merged 7 commits intoni:nilrt/master/sumofrom
amstewart:dev/sumo/kernel-devsrc

Conversation

@amstewart
Copy link
Contributor

The NI implementation of the kernel-devsrc packages have a postinst which cds into the kernel source directory and invokes make to prepare the kernel modules. GNU make uses file modification times to determine which target dependencies require rebuilding. When opkg unpacks the kernel-devsrc data segment, it intentionally does not refresh the file modification times; which means that the extracted files have their mtimes set to when they were packed by the IPK build server. On systems where the software clock is set backwards in time (either due to not having an RTC, or being enslaved to a network time server), it is possible for the system time to be behind the date on the source files' mtime.

Normally, you would expect make to skip creating some targets in this case; and make indeed throws a warning during compilation to that affect. However, the kernel-devsrc package also includes the objtool utility, which generates - as a consequence of its Makefile target - intermediate files which are reingested by make. Some exotic interaction in this special circumstance causes the kernel-devsrc postinst to loop indefinitely. The system appears to hang in this case.

The thrust of this PR is to fix this loop by reconciling the mtime on the kernel-devsrc data files. Before invoking make, the postinst will now find and touch the mtime of all the source files - rolling them back to whenever the software clock is set. The remainder of this PR cleans up the includes files which are shared between the kernel-devsrc(prime) bbappend and the alternative kernel flavors' recipes.

NI-AZDO #1605300

Note: the kernel-devsrc postinst will still throw a warning during compilation, alerting the user that the /usr/include/stdc-predef.h file is living in the future (for the same reason as above.) However, this doesn't seem to be a problem for the Makefile, and I don't think its appropriate for kernel-devsrc to refresh its mtime, because the file is owned by the libc6-dev package.

As a result, the user might see a few iterations of this warning during compilation:

make[4]: warning:  Clock skew detected.  Your build may be incomplete.
make[3]: Warning: File '/usr/include/stdc-predef.h' has modification time 670029495 s in the future

Testing

  • Rebuilt all of the kernel-devsrc{-*} recipes. Verified that the resulting packages look correct.
  • OE no longer warns about the /usr/src directory being unpackaged when building the alternative -devsrc recipes.
  • Manually installed the new kernel-devsrc package to a VM which has its soft-clock setback to 2000-01-01. Verified that 1) the gcc and as tools are now installed as dependencies, and 2) the compilation now succeeds without looping.

Maintainership

  • This PR should be cherry-picked to the hardknott mainline, once it is approved.

@ni/rtos

The kernel-devsrc.bbappend currently uses its own implementation of the
NI-specific postinst methods. There already exists a
kernel-devsrc-nilrt.inc file which includes a more modern version of the
same function, and which is sourced by the alternative kernel-devsrc
packages.

Use the kernel-devsrc-nilrt.inc file which is common to all NILRT
kernel-devsrc implementations, in the primary version of the package,
for easier maintenance.

Signed-off-by: Alex Stewart <alex.stewart@ni.com>
IPK data segment files have their file modification times set at the
datetime when they were packed into the IPK archive. On unpack, opkg
intentionally does not refresh this timestamp. This means that it is
possible for system to have it software clock set before the mtime of
the files its installing. This can cause unintended behavior for
packages which call GNU make in their postinst scripts; kernel-devsrc is
one such package.

Refresh the mtime of all the source files installed by kernel-devsrc
prior to calling `make` - to ensure that they are behind the software
clock source when `make` is executing.

Signed-off-by: Alex Stewart <alex.stewart@ni.com>
The `gcc` and `as` utilities are required by the kernel-devsrc Makefile
when rebuilding. Because the NI-specific postinst calls `make`, we must
provide these utilities through package dependencies.

Signed-off-by: Alex Stewart <alex.stewart@ni.com>
Break the common kernel-devsrc-* components into two includes files.

kernel-devsrc-nilrt.inc contains content which is common to all NI
kernel-devsrc packages.

kernel-devsrc-nilrt-alt.inc contains content common to only the
alternative-kernel devsrc packages.

Signed-off-by: Alex Stewart <alex.stewart@ni.com>
Rename to kernel-devsrc-nilrt-alternate.inc to be consistent with the
linux-nilrt-* includes naming.

Signed-off-by: Alex Stewart <alex.stewart@ni.com>
OE throws a QA warning during kernel-devsrc-*:do_package, about the
/usr/src directory not being installed into any package. When alternate
kernel-devsrc packages remove the /usr/src/kernel symlink, the /usr/src
path in the package install root becomes empty, and so triggers the
warning.

Try to remove the path from the install root, to satisfy OE.

Signed-off-by: Alex Stewart <alex.stewart@ni.com>
Use tabs for indentation in shell functions.

Nothing in this commit is intended to change behavior.

Signed-off-by: Alex Stewart <alex.stewart@ni.com>
Copy link
Contributor

@gratian gratian left a comment

Choose a reason for hiding this comment

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

This looks good and I like the clean-up.

I would sleep a lot better if you could also test that installing one of the alternate kernels (for example opkg install packagegroup-ni-debug-kernel) still works and NI out of tree modules get versioned correctly: for example you can see nikal when running lsmod after booting the alternate kernel. This requires installing the NI drivers on the VM or using real hardware.

@billpittman
Copy link

I'm fine with this change, but I wonder if we should have a warning output from "opkg update" if Packages.gz is newer than the system time. In general, Packages.gz should always be "older" than the current system time, and if not output a warning message similar to what gcc/make does.

I'm just a bit concerned that this may happen to other IPK/postinst/prerm/etc scripts. Maybe even promote the error all the way to MAX - but that's a UI element that I really don't want to get into.

@amstewart
Copy link
Contributor Author

@gratian
I booted a system with a 21.3 runmode and setup a custom feed with the new kernel-devsrc-next package. Installing the packagegroup-ni-next-kernel meta-package installed the kernel-devsrc-next package and the new kernel successfully. Installing the ni-kal driver after rebooting worked and rebuilt with the -next kernel headers.

I also tried installing the -next packagegroup on a 21.3 runmode with ni-kal already installed. It successfully rebuilt the driver and I could reload it.

@gratian
Copy link
Contributor

gratian commented Sep 13, 2021

Thanks. LGTM. Ship it!

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.

5 participants