1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * livepatch.c - x86-specific Kernel Live Patching Core
6 #include <linux/module.h>
7 #include <linux/kallsyms.h>
8 #include <linux/livepatch.h>
9 #include <asm/text-patching.h>
11 /* Apply per-object alternatives. Based on x86 module_finalize() */
12 void arch_klp_init_object_loaded(struct klp_patch
*patch
,
13 struct klp_object
*obj
)
16 struct klp_modinfo
*info
;
17 Elf_Shdr
*s
, *alt
= NULL
, *para
= NULL
;
20 char sec_objname
[MODULE_NAME_LEN
];
21 char secname
[KSYM_NAME_LEN
];
23 info
= patch
->mod
->klp_info
;
24 objname
= obj
->name
? obj
->name
: "vmlinux";
26 /* See livepatch core code for BUILD_BUG_ON() explanation */
27 BUILD_BUG_ON(MODULE_NAME_LEN
< 56 || KSYM_NAME_LEN
!= 128);
29 for (s
= info
->sechdrs
; s
< info
->sechdrs
+ info
->hdr
.e_shnum
; s
++) {
30 /* Apply per-object .klp.arch sections */
31 cnt
= sscanf(info
->secstrings
+ s
->sh_name
,
32 ".klp.arch.%55[^.].%127s",
33 sec_objname
, secname
);
36 if (strcmp(sec_objname
, objname
))
38 if (!strcmp(".altinstructions", secname
))
40 if (!strcmp(".parainstructions", secname
))
45 aseg
= (void *) alt
->sh_addr
;
46 apply_alternatives(aseg
, aseg
+ alt
->sh_size
);
50 pseg
= (void *) para
->sh_addr
;
51 apply_paravirt(pseg
, pseg
+ para
->sh_size
);