From patchwork Tue Nov 2 17:07:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12599405 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE750C433EF for ; Tue, 2 Nov 2021 17:08:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6C08261052 for ; Tue, 2 Nov 2021 17:08:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6C08261052 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id C88D4940008; Tue, 2 Nov 2021 13:08:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C3841940007; Tue, 2 Nov 2021 13:08:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B26F4940008; Tue, 2 Nov 2021 13:08:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0227.hostedemail.com [216.40.44.227]) by kanga.kvack.org (Postfix) with ESMTP id A20A4940007 for ; Tue, 2 Nov 2021 13:08:03 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 522F88249980 for ; Tue, 2 Nov 2021 17:08:03 +0000 (UTC) X-FDA: 78764622846.12.FE31432 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf16.hostedemail.com (Postfix) with ESMTP id D4A72F00009B for ; Tue, 2 Nov 2021 17:07:55 +0000 (UTC) Received: by mail-wm1-f73.google.com with SMTP id 128-20020a1c0486000000b0030dcd45476aso7282183wme.0 for ; Tue, 02 Nov 2021 10:08:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=VZR4veHDB/Hv5J8c9l5kvLwMvvSzVFvPkC6CzrVLaSc=; b=h5ZsJTLfAG9mNnQa0xWFAL2KxUVTpouTD3NLPXa9euGiJQFSkr8NLeCyb+LPhUqP4V CPA2cifJNDzf9m/dmWlxblumpDSRXmGZiavxecw6BQJ96z2N8jO+p74zDsfB4VZZpLCv PmQc1vrw1arnNklp77e5CMB5UGoAwRo1MCEk1M6IfXh8yLkVc27xokue/B18c8j0vRAc KBecirNBiVNE0bMRB52sbc1zt17fEXCH1dZys8h9YwrObCrr3Hk863S5dozbA4NqD3QX 6Yghlp9lPxhgjSIpsyDH5v1/oyULTQrrKGG4bz9Dwe9VREtkSvgGaNuyrq4T5QWD5Iti Ts8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=VZR4veHDB/Hv5J8c9l5kvLwMvvSzVFvPkC6CzrVLaSc=; b=cPgcX31LusHJxEpfdTgwv52FKf8kwn4OljR+rQqizy9DZVY63YgmrPfwL6a6WQ+nfe NGyUDXh8Gcm4v1volIwSe/I76dBq2irqR/lJtvgu3gkXP64c4ZVw2C1COo3j2JsytoFa JcxWJvrls4lymGJTnqzrTOEwuT0gNXrOUtabJalJ+KCRfSO8lMtHUI0DoVHGEHuJqUcE WA8Irb9miLbzbw4AA9eX8Zniy4WiTHEhAJSxrEz7kMENcRsfY1JeVD4nbwRHrLslPMuO ZFLRy6C/ziSl11I/+XPcRp4R84JJJFb385RAmuWvsnpmBlE08p3GZUymp6RJCJe3OsZG 1f2w== X-Gm-Message-State: AOAM533fPCsBE9V10Bag9af28rdVs65QCNRq2c1lVTjhZpQLTk0fJOdR 3ImR2DJF3IETNBH2DBkf4DTuPtyquA== X-Google-Smtp-Source: ABdhPJwsVlfeyltofJcj5J/2mtf997JPKCeDSm4UOFJj0uTkZTZ3OpdauGeH/9tTUDezWE+nVfvjDDTIJA== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:c225:73fc:3369:a4ae]) (user=elver job=sendgmr) by 2002:a5d:51cf:: with SMTP id n15mr38162615wrv.106.1635872881388; Tue, 02 Nov 2021 10:08:01 -0700 (PDT) Date: Tue, 2 Nov 2021 18:07:33 +0100 Message-Id: <20211102170733.648216-1-elver@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog Subject: [PATCH] mm/slab_common: use WARN() if cache still has objects on destroy From: Marco Elver To: elver@google.com, Andrew Morton Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Dmitry Vyukov , Alexander Potapenko , kasan-dev@googlegroups.com, Ingo Molnar X-Stat-Signature: 8mjwkq89931tzr4et8brmh96q1h8ry7h Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=h5ZsJTLf; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf16.hostedemail.com: domain of 3cXCBYQUKCGoMTdMZOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--elver.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3cXCBYQUKCGoMTdMZOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--elver.bounces.google.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D4A72F00009B X-HE-Tag: 1635872875-63271 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: 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. Signed-off-by: Marco Elver Reviewed-by: Vlastimil Babka Acked-by: David Rientjes --- mm/slab_common.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index ec2bb0beed75..0155a3042203 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -497,8 +497,6 @@ void slab_kmem_cache_release(struct kmem_cache *s) void kmem_cache_destroy(struct kmem_cache *s) { - int err; - if (unlikely(!s)) return; @@ -509,12 +507,9 @@ void kmem_cache_destroy(struct kmem_cache *s) 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();