Changeset 2299914 in mainline
- Timestamp:
- 2006-03-16T12:57:31Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e898a8d7
- Parents:
- b7dcabb
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
arch/ia64/src/mm/tlb.c
rb7dcabb r2299914 424 424 425 425 va = istate->cr_ifa; /* faulting address */ 426 page_table_lock(AS, true); 426 427 t = page_mapping_find(AS, va); 427 428 if (t) { … … 431 432 */ 432 433 itc_pte_copy(t); 434 page_table_unlock(AS, true); 433 435 } else { 434 436 /* 435 437 * Forward the page fault to address space page fault handler. 436 438 */ 439 page_table_unlock(AS, true); 437 440 if (!as_page_fault(va)) { 441 page_table_unlock(AS, true); 438 442 panic("%s: va=%P, rid=%d\n", __FUNCTION__, istate->cr_ifa, rr.map.rid); 439 443 } … … 467 471 } 468 472 473 page_table_lock(AS, true); 469 474 t = page_mapping_find(AS, va); 470 475 if (t) { … … 474 479 */ 475 480 dtc_pte_copy(t); 481 page_table_unlock(AS, true); 476 482 } else { 477 483 /* 478 484 * Forward the page fault to address space page fault handler. 479 485 */ 486 page_table_unlock(AS, true); 480 487 if (!as_page_fault(va)) { 481 488 panic("%s: va=%P, rid=%d, iip=%P\n", __FUNCTION__, va, rid, istate->cr_iip); … … 505 512 pte_t *t; 506 513 514 page_table_lock(AS, true); 507 515 t = page_mapping_find(AS, istate->cr_ifa); 508 516 ASSERT(t && t->p); … … 515 523 dtc_pte_copy(t); 516 524 } 525 page_table_unlock(AS, true); 517 526 } 518 527 … … 526 535 pte_t *t; 527 536 537 page_table_lock(AS, true); 528 538 t = page_mapping_find(AS, istate->cr_ifa); 529 539 ASSERT(t && t->p); … … 536 546 itc_pte_copy(t); 537 547 } 548 page_table_unlock(AS, true); 538 549 } 539 550 … … 547 558 pte_t *t; 548 559 560 page_table_lock(AS, true); 549 561 t = page_mapping_find(AS, istate->cr_ifa); 550 562 ASSERT(t && t->p); … … 557 569 dtc_pte_copy(t); 558 570 } 571 page_table_unlock(AS, true); 559 572 } 560 573 … … 571 584 572 585 va = istate->cr_ifa; /* faulting address */ 586 page_table_lock(AS, true); 573 587 t = page_mapping_find(AS, va); 574 588 ASSERT(t); … … 583 597 else 584 598 dtc_pte_copy(t); 599 page_table_unlock(AS, true); 585 600 } else { 601 page_table_unlock(AS, true); 586 602 if (!as_page_fault(va)) { 587 603 panic("%s: va=%P, rid=%d\n", __FUNCTION__, va, rr.map.rid); -
arch/mips32/src/mm/tlb.c
rb7dcabb r2299914 88 88 { 89 89 entry_lo_t lo; 90 entry_hi_t hi; 90 entry_hi_t hi; 91 asid_t asid; 91 92 __address badvaddr; 92 93 pte_t *pte; … … 94 95 badvaddr = cp0_badvaddr_read(); 95 96 96 spinlock_lock(&AS->lock); 97 spinlock_lock(&AS->lock); 98 asid = AS->asid; 99 spinlock_unlock(&AS->lock); 100 101 page_table_lock(AS, true); 97 102 98 103 pte = find_mapping_and_check(badvaddr); … … 105 110 pte->a = 1; 106 111 107 prepare_entry_hi(&hi, AS->asid, badvaddr);112 prepare_entry_hi(&hi, asid, badvaddr); 108 113 prepare_entry_lo(&lo, pte->g, pte->p, pte->d, pte->cacheable, pte->pfn); 109 114 … … 123 128 tlbwr(); 124 129 125 spinlock_unlock(&AS->lock);130 page_table_unlock(AS, true); 126 131 return; 127 132 128 133 fail: 129 spinlock_unlock(&AS->lock);134 page_table_unlock(AS, true); 130 135 tlb_refill_fail(istate); 131 136 } … … 155 160 tlbp(); 156 161 index.value = cp0_index_read(); 157 158 spinlock_lock(&AS->lock);162 163 page_table_lock(AS, true); 159 164 160 165 /* … … 192 197 tlbwi(); 193 198 194 spinlock_unlock(&AS->lock);199 page_table_unlock(AS, true); 195 200 return; 196 201 197 202 fail: 198 spinlock_unlock(&AS->lock);203 page_table_unlock(AS, true); 199 204 tlb_invalid_fail(istate); 200 205 } … … 224 229 tlbp(); 225 230 index.value = cp0_index_read(); 226 227 spinlock_lock(&AS->lock);231 232 page_table_lock(AS, true); 228 233 229 234 /* … … 268 273 tlbwi(); 269 274 270 spinlock_unlock(&AS->lock);275 page_table_unlock(AS, true); 271 276 return; 272 277 273 278 fail: 274 spinlock_unlock(&AS->lock);279 page_table_unlock(AS, true); 275 280 tlb_modified_fail(istate); 276 281 } … … 350 355 * Resort to higher-level page fault handler. 351 356 */ 357 page_table_unlock(AS, true); 352 358 if (as_page_fault(badvaddr)) { 353 359 /* … … 355 361 * The mapping ought to be in place. 356 362 */ 363 page_table_lock(AS, true); 357 364 pte = page_mapping_find(AS, badvaddr); 358 365 ASSERT(pte && pte->p); 359 366 return pte; 367 } else { 368 page_table_lock(AS, true); 369 printf("Page fault.\n"); 370 return NULL; 360 371 } 361 } 362 363 /* 364 * Handler cannot succeed if badvaddr has no mapping. 365 */ 366 if (!pte) { 367 printf("No such mapping.\n"); 368 return NULL; 369 } 370 371 /* 372 * Handler cannot succeed if the mapping is marked as invalid. 373 */ 374 if (!pte->p) { 375 printf("Invalid mapping.\n"); 376 return NULL; 377 } 378 379 return pte; 372 373 } 380 374 } 381 375 -
genarch/src/mm/as_ht.c
rb7dcabb r2299914 35 35 #include <memstr.h> 36 36 #include <adt/hash_table.h> 37 #include <synch/spinlock.h> 37 38 38 39 static pte_t *ht_create(int flags); 39 40 41 static void ht_lock(as_t *as, bool lock); 42 static void ht_unlock(as_t *as, bool unlock); 43 40 44 as_operations_t as_ht_operations = { 41 .page_table_create = ht_create 45 .page_table_create = ht_create, 46 .page_table_lock = ht_lock, 47 .page_table_unlock = ht_unlock, 42 48 }; 43 49 … … 59 65 return NULL; 60 66 } 67 68 /** Lock page table. 69 * 70 * Lock address space and page hash table. 71 * Interrupts must be disabled. 72 * 73 * @param as Address space. 74 * @param lock If false, do not attempt to lock the address space. 75 */ 76 void ht_lock(as_t *as, bool lock) 77 { 78 if (lock) 79 spinlock_lock(&as->lock); 80 spinlock_lock(&page_ht_lock); 81 } 82 83 /** Unlock page table. 84 * 85 * Unlock address space and page hash table. 86 * Interrupts must be disabled. 87 * 88 * @param as Address space. 89 * @param unlock If false, do not attempt to lock the address space. 90 */ 91 void ht_unlock(as_t *as, bool unlock) 92 { 93 spinlock_unlock(&page_ht_lock); 94 if (unlock) 95 spinlock_unlock(&as->lock); 96 } -
genarch/src/mm/as_pt.c
rb7dcabb r2299914 40 40 static pte_t *ptl0_create(int flags); 41 41 42 static void pt_lock(as_t *as, bool lock); 43 static void pt_unlock(as_t *as, bool unlock); 44 42 45 as_operations_t as_pt_operations = { 43 .page_table_create = ptl0_create 46 .page_table_create = ptl0_create, 47 .page_table_lock = pt_lock, 48 .page_table_unlock = pt_unlock 44 49 }; 45 50 … … 77 82 return (pte_t *) KA2PA((__address) dst_ptl0); 78 83 } 84 85 /** Lock page tables. 86 * 87 * Lock only the address space. 88 * Interrupts must be disabled. 89 * 90 * @param as Address space. 91 * @param lock If false, do not attempt to lock the address space. 92 */ 93 void pt_lock(as_t *as, bool lock) 94 { 95 if (lock) 96 spinlock_lock(&as->lock); 97 } 98 99 /** Unlock page tables. 100 * 101 * Unlock the address space. 102 * Interrupts must be disabled. 103 * 104 * @param as Address space. 105 * @param unlock If false, do not attempt to unlock the address space. 106 */ 107 void pt_unlock(as_t *as, bool unlock) 108 { 109 if (unlock) 110 spinlock_unlock(&as->lock); 111 } -
genarch/src/mm/page_ht.c
rb7dcabb r2299914 53 53 54 54 /** 55 * This lock protects the page hash table. 55 * This lock protects the page hash table. It must be acquired 56 * after address space lock and after any address space area 57 * locks. 56 58 */ 57 59 SPINLOCK_INITIALIZE(page_ht_lock); … … 156 158 * using 'flags'. 157 159 * 158 * The address space must be locked and interruptsmust be disabled.160 * The page table must be locked and interrupts must be disabled. 159 161 * 160 162 * @param as Address space to which page belongs. … … 168 170 __native key[2] = { (__address) as, page = ALIGN_DOWN(page, PAGE_SIZE) }; 169 171 170 spinlock_lock(&page_ht_lock);171 172 172 if (!hash_table_find(&page_ht, key)) { 173 173 t = (pte_t *) malloc(sizeof(pte_t), FRAME_ATOMIC); … … 187 187 hash_table_insert(&page_ht, key, &t->link); 188 188 } 189 190 spinlock_unlock(&page_ht_lock);191 189 } 192 190 … … 197 195 * this call visible. 198 196 * 199 * The address space must be locked and interrupts must be disabled.197 * The page table must be locked and interrupts must be disabled. 200 198 * 201 199 * @param as Address space to wich page belongs. … … 206 204 __native key[2] = { (__address) as, page = ALIGN_DOWN(page, PAGE_SIZE) }; 207 205 208 spinlock_lock(&page_ht_lock);209 210 206 /* 211 207 * Note that removed PTE's will be freed … … 213 209 */ 214 210 hash_table_remove(&page_ht, key, 2); 215 216 spinlock_unlock(&page_ht_lock);217 211 } 218 212 … … 222 216 * Find mapping for virtual page. 223 217 * 224 * The address space must be locked and interrupts must be disabled.218 * The page table must be locked and interrupts must be disabled. 225 219 * 226 220 * @param as Address space to wich page belongs. … … 235 229 __native key[2] = { (__address) as, page = ALIGN_DOWN(page, PAGE_SIZE) }; 236 230 237 spinlock_lock(&page_ht_lock);238 239 231 hlp = hash_table_find(&page_ht, key); 240 232 if (hlp) 241 233 t = hash_table_get_instance(hlp, pte_t, link); 242 234 243 spinlock_unlock(&page_ht_lock);244 235 return t; 245 236 } -
genarch/src/mm/page_pt.c
rb7dcabb r2299914 53 53 * using 'flags'. 54 54 * 55 * The address space must be locked and interrupts must be disabled.55 * The page table must be locked and interrupts must be disabled. 56 56 * 57 57 * @param as Address space to wich page belongs. … … 106 106 * Empty page tables except PTL0 are freed. 107 107 * 108 * The address space must be locked and interrupts must be disabled.108 * The page table must be locked and interrupts must be disabled. 109 109 * 110 110 * @param as Address space to wich page belongs. … … 226 226 * Find mapping for virtual page. 227 227 * 228 * The address space must be locked and interrupts must be disabled.228 * The page table must be locked and interrupts must be disabled. 229 229 * 230 230 * @param as Address space to which page belongs. -
generic/include/mm/as.h
rb7dcabb r2299914 94 94 struct as_operations { 95 95 pte_t *(* page_table_create)(int flags); 96 void (* page_table_lock)(as_t *as, bool lock); 97 void (* page_table_unlock)(as_t *as, bool unlock); 96 98 }; 97 99 typedef struct as_operations as_operations_t; -
generic/include/mm/page.h
rb7dcabb r2299914 83 83 84 84 extern void page_init(void); 85 extern void page_table_lock(as_t *as, bool lock); 86 extern void page_table_unlock(as_t *as, bool unlock); 85 87 extern void page_mapping_insert(as_t *as, __address page, __address frame, int flags); 86 88 extern void page_mapping_remove(as_t *as, __address page); -
generic/src/mm/as.c
rb7dcabb r2299914 174 174 175 175 ipl = interrupts_disable(); 176 spinlock_lock(&as->lock);176 page_table_lock(as, true); 177 177 178 178 area = find_area_and_lock(as, page); … … 184 184 185 185 spinlock_unlock(&area->lock); 186 spinlock_unlock(&as->lock);186 page_table_unlock(as, true); 187 187 interrupts_restore(ipl); 188 188 } … … 199 199 int as_page_fault(__address page) 200 200 { 201 pte_t *pte; 201 202 as_area_t *area; 202 203 __address frame; 203 204 204 205 ASSERT(AS); 206 205 207 spinlock_lock(&AS->lock); 206 207 208 area = find_area_and_lock(AS, page); 208 209 if (!area) { … … 213 214 spinlock_unlock(&AS->lock); 214 215 return 0; 216 } 217 218 page_table_lock(AS, false); 219 220 /* 221 * To avoid race condition between two page faults 222 * on the same address, we need to make sure 223 * the mapping has not been already inserted. 224 */ 225 if ((pte = page_mapping_find(AS, page))) { 226 if (PTE_PRESENT(pte)) { 227 page_table_unlock(AS, false); 228 spinlock_unlock(&area->lock); 229 spinlock_unlock(&AS->lock); 230 return 1; 231 } 215 232 } 216 233 … … 238 255 */ 239 256 page_mapping_insert(AS, page, frame, get_area_flags(area)); 257 page_table_unlock(AS, false); 240 258 241 259 spinlock_unlock(&area->lock); 242 260 spinlock_unlock(&AS->lock); 243 244 261 return 1; 245 262 } … … 358 375 } 359 376 377 /** Lock page table. 378 * 379 * This function should be called before any page_mapping_insert(), 380 * page_mapping_remove() and page_mapping_find(). 381 * 382 * Locking order is such that address space areas must be locked 383 * prior to this call. Address space can be locked prior to this 384 * call in which case the lock argument is false. 385 * 386 * @param as Address space. 387 * @param as_locked If false, do not attempt to lock as->lock. 388 */ 389 void page_table_lock(as_t *as, bool lock) 390 { 391 ASSERT(as_operations); 392 ASSERT(as_operations->page_table_lock); 393 394 as_operations->page_table_lock(as, lock); 395 } 396 397 /** Unlock page table. 398 * 399 * @param as Address space. 400 * @param as_locked If false, do not attempt to unlock as->lock. 401 */ 402 void page_table_unlock(as_t *as, bool unlock) 403 { 404 ASSERT(as_operations); 405 ASSERT(as_operations->page_table_unlock); 406 407 as_operations->page_table_unlock(as, unlock); 408 } 409 360 410 /** Find address space area and change it. 361 411 * … … 398 448 * Releasing physical memory. 399 449 * This depends on the fact that the memory was allocated using frame_alloc(). 400 */ 450 */ 451 page_table_lock(as, false); 401 452 pte = page_mapping_find(as, area->base + i*PAGE_SIZE); 402 453 if (pte && PTE_VALID(pte)) { 454 __address frame; 455 403 456 ASSERT(PTE_PRESENT(pte)); 404 frame _free(ADDR2PFN(PTE_GET_FRAME(pte)));457 frame = PTE_GET_FRAME(pte); 405 458 page_mapping_remove(as, area->base + i*PAGE_SIZE); 459 page_table_unlock(as, false); 460 461 frame_free(ADDR2PFN(frame)); 462 } else { 463 page_table_unlock(as, false); 406 464 } 407 465 } -
generic/src/mm/page.c
rb7dcabb r2299914 77 77 * using 'flags'. Allocate and setup any missing page tables. 78 78 * 79 * The address space must be locked and interrupts must be disabled.79 * The page table must be locked and interrupts must be disabled. 80 80 * 81 81 * @param as Address space to wich page belongs. … … 98 98 * this call visible. 99 99 * 100 * The address space must be locked and interrupts must be disabled.100 * The page table must be locked and interrupts must be disabled. 101 101 * 102 102 * @param as Address space to wich page belongs. … … 115 115 * Find mapping for virtual page. 116 116 * 117 * The address space must be locked and interrupts must be disabled.117 * The page table must be locked and interrupts must be disabled. 118 118 * 119 119 * @param as Address space to wich page belongs.
Note:
See TracChangeset
for help on using the changeset viewer.