From patchwork Tue Oct 1 14:02:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nilay Shroff X-Patchwork-Id: 13818045 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 484ABCEACC7 for ; Tue, 1 Oct 2024 14:03:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D05B328008D; Tue, 1 Oct 2024 10:03:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CB5C3280068; Tue, 1 Oct 2024 10:03:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B565928008D; Tue, 1 Oct 2024 10:03:05 -0400 (EDT) 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 94150280068 for ; Tue, 1 Oct 2024 10:03:05 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 30560AA796 for ; Tue, 1 Oct 2024 14:03:05 +0000 (UTC) X-FDA: 82625199930.05.D05FB76 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by imf04.hostedemail.com (Postfix) with ESMTP id DD4354001A for ; Tue, 1 Oct 2024 14:03:01 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=UIZnfv0Y; spf=pass (imf04.hostedemail.com: domain of nilay@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=nilay@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727791213; 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=BnmecZ0iqTgZULodIzqRc9lkfTQb08vAy8iJId148mM=; b=nw60LQh9FUs1TrTGUw8phvisjRfd0vrN4jPdFtAPJbSlES3bXVeym+Coi+RXa5AhN2Uk/o T/cbk0AUCEM24NUQuG0o24VhCRZmVsppMmLfFWobXbC5gGqLWzyN/xPKjzumHxWVsEx1A7 kfUymmrckoMO6IyX4fXHz8+thpYST/0= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=UIZnfv0Y; spf=pass (imf04.hostedemail.com: domain of nilay@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=nilay@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727791213; a=rsa-sha256; cv=none; b=But0+2Y+/az6rgj4gBso+NzpeBusLa/ttTK0H2Zy9QeKhQfsNcW1PF6hLZSOQoCYqrq0U+ UWOTjBoa/2xh+Q3E25MigWsbk3UjL3rNepvGpBFTjSZOGS2Qgwvkpp930PMtoW+BNCqtTw YAU9I3b1OS3yHm1vcq48YfnEUObHT1Y= Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 491AqUn4000759; Tue, 1 Oct 2024 14:02:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from :to:cc:subject:date:message-id:content-transfer-encoding :mime-version; s=pp1; bh=BnmecZ0iqTgZULodIzqRc9lkfTQb08vAy8iJId1 48mM=; b=UIZnfv0YD62X/iXf1XMWiU7GiEMpUJcb/3Cxw91mRBzNyKwhVD4mybx ia5HJb37RsM/Z6b8lb936l8m4lhZj7BG05RGtHgyf4fLHIWMXD4Ji/po1YNGqRbl wqj+x58Ons3+hjkHckLJnqe2Dq6YjlHckgaJD+i4yjKTgorioZ7FSNwgjDKwjuUe ZRIufA5Pi4zkf9n5PAcKXiJz8T0bnRl5fc8BY3M3pUJW3W/uXT9I0LvyWcNX/yL4 yDvcmwlkXpLqjaC/mXeVwDReZ+njp1vj6ydzfIR9fBewo2CBbTf0ILMB/42/b+8Z Q0ga1LXly/AAshwBv4Omn6ylh++l+jQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 420fq4s0w9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Oct 2024 14:02:55 +0000 (GMT) Received: from m0353725.ppops.net (m0353725.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 491DwjbB014448; Tue, 1 Oct 2024 14:02:54 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 420fq4s0w3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Oct 2024 14:02:54 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 491CgmYp017836; Tue, 1 Oct 2024 14:02:53 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 41xw4mvs15-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Oct 2024 14:02:53 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 491E2omo42598856 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 1 Oct 2024 14:02:50 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0EB242004D; Tue, 1 Oct 2024 14:02:50 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9990420040; Tue, 1 Oct 2024 14:02:46 +0000 (GMT) Received: from li-c9696b4c-3419-11b2-a85c-f9edc3bf8a84.in.ibm.com (unknown [9.109.198.143]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 1 Oct 2024 14:02:46 +0000 (GMT) From: Nilay Shroff To: linux-mm@kvack.org, linux-block@vger.kernel.org Cc: vbabka@suse.cz, akpm@linux-foundation.org, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, yi.zhang@redhat.com, shinichiro.kawasaki@wdc.com, axboe@kernel.dk, gjoyce@linux.ibm.com, Nilay Shroff Subject: [PATCH] mm, slab: fix use of SLAB_SUPPORTS_SYSFS in kmem_cache_release() Date: Tue, 1 Oct 2024 19:32:35 +0530 Message-ID: <20241001140245.306087-1-nilay@linux.ibm.com> X-Mailer: git-send-email 2.45.2 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 3VwRkQjG5-kubepOQFdAhebx0butX-gr X-Proofpoint-GUID: Hg5ddDC25tYzFi1maFfjT6DHJXN_XNtl X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-01_10,2024-09-30_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 adultscore=0 suspectscore=0 spamscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=960 clxscore=1011 mlxscore=0 priorityscore=1501 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2410010089 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: DD4354001A X-Stat-Signature: n3yceamzma8s3ki41zcp1ou43f5qzcty X-Rspam-User: X-HE-Tag: 1727791381-619683 X-HE-Meta: U2FsdGVkX18Zdkp5JzY/yH71lilJp8t5rBBLl2sdArJHYQNWAI0xScIkueZN6PQtMd6hQ2cYRujZkcA2hSKvbchf1YdaNzgb4U/CGx4bwEAAXTmpU4ifTp6PYjHt9tDCYa0mqXtBIyjI0y+WkVT4l8lNYPJh7PmN+y9mXTLkXpEq7aqBRcQ5hTUxx4aDqVWR/lTCcwcnL7gZSkg9bzmO7jtT/3hxhqgdA7ERV1CB73ipvLhg0+I5/a2bxh/UYC0UWpwmhEpusx6stR1u2Zrc6ac4LhnkfvijkhTVg/o4dpLfJO8RudCnseEAQrvzgb9/JAGxpDHO7BO8f2+MJeYMIEmrbk1CcxM/mtfckipVUONbkQDiNLu37H93I4GzLgeIiT6h1QXFBkNCXVJCLn5K9UmmfhZjiacrxSMgj7hvbnL/RNCV6BPZbzhsWR0KbxmW4SRpsTR46uWDgBpqHUjtTefYSDLhftv1RegfCObQotJ4d0SsMlj3KIe/9Pi4AvZiczXDHiqDlKGs6/QtfVmOHyYy9Qc72nLuOMaECjcdF3B20NDEX81KA7l3ayWxNnyYZ3LsRiTr0EoMdEPokZT8Ma4b8cIh15vbTft6EO6h/fXO58/pZ2m3OB6/rHcIkx9M4fXjtiS1p1Gkbis+cteizXoaNXI5w/d9B4nM3haxvtVy8EC2YeaazSetk7UddzZ5AHHZsl2nNjO710LIt1rO2KHuCeO48qsaMnR0VOOPaIGul9mXq2J/vhsr6ImMSR8hntpL7j8tuIrb7bqMDo4410G9IbmOHIEaqRUS0H7nQwanrvDaFD6fi1o2fINLb4mRjZL7znzKFbNvTLGVhp+msUxO5Q3L3LGNCc24Q52rEOuJKDor0IWTOMCWtGMcR9b0LxZjjjNXDKzfDZQtakrOfA4O3ocvYhIqd20srKjx/tJhUzXmi/TxIzaNFDEmYhtSz5dbz84Ppn0niauGtP1 /BqQAJr8 mdfSVDrE8NCEDzOInj9gjbxIn3Ln7SeHV6b2TdCGu2V6y6AKVvC1vVDWX8UPMXbBeBhx4/CSj9Jhg9K8zDT097BrzxsdhuRAAzGc3E4bz/lbbC28vWD4LhlCFQxxwXf1xNtX91UWBO3rz36RPRnOqDLMIAxZWKjeipXSKisUYY3mV6c1y84TNKB/Z1tZGgVTVawSoBwXJistRypj6cEDoAtB0Lf+GdFGwT821zmSfj3WpjC+wKfXOAqPSrnypesC0Oq/p8qCg3M4WUfdOyiK4YdjNu4aSwzYzAwFXbBSPjO7tIW7zQS3ycofvCfpz0U3YUqV9hY3FmiXTYnf+/1qMmu0dsXIfYa9U8IFgLE2ZwIVYaNzcs8zReCWEoHBgUoe9WbOCZDaTR/jH1F0= 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: The fix implemented in commit 4ec10268ed98 ("mm, slab: unlink slabinfo, sysfs and debugfs immediately") caused a subtle side effect due to which while destroying the kmem cache, the code path would never get into sysfs_slab_release() function even though SLAB_SUPPORTS_SYSFS is defined and slab state is FULL. Due to this side effect, we would never release kobject defined for kmem cache and leak the associated memory. The issue here's with the use of __is_defined() macro in kmem_cache_ release(). The __is_defined() macro expands to __take_second_arg( arg1_or_junk 1, 0). If "arg1_or_junk" is defined to 1 then it expands to __take_second_arg(0, 1, 0) and returns 1. If "arg1_or_junk" is NOT defined to any value then it expands to __take_second_arg(... 1, 0) and returns 0. In this particular issue, SLAB_SUPPORTS_SYSFS is defined without any associated value and that causes __is_defined(SLAB_SUPPORTS_SYSFS) to always evaluate to 0 and hence it would never invoke sysfs_slab_release(). This patch helps fix this issue by defining SLAB_SUPPORTS_SYSFS to 1. Fixes: 4ec10268ed98 ("mm, slab: unlink slabinfo, sysfs and debugfs immediately") Reported-by: Yi Zhang Closes: https://lore.kernel.org/all/CAHj4cs9YCCcfmdxN43-9H3HnTYQsRtTYw1Kzq-L468GfLKAENA@mail.gmail.com/ Signed-off-by: Nilay Shroff Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Tested-by: Yi Zhang --- mm/slab.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/slab.h b/mm/slab.h index f22fb760b286..3e0a08ea4c42 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -310,7 +310,7 @@ struct kmem_cache { }; #if defined(CONFIG_SYSFS) && !defined(CONFIG_SLUB_TINY) -#define SLAB_SUPPORTS_SYSFS +#define SLAB_SUPPORTS_SYSFS 1 void sysfs_slab_unlink(struct kmem_cache *s); void sysfs_slab_release(struct kmem_cache *s); #else