From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ig0-f176.google.com (mail-ig0-f176.google.com [209.85.213.176]) by kanga.kvack.org (Postfix) with ESMTP id 06FA86B0037 for ; Tue, 22 Jul 2014 18:58:01 -0400 (EDT) Received: by mail-ig0-f176.google.com with SMTP id hn18so4587814igb.3 for ; Tue, 22 Jul 2014 15:58:00 -0700 (PDT) Received: from mail-ie0-x229.google.com (mail-ie0-x229.google.com [2607:f8b0:4001:c03::229]) by mx.google.com with ESMTPS id bn6si1090028icb.24.2014.07.22.15.58.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 22 Jul 2014 15:58:00 -0700 (PDT) Received: by mail-ie0-f169.google.com with SMTP id rd18so281495iec.14 for ; Tue, 22 Jul 2014 15:58:00 -0700 (PDT) Date: Tue, 22 Jul 2014 15:57:58 -0700 (PDT) From: David Rientjes Subject: [patch 1/2] mm, slub: fix false-positive lockdep warning in free_partial() In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-linux-mm@kvack.org List-ID: To: Andrew Morton Cc: Vladimir Davydov , Dan Carpenter , Christoph Lameter , Joonsoo Kim , Pekka Enberg , linux-kernel@vger.kernel.org, linux-mm@kvack.org From: Vladimir Davydov Commit c65c1877bd68 ("slub: use lockdep_assert_held") requires remove_partial() to be called with n->list_lock held, but free_partial() called from kmem_cache_close() on cache destruction does not follow this rule, leading to a warning: WARNING: CPU: 0 PID: 2787 at mm/slub.c:1536 __kmem_cache_shutdown+0x1b2/0x1f0() Modules linked in: CPU: 0 PID: 2787 Comm: modprobe Tainted: G W 3.14.0-rc1-mm1+ #1 Hardware name: 0000000000000600 ffff88003ae1dde8 ffffffff816d9583 0000000000000600 0000000000000000 ffff88003ae1de28 ffffffff8107c107 0000000000000000 ffff880037ab2b00 ffff88007c240d30 ffffea0001ee5280 ffffea0001ee52a0 Call Trace: [] dump_stack+0x51/0x6e [] warn_slowpath_common+0x87/0xb0 [] warn_slowpath_null+0x15/0x20 [] __kmem_cache_shutdown+0x1b2/0x1f0 [] kmem_cache_destroy+0x43/0xf0 [] xfs_destroy_zones+0x103/0x110 [xfs] [] exit_xfs_fs+0x38/0x4e4 [xfs] [] SyS_delete_module+0x19a/0x1f0 [] ? retint_swapgs+0x13/0x1b [] ? trace_hardirqs_on_caller+0x105/0x1d0 [] ? trace_hardirqs_on_thunk+0x3a/0x3f [] system_call_fastpath+0x16/0x1b Although this cannot actually result in a race, because on cache destruction there should not be any concurrent frees or allocations from the cache, let's add spin_lock/unlock to free_partial() just to keep lockdep happy. Acked-by: Christoph Lameter Signed-off-by: Vladimir Davydov Signed-off-by: Pekka Enberg Signed-off-by: David Rientjes --- mm/slub.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/slub.c b/mm/slub.c --- a/mm/slub.c +++ b/mm/slub.c @@ -3195,12 +3195,13 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page, /* * Attempt to free all partial slabs on a node. * This is called from kmem_cache_close(). We must be the last thread - * using the cache and therefore we do not need to lock anymore. + * using the cache, but we still have to lock for lockdep's sake. */ static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n) { struct page *page, *h; + spin_lock_irq(&n->list_lock); list_for_each_entry_safe(page, h, &n->partial, lru) { if (!page->inuse) { __remove_partial(n, page); @@ -3210,6 +3211,7 @@ static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n) "Objects remaining in %s on kmem_cache_close()"); } } + spin_unlock_irq(&n->list_lock); } /* -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org