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/hal/tsar_mips32/core/hal_vmm.c

    r624 r625  
    4848// This function is called by the process_zero_init() function during kernel_init.
    4949// It initializes the VMM of the kernel proces_zero (containing all kernel threads)
    50 // in the local cluster: it registers one "kcode" vseg in kernel VSL, and registers
    51 // one big page in slot[0] of kernel GPT.
     50// in the local cluster: For TSAR, it registers one "kcode" vseg in kernel VSL,
     51// and registers one big page in slot[0] of kernel GPT.
    5252//////////////////////////////////////////////////////////////////////////////////////////
    5353error_t  hal_vmm_kernel_init( boot_info_t * info )
     
    119119    return 0;
    120120
    121 }  // end hal_kernel_vmm_init()
    122 
    123 //////////////////////////////////////////////////////////////////////////////////////////
    124 // This function is called by the vmm_init() function to update the VMM of an user
    125 // process identified by the <process> argument.
    126 // It registers in the user VSL the "kcode" vseg, registered in the local kernel VSL,
    127 // and register in the user GPT the big page[0] mapped in the local kernel GPT.
     121}  // end hal_vmm_kernel_init()
     122
     123//////////////////////////////////////////////////////////////////////////////////////////
     124// This function registers in the VMM of an user process identified by the <process>
     125// argument all required kernel vsegs.
     126// For TSAR, it registers in the user VSL the "kcode" vseg, from the local kernel VSL,
     127// and register in the user GPT the big page[0] from the local kernel GPT.
    128128//////////////////////////////////////////////////////////////////////////////////////////
    129129error_t hal_vmm_kernel_update( process_t * process )
    130130{
    131     error_t error;
     131    error_t  error;
    132132    uint32_t attr;
    133133    uint32_t ppn;
    134134
     135    // get cluster identifier
     136    cxy_t cxy = local_cxy;
     137
    135138#if DEBUG_HAL_VMM
    136139thread_t * this = CURRENT_THREAD;
    137140printk("\n[%s] thread[%x,%x] enter in cluster %x \n",
    138 __FUNCTION__, this->process->pid, this->trdid, local_cxy );
     141__FUNCTION__, this->process->pid, this->trdid, cxy );
     142hal_vmm_display( &process_zero , true );
    139143hal_vmm_display( process , true );
    140 hal_vmm_display( &process_zero , true );
    141 #endif
    142 
    143     // get cluster identifier
    144     cxy_t cxy = local_cxy;
    145 
    146     // get extended pointer on kernel GPT
     144#endif
     145
     146    // get extended pointer on local kernel GPT
    147147    xptr_t k_gpt_xp = XPTR( cxy , &process_zero.vmm.gpt );
    148148
     
    212212                      bool_t      mapping )
    213213{
     214    // get pointer on process VMM
    214215    vmm_t * vmm = &process->vmm;
    215     gpt_t * gpt = &vmm->gpt;
    216216
    217217    // get pointers on TXT0 chdev
     
    220220    chdev_t * txt0_ptr = GET_PTR( txt0_xp );
    221221
    222     // get extended pointer on remote TXT0 lock
    223     xptr_t  lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
    224 
    225     // get locks protecting the VSL and the GPT
    226     remote_rwlock_rd_acquire( XPTR( local_cxy , &vmm->vsegs_lock ) );
    227     remote_rwlock_rd_acquire( XPTR( local_cxy , &vmm->gpt_lock ) );
    228 
    229     // get TXT0 lock
    230     remote_busylock_acquire( lock_xp );
    231 
    232     nolock_printk("\n***** VSL and GPT for process %x in cluster %x\n",
    233     process->pid , local_cxy );
    234 
    235     // scan the list of vsegs
    236     xptr_t         root_xp = XPTR( local_cxy , &vmm->vsegs_root );
    237     xptr_t         iter_xp;
    238     xptr_t         vseg_xp;
    239     vseg_t       * vseg;
    240     XLIST_FOREACH( root_xp , iter_xp )
    241     {
    242         vseg_xp = XLIST_ELEMENT( iter_xp , vseg_t , xlist );
    243         vseg    = GET_PTR( vseg_xp );
    244 
    245         nolock_printk(" - %s : base = %X / size = %X / npages = %d\n",
    246         vseg_type_str( vseg->type ) , vseg->min , vseg->max - vseg->min , vseg->vpn_size );
    247 
    248         if( mapping )
     222    // build extended pointers on TXT0 lock, GPT lock and VSL lock
     223    xptr_t  txt_lock_xp = XPTR( txt0_cxy , &txt0_ptr->wait_lock );
     224    xptr_t  vsl_lock_xp = XPTR( local_cxy , &vmm->vsl_lock );
     225    xptr_t  gpt_lock_xp = XPTR( local_cxy , &vmm->gpt_lock );
     226
     227    // get root of vsegs list
     228    xptr_t root_xp = XPTR( local_cxy , &vmm->vsegs_root );
     229
     230    // get the locks protecting TXT0, VSL, and GPT
     231    remote_rwlock_rd_acquire( vsl_lock_xp );
     232    remote_rwlock_rd_acquire( gpt_lock_xp );
     233    remote_busylock_acquire( txt_lock_xp );
     234
     235    nolock_printk("\n***** VSL and GPT for process %x in cluster %x / PT1 = %x\n",
     236    process->pid , local_cxy , vmm->gpt.ptr );
     237
     238    if( xlist_is_empty( root_xp ) )
     239    {
     240        nolock_printk("   ... no vsegs registered\n");
     241    }
     242    else  // scan the list of vsegs
     243    {
     244        xptr_t         iter_xp;
     245        xptr_t         vseg_xp;
     246        vseg_t       * vseg;
     247
     248        XLIST_FOREACH( root_xp , iter_xp )
    249249        {
    250             vpn_t    vpn     = vseg->vpn_base;
    251             vpn_t    vpn_max = vpn + vseg->vpn_size;
    252             ppn_t    ppn;
    253             uint32_t attr;
    254 
    255             while( vpn < vpn_max )
     250            vseg_xp = XLIST_ELEMENT( iter_xp , vseg_t , xlist );
     251            vseg    = GET_PTR( vseg_xp );
     252
     253            nolock_printk(" - %s : base = %X / size = %X / npages = %d\n",
     254            vseg_type_str(vseg->type), vseg->min, vseg->max - vseg->min, vseg->vpn_size );
     255
     256            if( mapping ) 
    256257            {
    257                 hal_gpt_get_pte( XPTR( local_cxy , gpt ) , vpn , &attr , &ppn );
    258 
    259                 if( attr & GPT_MAPPED )
     258                vpn_t    vpn     = vseg->vpn_base;
     259                vpn_t    vpn_max = vpn + vseg->vpn_size;
     260                ppn_t    ppn;
     261                uint32_t attr;
     262
     263                while( vpn < vpn_max )   // scan the PTEs
    260264                {
    261                     if( attr & GPT_SMALL )
     265                    hal_gpt_get_pte( XPTR( local_cxy , &vmm->gpt ) , vpn , &attr , &ppn );
     266
     267                    if( attr & GPT_MAPPED )
    262268                    {
    263                         nolock_printk("    . SMALL : vpn = %X / attr = %X / ppn = %X\n",
    264                         vpn , attr , ppn );
    265                         vpn++;
     269                        if( attr & GPT_SMALL )
     270                        {
     271                            nolock_printk("    . SMALL : vpn = %X / attr = %X / ppn = %X\n",
     272                            vpn , attr , ppn );
     273                            vpn++;
     274                        }
     275                        else
     276                        {
     277                            nolock_printk("    . BIG   : vpn = %X / attr = %X / ppn = %X\n",
     278                            vpn , attr , ppn );
     279                            vpn += 512;
     280                        }
    266281                    }
    267282                    else
    268283                    {
    269                         nolock_printk("    . BIG   : vpn = %X / attr = %X / ppn = %X\n",
    270                         vpn , attr , ppn );
    271                         vpn += 512;
     284                        vpn++;
    272285                    }
    273                 }
    274                 else
    275                 {
    276                     vpn++;
    277286                }
    278287            }
     
    280289    }
    281290
    282     // release TXT0 lock
    283     remote_busylock_release( lock_xp );
    284 
    285     // release the VSK and GPT locks
    286     remote_rwlock_rd_release( XPTR( local_cxy , &vmm->vsegs_lock ) );
    287     remote_rwlock_rd_release( XPTR( local_cxy , &vmm->gpt_lock ) );
     291    // release locks
     292    remote_busylock_release( txt_lock_xp );
     293    remote_rwlock_rd_release( gpt_lock_xp );
     294    remote_rwlock_rd_release( vsl_lock_xp );
    288295
    289296}  // hal_vmm_display()
Note: See TracChangeset for help on using the changeset viewer.