Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1249849pxb; Sat, 29 Jan 2022 00:11:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJz3xzV8kdWWeRaDB5bV67E8GIjfiX+3rNv2ftljs1Z92/gvw8Iqf33VeklN0+wcf6jfHCYD X-Received: by 2002:aa7:d94a:: with SMTP id l10mr11800584eds.302.1643443915471; Sat, 29 Jan 2022 00:11:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643443915; cv=none; d=google.com; s=arc-20160816; b=ephNyuNMEYmsHdinR6g+8CaHflfrhYrOC3TxxqFVH8pA4hDhc/zF5rs0bNGg0PMQ4h cYi8EY64QL8XpC7S605s8M4gJ46YEcjHzBqvrwJtEQ0LQFypG71YqDto62Ld9Ijm7wBr gGjhNPwEdJUUt0urdPJaixvxS8Tl2kMPOIs8Jel6RxxRzMs+Hi2QDiiEI+8wmLhBWOcx 03K5fN7pHfjvu729TfQOI5mRcsUMYeY3oZ315Np4pKyW0xVtmoTbKioERWx+9EbNM7rW 3QRKiS+wcWjpTdgQHE7L+PMrhxWMvxaXlGP8Goh88MeDVzglX584UbcxbQeZgsW3SdAM kChA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=8CH0wvcR+CrliiA2gs4dx/6ORq3BjletmBurx0/y3Is=; b=JhvWx+4UK5YrShNgl1KdRFylEdwsz8bWvPguAKmwfaGk7vFee0SHDtqXLcV4V2mVdp 2molufio9eB7l4mVyDuto8fFHcxTsc9MlCyxZKUPLqN/1zdX4H8oklfTPAvNUSOAmWEY AN8TeD++ZhIDEXp5S4xvk4zOc/JHdx9rLl3MhtDiC8DjbzZUk1nESubNr9IQO1rkYOO2 uAK3HwaNiOcRvKfmSCyWypbX3wbU4TmgZiSvH3EGhiRULhItpiyURaNinG6BL/HWEkgl AvYImp7yLLzZV8TWfdC+cfH1DeU+V/quV5OgbGFnnifzGLmrC8kJ2iMym3DVpCe91YIC EOhQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cw12si4661760ejc.992.2022.01.29.00.11.30; Sat, 29 Jan 2022 00:11:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235426AbiA1Bly (ORCPT + 99 others); Thu, 27 Jan 2022 20:41:54 -0500 Received: from szxga01-in.huawei.com ([45.249.212.187]:35879 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230132AbiA1Blx (ORCPT ); Thu, 27 Jan 2022 20:41:53 -0500 Received: from kwepemi500020.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4JlKt34L5PzccpN; Fri, 28 Jan 2022 09:40:59 +0800 (CST) Received: from kwepemm600017.china.huawei.com (7.193.23.234) by kwepemi500020.china.huawei.com (7.221.188.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 28 Jan 2022 09:41:50 +0800 Received: from localhost.localdomain (10.175.112.125) by kwepemm600017.china.huawei.com (7.193.23.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 28 Jan 2022 09:41:49 +0800 From: Peng Liu To: , , , , , , CC: , , , , , Subject: [PATCH v2] kfence: Make test case compatible with run time set sample interval Date: Fri, 28 Jan 2022 01:57:52 +0000 Message-ID: <20220128015752.931256-1-liupeng256@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600017.china.huawei.com (7.193.23.234) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The parameter kfence_sample_interval can be set via boot parameter and late shell command, which is convenient for automatical tests and KFENCE parameter optimation. However, KFENCE test case just use compile time CONFIG_KFENCE_SAMPLE_INTERVAL, this will make KFENCE test case not run as user desired. This patch will make KFENCE test case compatible with run-time-set sample interval. v1->v2: - Use EXPORT_SYMBOL_GPL replace EXPORT_SYMBOL Signed-off-by: Peng Liu --- include/linux/kfence.h | 2 ++ mm/kfence/core.c | 3 ++- mm/kfence/kfence_test.c | 8 ++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/linux/kfence.h b/include/linux/kfence.h index 4b5e3679a72c..f49e64222628 100644 --- a/include/linux/kfence.h +++ b/include/linux/kfence.h @@ -17,6 +17,8 @@ #include #include +extern unsigned long kfence_sample_interval; + /* * We allocate an even number of pages, as it simplifies calculations to map * address to metadata indices; effectively, the very first page serves as an diff --git a/mm/kfence/core.c b/mm/kfence/core.c index 5ad40e3add45..13128fa13062 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -47,7 +47,8 @@ static bool kfence_enabled __read_mostly; -static unsigned long kfence_sample_interval __read_mostly = CONFIG_KFENCE_SAMPLE_INTERVAL; +unsigned long kfence_sample_interval __read_mostly = CONFIG_KFENCE_SAMPLE_INTERVAL; +EXPORT_SYMBOL_GPL(kfence_sample_interval); /* Export for test modules. */ #ifdef MODULE_PARAM_PREFIX #undef MODULE_PARAM_PREFIX diff --git a/mm/kfence/kfence_test.c b/mm/kfence/kfence_test.c index a22b1af85577..50dbb815a2a8 100644 --- a/mm/kfence/kfence_test.c +++ b/mm/kfence/kfence_test.c @@ -268,13 +268,13 @@ static void *test_alloc(struct kunit *test, size_t size, gfp_t gfp, enum allocat * 100x the sample interval should be more than enough to ensure we get * a KFENCE allocation eventually. */ - timeout = jiffies + msecs_to_jiffies(100 * CONFIG_KFENCE_SAMPLE_INTERVAL); + timeout = jiffies + msecs_to_jiffies(100 * kfence_sample_interval); /* * Especially for non-preemption kernels, ensure the allocation-gate * timer can catch up: after @resched_after, every failed allocation * attempt yields, to ensure the allocation-gate timer is scheduled. */ - resched_after = jiffies + msecs_to_jiffies(CONFIG_KFENCE_SAMPLE_INTERVAL); + resched_after = jiffies + msecs_to_jiffies(kfence_sample_interval); do { if (test_cache) alloc = kmem_cache_alloc(test_cache, gfp); @@ -608,7 +608,7 @@ static void test_gfpzero(struct kunit *test) int i; /* Skip if we think it'd take too long. */ - KFENCE_TEST_REQUIRES(test, CONFIG_KFENCE_SAMPLE_INTERVAL <= 100); + KFENCE_TEST_REQUIRES(test, kfence_sample_interval <= 100); setup_test_cache(test, size, 0, NULL); buf1 = test_alloc(test, size, GFP_KERNEL, ALLOCATE_ANY); @@ -739,7 +739,7 @@ static void test_memcache_alloc_bulk(struct kunit *test) * 100x the sample interval should be more than enough to ensure we get * a KFENCE allocation eventually. */ - timeout = jiffies + msecs_to_jiffies(100 * CONFIG_KFENCE_SAMPLE_INTERVAL); + timeout = jiffies + msecs_to_jiffies(100 * kfence_sample_interval); do { void *objects[100]; int i, num = kmem_cache_alloc_bulk(test_cache, GFP_ATOMIC, ARRAY_SIZE(objects), -- 2.18.0.huawei.25