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-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <5cc1ba9a0ade922dbf4ba450165b81a9ed17d4a9.1646055639.git.karolinadrobnik@gmail.com>
Date:   Mon, 28 Feb 2022 15:46:43 +0100
From:   Karolina Drobnik <karolinadrobnik@...il.com>
To:     linux-mm@...ck.org
Cc:     rppt@...nel.org, akpm@...ux-foundation.org,
        linux-kernel@...r.kernel.org,
        Karolina Drobnik <karolinadrobnik@...il.com>
Subject: [PATCH 1/9] memblock tests: Split up reset_memblock function

All memblock data structure fields are reset in one function. In some
test cases, it's preferred to reset memory region arrays without
modifying other values like allocation direction flag.

Extract two functions from reset_memblock, so it's possible to reset
different parts of memblock:
  - reset_memblock_regions    - reset region arrays and their counters
  - reset_memblock_attributes - set other fields to their default values

Update checks in basic_api.c to use new definitions. Remove
reset_memblock call from memblock_initialization_check, so the true
initial values are tested.

Signed-off-by: Karolina Drobnik <karolinadrobnik@...il.com>
---
 tools/testing/memblock/tests/basic_api.c | 48 ++++++++++++------------
 tools/testing/memblock/tests/common.c    | 14 ++++---
 tools/testing/memblock/tests/common.h    |  3 +-
 3 files changed, 33 insertions(+), 32 deletions(-)

diff --git a/tools/testing/memblock/tests/basic_api.c b/tools/testing/memblock/tests/basic_api.c
index fbb989f6ddbf..d5035a3dcce8 100644
--- a/tools/testing/memblock/tests/basic_api.c
+++ b/tools/testing/memblock/tests/basic_api.c
@@ -8,8 +8,6 @@

 static int memblock_initialization_check(void)
 {
-	reset_memblock();
-
 	assert(memblock.memory.regions);
 	assert(memblock.memory.cnt == 1);
 	assert(memblock.memory.max == EXPECTED_MEMBLOCK_REGIONS);
@@ -43,7 +41,7 @@ static int memblock_add_simple_check(void)
 		.size = SZ_4M
 	};

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_add(r.base, r.size);

 	assert(rgn->base == r.base);
@@ -72,7 +70,7 @@ static int memblock_add_node_simple_check(void)
 		.size = SZ_16M
 	};

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_add_node(r.base, r.size, 1, MEMBLOCK_HOTPLUG);

 	assert(rgn->base == r.base);
@@ -110,7 +108,7 @@ static int memblock_add_disjoint_check(void)
 		.size = SZ_8K
 	};

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_add(r1.base, r1.size);
 	memblock_add(r2.base, r2.size);

@@ -151,7 +149,7 @@ static int memblock_add_overlap_top_check(void)

 	total_size = (r1.base - r2.base) + r1.size;

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_add(r1.base, r1.size);
 	memblock_add(r2.base, r2.size);

@@ -190,7 +188,7 @@ static int memblock_add_overlap_bottom_check(void)

 	total_size = (r2.base - r1.base) + r2.size;

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_add(r1.base, r1.size);
 	memblock_add(r2.base, r2.size);

@@ -225,7 +223,7 @@ static int memblock_add_within_check(void)
 		.size = SZ_1M
 	};

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_add(r1.base, r1.size);
 	memblock_add(r2.base, r2.size);

@@ -249,7 +247,7 @@ static int memblock_add_twice_check(void)
 		.size = SZ_2M
 	};

-	reset_memblock();
+	reset_memblock_regions();

 	memblock_add(r.base, r.size);
 	memblock_add(r.base, r.size);
@@ -290,7 +288,7 @@ static int memblock_reserve_simple_check(void)
 		.size = SZ_128M
 	};

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_reserve(r.base, r.size);

 	assert(rgn->base == r.base);
@@ -321,7 +319,7 @@ static int memblock_reserve_disjoint_check(void)
 		.size = SZ_512M
 	};

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_reserve(r1.base, r1.size);
 	memblock_reserve(r2.base, r2.size);

@@ -364,7 +362,7 @@ static int memblock_reserve_overlap_top_check(void)

 	total_size = (r1.base - r2.base) + r1.size;

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_reserve(r1.base, r1.size);
 	memblock_reserve(r2.base, r2.size);

@@ -404,7 +402,7 @@ static int memblock_reserve_overlap_bottom_check(void)

 	total_size = (r2.base - r1.base) + r2.size;

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_reserve(r1.base, r1.size);
 	memblock_reserve(r2.base, r2.size);

@@ -440,7 +438,7 @@ static int memblock_reserve_within_check(void)
 		.size = SZ_64K
 	};

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_reserve(r1.base, r1.size);
 	memblock_reserve(r2.base, r2.size);

@@ -465,7 +463,7 @@ static int memblock_reserve_twice_check(void)
 		.size = SZ_2M
 	};

-	reset_memblock();
+	reset_memblock_regions();

 	memblock_reserve(r.base, r.size);
 	memblock_reserve(r.base, r.size);
@@ -511,7 +509,7 @@ static int memblock_remove_simple_check(void)
 		.size = SZ_4M
 	};

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_add(r1.base, r1.size);
 	memblock_add(r2.base, r2.size);
 	memblock_remove(r1.base, r1.size);
@@ -545,7 +543,7 @@ static int memblock_remove_absent_check(void)
 		.size = SZ_1G
 	};

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_add(r1.base, r1.size);
 	memblock_remove(r2.base, r2.size);

@@ -585,7 +583,7 @@ static int memblock_remove_overlap_top_check(void)
 	r2_end = r2.base + r2.size;
 	total_size = r1_end - r2_end;

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_add(r1.base, r1.size);
 	memblock_remove(r2.base, r2.size);

@@ -623,7 +621,7 @@ static int memblock_remove_overlap_bottom_check(void)

 	total_size = r2.base - r1.base;

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_add(r1.base, r1.size);
 	memblock_remove(r2.base, r2.size);

@@ -665,7 +663,7 @@ static int memblock_remove_within_check(void)
 	r2_size = (r1.base + r1.size) - (r2.base + r2.size);
 	total_size = r1_size + r2_size;

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_add(r1.base, r1.size);
 	memblock_remove(r2.base, r2.size);

@@ -715,7 +713,7 @@ static int memblock_free_simple_check(void)
 		.size = SZ_1M
 	};

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_reserve(r1.base, r1.size);
 	memblock_reserve(r2.base, r2.size);
 	memblock_free((void *)r1.base, r1.size);
@@ -749,7 +747,7 @@ static int memblock_free_absent_check(void)
 		.size = SZ_128M
 	};

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_reserve(r1.base, r1.size);
 	memblock_free((void *)r2.base, r2.size);

@@ -787,7 +785,7 @@ static int memblock_free_overlap_top_check(void)

 	total_size = (r1.size + r1.base) - (r2.base + r2.size);

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_reserve(r1.base, r1.size);
 	memblock_free((void *)r2.base, r2.size);

@@ -824,7 +822,7 @@ static int memblock_free_overlap_bottom_check(void)

 	total_size = r2.base - r1.base;

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_reserve(r1.base, r1.size);
 	memblock_free((void *)r2.base, r2.size);

@@ -867,7 +865,7 @@ static int memblock_free_within_check(void)
 	r2_size = (r1.base + r1.size) - (r2.base + r2.size);
 	total_size = r1_size + r2_size;

-	reset_memblock();
+	reset_memblock_regions();
 	memblock_reserve(r1.base, r1.size);
 	memblock_free((void *)r2.base, r2.size);

diff --git a/tools/testing/memblock/tests/common.c b/tools/testing/memblock/tests/common.c
index 03de6eab0c3c..dd7e87c589fe 100644
--- a/tools/testing/memblock/tests/common.c
+++ b/tools/testing/memblock/tests/common.c
@@ -5,23 +5,25 @@
 #define INIT_MEMBLOCK_REGIONS			128
 #define INIT_MEMBLOCK_RESERVED_REGIONS		INIT_MEMBLOCK_REGIONS

-void reset_memblock(void)
+void reset_memblock_regions(void)
 {
 	memset(memblock.memory.regions, 0,
 	       memblock.memory.cnt * sizeof(struct memblock_region));
-	memset(memblock.reserved.regions, 0,
-	       memblock.reserved.cnt * sizeof(struct memblock_region));
-
 	memblock.memory.cnt	= 1;
 	memblock.memory.max	= INIT_MEMBLOCK_REGIONS;
-	memblock.memory.name	= "memory";
 	memblock.memory.total_size = 0;

+	memset(memblock.reserved.regions, 0,
+	       memblock.reserved.cnt * sizeof(struct memblock_region));
 	memblock.reserved.cnt	= 1;
 	memblock.reserved.max	= INIT_MEMBLOCK_RESERVED_REGIONS;
-	memblock.reserved.name	= "reserved";
 	memblock.reserved.total_size = 0;
+}

+void reset_memblock_attributes(void)
+{
+	memblock.memory.name	= "memory";
+	memblock.reserved.name	= "reserved";
 	memblock.bottom_up	= false;
 	memblock.current_limit	= MEMBLOCK_ALLOC_ANYWHERE;
 }
diff --git a/tools/testing/memblock/tests/common.h b/tools/testing/memblock/tests/common.h
index 48efc4270ea1..b864c64fb60f 100644
--- a/tools/testing/memblock/tests/common.h
+++ b/tools/testing/memblock/tests/common.h
@@ -10,6 +10,7 @@ struct region {
 	phys_addr_t size;
 };

-void reset_memblock(void);
+void reset_memblock_regions(void);
+void reset_memblock_attributes(void);

 #endif
--
2.30.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ