From patchwork Thu Aug 15 07:21:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Ge X-Patchwork-Id: 13764460 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 ADE48C3DA7F for ; Thu, 15 Aug 2024 07:21:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DC7686B0088; Thu, 15 Aug 2024 03:21:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D773D6B0089; Thu, 15 Aug 2024 03:21:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C66D26B008A; Thu, 15 Aug 2024 03:21:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id AB4AA6B0088 for ; Thu, 15 Aug 2024 03:21:51 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5C98BA828F for ; Thu, 15 Aug 2024 07:21:51 +0000 (UTC) X-FDA: 82453635222.12.7870FD7 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) by imf12.hostedemail.com (Postfix) with ESMTP id 7317B4000F for ; Thu, 15 Aug 2024 07:21:49 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=BVzWtDEt; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf12.hostedemail.com: domain of hao.ge@linux.dev designates 95.215.58.174 as permitted sender) smtp.mailfrom=hao.ge@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723706456; a=rsa-sha256; cv=none; b=YzEsxegznU7LcUAudwMeesAtdPBWWFRkzm6RXuIcrhpO1iU29BfdfkLCJOOrpSn5goMer4 rvj4x7PKlLgcl06a6ltGFpVnfX9ZjXzqLHnSg0iF+OmRa5uQhxIqVP5mVYperogB/2MQMx aGt+51sVL7dQbB1Ib0+DuIQBCFHnQ2A= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=BVzWtDEt; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf12.hostedemail.com: domain of hao.ge@linux.dev designates 95.215.58.174 as permitted sender) smtp.mailfrom=hao.ge@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723706456; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=6L1k8kwIf+HGl+QxmcDKqyyW8jVzFtFYfbXsUufB3qI=; b=fIMhXBf+OqyxX9mZm/yzgPNprLrKMrsEKTxer+Fr+uwEXLCvvuubgKAO51GKxLIEYZpX57 MCP0O93RvqZ5BT7OLm7rwBtsESitKvj5+uaVPUdiDfigaqhrFJCAUFdWM4hJZvFbaFrRHD By6AzRW478YQyFF7l6HgFd5cJeOzbQs= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1723706507; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=6L1k8kwIf+HGl+QxmcDKqyyW8jVzFtFYfbXsUufB3qI=; b=BVzWtDEtnr6d3Q7t+dCGnR28ooBnKJ4uUL0e6Q66yUG1p//9oOR3J5bFyWhMXSTtZgp1T+ QNNhaxSCaiWz7RfTZVK+L6TD3+gmZZtoubTF4UgLo8wIC+GIFHjWS/yV6oMW8sV8rcFyHU QKAcp/JWX+8uJM7oKv4hD/JzVlvqTmk= From: Hao Ge To: cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, akpm@linux-foundation.org, vbabka@suse.cz, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, surenb@google.com, kees@kernel.org, kent.overstreet@linux.dev Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hao Ge Subject: [PATCH] mm/slub: Add check for s->flags in the alloc_tagging_slab_free_hook Date: Thu, 15 Aug 2024 15:21:13 +0800 Message-Id: <20240815072113.30288-1-hao.ge@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 7317B4000F X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 7867ep36txdbsjtm55uuc9x146gjfhko X-HE-Tag: 1723706509-571588 X-HE-Meta: U2FsdGVkX19MJ8BUNPPx5SR1+37DSA5BaWI9lK0FOwnwmKTCfG70B4SFhTpQWYdEnw5Zz1XZXWk8Ou9O92seRPeOaTVR6+EBQRrlsCzcAOZpa5AhG864u+9dv2QaZSnZgbO0INoXcdKg7haG42pvX3WYy1v2ugzw2Fs1xRltnYAMcaX3j7FMDxVPgALe+3Dlvr/wCjG2XfU7PGk2RTOJYNSxj9HynH1JW25ZhPohwSqdLnjwL/sDPnTe93Tq2mmFSlyeTihYPvHNMYwmlOr6D/ua7Pj2urgJrQz5Jmvfp+3U3ruw6RWWobkhn3+NhnTwyRkAFEwWBkc85qeLg1CggEfhHtaL5XrOGmDw1aIesy89myl1jYmsEDhp65T6tr70H48y3iX9eerXlCJQycdIkWZm3K+pHubbavc67CyE2+0qKEnx6W8Ef4MkB+4nDSUAgT6ixYHOxFTeT8lnXt2SJLlCggNUmKLAag8zUAJY2PYzTGto5XgopY5KEW6VY3Eb+OUhmkVKZen5dnbTb91xA9Z1OEPa4bqj2SEhrPh6NSWhUIcLjCszjsf8UrN5VZRNWe0aaFWXUlUMvpZY392dNNXhaQYGamEHq89jU+6hIUt1WD4AqCCvkBkF92j5o2KvwHWclSvrE5/yCEXszyglpHGGgIeNWWRuUnXUS9tMo+aM+/ozeuawDKRAPWuPz9jaNQ9p27DO+GUifgqdF9dhsxwxW00/p0VBDVEKvMD2wQLm/G/Xod76ceJCULSM5/XEDo7xABjDN7gQosD/0OG/64cMu8uA3PhA5fSFOUYYENCY1F1ggoESjHqJfugf8tDp5dd+NGmEXjckoPnDjus+6gZtYiFkQtHnZ/wpT+1D0FLXeCQnxWhJrfxgxH4nNlN3478H0/GaQP+touEx91dwgYpuEM9lvmgQj7iBaq1B6gJt307V/T2YS8qH1USFB2uyEJDaD4n/MfYm8B8Iifb 3qb9MDLF 2w+jMe1XSxEI97kMXK9oB2vHSihTuFH+T3GTPHkAoTqF077tGmBQgApoxz8v7uU0JWrdcaI0zv290815xJKLMaSSUd90R7SggYoA30kcx0t2vMhlrRKZTkm9kTrukj+JLpP8xsSDVqXNLFLXSUpNq3U2tEujhQRwKVoJszLnW8vpJi7Kgu8fba70dVtpmjZ713vToOOeUtt2+T43MJGwJHDh9qx48bSQtIiOWTICw3vJLNxY= 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: From: Hao Ge When enable CONFIG_MEMCG & CONFIG_KFENCE & CONFIG_KMEMLEAK, the following warning always occurs,This is because the following call stack occurred: mem_pool_alloc kmem_cache_alloc_noprof slab_alloc_node kfence_alloc Once the kfence allocation is successful,slab->obj_exts will not be empty. Since in the prepare_slab_obj_exts_hook function,we perform a check for s->flags & (SLAB_NO_OBJ_EXT | SLAB_NOLEAKTRACE),the alloc_tag_add function will not be called as a result.Therefore,ref->ct remains NULL. However,when we call mem_pool_free,since obj_ext is not empty, it eventually leads to the alloc_tag_sub scenario being invoked. This is where the warning occurs. So we should add corresponding checks in the alloc_tagging_slab_free_hook. For __GFP_NO_OBJ_EXT case,I didn't see the specific case where it's using kfence,so I won't add the corresponding check in alloc_tagging_slab_free_hook for now. [ 3.734349] ------------[ cut here ]------------ [ 3.734807] alloc_tag was not set [ 3.735129] WARNING: CPU: 4 PID: 40 at ./include/linux/alloc_tag.h:130 kmem_cache_free+0x444/0x574 [ 3.735866] Modules linked in: autofs4 [ 3.736211] CPU: 4 UID: 0 PID: 40 Comm: ksoftirqd/4 Tainted: G W 6.11.0-rc3-dirty #1 [ 3.736969] Tainted: [W]=WARN [ 3.737258] Hardware name: QEMU KVM Virtual Machine, BIOS unknown 2/2/2022 [ 3.737875] pstate: 60400005 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 3.738501] pc : kmem_cache_free+0x444/0x574 [ 3.738951] lr : kmem_cache_free+0x444/0x574 [ 3.739361] sp : ffff80008357bb60 [ 3.739693] x29: ffff80008357bb70 x28: 0000000000000000 x27: 0000000000000000 [ 3.740338] x26: ffff80008207f000 x25: ffff000b2eb2fd60 x24: ffff0000c0005700 [ 3.740982] x23: ffff8000804229e4 x22: ffff800082080000 x21: ffff800081756000 [ 3.741630] x20: fffffd7ff8253360 x19: 00000000000000a8 x18: ffffffffffffffff [ 3.742274] x17: ffff800ab327f000 x16: ffff800083398000 x15: ffff800081756df0 [ 3.742919] x14: 0000000000000000 x13: 205d344320202020 x12: 5b5d373038343337 [ 3.743560] x11: ffff80008357b650 x10: 000000000000005d x9 : 00000000ffffffd0 [ 3.744231] x8 : 7f7f7f7f7f7f7f7f x7 : ffff80008237bad0 x6 : c0000000ffff7fff [ 3.744907] x5 : ffff80008237ba78 x4 : ffff8000820bbad0 x3 : 0000000000000001 [ 3.745580] x2 : 68d66547c09f7800 x1 : 68d66547c09f7800 x0 : 0000000000000000 [ 3.746255] Call trace: [ 3.746530] kmem_cache_free+0x444/0x574 [ 3.746931] mem_pool_free+0x44/0xf4 [ 3.747306] free_object_rcu+0xc8/0xdc [ 3.747693] rcu_do_batch+0x234/0x8a4 [ 3.748075] rcu_core+0x230/0x3e4 [ 3.748424] rcu_core_si+0x14/0x1c [ 3.748780] handle_softirqs+0x134/0x378 [ 3.749189] run_ksoftirqd+0x70/0x9c [ 3.749560] smpboot_thread_fn+0x148/0x22c [ 3.749978] kthread+0x10c/0x118 [ 3.750323] ret_from_fork+0x10/0x20 [ 3.750696] ---[ end trace 0000000000000000 ]--- Fixes: 4b8736964640 ("mm/slab: add allocation accounting into slab allocation and free paths") Signed-off-by: Hao Ge --- mm/slub.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/slub.c b/mm/slub.c index c9d8a2497fd6..1f67621ba6dc 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -2116,6 +2116,9 @@ alloc_tagging_slab_free_hook(struct kmem_cache *s, struct slab *slab, void **p, if (!mem_alloc_profiling_enabled()) return; + if (s->flags & (SLAB_NO_OBJ_EXT | SLAB_NOLEAKTRACE)) + return; + obj_exts = slab_obj_exts(slab); if (!obj_exts) return;