From patchwork Thu Apr 13 14:34:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiongwei Song X-Patchwork-Id: 13210362 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA8EBC77B61 for ; Thu, 13 Apr 2023 14:42:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230324AbjDMOmv (ORCPT ); Thu, 13 Apr 2023 10:42:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229571AbjDMOmu (ORCPT ); Thu, 13 Apr 2023 10:42:50 -0400 Received: from pv50p00im-ztdg10011301.me.com (pv50p00im-ztdg10011301.me.com [17.58.6.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D94AF4EFD for ; Thu, 13 Apr 2023 07:42:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1681396536; bh=rfau5OufM0BiNWhby4onOK71jyUiBVhrPZSigYK+sks=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=OxAmEuHTfbSVCKdAfkQv02ZaI1VeZo+oqjWjiC0NDnzKYZ3QYcB9qQyCqVjceU2ns rxhuI69vMigg8bi+XZKz1aHRqvd2Fh79cHKvc0lQ77ndsMQ05s7rXerNHiGe+prOm1 gOsnVWdqjcuh0XBYfv+WIC50Ias0u2u6N7+9OgmvK90VpGloW7Ibfedr8mrjBZ6jDz AowZ4/ypEnQjcdRWoM2TE4resLxelcNFFJZl/CWzbHUKZRTSPNDZ9ODt+1/nfQv6xg 6hLraqC7BpImr5CalHFlNHbXvDZAuL1MHtuYMiiJly2ZfZGeuwTLB36ChB3fqlHhkG RAmlX0Fi5l1hQ== Received: from xiongwei.. (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztdg10011301.me.com (Postfix) with ESMTPSA id 540711805A0; Thu, 13 Apr 2023 14:35:30 +0000 (UTC) From: sxwjean@me.com 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, keescook@chromium.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Xiongwei Song Subject: [PATCH 1/5] slub: Correct the error code when slab_kset is NULL Date: Thu, 13 Apr 2023 22:34:48 +0800 Message-Id: <20230413143452.211250-2-sxwjean@me.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230413143452.211250-1-sxwjean@me.com> References: <20230413143452.211250-1-sxwjean@me.com> MIME-Version: 1.0 X-Proofpoint-GUID: 51lpZUJemfRvfvuXf7GNT1NeHV8UTyvG X-Proofpoint-ORIG-GUID: 51lpZUJemfRvfvuXf7GNT1NeHV8UTyvG X-Proofpoint-Virus-Version: =?utf-8?q?vendor=3Dfsecure_engine=3D1=2E1=2E170-?= =?utf-8?q?22c6f66c430a71ce266a39bfe25bc2903e8d5c8f=3A6=2E0=2E517=2C18=2E0?= =?utf-8?q?=2E883=2C17=2E0=2E605=2E474=2E0000000_definitions=3D2022-06-21=5F?= =?utf-8?q?08=3A2022-06-21=5F01=2C2022-06-21=5F08=2C2020-01-23=5F02_signatur?= =?utf-8?q?es=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 clxscore=1015 bulkscore=0 malwarescore=0 adultscore=0 suspectscore=0 mlxlogscore=989 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2304130130 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: Xiongwei Song The -ENOSYS is inproper when kset_create_and_add call returns a NULL pointer, the failure more likely is because lacking memory, hence returning -ENOMEM is better. Signed-off-by: Xiongwei Song --- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/slub.c b/mm/slub.c index 28ca576d988d..5cc56f780241 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -6225,7 +6225,7 @@ static int __init slab_sysfs_init(void) if (!slab_kset) { mutex_unlock(&slab_mutex); pr_err("Cannot register slab subsystem.\n"); - return -ENOSYS; + return -ENOMEM; } slab_state = FULL; From patchwork Thu Apr 13 14:34:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiongwei Song X-Patchwork-Id: 13210366 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D2BCC77B6E for ; Thu, 13 Apr 2023 14:43:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230352AbjDMOmy (ORCPT ); Thu, 13 Apr 2023 10:42:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230360AbjDMOmw (ORCPT ); Thu, 13 Apr 2023 10:42:52 -0400 Received: from pv50p00im-ztdg10011301.me.com (pv50p00im-ztdg10011301.me.com [17.58.6.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74A9A4EFD for ; Thu, 13 Apr 2023 07:42:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1681396543; bh=8jRYHdyOLx4stczwHdVkraZpDl6WNFY1n6xs2s88Ih4=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=XcKoR5cL/+upnaXqW5vEFVtkOztLb/OPL22EeKcuRy5aCKbMwJbI0lmkNMOd97cF8 U4nWgm3EJLu3+KVDvf2gpegVHJId7BREhcCxvx0qgyQyLCBDTjraGch7/Mh+sNnUpG 92/s8k/7x+2YqeGtk54ynj7p2UiHQ7d14zQlskNXll1HQ2Y1ksAoVjU0kHOYzrYiPh O4AJHBWOs1x1gkwS9kM8kB0zDEJDbBt+ipH34112Kl8ECnMt0m7FFOWkdnvWUFNQsi BPcQeMwhwXLQhEceqI+c8OpkxVYB4WBRjjstjTcPZrynKlB+GOgOZrkIwuBvUOfAV7 O7Z4mjnAAXeZQ== Received: from xiongwei.. (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztdg10011301.me.com (Postfix) with ESMTPSA id 95D4518043E; Thu, 13 Apr 2023 14:35:37 +0000 (UTC) From: sxwjean@me.com 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, keescook@chromium.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Xiongwei Song Subject: [PATCH 2/5] slub: Put objects_show() into CONFIG_SLUB_DEBUG enabled block Date: Thu, 13 Apr 2023 22:34:49 +0800 Message-Id: <20230413143452.211250-3-sxwjean@me.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230413143452.211250-1-sxwjean@me.com> References: <20230413143452.211250-1-sxwjean@me.com> MIME-Version: 1.0 X-Proofpoint-GUID: QqH1Ghpj5ydBr4pmMZw4eIZhmrwWvj9d X-Proofpoint-ORIG-GUID: QqH1Ghpj5ydBr4pmMZw4eIZhmrwWvj9d X-Proofpoint-Virus-Version: =?utf-8?q?vendor=3Dfsecure_engine=3D1=2E1=2E170-?= =?utf-8?q?22c6f66c430a71ce266a39bfe25bc2903e8d5c8f=3A6=2E0=2E517=2C18=2E0?= =?utf-8?q?=2E883=2C17=2E0=2E605=2E474=2E0000000_definitions=3D2022-06-21=5F?= =?utf-8?q?08=3A2022-06-21=5F01=2C2022-06-21=5F08=2C2020-01-23=5F02_signatur?= =?utf-8?q?es=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 clxscore=1015 bulkscore=0 malwarescore=0 adultscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2304130130 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: Xiongwei Song The SO_ALL|SO_OBJECTS pair is only used when enabling CONFIG_SLUB_DEBUG option, so the objects_show() definition should be surrounded by CONFIG_SLUB_DEBUG too. Signed-off-by: Xiongwei Song --- mm/slub.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 5cc56f780241..b8afe12ebba1 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5613,12 +5613,6 @@ static ssize_t cpu_slabs_show(struct kmem_cache *s, char *buf) } SLAB_ATTR_RO(cpu_slabs); -static ssize_t objects_show(struct kmem_cache *s, char *buf) -{ - return show_slab_objects(s, buf, SO_ALL|SO_OBJECTS); -} -SLAB_ATTR_RO(objects); - static ssize_t objects_partial_show(struct kmem_cache *s, char *buf) { return show_slab_objects(s, buf, SO_PARTIAL|SO_OBJECTS); @@ -5713,6 +5707,12 @@ static ssize_t total_objects_show(struct kmem_cache *s, char *buf) } SLAB_ATTR_RO(total_objects); +static ssize_t objects_show(struct kmem_cache *s, char *buf) +{ + return show_slab_objects(s, buf, SO_ALL|SO_OBJECTS); +} +SLAB_ATTR_RO(objects); + static ssize_t sanity_checks_show(struct kmem_cache *s, char *buf) { return sysfs_emit(buf, "%d\n", !!(s->flags & SLAB_CONSISTENCY_CHECKS)); From patchwork Thu Apr 13 14:34:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiongwei Song X-Patchwork-Id: 13210367 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F245C77B71 for ; Thu, 13 Apr 2023 14:43:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230254AbjDMOmy (ORCPT ); Thu, 13 Apr 2023 10:42:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230352AbjDMOmw (ORCPT ); Thu, 13 Apr 2023 10:42:52 -0400 Received: from pv50p00im-ztdg10011301.me.com (pv50p00im-ztdg10011301.me.com [17.58.6.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9798558B for ; Thu, 13 Apr 2023 07:42:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1681396550; bh=JAgRIwnVPHjbTYshg0Cq1C5avnVLUoxXJ3pl2kvDPSY=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=xO/T7yXeroPIvZvyiZbh8x1/X/oIWsBNuf3i2Jxqpee4hQabZaqIUSllys6W3vKOm fhBd5rqPfi0VHzmUG9xcCqs8YguaGRJxQfSBNX2RKZgR3Tlwc58xclavJ+aEuMUzDp e+MMrxFCGJH3sSBXM1INcprrw70wNtK4REsFYbv98wbX7EM8cHX+lQQUUVBqFY7Dq6 /ezTu0fwfSbI+qIgj5EbOxPknN9Z23QwKU4ckcDnydsfIrNH1Ov3I9Qa1QnevgbUFT /Y/EKM+m8TSExEgq4Ox2jjM0CBZTPFZL/jgPmrlbTSuScAJTlidSuIG7euqikTjLSx IuTLBj7bt7/LA== Received: from xiongwei.. (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztdg10011301.me.com (Postfix) with ESMTPSA id BE746180985; Thu, 13 Apr 2023 14:35:43 +0000 (UTC) From: sxwjean@me.com 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, keescook@chromium.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Xiongwei Song Subject: [PATCH 3/5] slub: Remove CONFIG_SMP defined check Date: Thu, 13 Apr 2023 22:34:50 +0800 Message-Id: <20230413143452.211250-4-sxwjean@me.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230413143452.211250-1-sxwjean@me.com> References: <20230413143452.211250-1-sxwjean@me.com> MIME-Version: 1.0 X-Proofpoint-GUID: Y1U1vCSTKtKD3BAtj30KeORsRiE5ZfNE X-Proofpoint-ORIG-GUID: Y1U1vCSTKtKD3BAtj30KeORsRiE5ZfNE X-Proofpoint-Virus-Version: =?utf-8?q?vendor=3Dfsecure_engine=3D1=2E1=2E170-?= =?utf-8?q?22c6f66c430a71ce266a39bfe25bc2903e8d5c8f=3A6=2E0=2E517=2C18=2E0?= =?utf-8?q?=2E883=2C17=2E0=2E605=2E474=2E0000000_definitions=3D2022-06-21=5F?= =?utf-8?q?08=3A2022-06-21=5F01=2C2022-06-21=5F08=2C2020-01-23=5F02_signatur?= =?utf-8?q?es=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 clxscore=1015 bulkscore=0 malwarescore=0 adultscore=0 suspectscore=0 mlxlogscore=980 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2304130130 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: Xiongwei Song As CONFIG_SMP is one of dependencies of CONFIG_SLUB_CPU_PARTIAL, so if CONFIG_SLUB_CPU_PARTIAL is defined then CONFIG_SMP must be defined, no need to check CONFIG_SMP definition here. Signed-off-by: Xiongwei Song --- mm/slub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/slub.c b/mm/slub.c index b8afe12ebba1..d897df8fe7e7 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5641,7 +5641,7 @@ static ssize_t slabs_cpu_partial_show(struct kmem_cache *s, char *buf) objects = (slabs * oo_objects(s->oo)) / 2; len += sysfs_emit_at(buf, len, "%d(%d)", objects, slabs); -#if defined(CONFIG_SLUB_CPU_PARTIAL) && defined(CONFIG_SMP) +#ifdef CONFIG_SLUB_CPU_PARTIAL for_each_online_cpu(cpu) { struct slab *slab; From patchwork Thu Apr 13 14:34:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiongwei Song X-Patchwork-Id: 13210363 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37E11C77B71 for ; Thu, 13 Apr 2023 14:42:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230362AbjDMOmw (ORCPT ); Thu, 13 Apr 2023 10:42:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230281AbjDMOmv (ORCPT ); Thu, 13 Apr 2023 10:42:51 -0400 Received: from pv50p00im-ztdg10011301.me.com (pv50p00im-ztdg10011301.me.com [17.58.6.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9B349EE0 for ; Thu, 13 Apr 2023 07:42:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1681396556; bh=X9rNsbyg8P2zc9bEIgObTak89L4pwM16nNASnZu43Cs=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=WOd2wAMW+qWyWk2cozpwKyj07x00lw52yUR5HaZdPGBbmkRAsTWGwqtV4xojlHTRU lrn2hlJ0NoQXTg/RXGrmpXYosF0+ezrHGt6IvOMYzpxxh0gWREg8Exc5Ll4cgJ6QpN WFuOLwbBjXRATVVksmR+4UgxmIFNurKRNZax42wcu13DClam0KAovkAc4dbIb7KIil 5evduAa7H3S4EyyGES25mPnXNjuR+FY6LJ8ALnPYP7zkmHkoswxvMea3Ln8HZsqRad WKV4ZpV7JX8ZnLUOwJg1kHzSuSNFoUeuPsyIi1ziiNT7RjrJR6CrMg+Fhcrcay2kYH V94yuCgc8bh/A== Received: from xiongwei.. (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztdg10011301.me.com (Postfix) with ESMTPSA id 2010B18065F; Thu, 13 Apr 2023 14:35:50 +0000 (UTC) From: sxwjean@me.com 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, keescook@chromium.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Xiongwei Song Subject: [PATCH 4/5] slub: Remove slabs_node() function Date: Thu, 13 Apr 2023 22:34:51 +0800 Message-Id: <20230413143452.211250-5-sxwjean@me.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230413143452.211250-1-sxwjean@me.com> References: <20230413143452.211250-1-sxwjean@me.com> MIME-Version: 1.0 X-Proofpoint-GUID: kXvLyGF-H8usFLhMixCBzmU7tdwWLDs3 X-Proofpoint-ORIG-GUID: kXvLyGF-H8usFLhMixCBzmU7tdwWLDs3 X-Proofpoint-Virus-Version: =?utf-8?q?vendor=3Dfsecure_engine=3D1=2E1=2E170-?= =?utf-8?q?22c6f66c430a71ce266a39bfe25bc2903e8d5c8f=3A6=2E0=2E517=2C18=2E0?= =?utf-8?q?=2E883=2C17=2E0=2E605=2E474=2E0000000_definitions=3D2022-06-21=5F?= =?utf-8?q?08=3A2022-06-21=5F01=2C2022-06-21=5F08=2C2020-01-23=5F02_signatur?= =?utf-8?q?es=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 clxscore=1015 bulkscore=0 malwarescore=0 adultscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2304130130 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: Xiongwei Song When traversing nodes one by one, the get_node() function called in for_each_kmem_cache_node macro, no need to call get_node() again in slabs_node(), just reading nr_slabs field should be enough. However, the node_nr_slabs() function can do this. Hence, the slabs_node() function is not needed anymore. Signed-off-by: Xiongwei Song --- mm/slub.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index d897df8fe7e7..33b4fec6bc7a 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1344,14 +1344,6 @@ static void remove_full(struct kmem_cache *s, struct kmem_cache_node *n, struct list_del(&slab->slab_list); } -/* Tracking of the number of slabs for debugging purposes */ -static inline unsigned long slabs_node(struct kmem_cache *s, int node) -{ - struct kmem_cache_node *n = get_node(s, node); - - return atomic_long_read(&n->nr_slabs); -} - static inline unsigned long node_nr_slabs(struct kmem_cache_node *n) { return atomic_long_read(&n->nr_slabs); @@ -1722,8 +1714,6 @@ slab_flags_t kmem_cache_flags(unsigned int object_size, #define disable_higher_order_debug 0 -static inline unsigned long slabs_node(struct kmem_cache *s, int node) - { return 0; } static inline unsigned long node_nr_slabs(struct kmem_cache_node *n) { return 0; } static inline void inc_slabs_node(struct kmem_cache *s, int node, @@ -4599,7 +4589,7 @@ bool __kmem_cache_empty(struct kmem_cache *s) struct kmem_cache_node *n; for_each_kmem_cache_node(s, node, n) - if (n->nr_partial || slabs_node(s, node)) + if (n->nr_partial || node_nr_slabs(n)) return false; return true; } @@ -4616,7 +4606,7 @@ int __kmem_cache_shutdown(struct kmem_cache *s) /* Attempt to free all objects */ for_each_kmem_cache_node(s, node, n) { free_partial(s, n); - if (n->nr_partial || slabs_node(s, node)) + if (n->nr_partial || node_nr_slabs(n)) return 1; } return 0; @@ -4829,7 +4819,7 @@ static int __kmem_cache_do_shrink(struct kmem_cache *s) list_for_each_entry_safe(slab, t, &discard, slab_list) free_slab(s, slab); - if (slabs_node(s, node)) + if (node_nr_slabs(n)) ret = 1; } From patchwork Thu Apr 13 14:34:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiongwei Song X-Patchwork-Id: 13210364 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 568E6C77B73 for ; Thu, 13 Apr 2023 14:42:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230287AbjDMOmx (ORCPT ); Thu, 13 Apr 2023 10:42:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230322AbjDMOmv (ORCPT ); Thu, 13 Apr 2023 10:42:51 -0400 X-Greylist: delayed 439 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 13 Apr 2023 07:42:49 PDT Received: from pv50p00im-ztdg10011301.me.com (pv50p00im-ztdg10011301.me.com [17.58.6.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D93034C3C for ; Thu, 13 Apr 2023 07:42:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1681396563; bh=MbAmcnG2CXhNY1EHnQtPRAGFD2rG2vh6+CqnhkUIkDg=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=JvOgqw6hQO6n706BQdyO1B5LykXqDdOsxC0Bat5AR7nSJZ3p1SJ3qIl3wSiTXSFyO wVvA9qtPK016jKajDu3n+P0tiMWM4FMq28xZnd7xUYbY/MPwODpTNsD7xkcEblz6Et QrfwEr+Zf5Tv3QDroo6WkXUc2MqwJ9yYBfeltVVuofA1zyEk+trEPIDlD20sMFsc85 AQr3Gqz4B7MNDCJ6Ei4lch97oAxilcSTnaezMb9H7+j6jJXRdeUUbIn1geZQpfs9sS ul0O/SS2Xizt0f0davmFhyeq88cIzma7kCuo0S8OQaGOjCHbSQJMWN7k/80Na58tgj XJl+AQFv11KZw== Received: from xiongwei.. (pv50p00im-dlb-asmtp-mailmevip.me.com [17.56.9.10]) by pv50p00im-ztdg10011301.me.com (Postfix) with ESMTPSA id A6CC818099F; Thu, 13 Apr 2023 14:35:56 +0000 (UTC) From: sxwjean@me.com 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, keescook@chromium.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Xiongwei Song Subject: [PATCH 5/5] slub: Don't read nr_slabs and total_objects directly Date: Thu, 13 Apr 2023 22:34:52 +0800 Message-Id: <20230413143452.211250-6-sxwjean@me.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230413143452.211250-1-sxwjean@me.com> References: <20230413143452.211250-1-sxwjean@me.com> MIME-Version: 1.0 X-Proofpoint-GUID: nAzode42SKfbD2lWdSEdjskVbXveXf7e X-Proofpoint-ORIG-GUID: nAzode42SKfbD2lWdSEdjskVbXveXf7e X-Proofpoint-Virus-Version: =?utf-8?q?vendor=3Dfsecure_engine=3D1=2E1=2E170-?= =?utf-8?q?22c6f66c430a71ce266a39bfe25bc2903e8d5c8f=3A6=2E0=2E517=2C18=2E0?= =?utf-8?q?=2E883=2C17=2E0=2E605=2E474=2E0000000_definitions=3D2022-06-21=5F?= =?utf-8?q?08=3A2022-06-21=5F01=2C2022-06-21=5F08=2C2020-01-23=5F02_signatur?= =?utf-8?q?es=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 clxscore=1015 bulkscore=0 malwarescore=0 adultscore=0 suspectscore=0 mlxlogscore=683 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2304130130 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: Xiongwei Song We have node_nr_slabs() to read nr_slabs, node_nr_objs() to read total_objects in a kmem_cache_node, so no need to access the two members directly. Signed-off-by: Xiongwei Song --- mm/slub.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index 33b4fec6bc7a..2c3af399d9d6 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5157,9 +5157,9 @@ static int validate_slab_node(struct kmem_cache *s, validate_slab(s, slab, obj_map); count++; } - if (count != atomic_long_read(&n->nr_slabs)) { + if (count != node_nr_slabs(n)) { pr_err("SLUB: %s %ld slabs counted but counter=%ld\n", - s->name, count, atomic_long_read(&n->nr_slabs)); + s->name, count, node_nr_slabs(n)); slab_add_kunit_errors(); } @@ -5443,12 +5443,11 @@ static ssize_t show_slab_objects(struct kmem_cache *s, for_each_kmem_cache_node(s, node, n) { if (flags & SO_TOTAL) - x = atomic_long_read(&n->total_objects); + x = node_nr_objs(n); else if (flags & SO_OBJECTS) - x = atomic_long_read(&n->total_objects) - - count_partial(n, count_free); + x = node_nr_objs(n) - count_partial(n, count_free); else - x = atomic_long_read(&n->nr_slabs); + x = node_nr_slabs(n); total += x; nodes[node] += x; } @@ -6387,7 +6386,7 @@ static int slab_debug_trace_open(struct inode *inode, struct file *filep) unsigned long flags; struct slab *slab; - if (!atomic_long_read(&n->nr_slabs)) + if (!node_nr_slabs(n)) continue; spin_lock_irqsave(&n->list_lock, flags);