Re: [PATCH 2/4] x86, cpa: Map in an arbitrary pgd

From: Matt Fleming
Date: Thu Jun 06 2013 - 06:22:42 EST


On Sun, 02 Jun, at 02:56:08PM, Borislav Petkov wrote:
> From: Borislav Petkov <bp@xxxxxxx>
>
> Add the ability to map pages in an arbitrary pgd.
>
> Signed-off-by: Borislav Petkov <bp@xxxxxxx>
> ---
> arch/x86/include/asm/pgtable_types.h | 3 +-
> arch/x86/mm/pageattr.c | 80 ++++++++++++++++++++++++++++--------
> 2 files changed, 65 insertions(+), 18 deletions(-)
>
> diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
> index e6423002c10b..0613e147f083 100644
> --- a/arch/x86/include/asm/pgtable_types.h
> +++ b/arch/x86/include/asm/pgtable_types.h
> @@ -352,7 +352,8 @@ static inline void update_page_count(int level, unsigned long pages) { }
> */
> extern pte_t *lookup_address(unsigned long address, unsigned int *level);
> extern phys_addr_t slow_virt_to_phys(void *__address);
> -
> +extern void kernel_map_pages_in_pgd(pgd_t *pgd, unsigned long address,
> + unsigned numpages, unsigned long page_flags);
> #endif /* !__ASSEMBLY__ */
>
> #endif /* _ASM_X86_PGTABLE_DEFS_H */
> diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
> index bb32480c2d71..3d64e5fc2adc 100644
> --- a/arch/x86/mm/pageattr.c
> +++ b/arch/x86/mm/pageattr.c
> @@ -30,6 +30,7 @@
> */
> struct cpa_data {
> unsigned long *vaddr;
> + pgd_t *pgd;
> pgprot_t mask_set;
> pgprot_t mask_clr;
> int numpages;

[...]

> @@ -697,7 +714,10 @@ static int __change_page_attr(struct cpa_data *cpa, int primary)
> else
> address = *cpa->vaddr;
> repeat:
> - kpte = lookup_address(address, &level);
> + if (cpa->pgd)
> + kpte = __lookup_address_in_pgd(cpa->pgd, address, &level);
> + else
> + kpte = _lookup_address_cpa(cpa, address, &level);

Don't you also need to initialise .pgd in __set_pages_p() and
__set_pages_np()?

--
Matt Fleming, Intel Open Source Technology Center
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/