Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp36414pxj; Wed, 12 May 2021 21:48:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxFK2o6DCjo6gkqlaegGw1EAq3dI52697q03LL8zwgzWxQrb9kexXog0KM4b9W1gX6RI1b X-Received: by 2002:a17:906:18b2:: with SMTP id c18mr9019288ejf.160.1620881328006; Wed, 12 May 2021 21:48:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620881328; cv=none; d=google.com; s=arc-20160816; b=g+C0fSYwOsZ2QJueN0Sdkd1O9EzRnmiatusDIQ47DqhCPBaZfLIsYt1GwtwRk6SlQW SXzQU/zjp5a+4whNZaOh+GuIAmhiqZ3dogZNB6JqN99lAgRm9pSLzmBwDDljfXUqUIUz lxmO9x9M3/kkPlJQN6cBttEfF4QCTSamU4ffc/VrxJRQewm6b5RKPKThHkTHRgLx5w3R NZw9kT0QXgtSiyw5KJmY0WVRn1h/d9L7YZuctxt6+Mb6kTB5p1Nc6eIyzDfP9/M3xLYu Nj+xSdLTMM5j348RF6W5wZldPABRzE7uICiG0vJRBHn6l8WAwv1VYL7jtN4s30uxiVSv Fbcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=MY0AP5EB4JLYJphpAXLa68eX1RyC5k1ebVc8n4CZ+yg=; b=uDNEgBHiSAgzfIp3fJMnCfHymoz25NGjuRhPXqH4JFxNIrpdobtn+H91G+939AAEN+ hhoLDJs8MzX5y2gAFIBX9eiCiRcnZyaBBboojtrZSyxjDxk7om27cN0K8lsBxryPVlKv Xbvz1a3EuCaDe+wu3VuOyAiAlUBLC4lWzD+glZp3Gch1uAU/2B3KPBN/UE5+PHsUdOyb Ig+RYi8/xAbIAF09u45SpeoVZ9SyW3r84GWRF5uMDRtOPd3VBwf2a4DevseOHHmxYngl pqEN55ak9DWTnVs21YY2u1IfDyuVI3k3cnI3+mN12xrPMVh9e70Jn/UM88QhDTXEWcmR EhoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=g82xDo6h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ay17si2271854ejb.340.2021.05.12.21.48.12; Wed, 12 May 2021 21:48:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=g82xDo6h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230112AbhEMEpw (ORCPT + 99 others); Thu, 13 May 2021 00:45:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:55240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbhEMEpu (ORCPT ); Thu, 13 May 2021 00:45:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B568761425; Thu, 13 May 2021 04:44:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1620881081; bh=0eRCsa825ZZVZO1LVEosg5gh2uAc3o9YDAtZzjcpTKE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=g82xDo6hWnPw/vISDdZ/uV5dxS47t99wzcTl2GWVxJvToXBPeBvpz0ShQzBVBG5ND bh0BOdcplDTX/CDAvtipQJ2fHDQWWLbtt8l7WJ92nrCDY6dGjfrUXTyH4VHUH3uwr8 efXjZ4SgAaznw8o7IG5u3CXr2HxNJbQMwHP0Nmj8= Date: Wed, 12 May 2021 21:44:40 -0700 From: Andrew Morton To: glittao@gmail.com Cc: brendanhiggins@google.com, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, vbabka@suse.cz, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-mm@kvack.org, elver@google.com, dlatypov@google.com Subject: Re: [PATCH v5 2/3] mm/slub, kunit: add a KUnit test for SLUB debugging functionality Message-Id: <20210512214440.e2cb47f751137db9802da62e@linux-foundation.org> In-Reply-To: <20210511150734.3492-2-glittao@gmail.com> References: <20210511150734.3492-1-glittao@gmail.com> <20210511150734.3492-2-glittao@gmail.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 11 May 2021 17:07:33 +0200 glittao@gmail.com wrote: > From: Oliver Glitta > > SLUB has resiliency_test() function which is hidden behind #ifdef > SLUB_RESILIENCY_TEST that is not part of Kconfig, so nobody > runs it. KUnit should be a proper replacement for it. > > Try changing byte in redzone after allocation and changing > pointer to next free node, first byte, 50th byte and redzone > byte. Check if validation finds errors. > > There are several differences from the original resiliency test: > Tests create own caches with known state instead of corrupting > shared kmalloc caches. > > The corruption of freepointer uses correct offset, the original > resiliency test got broken with freepointer changes. > > Scratch changing random byte test, because it does not have > meaning in this form where we need deterministic results. > > Add new option CONFIG_SLUB_KUNIT_TEST in Kconfig. > Tests next_pointer, first_word and clobber_50th_byte do not run > with KASAN option on. Because the test deliberately modifies non-allocated > objects. > > Use kunit_resource to count errors in cache and silence bug reports. > Count error whenever slab_bug() or slab_fix() is called or when > the count of pages is wrong. > > ... > > lib/slub_kunit.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++ > mm/slab.h | 1 + > mm/slub.c | 46 +++++++++++++- > 5 files changed, 212 insertions(+), 3 deletions(-) > create mode 100644 lib/slub_kunit.c > > diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug > index 678c13967580..7723f58a9394 100644 > --- a/lib/Kconfig.debug > +++ b/lib/Kconfig.debug > @@ -2429,6 +2429,18 @@ config BITS_TEST > > If unsure, say N. > > +config SLUB_KUNIT_TEST > + tristate "KUnit test for SLUB cache error detection" if !KUNIT_ALL_TESTS This means it can be compiled as a kernel module. Did you runtime test the code as a module? ERROR: modpost: "kasan_enable_current" [lib/slub_kunit.ko] undefined! ERROR: modpost: "kasan_disable_current" [lib/slub_kunit.ko] undefined! --- a/mm/kasan/common.c~a +++ a/mm/kasan/common.c @@ -51,11 +51,14 @@ void kasan_enable_current(void) { current->kasan_depth++; } +EXPORT_SYMBOL(kasan_enable_current); void kasan_disable_current(void) { current->kasan_depth--; } +EXPORT_SYMBOL(kasan_disable_current); + #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ void __kasan_unpoison_range(const void *address, size_t size) _