mm: Fix pud_alloc_track()
PATCH 1/1 mm: Fix pud_alloc_track()
From: Joerg Roedel <[email protected]>
The pud_alloc_track() needs to do different checks based on whether __ARCH_HAS_5LEVEL_HACK is defined, like it already does in pud_alloc(). Otherwise it causes boot failures on PowerPC.
Provide the correct implementations for both possible settings of __ARCH_HAS_5LEVEL_HACK to fix the boot problems.
--- include/asm-generic/5level-fixup.h | 5 +++++ include/linux/mm.h | 26 +++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-)
include/asm-generic/5level-fixup.h +5 -0
@@ -17,6 +17,11 @@ ((unlikely (pgd_none (*(p4d))) &&__pud_alloc (mm, p4d, address)) ? \ NULL : pud_offset(p4d, address)) +#define pud_alloc_track (mm, p4d, address, mask) \ + ((unlikely(pgd_none(*(p4d))) && \ + (__pud_alloc(mm, p4d, address) || ({*(mask)|=PGTBL_P4D_MODIFIED;0;})))? \ + NULL : pud_offset(p4d, address)) +#define p4d_alloc (mm, pgd, address) (pgd)#define p4d_alloc_track (mm, pgd, address, mask) (pgd)#define p4d_offset (pgd, start) (pgd)
include/linux/mm.h +13 -13
@@ -2088,35 +2088,35 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, p4d_t *p4d, NULL : pud_offset(p4d, address); } -static inline p4d_t *p4d_alloc_track (struct mm_struct *mm,pgd_t *pgd, +static inline pud_t *pud_alloc_track (struct mm_struct *mm,p4d_t *p4d,unsigned long address,pgtbl_mod_mask *mod_mask) - { -if (unlikely (pgd_none (*pgd))) { -if (__p4d_alloc (mm, pgd, address)) +if (unlikely (p4d_none (*p4d))) { +if (__pud_alloc (mm, p4d, address))return NULL ; - *mod_mask |=PGTBL_PGD_MODIFIED ; + *mod_mask |=PGTBL_P4D_MODIFIED ; } -return p4d_offset (pgd, address); +return pud_offset (p4d, address); } -#endif /* !__ARCH_HAS_5LEVEL_HACK */ - -static inline pud_t *pud_alloc_track (struct mm_struct *mm,p4d_t *p4d, +static inline p4d_t *p4d_alloc_track (struct mm_struct *mm,pgd_t *pgd,unsigned long address,pgtbl_mod_mask *mod_mask) + { -if (unlikely (p4d_none (*p4d))) { -if (__pud_alloc (mm, p4d, address)) +if (unlikely (pgd_none (*pgd))) { +if (__p4d_alloc (mm, pgd, address))return NULL ; - *mod_mask |=PGTBL_P4D_MODIFIED ; + *mod_mask |=PGTBL_PGD_MODIFIED ; } -return pud_offset (p4d, address); +return p4d_offset (pgd, address); } +#endif /* !__ARCH_HAS_5LEVEL_HACK */ +static inline pmd_t *pmd_alloc (struct mm_struct *mm,pud_t *pud,unsigned long address) { return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
Signature · 1 line
2.26.2
Mike Rapoport
reviewerQuoted 8 lines · Joerg Roedel
From: Joerg Roedel <[email protected]>
The
pud_alloc_track()needs to do different checks based on whether__ARCH_HAS_5LEVEL_HACKis defined, like it already does inpud_alloc(). Otherwise it causes boot failures on PowerPC.Provide the correct implementations for both possible settings of
__ARCH_HAS_5LEVEL_HACKto fix the boot problems.
There is a patch in mmotm [1] that completely removes __ARCH_HAS_5LEVEL_HACK which is a part of the series [2] that updates p4d folding accross architectures. This should fix boot on PowerPC and the addition of pXd_alloc_track() for __ARCH_HAS_5LEVEL_HACK wouldn't be necessary.
[1] https://github.com/hnaz/linux-mm/commit/cfae68792af3731ac902ea6ba5ed8df5a0f6bd2f
[2] https://lore.kernel.org/kvmarm/[email protected]/
Quoted 82 lines
Reported-by Abdul Haleem <[email protected]>Tested-by Abdul Haleem <[email protected]>Tested-by Satheesh Rajendran <[email protected]>Fixes d8626138009b ("mm: add functions to track page directory modifications")Signed-off-by Joerg Roedel <[email protected]>--- include/asm-generic/5level-fixup.h | 5 +++++ include/linux/mm.h | 26 +++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-)include/asm-generic/5level-fixup.h +5
-0@@ -17,6 +17,11 @@ ((unlikely (pgd_none (*(p4d))) &&__pud_alloc (mm, p4d, address)) ? \ NULL : pud_offset(p4d, address)) +#define pud_alloc_track (mm, p4d, address, mask) \ + ((unlikely(pgd_none(*(p4d))) && \ + (__pud_alloc(mm, p4d, address) || ({*(mask)|=PGTBL_P4D_MODIFIED;0;})))? \ + NULL : pud_offset(p4d, address)) +#define p4d_alloc (mm, pgd, address) (pgd)#define p4d_alloc_track (mm, pgd, address, mask) (pgd)#define p4d_offset (pgd, start) (pgd)include/linux/mm.h +13
-13@@ -2088,35 +2088,35 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, p4d_t *p4d, NULL : pud_offset(p4d, address); } -static inline p4d_t *p4d_alloc_track (struct mm_struct *mm,pgd_t *pgd, +static inline pud_t *pud_alloc_track (struct mm_struct *mm,p4d_t *p4d,unsigned long address,pgtbl_mod_mask *mod_mask) - { -if (unlikely (pgd_none (*pgd))) { -if (__p4d_alloc (mm, pgd, address)) +if (unlikely (p4d_none (*p4d))) { +if (__pud_alloc (mm, p4d, address))return NULL ; - *mod_mask |=PGTBL_PGD_MODIFIED ; + *mod_mask |=PGTBL_P4D_MODIFIED ; } -return p4d_offset (pgd, address); +return pud_offset (p4d, address); } -#endif /* !__ARCH_HAS_5LEVEL_HACK */ - -static inline pud_t *pud_alloc_track (struct mm_struct *mm,p4d_t *p4d, +static inline p4d_t *p4d_alloc_track (struct mm_struct *mm,pgd_t *pgd,unsigned long address,pgtbl_mod_mask *mod_mask) + { -if (unlikely (p4d_none (*p4d))) { -if (__pud_alloc (mm, p4d, address)) +if (unlikely (pgd_none (*pgd))) { +if (__p4d_alloc (mm, pgd, address))return NULL ; - *mod_mask |=PGTBL_P4D_MODIFIED ; + *mod_mask |=PGTBL_PGD_MODIFIED ; } -return pud_offset (p4d, address); +return p4d_offset (pgd, address); } +#endif /* !__ARCH_HAS_5LEVEL_HACK */ +static inline pmd_t *pmd_alloc (struct mm_struct *mm,pud_t *pud,unsigned long address) { return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?Signature · 1 line
2.26.2
Signature · 2 lines
Sincerely yours, Mike.
Quoted 18 lines · Mike Rapoport
Quoted 8 lines · Joerg Roedel
From: Joerg Roedel <[email protected]>
The
pud_alloc_track()needs to do different checks based on whether__ARCH_HAS_5LEVEL_HACKis defined, like it already does inpud_alloc(). Otherwise it causes boot failures on PowerPC.Provide the correct implementations for both possible settings of
__ARCH_HAS_5LEVEL_HACKto fix the boot problems.There is a patch in mmotm [1] that completely removes
__ARCH_HAS_5LEVEL_HACKwhich is a part of the series [2] that updates p4d folding accross architectures. This should fix boot on PowerPC and the addition ofpXd_alloc_track()for__ARCH_HAS_5LEVEL_HACKwouldn't be necessary.
Quoted 3 lines
[1] https://github.com/hnaz/linux-mm/commit/cfae68792af3731ac902ea6ba5ed8df5a0f6bd2f
[2] https://lore.kernel.org/kvmarm/[email protected]/
That link shows an overview of v4 and is easily downloadable as a single mbox file.
See " Series = mm: remove __ARCH_HAS_5LEVEL_HACK"
- Sedat -
[1] https://lore.kernel.org/patchwork/project/lkml/list/?series=438627
Quoted 86 lines
Quoted 80 lines
Reported-by Abdul Haleem <[email protected]>Tested-by Abdul Haleem <[email protected]>Tested-by Satheesh Rajendran <[email protected]>Fixes d8626138009b ("mm: add functions to track page directory modifications")Signed-off-by Joerg Roedel <[email protected]>--- include/asm-generic/5level-fixup.h | 5 +++++ include/linux/mm.h | 26 +++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-)include/asm-generic/5level-fixup.h +5
-0@@ -17,6 +17,11 @@ ((unlikely (pgd_none (*(p4d))) &&__pud_alloc (mm, p4d, address)) ? \ NULL : pud_offset(p4d, address)) +#define pud_alloc_track (mm, p4d, address, mask) \ + ((unlikely(pgd_none(*(p4d))) && \ + (__pud_alloc(mm, p4d, address) || ({*(mask)|=PGTBL_P4D_MODIFIED;0;})))? \ + NULL : pud_offset(p4d, address)) +#define p4d_alloc (mm, pgd, address) (pgd)#define p4d_alloc_track (mm, pgd, address, mask) (pgd)#define p4d_offset (pgd, start) (pgd)include/linux/mm.h +13
-14@@ -2088,35 +2088,35 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, p4d_t *p4d, NULL : pud_offset(p4d, address); } -static inline p4d_t *p4d_alloc_track (struct mm_struct *mm,pgd_t *pgd, +static inline pud_t *pud_alloc_track (struct mm_struct *mm,p4d_t *p4d,unsigned long address,pgtbl_mod_mask *mod_mask) - { -if (unlikely (pgd_none (*pgd))) { -if (__p4d_alloc (mm, pgd, address)) +if (unlikely (p4d_none (*p4d))) { +if (__pud_alloc (mm, p4d, address))return NULL ; - *mod_mask |=PGTBL_PGD_MODIFIED ; + *mod_mask |=PGTBL_P4D_MODIFIED ; } -return p4d_offset (pgd, address); +return pud_offset (p4d, address); } -#endif /* !__ARCH_HAS_5LEVEL_HACK */ - -static inline pud_t *pud_alloc_track (struct mm_struct *mm,p4d_t *p4d, +static inline p4d_t *p4d_alloc_track (struct mm_struct *mm,pgd_t *pgd,unsigned long address,pgtbl_mod_mask *mod_mask) + { -if (unlikely (p4d_none (*p4d))) { -if (__pud_alloc (mm, p4d, address)) +if (unlikely (pgd_none (*pgd))) { +if (__p4d_alloc (mm, pgd, address))return NULL ; - *mod_mask |=PGTBL_P4D_MODIFIED ; + *mod_mask |=PGTBL_PGD_MODIFIED ; } -return pud_offset (p4d, address); +return p4d_offset (pgd, address); } +#endif /* !__ARCH_HAS_5LEVEL_HACK */ +static inline pmd_t *pmd_alloc (struct mm_struct *mm,pud_t *pud,unsigned long address) { return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))? --Quoted 2 lines
2.26.2
--
Sincerely yours,
Mike.
Quoted 6 lines · Joerg Roedel
From: Joerg Roedel <[email protected]>
The
pud_alloc_track()needs to do different checks based on whether__ARCH_HAS_5LEVEL_HACKis defined, like it already does inpud_alloc(). Otherwise it causes boot failures on PowerPC.
Quoted 8 lines
Provide the correct implementations for both possible settings of
__ARCH_HAS_5LEVEL_HACKto fix the boot problems.Reported-by Abdul Haleem <[email protected]>Tested-by Abdul Haleem <[email protected]>Tested-by Satheesh Rajendran <[email protected]>Fixes d8626138009b ("mm: add functions to track page directory modifications")Signed-off-by Joerg Roedel <[email protected]>
Quoted 77 lines
--- include/asm-generic/5level-fixup.h | 5 +++++ include/linux/mm.h | 26 +++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-)include/asm-generic/5level-fixup.h +5
-0@@ -17,6 +17,11 @@ ((unlikely (pgd_none (*(p4d))) &&__pud_alloc (mm, p4d, address)) ? \ NULL : pud_offset(p4d, address)) +#define pud_alloc_track (mm, p4d, address, mask) \ + ((unlikely(pgd_none(*(p4d))) && \ + (__pud_alloc(mm, p4d, address) || ({*(mask)|=PGTBL_P4D_MODIFIED;0;})))? \ + NULL : pud_offset(p4d, address)) +#define p4d_alloc (mm, pgd, address) (pgd)#define p4d_alloc_track (mm, pgd, address, mask) (pgd)#define p4d_offset (pgd, start) (pgd)include/linux/mm.h +13
-13@@ -2088,35 +2088,35 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, p4d_t *p4d, NULL : pud_offset(p4d, address); } -static inline p4d_t *p4d_alloc_track (struct mm_struct *mm,pgd_t *pgd, +static inline pud_t *pud_alloc_track (struct mm_struct *mm,p4d_t *p4d,unsigned long address,pgtbl_mod_mask *mod_mask) - { -if (unlikely (pgd_none (*pgd))) { -if (__p4d_alloc (mm, pgd, address)) +if (unlikely (p4d_none (*p4d))) { +if (__pud_alloc (mm, p4d, address))return NULL ; - *mod_mask |=PGTBL_PGD_MODIFIED ; + *mod_mask |=PGTBL_P4D_MODIFIED ; } -return p4d_offset (pgd, address); +return pud_offset (p4d, address); } -#endif /* !__ARCH_HAS_5LEVEL_HACK */ - -static inline pud_t *pud_alloc_track (struct mm_struct *mm,p4d_t *p4d, +static inline p4d_t *p4d_alloc_track (struct mm_struct *mm,pgd_t *pgd,unsigned long address,pgtbl_mod_mask *mod_mask) + { -if (unlikely (p4d_none (*p4d))) { -if (__pud_alloc (mm, p4d, address)) +if (unlikely (pgd_none (*pgd))) { +if (__p4d_alloc (mm, pgd, address))return NULL ; - *mod_mask |=PGTBL_P4D_MODIFIED ; + *mod_mask |=PGTBL_PGD_MODIFIED ; } -return pud_offset (p4d, address); +return p4d_offset (pgd, address); } +#endif /* !__ARCH_HAS_5LEVEL_HACK */ +static inline pmd_t *pmd_alloc (struct mm_struct *mm,pud_t *pud,unsigned long address) { return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?Signature · 1 line
2.26.2
Andrew Morton
maintainerQuoted 17 lines · On Thu, 4 Jun 2020 19:48:14 +0300 Mike Rapoport <[email protected]> wrote:
Quoted 8 lines · Joerg Roedel
From: Joerg Roedel <[email protected]>
The
pud_alloc_track()needs to do different checks based on whether__ARCH_HAS_5LEVEL_HACKis defined, like it already does inpud_alloc(). Otherwise it causes boot failures on PowerPC.Provide the correct implementations for both possible settings of
__ARCH_HAS_5LEVEL_HACKto fix the boot problems.There is a patch in mmotm [1] that completely removes
__ARCH_HAS_5LEVEL_HACKwhich is a part of the series [2] that updates p4d folding accross architectures. This should fix boot on PowerPC and the addition ofpXd_alloc_track()for__ARCH_HAS_5LEVEL_HACKwouldn't be necessary.
Quoted 2 lines
[1] https://github.com/hnaz/linux-mm/commit/cfae68792af3731ac902ea6ba5ed8df5a0f6bd2f
[2] https://lore.kernel.org/kvmarm/[email protected]/
That patchset is stacked up behind many other patches, including all the powerpc stuff in linux-next :(
As it's a big bug fix, I'll pull those patches forward, hopefully send it all Linuswards later today...