From patchwork Thu Jan 16 18:23:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13942133 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8582DC02187 for ; Thu, 16 Jan 2025 18:23:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1CB3E6B0082; Thu, 16 Jan 2025 13:23:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 17B906B0083; Thu, 16 Jan 2025 13:23:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 069316B0088; Thu, 16 Jan 2025 13:23:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D944B6B0082 for ; Thu, 16 Jan 2025 13:23:57 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8DFB11A112B for ; Thu, 16 Jan 2025 18:23:57 +0000 (UTC) X-FDA: 83014138914.19.869237B Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf21.hostedemail.com (Postfix) with ESMTP id F18CA1C0009 for ; Thu, 16 Jan 2025 18:23:55 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of "SRS0=fJp8=UI=goodmis.org=rostedt@kernel.org" designates 147.75.193.91 as permitted sender) smtp.mailfrom="SRS0=fJp8=UI=goodmis.org=rostedt@kernel.org"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737051836; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=jDudDmb6guyMa5tfGZAyAM4ihYfBFrd7VV1Ma9/C4sY=; b=E8axO87+8+lVMhpGayaGF6QyHfE6kKoClkyzJdiBw5guDpz4sySAHdEvvUx/2be8g5+u9c yD5XbQ+zoG69krqku06f8rhBEslu/3uEpfcflYjzx4vwj2aUF7wTljTOxovANxTW7XrOnx yXHmDOX6HTiep5xMFwklz+7hKaNhoiI= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of "SRS0=fJp8=UI=goodmis.org=rostedt@kernel.org" designates 147.75.193.91 as permitted sender) smtp.mailfrom="SRS0=fJp8=UI=goodmis.org=rostedt@kernel.org"; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737051836; a=rsa-sha256; cv=none; b=xBr+DkGrw0ZexwNaKCcQSJxH/2dBndpnrF0BzPNV12hfBIAj2Eeu7+nmq+c/RDY8OTlJot hwoYaHDnLjUwNVDHN/ydx4fvXEOT/7CcNJlifxAaX47qFooX5hXTpq9+niPn4MoGH6TjjZ 6/DUKyjaNEZ7so5tsL1rWMMfd2URpk4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 4AC28A42707; Thu, 16 Jan 2025 18:22:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5B31C4CED6; Thu, 16 Jan 2025 18:23:53 +0000 (UTC) Date: Thu, 16 Jan 2025 13:23:59 -0500 From: Steven Rostedt To: LKML , Linux Trace Kernel , linux-mm@kvack.org, linux-perf-users@vger.kernel.org Cc: Masami Hiramatsu , Mathieu Desnoyers , Andrew Morton , Michael Petlan , Veronika Molnarova , Suren Baghdasaryan , Linus Torvalds Subject: [PATCH] tracing: gfp: Fix the GFP enum values shown for user space tracing tools Message-ID: <20250116132359.1f20cdec@gandalf.local.home> X-Mailer: Claws Mail 3.20.0git84 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: F18CA1C0009 X-Stat-Signature: iaia1r3wzxx43zbhfc433ea1ua59cxn5 X-Rspam-User: X-HE-Tag: 1737051835-947143 X-HE-Meta: U2FsdGVkX19YhyQJnuH89bo+7inHGmfkSBBk1Kz6I3y3gxb9TTAxkOQ1K6o4qpDa3M0BQpllUHMehNbbF/bzuhnM1bKK5plKFGmWKmqYqeinGBvwbSHbtAHjpOVsQYOUX0kzjcOMgMwzaKUuxNC8uHAcTKFx1gp8e78QDYhTFFeTSlngIpqs5xXKMwXzAbehLVI7Qk3bo3llJr2HM0tTzQYiyxFKF9vRQOXWqsan0iFr18IJ5PRiJg7na8FBvpygB4B+CXq/7Mpi0YuHk4bTtny3SvZAeCgqMTHOsCs7pvvnbhvVbP2RwFMQmgKp0edCdyi/EjVbT1KccF1XAk5iP3e0pKqAiVMme3i4EIMsAtc1Pj+1oIICBdUgSAkqxCQ1ptbqDVJrUnRRRe7Cz14E+49PAbRJ5KYjw5nrpigdnLeRdYW2O/SWek+k6lnlq5V4dYRXwWBPR1xlRkN63XNZf6wzjgRDFaPcfE1wcA1GvsADGPAXfZOYi8Pa8DK2QyFz8tRn7xpOulvSnCYF+sG6oSs7+Y/mIphe81BbXL1GxYEi+pctz37wdTVK6aq3bZF4NB14L1H/3ICman/gFxte4/9sAfclF5M9uw2m5MucoXYe7mbcghD6EmbVR+FKG+XUBeZnFvk+VG10GnQVyzLyUAQAdsQY5kGMeG1+8Mh5Og6LIXpQY14eQUo4ytjSajSudNivAy8io70B9d0tpb2PcJiNMmQlpws1P4rW0ODaesEZOrGIdvPNiZU0WTJS5uwBnzH+bsD3wFirxPHDI7MDfBV50tWkI6JVgy7b0mcDa9XvLFB1w3U1k3pnRuvtE0d8TX6BvGcrIxy5QwbUosGnSvQYE3N55xzNK2hU/gYr0l90hCsCCVwakl/UlhK/tnYgUN7rlIt6LxgqD1HYgPh/5iZOvbzdxdTYin2LTFFHs0nQaJkUOa51Cwx5Xk48HZAdmSeTR4leb7KXgu4ZVvm Gb3mtiEB UOXA/3imxh1Th+i0M1iPut9oeZLBJUrkH1i+JOwPcHwtnvzu00rEGiPLUEA2XmSIHzNj72TvJcwUgeZUc+FQlOkPIrOf6JAIY42wIKz6npK/3q/v/CIu0CzVujp7c02kE5n7U9wncJs6Bvm0Mcc1Fp8/WYjLkSfjDF/xBN5p2k+NApi0dhdf8RQxRPko9rinNwQTw4b8zwV0o132RJob6B/C2hXlUNeTz4AGBwCDC6/FAkUNUb9qY84QWEEzqJboxsPrSUsLYCxq3zzgyL4eHEOj6CFOvGFtP7160pdVBCR4mHXCpNn4f/HAo77xWnzIAlNE5PsIoPDdv+M602Z4A51VwZhgN/ggGWA8M X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Steven Rostedt 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: stable@vger.kernel.org Reported-by: Michael Petlan Closes: https://lore.kernel.org/all/87be5f7c-1a0-dad-daa0-54e342efaea7@redhat.com/ Fixes: 772dd0342727c ("mm: enumerate all gfp flags") Signed-off-by: Steven Rostedt (Google) --- include/linux/gfp_types.h | 47 ++++++++++++++++++++++++++++++++++ include/trace/events/kmem.h | 2 ++ include/trace/events/mmflags.h | 2 ++ 3 files changed, 51 insertions(+) diff --git a/include/linux/gfp_types.h b/include/linux/gfp_types.h index 65db9349f905..57efa0310900 100644 --- a/include/linux/gfp_types.h +++ b/include/linux/gfp_types.h @@ -104,6 +104,53 @@ enum { #define ___GFP_NO_OBJ_EXT 0 #endif +/* Need to have GFP flags convert to numbers in trace event format files */ +#define TRACE_DEFINE_GFP_FLAGS_GENERAL \ + TRACE_DEFINE_ENUM(___GFP_DMA_BIT); \ + TRACE_DEFINE_ENUM(___GFP_HIGHMEM_BIT); \ + TRACE_DEFINE_ENUM(___GFP_DMA32_BIT); \ + TRACE_DEFINE_ENUM(___GFP_MOVABLE_BIT); \ + TRACE_DEFINE_ENUM(___GFP_RECLAIMABLE_BIT); \ + TRACE_DEFINE_ENUM(___GFP_HIGH_BIT); \ + TRACE_DEFINE_ENUM(___GFP_IO_BIT); \ + TRACE_DEFINE_ENUM(___GFP_FS_BIT); \ + TRACE_DEFINE_ENUM(___GFP_ZERO_BIT); \ + TRACE_DEFINE_ENUM(___GFP_UNUSED_BIT); \ + TRACE_DEFINE_ENUM(___GFP_DIRECT_RECLAIM_BIT); \ + TRACE_DEFINE_ENUM(___GFP_KSWAPD_RECLAIM_BIT); \ + TRACE_DEFINE_ENUM(___GFP_WRITE_BIT); \ + TRACE_DEFINE_ENUM(___GFP_NOWARN_BIT); \ + TRACE_DEFINE_ENUM(___GFP_RETRY_MAYFAIL_BIT); \ + TRACE_DEFINE_ENUM(___GFP_NOFAIL_BIT); \ + TRACE_DEFINE_ENUM(___GFP_NORETRY_BIT); \ + TRACE_DEFINE_ENUM(___GFP_MEMALLOC_BIT); \ + TRACE_DEFINE_ENUM(___GFP_COMP_BIT); \ + TRACE_DEFINE_ENUM(___GFP_NOMEMALLOC_BIT); \ + TRACE_DEFINE_ENUM(___GFP_HARDWALL_BIT); \ + TRACE_DEFINE_ENUM(___GFP_THISNODE_BIT); \ + TRACE_DEFINE_ENUM(___GFP_ACCOUNT_BIT); \ + TRACE_DEFINE_ENUM(___GFP_ZEROTAGS_BIT); \ + TRACE_DEFINE_ENUM(___GFP_LAST_BIT); + +#ifdef CONFIG_KASAN_HW_TAGS +# define TRACE_DEFINE_GFP_FLAGS_KASAN \ + TRACE_DEFINE_ENUM(___GFP_SKIP_ZERO_BIT); \ + TRACE_DEFINE_ENUM(___GFP_SKIP_KASAN_BIT); +#else +# define TRACE_DEFINE_GFP_FLAGS_KASAN +#endif +#ifdef CONFIG_LOCKDEP +# define TRACE_DEFINE_GFP_FLAGS_LOCKDEP \ + TRACE_DEFINE_ENUM(___GFP_NOLOCKDEP_BIT); +#else +# define TRACE_DEFINE_GFP_FLAGS_LOCKDEP +#endif + +#define TRACE_DEFINE_GFP_FLAGS \ + TRACE_DEFINE_GFP_FLAGS_GENERAL \ + TRACE_DEFINE_GFP_FLAGS_KASAN \ + TRACE_DEFINE_GFP_FLAGS_LOCKDEP + /* * Physical address zone modifiers (see linux/mmzone.h - low four bits) * diff --git a/include/trace/events/kmem.h b/include/trace/events/kmem.h index b37eb0a7060f..e32098c0f187 100644 --- a/include/trace/events/kmem.h +++ b/include/trace/events/kmem.h @@ -9,6 +9,8 @@ #include #include +TRACE_DEFINE_GFP_FLAGS + TRACE_EVENT(kmem_cache_alloc, TP_PROTO(unsigned long call_site, diff --git a/include/trace/events/mmflags.h b/include/trace/events/mmflags.h index bb8a59c6caa2..522bbe3a5fe1 100644 --- a/include/trace/events/mmflags.h +++ b/include/trace/events/mmflags.h @@ -15,6 +15,8 @@ #define gfpflag_string(flag) {(__force unsigned long)flag, #flag} +TRACE_DEFINE_GFP_FLAGS + #define __def_gfpflag_names \ gfpflag_string(GFP_TRANSHUGE), \ gfpflag_string(GFP_TRANSHUGE_LIGHT), \