From patchwork Wed Apr 6 06:00:03 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: 12802531 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 3ED48C433EF for ; Wed, 6 Apr 2022 06:00:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84BAD6B0072; Wed, 6 Apr 2022 02:00:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7FA996B0073; Wed, 6 Apr 2022 02:00:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69BB56B0074; Wed, 6 Apr 2022 02:00:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0076.hostedemail.com [216.40.44.76]) by kanga.kvack.org (Postfix) with ESMTP id 5C3506B0072 for ; Wed, 6 Apr 2022 02:00:23 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 06BB5183C478E for ; Wed, 6 Apr 2022 06:00:13 +0000 (UTC) X-FDA: 79325403906.24.2B36407 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf27.hostedemail.com (Postfix) with ESMTP id 4E4AA40020 for ; Wed, 6 Apr 2022 06:00:12 +0000 (UTC) Received: by mail-pl1-f177.google.com with SMTP id i11so1057383plg.12 for ; Tue, 05 Apr 2022 23:00:12 -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=/7k7BLrcYuJWJ2LfF588XAam7OTZKNG4+QW50WUfUWI=; b=Gczx/EvG+a86wqSu8aHJxNClwfG7lXZXZkK4KsLf7lRrpO/J+ViVSrrskxM+Lke708 PtF6/Rr9RhA2YKxB84o30BDp7zsu9ffE/lAW+mhgC28itbciTYvfNrpmMuS27Aadjg/8 Z9E6aLMDCejESgs9h7J9E2MyoGJEujRByfDm7qr3t/aUUATl8FKw1ko51uYsPJz5lewK Xfi8T1y6umc42Q7VvIdDr+MoTqDYdMQuOX/FA7nveY/Kc6V9yYxKcW1BKwVPHPUOCsq+ R7U8Vm7kvHDGYVDjfumnYMH2eK8/YFr4fieVDjQ4uxgJDCfuTQf6uAR1EBAO81dvPyhc p0lA== 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=/7k7BLrcYuJWJ2LfF588XAam7OTZKNG4+QW50WUfUWI=; b=1HPkdVxBsg8VBOz8ghWAGdIJ1/2KpRzTzZvB+JWBIFDrQJAALEk+tFhr9aDMMjV1pG 93fArmaruXfkx8Zgx7s/N8eYEJHIPqmok8qOsVg99mwAKHpghyaF9XxjUyg5FYSUjVJ4 Plzu4dKfpGUOrz23SukaFSdQHfViEmN7K8RGN9z4ska+Yga6ppuaxfYw2p5sddpVni4Z rdkLYVXJ14oBtWeNxrOaoorfMHC8zF9PzxchX8R9Ti/0SMH4a6nHiVkdHXskbo/uYvl6 6su3cJlw12Yc4Zlb1okUdP9rO3eKpkqujD0H5NvYMdVh0Vvzr5VctbKXcInFv6c1f4JD t2zQ== X-Gm-Message-State: AOAM5327eul90q5pM8lEZwIUlD2fBhor6Wl6fu37cMWY/sBUYtLMHPQ4 Srgq+0QHfGYnKm06oKUb0Uk= X-Google-Smtp-Source: ABdhPJzz2my7aC+TNMFfmUiVb3SaD7oZrJR5osrjkw2UvwbaXipDO9P4q4HR47vJOas+6LNwMp1Gwg== X-Received: by 2002:a17:902:a710:b0:156:5650:f94a with SMTP id w16-20020a170902a71000b001565650f94amr6942507plq.86.1649224811131; Tue, 05 Apr 2022 23:00:11 -0700 (PDT) Received: from hyeyoo ([114.29.24.243]) by smtp.gmail.com with ESMTPSA id m8-20020a056a00080800b004faa4e113bfsm18521147pfk.154.2022.04.05.23.00.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 23:00:10 -0700 (PDT) Date: Wed, 6 Apr 2022 15:00:03 +0900 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: [PATCH v2] mm/slub, kunit: Make slub_kunit unaffected by user specified flags Message-ID: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="Gczx/EvG"; spf=pass (imf27.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: my69am3srdcrxx7w7y9twhjfcbyom5pd X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 4E4AA40020 X-HE-Tag: 1649224812-493003 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 user specified debugging flags, introduce SLAB_NO_USER_FLAGS to ignore them. With this flag, only flags specified in the code are used and others are ignored. Suggested-by: Vlastimil Babka Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- include/linux/slab.h | 7 +++++++ lib/slub_kunit.c | 10 +++++----- mm/slab.h | 5 +++-- mm/slub.c | 3 +++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 373b3ef99f4e..11ceddcae9f4 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -112,6 +112,13 @@ #define SLAB_KASAN 0 #endif +/* + * Ignore user specified debugging flags. + * Intended for caches created for self-tests so they have only flags + * specified in the code and other flags are ignored. + */ +#define SLAB_NO_USER_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..7a0564d7cb7a 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_USER_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_USER_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_USER_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_USER_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_USER_FLAGS, NULL); u8 *p = kmem_cache_alloc(s, GFP_KERNEL); kasan_disable_current(); diff --git a/mm/slab.h b/mm/slab.h index fd7ae2024897..f7d018100994 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -331,7 +331,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_USER_FLAGS) #else #define SLAB_CACHE_FLAGS (SLAB_NOLEAKTRACE) #endif @@ -350,7 +350,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_USER_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 74d92aa4a3a2..4c78f5919356 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1584,6 +1584,9 @@ slab_flags_t kmem_cache_flags(unsigned int object_size, slab_flags_t block_flags; slab_flags_t slub_debug_local = slub_debug; + if (flags & SLAB_NO_USER_FLAGS) + return flags; + /* * If the slab cache is for debugging (e.g. kmemleak) then * don't store user (stack trace) information by default,