From mboxrd@z Thu Jan 1 00:00:00 1970 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 56D03C433F5 for ; Mon, 7 Feb 2022 01:25:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7162F6B0072; Sun, 6 Feb 2022 20:25:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6C2676B0073; Sun, 6 Feb 2022 20:25:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 563226B0074; Sun, 6 Feb 2022 20:25:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0236.hostedemail.com [216.40.44.236]) by kanga.kvack.org (Postfix) with ESMTP id 42F386B0072 for ; Sun, 6 Feb 2022 20:25:50 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 019C2181C8F1C for ; Mon, 7 Feb 2022 01:25:50 +0000 (UTC) X-FDA: 79114242060.15.4BA7561 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf21.hostedemail.com (Postfix) with ESMTP id B131E1C000B for ; Mon, 7 Feb 2022 01:25:48 +0000 (UTC) Received: from kwepemi500020.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4JsT2j5gTZzcck1; Mon, 7 Feb 2022 09:24:45 +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; Mon, 7 Feb 2022 09:25:44 +0800 Received: from [10.174.179.19] (10.174.179.19) 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; Mon, 7 Feb 2022 09:25:43 +0800 Content-Type: multipart/alternative; boundary="------------WBwpaL1IxONE0il5bX100oVb" Message-ID: <1d0b0a51-8376-db19-2634-036e66692d02@huawei.com> Date: Mon, 7 Feb 2022 09:25:42 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: Re: [PATCH v2] kfence: Make test case compatible with run time set sample interval Content-Language: en-US To: Marco Elver CC: , , , , , , , , , , References: <20220128015752.931256-1-liupeng256@huawei.com> From: "liupeng (DM)" In-Reply-To: X-Originating-IP: [10.174.179.19] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600017.china.huawei.com (7.193.23.234) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: B131E1C000B X-Stat-Signature: q8yxes66eqryg4agqe8ze1s3r1to6zbk X-Rspam-User: nil Authentication-Results: imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of liupeng256@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=liupeng256@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-HE-Tag: 1644197148-296621 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: --------------WBwpaL1IxONE0il5bX100oVb Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit On 2022/1/28 17:49, Marco Elver wrote: > On Fri, 28 Jan 2022 at 02:41, Peng Liu wrote: >> The parameter kfence_sample_interval can be set via boot parameter >> and late shell command, which is convenient for automatical tests > s/automatical/automated/ > >> and KFENCE parameter optimation. However, KFENCE test case just use > s/optimation/optimization/ > >> 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. > I'm not too particular about it, but "This patch" is usually bad style: > https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes I'm sorry for the "bad style", and I will carefully revise later. >> v1->v2: >> - Use EXPORT_SYMBOL_GPL replace EXPORT_SYMBOL > Changelog is usually placed after '---', because it's mostly redundant > once committed. Often maintainers include a "Link" to the original > patch which then has history and discussion. > >> Signed-off-by: Peng Liu > Reviewed-by: Marco Elver > > >> --- >> 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 >> > . I'm sorry for the latency due to the spring festival. Thank you for your advice, and I will send a revised patch later. Thanks, -- Peng Liu --------------WBwpaL1IxONE0il5bX100oVb Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: 7bit


On 2022/1/28 17:49, Marco Elver wrote:
On Fri, 28 Jan 2022 at 02:41, Peng Liu <liupeng256@huawei.com> wrote:
The parameter kfence_sample_interval can be set via boot parameter
and late shell command, which is convenient for automatical tests
s/automatical/automated/

and KFENCE parameter optimation. However, KFENCE test case just use
s/optimation/optimization/

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.
I'm not too particular about it, but "This patch" is usually bad style:
https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes
I'm sorry for the "bad style", and I will carefully revise later.

      
v1->v2:
- Use EXPORT_SYMBOL_GPL replace EXPORT_SYMBOL
Changelog is usually placed after '---', because it's mostly redundant
once committed. Often maintainers include a "Link" to the original
patch which then has history and discussion.

Signed-off-by: Peng Liu <liupeng256@huawei.com>
Reviewed-by: Marco Elver <elver@google.com>


---
 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 <linux/atomic.h>
 #include <linux/static_key.h>

+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

.
I'm sorry for the latency due to the spring festival. Thank you for your advice,
and I will send a revised patch later.

Thanks,
-- Peng Liu
--------------WBwpaL1IxONE0il5bX100oVb--