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


Ignore:
Timestamp:
Dec 5, 2017, 4:20:07 PM (6 years ago)
Author:
alain
Message:

Fix several bugs in the fork() syscall.

File:
1 edited

Legend:

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

    r407 r408  
    8989/*********************************************************************************************
    9090 * This structure defines the Virtual Memory Manager for a given process in a given cluster.
    91  * This local VMM provides three main services:
    92  * 1) It registers all vsegs statically or dynamically defined in the vseg list.
    93  * 2) It allocates virtual memory space for the STACKS and MMAP vsegs (FILE/ANON/REMOTE).
    94  * 3) It contains the local copy of the generic page table descriptor.
     91 * This local VMM provides four main services:
     92 * 1) It registers all vsegs in the local copy of the vseg list (VSL).
     93 * 2) It contains the local copy of the generic page table (GPT).
     94 * 3) The stack manager dynamically allocates virtual memory space for the STACK vsegs.
     95 * 4) The mmap manager dynamically allocates virtual memory for the (FILE/ANON/REMOTE) vsegs.
     96 ******************************************************a**************************************
     97 * Implementation notes:
     98 * 1. The VSL contains only local vsegs, but it is implemented as an xlist, and protected by
     99 *    a remote_rwlock, because it can be accessed by a thread running in a remote cluster.
     100 *    An exemple is the vmm_fork_copy() function.
     101 * 2. In most custers, the VSL and GPT are only partial copies of the reference VSL and GPT
     102 *    structures, stored in the reference cluster.
    95103 ********************************************************************************************/
    96104
    97105typedef struct vmm_s
    98106{
    99         rwlock_t       vsegs_lock;         /*! lock protecting the vsegs list                   */
    100         list_entry_t   vsegs_root;         /*! all vsegs in same process and same cluster       */
    101         uint32_t       vsegs_nr;           /*! total number of local vsegs                      */
    102 
    103     gpt_t          gpt;                /*! embedded generic page table descriptor           */
    104 
    105     stack_mgr_t    stack_mgr;          /*! embedded STACK vsegs allocator                   */
    106     mmap_mgr_t     mmap_mgr;           /*! embedded MMAP vsegs allocator                    */
    107 
    108         uint32_t       pgfault_nr;         /*! page fault counter (instrumentation)             */
    109         uint32_t       u_err_nr;           /*! TODO ??? [AG]                                    */
    110         uint32_t       m_err_nr;           /*! TODO ??? [AG]                                    */
    111 
    112     vpn_t          kent_vpn_base;      /*! kentry vseg first page                           */
    113     vpn_t          args_vpn_base;      /*! args vseg first page                             */
    114     vpn_t          envs_vpn_base;      /*! envs zone first page                             */
    115     vpn_t          heap_vpn_base;      /*! envs zone first page                             */
    116         vpn_t          code_vpn_base;      /*! code zone first page                             */
    117         vpn_t          data_vpn_base;      /*! data zone first page                             */
    118 
    119         intptr_t       entry_point;        /*! main thread entry point                          */
     107        remote_rwlock_t  vsegs_lock;         /*! lock protecting the vsegs list                 */
     108        xlist_entry_t    vsegs_root;         /*! VSL root (VSL only complete in reference)      */
     109        uint32_t         vsegs_nr;           /*! total number of local vsegs                    */
     110
     111    gpt_t            gpt;                /*! Generic Page Table (complete in reference)     */
     112
     113    stack_mgr_t      stack_mgr;          /*! embedded STACK vsegs allocator                 */
     114    mmap_mgr_t       mmap_mgr;           /*! embedded MMAP vsegs allocator                  */
     115
     116        uint32_t         pgfault_nr;         /*! page fault counter (instrumentation)           */
     117
     118    vpn_t            kent_vpn_base;      /*! kentry vseg first page                         */
     119    vpn_t            args_vpn_base;      /*! args vseg first page                           */
     120    vpn_t            envs_vpn_base;      /*! envs zone first page                           */
     121    vpn_t            heap_vpn_base;      /*! envs zone first page                           */
     122        vpn_t            code_vpn_base;      /*! code zone first page                           */
     123        vpn_t            data_vpn_base;      /*! data zone first page                           */
     124
     125        intptr_t         entry_point;        /*! main thread entry point                        */
    120126}
    121127vmm_t;
     
    147153
    148154/*********************************************************************************************
    149  * This function is called by the sys_fork() system call.
    150  * It copies the content of a parent process descriptor VMM to a child process VMM.
    151  * - All vsegs registered in the source VSL are copied in the destination VSL.
    152  * - All PTEs registered in the source GPT are copied in destination GPT. For all writable
    153  *   PTEs - but the FILE vsegs - the WRITABLE flag is reset and the COW flag is set in
    154  *   the destination GPT.
    155  *********************************************************************************************
    156  * @ dst_process   : pointer on destination process descriptor.
    157  * @ src_process   : pointer on source process descriptor.
     155 * This function is called by the process_fork_create() function. It partially copies
     156 * the content of a remote parent process VMM to the local child process VMM:
     157 * - all DATA, MMAP, REMOTE vsegs registered in the parent VSL are registered in the child
     158 *   VSL, and all valid GPT entries in parent GPT are copied to the child GPT.
     159 *   The WRITABLE flag is reset and the COW flag is set in child GPT.
     160 * - all CODE vsegs registered in the parent VSL are registered in the child VSL, but the
     161 *   GPT entries are not copied in the chilf GPT, that will be dynamically updated from
     162 *   the .elf file when a page fault is reported.
     163 * - all FILE vsegs registered in the parent VSL are registered in the child VSL, and all
     164 *   valid GPT entries in parent GPT are copied to the child GPT. The COW flag is not set.
     165 * - no STACK vseg is copied from  parent VMM to child VMM, because the child STACK vseg
     166 *   must be copied from the cluster containing the user thread requesting the fork().
     167 *********************************************************************************************
     168 * @ child_process     : local pointer on local child process descriptor.
     169 * @ parent_process_xp : extended pointer on remote parent process descriptor.
    158170 * @ return 0 if success / return ENOMEM if failure.
    159171 ********************************************************************************************/
    160 error_t vmm_copy( struct process_s * dst_process,
    161                   struct process_s * src_process );
    162 
    163 /*********************************************************************************************
    164  * This function removes all vsegs registered in in a virtual memory manager,
    165  * and releases the memory allocated to the local generic page table.
     172error_t vmm_fork_copy( struct process_s * child_process,
     173                       xptr_t             parent_process_xp );
     174
     175/*********************************************************************************************
     176 * This function is called by the process_make_fork() function to handle the fork syscall.
     177 * It set the COW flag, and reset the WRITABLE flag of all GPT entries of the DATA, MMAP,
     178 * and REMOTE vsegs of a process identified by the <process> argument.
     179 * It must be called by a thread running in the reference cluster, that contains the complete
     180 * list of vsegs. Use the rpc_vmm_set_cow_client() when the calling thread client is remote.
     181 * It updates all copies of the process in all clusters, to maintain coherence in GPT copies,
     182 * using the list of copies stored in the owner process, and using remote_write accesses to
     183 * update the remote GPTs. It cannot fail, as only mapped entries in GPT copies are updated.
     184 *********************************************************************************************
     185 * @ process   : local pointer on local reference process descriptor.
     186 ********************************************************************************************/
     187void vmm_set_cow( struct process_s * process );
     188
     189/*********************************************************************************************
     190 * This function is called by the vmm_get_pte() function in case of COW exception.
     191 * It modifies both the PPN an the attributes for a GPT entry identified by the <process>
     192 * and <vpn> arguments.
     193 * It updates all copies of the process in all clusters, to maintain coherence in GPT copies,
     194 * using the list of copies stored in the owner process, and using remote_write accesses to
     195 * update the remote GPTs. It cannot fail, as only mapped entries in GPT copies are updated.
     196 *********************************************************************************************
     197 * @ process   : local pointer on local process descriptor.
     198 * @ vpn       : PTE index.
     199 * @ attr      : PTE / attributes.
     200 * @ ppn       : PTE / physical page index.
     201 ********************************************************************************************/
     202void vmm_update_pte( struct process_s * process,
     203                     vpn_t              vpn,
     204                     uint32_t           attr,
     205                     ppn_t              ppn );
     206
     207/*********************************************************************************************
     208 * This function removes all vsegs registered in in the virtual memory manager of the
     209 * process identified by the <process> argument.
     210 * It releases the memory allocated to the local generic page table.
    166211 *********************************************************************************************
    167212 * @ process   : pointer on process descriptor.
     
    315360 * @ returns 0 if success / returns ENOMEM if no memory.
    316361 ********************************************************************************************/
    317 error_t vmm_copy_on_write( struct process_s * process,
    318                            vpn_t              vpn );
     362error_t vmm_handle_cow( struct process_s * process,
     363                        vpn_t              vpn );
    319364
    320365/*********************************************************************************************
Note: See TracChangeset for help on using the changeset viewer.