From patchwork Thu Jun 18 09:46:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 11611695 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 85B0213A0 for ; Thu, 18 Jun 2020 09:46:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5C77321D7E for ; Thu, 18 Jun 2020 09:46:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5C77321D7E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linutronix.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 735138D0009; Thu, 18 Jun 2020 05:46:28 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6E5818D0001; Thu, 18 Jun 2020 05:46:28 -0400 (EDT) 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 5FB7B8D0009; Thu, 18 Jun 2020 05:46:28 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0024.hostedemail.com [216.40.44.24]) by kanga.kvack.org (Postfix) with ESMTP id 43C398D0001 for ; Thu, 18 Jun 2020 05:46:28 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id CC154138E5 for ; Thu, 18 Jun 2020 09:46:27 +0000 (UTC) X-FDA: 76941852414.22.roof40_3a060c826e0f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id A185618038E60 for ; Thu, 18 Jun 2020 09:46:27 +0000 (UTC) X-Spam-Summary: 2,0,0,fadb3e1ac4d99ef1,d41d8cd98f00b204,bigeasy@linutronix.de,,RULES_HIT:41:152:355:379:966:968:973:988:989:1260:1277:1311:1312:1313:1314:1345:1437:1513:1515:1516:1518:1519:1521:1534:1543:1593:1594:1595:1596:1711:1730:1747:1777:1792:1801:2194:2196:2199:2200:2393:2559:2562:2689:3138:3139:3140:3141:3142:3355:3865:3866:3867:3868:3870:3871:3872:4184:4321:4384:4385:4395:4605:5007:6261:7875:7904:9592:10004:10400:10473:11026:11473:11658:11914:12043:12160:12296:12297:12438:12555:12663:12679:12986:13071:13895:14096:14097:14180:14721:19900:21060:21067:21080:21433:21451:21627:21939:21966:21990:30029:30054:30070:30075,0,RBL:193.142.43.55:@linutronix.de:.lbl8.mailshell.net-64.201.201.201 62.14.6.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: roof40_3a060c826e0f X-Filterd-Recvd-Size: 4784 Received: from Galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf42.hostedemail.com (Postfix) with ESMTP for ; Thu, 18 Jun 2020 09:46:27 +0000 (UTC) Received: from bigeasy by Galois.linutronix.de with local (Exim 4.80) (envelope-from ) id 1jlr7n-0005K3-4D; Thu, 18 Jun 2020 11:46:23 +0200 Date: Thu, 18 Jun 2020 11:46:23 +0200 From: Sebastian Andrzej Siewior To: linux-mm@kvack.org Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Thomas Gleixner Subject: [RFC] SLUB: list_slab_objects() looks like a miss-merge Message-ID: <20200618094623.ef7wrsyrnrsfm7as@linutronix.de> MIME-Version: 1.0 Content-Disposition: inline X-Rspamd-Queue-Id: A185618038E60 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: Hi, I stumbled over the following: | static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n) | { … | unsigned long *map = NULL; | | #ifdef CONFIG_SLUB_DEBUG | map = bitmap_alloc(oo_objects(s->max), GFP_KERNEL); | #endif … | } else { | list_slab_objects(s, page, | "Objects remaining in %s on __kmem_cache_shutdown()", | map); | } | } … | #ifdef CONFIG_SLUB_DEBUG | bitmap_free(map); | #endif … | } so map gets allocated, passed to list_slab_objects() and then freed at end. Haven't notices where `map' is set but maybe it is just a buffer used in list_slab_objects(). And then there is this: | static void list_slab_objects(struct kmem_cache *s, struct page *page, | const char *text, unsigned long *map) | { | #ifdef CONFIG_SLUB_DEBUG | void *addr = page_address(page); | void *p; | | if (!map) | return; No map, return. Okay. | slab_err(s, page, text, s->name); | slab_lock(page); | | map = get_map(s, page); and here `map' gets overwritten, correct? But it gets initialized. And it also acquires `object_map_lock'. | for_each_object(p, s, addr, page->objects) { | | if (!test_bit(slab_index(p, s, addr), map)) { | pr_err("INFO: Object 0x%p @offset=%tu\n", p, p - addr); | print_tracking(s, p); | } | } and here I would expect to unlock `object_map_lock'. | slab_unlock(page); | #endif | } Is this a miss-merge of some kind? I would revert commit aa456c7aebb14 ("slub: remove kmalloc under list_lock from list_slab_objects() V2") by doing this: Is there something I'm missing? This is completely untested of course. Sebastian diff --git a/kernel/locking/rwsem.h b/kernel/locking/rwsem.h deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/mm/slub.c b/mm/slub.c index b8f798b50d44d..72195cafbb503 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3766,15 +3766,13 @@ static int kmem_cache_open(struct kmem_cache *s, slab_flags_t flags) } static void list_slab_objects(struct kmem_cache *s, struct page *page, - const char *text, unsigned long *map) + const char *text) { #ifdef CONFIG_SLUB_DEBUG void *addr = page_address(page); + unsigned long *map; void *p; - if (!map) - return; - slab_err(s, page, text, s->name); slab_lock(page); @@ -3786,6 +3784,7 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page, print_tracking(s, p); } } + put_map(map); slab_unlock(page); #endif } @@ -3799,11 +3798,6 @@ static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n) { 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); @@ -3813,16 +3807,11 @@ static void free_partial(struct kmem_cache *s, struct kmem_cache_node *n) list_add(&page->slab_list, &discard); } else { list_slab_objects(s, page, - "Objects remaining in %s on __kmem_cache_shutdown()", - map); + "Objects remaining in %s on __kmem_cache_shutdown()"); } } 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); }