From: "David Hildenbrand (Arm)" <[email protected]> As pgd_t is returned from a function like pgdp_get(), pgd_t shouldn't be an array.
So, just use an u64, and extract the right 32bit value in pgd_val(). Leave the STRICT_MM_TYPECHECKS case alone for now. As an alternative, the STRICT_MM_TYPECHECKS approach could be used here as well, but using an u64 looks conceptually cleaner, even though pgd_val() gets a bit more involved. Signed-off-by: David Hildenbrand (Arm) <[email protected]> --- arch/arm/include/asm/pgtable-2level-types.h | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/arch/arm/include/asm/pgtable-2level-types.h b/arch/arm/include/asm/pgtable-2level-types.h index 650e793f4142..805044ea315b 100644 --- a/arch/arm/include/asm/pgtable-2level-types.h +++ b/arch/arm/include/asm/pgtable-2level-types.h @@ -25,7 +25,7 @@ typedef struct { pteval_t pgprot; } pgprot_t; #define pte_val(x) ((x).pte) #define pmd_val(x) ((x).pmd) -#define pgd_val(x) ((x).pgd[0]) +#define pgd_val(x) ((x).pgd[0]) #define pgprot_val(x) ((x).pgprot) #define __pte(x) ((pte_t) { (x) } ) @@ -36,14 +36,28 @@ typedef struct { pteval_t pgprot; } pgprot_t; /* * .. while these make it easier on the compiler */ +typedef u64 pgdval_t; + typedef pteval_t pte_t; typedef pmdval_t pmd_t; -typedef pmdval_t pgd_t[2]; +typedef pgdval_t pgd_t; typedef pteval_t pgprot_t; #define pte_val(x) (x) #define pmd_val(x) (x) -#define pgd_val(x) ((x)[0]) + +static inline pmdval_t pgd_val(pgd_t pgd) +{ + /* + * A PGD entry actually corresponds to two PMD entries in the PMD table. + * Both PMD entries point to PTE tables residing in the same physical page, + * but at different offsets. See include/asm/pgtable-2level.h for details. + * + * Historically, pgd_val() has returned the lower of the two PMD entries. + */ + return (*(pmdval_t (*)[2])&pgd)[0]; +} + #define pgprot_val(x) (x) #define __pte(x) (x) -- 2.43.0

