Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 54faf77

Browse files
committed
Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf fixes from Ingo Molnar: "Three small fixlets" * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: hw_breakpoint: Use cpu_possible_mask in {reserve,release}_bp_slot() hw_breakpoint: Fix cpu check in task_bp_pinned(cpu) kprobes: Fix arch_prepare_kprobe to handle copy insn failures
2 parents e3ff911 + c790b0a commit 54faf77

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

arch/x86/kernel/kprobes/core.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,14 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
365365
return insn.length;
366366
}
367367

368-
static void __kprobes arch_copy_kprobe(struct kprobe *p)
368+
static int __kprobes arch_copy_kprobe(struct kprobe *p)
369369
{
370+
int ret;
371+
370372
/* Copy an instruction with recovering if other optprobe modifies it.*/
371-
__copy_instruction(p->ainsn.insn, p->addr);
373+
ret = __copy_instruction(p->ainsn.insn, p->addr);
374+
if (!ret)
375+
return -EINVAL;
372376

373377
/*
374378
* __copy_instruction can modify the displacement of the instruction,
@@ -384,6 +388,8 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
384388

385389
/* Also, displacement change doesn't affect the first byte */
386390
p->opcode = p->ainsn.insn[0];
391+
392+
return 0;
387393
}
388394

389395
int __kprobes arch_prepare_kprobe(struct kprobe *p)
@@ -397,8 +403,8 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
397403
p->ainsn.insn = get_insn_slot();
398404
if (!p->ainsn.insn)
399405
return -ENOMEM;
400-
arch_copy_kprobe(p);
401-
return 0;
406+
407+
return arch_copy_kprobe(p);
402408
}
403409

404410
void __kprobes arch_arm_kprobe(struct kprobe *p)

kernel/events/hw_breakpoint.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static int task_bp_pinned(int cpu, struct perf_event *bp, enum bp_type_idx type)
120120
list_for_each_entry(iter, &bp_task_head, hw.bp_list) {
121121
if (iter->hw.bp_target == tsk &&
122122
find_slot_idx(iter) == type &&
123-
cpu == iter->cpu)
123+
(iter->cpu < 0 || cpu == iter->cpu))
124124
count += hw_breakpoint_weight(iter);
125125
}
126126

@@ -149,7 +149,7 @@ fetch_bp_busy_slots(struct bp_busy_slots *slots, struct perf_event *bp,
149149
return;
150150
}
151151

152-
for_each_online_cpu(cpu) {
152+
for_each_possible_cpu(cpu) {
153153
unsigned int nr;
154154

155155
nr = per_cpu(nr_cpu_bp_pinned[type], cpu);
@@ -235,7 +235,7 @@ toggle_bp_slot(struct perf_event *bp, bool enable, enum bp_type_idx type,
235235
if (cpu >= 0) {
236236
toggle_bp_task_slot(bp, cpu, enable, type, weight);
237237
} else {
238-
for_each_online_cpu(cpu)
238+
for_each_possible_cpu(cpu)
239239
toggle_bp_task_slot(bp, cpu, enable, type, weight);
240240
}
241241

0 commit comments

Comments
 (0)