[PATCH 1/1] x86/mm/pae: Align up pteval_t, pmdval_t and pudval_t to avoid split locks

From: Javier Pello
Date: Mon Apr 01 2024 - 12:57:41 EST


From: Javier Pello <devel@xxxxxxxx>

When PAE is enabled on x86-32, the types pte_t, pmd_t and pud_t are
defined in terms of pteval_t, pmdval_t and pudval_t, respectively,
all of which are typedefs for u64, which is an 8-byte type with
4-byte alignment. However, variables of these types are subject to
compare-and-exchange operations in their respective native_set_*
functions, which can trigger split locks if a variable spans two
cache lines, for instance on the stack. Annotate these types with
__aligned(8) to avoid this.

Signed-off-by: Javier Pello <devel@xxxxxxxx>
Cc: x86@xxxxxxxxxx
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Borislav Petkov <bp@xxxxxxxxx>
Cc: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
arch/x86/include/asm/pgtable-3level_types.h | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/arch/x86/include/asm/pgtable-3level_types.h b/arch/x86/include/asm/pgtable-3level_types.h
index 80911349..61f62ab4 100644
--- a/arch/x86/include/asm/pgtable-3level_types.h
+++ b/arch/x86/include/asm/pgtable-3level_types.h
@@ -5,12 +5,16 @@
#ifndef __ASSEMBLY__
#include <linux/types.h>

-typedef u64 pteval_t;
-typedef u64 pmdval_t;
-typedef u64 pudval_t;
-typedef u64 p4dval_t;
-typedef u64 pgdval_t;
-typedef u64 pgprotval_t;
+/*
+ * Variables of these types are subject to atomic compare-and-exchange
+ * operations, so they have to be properly aligned to avoid split locks.
+ */
+typedef u64 pteval_t __aligned(8);
+typedef u64 pmdval_t __aligned(8);
+typedef u64 pudval_t __aligned(8);
+typedef u64 p4dval_t __aligned(8);
+typedef u64 pgdval_t __aligned(8);
+typedef u64 pgprotval_t __aligned(8);

typedef union {
struct {
--
2.43.3