tlbex_32.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * TLB miss handler for SH with an MMU.
  3. *
  4. * Copyright (C) 1999 Niibe Yutaka
  5. * Copyright (C) 2003 - 2012 Paul Mundt
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/mm.h>
  13. #include <linux/kprobes.h>
  14. #include <linux/kdebug.h>
  15. #include <asm/mmu_context.h>
  16. #include <asm/thread_info.h>
  17. /*
  18. * Called with interrupts disabled.
  19. */
  20. asmlinkage int __kprobes
  21. handle_tlbmiss(struct pt_regs *regs, unsigned long error_code,
  22. unsigned long address)
  23. {
  24. pgd_t *pgd;
  25. p4d_t *p4d;
  26. pud_t *pud;
  27. pmd_t *pmd;
  28. pte_t *pte;
  29. pte_t entry;
  30. /*
  31. * We don't take page faults for P1, P2, and parts of P4, these
  32. * are always mapped, whether it be due to legacy behaviour in
  33. * 29-bit mode, or due to PMB configuration in 32-bit mode.
  34. */
  35. if (address >= P3SEG && address < P3_ADDR_MAX) {
  36. pgd = pgd_offset_k(address);
  37. } else {
  38. if (unlikely(address >= TASK_SIZE || !current->mm))
  39. return 1;
  40. pgd = pgd_offset(current->mm, address);
  41. }
  42. p4d = p4d_offset(pgd, address);
  43. if (p4d_none_or_clear_bad(p4d))
  44. return 1;
  45. pud = pud_offset(p4d, address);
  46. if (pud_none_or_clear_bad(pud))
  47. return 1;
  48. pmd = pmd_offset(pud, address);
  49. if (pmd_none_or_clear_bad(pmd))
  50. return 1;
  51. pte = pte_offset_kernel(pmd, address);
  52. entry = *pte;
  53. if (unlikely(pte_none(entry) || pte_not_present(entry)))
  54. return 1;
  55. if (unlikely(error_code && !pte_write(entry)))
  56. return 1;
  57. if (error_code)
  58. entry = pte_mkdirty(entry);
  59. entry = pte_mkyoung(entry);
  60. set_pte(pte, entry);
  61. #if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SMP)
  62. /*
  63. * SH-4 does not set MMUCR.RC to the corresponding TLB entry in
  64. * the case of an initial page write exception, so we need to
  65. * flush it in order to avoid potential TLB entry duplication.
  66. */
  67. if (error_code == FAULT_CODE_INITIAL)
  68. local_flush_tlb_one(get_asid(), address & PAGE_MASK);
  69. #endif
  70. set_thread_fault_code(error_code);
  71. update_mmu_cache(NULL, address, pte);
  72. return 0;
  73. }