From patchwork Mon Feb 12 21:39:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13554072 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 0373EC4829D for ; Mon, 12 Feb 2024 21:41:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7A3726B00BC; Mon, 12 Feb 2024 16:40:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 72B316B00BD; Mon, 12 Feb 2024 16:40:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 57B506B00BE; Mon, 12 Feb 2024 16:40:49 -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 440DC6B00BC for ; Mon, 12 Feb 2024 16:40:49 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id F089C160231 for ; Mon, 12 Feb 2024 21:40:48 +0000 (UTC) X-FDA: 81784471776.07.0878761 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf11.hostedemail.com (Postfix) with ESMTP id 5A02D4000B for ; Mon, 12 Feb 2024 21:40:47 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=wRHxLdUJ; spf=pass (imf11.hostedemail.com: domain of 3XpDKZQYKCN0RTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3XpDKZQYKCN0RTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.NQF@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=1707774047; 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=RjVDAYkVgDU7fuXLh0MJZ7V+qIVlVtuXoydpki6LzsY=; b=TNkb6bdRImu7exuHCnj/8a7XBGriIsOPXjH5TNPtTIUAxLF5gSNft9zkzDLBXjQtLLP9OC wdWyHc05EUMXqjbXBIsF0KMKIFcWfaQ/zWCZKoWsN+6Bnp+YjtU0sa1tr4eDxSJX+CI0us LQyuEC5UtHBctIJj1qnNPsIe4rfSzVI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707774047; a=rsa-sha256; cv=none; b=jROnxsr0pq8Kur7XhG/q58d1v1JGNP03ArzA0j7WwLylgc9/A28i0I28fVPVOGswUuVL1J c/5d3dMvzrx6+WeaDFe3n5Saua1+H9vLHLNNQUrWLToaQQr9R60rXaxZClOJhJwmPC9TQD YFOyn/RUa9Eka9Iomz8DseRpVWeUAOE= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=wRHxLdUJ; spf=pass (imf11.hostedemail.com: domain of 3XpDKZQYKCN0RTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3XpDKZQYKCN0RTQDMAFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dcbfe1a42a4so1073060276.2 for ; Mon, 12 Feb 2024 13:40:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707774046; x=1708378846; 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=RjVDAYkVgDU7fuXLh0MJZ7V+qIVlVtuXoydpki6LzsY=; b=wRHxLdUJt5T0tzAUhPfudhqt8k1Brq8K8//u/1joLhaDjAkzheaEhtu7aeEEiB62FV 4hkol/uuApVTrkA0DRthOSveuHyj+GZKwazrfLwZUtW9+j1nR3WmfvDANkESJk8ahhn8 8ciwRWkNPIfdUB72P9vB6wjutoKSLqo811K/yK5mSW3ITmjNkix72tTuXRQAZP4qnmnx oSWu4cpQKuvUMaEYIGJjvWF+CMRT9AR2qXboqygRnYptZ58jufr+F/Cn5obD4MDi/m+J UTQn/7vaiJh2Yx0S151MkrEAVlsrFbNTbydHzlq8g61nlg5tqLmJbcXatmgI2p7QewDH O6VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707774046; x=1708378846; 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=RjVDAYkVgDU7fuXLh0MJZ7V+qIVlVtuXoydpki6LzsY=; b=Pjod3NH1tSHOWBZpNI/5zfO2eVgsJjQWskjAaRLB7XqXw99V8J5DrKs+57vWbAhjLq kGT0p4j42g7/gYOxMAEXK/V1KHLBEwlfScMO6Fwc2VM2tHVBI79qCAcCMqlde22lW0js eCy7cXYk1zSElrVyAWdGKGPXuUP0gkRHAfBqi3ByYeExPMxKqIizyx4Z3J67KYFWM0Ew wE64iepCS2j/MbCNZjCvfqkCBG3rAf93qiifJSSScYWtlyCYUZiG/XhaDErmunpb4kfg 16hQCaIxx7/ZdOqERhejm4kKvAeXRnjIqjqQQ5SYWMSZi0cvZnmS60WoLUEb08hhBP0A HrWQ== X-Forwarded-Encrypted: i=1; AJvYcCXk2vB9jEJHfnlmFz2TLv9xppCTgYEORuDO2vg9x2sl6ajVNP58YICbacF/FV5oKOGKMPd5InKetxbs6ubqW0km+Ic= X-Gm-Message-State: AOJu0YyNSs9zaK4w8XBpQx1Fms5LVlT8FT9DZsoTiPsxnNnwAkeD+DCl 5cWEhbAfUKhs2WV8BKxSbPiTSzHvAw4Yfmsc1HpTlJn5555bfgiOTbrpxNangFmqv7iZIlXbIoa MjQ== X-Google-Smtp-Source: AGHT+IESoh+UWKTP+1hXTVbYaUvPuidDpjnUl+NYldJf9cgWEgRiy1LGQkGWPWQFR+H7vya0ViMEzA6ILJE= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:b848:2b3f:be49:9cbc]) (user=surenb job=sendgmr) by 2002:a05:6902:150d:b0:dc6:d678:371d with SMTP id q13-20020a056902150d00b00dc6d678371dmr2278885ybu.3.1707774046204; Mon, 12 Feb 2024 13:40:46 -0800 (PST) Date: Mon, 12 Feb 2024 13:39:20 -0800 In-Reply-To: <20240212213922.783301-1-surenb@google.com> Mime-Version: 1.0 References: <20240212213922.783301-1-surenb@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240212213922.783301-35-surenb@google.com> Subject: [PATCH v3 34/35] 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, 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: 5A02D4000B X-Rspam-User: X-Stat-Signature: jpnss9ugx6bzew8pwhh8byw1y5qoxjt6 X-Rspamd-Server: rspam03 X-HE-Tag: 1707774047-715124 X-HE-Meta: U2FsdGVkX1+GInjq+9woiuDiWDRdiY1e0FZ2uAomd8y6G53bwELXX8gExah0sSAX5557fD8MB/3iyR2I8KeJyp2CqjnsXmRIf4wD8Ze/umJWFdiyCsA2D4O49oI56CizuH5HVhVKk2KJBBsaEhjcjJuAQ/xZCvqT+KbD1PKGAQzy8elgNz8ZCzR03KhTPprOSCdW7cUayqrNuHGOMfXk7MUMRTPf/kCjpjh1bbLZ9cIYkHJRL5LKDHNfycTbnQ1+LLOHL9aw66enU9uXwjGagq6ViT5bvMTwneBdM7xR9tIZ42Pk/daUpuyMjxObLQzRSoY04UYV3syk1wa+M3KdIDftBCF1gFeS93bzEfkBfo8k6/+5Pu89ZfhQBQ5Q2W6GtOPx3D3bH62CC2Sg5E3rzZ0P+QHABd4DZkgvFpfaGWqNXIDcCX9v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ender: 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/slab.h | 25 +++++++++++++++++++++++++ mm/slab_common.c | 22 +++++++++++++++------- 3 files changed, 43 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/slab.h b/mm/slab.h index cf332a839bf4..7bb3900f83ef 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -586,9 +586,34 @@ 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 */ diff --git a/mm/slab_common.c b/mm/slab_common.c index d5f75d04ced2..489c7a8ba8f1 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -214,29 +214,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