Skip to content

Commit 401c58f

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: "This is larger than usual: the main reason are the ARM symbol lookup speedups that came in late and were hard to resist. There's also a kprobes fix and various tooling fixes, plus the minimal re-enablement of the mmap2 support interface" * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (36 commits) x86/kprobes: Fix build errors and blacklist context_track_user perf tests: Add test for closing dso objects on EMFILE error perf tests: Add test for caching dso file descriptors perf tests: Allow reuse of test_file function perf tests: Spawn child for each test perf tools: Add dso__data_* interface descriptons perf tools: Allow to close dso fd in case of open failure perf tools: Add file size check and factor dso__data_read_offset perf tools: Cache dso data file descriptor perf tools: Add global count of opened dso objects perf tools: Add global list of opened dso objects perf tools: Add data_fd into dso object perf tools: Separate dso data related variables perf tools: Cache register accesses for unwind processing perf record: Fix to honor user freq/interval properly perf timechart: Reflow documentation perf probe: Improve error messages in --line option perf probe: Improve an error message of perf probe --vars mode perf probe: Show error code and description in verbose mode perf probe: Improve error message for unknown member of data structure ...
2 parents 7b08d61 + cf23091 commit 401c58f

41 files changed

Lines changed: 1249 additions & 126 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎arch/x86/kernel/traps.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code)
343343
if (poke_int3_handler(regs))
344344
return;
345345

346+
prev_state = exception_enter();
346347
#ifdef CONFIG_KGDB_LOW_LEVEL_TRAP
347348
if (kgdb_ll_trap(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP,
348349
SIGTRAP) == NOTIFY_STOP)
@@ -351,9 +352,8 @@ dotraplinkage void notrace do_int3(struct pt_regs *regs, long error_code)
351352

352353
#ifdef CONFIG_KPROBES
353354
if (kprobe_int3_handler(regs))
354-
return;
355+
goto exit;
355356
#endif
356-
prev_state = exception_enter();
357357

358358
if (notify_die(DIE_INT3, "int3", regs, error_code, X86_TRAP_BP,
359359
SIGTRAP) == NOTIFY_STOP)
@@ -433,6 +433,8 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
433433
unsigned long dr6;
434434
int si_code;
435435

436+
prev_state = exception_enter();
437+
436438
get_debugreg(dr6, 6);
437439

438440
/* Filter out all the reserved bits which are preset to 1 */
@@ -465,7 +467,6 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
465467
if (kprobe_debug_handler(regs))
466468
goto exit;
467469
#endif
468-
prev_state = exception_enter();
469470

470471
if (notify_die(DIE_DEBUG, "debug", regs, (long)&dr6, error_code,
471472
SIGTRAP) == NOTIFY_STOP)

‎include/uapi/linux/perf_event.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ enum perf_event_type {
705705
* u32 min;
706706
* u64 ino;
707707
* u64 ino_generation;
708+
* u32 prot, flags;
708709
* char filename[];
709710
* struct sample_id sample_id;
710711
* };

‎kernel/context_tracking.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/sched.h>
2020
#include <linux/hardirq.h>
2121
#include <linux/export.h>
22+
#include <linux/kprobes.h>
2223

2324
#define CREATE_TRACE_POINTS
2425
#include <trace/events/context_tracking.h>
@@ -104,6 +105,7 @@ void context_tracking_user_enter(void)
104105
}
105106
local_irq_restore(flags);
106107
}
108+
NOKPROBE_SYMBOL(context_tracking_user_enter);
107109

108110
#ifdef CONFIG_PREEMPT
109111
/**
@@ -181,6 +183,7 @@ void context_tracking_user_exit(void)
181183
}
182184
local_irq_restore(flags);
183185
}
186+
NOKPROBE_SYMBOL(context_tracking_user_exit);
184187

185188
/**
186189
* __context_tracking_task_switch - context switch the syscall callbacks

‎kernel/events/core.c‎

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <linux/mm_types.h>
4141
#include <linux/cgroup.h>
4242
#include <linux/module.h>
43+
#include <linux/mman.h>
4344

4445
#include "internal.h"
4546

@@ -5128,6 +5129,7 @@ struct perf_mmap_event {
51285129
int maj, min;
51295130
u64 ino;
51305131
u64 ino_generation;
5132+
u32 prot, flags;
51315133

51325134
struct {
51335135
struct perf_event_header header;
@@ -5169,6 +5171,8 @@ static void perf_event_mmap_output(struct perf_event *event,
51695171
mmap_event->event_id.header.size += sizeof(mmap_event->min);
51705172
mmap_event->event_id.header.size += sizeof(mmap_event->ino);
51715173
mmap_event->event_id.header.size += sizeof(mmap_event->ino_generation);
5174+
mmap_event->event_id.header.size += sizeof(mmap_event->prot);
5175+
mmap_event->event_id.header.size += sizeof(mmap_event->flags);
51725176
}
51735177

51745178
perf_event_header__init_id(&mmap_event->event_id.header, &sample, event);
@@ -5187,6 +5191,8 @@ static void perf_event_mmap_output(struct perf_event *event,
51875191
perf_output_put(&handle, mmap_event->min);
51885192
perf_output_put(&handle, mmap_event->ino);
51895193
perf_output_put(&handle, mmap_event->ino_generation);
5194+
perf_output_put(&handle, mmap_event->prot);
5195+
perf_output_put(&handle, mmap_event->flags);
51905196
}
51915197

51925198
__output_copy(&handle, mmap_event->file_name,
@@ -5205,6 +5211,7 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
52055211
struct file *file = vma->vm_file;
52065212
int maj = 0, min = 0;
52075213
u64 ino = 0, gen = 0;
5214+
u32 prot = 0, flags = 0;
52085215
unsigned int size;
52095216
char tmp[16];
52105217
char *buf = NULL;
@@ -5235,6 +5242,28 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
52355242
gen = inode->i_generation;
52365243
maj = MAJOR(dev);
52375244
min = MINOR(dev);
5245+
5246+
if (vma->vm_flags & VM_READ)
5247+
prot |= PROT_READ;
5248+
if (vma->vm_flags & VM_WRITE)
5249+
prot |= PROT_WRITE;
5250+
if (vma->vm_flags & VM_EXEC)
5251+
prot |= PROT_EXEC;
5252+
5253+
if (vma->vm_flags & VM_MAYSHARE)
5254+
flags = MAP_SHARED;
5255+
else
5256+
flags = MAP_PRIVATE;
5257+
5258+
if (vma->vm_flags & VM_DENYWRITE)
5259+
flags |= MAP_DENYWRITE;
5260+
if (vma->vm_flags & VM_MAYEXEC)
5261+
flags |= MAP_EXECUTABLE;
5262+
if (vma->vm_flags & VM_LOCKED)
5263+
flags |= MAP_LOCKED;
5264+
if (vma->vm_flags & VM_HUGETLB)
5265+
flags |= MAP_HUGETLB;
5266+
52385267
goto got_name;
52395268
} else {
52405269
name = (char *)arch_vma_name(vma);
@@ -5275,6 +5304,8 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
52755304
mmap_event->min = min;
52765305
mmap_event->ino = ino;
52775306
mmap_event->ino_generation = gen;
5307+
mmap_event->prot = prot;
5308+
mmap_event->flags = flags;
52785309

52795310
if (!(vma->vm_flags & VM_EXEC))
52805311
mmap_event->event_id.header.misc |= PERF_RECORD_MISC_MMAP_DATA;
@@ -5315,6 +5346,8 @@ void perf_event_mmap(struct vm_area_struct *vma)
53155346
/* .min (attr_mmap2 only) */
53165347
/* .ino (attr_mmap2 only) */
53175348
/* .ino_generation (attr_mmap2 only) */
5349+
/* .prot (attr_mmap2 only) */
5350+
/* .flags (attr_mmap2 only) */
53185351
};
53195352

53205353
perf_event_mmap_event(&mmap_event);
@@ -6897,10 +6930,6 @@ static int perf_copy_attr(struct perf_event_attr __user *uattr,
68976930
if (ret)
68986931
return -EFAULT;
68996932

6900-
/* disabled for now */
6901-
if (attr->mmap2)
6902-
return -EINVAL;
6903-
69046933
if (attr->__reserved_1)
69056934
return -EINVAL;
69066935

‎tools/lib/traceevent/event-parse.c‎

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,9 @@ static void free_arg(struct print_arg *arg)
765765
case PRINT_BSTRING:
766766
free(arg->string.string);
767767
break;
768+
case PRINT_BITMASK:
769+
free(arg->bitmask.bitmask);
770+
break;
768771
case PRINT_DYNAMIC_ARRAY:
769772
free(arg->dynarray.index);
770773
break;
@@ -2268,6 +2271,7 @@ static int arg_num_eval(struct print_arg *arg, long long *val)
22682271
case PRINT_FIELD ... PRINT_SYMBOL:
22692272
case PRINT_STRING:
22702273
case PRINT_BSTRING:
2274+
case PRINT_BITMASK:
22712275
default:
22722276
do_warning("invalid eval type %d", arg->type);
22732277
ret = 0;
@@ -2296,6 +2300,7 @@ static char *arg_eval (struct print_arg *arg)
22962300
case PRINT_FIELD ... PRINT_SYMBOL:
22972301
case PRINT_STRING:
22982302
case PRINT_BSTRING:
2303+
case PRINT_BITMASK:
22992304
default:
23002305
do_warning("invalid eval type %d", arg->type);
23012306
break;
@@ -2683,6 +2688,35 @@ process_str(struct event_format *event __maybe_unused, struct print_arg *arg,
26832688
return EVENT_ERROR;
26842689
}
26852690

2691+
static enum event_type
2692+
process_bitmask(struct event_format *event __maybe_unused, struct print_arg *arg,
2693+
char **tok)
2694+
{
2695+
enum event_type type;
2696+
char *token;
2697+
2698+
if (read_expect_type(EVENT_ITEM, &token) < 0)
2699+
goto out_free;
2700+
2701+
arg->type = PRINT_BITMASK;
2702+
arg->bitmask.bitmask = token;
2703+
arg->bitmask.offset = -1;
2704+
2705+
if (read_expected(EVENT_DELIM, ")") < 0)
2706+
goto out_err;
2707+
2708+
type = read_token(&token);
2709+
*tok = token;
2710+
2711+
return type;
2712+
2713+
out_free:
2714+
free_token(token);
2715+
out_err:
2716+
*tok = NULL;
2717+
return EVENT_ERROR;
2718+
}
2719+
26862720
static struct pevent_function_handler *
26872721
find_func_handler(struct pevent *pevent, char *func_name)
26882722
{
@@ -2797,6 +2831,10 @@ process_function(struct event_format *event, struct print_arg *arg,
27972831
free_token(token);
27982832
return process_str(event, arg, tok);
27992833
}
2834+
if (strcmp(token, "__get_bitmask") == 0) {
2835+
free_token(token);
2836+
return process_bitmask(event, arg, tok);
2837+
}
28002838
if (strcmp(token, "__get_dynamic_array") == 0) {
28012839
free_token(token);
28022840
return process_dynamic_array(event, arg, tok);
@@ -3324,6 +3362,7 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
33243362
return eval_type(val, arg, 0);
33253363
case PRINT_STRING:
33263364
case PRINT_BSTRING:
3365+
case PRINT_BITMASK:
33273366
return 0;
33283367
case PRINT_FUNC: {
33293368
struct trace_seq s;
@@ -3556,6 +3595,60 @@ static void print_str_to_seq(struct trace_seq *s, const char *format,
35563595
trace_seq_printf(s, format, str);
35573596
}
35583597

3598+
static void print_bitmask_to_seq(struct pevent *pevent,
3599+
struct trace_seq *s, const char *format,
3600+
int len_arg, const void *data, int size)
3601+
{
3602+
int nr_bits = size * 8;
3603+
int str_size = (nr_bits + 3) / 4;
3604+
int len = 0;
3605+
char buf[3];
3606+
char *str;
3607+
int index;
3608+
int i;
3609+
3610+
/*
3611+
* The kernel likes to put in commas every 32 bits, we
3612+
* can do the same.
3613+
*/
3614+
str_size += (nr_bits - 1) / 32;
3615+
3616+
str = malloc(str_size + 1);
3617+
if (!str) {
3618+
do_warning("%s: not enough memory!", __func__);
3619+
return;
3620+
}
3621+
str[str_size] = 0;
3622+
3623+
/* Start out with -2 for the two chars per byte */
3624+
for (i = str_size - 2; i >= 0; i -= 2) {
3625+
/*
3626+
* data points to a bit mask of size bytes.
3627+
* In the kernel, this is an array of long words, thus
3628+
* endianess is very important.
3629+
*/
3630+
if (pevent->file_bigendian)
3631+
index = size - (len + 1);
3632+
else
3633+
index = len;
3634+
3635+
snprintf(buf, 3, "%02x", *((unsigned char *)data + index));
3636+
memcpy(str + i, buf, 2);
3637+
len++;
3638+
if (!(len & 3) && i > 0) {
3639+
i--;
3640+
str[i] = ',';
3641+
}
3642+
}
3643+
3644+
if (len_arg >= 0)
3645+
trace_seq_printf(s, format, len_arg, str);
3646+
else
3647+
trace_seq_printf(s, format, str);
3648+
3649+
free(str);
3650+
}
3651+
35593652
static void print_str_arg(struct trace_seq *s, void *data, int size,
35603653
struct event_format *event, const char *format,
35613654
int len_arg, struct print_arg *arg)
@@ -3691,6 +3784,23 @@ static void print_str_arg(struct trace_seq *s, void *data, int size,
36913784
case PRINT_BSTRING:
36923785
print_str_to_seq(s, format, len_arg, arg->string.string);
36933786
break;
3787+
case PRINT_BITMASK: {
3788+
int bitmask_offset;
3789+
int bitmask_size;
3790+
3791+
if (arg->bitmask.offset == -1) {
3792+
struct format_field *f;
3793+
3794+
f = pevent_find_any_field(event, arg->bitmask.bitmask);
3795+
arg->bitmask.offset = f->offset;
3796+
}
3797+
bitmask_offset = data2host4(pevent, data + arg->bitmask.offset);
3798+
bitmask_size = bitmask_offset >> 16;
3799+
bitmask_offset &= 0xffff;
3800+
print_bitmask_to_seq(pevent, s, format, len_arg,
3801+
data + bitmask_offset, bitmask_size);
3802+
break;
3803+
}
36943804
case PRINT_OP:
36953805
/*
36963806
* The only op for string should be ? :
@@ -4822,6 +4932,9 @@ static void print_args(struct print_arg *args)
48224932
case PRINT_BSTRING:
48234933
printf("__get_str(%s)", args->string.string);
48244934
break;
4935+
case PRINT_BITMASK:
4936+
printf("__get_bitmask(%s)", args->bitmask.bitmask);
4937+
break;
48254938
case PRINT_TYPE:
48264939
printf("(%s)", args->typecast.type);
48274940
print_args(args->typecast.item);

0 commit comments

Comments
 (0)