From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD850C35247 for ; Mon, 3 Feb 2020 17:25:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7123E2051A for ; Mon, 3 Feb 2020 17:25:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7123E2051A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1A2F46B0679; Mon, 3 Feb 2020 12:25:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 12C866B0681; Mon, 3 Feb 2020 12:25:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01A956B068E; Mon, 3 Feb 2020 12:25:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0250.hostedemail.com [216.40.44.250]) by kanga.kvack.org (Postfix) with ESMTP id D98056B0679 for ; Mon, 3 Feb 2020 12:25:03 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 853C4180AD804 for ; Mon, 3 Feb 2020 17:25:03 +0000 (UTC) X-FDA: 76449491286.15.veil29_6655af2439002 X-HE-Tag: veil29_6655af2439002 X-Filterd-Recvd-Size: 3787 Received: from gentwo.org (gentwo.org [3.19.106.255]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Mon, 3 Feb 2020 17:25:03 +0000 (UTC) Received: by gentwo.org (Postfix, from userid 1002) id 8E4CB3F244; Mon, 3 Feb 2020 17:25:02 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by gentwo.org (Postfix) with ESMTP id 8BDBD3ED62; Mon, 3 Feb 2020 17:25:02 +0000 (UTC) Date: Mon, 3 Feb 2020 17:25:02 +0000 (UTC) From: Christopher Lameter X-X-Sender: cl@www.lameter.com To: Andrew Morton cc: iamjoonsoo.kim@lge.com, kirill.shutemov@linux.intel.com, linux-mm@kvack.org, mm-commits@vger.kernel.org, penberg@kernel.org, penguin-kernel@i-love.sakura.ne.jp, rientjes@google.com, torvalds@linux-foundation.org, yuzhao@google.com Subject: Re: [patch 018/118] mm/slub.c: avoid slub allocation while holding list_lock In-Reply-To: <20200131061157.f3GPdvwZv%akpm@linux-foundation.org> Message-ID: References: <20200131061157.f3GPdvwZv%akpm@linux-foundation.org> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII 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: On Thu, 30 Jan 2020, Andrew Morton wrote: > From: Yu Zhao > Subject: mm/slub.c: avoid slub allocation while holding list_lock > > If we are already under list_lock, don't call kmalloc(). Otherwise we > will run into a deadlock because kmalloc() also tries to grab the same > lock. I provided another patch that moves the lock. Remember we agreed that this here is a ugly hack. [FIX] slub: Remove kmalloc under list_lock from list_slab_objects() V2 V1->V2 : Properly handle CONFIG_SLUB_DEBUG. Handle bitmap free correctly. list_slab_objects() is called when a slab is destroyed and there are objects still left to list the objects in the syslog. This is a pretty rare event. And there it seems we take the list_lock and call kmalloc while holding that lock. Perform the allocation in free_partial() before the list_lock is taken. Fixes: bbd7d57bfe852d9788bae5fb171c7edb4021d8ac ("slub: Potential stack overflow") Signed-off-by: Christoph Lameter Index: linux/mm/slub.c =================================================================== --- linux.orig/mm/slub.c 2019-10-15 13:54:57.032655296 +0000 +++ linux/mm/slub.c 2019-11-11 15:52:11.616397853 +0000 @@ -3690,14 +3690,15 @@ error: } static void list_slab_objects(struct kmem_cache *s, struct page *page, - const char *text) + const char *text, unsigned long *map) { #ifdef CONFIG_SLUB_DEBUG void *addr = page_address(page); void *p; - unsigned long *map = bitmap_zalloc(page->objects, GFP_ATOMIC); + if (!map) return; + slab_err(s, page, text, s->name); slab_lock(page); @@ -3710,7 +3711,6 @@ static void list_slab_objects(struct kme } } slab_unlock(page); - bitmap_free(map); #endif } @@ -3723,6 +3723,11 @@ static void free_partial(struct kmem_cac { LIST_HEAD(discard); struct page *page, *h; + unsigned long *map = NULL; + +#ifdef CONFIG_SLUB_DEBUG + map = bitmap_alloc(oo_objects(s->max), GFP_KERNEL); +#endif BUG_ON(irqs_disabled()); spin_lock_irq(&n->list_lock); @@ -3732,11 +3737,16 @@ static void free_partial(struct kmem_cac list_add(&page->slab_list, &discard); } else { list_slab_objects(s, page, - "Objects remaining in %s on __kmem_cache_shutdown()"); + "Objects remaining in %s on __kmem_cache_shutdown()", + map); } } spin_unlock_irq(&n->list_lock); +#ifdef CONFIG_SLUB_DEBUG + bitmap_free(map); +#endif + list_for_each_entry_safe(page, h, &discard, slab_list) discard_slab(s, page); }