Re: [PATCH 32/39] x86/pgtable/pae: Use separate kernel PMDs for user page-table

From: Arnd Bergmann
Date: Fri Oct 05 2018 - 10:07:07 EST


On Wed, Jul 18, 2018 at 11:43 AM Joerg Roedel <joro@xxxxxxxxxx> wrote:
> arch/x86/mm/pgtable.c | 100 ++++++++++++++++++++++++++++++++++++++++----------
> 1 file changed, 81 insertions(+), 19 deletions(-)
>
> diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
> index db6fb77..8e4e63d 100644
> --- a/arch/x86/mm/pgtable.c
> +++ b/arch/x86/mm/pgtable.c
> @@ -182,6 +182,14 @@ static void pgd_dtor(pgd_t *pgd)
> */
> #define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
>
> +/*
> + * We allocate separate PMDs for the kernel part of the user page-table
> + * when PTI is enabled. We need them to map the per-process LDT into the
> + * user-space page-table.
> + */
> +#define PREALLOCATED_USER_PMDS (static_cpu_has(X86_FEATURE_PTI) ? \
> + KERNEL_PGD_PTRS : 0)

> * Xen paravirt assumes pgd table should be in one page. 64 bit kernel also
> * assumes that pgd should be in one page.
> @@ -376,6 +431,7 @@ static inline void _pgd_free(pgd_t *pgd)
> pgd_t *pgd_alloc(struct mm_struct *mm)
> {
> pgd_t *pgd;
> + pmd_t *u_pmds[PREALLOCATED_USER_PMDS];
> pmd_t *pmds[PREALLOCATED_PMDS];
>

This commit from back in July now causes a build warning after the patch
from Kees that enables -Wvla:

In file included from /git/arm-soc/include/linux/kernel.h:15,
from /git/arm-soc/include/asm-generic/bug.h:18,
from /git/arm-soc/arch/x86/include/asm/bug.h:83,
from /git/arm-soc/include/linux/bug.h:5,
from /git/arm-soc/include/linux/mmdebug.h:5,
from /git/arm-soc/include/linux/mm.h:9,
from /git/arm-soc/arch/x86/mm/pgtable.c:2:
/git/arm-soc/arch/x86/mm/pgtable.c: In function 'pgd_alloc':
/git/arm-soc/include/linux/build_bug.h:29:45: error: ISO C90 forbids
variable length array 'u_pmds' [-Werror=vla]
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); }))
^
/git/arm-soc/arch/x86/include/asm/cpufeature.h:85:5: note: in
expansion of macro 'BUILD_BUG_ON_ZERO'
BUILD_BUG_ON_ZERO(NCAPINTS != 19))
^~~~~~~~~~~~~~~~~
/git/arm-soc/arch/x86/include/asm/cpufeature.h:111:32: note: in
expansion of macro 'REQUIRED_MASK_BIT_SET'
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \
^~~~~~~~~~~~~~~~~~~~~
/git/arm-soc/arch/x86/include/asm/cpufeature.h:129:27: note: in
expansion of macro 'cpu_has'
#define boot_cpu_has(bit) cpu_has(&boot_cpu_data, bit)
^~~~~~~
/git/arm-soc/arch/x86/include/asm/cpufeature.h:209:3: note: in
expansion of macro 'boot_cpu_has'
boot_cpu_has(bit) : \
^~~~~~~~~~~~
/git/arm-soc/arch/x86/mm/pgtable.c:190:34: note: in expansion of macro
'static_cpu_has'
#define PREALLOCATED_USER_PMDS (static_cpu_has(X86_FEATURE_PTI) ? \
^~~~~~~~~~~~~~
/git/arm-soc/arch/x86/mm/pgtable.c:431:16: note: in expansion of macro
'PREALLOCATED_USER_PMDS'
pmd_t *u_pmds[PREALLOCATED_USER_PMDS];
^~~~~~~~~~~~~~~~~~~~~~

Arnd