| 1274 | } |
| 1275 | |
| 1276 | int |
| 1277 | vm_fault(vm_map_t map, vm_offset_t vaddr, vm_prot_t fault_type, |
| 1278 | int fault_flags, vm_page_t *m_hold) |
| 1279 | { |
| 1280 | struct faultstate fs; |
| 1281 | int ahead, behind, faultcount; |
| 1282 | int nera, result, rv; |
| 1283 | bool dead, hardfault; |
| 1284 | |
| 1285 | VM_CNT_INC(v_vm_faults); |
| 1286 | |
| 1287 | if ((curthread->td_pflags & TDP_NOFAULTING) != 0) |
| 1288 | return (KERN_PROTECTION_FAILURE); |
| 1289 | |
| 1290 | fs.vp = NULL; |
| 1291 | fs.vaddr = vaddr; |
| 1292 | fs.m_hold = m_hold; |
| 1293 | fs.fault_flags = fault_flags; |
| 1294 | fs.map = map; |
| 1295 | fs.lookup_still_valid = false; |
| 1296 | fs.oom = 0; |
| 1297 | faultcount = 0; |
| 1298 | nera = -1; |
| 1299 | hardfault = false; |
| 1300 | |
| 1301 | RetryFault: |
| 1302 | fs.fault_type = fault_type; |
| 1303 | |
| 1304 | /* |
| 1305 | * Find the backing store object and offset into it to begin the |
| 1306 | * search. |
| 1307 | */ |
| 1308 | result = vm_fault_lookup(&fs); |
| 1309 | if (result != KERN_SUCCESS) { |
| 1310 | if (result == KERN_RESOURCE_SHORTAGE) |
| 1311 | goto RetryFault; |
| 1312 | return (result); |
| 1313 | } |
| 1314 | |
| 1315 | /* |
| 1316 | * Try to avoid lock contention on the top-level object through |
| 1317 | * special-case handling of some types of page faults, specifically, |
| 1318 | * those that are mapping an existing page from the top-level object. |
| 1319 | * Under this condition, a read lock on the object suffices, allowing |
| 1320 | * multiple page faults of a similar type to run in parallel. |
| 1321 | */ |
| 1322 | if (fs.vp == NULL /* avoid locked vnode leak */ && |
| 1323 | (fs.entry->eflags & MAP_ENTRY_SPLIT_BOUNDARY_MASK) == 0 && |
| 1324 | (fs.fault_flags & (VM_FAULT_WIRE | VM_FAULT_DIRTY)) == 0) { |
| 1325 | VM_OBJECT_RLOCK(fs.first_object); |
| 1326 | rv = vm_fault_soft_fast(&fs); |
| 1327 | if (rv == KERN_SUCCESS) |
| 1328 | return (rv); |
| 1329 | if (!VM_OBJECT_TRYUPGRADE(fs.first_object)) { |
| 1330 | VM_OBJECT_RUNLOCK(fs.first_object); |
| 1331 | VM_OBJECT_WLOCK(fs.first_object); |
| 1332 | } |
| 1333 | } else { |
no test coverage detected