Changeset 2a2fbc8 in mainline for kernel/genarch/src


Ignore:
Timestamp:
2016-09-01T17:05:13Z (9 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
42d08592
Parents:
f126c87 (diff), fb63c06 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~jakub/helenos/pt

Location:
kernel/genarch/src/mm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/src/mm/as_ht.c

    rf126c87 r2a2fbc8  
    7777        if (flags & FLAG_AS_KERNEL) {
    7878                hash_table_create(&page_ht, PAGE_HT_ENTRIES, 2, &ht_operations);
    79                 mutex_initialize(&page_ht_lock, MUTEX_PASSIVE);
    8079                pte_cache = slab_cache_create("pte_t", sizeof(pte_t), 0,
    8180                    NULL, NULL, SLAB_CACHE_MAGDEFERRED);
     
    9998/** Lock page table.
    10099 *
    101  * Lock address space and page hash table.
     100 * Lock address space.
    102101 * Interrupts must be disabled.
    103102 *
     
    110109        if (lock)
    111110                mutex_lock(&as->lock);
    112        
    113         mutex_lock(&page_ht_lock);
    114111}
    115112
    116113/** Unlock page table.
    117114 *
    118  * Unlock address space and page hash table.
     115 * Unlock address space.
    119116 * Interrupts must be disabled.
    120117 *
     
    125122void ht_unlock(as_t *as, bool unlock)
    126123{
    127         mutex_unlock(&page_ht_lock);
    128        
    129124        if (unlock)
    130125                mutex_unlock(&as->lock);
     
    140135bool ht_locked(as_t *as)
    141136{
    142         return (mutex_locked(&page_ht_lock) && mutex_locked(&as->lock));
     137        return mutex_locked(&as->lock);
    143138}
    144139
  • kernel/genarch/src/mm/page_ht.c

    rf126c87 r2a2fbc8  
    5959static void ht_mapping_insert(as_t *, uintptr_t, uintptr_t, unsigned int);
    6060static void ht_mapping_remove(as_t *, uintptr_t);
    61 static pte_t *ht_mapping_find(as_t *, uintptr_t, bool);
     61static bool ht_mapping_find(as_t *, uintptr_t, bool, pte_t *);
     62static void ht_mapping_update(as_t *, uintptr_t, bool, pte_t *);
    6263static void ht_mapping_make_global(uintptr_t, size_t);
    6364
     
    7071 *
    7172 */
    72 mutex_t page_ht_lock;
     73IRQ_SPINLOCK_STATIC_INITIALIZE(page_ht_lock);
    7374
    7475/** Page hash table.
     
    9192        .mapping_remove = ht_mapping_remove,
    9293        .mapping_find = ht_mapping_find,
     94        .mapping_update = ht_mapping_update,
    9395        .mapping_make_global = ht_mapping_make_global
    9496};
     
    191193
    192194        ASSERT(page_table_locked(as));
     195
     196        irq_spinlock_lock(&page_ht_lock, true);
    193197       
    194198        if (!hash_table_find(&page_ht, key)) {
     
    217221                hash_table_insert(&page_ht, key, &pte->link);
    218222        }
     223
     224        irq_spinlock_unlock(&page_ht_lock, true);
    219225}
    220226
     
    238244        ASSERT(page_table_locked(as));
    239245       
     246        irq_spinlock_lock(&page_ht_lock, true);
     247
    240248        /*
    241249         * Note that removed PTE's will be freed
     
    243251         */
    244252        hash_table_remove(&page_ht, key, 2);
    245 }
    246 
    247 
    248 /** Find mapping for virtual page in page hash table.
    249  *
    250  * @param as     Address space to which page belongs.
    251  * @param page   Virtual page.
    252  * @param nolock True if the page tables need not be locked.
    253  *
    254  * @return NULL if there is no such mapping; requested mapping otherwise.
    255  *
    256  */
    257 pte_t *ht_mapping_find(as_t *as, uintptr_t page, bool nolock)
     253
     254        irq_spinlock_unlock(&page_ht_lock, true);
     255}
     256
     257static pte_t *ht_mapping_find_internal(as_t *as, uintptr_t page, bool nolock)
    258258{
    259259        sysarg_t key[2] = {
     
    263263
    264264        ASSERT(nolock || page_table_locked(as));
    265        
     265
    266266        link_t *cur = hash_table_find(&page_ht, key);
    267267        if (cur)
     
    271271}
    272272
     273/** Find mapping for virtual page in page hash table.
     274 *
     275 * @param as       Address space to which page belongs.
     276 * @param page     Virtual page.
     277 * @param nolock   True if the page tables need not be locked.
     278 * @param[out] pte Structure that will receive a copy of the found PTE.
     279 *
     280 * @return True if the mapping was found, false otherwise.
     281 */
     282bool ht_mapping_find(as_t *as, uintptr_t page, bool nolock, pte_t *pte)
     283{
     284        irq_spinlock_lock(&page_ht_lock, true);
     285
     286        pte_t *t = ht_mapping_find_internal(as, page, nolock);
     287        if (t)
     288                *pte = *t;
     289
     290        irq_spinlock_unlock(&page_ht_lock, true);
     291       
     292        return t != NULL;
     293}
     294
     295/** Update mapping for virtual page in page hash table.
     296 *
     297 * @param as       Address space to which page belongs.
     298 * @param page     Virtual page.
     299 * @param nolock   True if the page tables need not be locked.
     300 * @param pte      New PTE.
     301 */
     302void ht_mapping_update(as_t *as, uintptr_t page, bool nolock, pte_t *pte)
     303{
     304        irq_spinlock_lock(&page_ht_lock, true);
     305
     306        pte_t *t = ht_mapping_find_internal(as, page, nolock);
     307        if (!t)
     308                panic("Updating non-existent PTE");
     309       
     310        ASSERT(pte->as == t->as);
     311        ASSERT(pte->page == t->page);
     312        ASSERT(pte->frame == t->frame);
     313        ASSERT(pte->g == t->g);
     314        ASSERT(pte->x == t->x);
     315        ASSERT(pte->w == t->w);
     316        ASSERT(pte->k == t->k);
     317        ASSERT(pte->c == t->c);
     318        ASSERT(pte->p == t->p);
     319
     320        t->a = pte->a;
     321        t->d = pte->d;
     322
     323        irq_spinlock_unlock(&page_ht_lock, true);
     324}
     325
    273326void ht_mapping_make_global(uintptr_t base, size_t size)
    274327{
  • kernel/genarch/src/mm/page_pt.c

    rf126c87 r2a2fbc8  
    5353static void pt_mapping_insert(as_t *, uintptr_t, uintptr_t, unsigned int);
    5454static void pt_mapping_remove(as_t *, uintptr_t);
    55 static pte_t *pt_mapping_find(as_t *, uintptr_t, bool);
     55static bool pt_mapping_find(as_t *, uintptr_t, bool, pte_t *pte);
     56static void pt_mapping_update(as_t *, uintptr_t, bool, pte_t *pte);
    5657static void pt_mapping_make_global(uintptr_t, size_t);
    5758
     
    6061        .mapping_remove = pt_mapping_remove,
    6162        .mapping_find = pt_mapping_find,
     63        .mapping_update = pt_mapping_update,
    6264        .mapping_make_global = pt_mapping_make_global
    6365};
     
    289291}
    290292
    291 /** Find mapping for virtual page in hierarchical page tables.
    292  *
    293  * @param as     Address space to which page belongs.
    294  * @param page   Virtual page.
    295  * @param nolock True if the page tables need not be locked.
    296  *
    297  * @return NULL if there is no such mapping; entry from PTL3 describing
    298  *         the mapping otherwise.
    299  *
    300  */
    301 pte_t *pt_mapping_find(as_t *as, uintptr_t page, bool nolock)
     293static pte_t *pt_mapping_find_internal(as_t *as, uintptr_t page, bool nolock)
    302294{
    303295        ASSERT(nolock || page_table_locked(as));
     
    334326       
    335327        return &ptl3[PTL3_INDEX(page)];
     328}
     329
     330/** Find mapping for virtual page in hierarchical page tables.
     331 *
     332 * @param as       Address space to which page belongs.
     333 * @param page     Virtual page.
     334 * @param nolock   True if the page tables need not be locked.
     335 * @param[out] pte Structure that will receive a copy of the found PTE.
     336 *
     337 * @return True if the mapping was found, false otherwise.
     338 */
     339bool pt_mapping_find(as_t *as, uintptr_t page, bool nolock, pte_t *pte)
     340{
     341        pte_t *t = pt_mapping_find_internal(as, page, nolock);
     342        if (t)
     343                *pte = *t;
     344        return t != NULL;
     345}
     346
     347/** Update mapping for virtual page in hierarchical page tables.
     348 *
     349 * @param as       Address space to which page belongs.
     350 * @param page     Virtual page.
     351 * @param nolock   True if the page tables need not be locked.
     352 * @param[in] pte  New PTE.
     353 */
     354void pt_mapping_update(as_t *as, uintptr_t page, bool nolock, pte_t *pte)
     355{
     356        pte_t *t = pt_mapping_find_internal(as, page, nolock);
     357        if (!t)
     358                panic("Updating non-existent PTE");     
     359
     360        ASSERT(PTE_VALID(t) == PTE_VALID(pte));
     361        ASSERT(PTE_PRESENT(t) == PTE_PRESENT(pte));
     362        ASSERT(PTE_GET_FRAME(t) == PTE_GET_FRAME(pte));
     363        ASSERT(PTE_WRITABLE(t) == PTE_WRITABLE(pte));
     364        ASSERT(PTE_EXECUTABLE(t) == PTE_EXECUTABLE(pte));
     365
     366        *t = *pte;
    336367}
    337368
Note: See TracChangeset for help on using the changeset viewer.