From patchwork Thu Mar 21 16:36:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13599190 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 769E0C54E58 for ; Thu, 21 Mar 2024 16:38:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE9D26B00C2; Thu, 21 Mar 2024 12:38:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E70866B00C4; Thu, 21 Mar 2024 12:38:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C00736B00C5; Thu, 21 Mar 2024 12:38:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A871A6B00C2 for ; Thu, 21 Mar 2024 12:38:24 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 84E391608D7 for ; Thu, 21 Mar 2024 16:38:24 +0000 (UTC) X-FDA: 81921604128.28.4B19FC1 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf25.hostedemail.com (Postfix) with ESMTP id AB946A002A for ; Thu, 21 Mar 2024 16:38:22 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="vY6Wen6/"; spf=pass (imf25.hostedemail.com: domain of 3fWL8ZQYKCGoacZMVJOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3fWL8ZQYKCGoacZMVJOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711039102; 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:in-reply-to:references:references:dkim-signature; bh=WqtLQxxTOcT4NwKA/wnlkHzJUMqCp8K/X9+cNXxjvBQ=; b=LWf0O+G4buT6q0Hgfh/cVqhYzwUgU7yoCymu5Bjb2GFcCnxpg7nkTHZn4+UrxL24kmc1WN CJ32/SSA6qc7L+WwSFpcnGMAmpZJpyUY7Mu3ky5ShAlTTZDnmaOHr1OB6WUdBPbBK+pkW+ vbCNaQ1YEWQxNgOpXE9ChiYowv0IdZA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711039102; a=rsa-sha256; cv=none; b=sCgkdCs4dIXFiYLBHmm5hZ+djVMC4AnH+13TNZlYGX9FTsH47CN971/XiVme0sIGhbuS3C Q8dQlGdMhziiNGXvePanHO+jMOvtHO1SE88zdtOFu1KFtvFHRQ2bN0USeAKOuKNhPtNJYI BEJo9xyRTkb6QrxjgK+jcJ47R7VBm1Q= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="vY6Wen6/"; spf=pass (imf25.hostedemail.com: domain of 3fWL8ZQYKCGoacZMVJOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3fWL8ZQYKCGoacZMVJOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dbf216080f5so1809351276.1 for ; Thu, 21 Mar 2024 09:38:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711039102; x=1711643902; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=WqtLQxxTOcT4NwKA/wnlkHzJUMqCp8K/X9+cNXxjvBQ=; b=vY6Wen6/0T2AQDa2tZ5rIPAgcBDQAOofGHIJDYJq/x/R3RSH1JcZCtmwOGqTgDfgQC HjyrPdCr9nB5DoUDHdKrz4IM//Cq5I32MY3dch1EGn4hEod7ahzeEPy/uXnuFeanx5dV HikF0RnIT9v459wbUQFfAerah7tbULzV4nq1HCysMFPz7n9lc+YKgojb0yaLqooBzUgG Gs8x6NW4mIuHlkHVFNGDO+1W7LRzO8UogFbdq46qvxve6U7DyytrF1XuE8/b3u6UbGz2 j7GK7rjWSerkVSsReO9Eo8BFgj+xjtuhWv5UIcW7yXUZcKSKW6WXlDsfElAmtuFR0lH5 a9GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711039102; x=1711643902; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WqtLQxxTOcT4NwKA/wnlkHzJUMqCp8K/X9+cNXxjvBQ=; b=MekXAyxlxNs7qJD8jW10LQoBeVyJLBRoZieMDDOci8DN+Y+rXfC+miDc4MJw5E8I63 rLmB1l2KQTusN1GErKDvEfLxRQSyYyJaQw/eIAoblRTtrdQ6q2HuGi/o9YwQ1WgFHPWv mXbmVrV5Qljv3loOElCLeKjCxY3BY7p2Cl7j/eHu4x+XE69irjrWG11P5Vu+s5jxr24D 8mKvQGP4qrazU9inEOba4uuhEWoLtnKH+fnZkMRZEtV6xQ+nXTRdIJIR1PT+Zglsom3A eDEK1fOg4HrQ40oC+2vOAATj3/Njm3bNOlTxK3nlKpFW/n1bHTRZ0n6XBdYz3zPWppc+ QQZg== X-Forwarded-Encrypted: i=1; AJvYcCVAHbxbqqV8IRrzBpqLSm9WTOS8rXr8eUJSSX4RsTZOTQFC1ZMU0SMYJ/TVGfApNGQtnsLRrc8GbGDj2ly1l13UE5o= X-Gm-Message-State: AOJu0YyM4q6TlRLaXtsSdHUGZPw7GkPvfr8ZM/YSQIvAOTBL02zMnkiU YxuflgA2j+47F7mv+89EBUsm6cJ/jDCpSbubesgZ/Y/KyjwVNhmCz5hYEV6YqVk34Ppk/JCeJ94 e5g== X-Google-Smtp-Source: AGHT+IGROXQhVTEL+/Ecek6yIPftetu6NwNXc2sw4rx8G7tLlUrCGcwRYmXksEw30SynbjVDOeX+ECRwtfM= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:a489:6433:be5d:e639]) (user=surenb job=sendgmr) by 2002:a05:6902:2408:b0:dc2:1f34:fac4 with SMTP id dr8-20020a056902240800b00dc21f34fac4mr5790745ybb.2.1711039101565; Thu, 21 Mar 2024 09:38:21 -0700 (PDT) Date: Thu, 21 Mar 2024 09:36:55 -0700 In-Reply-To: <20240321163705.3067592-1-surenb@google.com> Mime-Version: 1.0 References: <20240321163705.3067592-1-surenb@google.com> X-Mailer: git-send-email 2.44.0.291.gc1ea87d7ee-goog Message-ID: <20240321163705.3067592-34-surenb@google.com> Subject: [PATCH v6 33/37] codetag: debug: skip objext checking when it's for objext itself From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: kent.overstreet@linux.dev, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, penguin-kernel@i-love.sakura.ne.jp, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, dennis@kernel.org, jhubbard@nvidia.com, tj@kernel.org, muchun.song@linux.dev, rppt@kernel.org, paulmck@kernel.org, pasha.tatashin@soleen.com, yosryahmed@google.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, andreyknvl@gmail.com, keescook@chromium.org, ndesaulniers@google.com, vvvvvv@google.com, gregkh@linuxfoundation.org, ebiggers@google.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, songmuchun@bytedance.com, jbaron@akamai.com, aliceryhl@google.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, surenb@google.com, kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org X-Stat-Signature: ju8nobm47tgermxzftn9cb67fccbihcx X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: AB946A002A X-Rspam-User: X-HE-Tag: 1711039102-677149 X-HE-Meta: U2FsdGVkX1/LadF5rQ+Qb8CLppSekpt2CVgllazjsr5u4unp+k0OozgmSXL/S8Bv+U4znFIUO+AQmToCxr7tZVJLdfYNGQTZYwfHViSnVGMIsexdXnR3sQHeNLJiVIqxmWQFdcAlfq7YYzh1jn59je0AHaQ9hefFcMadscBVdDiiub5N2CKDxhe2t8gAJ5JKU9G8F2+ESj1vlvc8U/By/tPwdVjsCJFdQSqOR+NhjifEsixWu2hjzBTb3nycg0hVaKeid9OWipOaAKuwIxHGHPR+yp08QZsjHm/1pHzLwlTyZUrLnrJQCn1NTGFUuuqWtkBSHqVJSo9vMg61lSOs2lhYVKZxBeQQsEfGHnZbAFs/10FqVncKel8gDYrn2U9bIt+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EvlYsW4FwqncDKN5rMBheaxGIXQ5My93Csi5FLdnCUkgnw+t6LMBQl7n8OizIgKs/Qu03Vl2/fou41E5sb8jft/KyrO0mfIOfO/RCQvAT8MnvnOCRM+TOlXZ1a4Vawk0jexr4AGfGhh3l0uEL/Ek1949DUosi080izLb/eIcJwRKPhIMppLDhRhoeNvL7c9FxRevBP+e41wA= 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: objext objects are created with __GFP_NO_OBJ_EXT flag and therefore have no corresponding objext themselves (otherwise we would get an infinite recursion). When freeing these objects their codetag will be empty and when CONFIG_MEM_ALLOC_PROFILING_DEBUG is enabled this will lead to false warnings. Introduce CODETAG_EMPTY special codetag value to mark allocations which intentionally lack codetag to avoid these warnings. Set objext codetags to CODETAG_EMPTY before freeing to indicate that the codetag is expected to be empty. Signed-off-by: Suren Baghdasaryan --- include/linux/alloc_tag.h | 26 ++++++++++++++++++++++++++ mm/slub.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h index aefe3c81a1e3..c30e6c944353 100644 --- a/include/linux/alloc_tag.h +++ b/include/linux/alloc_tag.h @@ -28,6 +28,27 @@ struct alloc_tag { struct alloc_tag_counters __percpu *counters; } __aligned(8); +#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG + +#define CODETAG_EMPTY ((void *)1) + +static inline bool is_codetag_empty(union codetag_ref *ref) +{ + return ref->ct == CODETAG_EMPTY; +} + +static inline void set_codetag_empty(union codetag_ref *ref) +{ + if (ref) + ref->ct = CODETAG_EMPTY; +} + +#else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ + +static inline bool is_codetag_empty(union codetag_ref *ref) { return false; } + +#endif /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ + #ifdef CONFIG_MEM_ALLOC_PROFILING struct codetag_bytes { @@ -140,6 +161,11 @@ static inline void alloc_tag_sub(union codetag_ref *ref, size_t bytes) if (!ref || !ref->ct) return; + if (is_codetag_empty(ref)) { + ref->ct = NULL; + return; + } + tag = ct_to_alloc_tag(ref->ct); this_cpu_sub(tag->counters->bytes, bytes); diff --git a/mm/slub.c b/mm/slub.c index a05d4daf1efd..de8171603269 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1873,6 +1873,30 @@ static inline enum node_stat_item cache_vmstat_idx(struct kmem_cache *s) #ifdef CONFIG_SLAB_OBJ_EXT +#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG + +static inline void mark_objexts_empty(struct slabobj_ext *obj_exts) +{ + struct slabobj_ext *slab_exts; + struct slab *obj_exts_slab; + + obj_exts_slab = virt_to_slab(obj_exts); + slab_exts = slab_obj_exts(obj_exts_slab); + if (slab_exts) { + unsigned int offs = obj_to_index(obj_exts_slab->slab_cache, + obj_exts_slab, obj_exts); + /* codetag should be NULL */ + WARN_ON(slab_exts[offs].ref.ct); + set_codetag_empty(&slab_exts[offs].ref); + } +} + +#else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ + +static inline void mark_objexts_empty(struct slabobj_ext *obj_exts) {} + +#endif /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ + /* * The allocated objcg pointers array is not accounted directly. * Moreover, it should not come from DMA buffer and is not readily @@ -1913,6 +1937,7 @@ static int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, * assign slabobj_exts in parallel. In this case the existing * objcg vector should be reused. */ + mark_objexts_empty(vec); kfree(vec); return 0; } @@ -1929,6 +1954,14 @@ static inline void free_slab_obj_exts(struct slab *slab) if (!obj_exts) return; + /* + * obj_exts was created with __GFP_NO_OBJ_EXT flag, therefore its + * corresponding extension will be NULL. alloc_tag_sub() will throw a + * warning if slab has extensions but the extension of an object is + * NULL, therefore replace NULL with CODETAG_EMPTY to indicate that + * the extension for obj_exts is expected to be NULL. + */ + mark_objexts_empty(obj_exts); kfree(obj_exts); slab->obj_exts = 0; }