Skip to content

Commit bf4be47

Browse files
committed
Merge pull request #191 from jpoimboe/revert-dynamic
Revert #186 (add dynamic symbol linking support)
2 parents d349d70 + 5e25365 commit bf4be47

File tree

12 files changed

+799
-653
lines changed

12 files changed

+799
-653
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
*.swp
88
.tmp_versions
99
Module.symvers
10-
kpatch-build/lookup
10+
kpatch-build/add-patches-section
1111
kpatch-build/create-diff-object
12+
kpatch-build/link-vmlinux-syms
1213
man/kpatch.1.gz
1314
man/kpatch-build.1.gz
1415
test/integration/test.log

kmod/core/core.c

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include <linux/ftrace.h>
4141
#include <linux/hashtable.h>
4242
#include <linux/hardirq.h>
43-
#include <linux/uaccess.h>
4443
#include <asm/stacktrace.h>
4544
#include <asm/cacheflush.h>
4645
#include "kpatch.h"
@@ -425,10 +424,6 @@ int kpatch_register(struct kpatch_module *kpmod, bool replace)
425424
int ret, i;
426425
struct kpatch_func *funcs, *func;
427426
int num_funcs = kpmod->patches_nr;
428-
struct kpatch_dynrela *dynrela;
429-
void *loc;
430-
u64 val;
431-
int size;
432427

433428
if (!kpmod->mod || !kpmod->patches || !num_funcs)
434429
return -EINVAL;
@@ -453,34 +448,6 @@ int kpatch_register(struct kpatch_module *kpmod, bool replace)
453448
goto err_up;
454449
}
455450

456-
for (i = 0; i < kpmod->dynrelas_nr; i++) {
457-
dynrela = &kpmod->dynrelas[i];
458-
switch (dynrela->type) {
459-
case R_X86_64_PC32:
460-
loc = (void *)dynrela->dest;
461-
val = (u32)(dynrela->src - dynrela->dest);
462-
size = 4;
463-
break;
464-
case R_X86_64_32S:
465-
loc = (void *)dynrela->dest;
466-
val = (s32)dynrela->src;
467-
size = 4;
468-
break;
469-
default:
470-
printk("unsupported rela type %ld for "
471-
"0x%lx <- 0x%lx at index %d\n",
472-
dynrela->type, dynrela->dest,
473-
dynrela->src, i);
474-
ret = -EINVAL;
475-
goto err_put;
476-
}
477-
set_memory_rw((unsigned long)loc & PAGE_MASK, 1);
478-
ret = probe_kernel_write(loc, &val, size);
479-
set_memory_ro((unsigned long)loc & PAGE_MASK, 1);
480-
if (ret)
481-
goto err_put;
482-
}
483-
484451
for (i = 0; i < num_funcs; i++) {
485452
func = &funcs[i];
486453

@@ -597,7 +564,6 @@ int kpatch_register(struct kpatch_module *kpmod, bool replace)
597564
kpatch_num_registered--;
598565
err_rollback:
599566
kpatch_remove_funcs_from_filter(funcs, num_funcs);
600-
err_put:
601567
module_put(kpmod->mod);
602568
err_up:
603569
up(&kpatch_mutex);

kmod/core/kpatch.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ struct kpatch_patch {
3030
unsigned long old_size;
3131
};
3232

33-
struct kpatch_dynrela {
34-
unsigned long dest;
35-
unsigned long src;
36-
unsigned long type;
37-
};
38-
3933
#ifdef __KERNEL__
4034

4135
#include <linux/types.h>
@@ -46,9 +40,7 @@ struct kpatch_internal;
4640
struct kpatch_module {
4741
struct module *mod;
4842
struct kpatch_patch *patches;
49-
struct kpatch_dynrela *dynrelas;
5043
int patches_nr;
51-
int dynrelas_nr;
5244
bool enabled;
5345
struct kpatch_internal *internal; /* used internally by core module */
5446
};

kmod/patch/kpatch-patch-hook.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ module_param(replace, bool, S_IRUGO);
2929
MODULE_PARM_DESC(replace, "replace all previously loaded patch modules");
3030

3131
extern char __kpatch_patches, __kpatch_patches_end;
32-
extern char __kpatch_dynrelas, __kpatch_dynrelas_end;
3332

3433
static struct kpatch_module kpmod;
3534
static struct kobject *patch_kobj;
@@ -72,15 +71,13 @@ static struct kobj_attribute patch_enabled_attr =
7271

7372
static int __init patch_init(void)
7473
{
74+
struct kpatch_patch *patches;
7575
int ret;
7676

7777
kpmod.mod = THIS_MODULE;
7878
kpmod.patches = (struct kpatch_patch *)&__kpatch_patches;
7979
kpmod.patches_nr = (&__kpatch_patches_end - &__kpatch_patches) /
80-
sizeof(*kpmod.patches);
81-
kpmod.dynrelas = (struct kpatch_dynrela *)&__kpatch_dynrelas;
82-
kpmod.dynrelas_nr = (&__kpatch_dynrelas_end - &__kpatch_dynrelas) /
83-
sizeof(*kpmod.dynrelas);
80+
sizeof(*patches);
8481

8582
patch_kobj = kobject_create_and_add(THIS_MODULE->name,
8683
kpatch_patches_kobj);

kmod/patch/kpatch.lds

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
__kpatch_patches = ADDR(.kpatch.patches);
2-
__kpatch_patches_end = ADDR(.kpatch.patches) + SIZEOF(.kpatch.patches);
3-
__kpatch_dynrelas = ADDR(.kpatch.dynrelas);
4-
__kpatch_dynrelas_end = ADDR(.kpatch.dynrelas) + SIZEOF(.kpatch.dynrelas);
1+
__kpatch_patches = ADDR(.patches);
2+
__kpatch_patches_end = ADDR(.patches) + SIZEOF(.patches);

kpatch-build/Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ include ../Makefile.inc
33
CFLAGS += -I../kmod/patch -Wall -g
44
LDFLAGS = -lelf
55

6-
TARGETS = create-diff-object
6+
TARGETS = create-diff-object add-patches-section link-vmlinux-syms
7+
78

89
all: $(TARGETS)
910

10-
create-diff-object: create-diff-object.c list.h lookup.c lookup.h
11-
$(CC) $(CFLAGS) create-diff-object.c lookup.c -o $@ $(LDFLAGS)
11+
%: %.c
12+
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
13+
14+
create-diff-object: create-diff-object.c list.h
15+
$(CC) $(CFLAGS) create-diff-object.c -o $@ $(LDFLAGS)
1216

1317
install: all
1418
$(INSTALL) -d $(LIBEXECDIR)

0 commit comments

Comments
 (0)