Skip to content

Commit 1d05334

Browse files
Peter ZijlstraJiri Kosina
authored andcommitted
livepatch: Remove .klp.arch
After the previous patch, vmlinux-specific KLP relocations are now applied early during KLP module load. This means that .klp.arch sections are no longer needed for *vmlinux-specific* KLP relocations. One might think they're still needed for *module-specific* KLP relocations. If a to-be-patched module is loaded *after* its corresponding KLP module is loaded, any corresponding KLP relocations will be delayed until the to-be-patched module is loaded. If any special sections (.parainstructions, for example) rely on those relocations, their initializations (apply_paravirt) need to be done afterwards. Thus the apparent need for arch_klp_init_object_loaded() and its corresponding .klp.arch sections -- it allows some of the special section initializations to be done at a later time. But... if you look closer, that dependency between the special sections and the module-specific KLP relocations doesn't actually exist in reality. Looking at the contents of the .altinstructions and .parainstructions sections, there's not a realistic scenario in which a KLP module's .altinstructions or .parainstructions section needs to access a symbol in a to-be-patched module. It might need to access a local symbol or even a vmlinux symbol; but not another module's symbol. When a special section needs to reference a local or vmlinux symbol, a normal rela can be used instead of a KLP rela. Since the special section initializations don't actually have any real dependency on module-specific KLP relocations, .klp.arch and arch_klp_init_object_loaded() no longer have a reason to exist. So remove them. As Peter said much more succinctly: So the reason for .klp.arch was that .klp.rela.* stuff would overwrite paravirt instructions. If that happens you're doing it wrong. Those RELAs are core kernel, not module, and thus should've happened in .rela.* sections at patch-module loading time. Reverting this removes the two apply_{paravirt,alternatives}() calls from the late patching path, and means we don't have to worry about them when removing module_disable_ro(). [ jpoimboe: Rewrote patch description. Tweaked klp_init_object_loaded() error path. ] Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Josh Poimboeuf <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Joe Lawrence <[email protected]> Acked-by: Miroslav Benes <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 7c8e2bd commit 1d05334

File tree

5 files changed

+11
-88
lines changed

5 files changed

+11
-88
lines changed

Documentation/livepatch/module-elf-format.rst

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ This document outlines the Elf format requirements that livepatch modules must f
1414
4. Livepatch symbols
1515
4.1 A livepatch module's symbol table
1616
4.2 Livepatch symbol format
17-
5. Architecture-specific sections
18-
6. Symbol table and Elf section access
17+
5. Symbol table and Elf section access
1918
2019
1. Background and motivation
2120
============================
@@ -298,17 +297,7 @@ Examples:
298297
Note that the 'Ndx' (Section index) for these symbols is SHN_LIVEPATCH (0xff20).
299298
"OS" means OS-specific.
300299

301-
5. Architecture-specific sections
302-
=================================
303-
Architectures may override arch_klp_init_object_loaded() to perform
304-
additional arch-specific tasks when a target module loads, such as applying
305-
arch-specific sections. On x86 for example, we must apply per-object
306-
.altinstructions and .parainstructions sections when a target module loads.
307-
These sections must be prefixed with ".klp.arch.$objname." so that they can
308-
be easily identified when iterating through a patch module's Elf sections
309-
(See arch/x86/kernel/livepatch.c for a complete example).
310-
311-
6. Symbol table and Elf section access
300+
5. Symbol table and Elf section access
312301
======================================
313302
A livepatch module's symbol table is accessible through module->symtab.
314303

arch/x86/kernel/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ obj-$(CONFIG_X86_MPPARSE) += mpparse.o
9090
obj-y += apic/
9191
obj-$(CONFIG_X86_REBOOTFIXUPS) += reboot_fixups_32.o
9292
obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o
93-
obj-$(CONFIG_LIVEPATCH) += livepatch.o
9493
obj-$(CONFIG_FUNCTION_TRACER) += ftrace_$(BITS).o
9594
obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o
9695
obj-$(CONFIG_FTRACE_SYSCALLS) += ftrace.o

arch/x86/kernel/livepatch.c

Lines changed: 0 additions & 53 deletions
This file was deleted.

include/linux/livepatch.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,6 @@ struct klp_patch {
195195

196196
int klp_enable_patch(struct klp_patch *);
197197

198-
void arch_klp_init_object_loaded(struct klp_patch *patch,
199-
struct klp_object *obj);
200-
201198
/* Called from the module loader during module coming/going states */
202199
int klp_module_coming(struct module *mod);
203200
void klp_module_going(struct module *mod);

kernel/livepatch/core.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -729,12 +729,6 @@ static int klp_init_func(struct klp_object *obj, struct klp_func *func)
729729
func->old_sympos ? func->old_sympos : 1);
730730
}
731731

732-
/* Arches may override this to finish any remaining arch-specific tasks */
733-
void __weak arch_klp_init_object_loaded(struct klp_patch *patch,
734-
struct klp_object *obj)
735-
{
736-
}
737-
738732
int klp_apply_object_relocs(struct klp_patch *patch, struct klp_object *obj)
739733
{
740734
int i, ret;
@@ -764,28 +758,25 @@ static int klp_init_object_loaded(struct klp_patch *patch,
764758
struct klp_func *func;
765759
int ret;
766760

767-
mutex_lock(&text_mutex);
768-
module_disable_ro(patch->mod);
769-
770761
if (klp_is_module(obj)) {
762+
763+
mutex_lock(&text_mutex);
764+
module_disable_ro(patch->mod);
765+
771766
/*
772767
* Only write module-specific relocations here
773768
* (.klp.rela.{module}.*). vmlinux-specific relocations were
774769
* written earlier during the initialization of the klp module
775770
* itself.
776771
*/
777772
ret = klp_apply_object_relocs(patch, obj);
778-
if (ret) {
779-
module_enable_ro(patch->mod, true);
780-
mutex_unlock(&text_mutex);
781-
return ret;
782-
}
783-
}
784773

785-
arch_klp_init_object_loaded(patch, obj);
774+
module_enable_ro(patch->mod, true);
775+
mutex_unlock(&text_mutex);
786776

787-
module_enable_ro(patch->mod, true);
788-
mutex_unlock(&text_mutex);
777+
if (ret)
778+
return ret;
779+
}
789780

790781
klp_for_each_func(obj, func) {
791782
ret = klp_find_object_symbol(obj->name, func->old_name,

0 commit comments

Comments
 (0)