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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACDD5C433FE for ; Thu, 17 Mar 2022 07:06:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DC7E6B0071; Thu, 17 Mar 2022 03:06:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 264AD8D0002; Thu, 17 Mar 2022 03:06:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DFEA8D0001; Thu, 17 Mar 2022 03:06:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0205.hostedemail.com [216.40.44.205]) by kanga.kvack.org (Postfix) with ESMTP id F224C6B0071 for ; Thu, 17 Mar 2022 03:06:52 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A110C1827391C for ; Thu, 17 Mar 2022 07:06:52 +0000 (UTC) X-FDA: 79252995864.19.7F058A2 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by imf13.hostedemail.com (Postfix) with ESMTP id 0CC312001D for ; Thu, 17 Mar 2022 07:06:51 +0000 (UTC) Received: by mail-pg1-f171.google.com with SMTP id c2so1988371pga.10 for ; Thu, 17 Mar 2022 00:06:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=JEomCzOOoqsitubEmRfhikvC8ISEh5vZizVnhY3qvtU=; b=p76qIQI3t5lUUAR403pBgtkokiMVromec5iM/cWkPFV0uRg/Wndlgu25v4sCfsDbDp YQyQJWBKUJegi9+kIzTDkL/E75vqUDwOQdWa/tlWMlhQjncUGrktaLJzPdG37t7T9L48 SQcoh2KGKFjaA4uTCJFVYP3eWQZrJYsRQPtdlGzy/G2gHUs5FCLDQcw6HCldUHv9bfMS 9hwWXuVBbAYow9BRDe36OKN8yG6jbS5D+PVa8pPbF3wJSzdexykxYcjVs1DVdAh8+eIK KwM4ZvFzaVohjarlDkw9wrAEHZEA28LJA0Dv29/ro8eKz4VT2k/GQjvELEqZXJ8c9i65 sV8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=JEomCzOOoqsitubEmRfhikvC8ISEh5vZizVnhY3qvtU=; b=Bw3/kXb+hKUF3aooUEMNb+xvz+kZn2zy/fLUAwGCdhXzmID57PoWdumM45dCKoHpsk 2qUNutLA89a2k4+ZHOJhkJTPwlQRTNUEKkLBuo4b/k8BiSdxM9rUtsi5kMs0kX9wtHY5 qR1Gzhzj1jJ+vSMZhMoTvALHkBTY51IjmnGCLoxVM1TnVAkXjlBlX6HpBMkXdPR7ej09 LUo0kjLvTpb62tpJI6MICjgxF4nwGuhVIvEd7QEFeYKGJctzE4kcjdIatzBKSPxbaWc2 NeydrhC7OdO/zPbCDUbKtWPJctS+wLP1A+qaVjCs4/gdwqHgQiH4DCj+q/nsiXz+sJZK 5w8w== X-Gm-Message-State: AOAM532QYye05VNC6WW7uankiNaOWiyQV87f1cz6CluRkyqVNRaHNcgh OuoZ88heDOyNcgARulveMFs= X-Google-Smtp-Source: ABdhPJzj4tt3LLrcqIkvwErxb1gD1YP3pnu5u2xw0vJyS2A/mRd77+HRjCxPPuE/qTR7mjxZgJpo9g== X-Received: by 2002:a05:6a00:130e:b0:4f3:9654:266d with SMTP id j14-20020a056a00130e00b004f39654266dmr3237064pfu.59.1647500810637; Thu, 17 Mar 2022 00:06:50 -0700 (PDT) Received: from ip-172-31-19-208.ap-northeast-1.compute.internal (ec2-18-181-137-102.ap-northeast-1.compute.amazonaws.com. [18.181.137.102]) by smtp.gmail.com with ESMTPSA id o12-20020a056a001bcc00b004fa2830a03esm1719924pfw.200.2022.03.17.00.06.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 00:06:50 -0700 (PDT) Date: Thu, 17 Mar 2022 07:06:45 +0000 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Vlastimil Babka Cc: linux-mm@kvack.org, Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Roman Gushchin , Oliver Glitta Subject: Re: [PATCH] mm/slub, kunit: Make slub_kunit pass even when SLAB_RED_ZONE flag is set Message-ID: References: <20220316143841.160373-1-42.hyeyoo@gmail.com> <46456d7a-fd35-5052-f3c0-a97d25345e79@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <46456d7a-fd35-5052-f3c0-a97d25345e79@suse.cz> X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0CC312001D X-Stat-Signature: zthnfczh69zyo5etu69n1rdktg85si3c Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=p76qIQI3; spf=pass (imf13.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.215.171 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1647500811-755155 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 Wed, Mar 16, 2022 at 11:11:08PM +0100, Vlastimil Babka wrote: > On 3/16/22 15:38, Hyeonggon Yoo wrote: > > Testcase test_next_pointer in slub_kunit fails when SLAB_RED_ZONE flag > > is globally set. This is because on_freelist() cuts corrupted freelist > > chain and does not update cut objects' redzone to SLUB_RED_ACTIVE. > > > > When the test validates a slab that whose freelist is cut, it expects > > redzone of objects unreachable by freelist is set to SLUB_RED_ACTIVE. > > And it reports "Left Redzone overritten" error because the expectation > > failed. > > > > This patch makes slub_kunit expect two more errors for reporting and > > fixing red overwritten error when SLAB_RED_ZONE flag is set. > > > > The test passes on slub_debug and slub_debug=Z after this patch. > > Hmm I think it's not optimal strategy for unit tests to adapt like this to > external influence. It seems rather fragile. The test cases should be > designed to test a specific condition and that's it. So maybe we could e.g. > introduce a new SLAB_ flag passed to kmem_cache_create that tells it to > ignore any globally specified slub debug flags? Agree. It's so easy to be broken. I think your suggestion is good for unit tests. I'll send a patch. BTW, The situation is that SLUB makes (by cutting freelist chain) objects invalid (invalid redzone) and reporting what caused by SLUB itself is quite ugly. No simple solution comes into mind but yeah... it's not a big problem as we rarely call validate_slab_cache(). > > Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> > > --- > > lib/slub_kunit.c | 19 +++++++++++++++++-- > > 1 file changed, 17 insertions(+), 2 deletions(-) > > > > diff --git a/lib/slub_kunit.c b/lib/slub_kunit.c > > index 8662dc6cb509..7cf1fb5a7fde 100644 > > --- a/lib/slub_kunit.c > > +++ b/lib/slub_kunit.c > > @@ -45,21 +45,36 @@ static void test_next_pointer(struct kunit *test) > > * Expecting three errors. > > * One for the corrupted freechain and the other one for the wrong > > * count of objects in use. The third error is fixing broken cache. > > + * > > + * When flag SLUB_RED_ZONE is set, we expect two more errors for reporting > > + * and fixing overwritten redzone error. This two errors are detected > > + * because SLUB cuts corrupted freelist in on_freelist(), but does not > > + * update its redzone to SLUB_RED_ACTIVE. > > */ > > validate_slab_cache(s); > > - KUNIT_EXPECT_EQ(test, 3, slab_errors); > > + > > + if (s->flags & SLAB_RED_ZONE) > > + KUNIT_EXPECT_EQ(test, 5, slab_errors); > > + else > > + KUNIT_EXPECT_EQ(test, 3, slab_errors); > > > > /* > > * Try to repair corrupted freepointer. > > * Still expecting two errors. The first for the wrong count > > * of objects in use. > > * The second error is for fixing broken cache. > > + * > > + * When SLUB_RED_ZONE flag is set, we expect two more errors > > + * for same reason as above. > > */ > > *ptr_addr = tmp; > > slab_errors = 0; > > > > validate_slab_cache(s); > > - KUNIT_EXPECT_EQ(test, 2, slab_errors); > > + if (s->flags & SLAB_RED_ZONE) > > + KUNIT_EXPECT_EQ(test, 4, slab_errors); > > + else > > + KUNIT_EXPECT_EQ(test, 2, slab_errors); > > > > /* > > * Previous validation repaired the count of objects in use. > -- Thank you, You are awesome! Hyeonggon :-)