From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 7901320C00C for ; Wed, 25 Feb 2026 21:23:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772054634; cv=none; b=I/KBUVl2m9j7INVJVuv7wXOSGQao7gA3QwLq70ncl0B2h36qlmXNR6vo7h5atcRQInTpvMQ/spgOVcbTxXNduLZ4PU9NxYiNvXeIXIbzsKLJqPWBAIhmn1rOPxby5KJ2sSwpZKVnL94CHrOUrAPGYz2g1ZVctVpSaGW5k9SJfFI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772054634; c=relaxed/simple; bh=BWRTzZPXdigt5EpwYOMgpwkZpVbxW8S6uVh3HKLBW4M=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=mOevNiuqy0NJpNgtpYNkovc2lhY5EeVgEHCVGuMRi1cNJvhr15PtaObVQ98OfXnMLvmQ8mwZK7jdWbpFj+dKh5CaFYSbamebaGPLeKNsiwNmZPoT1+PavRbNWpW37XxrqyWWjWlMV1XHlBS8lPqN8k3qB/QzjUK49Tmqf1orfIo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=F25bmvy3; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="F25bmvy3" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4806b8fca44so324925e9.0 for ; Wed, 25 Feb 2026 13:23:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1772054631; x=1772659431; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=IlMLp45NDj7DYd86qZChbWO6ROjDFlUvzJJvPaO91OI=; b=F25bmvy3CKyP/R2plxMhGLsM4doubw4bRctylyfB4lkz4ckC04NB+K4rKXOO/JBEPj yxFssg4ybzk59xbKgTcGPZXbrW2n9kVizgP4L5nQ9MLzzF7gse7PnEFyCki19hhsQj6z SptqI5ZIO4ogc5HRu1cl79wpTqpp1o+QZhI8InvcP0Yhf1YrVRdBKi0Rz+pKwbl2tL3t wKapZx/pFrU0xfYKmOYlloUAAUD366RCeRTSVITd8j1pNyPw1Q+bywOICWCcx2jJdAzl +keUi2F8WG1FklbnjHx4YZrMDRy+FAmHh2OTQtBWc2Q4pLVjU9eJZGyECOFNP8oyx6Im vKag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772054631; x=1772659431; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IlMLp45NDj7DYd86qZChbWO6ROjDFlUvzJJvPaO91OI=; b=FEDlSMHMyrWhXrAafAB7hbIOBUVUF6yf05xXqC8Q8tQmL6ezvVGIC6IfIMiohXF9Tk mRK+8dhhOyyKyi41hFZ3VOZprHc/YZpEb60wyu+z+nGbjSK9sWQjYPUFHLIPtd7GxHuY QaLoay1j8TlA/5bQwCAyxocXaXrpPGXRlxMofha/B+yNNnz9smkVfyHf3VG7nbKuP+lM 5H86EcoqDzchylBTo80C3PC/SLewHgCkNCQPUg1NA1OPWoLZm12XoE1Jyb0u72268wB/ tgrdHgUhX585Cr87GCuwwUanhjkN9WJ5TF1JXXH9D/GRkuZTnIsWkq2HPdfhX+JMeb1B Hb2Q== X-Forwarded-Encrypted: i=1; AJvYcCUbLQ2ZShNU7EfhD4hXzJ1+MQinYOUMNaHZVsWPH6dwyydEjtWfl3Ds/ak3nlFnsyG31wsRAcbB5D1Se84=@vger.kernel.org X-Gm-Message-State: AOJu0YxTUVeEqMmXHVSZhgSj/zMGqy75m3Ahg89HyYqv8S/SWTU7yGjS wol1uW9ssO+jqYXMjbkCEhfnT19PMdgEWFrGqxYVo3JFDRIY5QPW+evAmKl307i1oEo= X-Gm-Gg: ATEYQzx6G/dS5MfvNEO9b4N7BpIw2jZ+9PoJUhVBJF3NYyxf8/Y080J8fWDs/VqPNwc 4ddGu687zDKa0c4ggPnIqjcqHF9wY8IYwVXFOOgxiinVjF80EFZebVXSvhaPQk5DHjgMsP+V0oZ 7v9F3aBRp9VxQYpKsDK9f8tJrlxQHSmXZU5QFhXm5Arl9mvOTvFx6XT/5r/2kYOW5kvEUT28VgK pmyXgyZ1waZUvo7DzaAOdpkxJlYKJMHDCvOpXD54II/RlmqMjxcFbLaCRbq8sVAg3UHECm0CDq0 pXnkCKYhwVG8VO70CGBkJK7tok9fXgu8jL7m+8J78kueYdwK/LNtqQoHYQ67Cq/oJ5zkkTMC/fg qt7n3EV+MXTzx49wkEfl8CojP72UrE5SeST4vOmfUcw+DC8hQzDX5nArwkvaPmMunoU+aeiCtnV iDXTgKS6cHEKfaSso2tGjiaUEn/COiu5G68AXp+FdMIo2AoyO+tnFcPDZsycT0zFr/Zw== X-Received: by 2002:a05:600c:4e48:b0:47a:94fc:d063 with SMTP id 5b1f17b1804b1-483a95eb348mr178021595e9.1.1772054630728; Wed, 25 Feb 2026 13:23:50 -0800 (PST) Received: from ?IPV6:2001:1a48:8:903:654a:5c5e:479:172d? ([2001:1a48:8:903:654a:5c5e:479:172d]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43970d4c982sm36365573f8f.31.2026.02.25.13.23.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 Feb 2026 13:23:50 -0800 (PST) Message-ID: <3ab53191-5aac-4b9f-a019-303d837ec517@suse.com> Date: Wed, 25 Feb 2026 22:23:49 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 1/1] mm/slab: mark alloc tags empty for sheaves allocated with __GFP_NO_OBJ_EXT To: Suren Baghdasaryan , akpm@linux-foundation.org Cc: vbabka@suse.cz, harry.yoo@oracle.com, 00107082@163.com, cl@gentwo.org, rientjes@google.com, roman.gushchin@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20260225163407.2218712-1-surenb@google.com> From: Vlastimil Babka Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 2/25/26 8:08 PM, Suren Baghdasaryan wrote: > On Wed, Feb 25, 2026 at 4:34 PM Suren Baghdasaryan wrote: >> >> alloc_empty_sheaf() allocates sheaves from SLAB_KMALLOC caches using >> __GFP_NO_OBJ_EXT to avoid recursion, however it does not mark their >> allocation tags empty before freeing, which results in a warning when >> CONFIG_MEM_ALLOC_PROFILING_DEBUG is set. Fix this by marking allocation >> tags for such sheaves as empty. >> > > I think this should also have: > > Fixes: 4c0a17e28340 ("slab: prevent recursive kmalloc() in alloc_empty_sheaf()") > > and CC to stable for inclusion into 6.19. > Andrew, Vlastimil, should I post another version CC'ing stable or you > can add that line and forward to stable? I will add it. Note, they don't care about getting an actual email, but seeing the Cc: line in the mainline commit. >> Reported-by: David Wang <00107082@163.com> >> Closes: https://lore.kernel.org/all/20260223155128.3849-1-00107082@163.com/ >> Analyzed-by: Harry Yoo >> Signed-off-by: Suren Baghdasaryan >> Reviewed-by: Harry Yoo >> Tested-by: Harry Yoo >> Tested-by: David Wang <00107082@163.com> >> --- >> include/linux/gfp_types.h | 2 ++ >> mm/slab.h | 4 ++-- >> mm/slub.c | 33 +++++++++++++++++++++++---------- >> 3 files changed, 27 insertions(+), 12 deletions(-) >> >> diff --git a/include/linux/gfp_types.h b/include/linux/gfp_types.h >> index 814bb2892f99..6c75df30a281 100644 >> --- a/include/linux/gfp_types.h >> +++ b/include/linux/gfp_types.h >> @@ -139,6 +139,8 @@ enum { >> * %__GFP_ACCOUNT causes the allocation to be accounted to kmemcg. >> * >> * %__GFP_NO_OBJ_EXT causes slab allocation to have no object extension. >> + * mark_obj_codetag_empty() should be called upon freeing for objects allocated >> + * with this flag to indicate that their NULL tags are expected and normal. >> */ >> #define __GFP_RECLAIMABLE ((__force gfp_t)___GFP_RECLAIMABLE) >> #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) >> diff --git a/mm/slab.h b/mm/slab.h >> index 71c7261bf822..f6ef862b60ef 100644 >> --- a/mm/slab.h >> +++ b/mm/slab.h >> @@ -290,14 +290,14 @@ static inline void *nearest_obj(struct kmem_cache *cache, >> >> /* Determine object index from a given position */ >> static inline unsigned int __obj_to_index(const struct kmem_cache *cache, >> - void *addr, void *obj) >> + void *addr, const void *obj) >> { >> return reciprocal_divide(kasan_reset_tag(obj) - addr, >> cache->reciprocal_size); >> } >> >> static inline unsigned int obj_to_index(const struct kmem_cache *cache, >> - const struct slab *slab, void *obj) >> + const struct slab *slab, const void *obj) >> { >> if (is_kfence_address(obj)) >> return 0; >> diff --git a/mm/slub.c b/mm/slub.c >> index 862642c165ed..34c32749f091 100644 >> --- a/mm/slub.c >> +++ b/mm/slub.c >> @@ -2041,18 +2041,18 @@ static inline void dec_slabs_node(struct kmem_cache *s, int node, >> >> #ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG >> >> -static inline void mark_objexts_empty(struct slabobj_ext *obj_exts) >> +static inline void mark_obj_codetag_empty(const void *obj) >> { >> - struct slab *obj_exts_slab; >> + struct slab *obj_slab; >> unsigned long slab_exts; >> >> - obj_exts_slab = virt_to_slab(obj_exts); >> - slab_exts = slab_obj_exts(obj_exts_slab); >> + obj_slab = virt_to_slab(obj); >> + slab_exts = slab_obj_exts(obj_slab); >> if (slab_exts) { >> get_slab_obj_exts(slab_exts); >> - unsigned int offs = obj_to_index(obj_exts_slab->slab_cache, >> - obj_exts_slab, obj_exts); >> - struct slabobj_ext *ext = slab_obj_ext(obj_exts_slab, >> + unsigned int offs = obj_to_index(obj_slab->slab_cache, >> + obj_slab, obj); >> + struct slabobj_ext *ext = slab_obj_ext(obj_slab, >> slab_exts, offs); >> >> if (unlikely(is_codetag_empty(&ext->ref))) { >> @@ -2090,7 +2090,7 @@ static inline void handle_failed_objexts_alloc(unsigned long obj_exts, >> >> #else /* CONFIG_MEM_ALLOC_PROFILING_DEBUG */ >> >> -static inline void mark_objexts_empty(struct slabobj_ext *obj_exts) {} >> +static inline void mark_obj_codetag_empty(const void *obj) {} >> static inline bool mark_failed_objexts_alloc(struct slab *slab) { return false; } >> static inline void handle_failed_objexts_alloc(unsigned long obj_exts, >> struct slabobj_ext *vec, unsigned int objects) {} >> @@ -2211,7 +2211,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); >> + mark_obj_codetag_empty(vec); >> if (unlikely(!allow_spin)) >> kfree_nolock(vec); >> else >> @@ -2254,7 +2254,7 @@ static inline void free_slab_obj_exts(struct slab *slab, bool allow_spin) >> * 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); >> + mark_obj_codetag_empty(obj_exts); >> if (allow_spin) >> kfree(obj_exts); >> else >> @@ -2312,6 +2312,10 @@ static void alloc_slab_obj_exts_early(struct kmem_cache *s, struct slab *slab) >> >> #else /* CONFIG_SLAB_OBJ_EXT */ >> >> +static inline void mark_obj_codetag_empty(const void *obj) >> +{ >> +} >> + >> static inline void init_slab_obj_exts(struct slab *slab) >> { >> } >> @@ -2783,6 +2787,15 @@ static inline struct slab_sheaf *alloc_empty_sheaf(struct kmem_cache *s, >> >> static void free_empty_sheaf(struct kmem_cache *s, struct slab_sheaf *sheaf) >> { >> + /* >> + * If the sheaf was created with __GFP_NO_OBJ_EXT flag then its >> + * corresponding extension is NULL and alloc_tag_sub() will throw a >> + * warning, therefore replace NULL with CODETAG_EMPTY to indicate >> + * that the extension for this sheaf is expected to be NULL. >> + */ >> + if (s->flags & SLAB_KMALLOC) >> + mark_obj_codetag_empty(sheaf); >> + >> kfree(sheaf); >> >> stat(s, SHEAF_FREE); >> >> base-commit: 7dff99b354601dd01829e1511711846e04340a69 >> -- >> 2.53.0.414.gf7e9f6c205-goog >>