Ignore:
Timestamp:
Dec 27, 2018, 7:38:58 PM (5 years ago)
Author:
alain
Message:

Fix several bugs in VFS to support the following
ksh commandis : cp, mv, rm, mkdir, cd, pwd

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/tsar_mips32/core/hal_exception.c

    r587 r610  
    158158// This function is called when an MMU exception has been detected (IBE / DBE).
    159159// It get the relevant exception arguments from the MMU.
    160 // It signal a fatal error in case of illegal access. In case of page unmapped
    161 // it checks that the faulty address belongs to a registered vseg. It update the local
     160// It signal a fatal error in case of illegal access. In case of page unmapped,
     161// it get the client process to access the relevant VMM: for a RPC thread, the client
     162// process is NOT the calling thread process.
     163// Then, it checks that the faulty address belongs to a registered vseg, update the local
    162164// vseg list from the reference cluster if required, and signal a fatal user error
    163165// in case of illegal virtual address. Finally, it updates the local page table from the
     
    183185    uint32_t         bad_vaddr;
    184186    uint32_t         excp_code;
    185        
     187
     188    // check thread type
     189    if( CURRENT_THREAD->type != THREAD_USER )
     190    {
     191        printk("\n[KERNEL PANIC] in %s : illegal thread type %s\n",
     192        __FUNCTION__, thread_type_str(CURRENT_THREAD->type) );
     193
     194        return EXCP_KERNEL_PANIC;
     195    }
     196
     197    // get faulty thread process 
    186198    process = this->process;
    187199
     
    207219uint32_t cycle = (uint32_t)hal_get_cycles();
    208220if( DEBUG_HAL_EXCEPTIONS < cycle )
    209 printk("\n[DBG] %s : thread[%x,%x] enter / is_ins %d / %s / vaddr %x / cycle %d\n",
    210 __FUNCTION__, process->pid, this->trdid,
     221printk("\n[%s] thread[%x,%x] on core [%x,%x] enter / is_ins %d / %s / vaddr %x / cycle %d\n",
     222__FUNCTION__, process->pid, this->trdid, local_cxy, this->core->lid,
    211223is_ins, hal_mmu_exception_str(excp_code), bad_vaddr, cycle);
    212224#endif
     
    215227    switch( excp_code )
    216228    {
    217         case MMU_WRITE_PT1_UNMAPPED:      // non fatal
    218         case MMU_WRITE_PT2_UNMAPPED:
    219         case MMU_READ_PT1_UNMAPPED:
    220         case MMU_READ_PT2_UNMAPPED:
     229        case MMU_WRITE_PT1_UNMAPPED:      // can be non fatal
     230        case MMU_WRITE_PT2_UNMAPPED:      // can be non fatal
     231        case MMU_READ_PT1_UNMAPPED:       // can be non fatal
     232        case MMU_READ_PT2_UNMAPPED:       // can be non fatal
    221233        {
    222234            // try to map the unmapped PTE
     
    230242cycle = (uint32_t)hal_get_cycles();
    231243if( DEBUG_HAL_EXCEPTIONS < cycle )
    232 printk("\n[DBG] %s : thread[%x,%x] exit / page-fault handled for vaddr = %x\n",
    233 __FUNCTION__, process->pid, this->trdid, bad_vaddr );
     244printk("\n[%s] thread[%x,%x] on core [%x,%x] exit / page-fault handled for vaddr = %x\n",
     245__FUNCTION__, process->pid, this->trdid, local_cxy, this->core->lid, bad_vaddr );
    234246#endif
    235247 
     
    238250            else if( error == EXCP_USER_ERROR )      // illegal vaddr
    239251            {
    240                 printk("\n[USER ERROR] in %s for thread %x in process %x\n"
    241                 "   illegal vaddr = %x / is_ins %d / epc %x\n",
    242                 __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC );
     252                printk("\n[USER ERROR] in %s : thread[%x,%x] on core[%x,%x] / cycle %d\n"
     253                "  %s : epc %x / badvaddr %x / is_ins %d\n",
     254                __FUNCTION__, this->process->pid, this->trdid, local_cxy,
     255                this->core->lid, (uint32_t)hal_get_cycles(),
     256                hal_mmu_exception_str(excp_code), excPC, bad_vaddr, is_ins );
    243257
    244258                        return EXCP_USER_ERROR;
     
    246260            else  // error == EXCP_KERNEL_PANIC 
    247261            {
    248                 printk("\n[KERNEL ERROR] in %s for thread %x in process %x\n"
    249                 "   no memory to map vaddr = %x / is_ins %d / epc %x\n",
    250                 __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC );
     262                printk("\n[KERNEL PANIC] in %s : thread[%x,%x] on core[%x,%x] / cycle %d\n"
     263                "  %s : epc %x / badvaddr %x / is_ins %d\n",
     264                __FUNCTION__, this->process->pid, this->trdid, local_cxy,
     265                this->core->lid, (uint32_t)hal_get_cycles(),
     266                hal_mmu_exception_str(excp_code), excPC, bad_vaddr, is_ins );
    251267
    252268                        return EXCP_KERNEL_PANIC;
    253269            }
    254270        }
    255         case MMU_WRITE_PRIVILEGE_VIOLATION:  // illegal access user error
    256         case MMU_READ_PRIVILEGE_VIOLATION:
    257         {
    258             printk("\n[USER ERROR] in %s : thread %x in process %x\n"
    259             "   illegal user access to vaddr = %x / is_ins %d / epc %x\n",
    260             __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC );
     271        case MMU_WRITE_PRIVILEGE_VIOLATION:  // illegal user error
     272        case MMU_READ_PRIVILEGE_VIOLATION:   // illegal
     273        {
     274            printk("\n[USER ERROR] in %s : thread[%x,%x] on core[%x,%x] / cycle %d\n"
     275            "  %s : epc %x / badvaddr %x / is_ins %d\n",
     276            __FUNCTION__, this->process->pid, this->trdid, local_cxy,
     277            this->core->lid, (uint32_t)hal_get_cycles(),
     278            hal_mmu_exception_str(excp_code), excPC, bad_vaddr, is_ins );
    261279
    262280            return EXCP_USER_ERROR;
    263281        }
    264         case MMU_WRITE_ACCESS_VIOLATION:     // user error, or Copy-on-Write
    265         {
    266             // access page table to get GPT_COW flag
    267             bool_t cow = hal_gpt_pte_is_cow( &(process->vmm.gpt),
    268                                              bad_vaddr >> CONFIG_PPM_PAGE_SHIFT );
    269 
    270             if( cow )                        // Copy-on-Write
    271             {
    272                 // try to allocate and copy the page
    273                 error = vmm_handle_cow( process,
    274                                         bad_vaddr >> CONFIG_PPM_PAGE_SHIFT );
    275 
    276                 if( error == EXCP_NON_FATAL )        // Copy on write successfull
    277                 {
     282        case MMU_WRITE_ACCESS_VIOLATION:    // can be non fatal if COW
     283        {
     284            // try to handle a possible COW
     285            error = vmm_handle_cow( process,
     286                                    bad_vaddr >> CONFIG_PPM_PAGE_SHIFT );
     287
     288            if( error == EXCP_NON_FATAL )        // COW successfully handled
     289            {
    278290
    279291#if DEBUG_HAL_EXCEPTIONS
    280292cycle = (uint32_t)hal_get_cycles();
    281293if( DEBUG_HAL_EXCEPTIONS < cycle )
    282 printk("\n[DBG] %s : thread[%x,%x] exit / copy-on-write handled for vaddr = %x\n",
     294printk("\n[%s] thread[%x,%x] exit / copy-on-write handled for vaddr = %x\n",
    283295__FUNCTION__, process->pid, this->trdid, bad_vaddr );
    284296#endif
    285 
    286                     return EXCP_NON_FATAL;
    287                 }
    288                 else if( error == EXCP_USER_ERROR )  // illegal user access
    289                 {
    290                     printk("\n[USER ERROR] in %s : thread %x in process %x\n"
    291                     "   cannot cow vaddr = %x / is_ins %d / epc %x\n",
    292                     __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC );
     297                return EXCP_NON_FATAL;
     298            }
     299            else if( error == EXCP_USER_ERROR )  // illegal write access
     300            {
     301                    printk("\n[USER ERROR] in %s : thread[%x,%x] on core[%x,%x] / cycle %d\n"
     302                    "  %s : epc %x / badvaddr %x / is_ins %d\n",
     303                    __FUNCTION__, this->process->pid, this->trdid, local_cxy,
     304                    this->core->lid, (uint32_t)hal_get_cycles(),
     305                    hal_mmu_exception_str(excp_code), excPC, bad_vaddr, is_ins );
    293306
    294307                            return EXCP_USER_ERROR;
    295                 }
    296                 else   // error == EXCP_KERNEL_PANIC
    297                 {
    298                     printk("\n[KERNEL ERROR] in %s : thread %x in process %x\n"
    299                     "   no memoty to cow vaddr = %x / is_ins %d / epc %x\n",
    300                     __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC );
    301 
    302                             return EXCP_USER_ERROR;
    303                 }
    304308            }
    305             else                             // non writable user error
    306             {
    307                 printk("\n[USER ERROR] in %s : thread %x in process %x\n"
    308                 "   non-writable vaddr = %x / is_ins %d / epc %x\n",
    309                 __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC );
    310 
    311                 return EXCP_USER_ERROR;
     309            else   // error == EXCP_KERNEL_PANIC
     310            {
     311                printk("\n[KERNEL PANIC] in %s : thread[%x,%x] on core[%x,%x] / cycle %d\n"
     312                "  %s : epc %x / badvaddr %x / is_ins %d\n",
     313                __FUNCTION__, this->process->pid, this->trdid, local_cxy,
     314                this->core->lid, (uint32_t)hal_get_cycles(),
     315                hal_mmu_exception_str(excp_code), excPC, bad_vaddr, is_ins );
     316
     317                        return EXCP_USER_ERROR;
    312318            }
    313319        }
    314320        case MMU_READ_EXEC_VIOLATION:        // user error
    315321        {
    316             printk("\n[USER_ERROR] in %s : thread %x in process %x\n"
    317             "   non-executable vaddr = %x / is_ins %d / epc %x\n",
    318             __FUNCTION__, this->trdid, this->process->pid, bad_vaddr, is_ins, excPC );
     322            printk("\n[USER ERROR] in %s : thread[%x,%x] on core[%x,%x] / cycle %d\n"
     323            "  %s : epc %x / badvaddr %x / is_ins %d\n",
     324            __FUNCTION__, this->process->pid, this->trdid, local_cxy,
     325            this->core->lid, (uint32_t)hal_get_cycles(),
     326            hal_mmu_exception_str(excp_code), excPC, bad_vaddr, is_ins );
    319327
    320328            return EXCP_USER_ERROR;
     
    322330        default:                             // this is a kernel error   
    323331        {
    324             printk("\n[KERNEL ERROR] in %s : thread %x in process %x\n"
    325             "  epc %x / badvaddr %x / is_ins %d\n",
    326             __FUNCTION__, this->trdid, this->process->pid, excPC, bad_vaddr, is_ins );
     332            printk("\n[KERNEL PANIC] in %s : thread[%x,%x] on core[%x,%x] / cycle %d\n"
     333            "  %s : epc %x / badvaddr %x / is_ins %d\n",
     334            __FUNCTION__, this->process->pid, this->trdid, local_cxy,
     335            this->core->lid, (uint32_t)hal_get_cycles(),
     336            hal_mmu_exception_str(excp_code), excPC, bad_vaddr, is_ins );
    327337
    328338            return EXCP_KERNEL_PANIC;
     
    359369    if( error == EXCP_USER_ERROR )
    360370    {
    361         nolock_printk("\n=== USER ERROR / trdid %x / pid %x / core[%x,%d] / cycle %d ===\n",
    362         this->trdid, process->pid, local_cxy, core->lid , (uint32_t)hal_get_cycles() );
     371        nolock_printk("\n=== USER ERROR / thread(%x,%x) / core[%d] / cycle %d ===\n",
     372        process->pid, this->trdid, core->lid, (uint32_t)hal_get_cycles() );
    363373    }
    364374    else
    365375    {
    366         nolock_printk("\n=== KERNEL ERROR / trdid %x / pid %x / core[%x,%d] / cycle %d ===\n",
    367         this->trdid, process->pid, local_cxy, core->lid , (uint32_t)hal_get_cycles() );
     376        nolock_printk("\n=== KERNEL PANIC / thread(%x,%x) / core[%d] / cycle %d ===\n",
     377        process->pid, this->trdid, core->lid, (uint32_t)hal_get_cycles() );
    368378    }
    369379
     
    400410}  // end hal_exception_dump()
    401411
    402 ///////////////////////
     412/////////////////////////////
    403413void hal_do_exception( void )
    404414{
     
    420430uint32_t cycle = (uint32_t)hal_get_cycles();
    421431if( DEBUG_HAL_EXCEPTIONS < cycle )
    422 printk("\n[DBG] %s : thread %x in process %x enter / core[%x,%d] / epc %x / xcode %x / cycle %d\n",
    423 __FUNCTION__, this->trdid, this->process->pid, local_cxy, this->core->lid, excPC, excCode, cycle );
     432printk("\n[%s] thread[%x,%x] enter / core[%x,%d] / epc %x / xcode %x / cycle %d\n",
     433__FUNCTION__, this->process->pid, this->trdid,
     434local_cxy, this->core->lid, excPC, excCode, cycle );
    424435#endif
    425436
     
    473484        {
    474485            printk("\n[USER_ERROR] in %s for thread %x in process %x\n"
    475             "   illegal data load address / epc %x\n",
    476             __FUNCTION__, this->trdid, this->process->pid, excPC );
     486            "   illegal data load address / epc %x / bad_address %x\n",
     487            __FUNCTION__, this->trdid, this->process->pid, excPC, hal_get_bad_vaddr() );
    477488
    478489                    error = EXCP_USER_ERROR;
     
    482493        {
    483494            printk("\n[USER_ERROR] in %s for thread %x in process %x\n"
    484             "   illegal data store address / epc %x\n",
    485             __FUNCTION__, this->trdid, this->process->pid, excPC );
     495            "   illegal data store address / epc %x / bad_address %x\n",
     496            __FUNCTION__, this->trdid, this->process->pid, excPC, hal_get_bad_vaddr() );
    486497
    487498                    error = EXCP_USER_ERROR;
     
    505516        hal_exception_dump( this , uzone , error );
    506517
    507         assert( false , "Exception raised kernel panic see information below.\n" );
     518        hal_core_sleep();
    508519    }
    509520
     
    511522cycle = (uint32_t)hal_get_cycles();
    512523if( DEBUG_HAL_EXCEPTIONS < cycle )
    513 printk("\n[DBG] %s : thread %x in process %x exit / core[%x,%d] / epc %x / xcode %x / cycle %d\n",
    514 __FUNCTION__, this->trdid, this->process->pid, local_cxy, this->core->lid, excPC, excCode, cycle );
     524printk("\n[%s] thread[%x,%x] exit / core[%x,%d] / epc %x / xcode %x / cycle %d\n",
     525__FUNCTION__, this->process->pid, this->trdid,
     526local_cxy, this->core->lid, excPC, excCode, cycle );
    515527#endif
    516528
Note: See TracChangeset for help on using the changeset viewer.