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>] [day] [month] [year] [list]
Message-Id: <20240604014413.694442-1-acelan.kao@canonical.com>
Date: Tue,  4 Jun 2024 09:44:13 +0800
From: AceLan Kao <acelan.kao@...onical.com>
To: Dave Hansen <dave.hansen@...ux.intel.com>,
	Andy Lutomirski <luto@...nel.org>,
	Peter Zijlstra <peterz@...radead.org>,
	Thomas Gleixner <tglx@...utronix.de>,
	Ingo Molnar <mingo@...hat.com>,
	Borislav Petkov <bp@...en8.de>,
	x86@...nel.org,
	"H. Peter Anvin" <hpa@...or.com>,
	linux-kernel@...r.kernel.org
Subject: [PATCH] x86/mm: Simplify conditionals in PGD synchronization functions

From: "Chia-Lin Kao (AceLan)" <acelan.kao@...onical.com>

This patch streamlines the conditional checks within the sync_global_pgds_l5
and sync_global_pgds_l4 functions. Previously, the code redundantly checked
both reference and target PGD/P4D entries for existence before proceeding
with further actions. This redundancy is unnecessary since the existence of
the reference entries is implied by earlier checks in the code flow.

By assuming the reference PGD/P4D entries (*pgd_ref and *p4d_ref) are always
valid within these conditional checks, we simplify the logic to only check
the target entries (*pgd and *p4d). This change makes the code easier to read
and understand while maintaining its original functionality.

Modifications:
- In sync_global_pgds_l5, removed the redundant check for pgd_none(*pgd_ref)
  when asserting or setting *pgd entries.
- Applied a similar simplification in sync_global_pgds_l4 for *p4d and *p4d_ref
  checks.

This patch does not alter the functionality of these functions but improves
the clarity and efficiency of the code by removing unnecessary conditions.

Signed-off-by: Chia-Lin Kao (AceLan) <acelan.kao@...onical.com>
---
 arch/x86/mm/init_64.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index a0dffaca6d2b..ed964bd081f8 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -155,10 +155,9 @@ static void sync_global_pgds_l5(unsigned long start, unsigned long end)
 			pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
 			spin_lock(pgt_lock);
 
-			if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
+			if (!pgd_none(*pgd))
 				BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
-
-			if (pgd_none(*pgd))
+			else
 				set_pgd(pgd, *pgd_ref);
 
 			spin_unlock(pgt_lock);
@@ -198,11 +197,10 @@ static void sync_global_pgds_l4(unsigned long start, unsigned long end)
 			pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
 			spin_lock(pgt_lock);
 
-			if (!p4d_none(*p4d_ref) && !p4d_none(*p4d))
+			if (!p4d_none(*p4d))
 				BUG_ON(p4d_pgtable(*p4d)
 				       != p4d_pgtable(*p4d_ref));
-
-			if (p4d_none(*p4d))
+			else
 				set_p4d(p4d, *p4d_ref);
 
 			spin_unlock(pgt_lock);
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ