-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf trace beauty: Beautify pkey_{alloc,free,mprotect} arguments
Reuse 'mprotect' beautifiers for 'pkey_mprotect'. System wide tracing pkey_alloc, pkey_free and pkey_mprotect calls, with backtraces: # perf trace -e pkey_alloc,pkey_mprotect,pkey_free --max-stack=5 0.000 ( 0.011 ms): pkey/7818 pkey_alloc(init_val: DISABLE_ACCESS|DISABLE_WRITE) = -1 EINVAL Invalid argument syscall (/usr/lib64/libc-2.25.so) pkey_alloc (/home/acme/c/pkey) 0.022 ( 0.003 ms): pkey/7818 pkey_mprotect(start: 0x7f28c3890000, len: 4096, prot: READ|WRITE, pkey: -1) = 0 syscall (/usr/lib64/libc-2.25.so) pkey_mprotect (/home/acme/c/pkey) 0.030 ( 0.002 ms): pkey/7818 pkey_free(pkey: -1 ) = -1 EINVAL Invalid argument syscall (/usr/lib64/libc-2.25.so) pkey_free (/home/acme/c/pkey) The tools/include/uapi/asm-generic/mman-common.h file is used to find the access rights defines for the pkey_alloc syscall second argument. Since we have the detector of changes for the tools/include header files versus its kernel origin (include/uapi/asm-generic/mman-common.h), we'll get whatever new flag appears for that argument automatically. This method should be used in other cases where it is easy to generate those flags tables because the header has properly namespaced defines like PKEY_DISABLE_ACCESS and PKEY_DISABLE_WRITE. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-3xq5312qlks7wtfzv2sk3nct@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
- Loading branch information
Arnaldo Carvalho de Melo
committed
Aug 28, 2017
1 parent
a2105f8
commit 83bc9c3
Showing
6 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* trace/beauty/pkey_alloc.c | ||
* | ||
* Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> | ||
* | ||
* Released under the GPL v2. (and only v2, not any later version) | ||
*/ | ||
|
||
#include "trace/beauty/beauty.h" | ||
#include <linux/kernel.h> | ||
#include <linux/log2.h> | ||
|
||
static size_t pkey_alloc__scnprintf_access_rights(int access_rights, char *bf, size_t size) | ||
{ | ||
int i, printed = 0; | ||
|
||
#include "trace/beauty/generated/pkey_alloc_access_rights_array.c" | ||
static DEFINE_STRARRAY(pkey_alloc_access_rights); | ||
|
||
if (access_rights == 0) { | ||
const char *s = strarray__pkey_alloc_access_rights.entries[0]; | ||
if (s) | ||
return scnprintf(bf, size, "%s", s); | ||
return scnprintf(bf, size, "%d", 0); | ||
} | ||
|
||
for (i = 1; i < strarray__pkey_alloc_access_rights.nr_entries; ++i) { | ||
int bit = 1 << (i - 1); | ||
|
||
if (!(access_rights & bit)) | ||
continue; | ||
|
||
if (printed != 0) | ||
printed += scnprintf(bf + printed, size - printed, "|"); | ||
|
||
if (strarray__pkey_alloc_access_rights.entries[i] != NULL) | ||
printed += scnprintf(bf + printed, size - printed, "%s", strarray__pkey_alloc_access_rights.entries[i]); | ||
else | ||
printed += scnprintf(bf + printed, size - printed, "0x%#", bit); | ||
} | ||
|
||
return printed; | ||
} | ||
|
||
size_t syscall_arg__scnprintf_pkey_alloc_access_rights(char *bf, size_t size, struct syscall_arg *arg) | ||
{ | ||
unsigned long cmd = arg->val; | ||
|
||
return pkey_alloc__scnprintf_access_rights(cmd, bf, size); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/sh | ||
|
||
header_dir=$1 | ||
|
||
printf "static const char *pkey_alloc_access_rights[] = {\n" | ||
regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+PKEY_([[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*' | ||
egrep $regex ${header_dir}/mman-common.h | \ | ||
sed -r "s/$regex/\2 \2 \1/g" | \ | ||
sort | xargs printf "\t[%s ? (ilog2(%s) + 1) : 0] = \"%s\",\n" | ||
printf "};\n" |