Skip to content
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

[RFC] kmod/patch: merge .text.* and .rodata.* sections for new and patched functions #1131

Closed
wants to merge 1 commit into from

Conversation

euspectre
Copy link
Contributor

@euspectre euspectre commented Jul 22, 2020

This is a request for comments, because the relevant code is quite complex and I may be missing something important.
Reviews and suggestions are welcome.

When a kernel module is loaded, sysfs attributes are created for its ELF
sections (visible as /sys/module/<module_name>/sections/*). and contain
the start addresses of the ELF sections. A single memory chunk is allocated
for all these, see add_sect_attrs(), kernel/module.c:

        size[0] = ALIGN(sizeof(*sect_attrs)
                        + nloaded * sizeof(sect_attrs->attrs[0]),
                        sizeof(sect_attrs->grp.attrs[0]));
        size[1] = (nloaded + 1) * sizeof(sect_attrs->grp.attrs[0]);
        sect_attrs = kzalloc(size[0] + size[1], GFP_KERNEL);

'nloaded' is the number of loaded ELF section in the module.

As of the kernel 4.18.0-193.6.3 from RHEL 8, x86_64, the total allocation
size is (80 * nloaded + 56).

Cumulative livepatches can easily get hundreds of new and changed
functions. Each such function will be placed into a separate .text.*,
.text.unlikely.* or a similar section, R/O data for each function will
also be stored in a separate section, same for .klp.rela.* sections.

Testing had shown that a patch that added 120+ new functions and touched
a handful of existing ones got 450+ loaded sections, so more than 450 *
80 == 36000 bytes of kmalloc'ed memory was requested. This is a 4th
order allocation, which might fail (and fail loading of the patch) or
become slow when the memory is fragmented.

The thing is, the addresses of these ELF sections of a livepatch module
are unlikely to be needed once the module has been loaded, so that kernel
memory is wasted.

If I understand it right, keeping functions and data in separate
sections is no longer needed after the patch module has been built. The
kernel code that handles loading of livepatch modules does not require
that. It requires that .klp.rela* and .klp.sym* sections have proper
names but that is preserved here.

create-klp-module and create-kpatch-module seem to be fine with that as
well.

The linker script for the patch module has been updated to merge:

  • all .text.unlikely.* sections into .text.unlikely.livepatch;
  • all other .text.* sections into .text.livepatch;
  • .rodata.__func__.*, .rodata.*.str1.1, .rodata.*.str1.8 into respective
    sections.

As for .klp.rela sections, create-klp-module already does the right
thing and generates these as follows:

  • .klp.rela.vmlinux..text.livepatch
  • .klp.rela.vmlinux..text.unlikely.livepatch

This way, the number of loaded sections in the test patch mentioned above
shrinks from 454 to 29 and the amount of requested memory -
from 36376 to 2376 bytes.

To check the amount of requested memory, one can use 'mm_page_alloc'
tracepoint:

(Assuming debugfs is mounted to /sys/kernel/debug.)

  # echo nop > /sys/kernel/debug/tracing/current_tracer
  # echo 'order > 3' > /sys/kernel/debug/tracing/events/kmem/mm_page_alloc/filter
  # echo 1 > /sys/kernel/debug/tracing/events/kmem/mm_page_alloc/enable
  # echo 1 > /sys/kernel/debug/tracing/tracing_on

  <... load the patch module with lots of sections ... >
  # kpatch load test-patch.ko

  <shortened output>
  # cat /sys/kernel/debug/tracing/trace
  TASK-PID   CPU#    ||||    TIMESTAMP  FUNCTION
    |   |       |    ||||       |         |
  <...>-189468 [001] .... 1110159.836398: mm_page_alloc: <...> order=4 <...>
  <...>-189468 [001] .... 1110159.836653: mm_page_alloc: <...> order=4 <...>

  # echo 0 > /sys/kernel/debug/tracing/tracing_on

In this example, 4th order allocations have been detected when loading
the patch.

…functions

When a kernel module is loaded, sysfs attributes are created for its ELF
sections (visible as /sys/module/<module_name>/sections/*). and contain
the start addresses of the ELF sections. A single memory chunk is allocated
for all these, see add_sect_attrs(), kernel/module.c:

        size[0] = ALIGN(sizeof(*sect_attrs)
                        + nloaded * sizeof(sect_attrs->attrs[0]),
                        sizeof(sect_attrs->grp.attrs[0]));
        size[1] = (nloaded + 1) * sizeof(sect_attrs->grp.attrs[0]);
        sect_attrs = kzalloc(size[0] + size[1], GFP_KERNEL);

'nloaded' is the number of loaded ELF section in the module.

As of the kernel 4.18.0-193.6.3 from RHEL 8, x86_64, the total allocation
size is (80 * nloaded + 56).

Cumulative livepatches can easily get hundreds of new and changed
functions. Each such function will be placed into a separate .text.*,
.text.unlikely.* or a similar section, R/O data for each function will
also be stored in a separate section, same for .klp.rela.* sections.

Testing had shown that a patch that added 120+ new functions and touched
a handful of existing ones got 450+ loaded sections, so more than 450 *
80 == 36000 bytes of kmalloc'ed memory was requested. This is a 4th
order allocation, which might fail (and fail loading of the patch) or
become slow when the memory is fragmented.

The thing is, the addresses of these ELF sections of a livepatch module
are unlikely to be needed once the module has been loaded, so that kernel
memory is wasted.

If I understand it right, keeping functions and data in separate
sections is no longer needed after the patch module has been built. The
kernel code that handles loading of livepatch modules does not require
that. It requires that .klp.rela* and .klp.sym* sections have proper
names but that is preserved here.

create-klp-module and create-kpatch-module seem to be fine with that as
well.

The linker script for the patch module has been updated to merge:
  all .text.unlikely.* sections into .text.unlikely.livepatch;
  all other .text.* sections into .text.livepatch;
  .rodata.__func__.*, .rodata.*.str1.1, .rodata.*.str1.8 into respective
    sections.

As for .klp.rela sections, create-klp-module already does the right
thing and generates these as follows:
  .klp.rela.vmlinux..text.livepatch
  .klp.rela.vmlinux..text.unlikely.livepatch

This way, the number of loaded sections in the test patch mentioned above
shrinks from 454 to 29 and the amount of requested memory -
from 36376 to 2376 bytes.

To check the amount of requested memory, one can use 'mm_page_alloc'
tracepoint:

(Assuming debugfs is mounted to /sys/kernel/debug.)

  # echo nop > /sys/kernel/debug/tracing/current_tracer
  # echo 'order > 3' > /sys/kernel/debug/tracing/events/kmem/mm_page_alloc/filter
  # echo 1 > /sys/kernel/debug/tracing/events/kmem/mm_page_alloc/enable
  # echo 1 > /sys/kernel/debug/tracing/tracing_on

  <... load the patch module with lots of sections ... >
  # kpatch load test-patch.ko

  <shortened output>
  # cat /sys/kernel/debug/tracing/trace
  TASK-PID   CPU#    ||||    TIMESTAMP  FUNCTION
    |   |       |    ||||       |         |
  <...>-189468 [001] .... 1110159.836398: mm_page_alloc: <...> order=4 <...>
  <...>-189468 [001] .... 1110159.836653: mm_page_alloc: <...> order=4 <...>

  # echo 0 > /sys/kernel/debug/tracing/tracing_on

In this example, 4th order allocations have been detected when loading
the patch.

Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
@euspectre
Copy link
Contributor Author

Here is the patch I mentioned:
many_sections.patch.txt

I used kernel 4.18.0-193.6.3 from RHEL 8 for testing.

@joe-lawrence
Copy link
Contributor

Hi @euspectre , thanks for posting the PR, I vaguely remember discussing this on the livepatching mailing list some time ago. Livepatching hundreds of functions is definitely impressive! Just curious, how many kpatch modules do you typically load on a given system?

I think these linker script changes to consolidate the .text and .rodata sections should be safe. I keep wondering if it might break some special section construct, but I can't come up with a failing case. I'm guessing you've tested this against x86_64, how about ppc64le?

BTW, have you seen the upstream Function Granular KASLR series? That uses -ffunction-sections to build modules and then randomize the loading of separate module sections. I wonder if Kristen is concerned about similar high-order sysfs allocations since presumable all modules will have many sections when CONFIG_MODULE_FG_KASLR=y. I only mention it in case there may be an opportunity to modify the upstream module loader and these allocations.

@euspectre
Copy link
Contributor Author

euspectre commented Jul 28, 2020

I vaguely remember discussing this on the livepatching mailing list some time ago.

Yes, I wrote about that a while ago, was asked to submit patches and then completely forgot about it ;-) My bad.

how many kpatch modules do you typically load on a given system?

We mostly use cumulative patches, so, usually, no more than 2 kpatch modules are loaded at the same time:

  • the official cumulative patch;
  • an additional, temporary, non-cumulative patch for debugging or enhancements if the customers request that.

Our kernels are supported with livepatches for about 1.5 years. The latest cumulative patch for the oldest supported kernel touches about 130 kernel functions and has 200+ loaded ELF sections, so these large allocations can be a problem.

I keep wondering if it might break some special section construct

Me too. This one of the reasons, I'd like to collect comments on the matter.

I'm guessing you've tested this against x86_64, how about ppc64le?

Right, I have only tested it against x86_64. If someone could check if it works OK for ppc64le as well, it would be great, because I have no such hardware available at the moment.

have you seen the upstream Function Granular KASLR series?

I saw the series but did not dig into it. Interesting, so we might have a similar issue with all modules with FGKASLR, not only livepatch.

Need to take a closer look.

At the first glance, kmalloc'ed, physically contiguous memory areas for these sysfs attributes is an overkill. Merging sections is not an option for FGKASLR, so, just in case someone does need /sys/module/<...>/sections/*, I think, I'll suggest using vmalloc there instead.

Copy link
Contributor

@joe-lawrence joe-lawrence left a comment

Choose a reason for hiding this comment

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

I'm guessing you've tested this against x86_64, how about ppc64le?

Right, I have only tested it against x86_64. If someone could check if it works OK for ppc64le as well, it would be great, because I have no such hardware available at the moment.

I can confirm that the changes can build and load many-sections.patch on ppc64le if I add __attribute__((optimize("-fno-optimize-sibling-calls"))) before the definition of pde_put().

}

.text.livepatch : {
*(.text.*)
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, this pattern seems compatible with scripts/module-common.lds and arch/powerpc/kernel/module.lds (no x86_64 counterpart).

I did notice that arch/x86/kernel/vmlinux.lds.S does use the linker script to setup __indirect_thunk_{start,end} relocations like so:

SECTIONS
{
...
        /* Text and read-only data */
        .text :  AT(ADDR(.text) - LOAD_OFFSET) {
...
                __indirect_thunk_start = .;
                *(.text.__x86.indirect_thunk)
                __indirect_thunk_end = .;

and I wonder if a pattern like this ever made it into one of the module.lds files if we're going to experience some weird failure modes. I don't know much about module linker files, so this only speculation. For another example, arch/arm64/kernel/module.lds includes this:

SECTIONS {
...
	.text.ftrace_trampoline (NOLOAD) : { BYTE(0) }
}

so maybe *(.text.*) is too inclusive and we should try to limit it to the functions that kpatch-build detects have changed?

Copy link
Contributor Author

@euspectre euspectre Jul 29, 2020

Choose a reason for hiding this comment

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

so maybe (.text.) is too inclusive and we should try to limit it to the functions that kpatch-build detects have changed?

You mean, generate kpatch.lds on the fly, with the patterns corresponding to changed functions like *(.text.*func1*), *(.text.*func2*), etc. ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that was the suggestion, but maybe I'm being too paranoid, I don't know.

@jpoimboe any thoughts on this patch module linker script?

Copy link
Member

Choose a reason for hiding this comment

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

As @euspectre said, merging sections is not an option for FGKASLR, so wouldn't this make kpatch incompatible with FGKASLR? Maybe the proper fix is indeed to use vmalloc.

@euspectre
Copy link
Contributor Author

I'm guessing you've tested this against x86_64, how about ppc64le?

Right, I have only tested it against x86_64. If someone could check if it works OK for ppc64le as well, it would be great, because I have no such hardware available at the moment.

I can confirm that the changes can build and load many-sections.patch on ppc64le if I add __attribute__((optimize("-fno-optimize-sibling-calls"))) before the definition of pde_put().

Cool. Thanks!

@euspectre
Copy link
Contributor Author

I have finally built kernel 5.8-rc7 with FGKASLR and monitored memory allocations with FTrace. Yes, the problem is even worse there. Large modules like xfs.ko or btrfs.ko cause allocations of 6th order for sysfs attrs:

modprobe-1509: mm_page_alloc: <...> order=4 migratetype=0 gfp_flags=GFP_KERNEL|__GFP_COMP
modprobe-1509: mm_page_alloc: <...> order=6 migratetype=0 gfp_flags=GFP_KERNEL|__GFP_COMP|__GFP_ZERO

The first alloc is from randomize_text(), size == 8 * total_number_of_sections. 8 * 4849 == 38792 bytes for xfs.ko.

The second one is what we were talking about, the one from add_sect_attrs(): size == 56 + 72 * num_loaded_sections in this case, 56 + 72 * 2428 == 174872 bytes for xfs.ko.

I'll write to the thread where FGKASLR is discussed and will probably suggest to switch to kvmalloc+kvfree in both places.

openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Dec 30, 2020
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file /sys/module/<module_name>/sections/<section_name>
for each loaded section when the patch module is being loaded, see
add_sect_attrs() in kernel/module.c. A big chunk of memory is allocated
for all these with kzalloc.

For the ReadyKernel patches we have already released, the amount of memory
could be as high as 34528 bytes (48 + 80 * 431 loaded sections), which is
a 4th order allocation. 3rd order allocations are also common here,
see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel patches
are often used in the systems with rather significant uptime, so the
fragmentation is possible.

It could be better if the patch modules did not use too many ELF sections.
However, the KPatch maintainers pointed out (dynup/kpatch#1131)
that the same problem would affect regular kernel modules as well after
FGKASLR has been merged into the mainline kernel. Combining the sections
of the kernel modules destroys the purpose of FGKASLR, so, it was agreed
that we probably should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion: https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108015
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Dec 30, 2020
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Dec 30, 2020
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Jul 21, 2021
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Aug 19, 2021
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
@joe-lawrence
Copy link
Contributor

@euspectre : Hi, way back when you opened this bug, I remember we took the discussion over the livepatching kernel list. Did we ever implement anything upstream to fix this?

@euspectre
Copy link
Contributor Author

@joe-lawrence FGKASLR series v5 now includes the patch that changes add_sect_attrs() and friends to use kvmalloc/kvfree, among other things: "[PATCH v5 09/10] module: Reorder functions", https://www.spinics.net/lists/kernel-hardening/msg04575.html

The series, however, was not merged and the change is not in the mainline kernel yet. They said, v6 of the series was needed but it is yet to appear.

@euspectre
Copy link
Contributor Author

This PR can be closed, I think. Using kvmalloc/kvfree seems safer than merging sections.

openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Oct 6, 2021
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Oct 23, 2021
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>

(cherry picked from vz8 commit e16aab1)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Jan 1, 2022
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>

(cherry picked from vz8 commit e16aab1)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Jan 20, 2022
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>

(cherry picked from vz8 commit e16aab1)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Feature: mm: avoid high order allocations in all subsystems
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Mar 23, 2022
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>

(cherry picked from vz8 commit e16aab1)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Feature: mm: avoid high order allocations in all subsystems
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Apr 18, 2022
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>

(cherry picked from vz8 commit e16aab1)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Feature: mm: avoid high order allocations in all subsystems
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Jun 9, 2022
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>

(cherry picked from vz8 commit e16aab1)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Feature: mm: avoid high order allocations in all subsystems
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Sep 27, 2022
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>

(cherry picked from vz8 commit e16aab1)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Feature: mm: avoid high order allocations in all subsystems
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Sep 28, 2022
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>

(cherry picked from vz8 commit e16aab1)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Feature: mm: avoid high order allocations in all subsystems
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Jan 10, 2023
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>

(cherry picked from vz8 commit e16aab1)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Feature: mm: avoid high order allocations in all subsystems
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Jan 10, 2023
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>

(cherry picked from vz8 commit e16aab1)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Feature: mm: avoid high order allocations in all subsystems
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Apr 1, 2023
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>

(cherry picked from vz8 commit e16aab1)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Feature: mm: avoid high order allocations in all subsystems
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Jul 7, 2023
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>

(cherry picked from vz8 commit e16aab1)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Feature: mm: avoid high order allocations in all subsystems
@github-actions
Copy link

github-actions bot commented Aug 5, 2023

This PR has been open for 60 days with no activity and no assignee. It will be closed in 7 days unless a comment is added.

@github-actions github-actions bot added the stale label Aug 5, 2023
@euspectre
Copy link
Contributor Author

Nothing more to do here. Closing.

@euspectre euspectre closed this Aug 5, 2023
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Aug 18, 2023
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>

(cherry picked from vz8 commit e16aab1)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Feature: mm: avoid high order allocations in all subsystems
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Sep 9, 2023
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>

(cherry picked from vz8 commit e16aab1)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Feature: mm: avoid high order allocations in all subsystems
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Sep 23, 2023
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file /sys/module/<module_name>/sections/<section_name>
for each loaded section when the patch module is being loaded, see
add_sect_attrs() in kernel/module.c. A big chunk of memory is allocated
for all these with kzalloc.

For the ReadyKernel patches we have already released, the amount of memory
could be as high as 34528 bytes (48 + 80 * 431 loaded sections), which is
a 4th order allocation. 3rd order allocations are also common here,
see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel patches
are often used in the systems with rather significant uptime, so the
fragmentation is possible.

It could be better if the patch modules did not use too many ELF sections.
However, the KPatch maintainers pointed out (dynup/kpatch#1131)
that the same problem would affect regular kernel modules as well after
FGKASLR has been merged into the mainline kernel. Combining the sections
of the kernel modules destroys the purpose of FGKASLR, so, it was agreed
that we probably should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion: https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108015
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Jan 19, 2024
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>

(cherry picked from vz8 commit e16aab1)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Feature: mm: avoid high order allocations in all subsystems
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Apr 9, 2024
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>

(cherry picked from vz8 commit e16aab1)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Feature: mm: avoid high order allocations in all subsystems
openvz-integrator pushed a commit to OpenVZ/vzkernel that referenced this pull request Apr 9, 2024
A kernel module containing a ReadyKernel patch could have lots of ELF
sections: one per each new or patched function, one per each new static
or global variable, etc.

The kernel creates a sysfs file
/sys/module/<module_name>/sections/<section_name> for each loaded
section when the patch module is being loaded, see add_sect_attrs() in
kernel/module.c. A big chunk of memory is allocated for all these with
kzalloc.

For the ReadyKernel patches we have already released, the amount of
memory could be as high as 34528 bytes (48 + 80 * 431 loaded sections),
which is a 4th order allocation. 3rd order allocations are also common
here, see https://jira.sw.ru/browse/PSBM-95050.

Not only it is a waste (contiguous memory is not needed there), but the
allocation may also fail when the memory is fragmented. ReadyKernel
patches are often used in the systems with rather significant uptime, so
the fragmentation is possible.

It could be better if the patch modules did not use too many ELF
sections. However, the KPatch maintainers pointed out
(dynup/kpatch#1131) that the same problem would
affect regular kernel modules as well after FGKASLR has been merged into
the mainline kernel. Combining the sections of the kernel modules
destroys the purpose of FGKASLR, so, it was agreed that we probably
should just switch to kvmalloc+kvfree in add_sect_attrs/free_sect_attrs.

Details and discussion:
https://www.spinics.net/lists/live-patching/msg06364.html

https://jira.sw.ru/browse/PSBM-108017
Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>

(cherry picked from vz8 commit e16aab1)
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
Feature: mm: avoid high order allocations in all subsystems
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants