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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D186C433FE for ; Fri, 14 Jan 2022 22:04:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A34C6B00AB; Fri, 14 Jan 2022 17:04:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 02CB96B00AD; Fri, 14 Jan 2022 17:04:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE7D66B00AE; Fri, 14 Jan 2022 17:04:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0216.hostedemail.com [216.40.44.216]) by kanga.kvack.org (Postfix) with ESMTP id C71E96B00AB for ; Fri, 14 Jan 2022 17:04:01 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 8C975181953FC for ; Fri, 14 Jan 2022 22:04:01 +0000 (UTC) X-FDA: 79030271082.06.E48F371 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf21.hostedemail.com (Postfix) with ESMTP id 783811C0006 for ; Fri, 14 Jan 2022 22:04:00 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C11C761FFA; Fri, 14 Jan 2022 22:03:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7327C36AE9; Fri, 14 Jan 2022 22:03:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1642197839; bh=iOVyw2IzQSARaWNOIL3nAQMty30KC8WIeK0cp2QJhL8=; h=Date:From:To:Subject:In-Reply-To:From; b=QCQTMvAIal2ShTmLmYp3amdPcmFbO2oSKRCpFQ9s1wBfPh2sfp6qzK5xWf35Q7zJS KMc6Dt54qytQ3FbsLUFJ6DOvrfFLSN9MrNXtDLI7Ep3wtffRTYPoFfBpGI5eyhiucI RwfAVDh5klhGzKrXWUvHCf1EoaffzGjqPD0SZN3E= Date: Fri, 14 Jan 2022 14:03:58 -0800 From: Andrew Morton To: akpm@linux-foundation.org, cl@linux.com, dvyukov@google.com, elver@google.com, glider@google.com, iamjoonsoo.kim@lge.com, linux-mm@kvack.org, mingo@redhat.com, mm-commits@vger.kernel.org, penberg@kernel.org, rientjes@google.com, torvalds@linux-foundation.org, vbabka@suse.cz Subject: [patch 021/146] mm/slab_common: use WARN() if cache still has objects on destroy Message-ID: <20220114220358.-PVz8K_7b%akpm@linux-foundation.org> In-Reply-To: <20220114140222.6b14f0061194d3200000c52d@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Queue-Id: 783811C0006 X-Stat-Signature: azzqbaii6no1kr6y6gnng9zcsg7wt5yp Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=QCQTMvAI; spf=pass (imf21.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspamd-Server: rspam07 X-HE-Tag: 1642197840-625052 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: From: Marco Elver Subject: mm/slab_common: use WARN() if cache still has objects on destroy Calling kmem_cache_destroy() while the cache still has objects allocated is a kernel bug, and will usually result in the entire cache being leaked. While the message in kmem_cache_destroy() resembles a warning, it is currently not implemented using a real WARN(). This is problematic for infrastructure testing the kernel, all of which rely on the specific format of WARN()s to pick up on bugs. Some 13 years ago this used to be a simple WARN_ON() in slub, but d629d8195793 ("slub: improve kmem_cache_destroy() error message") changed it into an open-coded warning to avoid confusion with a bug in slub itself. Instead, turn the open-coded warning into a real WARN() with the message preserved, so that test systems can actually identify these issues, and we get all the other benefits of using a normal WARN(). The warning message is extended with "when called from " to make it even clearer where the fault lies. For most configurations this is only a cosmetic change, however, note that WARN() here will now also respect panic_on_warn. Link: https://lkml.kernel.org/r/20211102170733.648216-1-elver@google.com Signed-off-by: Marco Elver Reviewed-by: Vlastimil Babka Acked-by: David Rientjes Cc: Christoph Lameter Cc: Pekka Enberg Cc: Joonsoo Kim Cc: Dmitry Vyukov Cc: Alexander Potapenko Cc: Ingo Molnar Signed-off-by: Andrew Morton --- mm/slab_common.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) --- a/mm/slab_common.c~mm-slab_common-use-warn-if-cache-still-has-objects-on-destroy +++ a/mm/slab_common.c @@ -489,8 +489,6 @@ void slab_kmem_cache_release(struct kmem void kmem_cache_destroy(struct kmem_cache *s) { - int err; - if (unlikely(!s)) return; @@ -501,12 +499,9 @@ void kmem_cache_destroy(struct kmem_cach if (s->refcount) goto out_unlock; - err = shutdown_cache(s); - if (err) { - pr_err("%s %s: Slab cache still has objects\n", - __func__, s->name); - dump_stack(); - } + WARN(shutdown_cache(s), + "%s %s: Slab cache still has objects when called from %pS", + __func__, s->name, (void *)_RET_IP_); out_unlock: mutex_unlock(&slab_mutex); cpus_read_unlock(); _