Skip to content

Commit 60295b9

Browse files
committed
tracing: gfp: Fix the GFP enum values shown for user space tracing tools
Tracing tools like perf and trace-cmd read the /sys/kernel/tracing/events/*/*/format files to know how to parse the data and also how to print it. For the "print fmt" portion of that file, if anything uses an enum that is not exported to the tracing system, user space will not be able to parse it. The GFP flags use to be defines, and defines get translated in the print fmt sections. But now they are converted to use enums, which is not. The mm_page_alloc trace event format use to have: print fmt: "page=%p pfn=0x%lx order=%d migratetype=%d gfp_flags=%s", REC->pfn != -1UL ? (((struct page *)vmemmap_base) + (REC->pfn)) : ((void *)0), REC->pfn != -1UL ? REC->pfn : 0, REC->order, REC->migratetype, (REC->gfp_flags) ? __print_flags(REC->gfp_flags, "|", {( unsigned long)(((((((( gfp_t)(0x400u|0x800u)) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x100000u)) | (( gfp_t)0x02u)) | (( gfp_t)0x08u) | (( gfp_t)0)) | (( gfp_t)0x40000u) | (( gfp_t)0x80000u) | (( gfp_t)0x2000u)) & ~(( gfp_t)(0x400u|0x800u))) | (( gfp_t)0x400u)), "GFP_TRANSHUGE"}, {( unsigned long)((((((( gfp_t)(0x400u|0x800u)) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x100000u)) | (( gfp_t)0x02u)) | (( gfp_t)0x08u) | (( gfp_t)0)) ... Where the GFP values are shown and not their names. But after the GFP flags were converted to use enums, it has: print fmt: "page=%p pfn=0x%lx order=%d migratetype=%d gfp_flags=%s", REC->pfn != -1UL ? (vmemmap + (REC->pfn)) : ((void *)0), REC->pfn != -1UL ? REC->pfn : 0, REC->order, REC->migratetype, (REC->gfp_flags) ? __print_flags(REC->gfp_flags, "|", {( unsigned long)(((((((( gfp_t)(((((1UL))) << (___GFP_DIRECT_RECLAIM_BIT))|((((1UL))) << (___GFP_KSWAPD_RECLAIM_BIT)))) | (( gfp_t)((((1UL))) << (___GFP_IO_BIT))) | (( gfp_t)((((1UL))) << (___GFP_FS_BIT))) | (( gfp_t)((((1UL))) << (___GFP_HARDWALL_BIT)))) | (( gfp_t)((((1UL))) << (___GFP_HIGHMEM_BIT)))) | (( gfp_t)((((1UL))) << (___GFP_MOVABLE_BIT))) | (( gfp_t)0)) | (( gfp_t)((((1UL))) << (___GFP_COMP_BIT))) ... Where the enums names like ___GFP_KSWAPD_RECLAIM_BIT are shown and not their values. User space has no way to convert these names to their values and the output will fail to parse. What is shown is now: mm_page_alloc: page=0xffffffff981685f3 pfn=0x1d1ac1 order=0 migratetype=1 gfp_flags=0x140cca The TRACE_DEFINE_ENUM() macro was created to handle enums in the print fmt files. This causes them to be replaced at boot up with the numbers, so that user space tooling can parse it. By using this macro, the output is back to the human readable: mm_page_alloc: page=0xffffffff981685f3 pfn=0x122233 order=0 migratetype=1 gfp_flags=GFP_HIGHUSER_MOVABLE|__GFP_COMP Cc: [email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Veronika Molnarova <[email protected]> Cc: Suren Baghdasaryan <[email protected]> Cc: Linus Torvalds <[email protected]> Link: https://lore.kernel.org/[email protected] Reported-by: Michael Petlan <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Fixes: 772dd03 ("mm: enumerate all gfp flags") Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 94d529a commit 60295b9

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

include/trace/events/mmflags.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,69 @@
1313
* Thus most bits set go first.
1414
*/
1515

16+
/* These define the values that are enums (the bits) */
17+
#define TRACE_GFP_FLAGS_GENERAL \
18+
TRACE_GFP_EM(DMA) \
19+
TRACE_GFP_EM(HIGHMEM) \
20+
TRACE_GFP_EM(DMA32) \
21+
TRACE_GFP_EM(MOVABLE) \
22+
TRACE_GFP_EM(RECLAIMABLE) \
23+
TRACE_GFP_EM(HIGH) \
24+
TRACE_GFP_EM(IO) \
25+
TRACE_GFP_EM(FS) \
26+
TRACE_GFP_EM(ZERO) \
27+
TRACE_GFP_EM(DIRECT_RECLAIM) \
28+
TRACE_GFP_EM(KSWAPD_RECLAIM) \
29+
TRACE_GFP_EM(WRITE) \
30+
TRACE_GFP_EM(NOWARN) \
31+
TRACE_GFP_EM(RETRY_MAYFAIL) \
32+
TRACE_GFP_EM(NOFAIL) \
33+
TRACE_GFP_EM(NORETRY) \
34+
TRACE_GFP_EM(MEMALLOC) \
35+
TRACE_GFP_EM(COMP) \
36+
TRACE_GFP_EM(NOMEMALLOC) \
37+
TRACE_GFP_EM(HARDWALL) \
38+
TRACE_GFP_EM(THISNODE) \
39+
TRACE_GFP_EM(ACCOUNT) \
40+
TRACE_GFP_EM(ZEROTAGS)
41+
42+
#ifdef CONFIG_KASAN_HW_TAGS
43+
# define TRACE_GFP_FLAGS_KASAN \
44+
TRACE_GFP_EM(SKIP_ZERO) \
45+
TRACE_GFP_EM(SKIP_KASAN)
46+
#else
47+
# define TRACE_GFP_FLAGS_KASAN
48+
#endif
49+
50+
#ifdef CONFIG_LOCKDEP
51+
# define TRACE_GFP_FLAGS_LOCKDEP \
52+
TRACE_GFP_EM(NOLOCKDEP)
53+
#else
54+
# define TRACE_GFP_FLAGS_LOCKDEP
55+
#endif
56+
57+
#ifdef CONFIG_SLAB_OBJ_EXT
58+
# define TRACE_GFP_FLAGS_SLAB \
59+
TRACE_GFP_EM(NO_OBJ_EXT)
60+
#else
61+
# define TRACE_GFP_FLAGS_SLAB
62+
#endif
63+
64+
#define TRACE_GFP_FLAGS \
65+
TRACE_GFP_FLAGS_GENERAL \
66+
TRACE_GFP_FLAGS_KASAN \
67+
TRACE_GFP_FLAGS_LOCKDEP \
68+
TRACE_GFP_FLAGS_SLAB
69+
70+
#undef TRACE_GFP_EM
71+
#define TRACE_GFP_EM(a) TRACE_DEFINE_ENUM(___GFP_##a##_BIT);
72+
73+
TRACE_GFP_FLAGS
74+
75+
/* Just in case these are ever used */
76+
TRACE_DEFINE_ENUM(___GFP_UNUSED_BIT);
77+
TRACE_DEFINE_ENUM(___GFP_LAST_BIT);
78+
1679
#define gfpflag_string(flag) {(__force unsigned long)flag, #flag}
1780

1881
#define __def_gfpflag_names \

0 commit comments

Comments
 (0)