From patchwork Thu Jan 24 07:00:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miles Chen X-Patchwork-Id: 10778419 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D123139A for ; Thu, 24 Jan 2019 07:01:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB8B42E26F for ; Thu, 24 Jan 2019 07:00:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9ADD2E228; Thu, 24 Jan 2019 07:00:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 713F82E20D for ; Thu, 24 Jan 2019 07:00:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=1CovVJduHQH/XkZIqYrtW/qYFfFVsmBAIVxP59gD2kQ=; b=cnsQB2wZQu/x/d xj9I32g1ga32NYsu3cvYL5Xb81m9APf2WbzvGbhRzy+hZspoeyPOsZOgLhUn68F8K3Jrh2MHi5k5T Hcp991hFSstVrmWutkHhtXhf7vgXX6lkp/gsgnQ+68/D0QGPN3V5nf1R0amTzP+uJ2gWP+RdftCHG qA1gv6P9Wq2mg8mxPkI2TH2FY9hxl6FOCDfiBxkKIMsAe+q7fahBg4QE9SedZwI8MwPmAqM4dJt1h A7Y8pWlKVdyq/rBhuMEQUVOd/4Ijo6IyGa+eFYFitqiwVSqUQJc7jf5BAJOF6U0yXPM+OyIKcNbMh pPba0qdT3s9z6jRMQpJw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gmZ0V-0005lb-11; Thu, 24 Jan 2019 07:00:59 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gmZ0S-0005lA-QA for linux-mediatek@lists.infradead.org; Thu, 24 Jan 2019 07:00:58 +0000 X-UUID: 32fab9a14b104733b52379a41c463523-20190123 X-UUID: 32fab9a14b104733b52379a41c463523-20190123 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 815719164; Wed, 23 Jan 2019 23:00:28 -0800 Received: from mtkmbs08n1.mediatek.inc (172.21.101.55) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 23 Jan 2019 23:00:26 -0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs08n1.mediatek.inc (172.21.101.55) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 24 Jan 2019 15:00:24 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Thu, 24 Jan 2019 15:00:24 +0800 From: To: Christoph Lameter , Pekka Enberg , "David Rientjes" , Joonsoo Kim , "Andrew Morton" , Jonathan Corbet Subject: [PATCH v2] mm/slub: introduce SLAB_WARN_ON_ERROR Date: Thu, 24 Jan 2019 15:00:23 +0800 Message-ID: <1548313223-17114-1-git-send-email-miles.chen@mediatek.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190123_230056_855078_2667CB13 X-CRM114-Status: GOOD ( 13.04 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mm@kvack.org, Miles Chen , linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Miles Chen When debugging slab errors in slub.c, sometimes we have to trigger a panic in order to get the coredump file. Add a debug option SLAB_WARN_ON_ERROR to toggle WARN_ON() when the option is set. Change since v1: 1. Add a special debug option SLAB_WARN_ON_ERROR and toggle WARN_ON() if it is set. 2. SLAB_WARN_ON_ERROR can be set by kernel parameter slub_debug. Cc: Christopher Lameter Cc: Pekka Enberg , Cc: David Rientjes , Cc: Joonsoo Kim , Cc: Andrew Morton Cc: Jonathan Corbet Signed-off-by: Miles Chen --- Documentation/vm/slub.rst | 1 + include/linux/slab.h | 3 +++ mm/slub.c | 34 ++++++++++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Documentation/vm/slub.rst b/Documentation/vm/slub.rst index 195928808bac..236c00b2d17b 100644 --- a/Documentation/vm/slub.rst +++ b/Documentation/vm/slub.rst @@ -52,6 +52,7 @@ Possible debug options are:: A Toggle failslab filter mark for the cache O Switch debugging off for caches that would have caused higher minimum slab orders + W Toggle WARN_ON() on slab errors - Switch all debugging off (useful if the kernel is configured with CONFIG_SLUB_DEBUG_ON) diff --git a/include/linux/slab.h b/include/linux/slab.h index 11b45f7ae405..1fd9911890c6 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -109,6 +109,9 @@ #define SLAB_KASAN 0 #endif +/* WARN_ON slab error */ +#define SLAB_WARN_ON_ERROR ((slab_flags_t __force)0x10000000U) + /* The following flags affect the page allocator grouping pages by mobility */ /* Objects are reclaimable */ #define SLAB_RECLAIM_ACCOUNT ((slab_flags_t __force)0x00020000U) diff --git a/mm/slub.c b/mm/slub.c index 1e3d0ec4e200..60f93e0657fb 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -684,7 +684,10 @@ static void print_trailer(struct kmem_cache *s, struct page *page, u8 *p) print_section(KERN_ERR, "Padding ", p + off, size_from_object(s) - off); - dump_stack(); + if (unlikely(s->flags & SLAB_WARN_ON_ERROR)) + WARN_ON(1); + else + dump_stack(); } void object_err(struct kmem_cache *s, struct page *page, @@ -705,7 +708,11 @@ static __printf(3, 4) void slab_err(struct kmem_cache *s, struct page *page, va_end(args); slab_bug(s, "%s", buf); print_page_info(page); - dump_stack(); + + if (unlikely(s->flags & SLAB_WARN_ON_ERROR)) + WARN_ON(1); + else + dump_stack(); } static void init_object(struct kmem_cache *s, void *object, u8 val) @@ -1254,6 +1261,9 @@ static int __init setup_slub_debug(char *str) case 'a': slub_debug |= SLAB_FAILSLAB; break; + case 'w': + slub_debug |= SLAB_WARN_ON_ERROR; + break; case 'o': /* * Avoid enabling debugging on caches if its minimum @@ -5220,6 +5230,25 @@ static ssize_t store_user_store(struct kmem_cache *s, } SLAB_ATTR(store_user); +static ssize_t warn_on_error_show(struct kmem_cache *s, char *buf) +{ + return sprintf(buf, "%d\n", !!(s->flags & SLAB_WARN_ON_ERROR)); +} + +static ssize_t warn_on_error_store(struct kmem_cache *s, + const char *buf, size_t length) +{ + if (any_slab_objects(s)) + return -EBUSY; + + s->flags &= ~SLAB_WARN_ON_ERROR; + if (buf[0] == '1') + s->flags |= SLAB_WARN_ON_ERROR; + + return length; +} +SLAB_ATTR(warn_on_error); + static ssize_t validate_show(struct kmem_cache *s, char *buf) { return 0; @@ -5428,6 +5457,7 @@ static struct attribute *slab_attrs[] = { &validate_attr.attr, &alloc_calls_attr.attr, &free_calls_attr.attr, + &warn_on_error_attr.attr, #endif #ifdef CONFIG_ZONE_DMA &cache_dma_attr.attr,