From patchwork Thu Jan 16 21:41:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13942347 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 21760C02187 for ; Thu, 16 Jan 2025 21:44:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 844B76B0088; Thu, 16 Jan 2025 16:44:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 78F6A6B0093; Thu, 16 Jan 2025 16:44:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 520B16B0088; Thu, 16 Jan 2025 16:44:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2BAD96B008A for ; Thu, 16 Jan 2025 16:44:35 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D06981A13D6 for ; Thu, 16 Jan 2025 21:44:34 +0000 (UTC) X-FDA: 83014644468.26.4323A71 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf14.hostedemail.com (Postfix) with ESMTP id 3DBBB10000C for ; Thu, 16 Jan 2025 21:44:33 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of "SRS0=fJp8=UI=goodmis.org=rostedt@kernel.org" designates 139.178.84.217 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=1737063873; 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:in-reply-to: references:references; bh=QVaWJEtyKyX3Toa9TMQ9NvTW0PZ48T3utLLllXOVFN8=; b=UVzhavr2TmOfIqRSLSlnScDGppi74xAhdcsvIfp3K3AIQQ6uZwDvAJbX38Vr2TjPDl7yiT ddw8altzPZs10G8QEa4y1UwjwfBoLYrX6FKnOAXYiWQL9H9I0rAO0ZlR9ntTmemSJ+vyPF d/A5IBC3kF1MukD5SneBwHBJ8XQsczw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1737063873; a=rsa-sha256; cv=none; b=XyMkJq2lbWmhLKtfNVWWTXkCrfe1K7hwnwA6nVtaMlPmQfaem7XHF3LG1JRwJbOuCL8CRb uC5cEzCu6QtU6ZAYG4bjHvnXJPh7VWqsVBxwuHHaZedcP3lY7Ef2KHOhZhGe7Uir+5LVbr PqeAzLx9Jq2U9yNAU16y9158fkPApxU= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of "SRS0=fJp8=UI=goodmis.org=rostedt@kernel.org" designates 139.178.84.217 as permitted sender) smtp.mailfrom="SRS0=fJp8=UI=goodmis.org=rostedt@kernel.org"; dmarc=none Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id A7EB05C063B; Thu, 16 Jan 2025 21:43:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CA3EC4CEDF; Thu, 16 Jan 2025 21:44:32 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1tYXfK-00000000yyC-46fX; Thu, 16 Jan 2025 16:44:38 -0500 Message-ID: <20250116214438.749504792@goodmis.org> User-Agent: quilt/0.68 Date: Thu, 16 Jan 2025 16:41:24 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-mm@kvack.org, linux-perf-users@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Michael Petlan , Veronika Molnarova , Suren Baghdasaryan , Linus Torvalds , stable@vger.kernel.org Subject: [PATCH v2 1/2] tracing: gfp: Fix the GFP enum values shown for user space tracing tools References: <20250116214123.917928229@goodmis.org> MIME-Version: 1.0 X-Stat-Signature: tnqejsbfkm36r3gw4ffcatsjr133qhmk X-Rspamd-Queue-Id: 3DBBB10000C X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1737063873-396273 X-HE-Meta: U2FsdGVkX1/sQ2xVFMvmROPfjUcYX1acHhORIrFhyRD3cEKE+8HzVtvly2qdVkSXT5Qh/N76JvFrlD/mHtf8eJGe6TiUeHPmjNFeKfzuRDqzFXw3viWua8mcSYnZW5qU8OtJ3OpugtcV5QLtG/OLMyYn2B9w92JIkopH8YAVy8/AqTnXbh6vVdv2QTdEsLiUziSf9myztfre42wuuffWI2IvzoTXFzpEutTQjuPA6dtcGjeSMBCci4S9YdfXyIdG1+twmrhX0o3o+psGajRyM8bVqd7ev1Jhfb73cQkbo+D16aVxmMbKQ/wPLVriwGhkc7B7xKzyvvRtMaNQbKNs3XZAdPRsU2rriiJ74HoCEbF1Sx2zd7dhTGEX/xWhlqPQt67jly58wjIkL50g8Ls6W9c0DCdI+IV8dFV4+Bvlf2YZN+pDiuFnhWnfPdqAK/r0dbNoAHbYU5tvy70F/iHFop1MEYc5VvNUhwM2o+z1RsqzO2JqipEIyE97p6DEbb02l9f1RU2wu+bPHBsn4ClpaKK2nee27TkR7EJk8q31/qwI//sgy+Q83t97fXQ59lM0eOGUyl3TT/Sz4v60mYRXSeXM3d7Gbm0MDCjPIIJ9JSoNI4TSgKUiS+61XOvQKM0oA5AQoBx9u2d85R7s/xPejz8NsmNfxHDOjZkfw7yNK4CUNdz7I5Q8xBAL336s1AD84yf7dKpZ+kRlO3MqRwHcnMmY5Qyk+7JPBHhV1tke+WiSPQsBmIpMhxXy6CTuxaq5AngM4Soc5UISMHYmYA1GZw1SBG1nuT7a63LnXxqcWCGZFcB1b6EnHrGTkvoheEJP2xGR0uZbzlLbfsBx16KuqxoJ0XHKIF7men56VNFp6ZmJ8EW8UHVeTXuDPSJEgdUqKbedg8ErWM9JjGMGiDWOBhZRlaoMzGBodKpcdRh++ZHmrEcWKeZbgrmShKtuAi7wPmqKjZz8LFw204UhCOo JK+8Ild9 w/sUApyCREnEdMc29KVbAkUILyRVeCvkSo9uMpZaHqfgCA23KuE6J0l+GPRf2ltWkocqaSaQet5inw/Oh5/ApWCyxNqVxkPZEoJNvkjBrmzm/ssAnmevt8r3vWRrYMyn7bRw+HdNws72F7INty2NWwQUZmgaBFdPYPM+J7Q+hj1hlCiNuKi2zC5kjaQ8w1CNV7n2YzTDTeO6/D9DAk8JHLaN8iqlT/NMItZOwdhhtH8v3TaZqKFmu/LgBmaOBQ3DNjf3ni3HSwtex8c/Ms1UnFPR4D/SHFChwXhvxcbvafBJ9cf32MuXAKWx9yB6sfLmQUCV3L0WrOD3w1NUZPhYyHX2Oq8aMqAfQSqDxm82HDF1SlMjvk+iL6HU1nAWzGMYnpbszR6028frCqXJdLcqDUx4igQ== 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) --- Changes since v1: https://lore.kernel.org/20250116132359.1f20cdec@gandalf.local.home - Moved the updates to only include/trace/events/mmflags.h - Removed the macro call in include/trace/events/kmem.h - Use an internal TRACE_GFP_EM() macro in TRACE_GFP_FLAGS to allow it to be expanded later for use with the __def_gfpflags_names() macro include/trace/events/mmflags.h | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/include/trace/events/mmflags.h b/include/trace/events/mmflags.h index bb8a59c6caa2..d36c857dd249 100644 --- a/include/trace/events/mmflags.h +++ b/include/trace/events/mmflags.h @@ -13,6 +13,69 @@ * Thus most bits set go first. */ +/* These define the values that are enums (the bits) */ +#define TRACE_GFP_FLAGS_GENERAL \ + TRACE_GFP_EM(DMA) \ + TRACE_GFP_EM(HIGHMEM) \ + TRACE_GFP_EM(DMA32) \ + TRACE_GFP_EM(MOVABLE) \ + TRACE_GFP_EM(RECLAIMABLE) \ + TRACE_GFP_EM(HIGH) \ + TRACE_GFP_EM(IO) \ + TRACE_GFP_EM(FS) \ + TRACE_GFP_EM(ZERO) \ + TRACE_GFP_EM(DIRECT_RECLAIM) \ + TRACE_GFP_EM(KSWAPD_RECLAIM) \ + TRACE_GFP_EM(WRITE) \ + TRACE_GFP_EM(NOWARN) \ + TRACE_GFP_EM(RETRY_MAYFAIL) \ + TRACE_GFP_EM(NOFAIL) \ + TRACE_GFP_EM(NORETRY) \ + TRACE_GFP_EM(MEMALLOC) \ + TRACE_GFP_EM(COMP) \ + TRACE_GFP_EM(NOMEMALLOC) \ + TRACE_GFP_EM(HARDWALL) \ + TRACE_GFP_EM(THISNODE) \ + TRACE_GFP_EM(ACCOUNT) \ + TRACE_GFP_EM(ZEROTAGS) + +#ifdef CONFIG_KASAN_HW_TAGS +# define TRACE_GFP_FLAGS_KASAN \ + TRACE_GFP_EM(SKIP_ZERO) \ + TRACE_GFP_EM(SKIP_KASAN) +#else +# define TRACE_GFP_FLAGS_KASAN +#endif + +#ifdef CONFIG_LOCKDEP +# define TRACE_GFP_FLAGS_LOCKDEP \ + TRACE_GFP_EM(NOLOCKDEP) +#else +# define TRACE_GFP_FLAGS_LOCKDEP +#endif + +#ifdef CONFIG_SLAB_OBJ_EXT +# define TRACE_GFP_FLAGS_SLAB \ + TRACE_GFP_EM(NO_OBJ_EXT) +#else +# define TRACE_GFP_FLAGS_SLAB +#endif + +#define TRACE_GFP_FLAGS \ + TRACE_GFP_FLAGS_GENERAL \ + TRACE_GFP_FLAGS_KASAN \ + TRACE_GFP_FLAGS_LOCKDEP \ + TRACE_GFP_FLAGS_SLAB + +#undef TRACE_GFP_EM +#define TRACE_GFP_EM(a) TRACE_DEFINE_ENUM(___GFP_##a##_BIT); + +TRACE_GFP_FLAGS + +/* Just in case these are ever used */ +TRACE_DEFINE_ENUM(___GFP_UNUSED_BIT); +TRACE_DEFINE_ENUM(___GFP_LAST_BIT); + #define gfpflag_string(flag) {(__force unsigned long)flag, #flag} #define __def_gfpflag_names \