bug-hurd
[Top][All Lists]
Advanced

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

Re: [PATCH v2 1/3 gnumach] pmap: Refactor temporary mapping functions


From: Samuel Thibault
Subject: Re: [PATCH v2 1/3 gnumach] pmap: Refactor temporary mapping functions
Date: Fri, 3 Feb 2023 20:09:48 +0100
User-agent: NeoMutt/20170609 (1.8.3)

Applied, thanks!

Damien Zammit, le ven. 03 févr. 2023 10:01:49 +0000, a ecrit:
> ---
>  i386/i386at/model_dep.c | 73 +-------------------------------
>  i386/intel/pmap.c       | 93 +++++++++++++++++++++++++++++++++++++++++
>  i386/intel/pmap.h       |  6 +++
>  3 files changed, 101 insertions(+), 71 deletions(-)
> 
> diff --git a/i386/i386at/model_dep.c b/i386/i386at/model_dep.c
> index fe11bffc..98408c06 100644
> --- a/i386/i386at/model_dep.c
> +++ b/i386/i386at/model_dep.c
> @@ -359,10 +359,6 @@ register_boot_data(const struct multiboot_raw_info *mbi)
>  static void
>  i386at_init(void)
>  {
> -     /* XXX move to intel/pmap.h */
> -     extern pt_entry_t *kernel_page_dir;
> -     int i;
> -
>       /*
>        * Initialize the PIC prior to any possible call to an spl.
>        */
> @@ -448,47 +444,8 @@ i386at_init(void)
>        */
>       biosmem_setup();
> 
> -     /*
> -      * We'll have to temporarily install a direct mapping
> -      * between physical memory and low linear memory,
> -      * until we start using our new kernel segment descriptors.
> -      */
> -#if INIT_VM_MIN_KERNEL_ADDRESS != LINEAR_MIN_KERNEL_ADDRESS
> -     vm_offset_t delta = INIT_VM_MIN_KERNEL_ADDRESS - 
> LINEAR_MIN_KERNEL_ADDRESS;
> -     if ((vm_offset_t)(-delta) < delta)
> -             delta = (vm_offset_t)(-delta);
> -     int nb_direct = delta >> PDESHIFT;
> -     for (i = 0; i < nb_direct; i++)
> -             kernel_page_dir[lin2pdenum_cont(INIT_VM_MIN_KERNEL_ADDRESS) + 
> i] =
> -                     
> kernel_page_dir[lin2pdenum_cont(LINEAR_MIN_KERNEL_ADDRESS) + i];
> -#endif
> -     /* We need BIOS memory mapped at 0xc0000 & co for BIOS accesses */
> -#if VM_MIN_KERNEL_ADDRESS != 0
> -     kernel_page_dir[lin2pdenum_cont(LINEAR_MIN_KERNEL_ADDRESS - 
> VM_MIN_KERNEL_ADDRESS)] =
> -             kernel_page_dir[lin2pdenum_cont(LINEAR_MIN_KERNEL_ADDRESS)];
> -#endif
> +     pmap_make_temporary_mapping();
> 
> -#ifdef       MACH_PV_PAGETABLES
> -     for (i = 0; i < PDPNUM; i++)
> -             pmap_set_page_readonly_init((void*) kernel_page_dir + i * 
> INTEL_PGBYTES);
> -#if PAE
> -     pmap_set_page_readonly_init(kernel_pmap->pdpbase);
> -#endif       /* PAE */
> -#endif       /* MACH_PV_PAGETABLES */
> -#if PAE
> -#ifdef __x86_64__
> -     set_cr3((unsigned long)_kvtophys(kernel_pmap->l4base));
> -#else
> -     set_cr3((unsigned long)_kvtophys(kernel_pmap->pdpbase));
> -#endif
> -#ifndef      MACH_HYP
> -     if (!CPU_HAS_FEATURE(CPU_FEATURE_PAE))
> -             panic("CPU doesn't have support for PAE.");
> -     set_cr4(get_cr4() | CR4_PAE);
> -#endif       /* MACH_HYP */
> -#else
> -     set_cr3((unsigned long)_kvtophys(kernel_page_dir));
> -#endif       /* PAE */
>  #ifndef      MACH_HYP
>       /* Turn paging on.
>        * Also set the WP bit so that on 486 or better processors
> @@ -520,33 +477,7 @@ i386at_init(void)
>       mp_desc_init(0);
>  #endif // NCPUS
> 
> -#if INIT_VM_MIN_KERNEL_ADDRESS != LINEAR_MIN_KERNEL_ADDRESS
> -     /* Get rid of the temporary direct mapping and flush it out of the TLB. 
>  */
> -     for (i = 0 ; i < nb_direct; i++) {
> -#ifdef       MACH_XEN
> -#ifdef       MACH_PSEUDO_PHYS
> -             if 
> (!hyp_mmu_update_pte(kv_to_ma(&kernel_page_dir[lin2pdenum_cont(VM_MIN_KERNEL_ADDRESS)
>  + i]), 0))
> -#else        /* MACH_PSEUDO_PHYS */
> -             if (hyp_do_update_va_mapping(VM_MIN_KERNEL_ADDRESS + i * 
> INTEL_PGBYTES, 0, UVMF_INVLPG | UVMF_ALL))
> -#endif       /* MACH_PSEUDO_PHYS */
> -                     printf("couldn't unmap frame %d\n", i);
> -#else        /* MACH_XEN */
> -             kernel_page_dir[lin2pdenum_cont(INIT_VM_MIN_KERNEL_ADDRESS) + 
> i] = 0;
> -#endif       /* MACH_XEN */
> -     }
> -#endif
> -     /* Keep BIOS memory mapped */
> -#if VM_MIN_KERNEL_ADDRESS != 0
> -     kernel_page_dir[lin2pdenum_cont(LINEAR_MIN_KERNEL_ADDRESS - 
> VM_MIN_KERNEL_ADDRESS)] =
> -             kernel_page_dir[lin2pdenum_cont(LINEAR_MIN_KERNEL_ADDRESS)];
> -#endif
> -
> -     /* Not used after boot, better give it back.  */
> -#ifdef       MACH_XEN
> -     hyp_free_page(0, (void*) VM_MIN_KERNEL_ADDRESS);
> -#endif       /* MACH_XEN */
> -
> -     flush_tlb();
> +     pmap_remove_temporary_mapping();
> 
>  #ifdef       MACH_XEN
>       hyp_p2m_init();
> diff --git a/i386/intel/pmap.c b/i386/intel/pmap.c
> index 0505cfa2..3c57d732 100644
> --- a/i386/intel/pmap.c
> +++ b/i386/intel/pmap.c
> @@ -3009,3 +3009,96 @@ pmap_unmap_page_zero (void)
>  #endif       /* MACH_PV_PAGETABLES */
>  }
>  #endif /* __i386__ */
> +
> +void
> +pmap_make_temporary_mapping(void)
> +{
> +     int i;
> +
> +     /*
> +      * We'll have to temporarily install a direct mapping
> +      * between physical memory and low linear memory,
> +      * until we start using our new kernel segment descriptors.
> +      */
> +#if INIT_VM_MIN_KERNEL_ADDRESS != LINEAR_MIN_KERNEL_ADDRESS
> +     vm_offset_t delta = INIT_VM_MIN_KERNEL_ADDRESS - 
> LINEAR_MIN_KERNEL_ADDRESS;
> +     if ((vm_offset_t)(-delta) < delta)
> +             delta = (vm_offset_t)(-delta);
> +     int nb_direct = delta >> PDESHIFT;
> +     for (i = 0; i < nb_direct; i++)
> +             kernel_page_dir[lin2pdenum_cont(INIT_VM_MIN_KERNEL_ADDRESS) + 
> i] =
> +                     
> kernel_page_dir[lin2pdenum_cont(LINEAR_MIN_KERNEL_ADDRESS) + i];
> +#endif
> +     /* We need BIOS memory mapped at 0xc0000 & co for BIOS accesses */
> +#if VM_MIN_KERNEL_ADDRESS != 0
> +     kernel_page_dir[lin2pdenum_cont(LINEAR_MIN_KERNEL_ADDRESS - 
> VM_MIN_KERNEL_ADDRESS)] =
> +             kernel_page_dir[lin2pdenum_cont(LINEAR_MIN_KERNEL_ADDRESS)];
> +#endif
> +
> +#ifdef       MACH_PV_PAGETABLES
> +     for (i = 0; i < PDPNUM; i++)
> +             pmap_set_page_readonly_init((void*) kernel_page_dir + i * 
> INTEL_PGBYTES);
> +#if PAE
> +     pmap_set_page_readonly_init(kernel_pmap->pdpbase);
> +#endif       /* PAE */
> +#endif       /* MACH_PV_PAGETABLES */
> +
> +     pmap_set_page_dir();
> +}
> +
> +void
> +pmap_set_page_dir(void)
> +{
> +#if PAE
> +#ifdef __x86_64__
> +     set_cr3((unsigned long)_kvtophys(kernel_pmap->l4base));
> +#else
> +     set_cr3((unsigned long)_kvtophys(kernel_pmap->pdpbase));
> +#endif
> +#ifndef      MACH_HYP
> +     if (!CPU_HAS_FEATURE(CPU_FEATURE_PAE))
> +             panic("CPU doesn't have support for PAE.");
> +     set_cr4(get_cr4() | CR4_PAE);
> +#endif       /* MACH_HYP */
> +#else
> +     set_cr3((unsigned long)_kvtophys(kernel_page_dir));
> +#endif       /* PAE */
> +}
> +
> +void
> +pmap_remove_temporary_mapping(void)
> +{
> +     int i;
> +
> +#if INIT_VM_MIN_KERNEL_ADDRESS != LINEAR_MIN_KERNEL_ADDRESS
> +     vm_offset_t delta = INIT_VM_MIN_KERNEL_ADDRESS - 
> LINEAR_MIN_KERNEL_ADDRESS;
> +     if ((vm_offset_t)(-delta) < delta)
> +             delta = (vm_offset_t)(-delta);
> +     int nb_direct = delta >> PDESHIFT;
> +     /* Get rid of the temporary direct mapping and flush it out of the TLB. 
>  */
> +     for (i = 0 ; i < nb_direct; i++) {
> +#ifdef       MACH_XEN
> +#ifdef       MACH_PSEUDO_PHYS
> +             if 
> (!hyp_mmu_update_pte(kv_to_ma(&kernel_page_dir[lin2pdenum_cont(VM_MIN_KERNEL_ADDRESS)
>  + i]), 0))
> +#else        /* MACH_PSEUDO_PHYS */
> +             if (hyp_do_update_va_mapping(VM_MIN_KERNEL_ADDRESS + i * 
> INTEL_PGBYTES, 0, UVMF_INVLPG | UVMF_ALL))
> +#endif       /* MACH_PSEUDO_PHYS */
> +                     printf("couldn't unmap frame %d\n", i);
> +#else        /* MACH_XEN */
> +             kernel_page_dir[lin2pdenum_cont(INIT_VM_MIN_KERNEL_ADDRESS) + 
> i] = 0;
> +#endif       /* MACH_XEN */
> +     }
> +#endif
> +     /* Keep BIOS memory mapped */
> +#if VM_MIN_KERNEL_ADDRESS != 0
> +     kernel_page_dir[lin2pdenum_cont(LINEAR_MIN_KERNEL_ADDRESS - 
> VM_MIN_KERNEL_ADDRESS)] =
> +             kernel_page_dir[lin2pdenum_cont(LINEAR_MIN_KERNEL_ADDRESS)];
> +#endif
> +
> +     /* Not used after boot, better give it back.  */
> +#ifdef       MACH_XEN
> +     hyp_free_page(0, (void*) VM_MIN_KERNEL_ADDRESS);
> +#endif       /* MACH_XEN */
> +
> +     flush_tlb();
> +}
> diff --git a/i386/intel/pmap.h b/i386/intel/pmap.h
> index d6bf85fb..92247faa 100644
> --- a/i386/intel/pmap.h
> +++ b/i386/intel/pmap.h
> @@ -475,6 +475,8 @@ pt_entry_t *pmap_pte(const pmap_t pmap, vm_offset_t addr);
>  #define      pmap_attribute(pmap,addr,size,attr,value) \
>                                       (KERN_INVALID_ADDRESS)
> 
> +extern pt_entry_t *kernel_page_dir;
> +
>  /*
>   *  Bootstrap the system enough to run with virtual memory.
>   *  Allocate the kernel page directory and page tables,
> @@ -483,6 +485,10 @@ pt_entry_t *pmap_pte(const pmap_t pmap, vm_offset_t 
> addr);
>   */
>  extern void pmap_bootstrap(void);
> 
> +extern void pmap_set_page_dir(void);
> +extern void pmap_make_temporary_mapping(void);
> +extern void pmap_remove_temporary_mapping(void);
> +
>  extern void pmap_unmap_page_zero (void);
> 
>  /*
> --
> 2.34.1
> 
> 
> 

-- 
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]