CDO: Ignore section "alloc_tags"#1455
Conversation
Upstream kernel commit [1] introduces a new "alloc_tags" section. Ignore it
while building patches.
[1] commit 0db6f8d7820a ("alloc_tag: load module tags into separate contiguous memory")
Signed-off-by: Song Liu <song@kernel.org>
|
Hi Song, I have a dumb question : do these sections need to be regenerated for the livepatch module, or? |
Well, this will probably break some allocation profile. I was thinking discrepancy in the profile is acceptable for KLPs. |
|
I don't know much about the alloc tags, but from a quick glance it sounds like a way to track allocations to a specific place in the code. I wonder if 1) livepatch in general may confuse the tracking as we rebuild sources with the same source paths and load them via kpatch or 2) the kpatch module build already contains sane tags and gets tracked separately, in which case we would need a (subset of) the ones generated for by the patched build? (Or perhaps 3) none at all and we just don't track any allocations by kpatched code.) If you know more (I hope so :) perhaps we can set up a few experiments to play with the feature. LMK or point me to references to learn more. (https://origin.kernel.org/doc/html/latest/mm/allocation-profiling.html details a little bit, but it may just be faster to try it with a simple kpatch.) |
|
I am testing kpatch for 6.13 kernel, but I haven't fixed all issues, so we cannot try this out yet. The next issue, after this fix and 1454, is that commit 11b3d5175e6b changed how we build out of tree kernel modules. |
|
Tried this on an x86_64 kernel build (config.txt). Didn't get far before EOD, but tried with the example cmdline.patch w/o kpatch-build changes: $ grep -e 'Kernel Config' -e CONFIG_MEM_ALLOC_PROFILING ~/linux/.config
# Linux/x86 6.14.0 Kernel Configuration
CONFIG_MEM_ALLOC_PROFILING=y
CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT=y
CONFIG_MEM_ALLOC_PROFILING_DEBUG=y
$ readelf --wide --sections livepatch-cmdline-string.ko | grep tags
[36] .codetag.alloc_tags PROGBITS 0000000000000540 003200 0000c8 00 WA 0 0 8
[37] .rela.codetag.alloc_tags RELA 0000000000000000 0032c8 0001e0 18 I 70 36 8Next experiment is to change a function that actually uses the tags to invoke a section change and pickup this fix. |
|
I looked more into this. The "alloc_tags" section only exists in vmlinux.o, but not in vmlinx. Since my version of kpatch-build use vmlinux.o (to support LTO), I need to ignore "alloc_tags" section. For upstream, this is probably not needed. |
|
With the builds from the config I attached in an earlier comment, I do see "alloc_tags" and ".relaalloc_tags" in the individual object files. So a patch to kernel/pid.c :: alloc_pid() will result in a change in the section: The sections I reported seeing in the cmdline.patch generated example were the "alloc_tags" corresponding to the support code provided in kmod/patch and not from the changed objects themselves. Oddly enough, even with my livepatch to alloc_pid() loaded and enabled, the results of |
|
With gcc, I tried to patch alloc_pid and saw the same behavior. It appears we have the proper relocation information built in the patch .ko file: _alloc_tag.12,5 matches the one in kallsyms. |
Upstream kernel commit [1] introduces a new "alloc_tags" section. Ignore it while building patches.
[1] commit 0db6f8d7820a ("alloc_tag: load module tags into separate contiguous memory")
Signed-off-by: Song Liu song@kernel.org