From patchwork Tue Nov 29 06:33:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Tang X-Patchwork-Id: 13058582 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 6F860C46467 for ; Tue, 29 Nov 2022 13:46:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CA7646B007D; Tue, 29 Nov 2022 08:46:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C30406B007E; Tue, 29 Nov 2022 08:46:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA97A6B0080; Tue, 29 Nov 2022 08:46:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 7C0E26B007E for ; Tue, 29 Nov 2022 08:46:58 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2176D1A09E6 for ; Tue, 29 Nov 2022 06:36:59 +0000 (UTC) X-FDA: 80185522158.13.1DDEC20 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by imf26.hostedemail.com (Postfix) with ESMTP id 1C608140005 for ; Tue, 29 Nov 2022 06:36:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669703818; x=1701239818; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=sS0dUVwwbqCbyVXenUC31s2Bure2EG6lW7uFTvRVHFs=; b=gCHy2an7xBujwVplQ/9nU5wggo54uzsU6+Q7irJeOXyuTISPDKoQkeYf xxfyY8aJh7Ryi8R3wTiwkM4j+y5cUEx/yrNENGp/LsKnrtyfdG+n+8oxA notLGpPzLkcVvH+IZJoygaJ4NH3GufSiXhuuqLsz8SzhU5kJgXD21ASg6 FCU/r6AKj2peuKh0dfyTOZSz+gDF99pLvDzJ8AhySUPWwxnlfmeRtzJ/N QB5VF9CQL2/baGGpkwI9nOeoOBu2xrM1L/adelMGXZM2tvwGceYqr/i9J 64C6k6iijUjNrqMr/A1ksX5W5vwq5nr1EHipURdIH69qQxjmQRviifqN4 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10545"; a="377178775" X-IronPort-AV: E=Sophos;i="5.96,202,1665471600"; d="scan'208";a="377178775" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Nov 2022 22:36:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10545"; a="645784210" X-IronPort-AV: E=Sophos;i="5.96,202,1665471600"; d="scan'208";a="645784210" Received: from feng-clx.sh.intel.com ([10.238.200.228]) by fmsmga007.fm.intel.com with ESMTP; 28 Nov 2022 22:36:53 -0800 From: Feng Tang To: Vlastimil Babka , Andrew Morton , Oliver Glitta , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Marco Elver Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Feng Tang Subject: [PATCH v2 1/2] mm/slub, kunit: add SLAB_SKIP_KFENCE flag for cache creation Date: Tue, 29 Nov 2022 14:33:57 +0800 Message-Id: <20221129063358.3012362-1-feng.tang@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669703818; a=rsa-sha256; cv=none; b=WWO/oR2JzXM1A1SMs1haw1Fo20H8YS1ySI8UH0j3wuaFAQ7pvSBA7OFHAWkbFH+vVYhtmy Prh9hLo2bCMqYdt4dRyozo6vps6lFpLQAf4t80ZTxhkSTwo3gXbK+pF1gXXjv+MlAQasu1 tb+MVNFUN4HimBoEV5bIFBpmizNgX3g= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=gCHy2an7; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf26.hostedemail.com: domain of feng.tang@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=feng.tang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669703818; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=SWOG0vh35TiQqgnUOMXmkjN68hZgLZhawGJcTvL9WC4=; b=6FEBX34Zp6ee0kbpcuuWEQp50AtiI0ezl65ERNmMQDANaatKGuuyXJPx7VVTUBgds+3cYw Y3TvoaEivKDvFuy4gQiH0lqgGNGkkdRXPwTnvNN8Ip4OP7wmOImwaFw5di2+T0wI9O1RkH iUG7CV22uU5HFNC4aexSsrNtTHrrMyo= X-Rspamd-Queue-Id: 1C608140005 Authentication-Results: imf26.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=gCHy2an7; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf26.hostedemail.com: domain of feng.tang@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=feng.tang@intel.com X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: mib5i9r1hx8f5y6bteth5w1kukqdh9ho X-HE-Tag: 1669703817-711118 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: When kfence is enabled, the buffer allocated from the test case could be from a kfence pool, and the operation could be also caught and reported by kfence first, causing the case to fail. With default kfence setting, this is very difficult to be triggered. By changing CONFIG_KFENCE_NUM_OBJECTS from 255 to 16383, and CONFIG_KFENCE_SAMPLE_INTERVAL from 100 to 5, the allocation from kfence did hit 7 times in different slub_kunit cases out of 900 times of boot test. To avoid this, initially we tried is_kfence_address() to check this and repeated allocation till finding a non-kfence address. Vlastimil Babka suggested SLAB_SKIP_KFENCE flag could be used to achieve this more simply. Signed-off-by: Feng Tang --- lib/slub_kunit.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/slub_kunit.c b/lib/slub_kunit.c index 7a0564d7cb7a..a303adf8f11c 100644 --- a/lib/slub_kunit.c +++ b/lib/slub_kunit.c @@ -6,13 +6,15 @@ #include #include "../mm/slab.h" +#define DEFAULT_FLAGS (SLAB_SKIP_KFENCE | SLAB_NO_USER_FLAGS) + static struct kunit_resource resource; 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|SLAB_NO_USER_FLAGS, NULL); + SLAB_RED_ZONE|DEFAULT_FLAGS, NULL); u8 *p = kmem_cache_alloc(s, GFP_KERNEL); kasan_disable_current(); @@ -30,7 +32,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|SLAB_NO_USER_FLAGS, NULL); + SLAB_POISON|DEFAULT_FLAGS, NULL); u8 *p = kmem_cache_alloc(s, GFP_KERNEL); unsigned long tmp; unsigned long *ptr_addr; @@ -75,7 +77,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|SLAB_NO_USER_FLAGS, NULL); + SLAB_POISON|DEFAULT_FLAGS, NULL); u8 *p = kmem_cache_alloc(s, GFP_KERNEL); kmem_cache_free(s, p); @@ -90,7 +92,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|SLAB_NO_USER_FLAGS, NULL); + SLAB_POISON|DEFAULT_FLAGS, NULL); u8 *p = kmem_cache_alloc(s, GFP_KERNEL); kmem_cache_free(s, p); @@ -106,7 +108,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|SLAB_NO_USER_FLAGS, NULL); + SLAB_RED_ZONE|DEFAULT_FLAGS, NULL); u8 *p = kmem_cache_alloc(s, GFP_KERNEL); kasan_disable_current();