From patchwork Sat Nov 11 02:03:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miles Chen X-Patchwork-Id: 10054145 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 818F660637 for ; Sat, 11 Nov 2017 02:09:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F3FF2B5E2 for ; Sat, 11 Nov 2017 02:09:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 42B702B5E1; Sat, 11 Nov 2017 02:09:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 75FDE2B5E1 for ; Sat, 11 Nov 2017 02:09:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=OkcfG7hRUK5txPPOGHYAtUt0W8kL3mY0vg6XWZISmB8=; b=U90y/GIdjZWUoB P8jbRVB1gJAmvf6wNcBWGsirtLcWTdlVeHEDBvNzhxBQAO2v/0sNMdMBexOL9kyDabPwuXe2nAPWF lQBbxiTTNTwQ0tenlnDnBWz8va3qeO815Mp2qSmd6PtcK1Wm0lWVbS7pkS6SiIXxI5B1ld3cz7Ip1 3Tdl6GQbF6VXe1R1cZ4YAlCDr4NTbAKjiLHWyqlnsGXX7G/F6H99uFIjL5mHR0QHdYfpjj7fpKZJc vPzJbs0RRXSrDsNupwzPZ2/NSSyDDJk+IZDDuK1KaODc1C4hUBX9V3Axj2SD8HnBlZ1SM4p3Trr+0 xp3IllKaXgQObpLkeM+g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eDLES-0002Je-Mf; Sat, 11 Nov 2017 02:09:16 +0000 Received: from [210.61.82.184] (helo=mailgw02.mediatek.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eDLEN-0002Cu-47 for linux-mediatek@lists.infradead.org; Sat, 11 Nov 2017 02:09:14 +0000 X-UUID: 4fac8c421eb64c8596badb8492526384-20171111 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1486744139; Sat, 11 Nov 2017 10:03:27 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Sat, 11 Nov 2017 10:03:26 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Sat, 11 Nov 2017 10:03:26 +0800 From: To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton Subject: [PATCHv2] slub: Fix sysfs duplicate filename creation when slub_debug=O Date: Sat, 11 Nov 2017 10:03:25 +0800 Message-ID: <1510365805-5155-1-git-send-email-miles.chen@mediatek.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171110_180911_563086_730A08E0 X-CRM114-Status: GOOD ( 12.78 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mm@kvack.org, Miles Chen , linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, wsd_upstream@mediatek.com Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Miles Chen When slub_debug=O is set. It is possible to clear debug flags for an "unmergeable" slab cache in kmem_cache_open(). It makes the "unmergeable" cache became "mergeable" in sysfs_slab_add(). These caches will generate their "unique IDs" by create_unique_id(), but it is possible to create identical unique IDs. In my experiment, sgpool-128, names_cache, biovec-256 generate the same ID ":Ft-0004096" and the kernel reports "sysfs: cannot create duplicate filename '/kernel/slab/:Ft-0004096'". To repeat my experiment, set disable_higher_order_debug=1, CONFIG_SLUB_DEBUG_ON=y in kernel-4.14. Fix this issue by setting unmergeable=1 if slub_debug=O and the the default slub_debug contains any no-merge flags. call path: kmem_cache_create() __kmem_cache_alias() -> we set SLAB_NEVER_MERGE flags here create_cache() __kmem_cache_create() kmem_cache_open() -> clear DEBUG_METADATA_FLAGS sysfs_slab_add() -> the slab cache is mergeable now [ 0.674272] sysfs: cannot create duplicate filename '/kernel/slab/:Ft-0004096' [ 0.674473] ------------[ cut here ]------------ [ 0.674653] WARNING: CPU: 0 PID: 1 at fs/sysfs/dir.c:31 sysfs_warn_dup+0x60/0x7c [ 0.674847] Modules linked in: [ 0.674969] CPU: 0 PID: 1 Comm: swapper/0 Tainted: G W 4.14.0-rc7ajb-00131-gd4c2e9f-dirty #123 [ 0.675211] Hardware name: linux,dummy-virt (DT) [ 0.675342] task: ffffffc07d4e0080 task.stack: ffffff8008008000 [ 0.675505] PC is at sysfs_warn_dup+0x60/0x7c [ 0.675633] LR is at sysfs_warn_dup+0x60/0x7c [ 0.675759] pc : [] lr : [] pstate: 60000145 [ 0.675948] sp : ffffff800800bb40 [ 0.676048] x29: ffffff800800bb40 x28: 0000000000000040 [ 0.676209] x27: ffffffc07c52a380 x26: 0000000000000000 [ 0.676369] x25: ffffff8008af4ad0 x24: ffffff8008af4000 [ 0.676528] x23: ffffffc07c532580 x22: ffffffc07cf04598 [ 0.676695] x21: ffffffc07cf26578 x20: ffffffc07c533700 [ 0.676857] x19: ffffffc07ce67000 x18: 0000000000000002 [ 0.677017] x17: 0000000000007ffe x16: 0000000000000007 [ 0.677176] x15: 0000000000000001 x14: 0000000000007fff [ 0.677335] x13: 0000000000000394 x12: 0000000000000000 [ 0.677492] x11: 00000000000001ab x10: 0000000000000007 [ 0.677651] x9 : 00000000000001ac x8 : ffffff800835d114 [ 0.677809] x7 : 656b2f2720656d61 x6 : 0000000000000017 [ 0.677967] x5 : ffffffc07ffdb9a8 x4 : 0000000000000000 [ 0.678124] x3 : 0000000000000000 x2 : ffffffffffffffff [ 0.678282] x1 : ffffff8008a4e878 x0 : 0000000000000042 [ 0.678442] Call trace: [ 0.678528] Exception stack(0xffffff800800ba00 to 0xffffff800800bb40) [ 0.678706] ba00: 0000000000000042 ffffff8008a4e878 ffffffffffffffff 0000000000000000 [ 0.678914] ba20: 0000000000000000 ffffffc07ffdb9a8 0000000000000017 656b2f2720656d61 [ 0.679121] ba40: ffffff800835d114 00000000000001ac 0000000000000007 00000000000001ab [ 0.679326] ba60: 0000000000000000 0000000000000394 0000000000007fff 0000000000000001 [ 0.679532] ba80: 0000000000000007 0000000000007ffe 0000000000000002 ffffffc07ce67000 [ 0.679739] baa0: ffffffc07c533700 ffffffc07cf26578 ffffffc07cf04598 ffffffc07c532580 [ 0.679944] bac0: ffffff8008af4000 ffffff8008af4ad0 0000000000000000 ffffffc07c52a380 [ 0.680149] bae0: 0000000000000040 ffffff800800bb40 ffffff8008235808 ffffff800800bb40 [ 0.680354] bb00: ffffff8008235808 0000000060000145 ffffffc07c533700 0000000062616c73 [ 0.680560] bb20: ffffffffffffffff 0000000000000000 ffffff800800bb40 ffffff8008235808 [ 0.680774] [] sysfs_warn_dup+0x60/0x7c [ 0.680928] [] sysfs_create_dir_ns+0x98/0xa0 [ 0.681095] [] kobject_add_internal+0xa0/0x294 [ 0.681267] [] kobject_init_and_add+0x90/0xb4 [ 0.681435] [] sysfs_slab_add+0x90/0x200 [ 0.681592] [] __kmem_cache_create+0x26c/0x438 [ 0.681769] [] kmem_cache_create+0x164/0x1f4 [ 0.681940] [] sg_pool_init+0x60/0x100 [ 0.682094] [] do_one_initcall+0x38/0x12c [ 0.682254] [] kernel_init_freeable+0x138/0x1d4 [ 0.682423] [] kernel_init+0x10/0xfc [ 0.682571] [] ret_from_fork+0x10/0x18 Signed-off-by: Miles Chen --- mm/slub.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/slub.c b/mm/slub.c index 1efbb812..8e1c027 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5704,6 +5704,10 @@ static int sysfs_slab_add(struct kmem_cache *s) return 0; } + if (!unmergeable && disable_higher_order_debug && + (slub_debug & DEBUG_METADATA_FLAGS)) + unmergeable = 1; + if (unmergeable) { /* * Slabcache can never be merged so we can use the name proper.