From patchwork Thu Mar 21 16:36:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13599192 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 199F2C54E58 for ; Thu, 21 Mar 2024 16:39:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A1A56B00CA; Thu, 21 Mar 2024 12:38:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 151826B00CB; Thu, 21 Mar 2024 12:38:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC0696B00CC; Thu, 21 Mar 2024 12:38:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D090C6B00CA for ; Thu, 21 Mar 2024 12:38:28 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 87EF7A02E6 for ; Thu, 21 Mar 2024 16:38:28 +0000 (UTC) X-FDA: 81921604296.16.44D330F Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf16.hostedemail.com (Postfix) with ESMTP id BAB8E180010 for ; Thu, 21 Mar 2024 16:38:26 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=04alsgHu; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf16.hostedemail.com: domain of 3gWL8ZQYKCG4egdQZNSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3gWL8ZQYKCG4egdQZNSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711039106; 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=f5LdsTMnIqabj8ROFrnDTgTazgUa7GmHleuFcbzHgo8=; b=dIfvJJ0bdu4/xqn0qv3N8cFBJCI59nRo0cBphSd+RossL3Gx45M2SKnLhjqRTOLwxeMUar O1Miann05cnym+1GReE3lo0iAGggHwXoJYUqIx5voY7MmIbaaQbfCoNl644Up46uvwA11o xKCK1acfVVnH00PmcDXw0S+NQOFFOsU= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=04alsgHu; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf16.hostedemail.com: domain of 3gWL8ZQYKCG4egdQZNSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3gWL8ZQYKCG4egdQZNSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711039106; a=rsa-sha256; cv=none; b=3NqrOujoT82igKou8krX9sJpMr+Of0/a8Em2+Ts190p9i4K1kLVRtt9vwP6MJA3l4O2Ymp YAOweYP7ifcqP4aREn6tMDWoD+BoItaBpdtFDIgCD2/WEr1rKlRYopMJ4v7RQv9wqKgusO TSwCbNPzWmP8pNzSb2zo9oz8JNZvjdw= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60ab69a9e6fso28869637b3.0 for ; Thu, 21 Mar 2024 09:38:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711039106; x=1711643906; 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=f5LdsTMnIqabj8ROFrnDTgTazgUa7GmHleuFcbzHgo8=; b=04alsgHus8OMwoo9TYwCUt1YdVfV3QMZmGhym5SPRPfX8AZJ0xVQ3pOaO9LCzj/uY+ wREMrjqT7V4B4VsO4hPzMNV1Y+ljCia4w/VJzfKGWBOsNzThsUuffR0YRIUO5y1WRkq8 jsCUL1WCk1Fae3YTD68PKgsdjHeBE49rNcvC6W4/o9HgbetVgrrtMWFZRZd2m28ubZYX /fs/PvnYM6paOU5g6e2b2hyjArRI8rLLfSSEq6c2Xm2CUjwdS7OA6XZaY7+iMfnYSeAq FvlEbCk9JxI2lILhU77GMHLib4tuz5eCoHOrPl7vvMPKhaFLsPyWUNOG1EqoGRIzZJua AW/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711039106; x=1711643906; 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=f5LdsTMnIqabj8ROFrnDTgTazgUa7GmHleuFcbzHgo8=; b=QTMhtSMBXIseZnYq99Rj84kU72vjXVvE/aWsPzAQyMcq6hjFDx6X92f+3utwYz9nCt g13k8xsKUIIruuzALPwWStV3qZ9kVK75nKXk7ib1luUAMNs174pTWcZGKWZkRKvqjE5N 68wnmrSDKzTRMn931SLh83f6KI+9SMg/9JmDbQbUxi8zZMa2+DXNHo9B4HRp8h1PuaFb JqzYT5yzwBc+oya+9DuXAmcAgDJxvRKA78hyFIMjg0E4n6GyAXn3MN0k5OzTC/ffScBj 9TjKe39AWHrZ+CnaaAWSYvQeGnryJgucLTW4A3dwVvFCUTh/MyUswh3eosDbF5gjTWK8 7mBw== X-Forwarded-Encrypted: i=1; AJvYcCW36/vCKrpRVjELA07IboT0VWBOPbvJELxnRgThCuSDcO0JQ8qN6i8u5r0uZ86cVEstRYAQuXPN/yZO8lY+lOTA2E0= X-Gm-Message-State: AOJu0Yy2K7vntUSf7x1+cPRNCMYa6xAKVFEfzbyU5YoqM6DRBix+DYJn zkn4fXs97dy1gfnPxAHJMBINaKCCryDEPbF3tJDdkCcset1RuuQBg4gxK+B7sO+5TLBk5bxWSU3 qoA== X-Google-Smtp-Source: AGHT+IHcdcDq5+VHUFf2WWlMxzMO+//nklguhi2MOjraFbT9V29sxxC0Or3cfCWp5X/LcbCc/1WTryTy5Uo= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:a489:6433:be5d:e639]) (user=surenb job=sendgmr) by 2002:a0d:cc41:0:b0:610:dc1b:8e57 with SMTP id o62-20020a0dcc41000000b00610dc1b8e57mr863711ywd.3.1711039105858; Thu, 21 Mar 2024 09:38:25 -0700 (PDT) Date: Thu, 21 Mar 2024 09:36:57 -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-36-surenb@google.com> Subject: [PATCH v6 35/37] codetag: debug: introduce OBJEXTS_ALLOC_FAIL to mark failed slab_ext allocations 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-Rspam-User: X-Stat-Signature: 5zzkdf4zkdowc36d9ski57sx9eyeq6yk X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: BAB8E180010 X-HE-Tag: 1711039106-573316 X-HE-Meta: U2FsdGVkX1+ThYT44ScrEYG5H2x6O7MMOspegY/sJh7A++w6fGZaZBHrI9MetYYgdCz2/qc4//sc3juMAEKOQynfL0JMzEYsw1nDlQpST8eblsIxdRs968at8tOUdRNnJNVpw+5wTAMLDjy+62fgQh1d+ON9OR/ISbplk1Q9rdUJ2UmOJ4cyuci34kJ37NaQOBXer9f8FfIqsfkSwvV4MRLqGatWgadU/oB3fqp9g4vWL/2rFP7tkNq0PRf8V5Wz9ydN/UAF2ZDROqoMhXRFfaRcgxHsxtuq+siJHstGzLgS3BF4J5vIjipkmNDpAXrWDRAU5Ujn08pepomkgQa+1uRFZLN9dp+KifGoViSBDjNWefqrBszgNTiyDjOHQgGA7nebtvQhGof36+HvsUoHbgHiRsyrubT6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hWjYSUJKVtcXWONRxoxPSjUI9RnLVoSdcZyGwlZGO7TTb6F11LFiEUMKpItroX9Q87Or72X9vZVTDBNE95GWnc0uJRupqrC4yAonpTAsf+ctS08lkgr/pdJ1sf7X4V9EJQ5oWj8uqkbL7CdlLYrv9z2ewOykIU88ZSXMqQs9xxl4HZxPxCffqo6rooq6PHAlVo/fAIWrjN7wd8mTIARBHUZI11ui3HLaJ2ugFUFmr+rNTIjNJ 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: If slabobj_ext vector allocation for a slab object fails and later on it succeeds for another object in the same slab, the slabobj_ext for the original object will be NULL and will be flagged in case when CONFIG_MEM_ALLOC_PROFILING_DEBUG is enabled. Mark failed slabobj_ext vector allocations using a new objext_flags flag stored in the lower bits of slab->obj_exts. When new allocation succeeds it marks all tag references in the same slabobj_ext vector as empty to avoid warnings implemented by CONFIG_MEM_ALLOC_PROFILING_DEBUG checks. Signed-off-by: Suren Baghdasaryan --- include/linux/memcontrol.h | 4 +++- mm/slub.c | 46 ++++++++++++++++++++++++++++++++------ 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 24a6df30be49..8f332b4ae84c 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -366,8 +366,10 @@ enum page_memcg_data_flags { #endif /* CONFIG_MEMCG */ enum objext_flags { + /* slabobj_ext vector failed to allocate */ + OBJEXTS_ALLOC_FAIL = __FIRST_OBJEXT_FLAG, /* the next bit after the last actual flag */ - __NR_OBJEXTS_FLAGS = __FIRST_OBJEXT_FLAG, + __NR_OBJEXTS_FLAGS = (__FIRST_OBJEXT_FLAG << 1), }; #define OBJEXTS_FLAGS_MASK (__NR_OBJEXTS_FLAGS - 1) diff --git a/mm/slub.c b/mm/slub.c index de8171603269..7b68a3451eb9 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1891,9 +1891,33 @@ static inline void mark_objexts_empty(struct slabobj_ext *obj_exts) } } +static inline void mark_failed_objexts_alloc(struct slab *slab) +{ + slab->obj_exts = OBJEXTS_ALLOC_FAIL; +} + +static inline void handle_failed_objexts_alloc(unsigned long obj_exts, + struct slabobj_ext *vec, unsigned int objects) +{ + /* + * If vector previously failed to allocate then we have live + * objects with no tag reference. Mark all references in this + * vector as empty to avoid warnings later on. + */ + if (obj_exts & OBJEXTS_ALLOC_FAIL) { + unsigned int i; + + for (i = 0; i < objects; i++) + set_codetag_empty(&vec[i].ref); + } +} + #else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ static inline void mark_objexts_empty(struct slabobj_ext *obj_exts) {} +static inline void mark_failed_objexts_alloc(struct slab *slab) {} +static inline void handle_failed_objexts_alloc(unsigned long obj_exts, + struct slabobj_ext *vec, unsigned int objects) {} #endif /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ @@ -1909,29 +1933,37 @@ static int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s, gfp_t gfp, bool new_slab) { unsigned int objects = objs_per_slab(s, slab); - unsigned long obj_exts; - void *vec; + unsigned long new_exts; + unsigned long old_exts; + struct slabobj_ext *vec; gfp &= ~OBJCGS_CLEAR_MASK; /* Prevent recursive extension vector allocation */ gfp |= __GFP_NO_OBJ_EXT; vec = kcalloc_node(objects, sizeof(struct slabobj_ext), gfp, slab_nid(slab)); - if (!vec) + if (!vec) { + /* Mark vectors which failed to allocate */ + if (new_slab) + mark_failed_objexts_alloc(slab); + return -ENOMEM; + } - obj_exts = (unsigned long)vec; + new_exts = (unsigned long)vec; #ifdef CONFIG_MEMCG - obj_exts |= MEMCG_DATA_OBJEXTS; + new_exts |= MEMCG_DATA_OBJEXTS; #endif + old_exts = slab->obj_exts; + handle_failed_objexts_alloc(old_exts, vec, objects); if (new_slab) { /* * If the slab is brand new and nobody can yet access its * obj_exts, no synchronization is required and obj_exts can * be simply assigned. */ - slab->obj_exts = obj_exts; - } else if (cmpxchg(&slab->obj_exts, 0, obj_exts)) { + slab->obj_exts = new_exts; + } else if (cmpxchg(&slab->obj_exts, old_exts, new_exts) != old_exts) { /* * If the slab is already in use, somebody can allocate and * assign slabobj_exts in parallel. In this case the existing