| .. | .. |
|---|
| 18 | 18 | #include <linux/extable.h> |
|---|
| 19 | 19 | #include <linux/uaccess.h> |
|---|
| 20 | 20 | #include <linux/hugetlb.h> |
|---|
| 21 | +#include <linux/perf_event.h> |
|---|
| 21 | 22 | |
|---|
| 22 | 23 | #include <asm/traps.h> |
|---|
| 23 | 24 | |
|---|
| .. | .. |
|---|
| 66 | 67 | case 0x30000000: /* coproc2 */ |
|---|
| 67 | 68 | if (bit22set(inst)) |
|---|
| 68 | 69 | return VM_WRITE; |
|---|
| 70 | + fallthrough; |
|---|
| 69 | 71 | |
|---|
| 70 | 72 | case 0x0: /* indexed/memory management */ |
|---|
| 71 | 73 | if (bit22set(inst)) { |
|---|
| .. | .. |
|---|
| 273 | 275 | if (!mm) |
|---|
| 274 | 276 | goto no_context; |
|---|
| 275 | 277 | |
|---|
| 276 | | - flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE; |
|---|
| 278 | + flags = FAULT_FLAG_DEFAULT; |
|---|
| 277 | 279 | if (user_mode(regs)) |
|---|
| 278 | 280 | flags |= FAULT_FLAG_USER; |
|---|
| 279 | 281 | |
|---|
| 280 | 282 | acc_type = parisc_acctyp(code, regs->iir); |
|---|
| 281 | 283 | if (acc_type & VM_WRITE) |
|---|
| 282 | 284 | flags |= FAULT_FLAG_WRITE; |
|---|
| 285 | + perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address); |
|---|
| 283 | 286 | retry: |
|---|
| 284 | | - down_read(&mm->mmap_sem); |
|---|
| 287 | + mmap_read_lock(mm); |
|---|
| 285 | 288 | vma = find_vma_prev(mm, address, &prev_vma); |
|---|
| 286 | 289 | if (!vma || address < vma->vm_start) |
|---|
| 287 | 290 | goto check_expansion; |
|---|
| .. | .. |
|---|
| 301 | 304 | * fault. |
|---|
| 302 | 305 | */ |
|---|
| 303 | 306 | |
|---|
| 304 | | - fault = handle_mm_fault(vma, address, flags); |
|---|
| 307 | + fault = handle_mm_fault(vma, address, flags, regs); |
|---|
| 305 | 308 | |
|---|
| 306 | | - if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(current)) |
|---|
| 309 | + if (fault_signal_pending(fault, regs)) |
|---|
| 307 | 310 | return; |
|---|
| 308 | 311 | |
|---|
| 309 | 312 | if (unlikely(fault & VM_FAULT_ERROR)) { |
|---|
| .. | .. |
|---|
| 322 | 325 | BUG(); |
|---|
| 323 | 326 | } |
|---|
| 324 | 327 | if (flags & FAULT_FLAG_ALLOW_RETRY) { |
|---|
| 325 | | - if (fault & VM_FAULT_MAJOR) |
|---|
| 326 | | - current->maj_flt++; |
|---|
| 327 | | - else |
|---|
| 328 | | - current->min_flt++; |
|---|
| 329 | 328 | if (fault & VM_FAULT_RETRY) { |
|---|
| 330 | | - flags &= ~FAULT_FLAG_ALLOW_RETRY; |
|---|
| 331 | | - |
|---|
| 332 | 329 | /* |
|---|
| 333 | | - * No need to up_read(&mm->mmap_sem) as we would |
|---|
| 330 | + * No need to mmap_read_unlock(mm) as we would |
|---|
| 334 | 331 | * have already released it in __lock_page_or_retry |
|---|
| 335 | 332 | * in mm/filemap.c. |
|---|
| 336 | 333 | */ |
|---|
| 337 | | - |
|---|
| 334 | + flags |= FAULT_FLAG_TRIED; |
|---|
| 338 | 335 | goto retry; |
|---|
| 339 | 336 | } |
|---|
| 340 | 337 | } |
|---|
| 341 | | - up_read(&mm->mmap_sem); |
|---|
| 338 | + mmap_read_unlock(mm); |
|---|
| 342 | 339 | return; |
|---|
| 343 | 340 | |
|---|
| 344 | 341 | check_expansion: |
|---|
| .. | .. |
|---|
| 350 | 347 | * Something tried to access memory that isn't in our memory map.. |
|---|
| 351 | 348 | */ |
|---|
| 352 | 349 | bad_area: |
|---|
| 353 | | - up_read(&mm->mmap_sem); |
|---|
| 350 | + mmap_read_unlock(mm); |
|---|
| 354 | 351 | |
|---|
| 355 | 352 | if (user_mode(regs)) { |
|---|
| 356 | 353 | int signo, si_code; |
|---|
| .. | .. |
|---|
| 373 | 370 | } |
|---|
| 374 | 371 | |
|---|
| 375 | 372 | /* probably address is outside of mapped file */ |
|---|
| 376 | | - /* fall through */ |
|---|
| 373 | + fallthrough; |
|---|
| 377 | 374 | case 17: /* NA data TLB miss / page fault */ |
|---|
| 378 | 375 | case 18: /* Unaligned access - PCXS only */ |
|---|
| 379 | 376 | signo = SIGBUS; |
|---|
| .. | .. |
|---|
| 403 | 400 | lsb = PAGE_SHIFT; |
|---|
| 404 | 401 | |
|---|
| 405 | 402 | force_sig_mceerr(BUS_MCEERR_AR, (void __user *) address, |
|---|
| 406 | | - lsb, current); |
|---|
| 403 | + lsb); |
|---|
| 407 | 404 | return; |
|---|
| 408 | 405 | } |
|---|
| 409 | 406 | #endif |
|---|
| 410 | 407 | show_signal_msg(regs, code, address, tsk, vma); |
|---|
| 411 | 408 | |
|---|
| 412 | | - force_sig_fault(signo, si_code, (void __user *) address, current); |
|---|
| 409 | + force_sig_fault(signo, si_code, (void __user *) address); |
|---|
| 413 | 410 | return; |
|---|
| 414 | 411 | } |
|---|
| 415 | 412 | |
|---|
| .. | .. |
|---|
| 422 | 419 | parisc_terminate("Bad Address (null pointer deref?)", regs, code, address); |
|---|
| 423 | 420 | |
|---|
| 424 | 421 | out_of_memory: |
|---|
| 425 | | - up_read(&mm->mmap_sem); |
|---|
| 422 | + mmap_read_unlock(mm); |
|---|
| 426 | 423 | if (!user_mode(regs)) |
|---|
| 427 | 424 | goto no_context; |
|---|
| 428 | 425 | pagefault_out_of_memory(); |
|---|
| 429 | 426 | } |
|---|
| 427 | + |
|---|
| 428 | +/* Handle non-access data TLB miss faults. |
|---|
| 429 | + * |
|---|
| 430 | + * For probe instructions, accesses to userspace are considered allowed |
|---|
| 431 | + * if they lie in a valid VMA and the access type matches. We are not |
|---|
| 432 | + * allowed to handle MM faults here so there may be situations where an |
|---|
| 433 | + * actual access would fail even though a probe was successful. |
|---|
| 434 | + */ |
|---|
| 435 | +int |
|---|
| 436 | +handle_nadtlb_fault(struct pt_regs *regs) |
|---|
| 437 | +{ |
|---|
| 438 | + unsigned long insn = regs->iir; |
|---|
| 439 | + int breg, treg, xreg, val = 0; |
|---|
| 440 | + struct vm_area_struct *vma, *prev_vma; |
|---|
| 441 | + struct task_struct *tsk; |
|---|
| 442 | + struct mm_struct *mm; |
|---|
| 443 | + unsigned long address; |
|---|
| 444 | + unsigned long acc_type; |
|---|
| 445 | + |
|---|
| 446 | + switch (insn & 0x380) { |
|---|
| 447 | + case 0x280: |
|---|
| 448 | + /* FDC instruction */ |
|---|
| 449 | + fallthrough; |
|---|
| 450 | + case 0x380: |
|---|
| 451 | + /* PDC and FIC instructions */ |
|---|
| 452 | + if (printk_ratelimit()) { |
|---|
| 453 | + pr_warn("BUG: nullifying cache flush/purge instruction\n"); |
|---|
| 454 | + show_regs(regs); |
|---|
| 455 | + } |
|---|
| 456 | + if (insn & 0x20) { |
|---|
| 457 | + /* Base modification */ |
|---|
| 458 | + breg = (insn >> 21) & 0x1f; |
|---|
| 459 | + xreg = (insn >> 16) & 0x1f; |
|---|
| 460 | + if (breg && xreg) |
|---|
| 461 | + regs->gr[breg] += regs->gr[xreg]; |
|---|
| 462 | + } |
|---|
| 463 | + regs->gr[0] |= PSW_N; |
|---|
| 464 | + return 1; |
|---|
| 465 | + |
|---|
| 466 | + case 0x180: |
|---|
| 467 | + /* PROBE instruction */ |
|---|
| 468 | + treg = insn & 0x1f; |
|---|
| 469 | + if (regs->isr) { |
|---|
| 470 | + tsk = current; |
|---|
| 471 | + mm = tsk->mm; |
|---|
| 472 | + if (mm) { |
|---|
| 473 | + /* Search for VMA */ |
|---|
| 474 | + address = regs->ior; |
|---|
| 475 | + mmap_read_lock(mm); |
|---|
| 476 | + vma = find_vma_prev(mm, address, &prev_vma); |
|---|
| 477 | + mmap_read_unlock(mm); |
|---|
| 478 | + |
|---|
| 479 | + /* |
|---|
| 480 | + * Check if access to the VMA is okay. |
|---|
| 481 | + * We don't allow for stack expansion. |
|---|
| 482 | + */ |
|---|
| 483 | + acc_type = (insn & 0x40) ? VM_WRITE : VM_READ; |
|---|
| 484 | + if (vma |
|---|
| 485 | + && address >= vma->vm_start |
|---|
| 486 | + && (vma->vm_flags & acc_type) == acc_type) |
|---|
| 487 | + val = 1; |
|---|
| 488 | + } |
|---|
| 489 | + } |
|---|
| 490 | + if (treg) |
|---|
| 491 | + regs->gr[treg] = val; |
|---|
| 492 | + regs->gr[0] |= PSW_N; |
|---|
| 493 | + return 1; |
|---|
| 494 | + |
|---|
| 495 | + case 0x300: |
|---|
| 496 | + /* LPA instruction */ |
|---|
| 497 | + if (insn & 0x20) { |
|---|
| 498 | + /* Base modification */ |
|---|
| 499 | + breg = (insn >> 21) & 0x1f; |
|---|
| 500 | + xreg = (insn >> 16) & 0x1f; |
|---|
| 501 | + if (breg && xreg) |
|---|
| 502 | + regs->gr[breg] += regs->gr[xreg]; |
|---|
| 503 | + } |
|---|
| 504 | + treg = insn & 0x1f; |
|---|
| 505 | + if (treg) |
|---|
| 506 | + regs->gr[treg] = 0; |
|---|
| 507 | + regs->gr[0] |= PSW_N; |
|---|
| 508 | + return 1; |
|---|
| 509 | + |
|---|
| 510 | + default: |
|---|
| 511 | + break; |
|---|
| 512 | + } |
|---|
| 513 | + |
|---|
| 514 | + return 0; |
|---|
| 515 | +} |
|---|