Changeset 625 for trunk/kernel/mm/vmm.h


Ignore:
Timestamp:
Apr 10, 2019, 10:09:39 AM (5 years ago)
Author:
alain
Message:

Fix a bug in the vmm_remove_vseg() function: the physical pages
associated to an user DATA vseg were released to the kernel when
the target process descriptor was in the reference cluster.
This physical pages release should be done only when the page
forks counter value is zero.
All other modifications are cosmetic.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/mm/vmm.h

    r624 r625  
    4848 * Each slot can contain one user stack vseg. The first 4 Kbytes page in the slot is not
    4949 * mapped to detect stack overflow.
    50  * The slot index can be computed form the slot base address, and reversely.
    51  * All allocation / release operations are registered in the stack_bitmap, that completely
    52  * define the STACK zone status.
     50 * In this implementation, the slot index is defined by the user thead LTID.
     51 * All allocated stacks are registered in a bitmap defining the STACK zone state:
     52 * - The allocator checks that the requested slot has not been already allocated, and set the
     53 *   corresponding bit in the bitmap.
     54 * - The de-allocator function reset the corresponding bit in the bitmap.
    5355 ********************************************************************************************/
    5456
     
    5759    busylock_t     lock;               /*! lock protecting STACK allocator                  */
    5860    vpn_t          vpn_base;           /*! first page of STACK zone                         */
    59     bitmap_t       bitmap;             /*! bit bector of allocated stacks                   */
     61    bitmap_t       bitmap;             /*! bit vector of allocated stacks                   */
    6062}
    6163stack_mgr_t;
     
    8486    vpn_t          vpn_size;           /*! number of pages in MMAP zone                     */
    8587    vpn_t          first_free_vpn;     /*! first free page in MMAP zone                     */
    86     list_entry_t   zombi_list[32];     /*! array of roots of released vsegs lists           */
     88    xlist_entry_t  zombi_list[32];     /*! array of roots of released vsegs lists           */
    8789}
    8890mmap_mgr_t;
     
    109111typedef struct vmm_s
    110112{
    111         remote_rwlock_t  vsegs_lock;         /*! lock protecting the local VSL                  */
     113        remote_rwlock_t  vsl_lock;           /*! lock protecting the local VSL                  */
    112114        xlist_entry_t    vsegs_root;         /*! Virtual Segment List (complete in reference)   */
    113115        uint32_t         vsegs_nr;           /*! total number of local vsegs                    */
     
    132134
    133135/*********************************************************************************************
    134  * This function initialises the virtual memory manager attached to an user process.
     136 * This function mkkes a partial initialisation of the VMM attached to an user process.
     137 * The GPT must have been previously created, with the hal_gpt_create() function.
     138 * - It registers "args", "envs" vsegs in the VSL.
    135139 * - It initializes the STACK and MMAP allocators.
    136  * - It registers the "kentry", "args", "envs" vsegs in the VSL.
    137  * - It initializes the generic page table, calling the HAL specific hal_gpt_init() function.
    138  * - For TSAR it map all pages for the "kentry" vseg, that must be identity mapping.
    139  ******************************************************a**************************************
    140  * Implementation notes:
     140 * Note:
    141141 * - The "code" and "data" vsegs are registered by the elf_load_process() function.
    142  * - The "stack" vsegs are dynamically created by the thread_user_create() function.
    143  * - The "file", "anon", "remote" vsegs are dynamically created by the mmap() syscall.
     142 * - The "stack" vsegs are dynamically registered by the thread_user_create() function.
     143 * - The "file", "anon", "remote" vsegs are dynamically registered by the mmap() syscall.
    144144 *********************************************************************************************
    145145 * @ process   : pointer on process descriptor
    146146 * @ return 0 if success / return -1 if failure.
    147147 ********************************************************************************************/
    148 error_t vmm_init( struct process_s * process );
    149 
    150 /*********************************************************************************************
    151  * This function displays on TXY0 the list or registered vsegs for a given <process>.
    152  * It must be executed by a thread running in reference cluster.
    153  * If the <mapping> argument is true, it displays for each vseg all mapped PTEs in GPT.
     148error_t vmm_user_init( struct process_s * process );
     149
     150/*********************************************************************************************
     151 * This function re-initialises the VMM attached to an user process to prepare a new
     152 * call to the vmm_user_init() function after an exec() syscall.
     153 * It removes from the VMM of the process identified by the <process> argument all
     154 * non kernel vsegs (i.e. all user vsegs), by calling the vmm_remove_vseg() function.
     155 * - the vsegs are removed from the VSL.
     156 * - the corresponding GPT entries are removed from the GPT.
     157 * - the physical pages are released to the relevant kmem when they are not shared.
     158 * The VSL and the GPT are not modified for the kernel vsegs.
    154159 *********************************************************************************************
    155160 * @ process   : pointer on process descriptor.
    156  * @ mapping   : detailed mapping if true.
    157  ********************************************************************************************/
    158 void hal_vmm_display( struct process_s * process,
    159                   bool_t             mapping );
     161 ********************************************************************************************/
     162void vmm_user_reset( struct process_s * process );
    160163
    161164/*********************************************************************************************
    162165 * This function is called by the process_make_fork() function. It partially copies
    163166 * the content of a remote parent process VMM to the local child process VMM:
    164  * - all DATA, MMAP, REMOTE vsegs registered in the parent VSL are registered in the child
    165  *   VSL, and all valid GPT entries in parent GPT are copied to the child GPT.
    166  *   The WRITABLE flag is reset and the COW flag is set in child GPT.
    167  * - all CODE vsegs registered in the parent VSL are registered in the child VSL, but the
    168  *   GPT entries are not copied in the chilf GPT, that will be dynamically updated from
     167 * - All DATA, ANON, REMOTE vsegs registered in the parent VSL are registered in the
     168 *   child VSL. All valid PTEs in parent GPT are copied to the child GPT, but the
     169 *   WRITABLE flag is reset and the COW flag is set.
     170 * - All CODE vsegs registered in the parent VSL are registered in the child VSL, but the
     171 *   GPT entries are not copied in the child GPT, and will be dynamically updated from
    169172 *   the .elf file when a page fault is reported.
    170  * - all FILE vsegs registered in the parent VSL are registered in the child VSL, and all
     173 * - All FILE vsegs registered in the parent VSL are registered in the child VSL, and all
    171174 *   valid GPT entries in parent GPT are copied to the child GPT. The COW flag is not set.
    172  * - no STACK vseg is copied from  parent VMM to child VMM, because the child STACK vseg
     175 * - No STACK vseg is copied from  parent VMM to child VMM, because the child stack vseg
    173176 *   must be copied later from the cluster containing the user thread requesting the fork().
     177 * - The KERNEL vsegs required by the target architecture are re-created in the child
     178 *   VMM, from the local kernel process VMM, using the hal_vmm_kernel_update() function.
    174179 *********************************************************************************************
    175180 * @ child_process     : local pointer on local child process descriptor.
     
    196201
    197202/*********************************************************************************************
    198  * This global function modifies a GPT entry identified by the <process> and <vpn>
    199  * arguments in all clusters containing a process copy.
     203 * This function modifies a GPT entry identified by the <process> and <vpn> arguments
     204 * in all clusters containing a process copy.
    200205 * It must be called by a thread running in the reference cluster.
    201206 * It updates all copies of the process in all clusters, to maintain coherence in GPT copies,
     
    240245/*********************************************************************************************
    241246 * This function allocates memory for a vseg descriptor, initialises it, and register it
    242  * in the VMM of the local process descriptor, that must be the reference process.
    243  * For the 'stack", "file", "anon", & "remote" types, it does not use the <base> argument,
    244  * but uses the STACK and MMAP virtual memory allocators.
     247 * in the VSL of the local process descriptor, that must be the reference process.
     248 * - For the FILE, ANON, & REMOTE types, it does not use the <base> and <size> arguments,
     249 *   but uses the specific MMAP virtual memory allocator.
     250 * - For the STACK type, it does not use the <size> argument, and the <base> argument
     251 *   defines the user thread LTID used by the specific STACK virtual memory allocator.
    245252 * It checks collision with all pre-existing vsegs.
    246  * To comply with the "on-demand" paging policy, this function does NOT modify the page table,
     253 * To comply with the "on-demand" paging policy, this function does NOT modify the GPT,
    247254 * and does not allocate physical memory for vseg data.
    248255 * It should be called by a local thread (could be a RPC thread if the client thread is not
    249  * running in the regerence cluster).
     256 * running in the reference cluster).
    250257 *********************************************************************************************
    251258 * @ process     : pointer on local processor descriptor.
    252259 * @ type        : vseg type.
    253  * @ base        : vseg base address (not used for dynamically allocated vsegs).
     260 * @ base        : vseg base address (or user thread ltid for an user stack vseg).
    254261 * @ size        : vseg size (bytes).
    255262 * @ file_offset : offset in file for CODE, DATA, FILE types.
     
    269276
    270277/*********************************************************************************************
    271  * This function removes from the local VMM of a process descriptor identified by the <pid>
    272  * argument a local vseg identified by its base address <vaddr> in user space.
    273  * It can be used for any type of vseg, but must be called by a local thread.
    274  * Use the RPC_VMM_DELETE_VSEG if the client thread is not local.
    275  * It does nothing if the process is not registered in the local cluster.
    276  * It does nothing if the vseg is not registered in the local process VSL.
    277  * - It removes from the local GPT all registered PTEs. If it is executed in the reference
    278  *   cluster, it releases the referenced physical pages, to the relevant kmem allocator,
    279  *   depending on vseg type and the pending forks counter.
    280  * - It removes the vseg from the local VSL, and release the vseg descriptor if not MMAP.
    281  *********************************************************************************************
    282  * @ process  : process identifier.
    283  * @ vaddr    : vseg base address in user space.
     278 * This function removes from the VMM of a process descriptor identified by the <process>
     279 * argument the vseg identified by the <vseg> argument. It can be used for any type of vseg.
     280 * As it uses local pointers, it must be called by a local thread.
     281 * It is called by the vmm_user_reset(), vmm_delete_vseg() and vmm_destroy() functions.
     282 * It makes a kernel panic if the process is not registered in the local cluster,
     283 * or if the vseg is not registered in the process VSL.
     284 * For all vseg types, the vseg is detached from local VSL, and all associated PTEs are
     285 * unmapped from local GPT. Other actions depend on the vseg type:
     286 * - Regarding the vseg descriptor release:
     287 *   . for ANON and REMOTE, the vseg is not released, but registered in local zombi_list.
     288 *   . for STACK the vseg is released to the local stack allocator.
     289 *   . for all other types, the vseg is released to the local kmem.
     290 * - Regarding the physical pages release:
     291 *   . for KERNEL and FILE, the pages are not released to kmem.
     292 *   . for CODE and STACK, the pages are released to local kmem when they are not COW.
     293 *   . for DATA, ANON and REMOTE, the pages are released to relevant kmem only when
     294 *     the local cluster is the reference cluster.
     295 * The lock protecting the VSL must be taken by the caller.
     296 *********************************************************************************************
     297 * @ process  : local pointer on process.
     298 * @ vseg     : local pointer on vseg.
     299 ********************************************************************************************/
     300void vmm_remove_vseg( struct process_s * process,
     301                      struct vseg_s    * vseg );
     302
     303/*********************************************************************************************
     304 * This function call the vmm_remove vseg() function to remove from the VMM of a local
     305 * process descriptor, identified by the <pid> argument the vseg identified by the <vaddr>
     306 * virtual address in user space.
     307 * Use the RPC_VMM_DELETE_VSEG to remove a vseg from a remote process descriptor.
     308 *********************************************************************************************
     309 * @ pid      : process identifier.
     310 * @ vaddr    : virtual address in user space.
    284311 ********************************************************************************************/
    285312void vmm_delete_vseg( pid_t    pid,
    286313                      intptr_t vaddr );
    287 
    288 /*********************************************************************************************
    289  * This function insert a new <vseg> descriptor in the VSL identifed by the <vmm> argument.
    290  * and updates the vmm field in the vseg descriptor.
    291  * It takes the lock protecting VSL.
    292  *********************************************************************************************
    293  * @ vmm       : local pointer on local VMM.
    294  * @ vseg      : local pointer on local vseg descriptor.
    295  ********************************************************************************************/
    296 void vmm_attach_vseg_to_vsl( vmm_t  * vmm,
    297                              vseg_t * vseg );
    298 
    299 /*********************************************************************************************
    300  * This function removes a vseg identified by the <vseg> argument from the local VSL
    301  * identified by the <vmm> argument and release the memory allocated to vseg descriptor,
    302  * for all vseg types, BUT the MMAP type (i.e. ANON or REMOTE).
    303  * - If the vseg has not the STACK or MMAP type, it is simply removed from the VSL,
    304  *   and vseg descriptor is released.
    305  * - If the vseg has the STACK type, it is removed from VSL, vseg descriptor is released,
    306  *   and the stack slot is returned to the local VMM_STACK allocator.
    307  * - If the vseg has the MMAP type, it is removed from VSL and is registered in zombi_list
    308  *   of the VMM_MMAP allocator for future reuse. The vseg descriptor is NOT released.
    309  *********************************************************************************************
    310  * @ vmm       : local pointer on local VMM.
    311  * @ vseg      : local pointer on local vseg to be removed.
    312  ********************************************************************************************/
    313 void vmm_detach_vseg_from_vsl( vmm_t  * vmm,
    314                                vseg_t * vseg );
    315314
    316315/*********************************************************************************************
Note: See TracChangeset for help on using the changeset viewer.