Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6357181ybx; Mon, 11 Nov 2019 07:56:53 -0800 (PST) X-Google-Smtp-Source: APXvYqwqVDC/hQpRsVio7E1DQF8QOFz9mR60syVwLzNNJmHFa8Logm2p27WLnDRTmcgepN/AlU5W X-Received: by 2002:a17:906:1f44:: with SMTP id d4mr23482997ejk.16.1573487812878; Mon, 11 Nov 2019 07:56:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573487812; cv=none; d=google.com; s=arc-20160816; b=RBtS3PoT3CwPzFi27J/Vo7e0ajj2Ysxi6SM320d4hz8vz+THop6ynco0wZI1f/czJt rUcT3LsyIktBuXCRTtuYsAsnWtbzfevrb5Al3DJbtmFZGAz2nv8YlKBUGTscICe+Zt4f 2H9eTshMbUGJiK7Q4hnoq3o+aMR/Ndr6lwjkXXxbjBAi9wDAPe7Q9lEIuaMfrPYxO9bU CK5eVr8l1abD9zP9/PAX087Nk4ITeIRg3DHKEF41+BWOxI3JS1LKBZGiqt2uf7uKdxNl 3IkWZ3zauEt1RM6YtpxttolHzPYVWmU6X79F2xKBreAWfZ5FCUhA4q0ZyYJvcbFCLL1H UbJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=PueZeYP7pbcofmR5pBeePY7imclmwo7HbysN8nUPa5c=; b=RM7mZOkcH1Tqa9sYEahK3Vcrwuiyefgm+4QnqPipZqQLQ7BvI1ocSNmZqRxrrHMYAk wVeVw55WrZBZmboJUDBfj7pJD0bL6vFgD5uFwKdI5sF8/HAZfYjGR6yMz4zY28lev1hp /IwU1urAqJ0rEalUZELf5baDLViqxrAD/G8RR4Mab3qN6csa5WZgJZjSM+3r0CMQ12Ct jMgRbFKjg+GkUpNjs3JajkWhARw4paGNJ1U6fQjZmeI4dudbqe7oDhfbl9JY/7Vs8Mtm 8JBN4AzDrrJPRonc8pEOtBhcEqp6LV7LiUzqQLe+80OMOs2Hu0lRS+QgNrRXY+X8bL8W COCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t4si12006310edc.171.2019.11.11.07.56.28; Mon, 11 Nov 2019 07:56:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727068AbfKKPzH (ORCPT + 99 others); Mon, 11 Nov 2019 10:55:07 -0500 Received: from gentwo.org ([3.19.106.255]:39218 "EHLO gentwo.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726857AbfKKPzG (ORCPT ); Mon, 11 Nov 2019 10:55:06 -0500 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 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); }