From patchwork Mon Nov 11 15:55:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Christoph Lameter (Ampere)" X-Patchwork-Id: 11237267 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 522FA13BD for ; Mon, 11 Nov 2019 15:55:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 28C8E2184C for ; Mon, 11 Nov 2019 15:55:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 28C8E2184C 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 665466B0007; Mon, 11 Nov 2019 10:55:07 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 615436B0008; Mon, 11 Nov 2019 10:55:07 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 52B1E6B000A; Mon, 11 Nov 2019 10:55:07 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0135.hostedemail.com [216.40.44.135]) by kanga.kvack.org (Postfix) with ESMTP id 3F7956B0007 for ; Mon, 11 Nov 2019 10:55:07 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id DD63F180AD81F for ; Mon, 11 Nov 2019 15:55:06 +0000 (UTC) X-FDA: 76144445412.04.match60_66cacb2238649 X-Spam-Summary: 2,0,0,fd65e4f040348a54,d41d8cd98f00b204,cl@linux.com,:yuzhao@google.com:penberg@kernel.org:rientjes@google.com:iamjoonsoo.kim@lge.com:akpm@linux-foundation.org:kirill@shutemov.name:penguin-kernel@i-love.sakura.ne.jp::linux-kernel@vger.kernel.org:kirill.shutemov@linux.intel.com,RULES_HIT:41:355:379:966:968:988:989:1260:1261:1277:1313:1314:1345:1359:1437:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2194:2196:2199:2200:2393:2559:2562:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:3874:4321:4384:4385:4395:5007:6261:7875:8660:9010:10004:10400:11026:11473:11658:11914:12043:12266:12291:12296:12297:12438:12555:12679:12683:12740:12895:12986:13148:13153:13172:13228:13229:13230:13439:14093:14096:14097:14181:14659:14721:21080:21433:21451:21627:21966:30029:30054,0,RBL:3.19.106.255:@linux.com:.lbl8.mailshell.net-62.6.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fs,MSBL:0,DNSBL:neutral,Custom_ rules:0: X-HE-Tag: match60_66cacb2238649 X-Filterd-Recvd-Size: 4008 Received: from gentwo.org (gentwo.org [3.19.106.255]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Mon, 11 Nov 2019 15:55:06 +0000 (UTC) Received: by gentwo.org (Postfix, from userid 1002) id CB4C63EC1E; Mon, 11 Nov 2019 15:55:05 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by gentwo.org (Postfix) with ESMTP id CA3263EC1D; Mon, 11 Nov 2019 15:55:05 +0000 (UTC) Date: Mon, 11 Nov 2019 15:55:05 +0000 (UTC) From: Christopher Lameter X-X-Sender: cl@www.lameter.com To: Yu Zhao cc: Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , "Kirill A . Shutemov" , Tetsuo Handa , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A . Shutemov" Subject: [FIX] slub: Remove kmalloc under list_lock from list_slab_objects() V2 In-Reply-To: Message-ID: References: <20190914000743.182739-1-yuzhao@google.com> <20191108193958.205102-1-yuzhao@google.com> <20191108193958.205102-2-yuzhao@google.com> <20191109230147.GA75074@google.com> <20191110184721.GA171640@google.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 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: Regardless of the issue with memcgs allowing allocations from its kmalloc array during shutdown: This patch cleans things up and properly allocates the bitmap outside of the list_lock. [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); }