Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp384153rwb; Mon, 28 Nov 2022 23:04:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf5/LyE7XZmb4fyBR3xSWR4Hm1njPmT7KSsHtA/lL7rio6L2/Z3ZDIruUGyQusPvJLFNLBgA X-Received: by 2002:a17:902:6943:b0:188:ab16:2393 with SMTP id k3-20020a170902694300b00188ab162393mr39015672plt.87.1669705496333; Mon, 28 Nov 2022 23:04:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669705496; cv=none; d=google.com; s=arc-20160816; b=WJs0MzxcYuuFo53e0Rm92RHNaCqOGlSb0pFeM1qlzypjeNwIlU8yp40pHHYeGjyXhp 5kPFYQt22tyI8mT+xPnvYUfbDQV4hYrUsrkDSEI6KGyh3GjJjE155DVRygqO4kA3LBFC LRWAO4HAQDAUvRRa2o25bcJo5qhSKBengoNjQuIC46RwJ5t4ZloY6BHlwVtPAwAqvQbe YbFI6nLUD0STyOleXZ7y1cZ/F43s7h1I3hm2qy7/e2ZQmqo6d7IDEXmqRWwGqlUno0mf orMLxB11MM+/mmYl5WhD27T/OtmcXNegQZkPheiJQBSDbmMBCYPUznX4dcJk1pWuf121 1vlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=SWOG0vh35TiQqgnUOMXmkjN68hZgLZhawGJcTvL9WC4=; b=CqmQO8GSipE/K3sB9Ch2Es/WYhUwe8n4oZRKqs8AfF67wAZgqOOTHZ1FHrohx04G6x w5Zdw4HR/wSoYsOsfZ+mtb4hwd1k9L+IYCnlKQ3FELsq9nD0qKoFDEyYlcInyoVq20/U A9Wp5UL4uALpw7ooo/CxHW1GXEj0e5xcxoQRrY/ht052r4HZgvDmYFnap78sH9Zaq0DP o4u1fMwHs7dNiYi64gf0IlUkQJstCAm6PVEMat2hE9A63mc10dgZ5MoC1SjHlqhJ4q0r lAyAkYXSAPmU56dRhswgYUNfyMzqs/1OYugVVLZHkloXTyb+JErdqf6LrDd6tIZkZ/56 uPDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YhqTiB94; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v13-20020a63464d000000b00477ae8def63si13635249pgk.495.2022.11.28.23.04.44; Mon, 28 Nov 2022 23:04:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YhqTiB94; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229509AbiK2Gg6 (ORCPT + 83 others); Tue, 29 Nov 2022 01:36:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbiK2Gg5 (ORCPT ); Tue, 29 Nov 2022 01:36:57 -0500 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C964E528A8 for ; Mon, 28 Nov 2022 22:36:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669703816; x=1701239816; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=sS0dUVwwbqCbyVXenUC31s2Bure2EG6lW7uFTvRVHFs=; b=YhqTiB94Cl/0CAxJ4eYzlo8gc0S2D+NBn8Kw+ggkHJnCYKF0NmZDDfhz dSuxeAWgIBlqYzIArBgjOzrNR88WFWfkiyoSqJyL8jB8l38CraEvm8UB8 FEEddru8d33Q0wezDgn5JoUGM3VJ25sB4NkwaDvNcpLniJfZhKTt23+/x kmYBkpo/bJ/FvL5PtSyOvJko8blN/5w0qkuA1odyQhAcgfkQ1MGtjO92e NUBfa7kIZ/vUYYmIztlvu0n8X/5a6Z7DOIg6mKN7ekz8bdcPNiURzljmT ZAvcmitSedkkeEvLuTWrscdgW6VyUvwb/IG/yBibykb3lq2INSBvGCo0i Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10545"; a="377178779" X-IronPort-AV: E=Sophos;i="5.96,202,1665471600"; d="scan'208";a="377178779" 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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(); -- 2.34.1