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: <20240521023957.2587005-7-jaewon31.kim@samsung.com>
Date: Tue, 21 May 2024 11:39:53 +0900
From: Jaewon Kim <jaewon31.kim@...sung.com>
To: rppt@...nel.org, vbabka@...e.cz, akpm@...ux-foundation.org
Cc: linux-mm@...ck.org, linux-kernel@...r.kernel.org,
	jaewon31.kim@...il.com, Jaewon Kim <jaewon31.kim@...sung.com>
Subject: [RESEND PATCH 06/10] memblock: recognize late freed size by
 checking PageReserved

There are some cases in which reserved pages are freed late after the
initial memblock_free_all of mem_init. We'd like to recognize this
late free pages, and update the memsize information.

Because additional job is needed to a no-map or reusable region, the
late free is usually done to a map and unusable region. So only for map
and unusable region, check if some pages within the region is freed. The
freed pages can be recoginzed by checking if PageReserved flag is clear.
To be fast, let's skip other pages within 64 KB range. And this check is
done when a user wants to see the memsize information.

This is an example. If all pages are freed the region size will be 0.

Before
0x0a2300000-0x0a2400000 0x00100000 (    1024 KB )   map unusable latefree

After
0x0a2300000-0x0a2300000 0x00000000 (       0 KB )   map unusable latefree

Signed-off-by: Jaewon Kim <jaewon31.kim@...sung.com>
---
 mm/memblock.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/mm/memblock.c b/mm/memblock.c
index edb2575967ab..de49e7ce74f1 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -2608,6 +2608,39 @@ static int memsize_rgn_cmp(const void *a, const void *b)
 	return 0;
 }
 
+/* assume that freed size is always 64 KB aligned */
+static inline void memblock_memsize_check_size(struct memsize_rgn_struct *rgn)
+{
+	phys_addr_t phy, end, freed = 0;
+	bool has_freed = false;
+	struct page *page;
+
+	if (rgn->reusable || rgn->nomap)
+		return;
+
+	/* check the first page of each 1 MB */
+	phy = rgn->base;
+	end = rgn->base + rgn->size;
+	while (phy < end) {
+		unsigned long pfn = __phys_to_pfn(phy);
+
+		if (!pfn_valid(pfn))
+			return;
+		page = pfn_to_page(pfn);
+		if (!has_freed && !PageReserved(page)) {
+			has_freed = true;
+			freed = phy;
+		} else if (has_freed && PageReserved(page)) {
+			has_freed = false;
+			memblock_memsize_free(freed, phy - freed);
+		}
+
+		if (has_freed && (phy + SZ_64K >= end))
+			memblock_memsize_free(freed, end - freed);
+		phy += SZ_64K;
+	}
+}
+
 static int memblock_memsize_show(struct seq_file *m, void *private)
 {
 	int i;
@@ -2621,6 +2654,7 @@ static int memblock_memsize_show(struct seq_file *m, void *private)
 		long size;
 
 		rgn = &memsize_rgn[i];
+		memblock_memsize_check_size(rgn);
 		base = rgn->base;
 		size = rgn->size;
 		end = base + size;
-- 
2.25.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ