From patchwork Mon May 1 16:54:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13227671 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 4E1B3C77B73 for ; Mon, 1 May 2023 16:56:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6DC1B900021; Mon, 1 May 2023 12:56:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 68D09900002; Mon, 1 May 2023 12:56:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 505AA900021; Mon, 1 May 2023 12:56:35 -0400 (EDT) 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 429C8900002 for ; Mon, 1 May 2023 12:56:35 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 27981407F2 for ; Mon, 1 May 2023 16:56:35 +0000 (UTC) X-FDA: 80742289950.18.C956837 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf03.hostedemail.com (Postfix) with ESMTP id 5E6CE2001A for ; Mon, 1 May 2023 16:56:33 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=lLa+vy9Y; spf=pass (imf03.hostedemail.com: domain of 3QO9PZAYKCIc352pymrzzrwp.nzxwty58-xxv6lnv.z2r@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3QO9PZAYKCIc352pymrzzrwp.nzxwty58-xxv6lnv.z2r@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=1682960193; 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=nH88FGoAACjgZmQtkl43JvHLPN3RafkQwEsrc5bfN4s=; b=t6LyTTlY0nAqA1yJUjVGtvgCaN9lI0NTAmz6nDvNoyjzOW75HqN+O6P4/K5SnyrciBIwhO /husoIAklj0Q+ZF3qwOxyfUaa6G2vLxwkCKPYWLxbZqZGbSyTmBh37D0zDA0Zy9DiSDqyo 6S8GmpAQUOccBAOgYTnOltbWitMBjKk= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=lLa+vy9Y; spf=pass (imf03.hostedemail.com: domain of 3QO9PZAYKCIc352pymrzzrwp.nzxwty58-xxv6lnv.z2r@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3QO9PZAYKCIc352pymrzzrwp.nzxwty58-xxv6lnv.z2r@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682960193; a=rsa-sha256; cv=none; b=BQSPqPy73ngHOVR9J672bsFhPaS8LaEcBiwAsGTSFGIbH4lI9iR6O3SimHNOLqsZ0FuQdQ +/jMJ3JTFdIIPR3KjmEAFXO7SGpWp5oFfvqHmKdhkS1ohBsOeqt2LF9utJKQwOMIxtyoYu MypxJPSD0YKwXGpRHjMsxUQdW0KUOrg= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-559f179cd38so41362047b3.0 for ; Mon, 01 May 2023 09:56:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682960192; x=1685552192; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=nH88FGoAACjgZmQtkl43JvHLPN3RafkQwEsrc5bfN4s=; b=lLa+vy9YS9JYxnsS/wzOxOEwwt8wSy5Uuy+3HdA356nRicp9ut8/ucfpMAH5tzjtpk TZcWKstbLNfc+ExqK3JufnNMMSOfGAmXHFXOkaH7uvY2JNRcUhOQ+mziqCIge56WJNZ/ gi3cQ2XcWFl2PGrQeodns68az+EoIqlViDNY/5PRPUy6or731mNfftlLkYP0wViktDEH g0WRqa3axpcg1emeJdFyEEwnjL1yqR7Zf3pRutm7Z9+tW9GBqkt749c0MDSZR/CpVzak uesUCRPASh4BPez2LMwWVpOzpXLQw5JYdzG+OUSaei3lVr1p9uTTjV6lehd+V/Xsz/IX /oSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682960192; x=1685552192; 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=nH88FGoAACjgZmQtkl43JvHLPN3RafkQwEsrc5bfN4s=; b=jZEpPeJtZMmAJ5aB1wcrW8k+/P/4B7UvgK6G43ubz9r0vtdlS5Bhg0w5JlqnGl7cgY 9T7jcDfZDrht/XXi6qhOjOFX/BXkR0Ev88WImv5KWonqIWcc5b7lzMg9nyqlTLrrcmB1 YvYLC9u+ACqBAi5lussn3nvFQdyWJ7+YcB/MOVKC0EkxQE/HRrK6LLrnpqp+0vwoZ+7r 9X30pIoiECF4wB7DakM82P0hsqxNL3CZR1DcNUrOE4KxUwNWTaB/HudsF60B0vmFDDQG ZaO6U7ogMFi6MUrMmVFNOYGPNQlQ7pfDijoLn7l1+TLGCDNjDq11TOXhShnpVUBnKXsJ mTSQ== X-Gm-Message-State: AC+VfDwEaXqzvKun1nVFzwSYoIysbEmia49U8LpY+ywKNU4cVP2ZKERJ dCt0ZPdC656XOnoArankU8ULNkuZnn0= X-Google-Smtp-Source: ACHHUZ5TmDDUIxEKAG9xtiDkwRqmJC5j3DPuQpKL1gsUmhKOzqQ3R0545H3ZiUaU/3KgnQbVgGPYgv/taTQ= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:6d24:3efd:facc:7ac4]) (user=surenb job=sendgmr) by 2002:a81:4011:0:b0:54f:9e1b:971c with SMTP id l17-20020a814011000000b0054f9e1b971cmr8801791ywn.1.1682960192486; Mon, 01 May 2023 09:56:32 -0700 (PDT) Date: Mon, 1 May 2023 09:54:47 -0700 In-Reply-To: <20230501165450.15352-1-surenb@google.com> Mime-Version: 1.0 References: <20230501165450.15352-1-surenb@google.com> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Message-ID: <20230501165450.15352-38-surenb@google.com> Subject: [PATCH 37/40] 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, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, ldufour@linux.ibm.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, 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, 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, shakeelb@google.com, songmuchun@bytedance.com, jbaron@akamai.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-Rspamd-Queue-Id: 5E6CE2001A X-Stat-Signature: 86dshca6hq5m33bgtdkfsqwmfmr1g3g7 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1682960193-864748 X-HE-Meta: U2FsdGVkX1/7Rq48tpHSCjrZnC4/k0oRe30/adYgc/RCeUGoo5CIWvehKatlcu6OCm7e1npZVctalmFaufGoNtcdOMJTmXIDfNZdoXAZqeJohPvqnjxkgpPpcuOC4ACzDvn/R7YLNp8J0ceKlV9qHb1e5f6NgP8lmTwwr+fQuB2BbsOpimt/Sw+4S2Vs8wwE+biBPkvS8def7P7ay8ES7jRI0iqgxXqhjEogdHwUVtZ1nGRPPb44GfjUAI0uewCk8Fky2fj/omAwpMtgVEvl8gYxYcXTO3p61mqOKuCF5lnZbTLQ5msCP3Vm26FSLTRQwLEc3Wkhcc704yMCqw4+M8OHIKdghrWtHTTU1IefyobNvfCH8+MvratqT/tKZoFURNfIBFFRqS336D9zmbEYKhceolD+jarhNaSn3TRSk2+Nyq5LuBquEoHEXWS3LG0vdPQCkIjlnNbDM4UY6pA5I80ceiCZWG8pAa14mVj0X6xcB9GWq9xIKRGudDPXCDyEw5/m0DodhJds/F8xy0XN3DeZTUEdD6/+dpm+X9KhaCxxiASQ6DiFhDqovAYzoWRWIQuIbBlSxvjPy1QK6UJfje+ujy8EjKgH/NN0HtluEx6FZj9cWq0GI3GdsdU+lvCu/vU+lWa6clT896PF6DnqXafApKofKGVy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.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 | 28 ++++++++++++++++++++++++++++ mm/slab.h | 33 +++++++++++++++++++++++++++++++++ mm/slab_common.c | 1 + 3 files changed, 62 insertions(+) diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h index 190ab793f7e5..2c3f4f3a8c93 100644 --- a/include/linux/alloc_tag.h +++ b/include/linux/alloc_tag.h @@ -51,6 +51,28 @@ static inline bool mem_alloc_profiling_enabled(void) return static_branch_likely(&mem_alloc_profiling_key); } +#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; } +static inline void set_codetag_empty(union codetag_ref *ref) {} + +#endif /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ + static inline void __alloc_tag_sub(union codetag_ref *ref, size_t bytes, bool may_allocate) { @@ -65,6 +87,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; + } + if (is_codetag_ctx_ref(ref)) alloc_tag_free_ctx(ref->ctx, &tag); else @@ -112,6 +139,7 @@ static inline void alloc_tag_add(union codetag_ref *ref, struct alloc_tag *tag, #else #define DEFINE_ALLOC_TAG(_alloc_tag, _old) +static inline void set_codetag_empty(union codetag_ref *ref) {} static inline void alloc_tag_sub(union codetag_ref *ref, size_t bytes) {} static inline void alloc_tag_sub_noalloc(union codetag_ref *ref, size_t bytes) {} static inline void alloc_tag_add(union codetag_ref *ref, struct alloc_tag *tag, diff --git a/mm/slab.h b/mm/slab.h index f9442d3a10b2..50d86008a86a 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -416,6 +416,31 @@ static inline struct slabobj_ext *slab_obj_exts(struct slab *slab) int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp_t gfp, bool new_slab); + +#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 */ + static inline bool need_slab_obj_ext(void) { #ifdef CONFIG_MEM_ALLOC_PROFILING @@ -437,6 +462,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; } diff --git a/mm/slab_common.c b/mm/slab_common.c index a05333bbb7f1..89265f825c43 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -244,6 +244,7 @@ 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; }