Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp238224pxj; Thu, 13 May 2021 03:52:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTiEtd8o4oCpjK0cpbsUKwXDoRdaYPaoZusuX2bOH3/MhhpyNaX4RONc66ZgRBj/b2L+LD X-Received: by 2002:a02:9505:: with SMTP id y5mr37039009jah.27.1620903162129; Thu, 13 May 2021 03:52:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620903162; cv=none; d=google.com; s=arc-20160816; b=JGth6nt8lkwpifOkUoysDbitws5U4FNEYDdlZRReQpCkuzIWWq5uO28a6G7jifjW+D Y4sbOHIt4f+IUfvpd9x32zj93SN23qDpr5aXyv1DYCPskBXuB8Y4nOXNPGkPnWgcU9bG fRwAbuiPCvy0dNs2816hzJCTwNJTpWjOwvOmb2Z0xZcjFHSEB4EOGlBSGxVBpCHZ4iQ8 qREnDTwJrYLgkSEXZ27WnLFVgpi7dtTHkToUAva+BBXGN6Zdxc69W47tXeQ/N3OyweZV mTmYayEbGn6pLnM5HzDh8QdTyd7fn/a+14I71VtWtFz1lVr/EpSqwl1aHAfcQokNZyRl QLMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=jG12S413O8fUiJ8iykc3p7wvxXhef9ESdPVA0acK7/k=; b=gp7Cj5BbVGdVh5nMIQSugQYhSeD57jRPU8GWTh30HISEJjVTC8NXHd8rU6az+J8B97 mtaJ5E2bR0Nh2G0fnRfHO2Bd6lD7L3fH7ZFJTRa30APJNm0IJizb5zsntDMUrV4PSRRt j9BqyfogguPwLaXVvIsDPKQI+aTpYYHAngTdmufx4BJ/vfUX7Xo70cVh1FFqy+iSXhZP X5uj90r741ji/rCW/bVuyacI5leViS6DFzDQk+g7QofNXgbdedW8JdnG0+997lDJqU+d JdKYNxBRPr0bFgfQYV21zgToJAawwaqToe9+Er+vA3ojyn1oZVbqM9F/QFU9joSEMuQp 6/9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NDyBX09O; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d6si3802303ilv.134.2021.05.13.03.52.26; Thu, 13 May 2021 03:52:42 -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=@google.com header.s=20161025 header.b=NDyBX09O; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232224AbhEMIzo (ORCPT + 99 others); Thu, 13 May 2021 04:55:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231176AbhEMIzi (ORCPT ); Thu, 13 May 2021 04:55:38 -0400 Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73308C06174A for ; Thu, 13 May 2021 01:54:25 -0700 (PDT) Received: by mail-oi1-x231.google.com with SMTP id v22so19865224oic.2 for ; Thu, 13 May 2021 01:54:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jG12S413O8fUiJ8iykc3p7wvxXhef9ESdPVA0acK7/k=; b=NDyBX09Om2k3j1J6yBIltr0QKv4OUv8wA0NvZw9OdVOa8L4npbuGF1BDzMwBnDlcFZ Emb2fYN5KnXR76wk9o6ekppMI2W02qXSielDjKiz5A9HWTDAsqY6IEUj/iq1zYpf0ZuO HT7HGrSG+U6CkeBqg9IRNWEKaqFdWKFZIpdNq7Kv/osIe24YLUttO+KE6LIq8rZHo+AQ V3c7QCOxyC8eAMi4Tx9XCh5dlaFDBoKvcv9OUpZnPFUeK7A1Ip4XFavPbBrEfCv3AIjT CUoMXrjvc51Y6VaEUD3KTznAsmgh+J5UGPXOrcs+8MGp9Lhca21EuNpoigsG1En/TsSS 6LHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jG12S413O8fUiJ8iykc3p7wvxXhef9ESdPVA0acK7/k=; b=sLQ194e4LeIduHhBNYSEl1mgwKqg201GwpfGU2s5Ka6PUUGZTcVbXkK6ncbCSgTZKp 5E3bjzlAQTdAxh7q9TNOz9bwJdbjlZnSB1E7Oov9FfoKa57+pcbJM1OLqfi9AKUpjldU hoZ9puCNsoUfz2V1eGPnRUCJ7NCfDIYZci1XoBpOOacc+5Nd6MIDZNP3k+4ZHTtW8k9B fancnPxb92RVrjhm6gikh8psVf8p+A3gwNTosyXft6Ic75jzeLVNXylgVS/+giHys2s8 jjiF8FdlAkPpRuBjbydVsHf1p/IVM53zysJe+2OsFHjbXandlzYL/ylmUNKOQ5T46jmQ AwGA== X-Gm-Message-State: AOAM532IQOFQhEkXRHYuhMBdrxrwbTprf9a0b4nVyccgkvybqPkCNrf4 Y8jzemwI8RrgU0nkk2JmaiCCi4FhC2upiMHBCVmEIg== X-Received: by 2002:aca:bb06:: with SMTP id l6mr29564018oif.121.1620896064734; Thu, 13 May 2021 01:54:24 -0700 (PDT) MIME-Version: 1.0 References: <20210511150734.3492-1-glittao@gmail.com> <20210511150734.3492-2-glittao@gmail.com> <20210512214440.e2cb47f751137db9802da62e@linux-foundation.org> In-Reply-To: <20210512214440.e2cb47f751137db9802da62e@linux-foundation.org> From: Marco Elver Date: Thu, 13 May 2021 10:54:13 +0200 Message-ID: Subject: Re: [PATCH v5 2/3] mm/slub, kunit: add a KUnit test for SLUB debugging functionality To: Andrew Morton Cc: Oliver Glitta , Brendan Higgins , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Vlastimil Babka , LKML , "open list:KERNEL SELFTEST FRAMEWORK" , KUnit Development , Linux Memory Management List , Daniel Latypov Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 13 May 2021 at 06:44, Andrew Morton wrote: > 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) > _ Acked-by: Marco Elver