Received: by 2002:ab2:788f:0:b0:1ee:8f2e:70ae with SMTP id b15csp82152lqi; Wed, 6 Mar 2024 10:35:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWA+y68OFeSAN8G2mBBVpkryz2g2a2KKXMeGDJWV8avcd+Q86b5EemkdX/LmGpI40OafJJ4obFcR6Uubp+DKozToR0Ktk5df2B5SkCQjA== X-Google-Smtp-Source: AGHT+IH6KDGfKPjjaFjgTvEMar9eq32H3W3Mbkh0OgpNKLvNZWdb23ks5D2OYVrCDS8y+M9kJL9g X-Received: by 2002:a17:902:6544:b0:1dc:7890:72d6 with SMTP id d4-20020a170902654400b001dc789072d6mr5010426pln.22.1709750155196; Wed, 06 Mar 2024 10:35:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709750155; cv=pass; d=google.com; s=arc-20160816; b=wL3fl+w1d0nHXSniKCl9bhrCsEHvMrX6dfa+lXjHf2kKaQds/8fY3eHEDWgGLQmiKz 1fZMdHcBRrPPjq6zVLkQXFbjtgR+yhOqKO0A+uiTmjL9saPBhTSk0R7qd8nQnODkbfmq gKfx067hlYfF0fwql2uSZJwHYth5XSCTMAAa8Q8Frm0v3x5EyKxFbbC0fQOn6r/QJ4pJ qAv7Irbn5rM9Drj5rPnZsguhj+0BSL2bUWHMZU+sC/iC7nt33j0hU9vw3sxGfTSP70Dl +kDiF6PGxs4pLEPuHneZUqsbqyNUhHsDId8asTstHWG9fpx6TDxeVbLGNPrxmPbdvAMh 8irQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=O0frA1qINx6EEpp9W3MZZMQxDt0vbebTSbODwHd6D+c=; fh=sE60alBh1WzQGRvY46hV9SzO8cQ/ZViowOW2+BBxmMU=; b=bLpLr29xGQmfzyuzr6cZZ2HCRaY/J4RDcmmeJLLBExtrLObIHWJqYzrB/pfvwEZ3U4 81R0c6glhoXFGSSlgPalrAO5C6TScMR/LrTSqo/uC2/hjRtS44u/R2hFnJINpkOal3lD RlG+Gs3HUHindziRa8Di0sx9P0Mig0tRLmwDEFBVRotjvJvnZ4r1IMaBJ8dSPNfv28PH ki7P0WAIuIxO7HgaFGl/M4H/SXu1o2M+Xf/C0iYRf1Y9Nxt+CRzWA6XgUBqC+WSBmSTx 7blgpWD4sGWnj8WGwBGpSi7R8ZaYqiJX0vJT2NtBgvyy8eTqc4HpHbjrnc387sTVeimt oRBw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Hf5l5DH4; arc=pass (i=1 spf=pass spfdomain=flex--surenb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-94425-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94425-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id jk19-20020a170903331300b001db7c5ef0a6si12128422plb.136.2024.03.06.10.35.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 10:35:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-94425-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Hf5l5DH4; arc=pass (i=1 spf=pass spfdomain=flex--surenb.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-94425-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-94425-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D4BF5282F6A for ; Wed, 6 Mar 2024 18:35:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 86085151CF7; Wed, 6 Mar 2024 18:26:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Hf5l5DH4" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD6A41509B9 for ; Wed, 6 Mar 2024 18:25:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709749560; cv=none; b=PtDUMTGr93P4vfIRaUVa5lHZkQSnCHeXBbG5IUNE+NGGFzM31WTdEZbUc40VPxufn9vFjA2Frb8nEw7WGhdEHj43BF1jb1nHBq74BYLHM0G39Fmn007+yO+GI93PXtapRJkIKiK/6zqwCyPW9iYsE/mOi8Sx/yTjKZS6YQreQ2M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709749560; c=relaxed/simple; bh=L9xZd/8dD/B+wVgzLMXnQW4+21qHfcs5mXi5Enxm84s=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MuPwqbAeeswR5BRQ0ZcJNknlsQPQ4rdtfoTnJ/ikSTfm9GRY0tNxUyKUUzvT9mQyrR+Wggzigrwb0oVJuRVw/4Udue+HUq7YXed8isRWh1MGtgRs+bew0Zx/rM5KOOTvro8y7ylAOzFMKrPALhcwq4JIFbbfFRWnGC0u3ziq7nQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Hf5l5DH4; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dd0ae66422fso201037276.0 for ; Wed, 06 Mar 2024 10:25:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709749556; x=1710354356; darn=vger.kernel.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=O0frA1qINx6EEpp9W3MZZMQxDt0vbebTSbODwHd6D+c=; b=Hf5l5DH4K8vvxwlZhhFQaLpGI6DEffc+yMW2OccSJDwMlYlebQU6zm3xvVyhmpJJqO Hxqi5OxRPU0nVhxsGwzgVyp8rj9Q2QZ6WQm/mXS58H+1oyVsN+eP0Ozb+7xZ0CbWMnUK tbZNyiO6hzHT1bMk8U08nUDWAH5eBDexyNSTVHqvnwFirbWsuHnulVRbBxYwI+zT4Ep9 x/qEkSdUnqx9P6u4lo301zpqvMhosvGwv/EUTSbofBHYv1CfOXmNU7trJWC30Z12cBSL oZ2pGR6yWDt/arVgclHoXOfdvTShA78+jWNGS3bfdQmy/QvnJPP8XF2Npq6c2TSn+tTz eiog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709749556; x=1710354356; 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=O0frA1qINx6EEpp9W3MZZMQxDt0vbebTSbODwHd6D+c=; b=wU6UmLhi4zHq1jArq6jVynXUm1tfbU0LXpNdTRh4O2tEdujYPAKvxtyrWlh4pVSiyn wtjt10EQ2rGUeCa56r0saAPfDX3stMt+jLb0xT2dP9UCgZ6yZ0NeB5Y/jao8ID7/agM8 BMCulkmXna/xFTE/yS65a5sgI1SRwu/MNnk06dGHvuJ5jxJNkmMnVIYcsp3km4eFR2fJ C6q+z8MegXQrmjEdTTSGBLqHV3WZ0IdFn+ltX6JElKTtzZZt53gXBcLfwshIRBW44Fv1 kw499rdXXBdQ+9Y0rtdH/ugX0fFuwXSW6hzvoWQiJB6AoLit4G9zwKggUwp5wjuO7KTC HKUA== X-Forwarded-Encrypted: i=1; AJvYcCVLxXmZ39A3Fv9kylSzZZ12ZLkXQALp9mKAPXHhcEiaFoNTYYwTxNh/MHT2xaIS52nB1ij1tHnpLo7jiw4hcOw7ciboWJdwuCjs+kGl X-Gm-Message-State: AOJu0YyjOK/jKwPZqcKpmvMh5kpE4/esSBygMMvZuKfThrenKZepQkzz N24iDXZQIYzjKFRnYRIPkwNyRXnfxyTNMQaRsn0K+vaN6ryy+kFoHr78I2MAONIiLo9vnX5lb3L rxA== X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:85f0:e3db:db05:85e2]) (user=surenb job=sendgmr) by 2002:a05:6902:705:b0:dbe:d0a9:2be3 with SMTP id k5-20020a056902070500b00dbed0a92be3mr1901493ybt.3.1709749555637; Wed, 06 Mar 2024 10:25:55 -0800 (PST) Date: Wed, 6 Mar 2024 10:24:31 -0800 In-Reply-To: <20240306182440.2003814-1-surenb@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240306182440.2003814-1-surenb@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240306182440.2003814-34-surenb@google.com> Subject: [PATCH v5 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, shakeelb@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 Content-Type: text/plain; charset="UTF-8" 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 5e6d68d05740..4a396e1315ae 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1883,6 +1883,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 @@ -1923,6 +1947,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; } @@ -1939,6 +1964,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; } -- 2.44.0.278.ge034bb2e1d-goog