lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Fri,  2 Sep 2022 15:10:45 +0800
From:   Song Chen <chensong_2000@....cn>
To:     karolinadrobnik@...il.com, rppt@...nel.org, david@...hat.com,
        remckee0@...il.com, shaoqin.huang@...el.com
Cc:     linux-kernel@...r.kernel.org, linux-mm@...ck.org,
        Song Chen <chensong_2000@....cn>
Subject: [PATCH] tools/testing/memblock: add double array test

By default, there are 128 memblock_regions in memblock.memory.regions.
This test is trying to add the 129th region by calling memblock_add,
expects to trigger memblock_double_array.

The test will pass if
    memblock.memory.cnt == 129 and
    memblock.memory.max == 256

Below is the output:

./main -v
Running memblock_double_array tests...
memblock_add: [0x7fffdccdf0a0a-0x7fffdccdf080a] 0x5616cca50dc4S
.....
memblock_add: [0x7fffdccdf0a0a-0x7fffdccdf080a] 0x5616cca50de4S
memblock: memory is doubled to 256 at [0x7fffdccdeeb0a-0x7fffdccdeed0a]
ok 25 : memblock_double_array: passed

Signed-off-by: Song Chen <chensong_2000@....cn>
---
 tools/testing/memblock/tests/basic_api.c | 42 ++++++++++++++++++++++++
 tools/testing/memblock/tests/common.c    |  5 ---
 tools/testing/memblock/tests/common.h    |  4 +++
 3 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c
index 66f46f261e66..e668ceff2f10 100644
--- a/tools/testing/memblock/tests/basic_api.c
+++ b/tools/testing/memblock/tests/basic_api.c
@@ -8,6 +8,7 @@
 #define FUNC_RESERVE					"memblock_reserve"
 #define FUNC_REMOVE					"memblock_remove"
 #define FUNC_FREE					"memblock_free"
+#define FUNC_DOUBLE_ARRAY			"memblock_double_array"
 
 static int memblock_initialization_check(void)
 {
@@ -1180,6 +1181,46 @@ static int memblock_free_checks(void)
 	return 0;
 }
 
+/*
+ * A simple test that adds to 129 memory blocks.
+ * Expect the region max doubled.
+ */
+static int memblock_double_array_check(void)
+{
+	int i;
+	struct memblock_region *regions = memblock.memory.regions;
+	struct region r = {
+		.base = 0,
+		.size = SZ_512,
+	};
+
+	prefix_reset();
+	prefix_push(FUNC_DOUBLE_ARRAY);
+	test_print("Running %s tests...\n", FUNC_DOUBLE_ARRAY);
+
+	dummy_physical_memory_init();
+	reset_memblock_attributes();
+	setup_memblock();
+	memblock_allow_resize();
+
+	for (i = 0; i < INIT_MEMBLOCK_REGIONS; i++) {
+		r.base += SZ_1K;
+		memblock_add(r.base, r.size);
+	}
+
+	ASSERT_EQ(memblock.memory.cnt, INIT_MEMBLOCK_REGIONS + 1);
+	ASSERT_EQ(memblock.memory.max, INIT_MEMBLOCK_REGIONS * 2);
+
+	memblock.memory.regions = regions;
+	memblock.memory.cnt = INIT_MEMBLOCK_REGIONS;
+	dummy_physical_memory_cleanup();
+
+	test_pass_pop();
+
+	return 0;
+}
+
+
 int memblock_basic_checks(void)
 {
 	memblock_initialization_check();
@@ -1187,6 +1228,7 @@ int memblock_basic_checks(void)
 	memblock_reserve_checks();
 	memblock_remove_checks();
 	memblock_free_checks();
+	memblock_double_array_check();
 
 	return 0;
 }
diff --git a/tools/testing/memblock/tests/common.c b/tools/testing/memblock/tests/common.c
index e43b2676af81..1d295a71ad44 100644
--- a/tools/testing/memblock/tests/common.c
+++ b/tools/testing/memblock/tests/common.c
@@ -5,11 +5,6 @@
 #include <linux/memory_hotplug.h>
 #include <linux/build_bug.h>
 
-#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;
 static const char __maybe_unused *prefixes[PREFIXES_MAX];
 static int __maybe_unused nr_prefixes;
diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock/tests/common.h
index 3e7f23d341d7..13559825ddca 100644
--- a/tools/testing/memblock/tests/common.h
+++ b/tools/testing/memblock/tests/common.h
@@ -11,6 +11,10 @@
 #include <../selftests/kselftest.h>
 
 #define MEM_SIZE SZ_16K
+#define INIT_MEMBLOCK_REGIONS			128
+#define INIT_MEMBLOCK_RESERVED_REGIONS		INIT_MEMBLOCK_REGIONS
+#define PREFIXES_MAX				15
+#define DELIM					": "
 
 /**
  * ASSERT_EQ():
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ