Changeset 625 for trunk/kernel/mm/vmm.h
- Timestamp:
- Apr 10, 2019, 10:09:39 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/mm/vmm.h
r624 r625 48 48 * Each slot can contain one user stack vseg. The first 4 Kbytes page in the slot is not 49 49 * 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. 53 55 ********************************************************************************************/ 54 56 … … 57 59 busylock_t lock; /*! lock protecting STACK allocator */ 58 60 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 */ 60 62 } 61 63 stack_mgr_t; … … 84 86 vpn_t vpn_size; /*! number of pages in MMAP zone */ 85 87 vpn_t first_free_vpn; /*! first free page in MMAP zone */ 86 list_entry_tzombi_list[32]; /*! array of roots of released vsegs lists */88 xlist_entry_t zombi_list[32]; /*! array of roots of released vsegs lists */ 87 89 } 88 90 mmap_mgr_t; … … 109 111 typedef struct vmm_s 110 112 { 111 remote_rwlock_t vs egs_lock;/*! lock protecting the local VSL */113 remote_rwlock_t vsl_lock; /*! lock protecting the local VSL */ 112 114 xlist_entry_t vsegs_root; /*! Virtual Segment List (complete in reference) */ 113 115 uint32_t vsegs_nr; /*! total number of local vsegs */ … … 132 134 133 135 /********************************************************************************************* 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. 135 139 * - 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: 141 141 * - 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. 144 144 ********************************************************************************************* 145 145 * @ process : pointer on process descriptor 146 146 * @ return 0 if success / return -1 if failure. 147 147 ********************************************************************************************/ 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. 148 error_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. 154 159 ********************************************************************************************* 155 160 * @ 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 ********************************************************************************************/ 162 void vmm_user_reset( struct process_s * process ); 160 163 161 164 /********************************************************************************************* 162 165 * This function is called by the process_make_fork() function. It partially copies 163 166 * 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 child165 * 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 the168 * GPT entries are not copied in the chil f GPT, thatwill be dynamically updated from167 * - 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 169 172 * 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 all173 * - All FILE vsegs registered in the parent VSL are registered in the child VSL, and all 171 174 * 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 STACKvseg175 * - No STACK vseg is copied from parent VMM to child VMM, because the child stack vseg 173 176 * 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. 174 179 ********************************************************************************************* 175 180 * @ child_process : local pointer on local child process descriptor. … … 196 201 197 202 /********************************************************************************************* 198 * This global function modifies a GPT entry identified by the <process> and <vpn>199 * argumentsin 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. 200 205 * It must be called by a thread running in the reference cluster. 201 206 * It updates all copies of the process in all clusters, to maintain coherence in GPT copies, … … 240 245 /********************************************************************************************* 241 246 * 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. 245 252 * 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, 247 254 * and does not allocate physical memory for vseg data. 248 255 * It should be called by a local thread (could be a RPC thread if the client thread is not 249 * running in the re gerence cluster).256 * running in the reference cluster). 250 257 ********************************************************************************************* 251 258 * @ process : pointer on local processor descriptor. 252 259 * @ 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). 254 261 * @ size : vseg size (bytes). 255 262 * @ file_offset : offset in file for CODE, DATA, FILE types. … … 269 276 270 277 /********************************************************************************************* 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 ********************************************************************************************/ 300 void 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. 284 311 ********************************************************************************************/ 285 312 void vmm_delete_vseg( pid_t pid, 286 313 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 VSL301 * 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_list308 * 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 );315 314 316 315 /*********************************************************************************************
Note: See TracChangeset
for help on using the changeset viewer.