From patchwork Thu Jul 28 19:00:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Shaoqin" X-Patchwork-Id: 12930998 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 9CC1EC19F2B for ; Thu, 28 Jul 2022 03:58:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A732C8E0001; Wed, 27 Jul 2022 23:58:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A22BC6B0072; Wed, 27 Jul 2022 23:58:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91C9C8E0001; Wed, 27 Jul 2022 23:58:10 -0400 (EDT) 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 82BA86B0071 for ; Wed, 27 Jul 2022 23:58:10 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 56543C0DDF for ; Thu, 28 Jul 2022 03:58:10 +0000 (UTC) X-FDA: 79735150740.22.5D5EBA8 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by imf12.hostedemail.com (Postfix) with ESMTP id 58AFA400CD for ; Thu, 28 Jul 2022 03:58:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1658980689; x=1690516689; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=rveEgmV9RWZSzZ8jsgQMx2q5Z94soNvnQgHkt+FOIVI=; b=XUvXnVuqePq7wEI+DWMhCBK2bIKtYzduLg1hyQPUq3MHD6h1/9rCw+xb tvX36NsNDuhRXUzZQN6UuueVNeOA2HOkJEpq4NQc085pdmFVG/fzufFEj +RQYLlk9MvkeLjVy2ckWJCaCi6cEe3Bd0dn0kYV0l/bcWRMXTiomLP5UT grdg7DKZZykxtcNRlAFa1yZCwLJo/O30Bz1K6epNf9uL1hvHZlBkGzVkT jIkj2efpREFaJy+tAkH/Nst7C7FKRbF2nSbd+WEQTirk3igJWk6QvFjAP bR36+GkGD1CkbdV5kpuB/OYnGd9q/CZ/6oZZesaG2u2GqOqbTM4RxoXqZ g==; X-IronPort-AV: E=McAfee;i="6400,9594,10421"; a="314199416" X-IronPort-AV: E=Sophos;i="5.93,196,1654585200"; d="scan'208";a="314199416" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2022 20:58:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,196,1654585200"; d="scan'208";a="668640698" Received: from q.bj.intel.com ([10.238.154.102]) by fmsmga004.fm.intel.com with ESMTP; 27 Jul 2022 20:58:01 -0700 From: shaoqin.huang@intel.com To: rppt@kernel.org Cc: Shaoqin Huang , Karolina Drobnik , David Hildenbrand , Rebecca Mckeever , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] memblock test: Add test to memblock_add() 129th region Date: Thu, 28 Jul 2022 13:00:47 -0600 Message-Id: <20220728190051.237437-1-shaoqin.huang@intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=XUvXnVuq; spf=pass (imf12.hostedemail.com: domain of shaoqin.huang@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=shaoqin.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658980690; a=rsa-sha256; cv=none; b=6V5XmZ0KQdjrmZ+cDyyxdpQJYhIBZKGRH1ZQudQSXztc+mC+y2E99xnMevV8L3sZFc9i2T 39797OjSx3/N8ONboO8VLWtiE9XGx/IPprBTziCJYZC/izH7lrL/qfcIGecsNes24E1uJB lfiw/VyJfGKlTCjM4wblaCZpIFqpxJ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658980690; 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=zsBBY7J2O6DHatiZO2ZjIJu31CKlahj9deWKvSVl5+4=; b=J0kHINsSbD/0WS0iXrGgLfSIBQmjd16qERzywrxCnwCYnkgGpszBqWsnqmzRGjYrRg2uHO a0XLC3PAy0LygKoprRu9FFMdl7c1WwkvrOj7Xg+chKxrMiyVI4M/daNMPaIgY8WVeyo6WC kB95FkmXEiMXzNq2EX1SnfX0r+aiiMM= X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 58AFA400CD Authentication-Results: imf12.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=XUvXnVuq; spf=pass (imf12.hostedemail.com: domain of shaoqin.huang@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=shaoqin.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Stat-Signature: amiymsnks8hgf6f9dxzeyw9ude4wofir X-Rspam-User: X-HE-Tag: 1658980689-318871 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: 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 --- tools/testing/memblock/tests/basic_api.c | 65 ++++++++++++++++++++++++ tools/testing/memblock/tests/common.c | 9 ++-- tools/testing/memblock/tests/common.h | 5 ++ 3 files changed, 76 insertions(+), 3 deletions(-) diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c index 66f46f261e66..ded93f97d98e 100644 --- a/tools/testing/memblock/tests/basic_api.c +++ b/tools/testing/memblock/tests/basic_api.c @@ -326,6 +326,70 @@ static int memblock_add_twice_check(void) return 0; } +static int memblock_add_many_check(void) +{ + int i; + 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(); + + for (i = 0; i < INIT_MEMBLOCK_REGIONS; i++) { + dummy_physical_memory_init(); + append_memblock(); + base[i] = memory_block.base; + + assert(memblock.memory.cnt == i + 1); + assert(memblock.memory.total_size == (i + 1) * MEM_SIZE); + } + + orig_region = memblock.memory.regions; + + /* This adds the 129 memory_region, and makes it double array. */ + dummy_physical_memory_init(); + append_memblock(); + base[i] = memory_block.base; + + assert(memblock.memory.cnt == INIT_MEMBLOCK_REGIONS + 1); + assert(memblock.memory.total_size == (INIT_MEMBLOCK_REGIONS + 1) * MEM_SIZE); + assert(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(memblock.memory.regions[0].base == r.base); + assert(memblock.memory.regions[0].size == r.size); + + assert(memblock.memory.cnt == INIT_MEMBLOCK_REGIONS + 2); + assert(memblock.memory.total_size == (INIT_MEMBLOCK_REGIONS + 2) * MEM_SIZE); + assert(memblock.memory.max == INIT_MEMBLOCK_REGIONS * 2); + + /* Free these allocated memory. */ + for (i = 0; i < INIT_MEMBLOCK_REGIONS + 1; i++) { + memory_block.base = base[i]; + dummy_physical_memory_cleanup(); + } + + /* + * 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 +403,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..4741e860123a 100644 --- a/tools/testing/memblock/tests/common.c +++ b/tools/testing/memblock/tests/common.c @@ -5,12 +5,10 @@ #include #include -#define INIT_MEMBLOCK_REGIONS 128 -#define INIT_MEMBLOCK_RESERVED_REGIONS INIT_MEMBLOCK_REGIONS #define PREFIXES_MAX 15 #define DELIM ": " -static struct test_memory memory_block; +struct test_memory memory_block; static const char __maybe_unused *prefixes[PREFIXES_MAX]; static int __maybe_unused nr_prefixes; @@ -64,6 +62,11 @@ void setup_memblock(void) memblock_add((phys_addr_t)memory_block.base, MEM_SIZE); } +void append_memblock(void) +{ + memblock_add((phys_addr_t)memory_block.base, MEM_SIZE); +} + void dummy_physical_memory_init(void) { memory_block.base = malloc(MEM_SIZE); diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock/tests/common.h index 3e7f23d341d7..8946a3b77f24 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(): @@ -65,9 +67,12 @@ struct region { phys_addr_t size; }; +extern struct test_memory memory_block; + void reset_memblock_regions(void); void reset_memblock_attributes(void); void setup_memblock(void); +void append_memblock(void); void dummy_physical_memory_init(void); void dummy_physical_memory_cleanup(void); void parse_args(int argc, char **argv);