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 X-Spam-Level: X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7340BC433E0 for ; Tue, 9 Mar 2021 15:09:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 195046525F for ; Tue, 9 Mar 2021 15:09:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 195046525F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 983378D00FC; Tue, 9 Mar 2021 10:09:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9567C8D007F; Tue, 9 Mar 2021 10:09:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F97D8D00FC; Tue, 9 Mar 2021 10:09:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0218.hostedemail.com [216.40.44.218]) by kanga.kvack.org (Postfix) with ESMTP id 009B28D007F for ; Tue, 9 Mar 2021 10:09:56 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id B31F85DD1 for ; Tue, 9 Mar 2021 15:09:56 +0000 (UTC) X-FDA: 77900670792.22.B52C38D Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf11.hostedemail.com (Postfix) with ESMTP id 85D072000D9F for ; Tue, 9 Mar 2021 15:09:44 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 43273AC8C; Tue, 9 Mar 2021 15:09:46 +0000 (UTC) Subject: Re: [PATCH] mm/slub: Add slub_debug option to panic on memory corruption To: Georgi Djakov , linux-mm@kvack.org, akpm@linux-foundation.org, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com Cc: corbet@lwn.net, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210309134720.29052-1-georgi.djakov@linaro.org> From: Vlastimil Babka Message-ID: <390d8a2f-ead9-48a9-99eb-65c73bd18422@suse.cz> Date: Tue, 9 Mar 2021 16:09:45 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <20210309134720.29052-1-georgi.djakov@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Stat-Signature: gcwodi4sz5s9kz5ptnc4z6rjmn7kxxsu X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 85D072000D9F Received-SPF: none (suse.cz>: No applicable sender policy available) receiver=imf11; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: none/none X-HE-Tag: 1615302584-334355 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: On 3/9/21 2:47 PM, Georgi Djakov wrote: > Being able to stop the system immediately when a memory corruption > is detected is crucial to finding the source of it. This is very > useful when the memory can be inspected with kdump or other tools. Is this in some testing scenarios where you would also use e.g. panic_on_warn? We could hook to that. If not, we could introduce a new panic_on_memory_corruption that would apply also for debug_pagealloc and whatnot? > Let's add an option panic the kernel when slab debug catches an > object or list corruption. > > This new option is not enabled by default (yet), so it needs to be > enabled explicitly (for example by adding "slub_debug=FZPUC" to > the kernel command line). > > Signed-off-by: Georgi Djakov > --- > Documentation/vm/slub.rst | 1 + > include/linux/slab.h | 3 +++ > mm/slab.h | 2 +- > mm/slub.c | 9 +++++++++ > 4 files changed, 14 insertions(+), 1 deletion(-) > > diff --git a/Documentation/vm/slub.rst b/Documentation/vm/slub.rst > index 03f294a638bd..32878c44f3de 100644 > --- a/Documentation/vm/slub.rst > +++ b/Documentation/vm/slub.rst > @@ -53,6 +53,7 @@ Possible debug options are:: > Z Red zoning > P Poisoning (object and padding) > U User tracking (free and alloc) > + C Panic on object corruption (enables SLAB_CORRUPTION_PANIC) > T Trace (please only use on single slabs) > A Enable failslab filter mark for the cache > O Switch debugging off for caches that would have > diff --git a/include/linux/slab.h b/include/linux/slab.h > index 0c97d788762c..ebff5e704d08 100644 > --- a/include/linux/slab.h > +++ b/include/linux/slab.h > @@ -39,6 +39,9 @@ > #define SLAB_STORE_USER ((slab_flags_t __force)0x00010000U) > /* Panic if kmem_cache_create() fails */ > #define SLAB_PANIC ((slab_flags_t __force)0x00040000U) > +/* Panic if memory corruption is detected */ > +#define SLAB_CORRUPTION_PANIC ((slab_flags_t __force)0x00080000U) > + > /* > * SLAB_TYPESAFE_BY_RCU - **WARNING** READ THIS! > * > diff --git a/mm/slab.h b/mm/slab.h > index 120b1d0dfb6d..ae0079017fc6 100644 > --- a/mm/slab.h > +++ b/mm/slab.h > @@ -134,7 +134,7 @@ static inline slab_flags_t kmem_cache_flags(unsigned int object_size, > #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER) > #elif defined(CONFIG_SLUB_DEBUG) > #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \ > - SLAB_TRACE | SLAB_CONSISTENCY_CHECKS) > + SLAB_TRACE | SLAB_CONSISTENCY_CHECKS | SLAB_CORRUPTION_PANIC) > #else > #define SLAB_DEBUG_FLAGS (0) > #endif > diff --git a/mm/slub.c b/mm/slub.c > index 077a019e4d7a..49351427f701 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -741,6 +741,8 @@ void object_err(struct kmem_cache *s, struct page *page, > { > slab_bug(s, "%s", reason); > print_trailer(s, page, object); > + if (slub_debug & SLAB_CORRUPTION_PANIC) > + panic(reason); > } > > static __printf(3, 4) void slab_err(struct kmem_cache *s, struct page *page, > @@ -755,6 +757,8 @@ static __printf(3, 4) void slab_err(struct kmem_cache *s, struct page *page, > slab_bug(s, "%s", buf); > print_page_info(page); > dump_stack(); > + if (slub_debug & SLAB_CORRUPTION_PANIC) > + panic("slab: slab error\n"); > } > > static void init_object(struct kmem_cache *s, void *object, u8 val) > @@ -776,6 +780,8 @@ static void init_object(struct kmem_cache *s, void *object, u8 val) > static void restore_bytes(struct kmem_cache *s, char *message, u8 data, > void *from, void *to) > { > + if (slub_debug & SLAB_CORRUPTION_PANIC) > + panic("slab: object overwritten\n"); > slab_fix(s, "Restoring 0x%p-0x%p=0x%x\n", from, to - 1, data); > memset(from, data, to - from); > } > @@ -1319,6 +1325,9 @@ parse_slub_debug_flags(char *str, slab_flags_t *flags, char **slabs, bool init) > case 'a': > *flags |= SLAB_FAILSLAB; > break; > + case 'c': > + *flags |= SLAB_CORRUPTION_PANIC; > + break; > case 'o': > /* > * Avoid enabling debugging on caches if its minimum >