All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/mm: Fix {split,collapse}_page_count to use PTRS_PER_PMD if necessary
@ 2025-11-19  5:46 Yohei Kojima
  2025-11-19 10:33 ` Yohei Kojima
  0 siblings, 1 reply; 2+ messages in thread
From: Yohei Kojima @ 2025-11-19  5:46 UTC (permalink / raw)
  To: Dave Hansen, Andy Lutomirski, Peter Zijlstra, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, x86, H. Peter Anvin
  Cc: Yohei Kojima, linux-kernel

Before this commit, split_page_count() and collapse_page_count() updated
direct_pages_count using PTRS_PER_PTE constant. However, these functions
should use PTRS_PER_PMD if 1G page is splitted into 2M pages and vice
versa because 2M direct pages are managed by PMD.

This commit fixes {split,collapse}_page_count() to use PTRS_PER_PMD in
such cases. The basic behavior of these functions are unchanged because
x86's 1G page split and collapse are currently only supported on 64-bit
environment where PTRS_PER_PTE and PTRS_PER_PMD are both 512.
---
 arch/x86/mm/pat/set_memory.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index 970981893c9b..aa6fa4894edb 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -97,25 +97,29 @@ static void split_page_count(int level)
 		return;
 
 	direct_pages_count[level]--;
-	if (system_state == SYSTEM_RUNNING) {
-		if (level == PG_LEVEL_2M)
+	if (level == PG_LEVEL_2M) {
+		if (system_state == SYSTEM_RUNNING)
 			count_vm_event(DIRECT_MAP_LEVEL2_SPLIT);
-		else if (level == PG_LEVEL_1G)
+		direct_pages_count[PG_LEVEL_4K] += PTRS_PER_PTE;
+	} else if (level == PG_LEVEL_1G) {
+		if (system_state == SYSTEM_RUNNING)
 			count_vm_event(DIRECT_MAP_LEVEL3_SPLIT);
+		direct_pages_count[PG_LEVEL_2M] += PTRS_PER_PMD;
 	}
-	direct_pages_count[level - 1] += PTRS_PER_PTE;
 }
 
 static void collapse_page_count(int level)
 {
 	direct_pages_count[level]++;
-	if (system_state == SYSTEM_RUNNING) {
-		if (level == PG_LEVEL_2M)
+	if (level == PG_LEVEL_2M) {
+		if (system_state == SYSTEM_RUNNING)
 			count_vm_event(DIRECT_MAP_LEVEL2_COLLAPSE);
-		else if (level == PG_LEVEL_1G)
+		direct_pages_count[PG_LEVEL_4K] -= PTRS_PER_PTE;
+	} else if (level == PG_LEVEL_1G) {
+		if (system_state == SYSTEM_RUNNING)
 			count_vm_event(DIRECT_MAP_LEVEL3_COLLAPSE);
+		direct_pages_count[PG_LEVEL_2M] -= PTRS_PER_PMD;
 	}
-	direct_pages_count[level - 1] -= PTRS_PER_PTE;
 }
 
 void arch_report_meminfo(struct seq_file *m)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-19 10:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-19  5:46 [PATCH] x86/mm: Fix {split,collapse}_page_count to use PTRS_PER_PMD if necessary Yohei Kojima
2025-11-19 10:33 ` Yohei Kojima

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.