From patchwork Wed Feb 21 19:40:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13566214 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 5F048C48BEB for ; Wed, 21 Feb 2024 19:42:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 568836B00C7; Wed, 21 Feb 2024 14:42:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F1B16B00C8; Wed, 21 Feb 2024 14:42:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 31BD06B00C9; Wed, 21 Feb 2024 14:42:15 -0500 (EST) 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 1661D6B00C7 for ; Wed, 21 Feb 2024 14:42:15 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E5BB312077A for ; Wed, 21 Feb 2024 19:42:14 +0000 (UTC) X-FDA: 81816832188.15.0C6490F Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf06.hostedemail.com (Postfix) with ESMTP id 1BDEA180012 for ; Wed, 21 Feb 2024 19:42:12 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=cZisyCrP; spf=pass (imf06.hostedemail.com: domain of 3E1LWZQYKCEY02zmvjowwotm.kwutqv25-uus3iks.wzo@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3E1LWZQYKCEY02zmvjowwotm.kwutqv25-uus3iks.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=1708544533; 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=BN4n4r+pGIOuiPq9+HuwMZ/LVswbQsC+381oXCoHOQk=; b=g0R8Ii5IREPS/ylu3D58XFvd8lNIvPAX+yTt7c9mlKmhtg3hTkOXLgIxCtYGyoQXn1QtOW 6f84zOZt9WdIULIh3CfzyzPJoyIQSl/a3tmGIRg2ESJUoG6vt9ROWYL0tgffvsvZX832xx +4K6D7WIyvCv4fsa5lovnddCHnIA1Gw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708544533; a=rsa-sha256; cv=none; b=u/Xq1eTB8HwVy40hekUJx0DSo8jY2QUc2EwC5NplcVP7MgRm9Gf47+th0CqTVk2WRexKd2 6du2/x0k5pKhGF/WMAB3BhS+b1b3g1X8PuA1jzQXnvinwuREZDu/bUC9dT5Br7VHYZPr1u gyjV8M9uNwFT0h/8z/wtuMTjv7hqslE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=cZisyCrP; spf=pass (imf06.hostedemail.com: domain of 3E1LWZQYKCEY02zmvjowwotm.kwutqv25-uus3iks.wzo@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3E1LWZQYKCEY02zmvjowwotm.kwutqv25-uus3iks.wzo@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6b26ce0bbso14756151276.1 for ; Wed, 21 Feb 2024 11:42:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708544532; x=1709149332; 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=BN4n4r+pGIOuiPq9+HuwMZ/LVswbQsC+381oXCoHOQk=; b=cZisyCrPeonXae56aL6675SC9EaYlHm9Vzx1RTE2YRmx94ly19kUmryrTZWOkbdCQi uRXWHNyYe3F6SDlD1fHVi/rAnMlg8VkvJtThTsGPThac8Sb2MmfF4yuHWlAUoK1Uqy5I yVlzg/A7cb/sb3qk8QM5Tpd7WEJNwBVEOS7LVuTf7U4AEsETP3CzYtMHQd9j8ffPPKXD 2Ne+9KWxr4+kpH+0pM+uYs/7molWuPPTrd4/sLMqfdOMmwKCgud3gjWULEgQOvDK9OP8 2ro1mIwz1fB1FFkIZktj6pNrbCdF/+ZdtQBrExfUrFkAQJAddPsF/mXycRcpD5qxzAAt caaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708544532; x=1709149332; 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=BN4n4r+pGIOuiPq9+HuwMZ/LVswbQsC+381oXCoHOQk=; b=L4qstj8ftM7OiQhWrpnnCN4OUy9g2ofXnBX08xncCUozA8PRBY8zUyWdU/u7AEZZat ViUJv3q7EwLu9U5YDZ/60lLVbu7l7mpii6+l4Ou8bTna3m6XIMTs8RiZvWAzXviEWlQS GY6SBsW9pX51SXRIZLYlbk6D0BmX/oHwDSaC4sTywW30o9MSOhzkCxt52+I9BA2V038y GpXqxzKiWg5f1n8ryuLQBWPo1VqvzvKAQC39A68V+g8XxfxZiS+fZMwKc7dzUt0wzVr6 ak2jszEgzPwtf1/7hD8HYzGm1Rtg4pDNq9LWiK87QX5I3ESTvj72CkiyIWpPwY+ITzja O8oA== X-Forwarded-Encrypted: i=1; AJvYcCV/DK5XAE6PpCifg31Swd89qk/QtlKkx0OHVfFthylGIdF/p4N+YHYh1MGJCaP4hcCJymWyKyVU1EiCeM6WAQQ+67c= X-Gm-Message-State: AOJu0YwZ5Cj64eAgEtGrCOXRsYWB5VSzCcWvdelhdt883o9bRAAzURza tYA3MWL7BVP4x85e4f481cC90UqYOaPmSmiD2IEX06D4hrHX/ZAIZTZuyc3239CuTn7ljhJ1fx7 Krg== X-Google-Smtp-Source: AGHT+IGccLdK1+8RZqTfFKQGLX6PM7i11Typ+L1RnqZIOYRT2MopGhT4QGJWEbhgFrEtPg85XhcRKYt7Lzg= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:953b:9a4e:1e10:3f07]) (user=surenb job=sendgmr) by 2002:a25:ab6f:0:b0:dcb:b9d7:2760 with SMTP id u102-20020a25ab6f000000b00dcbb9d72760mr67613ybi.13.1708544531841; Wed, 21 Feb 2024 11:42:11 -0800 (PST) Date: Wed, 21 Feb 2024 11:40:47 -0800 In-Reply-To: <20240221194052.927623-1-surenb@google.com> Mime-Version: 1.0 References: <20240221194052.927623-1-surenb@google.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240221194052.927623-35-surenb@google.com> Subject: [PATCH v4 34/36] 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, 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: 1BDEA180012 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: yur6fbamxzdd4gcptfmoo1c9cq67f8y1 X-HE-Tag: 1708544532-791600 X-HE-Meta: U2FsdGVkX19kbpqJbvgZidA0NFVRkGkbTolcmSxX8S0vAatYQuk0xWN+s+vFncbstet3n9dziVhl5823yibRxK6om5uhEYWl9QPJEOLT94MrMDSv8uHEfmB1l+t/uUjdGj02B5nJr5p/MF1ndT/k4zSq5FTyIgUft7V1lMn+A5UKHzBqBa3+Jkz9XA7ErtZSTNew/9XI9EaY7gpetOncmfX8oXuTeqHjitkNsUJa2bXqeg+ee1ewnnrg0705hiveiWhMD2mNBxxoqZtzNIogN8SdZ1Li8r1DmHyBlrWOHWDMy15o7FmQCqtB17nOfUbPNQscWMX2djL/HmpF4P0p/MgW1uuSm/MYPWbimOIph5wVfsuFT42agkLK2IihymMThrRW2yKMH3vJpCnQiFY5HzuDeSzCsrrMQhOgmH+1Sc2cHWshfpfKtjU8M/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iIKLr23EHFcp/jugc2jlKevHp/Uu3/ewN5qFSlYFlrCXcoP5yWAMPnzIc1HHMqovNs/Nvv5MHrY8n05iWqazUfRyx05fgq3m24l0+75XW84u/WM0//R9czjaj/ZFC3g2szagjKOH84cnet2JCzZAS5hw9FwSbKpIha7S2shdHa5MToAjCRbqzEcATrZ5N1oDYMGA== 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 2b010316016c..f95241ca9052 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -365,8 +365,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 3e41d45f9fa4..43d63747cad2 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1901,9 +1901,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 */ @@ -1919,29 +1943,37 @@ 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