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 0D218C00140 for ; Tue, 2 Aug 2022 07:15:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7666E8E0002; Tue, 2 Aug 2022 03:15:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 716148E0001; Tue, 2 Aug 2022 03:15:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5DD348E0002; Tue, 2 Aug 2022 03:15:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4C22E8E0001 for ; Tue, 2 Aug 2022 03:15:40 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 22FF41A0E18 for ; Tue, 2 Aug 2022 07:15:40 +0000 (UTC) X-FDA: 79753792440.27.49D9878 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf04.hostedemail.com (Postfix) with ESMTP id 6A23B400FE for ; Tue, 2 Aug 2022 07:15:39 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 450D16133F; Tue, 2 Aug 2022 07:15:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79FBFC433D6; Tue, 2 Aug 2022 07:15:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659424537; bh=OU7TGxK68vWv69y0xszAk63+oYqYivbkurLi5vKI8cI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=p83QkmjC4ZQZkA01ck97y9rqOZvhlDghckiMuN8M/OI+xpgEma8PuxR2UofjCDu+3 XWE6jvnf3DSKOVqRilDj3rE4MBaxEdh68WxeBsEW5Bw5JNpZ6Pg+7CVVzWI/W/0fXZ a4ZTht5McBmrNY+PGtx40hIvYKt8CVtlwiS0OvZIPEanWCt5TxAwdiB4HmLZAw4V1T DO88B1M8XZLcc2feUJrK+MpidqdL6J2Up3QgUUJoiWwcCuRcQheOLRac7a7B0M0vM6 NYrtx9KsaROennEEqeLtPB48UrpKv8+EHsBpb2gNxvWNgIUtL5PI0HDtvFaZGxv8HE Ip7P3qio7MfZw== Date: Tue, 2 Aug 2022 10:15:24 +0300 From: Mike Rapoport To: shaoqin.huang@intel.com Cc: Karolina Drobnik , Rebecca Mckeever , David Hildenbrand , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] memblock test: Add test to memblock_add() 129th region Message-ID: References: <20220801064901.980558-1-shaoqin.huang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220801064901.980558-1-shaoqin.huang@intel.com> ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=p83QkmjC; spf=pass (imf04.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659424539; a=rsa-sha256; cv=none; b=IeL7PC32OGIayOcrVyZ6VNIE/0bJm171uEX5mP5X4/L9GLB+qb2ZNOt0KQb1I2YxZ3wXQd EbaKRQvqwcAyNgbW+mC2o9MEygSXr3xTY0ubxrzVTf4mdos7Sm/WxArnJ4YCAzO3JobIcH TetipsCBwiPghQ/mImxETlA7yYNtr7k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659424539; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=csbzzXumLlCNIeZM0+QYDzWBYoGCMirYecZZlEtvMAk=; b=WH71evpCtl0kG62CR4IqJ9WaE8RNeXiI2Wb+e0ahZVzy4e+6uWqnudNGcOEe0fj5SKarsH Wgel221x++xUOg7UHtNk1wTR9/AqLnewbrEZTg9bwj5EJ/FLaMFc1JUQ0FSNf8K9NMqvw1 Ixll/EkyQz5J9gC5Iv1SNAR7pdCW2V4= X-Rspamd-Queue-Id: 6A23B400FE Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=p83QkmjC; spf=pass (imf04.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam01 X-Rspam-User: X-Stat-Signature: oqby7nrmhtqdkwox1i3wsk1ahb6a9yn3 X-HE-Tag: 1659424539-307088 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: On Mon, Aug 01, 2022 at 02:48:36PM +0800, shaoqin.huang@intel.com wrote: > From: Shaoqin Huang > > Add 129th region into the memblock, and this will trigger the > memblock_double_array() function, this needs valid memory regions. So > using dummy_physical_memory_init() to allocate some valid memory, when > memblock_double_array() choose a new memory region from memory.regions, > it will always choose a valid memory region if we add all valid memory > region, so the memblock_double_array() must success. > > Another thing should be done is to restore the memory.regions after > memblock_double_array(), due to now the memory.regions is pointing to a > memory region allocated by dummy_physical_memory_init(). And it will > affect the subsequent tests if we don't restore the memory region. So > Simply record the origin region, and restore it after the test. > > Signed-off-by: Shaoqin Huang > --- > Changelog: > ---------- > v2: > - Use ASSERT_EQ() to replace assert(). > - Not to expose memory_block, and add a function get_memory_block_base() to > get the memory_block.base. > - Add two functions for common usage, and now it has been used by this patch > to allocate many valid memory regions and free them at the end. > > tools/testing/memblock/tests/basic_api.c | 54 ++++++++++++++++++++++++ > tools/testing/memblock/tests/common.c | 38 +++++++++++++++-- > tools/testing/memblock/tests/common.h | 6 +++ > 3 files changed, 95 insertions(+), 3 deletions(-) > > diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c > index 66f46f261e66..46948d5a975e 100644 > --- a/tools/testing/memblock/tests/basic_api.c > +++ b/tools/testing/memblock/tests/basic_api.c > @@ -326,6 +326,59 @@ static int memblock_add_twice_check(void) > return 0; > } > > +static int memblock_add_many_check(void) > +{ > + void *base[INIT_MEMBLOCK_REGIONS + 1]; > + void *orig_region; > + struct region r = { > + .base = SZ_16K, > + .size = MEM_SIZE, > + }; > + > + PREFIX_PUSH(); > + > + reset_memblock_regions(); > + memblock_allow_resize(); > + > + dummy_physical_memory_many_init(base, INIT_MEMBLOCK_REGIONS); Why do we need this? dummy_physical_memory_init() allocates the "physical" memory, so to trigger memblock_double_array() it's enough to memblock_add() 129 non-intersecting chunks in the range [memory_block.base, memory_block.base + MEM_SIZE]. If MEM_SIZE of 16k won't be enough, it can be increased. > + > + orig_region = memblock.memory.regions; > + > + /* This adds the 129 memory_region, and makes it double array. */ > + dummy_physical_memory_init(); > + append_memblock(); > + base[INIT_MEMBLOCK_REGIONS] = get_memory_block_base(); > + > + ASSERT_EQ(memblock.memory.cnt, INIT_MEMBLOCK_REGIONS + 1); > + ASSERT_EQ(memblock.memory.total_size, (INIT_MEMBLOCK_REGIONS + 1) * MEM_SIZE); > + ASSERT_EQ(memblock.memory.max, INIT_MEMBLOCK_REGIONS * 2); > + > + /* The base is very small, so it should be insert to the first region. */ > + memblock_add(r.base, r.size); > + ASSERT_EQ(memblock.memory.regions[0].base, r.base); > + ASSERT_EQ(memblock.memory.regions[0].size, r.size); > + > + ASSERT_EQ(memblock.memory.cnt, INIT_MEMBLOCK_REGIONS + 2); > + ASSERT_EQ(memblock.memory.total_size, (INIT_MEMBLOCK_REGIONS + 2) * MEM_SIZE); > + ASSERT_EQ(memblock.memory.max, INIT_MEMBLOCK_REGIONS * 2); > + > + /* Free these allocated memory. */ > + dummy_physical_memory_many_cleanup(base, INIT_MEMBLOCK_REGIONS + 1); > + > + /* > + * The current memory.regions is occupying a range of memory that > + * allocated from dummy_physical_memory_init(). After free the memory, > + * we must not use it. So restore the origin memory region to make sure > + * the tests can run as normal and not affected by the double array. > + */ > + memblock.memory.regions = orig_region; > + memblock.memory.cnt = INIT_MEMBLOCK_REGIONS; > + > + test_pass_pop(); > + > + return 0; > +} > + > static int memblock_add_checks(void) > { > prefix_reset(); > @@ -339,6 +392,7 @@ static int memblock_add_checks(void) > memblock_add_overlap_bottom_check(); > memblock_add_within_check(); > memblock_add_twice_check(); > + memblock_add_many_check(); > > prefix_pop(); > > diff --git a/tools/testing/memblock/tests/common.c b/tools/testing/memblock/tests/common.c > index e43b2676af81..960b3ce07696 100644 > --- a/tools/testing/memblock/tests/common.c > +++ b/tools/testing/memblock/tests/common.c > @@ -5,8 +5,6 @@ > #include > #include > > -#define INIT_MEMBLOCK_REGIONS 128 > -#define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS > #define PREFIXES_MAX 15 > #define DELIM ": " > > @@ -58,10 +56,20 @@ void reset_memblock_attributes(void) > memblock.current_limit = MEMBLOCK_ALLOC_ANYWHERE; > } > > +void *get_memory_block_base(void) > +{ > + return memory_block.base; > +} > + > +void append_memblock(void) > +{ > + memblock_add((phys_addr_t)memory_block.base, MEM_SIZE); > +} > + > void setup_memblock(void) > { > reset_memblock_regions(); > - memblock_add((phys_addr_t)memory_block.base, MEM_SIZE); > + append_memblock(); > } > > void dummy_physical_memory_init(void) > @@ -75,6 +83,30 @@ void dummy_physical_memory_cleanup(void) > free(memory_block.base); > } > > +void dummy_physical_memory_many_init(void *base[], int cnt) > +{ > + int i; > + > + for (i = 0; i < cnt; i++) { > + dummy_physical_memory_init(); > + append_memblock(); > + base[i] = memory_block.base; > + > + ASSERT_EQ(memblock.memory.cnt, i + 1); > + ASSERT_EQ(memblock.memory.total_size, (i + 1) * MEM_SIZE); > + } > +} > + > +void dummy_physical_memory_many_cleanup(void *base[], int cnt) > +{ > + int i; > + > + for (i = 0; i < cnt; i++) { > + memory_block.base = base[i]; > + dummy_physical_memory_cleanup(); > + } > +} > + > static void usage(const char *prog) > { > BUILD_BUG_ON(ARRAY_SIZE(help_opts) != ARRAY_SIZE(long_opts) - 1); > diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock/tests/common.h > index 3e7f23d341d7..848900aa8db6 100644 > --- a/tools/testing/memblock/tests/common.h > +++ b/tools/testing/memblock/tests/common.h > @@ -11,6 +11,8 @@ > #include <../selftests/kselftest.h> > > #define MEM_SIZE SZ_16K > +#define INIT_MEMBLOCK_REGIONS 128 > +#define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS > > /** > * ASSERT_EQ(): > @@ -68,8 +70,12 @@ struct region { > void reset_memblock_regions(void); > void reset_memblock_attributes(void); > void setup_memblock(void); > +void append_memblock(void); > +void *get_memory_block_base(void); > void dummy_physical_memory_init(void); > void dummy_physical_memory_cleanup(void); > +void dummy_physical_memory_many_init(void *base[], int cnt); > +void dummy_physical_memory_many_cleanup(void *base[], int cnt); > void parse_args(int argc, char **argv); > > void test_fail(void); > -- > 2.30.2 > > -- Sincerely yours, Mike.