[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Minios-devel] [PATCH v2 14/18] mini-os: move p2m related macros to header file



Juergen Gross, on Fri 05 Aug 2016 19:35:58 +0200, wrote:
> In order to be able to use p2m related macros for ballooning move
> their definitions to arch/x86/mm.h.
> 
> There is no need to define different macros regarding index masks and
> number of entries for the different levels, as all levels share the
> same entry format (a plain mfn). So reduce the number of macros
> accordingly.
> 
> Add some macros to get the indices into p2m pages from a pfn and make
> use of them in current p2m code.
> 
> Signed-off-by: Juergen Gross <jgross@xxxxxxxx>

Reviewed-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxx>

> ---
>  arch/x86/mm.c         | 31 +++++--------------------------
>  include/x86/arch_mm.h | 21 +++++++++++++++++++++
>  2 files changed, 26 insertions(+), 26 deletions(-)
> 
> diff --git a/arch/x86/mm.c b/arch/x86/mm.c
> index e10c2c5..a5c8959 100644
> --- a/arch/x86/mm.c
> +++ b/arch/x86/mm.c
> @@ -609,40 +609,19 @@ static void clear_bootstrap(void)
>  
>  void arch_init_p2m(unsigned long max_pfn)
>  {
> -#ifdef __x86_64__
> -#define L1_P2M_SHIFT    9
> -#define L2_P2M_SHIFT    18    
> -#define L3_P2M_SHIFT    27    
> -#else
> -#define L1_P2M_SHIFT    10
> -#define L2_P2M_SHIFT    20    
> -#define L3_P2M_SHIFT    30    
> -#endif
> -#define L1_P2M_ENTRIES  (1 << L1_P2M_SHIFT)    
> -#define L2_P2M_ENTRIES  (1 << (L2_P2M_SHIFT - L1_P2M_SHIFT))    
> -#define L3_P2M_ENTRIES  (1 << (L3_P2M_SHIFT - L2_P2M_SHIFT))    
> -#define L1_P2M_MASK     (L1_P2M_ENTRIES - 1)    
> -#define L2_P2M_MASK     (L2_P2M_ENTRIES - 1)    
> -#define L3_P2M_MASK     (L3_P2M_ENTRIES - 1)    
> -    
>      unsigned long *l2_list = NULL, *l3_list;
>      unsigned long pfn;
>      
> +    p2m_chk_pfn(max_pfn - 1);
>      l3_list = (unsigned long *)alloc_page(); 
> -    for ( pfn = 0; pfn < max_pfn; pfn += L1_P2M_ENTRIES )
> +    for ( pfn = 0; pfn < max_pfn; pfn += P2M_ENTRIES )
>      {
> -        if ( !(pfn % (L1_P2M_ENTRIES * L2_P2M_ENTRIES)) )
> +        if ( !(pfn % (P2M_ENTRIES * P2M_ENTRIES)) )
>          {
>              l2_list = (unsigned long*)alloc_page();
> -            if ( (pfn >> L3_P2M_SHIFT) > 0 )
> -            {
> -                printk("Error: Too many pfns.\n");
> -                do_exit();
> -            }
> -            l3_list[(pfn >> L2_P2M_SHIFT)] = virt_to_mfn(l2_list);  
> +            l3_list[L3_P2M_IDX(pfn)] = virt_to_mfn(l2_list);
>          }
> -        l2_list[(pfn >> L1_P2M_SHIFT) & L2_P2M_MASK] =
> -            virt_to_mfn(phys_to_machine_mapping + pfn);
> +        l2_list[L2_P2M_IDX(pfn)] = virt_to_mfn(phys_to_machine_mapping + 
> pfn);
>      }
>      HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = 
>          virt_to_mfn(l3_list);
> diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h
> index d87fe55..7283f64 100644
> --- a/include/x86/arch_mm.h
> +++ b/include/x86/arch_mm.h
> @@ -176,7 +176,28 @@ typedef unsigned long pgentry_t;
>  #define IO_PROT_NOCACHE (L1_PROT | _PAGE_PCD)
>  
>  /* for P2M */
> +#ifdef __x86_64__
> +#define P2M_SHIFT       9
> +#else
> +#define P2M_SHIFT       10
> +#endif
> +#define P2M_ENTRIES     (1UL << P2M_SHIFT)
> +#define P2M_MASK        (P2M_ENTRIES - 1)
> +#define L1_P2M_SHIFT    P2M_SHIFT
> +#define L2_P2M_SHIFT    (2 * P2M_SHIFT)
> +#define L3_P2M_SHIFT    (3 * P2M_SHIFT)
> +#define L1_P2M_IDX(pfn) ((pfn) & P2M_MASK)
> +#define L2_P2M_IDX(pfn) (((pfn) >> L1_P2M_SHIFT) & P2M_MASK)
> +#define L3_P2M_IDX(pfn) (((pfn) >> L2_P2M_SHIFT) & P2M_MASK)
>  #define INVALID_P2M_ENTRY (~0UL)
> +static inline void p2m_chk_pfn(unsigned long pfn)
> +{
> +    if ( (pfn >> L3_P2M_SHIFT) > 0 )
> +    {
> +        printk("Error: Too many pfns.\n");
> +        do_exit();
> +    }
> +}
>  
>  #include "arch_limits.h"
>  #define PAGE_SIZE       __PAGE_SIZE
> -- 
> 2.6.6
> 

-- 
Samuel
"2 + 2 = 5 pour d'assez grandes valeurs de 2"

_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/cgi-bin/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.