|
19 | 19 | #include <linux/uaccess.h> /* faulthandler_disabled() */
|
20 | 20 | #include <linux/efi.h> /* efi_crash_gracefully_on_page_fault()*/
|
21 | 21 | #include <linux/mm_types.h>
|
| 22 | +#include <linux/mm.h> /* find_and_lock_vma() */ |
22 | 23 |
|
23 | 24 | #include <asm/cpufeature.h> /* boot_cpu_has, ... */
|
24 | 25 | #include <asm/traps.h> /* dotraplinkage, ... */
|
@@ -1333,6 +1334,38 @@ void do_user_addr_fault(struct pt_regs *regs,
|
1333 | 1334 | }
|
1334 | 1335 | #endif
|
1335 | 1336 |
|
| 1337 | +#ifdef CONFIG_PER_VMA_LOCK |
| 1338 | + if (!(flags & FAULT_FLAG_USER)) |
| 1339 | + goto lock_mmap; |
| 1340 | + |
| 1341 | + vma = lock_vma_under_rcu(mm, address); |
| 1342 | + if (!vma) |
| 1343 | + goto lock_mmap; |
| 1344 | + |
| 1345 | + if (unlikely(access_error(error_code, vma))) { |
| 1346 | + vma_end_read(vma); |
| 1347 | + goto lock_mmap; |
| 1348 | + } |
| 1349 | + fault = handle_mm_fault(vma, address, flags | FAULT_FLAG_VMA_LOCK, regs); |
| 1350 | + vma_end_read(vma); |
| 1351 | + |
| 1352 | + if (!(fault & VM_FAULT_RETRY)) { |
| 1353 | + count_vm_vma_lock_event(VMA_LOCK_SUCCESS); |
| 1354 | + goto done; |
| 1355 | + } |
| 1356 | + count_vm_vma_lock_event(VMA_LOCK_RETRY); |
| 1357 | + |
| 1358 | + /* Quick path to respond to signals */ |
| 1359 | + if (fault_signal_pending(fault, regs)) { |
| 1360 | + if (!user_mode(regs)) |
| 1361 | + kernelmode_fixup_or_oops(regs, error_code, address, |
| 1362 | + SIGBUS, BUS_ADRERR, |
| 1363 | + ARCH_DEFAULT_PKEY); |
| 1364 | + return; |
| 1365 | + } |
| 1366 | +lock_mmap: |
| 1367 | +#endif /* CONFIG_PER_VMA_LOCK */ |
| 1368 | + |
1336 | 1369 | /*
|
1337 | 1370 | * Kernel-mode access to the user address space should only occur
|
1338 | 1371 | * on well-defined single instructions listed in the exception
|
@@ -1433,6 +1466,9 @@ void do_user_addr_fault(struct pt_regs *regs,
|
1433 | 1466 | }
|
1434 | 1467 |
|
1435 | 1468 | mmap_read_unlock(mm);
|
| 1469 | +#ifdef CONFIG_PER_VMA_LOCK |
| 1470 | +done: |
| 1471 | +#endif |
1436 | 1472 | if (likely(!(fault & VM_FAULT_ERROR)))
|
1437 | 1473 | return;
|
1438 | 1474 |
|
|
0 commit comments