Skip to content

Commit d890e6a

Browse files
committed
s390/kprobes: Remove custom insn slot allocator
Since commit c98d2ec ("s390/mm: Uncouple physical vs virtual address spaces") the kernel image and module area are within the same 4GB area. This eliminates the need of a custom insn slot allocator for kprobes within the kernel image, since standard module_alloc() allocated pages are sufficient for PC relative instructions with a signed 32 bit offset. Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
1 parent e7dec0b commit d890e6a

File tree

4 files changed

+10
-89
lines changed

4 files changed

+10
-89
lines changed

arch/s390/kernel/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ obj-$(CONFIG_COMPAT) += compat_linux.o compat_signal.o
5959
obj-$(CONFIG_COMPAT) += $(compat-obj-y)
6060
obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
6161
obj-$(CONFIG_KPROBES) += kprobes.o
62-
obj-$(CONFIG_KPROBES) += kprobes_insn_page.o
6362
obj-$(CONFIG_KPROBES) += mcount.o
6463
obj-$(CONFIG_RETHOOK) += rethook.o
6564
obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o

arch/s390/kernel/kprobes.c

Lines changed: 10 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,13 @@
2424
#include <asm/set_memory.h>
2525
#include <asm/sections.h>
2626
#include <asm/dis.h>
27-
#include "kprobes.h"
2827
#include "entry.h"
2928

3029
DEFINE_PER_CPU(struct kprobe *, current_kprobe);
3130
DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
3231

3332
struct kretprobe_blackpoint kretprobe_blacklist[] = { };
3433

35-
static int insn_page_in_use;
36-
3734
void *alloc_insn_page(void)
3835
{
3936
void *page;
@@ -45,26 +42,6 @@ void *alloc_insn_page(void)
4542
return page;
4643
}
4744

48-
static void *alloc_s390_insn_page(void)
49-
{
50-
if (xchg(&insn_page_in_use, 1) == 1)
51-
return NULL;
52-
return &kprobes_insn_page;
53-
}
54-
55-
static void free_s390_insn_page(void *page)
56-
{
57-
xchg(&insn_page_in_use, 0);
58-
}
59-
60-
struct kprobe_insn_cache kprobe_s390_insn_slots = {
61-
.mutex = __MUTEX_INITIALIZER(kprobe_s390_insn_slots.mutex),
62-
.alloc = alloc_s390_insn_page,
63-
.free = free_s390_insn_page,
64-
.pages = LIST_HEAD_INIT(kprobe_s390_insn_slots.pages),
65-
.insn_size = MAX_INSN_SIZE,
66-
};
67-
6845
static void copy_instruction(struct kprobe *p)
6946
{
7047
kprobe_opcode_t insn[MAX_INSN_SIZE];
@@ -78,10 +55,10 @@ static void copy_instruction(struct kprobe *p)
7855
if (probe_is_insn_relative_long(&insn[0])) {
7956
/*
8057
* For pc-relative instructions in RIL-b or RIL-c format patch
81-
* the RI2 displacement field. We have already made sure that
82-
* the insn slot for the patched instruction is within the same
83-
* 2GB area as the original instruction (either kernel image or
84-
* module area). Therefore the new displacement will always fit.
58+
* the RI2 displacement field. The insn slot for the to be
59+
* patched instruction is within the same 4GB area like the
60+
* original instruction. Therefore the new displacement will
61+
* always fit.
8562
*/
8663
disp = *(s32 *)&insn[1];
8764
addr = (u64)(unsigned long)p->addr;
@@ -93,34 +70,6 @@ static void copy_instruction(struct kprobe *p)
9370
}
9471
NOKPROBE_SYMBOL(copy_instruction);
9572

96-
static int s390_get_insn_slot(struct kprobe *p)
97-
{
98-
/*
99-
* Get an insn slot that is within the same 2GB area like the original
100-
* instruction. That way instructions with a 32bit signed displacement
101-
* field can be patched and executed within the insn slot.
102-
*/
103-
p->ainsn.insn = NULL;
104-
if (is_kernel((unsigned long)p->addr))
105-
p->ainsn.insn = get_s390_insn_slot();
106-
else if (is_module_addr(p->addr))
107-
p->ainsn.insn = get_insn_slot();
108-
return p->ainsn.insn ? 0 : -ENOMEM;
109-
}
110-
NOKPROBE_SYMBOL(s390_get_insn_slot);
111-
112-
static void s390_free_insn_slot(struct kprobe *p)
113-
{
114-
if (!p->ainsn.insn)
115-
return;
116-
if (is_kernel((unsigned long)p->addr))
117-
free_s390_insn_slot(p->ainsn.insn, 0);
118-
else
119-
free_insn_slot(p->ainsn.insn, 0);
120-
p->ainsn.insn = NULL;
121-
}
122-
NOKPROBE_SYMBOL(s390_free_insn_slot);
123-
12473
/* Check if paddr is at an instruction boundary */
12574
static bool can_probe(unsigned long paddr)
12675
{
@@ -174,7 +123,8 @@ int arch_prepare_kprobe(struct kprobe *p)
174123
/* Make sure the probe isn't going on a difficult instruction */
175124
if (probe_is_prohibited_opcode(p->addr))
176125
return -EINVAL;
177-
if (s390_get_insn_slot(p))
126+
p->ainsn.insn = get_insn_slot();
127+
if (!p->ainsn.insn)
178128
return -ENOMEM;
179129
copy_instruction(p);
180130
return 0;
@@ -216,7 +166,10 @@ NOKPROBE_SYMBOL(arch_disarm_kprobe);
216166

217167
void arch_remove_kprobe(struct kprobe *p)
218168
{
219-
s390_free_insn_slot(p);
169+
if (!p->ainsn.insn)
170+
return;
171+
free_insn_slot(p->ainsn.insn, 0);
172+
p->ainsn.insn = NULL;
220173
}
221174
NOKPROBE_SYMBOL(arch_remove_kprobe);
222175

arch/s390/kernel/kprobes.h

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

arch/s390/kernel/kprobes_insn_page.S

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

0 commit comments

Comments
 (0)