Changeset 38dc82d in mainline for kernel/genarch/src


Ignore:
Timestamp:
2016-08-31T14:16:45Z (9 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
346b12a2
Parents:
dc05a9a
Message:

Make page_mapping_find() return a copy rather than the actual PTE

This makes page_mapping_find() more suitable for use with lock-free data
structures such as CHT that guarantee existence of the data only for
some limited time while a condition holds (e.g. inside of a RCU-protected
critical section that must be around all CHT lookups).

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

Legend:

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

    rdc05a9a r38dc82d  
    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 *);
    6262static void ht_mapping_make_global(uintptr_t, size_t);
    6363
     
    248248/** Find mapping for virtual page in page hash table.
    249249 *
    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)
     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 * @param[out] pte Structure that will receive a copy of the found PTE.
     254 *
     255 * @return True if the mapping was found, false otherwise.
     256 */
     257bool ht_mapping_find(as_t *as, uintptr_t page, bool nolock, pte_t *pte)
    258258{
    259259        sysarg_t key[2] = {
     
    266266        link_t *cur = hash_table_find(&page_ht, key);
    267267        if (cur)
    268                 return hash_table_get_instance(cur, pte_t, link);
    269        
    270         return NULL;
     268                *pte = *hash_table_get_instance(cur, pte_t, link);
     269       
     270        return cur != NULL;
    271271}
    272272
  • kernel/genarch/src/mm/page_pt.c

    rdc05a9a r38dc82d  
    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);
    5656static void pt_mapping_make_global(uintptr_t, size_t);
    5757
     
    291291/** Find mapping for virtual page in hierarchical page tables.
    292292 *
    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)
     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 * @param[out] pte Structure that will receive a copy of the found PTE.
     297 *
     298 * @return True if the mapping was found, false otherwise.
     299 */
     300bool pt_mapping_find(as_t *as, uintptr_t page, bool nolock, pte_t *pte)
    302301{
    303302        ASSERT(nolock || page_table_locked(as));
     
    305304        pte_t *ptl0 = (pte_t *) PA2KA((uintptr_t) as->genarch.page_table);
    306305        if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT)
    307                 return NULL;
     306                return false;
    308307
    309308        read_barrier();
     
    311310        pte_t *ptl1 = (pte_t *) PA2KA(GET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page)));
    312311        if (GET_PTL2_FLAGS(ptl1, PTL1_INDEX(page)) & PAGE_NOT_PRESENT)
    313                 return NULL;
     312                return false;
    314313
    315314#if (PTL1_ENTRIES != 0)
     
    322321        pte_t *ptl2 = (pte_t *) PA2KA(GET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page)));
    323322        if (GET_PTL3_FLAGS(ptl2, PTL2_INDEX(page)) & PAGE_NOT_PRESENT)
    324                 return NULL;
     323                return false;
    325324
    326325#if (PTL2_ENTRIES != 0)
     
    333332        pte_t *ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page)));
    334333       
    335         return &ptl3[PTL3_INDEX(page)];
     334        *pte = ptl3[PTL3_INDEX(page)];
     335        return true;
    336336}
    337337
Note: See TracChangeset for help on using the changeset viewer.