From nobody Tue Dec 2 02:20:16 2025 Received: from jpms-ob01.noc.sony.co.jp (jpms-ob01.noc.sony.co.jp [211.125.140.164]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E890134B1AD for ; Wed, 19 Nov 2025 10:24:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=211.125.140.164 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763547883; cv=none; b=L0ZFpBJC9ShOWLXcPtS3+7zYynDZE0AznrzaI/C9VAiMWmv+bJRPkpmaTzdiuC3COe4gPmxpOfJZtc671oiEzmYeMMISZIwQLKz6UmXpnRFL9/jnMp5A62xmPUZcv/rzidh2ydyIS0P+q7tcE9BdYE38VDp0CnOSvx3cAv5DMec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763547883; c=relaxed/simple; bh=K5TYCI0mHMpZ4yknzbhbX6whKmjdhswH20rfiGRJ4E0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=oQ11pujD/HAtsqTwt8CLsusueSfnPIX5HkycvMGow/J2vZvatIfrSCQ4CWJRFoUg5NI4eYx+gWRohJ2Xn67bQbGSppVUdL6PY6N9VJCqHMpN9q8i/by/XM9WBLlN92QhHQtDgmlIupDtKgkHQYCukxeKA6GS4F+aCzmY2a+IsJU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sony.com; spf=pass smtp.mailfrom=sony.com; dkim=pass (2048-bit key) header.d=sony.com header.i=@sony.com header.b=f3zigG9f; arc=none smtp.client-ip=211.125.140.164 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sony.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sony.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sony.com header.i=@sony.com header.b="f3zigG9f" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sony.com; s=s1jp; t=1763547881; x=1795083881; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=o7oBE7Mms6z459Ax/SgKvGeg4hLNYSL4xPmGIhkEalk=; b=f3zigG9fvhaE0X49Ky//EauxfaNM0267W0OIRQWu+u7ONKHduG0CAoE0 VWL7R/W+4fRnEvjbXoxtlQ5fIt+z6x/08T9kVUQwRDmXs+vnw8kojIc8d HMb49c7QFknz1cBWWphY6A29vTPMXASdfDG9at0LekkDiTZjt5wEOSeow fF/LcHDTtMgetu+/6GY52aHuC0DqlumkOW3ZMjkzk5tQhlxe3Sy/STDr1 vqym7HDpGfB5PRP0wCnHm9jTDIyAVV40chhylH3ZpobEcRg+6ftbxbihR yTd5wIbcJbWeiaNChmA5FVjv98bAdlgFj14W0ZntNIqp9H+mwWXdPoLnL A==; Received: from unknown (HELO jpmta-ob02.noc.sony.co.jp) ([IPv6:2001:cf8:0:6e7::7]) by jpms-ob01.noc.sony.co.jp with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Nov 2025 19:14:31 +0900 X-IronPort-AV: E=Sophos;i="6.19,227,1754924400"; d="scan'208";a="550187337" Received: from unknown (HELO asagi..) ([43.11.56.84]) by jpmta-ob02.noc.sony.co.jp with ESMTP; 19 Nov 2025 19:14:31 +0900 From: Yohei Kojima To: Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Cc: Yohei Kojima , linux-kernel@vger.kernel.org Subject: [PATCH v1] x86/mm: Fix {split,collapse}_page_count to use PTRS_PER_PMD if necessary Date: Wed, 19 Nov 2025 19:09:21 +0900 Message-ID: <1ed1400d08a3de2d14f944a36efc9b84f9ca6f42.1763546758.git.yohei.kojima@sony.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 split 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. Signed-off-by: Yohei Kojima --- I'm sorry I forgot adding Signed-off-by line. v1: - Add Signed-off-by line - https://lore.kernel.org/all/3d8bca84657d8b22a007a052258be1fb2a7c917d.176= 3531142.git.Yohei.Kojima@sony.com/ --- 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; =20 direct_pages_count[level]--; - if (system_state =3D=3D SYSTEM_RUNNING) { - if (level =3D=3D PG_LEVEL_2M) + if (level =3D=3D PG_LEVEL_2M) { + if (system_state =3D=3D SYSTEM_RUNNING) count_vm_event(DIRECT_MAP_LEVEL2_SPLIT); - else if (level =3D=3D PG_LEVEL_1G) + direct_pages_count[PG_LEVEL_4K] +=3D PTRS_PER_PTE; + } else if (level =3D=3D PG_LEVEL_1G) { + if (system_state =3D=3D SYSTEM_RUNNING) count_vm_event(DIRECT_MAP_LEVEL3_SPLIT); + direct_pages_count[PG_LEVEL_2M] +=3D PTRS_PER_PMD; } - direct_pages_count[level - 1] +=3D PTRS_PER_PTE; } =20 static void collapse_page_count(int level) { direct_pages_count[level]++; - if (system_state =3D=3D SYSTEM_RUNNING) { - if (level =3D=3D PG_LEVEL_2M) + if (level =3D=3D PG_LEVEL_2M) { + if (system_state =3D=3D SYSTEM_RUNNING) count_vm_event(DIRECT_MAP_LEVEL2_COLLAPSE); - else if (level =3D=3D PG_LEVEL_1G) + direct_pages_count[PG_LEVEL_4K] -=3D PTRS_PER_PTE; + } else if (level =3D=3D PG_LEVEL_1G) { + if (system_state =3D=3D SYSTEM_RUNNING) count_vm_event(DIRECT_MAP_LEVEL3_COLLAPSE); + direct_pages_count[PG_LEVEL_2M] -=3D PTRS_PER_PMD; } - direct_pages_count[level - 1] -=3D PTRS_PER_PTE; } =20 void arch_report_meminfo(struct seq_file *m) --=20 2.43.0