diff options
Diffstat (limited to 'arch/x86/mm/fault.c')
-rw-r--r-- | arch/x86/mm/fault.c | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index 6dea040cc3a1..a10c8c792161 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c | |||
@@ -1020,13 +1020,17 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs) | |||
1020 | * This routine handles page faults. It determines the address, | 1020 | * This routine handles page faults. It determines the address, |
1021 | * and the problem, and then passes it off to one of the appropriate | 1021 | * and the problem, and then passes it off to one of the appropriate |
1022 | * routines. | 1022 | * routines. |
1023 | * | ||
1024 | * This function must have noinline because both callers | ||
1025 | * {,trace_}do_page_fault() have notrace on. Having this an actual function | ||
1026 | * guarantees there's a function trace entry. | ||
1023 | */ | 1027 | */ |
1024 | static void __kprobes | 1028 | static void __kprobes noinline |
1025 | __do_page_fault(struct pt_regs *regs, unsigned long error_code) | 1029 | __do_page_fault(struct pt_regs *regs, unsigned long error_code, |
1030 | unsigned long address) | ||
1026 | { | 1031 | { |
1027 | struct vm_area_struct *vma; | 1032 | struct vm_area_struct *vma; |
1028 | struct task_struct *tsk; | 1033 | struct task_struct *tsk; |
1029 | unsigned long address; | ||
1030 | struct mm_struct *mm; | 1034 | struct mm_struct *mm; |
1031 | int fault; | 1035 | int fault; |
1032 | unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE; | 1036 | unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE; |
@@ -1034,9 +1038,6 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code) | |||
1034 | tsk = current; | 1038 | tsk = current; |
1035 | mm = tsk->mm; | 1039 | mm = tsk->mm; |
1036 | 1040 | ||
1037 | /* Get the faulting address: */ | ||
1038 | address = read_cr2(); | ||
1039 | |||
1040 | /* | 1041 | /* |
1041 | * Detect and handle instructions that would cause a page fault for | 1042 | * Detect and handle instructions that would cause a page fault for |
1042 | * both a tracked kernel page and a userspace page. | 1043 | * both a tracked kernel page and a userspace page. |
@@ -1248,32 +1249,50 @@ good_area: | |||
1248 | up_read(&mm->mmap_sem); | 1249 | up_read(&mm->mmap_sem); |
1249 | } | 1250 | } |
1250 | 1251 | ||
1251 | dotraplinkage void __kprobes | 1252 | dotraplinkage void __kprobes notrace |
1252 | do_page_fault(struct pt_regs *regs, unsigned long error_code) | 1253 | do_page_fault(struct pt_regs *regs, unsigned long error_code) |
1253 | { | 1254 | { |
1255 | unsigned long address = read_cr2(); /* Get the faulting address */ | ||
1254 | enum ctx_state prev_state; | 1256 | enum ctx_state prev_state; |
1255 | 1257 | ||
1258 | /* | ||
1259 | * We must have this function tagged with __kprobes, notrace and call | ||
1260 | * read_cr2() before calling anything else. To avoid calling any kind | ||
1261 | * of tracing machinery before we've observed the CR2 value. | ||
1262 | * | ||
1263 | * exception_{enter,exit}() contain all sorts of tracepoints. | ||
1264 | */ | ||
1265 | |||
1256 | prev_state = exception_enter(); | 1266 | prev_state = exception_enter(); |
1257 | __do_page_fault(regs, error_code); | 1267 | __do_page_fault(regs, error_code, address); |
1258 | exception_exit(prev_state); | 1268 | exception_exit(prev_state); |
1259 | } | 1269 | } |
1260 | 1270 | ||
1261 | static void trace_page_fault_entries(struct pt_regs *regs, | 1271 | #ifdef CONFIG_TRACING |
1272 | static void trace_page_fault_entries(unsigned long address, struct pt_regs *regs, | ||
1262 | unsigned long error_code) | 1273 | unsigned long error_code) |
1263 | { | 1274 | { |
1264 | if (user_mode(regs)) | 1275 | if (user_mode(regs)) |
1265 | trace_page_fault_user(read_cr2(), regs, error_code); | 1276 | trace_page_fault_user(address, regs, error_code); |
1266 | else | 1277 | else |
1267 | trace_page_fault_kernel(read_cr2(), regs, error_code); | 1278 | trace_page_fault_kernel(address, regs, error_code); |
1268 | } | 1279 | } |
1269 | 1280 | ||
1270 | dotraplinkage void __kprobes | 1281 | dotraplinkage void __kprobes notrace |
1271 | trace_do_page_fault(struct pt_regs *regs, unsigned long error_code) | 1282 | trace_do_page_fault(struct pt_regs *regs, unsigned long error_code) |
1272 | { | 1283 | { |
1284 | /* | ||
1285 | * The exception_enter and tracepoint processing could | ||
1286 | * trigger another page faults (user space callchain | ||
1287 | * reading) and destroy the original cr2 value, so read | ||
1288 | * the faulting address now. | ||
1289 | */ | ||
1290 | unsigned long address = read_cr2(); | ||
1273 | enum ctx_state prev_state; | 1291 | enum ctx_state prev_state; |
1274 | 1292 | ||
1275 | prev_state = exception_enter(); | 1293 | prev_state = exception_enter(); |
1276 | trace_page_fault_entries(regs, error_code); | 1294 | trace_page_fault_entries(address, regs, error_code); |
1277 | __do_page_fault(regs, error_code); | 1295 | __do_page_fault(regs, error_code, address); |
1278 | exception_exit(prev_state); | 1296 | exception_exit(prev_state); |
1279 | } | 1297 | } |
1298 | #endif /* CONFIG_TRACING */ | ||