From patchwork Tue Oct 24 13:46:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13434606 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 C5292C07545 for ; Tue, 24 Oct 2023 13:48:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D90AA6B0296; Tue, 24 Oct 2023 09:48:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D199F6B0297; Tue, 24 Oct 2023 09:48:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B42CD6B0298; Tue, 24 Oct 2023 09:48:04 -0400 (EDT) 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 9AFEF6B0296 for ; Tue, 24 Oct 2023 09:48:04 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7B692160172 for ; Tue, 24 Oct 2023 13:48:04 +0000 (UTC) X-FDA: 81380483688.29.9CB6F19 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf21.hostedemail.com (Postfix) with ESMTP id B2F1E1C0018 for ; Tue, 24 Oct 2023 13:48:02 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=iJDQLbhz; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf21.hostedemail.com: domain of 3Ecs3ZQYKCLYoqnajXckkcha.Ykihejqt-iigrWYg.knc@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3Ecs3ZQYKCLYoqnajXckkcha.Ykihejqt-iigrWYg.knc@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698155282; 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=+3jXXsjNPLXrWv+rf69UQa/6uvXnoVOikFRei2b/KT8=; b=oE1LdW9Ol6kDCu1QgH/2+g80WTtmUuOTL6247xIyOKBCMWiTh8OLC4eOvAYbteq5Uhh2vk aTtbHAG5yeI39OOHh6GmJzRVCYAUYos5RnbduGYCKD0Bp4UJ0QpXewelxgOLzUf709aYD0 YxQwo+rcmoaTYRCyNv+4fEIYNkFX3Pk= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=iJDQLbhz; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf21.hostedemail.com: domain of 3Ecs3ZQYKCLYoqnajXckkcha.Ykihejqt-iigrWYg.knc@flex--surenb.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3Ecs3ZQYKCLYoqnajXckkcha.Ykihejqt-iigrWYg.knc@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698155282; a=rsa-sha256; cv=none; b=nHdh5gk0WeM3DfPev2Dna5zWPZl6bbgIeJTFhQKac7zXJ0HoR4LBxvW/Dt+CloZwSVJGRB ns2CdFa79MROFJGD2ZLRBJB4oUhq8ZqMkNwqDb2KdysgWgCuiXwcG1BBBkKT4YSnD5uYSj Y8p1TtT2fFZiBRdWTzmIvnCp/RcLjr0= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-d9a541b720aso5409628276.0 for ; Tue, 24 Oct 2023 06:48:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698155282; x=1698760082; 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=+3jXXsjNPLXrWv+rf69UQa/6uvXnoVOikFRei2b/KT8=; b=iJDQLbhz/W9d3D8wBDpO8wxSCvw23tusRpCmZ2yXAvvmyjoS0+LFMXibtuZNf/Uq+s v95I5qB9l66r8YhBN6zIgpH1+QFQ8Knk+9MJETtySq8cT3dvyPuinZ9i5ySquTycDX6E 4n8uhR1lwS4QT6a0zStU1NWLWUK5k4+naPcgSlOMtNL7a9tWXVs0sV9JxUxSObfJp/+Z laqjZvmTe6J5dy52JN65eLkbuPO28G5LWCIBIo2Wu/P8jUS6yhQfoxAlK8D6DAK4heEH U12ujNryAyXaKJ7WGknEh9vGjgofpzjL4UdAXPHJxofo1lrstgxbVOkwMSoGoUP0TD65 Es2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698155282; x=1698760082; 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=+3jXXsjNPLXrWv+rf69UQa/6uvXnoVOikFRei2b/KT8=; b=gcMiCBr3cmxSZbMklRMNA8pqFf65Our6b2lWf6/fNUykVVJ6ihGHID3bQyFnmoDHuk yOxJudP4V0MOic9zZGElXW+t+rkRtqRb/8QhCJYzz+/1w94y7Ujh6ce+LSb90ur4lbuU NjuDU2WDsJzZTy4hXtIChtKNUc1IBtesExinI6o4KuzSFjukhtyKEaFOZAFm3i5Dezkv ByCAAy5+NAZAtJZKazxS62IGvstdzNj5c8cLPe4pOk3v6b59m1YeqZFmsN9hR8LRuoXs 4XwuUH2v4LaHVNMewXPSyaoeEH3EZogofUvjuCjCQoa35GDkviSFFz0ZLK8moPlaGeWD 7GHw== X-Gm-Message-State: AOJu0YxmD9xD81h5d6NkCVW32VpGOjbmWtvAMrezX1bUf8NLIh5bAbMd Bb3X79DtY4Fjg+kzjERfzoLoIO+sFWE= X-Google-Smtp-Source: AGHT+IH8yezIA8jxKZavrTPxkBvsmi2Yxz7WtkoiuiQPT9VSDtMO7/bIUQjwMdJw5xsPHzLAEf+sR1TuKL8= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:45ba:3318:d7a5:336a]) (user=surenb job=sendgmr) by 2002:a25:d50c:0:b0:d9c:66d1:9597 with SMTP id r12-20020a25d50c000000b00d9c66d19597mr227720ybe.13.1698155281680; Tue, 24 Oct 2023 06:48:01 -0700 (PDT) Date: Tue, 24 Oct 2023 06:46:33 -0700 In-Reply-To: <20231024134637.3120277-1-surenb@google.com> Mime-Version: 1.0 References: <20231024134637.3120277-1-surenb@google.com> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog Message-ID: <20231024134637.3120277-37-surenb@google.com> Subject: [PATCH v2 36/39] 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, 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, 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: B2F1E1C0018 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: gbajfno3b8kwgsz4mundmm9gdbgitwtw X-HE-Tag: 1698155282-500195 X-HE-Meta: U2FsdGVkX19n+wXryDbtJi5WXOek24CYbVBiPz/cXyZjoYPuFisuiGhEPo+Cz7Ntgp+fx3GiNzPlviXFr44X4s9uriaidwERo2mBJu21j0liVrSBBW/FvaTViRpAXh4UPLSfWqljFqI/q+WlkDml5JAcS0Q2UAOVbC7dGdgtfrMjqgXIxXcwb+Ex+ykfE0b843ZQE6bYECiyhrq2elBfhwFh1fPAeSR41t5hay5iqBSO4qNm/rucboPtBjZRWZ/t547YUbLrp+bmlAWW5dHUoA//HlpSlTcj/xSI3s6ZVdnnZ+Ca/cvlLTziw9ZJE0rmPof9HPCzuFHTWxeBPmNIpkzUp+n9Op+ubPiSM2EvJsaQILu9RfPee3tG32VZUMSw1llHcd1fHHgKFhSZNhfjqm4ajhldBPg0BEAptykKHYXpjXG5pYfGxwaXf4L36wns8K8AZzeTst9jRdxPI4YDlhDkM3li85tu9QMabN1a/2ZY+iyldm1Oj+EcDtOLqYYtsI/YV0dX1P9JdANJt9KkpiizsmTSqDLYH1sw3f+fhItKE/y6RtkPqG5/BSQ7roGYsMHO4OdyyYbg6ElTCudNwKoazraIO11E20P699L/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ity=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/slab.h | 33 +++++++++++++++++++++++++++++++++ mm/slab_common.c | 1 + 3 files changed, 60 insertions(+) diff --git a/include/linux/alloc_tag.h b/include/linux/alloc_tag.h index 0a5973c4ad77..1f3207097b03 100644 --- a/include/linux/alloc_tag.h +++ b/include/linux/alloc_tag.h @@ -77,6 +77,27 @@ static inline struct alloc_tag_counters alloc_tag_read(struct alloc_tag *tag) return v; } +#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 */ + static inline void __alloc_tag_sub(union codetag_ref *ref, size_t bytes) { struct alloc_tag *tag; @@ -87,6 +108,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/slab.h b/mm/slab.h index 4859ce1f8808..45216bad34b8 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -455,6 +455,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 @@ -476,6 +501,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 8ef5e47ff6a7..db2cd7afc353 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -246,6 +246,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; }