From patchwork Thu Mar 17 08:10:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyeonggon Yoo <42.hyeyoo@gmail.com> X-Patchwork-Id: 12783667 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 26E81C433FE for ; Thu, 17 Mar 2022 08:10:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C4796B0071; Thu, 17 Mar 2022 04:10:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 74D6A8D0002; Thu, 17 Mar 2022 04:10:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C72D8D0001; Thu, 17 Mar 2022 04:10:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id 468C66B0071 for ; Thu, 17 Mar 2022 04:10:53 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0604221814 for ; Thu, 17 Mar 2022 08:10:53 +0000 (UTC) X-FDA: 79253157186.05.D7666B5 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf18.hostedemail.com (Postfix) with ESMTP id 7579E1C0003 for ; Thu, 17 Mar 2022 08:10:52 +0000 (UTC) Received: by mail-pl1-f174.google.com with SMTP id w4so3802736ply.13 for ; Thu, 17 Mar 2022 01:10:52 -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:mime-version:content-disposition :in-reply-to; bh=NuRuM8VQcj0cMLW6NaMsolBEookYg2f+ZzcA/iC4kl8=; b=QR+L0RdMe+8AEf5db/yjon7PK0pZ6K4HB9yODg7PlfCkjuRYH/sLBnjeRAuAzYw2L4 TuqGH6Kxu7tGIxZJRhu0rm3STjM7Ha8sE/4bKRxQMHoKlx28hfBgCDFUjhrsc4vSeNwZ EbHLKyENeTaeLXQf2n9SntHQNBTWU+4KQ0Sz2Fezn352xZx0k7ymdBP6mcW/aMea2tMr ZxH3nXlnnIwWxclmYgtgZd1uXBAcPwotdjJXiujFBEdzzouSOC4wsEpjegNWlPdaachm bJ4IpSKbPiFZiw4MTa/TkMBVKjPwLiFqvYZ0XKSD9ZzTBxpqIo18SFU56uVZbMGZWWIf iLLg== 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:mime-version :content-disposition:in-reply-to; bh=NuRuM8VQcj0cMLW6NaMsolBEookYg2f+ZzcA/iC4kl8=; b=2PHcLrRY/dLYs8gEnvJPe7x48yBIU0m8B+IYTo9wKUipWR+t/ck88wKQsINEZSvn4U 8bcO1ewttoMQqJbX0s0eOxWZu3kq/Pp2bH0+Gc+0wYsBufMUi0fleyO6ztNKb90zeVom S4InOunrUYqjLojjLsJu9wGHf52CVdGIeZO+x0SiVtz72iuS/MhGM4XFBji/ee5VzXkC 1O+H5HNH6A+Pd5QOr0VTsw7K2EuCbxMMcFlvfREbHBBjlzPV3CunBQL+lsE+v6rQAhyT FpwBv3izsvO5/EKCHxq4wJEvOettbiXt6fIyguixfEtwPhhy0PI/IFye/aMDmITwVNbz YQdg== X-Gm-Message-State: AOAM531lvq9bt9ixzPIsQmACCc7BkTctdtUSKNHw+ZrfvTtJGzECv1Bt 82Jc1Hu18tjQwWLF4bYkyaI= X-Google-Smtp-Source: ABdhPJwizy+UGiCxGK6z35YEnJ1mBTxkrZDPYnKx9fALEwTlZeqFx3foZ0/CCoWNsf/Ml/nfXgppmg== X-Received: by 2002:a17:90b:4b0d:b0:1bc:4cdb:ebe3 with SMTP id lx13-20020a17090b4b0d00b001bc4cdbebe3mr3961413pjb.176.1647504651256; Thu, 17 Mar 2022 01:10:51 -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 u126-20020a637984000000b0038147b4f53esm4361340pgc.93.2022.03.17.01.10.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Mar 2022 01:10:50 -0700 (PDT) Date: Thu, 17 Mar 2022 08:10: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 , Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [PATCH] mm/slub, kunit: Make slub_kunit unaffected by global slub debugging flags Message-ID: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <46456d7a-fd35-5052-f3c0-a97d25345e79@suse.cz> X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 7579E1C0003 X-Stat-Signature: 7ksi9yds3sf81fydnc1rsjfas1og45b8 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=QR+L0RdM; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com X-Rspam-User: X-HE-Tag: 1647504652-589268 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: slub_kunit does not expect other debugging flags to be set when running tests. When SLAB_RED_ZONE flag is set globally, test fails because the flag affects number of errors reported. To make slub_kunit unaffected by global slub debugging flags, introduce SLAB_NO_GLOBAL_FLAGS to ignore them. It's still allowed to specify debugging flags by specifying cache name(s) in slub_debug parameter. Suggested-by: Vlastimil Babka Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- include/linux/slab.h | 3 +++ lib/slub_kunit.c | 10 +++++----- mm/slab.h | 5 +++-- mm/slub.c | 3 +++ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 0381868e5118..11fe2c28422d 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -112,6 +112,9 @@ #define SLAB_KASAN 0 #endif +/* Ignore globally specified debugging flags */ +#define SLAB_NO_GLOBAL_FLAGS ((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/lib/slub_kunit.c b/lib/slub_kunit.c index 8662dc6cb509..acf061dc558d 100644 --- a/lib/slub_kunit.c +++ b/lib/slub_kunit.c @@ -12,7 +12,7 @@ static int slab_errors; static void test_clobber_zone(struct kunit *test) { struct kmem_cache *s = kmem_cache_create("TestSlub_RZ_alloc", 64, 0, - SLAB_RED_ZONE, NULL); + SLAB_RED_ZONE|SLAB_NO_GLOBAL_FLAGS, NULL); u8 *p = kmem_cache_alloc(s, GFP_KERNEL); kasan_disable_current(); @@ -30,7 +30,7 @@ static void test_clobber_zone(struct kunit *test) static void test_next_pointer(struct kunit *test) { struct kmem_cache *s = kmem_cache_create("TestSlub_next_ptr_free", 64, 0, - SLAB_POISON, NULL); + SLAB_POISON|SLAB_NO_GLOBAL_FLAGS, NULL); u8 *p = kmem_cache_alloc(s, GFP_KERNEL); unsigned long tmp; unsigned long *ptr_addr; @@ -75,7 +75,7 @@ static void test_next_pointer(struct kunit *test) static void test_first_word(struct kunit *test) { struct kmem_cache *s = kmem_cache_create("TestSlub_1th_word_free", 64, 0, - SLAB_POISON, NULL); + SLAB_POISON|SLAB_NO_GLOBAL_FLAGS, NULL); u8 *p = kmem_cache_alloc(s, GFP_KERNEL); kmem_cache_free(s, p); @@ -90,7 +90,7 @@ static void test_first_word(struct kunit *test) static void test_clobber_50th_byte(struct kunit *test) { struct kmem_cache *s = kmem_cache_create("TestSlub_50th_word_free", 64, 0, - SLAB_POISON, NULL); + SLAB_POISON|SLAB_NO_GLOBAL_FLAGS, NULL); u8 *p = kmem_cache_alloc(s, GFP_KERNEL); kmem_cache_free(s, p); @@ -106,7 +106,7 @@ static void test_clobber_50th_byte(struct kunit *test) static void test_clobber_redzone_free(struct kunit *test) { struct kmem_cache *s = kmem_cache_create("TestSlub_RZ_free", 64, 0, - SLAB_RED_ZONE, NULL); + SLAB_RED_ZONE|SLAB_NO_GLOBAL_FLAGS, NULL); u8 *p = kmem_cache_alloc(s, GFP_KERNEL); kasan_disable_current(); diff --git a/mm/slab.h b/mm/slab.h index c7f2abc2b154..69946131208a 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -330,7 +330,7 @@ static inline slab_flags_t kmem_cache_flags(unsigned int object_size, SLAB_ACCOUNT) #elif defined(CONFIG_SLUB) #define SLAB_CACHE_FLAGS (SLAB_NOLEAKTRACE | SLAB_RECLAIM_ACCOUNT | \ - SLAB_TEMPORARY | SLAB_ACCOUNT) + SLAB_TEMPORARY | SLAB_ACCOUNT | SLAB_NO_GLOBAL_FLAGS) #else #define SLAB_CACHE_FLAGS (SLAB_NOLEAKTRACE) #endif @@ -349,7 +349,8 @@ static inline slab_flags_t kmem_cache_flags(unsigned int object_size, SLAB_NOLEAKTRACE | \ SLAB_RECLAIM_ACCOUNT | \ SLAB_TEMPORARY | \ - SLAB_ACCOUNT) + SLAB_ACCOUNT | \ + SLAB_NO_GLOBAL_FLAGS) bool __kmem_cache_empty(struct kmem_cache *); int __kmem_cache_shutdown(struct kmem_cache *); diff --git a/mm/slub.c b/mm/slub.c index 71e8663f6037..2a3cffd7b27f 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1592,6 +1592,9 @@ slab_flags_t kmem_cache_flags(unsigned int object_size, if (flags & SLAB_NOLEAKTRACE) slub_debug_local &= ~SLAB_STORE_USER; + if (flags & SLAB_NO_GLOBAL_FLAGS) + slub_debug_local = 0; + len = strlen(name); next_block = slub_debug_string; /* Go through all blocks of debug options, see if any matches our slab's name */