spu_fault.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * SPU mm fault handler
  3. *
  4. * (C) Copyright IBM Deutschland Entwicklung GmbH 2007
  5. *
  6. * Author: Arnd Bergmann <arndb@de.ibm.com>
  7. * Author: Jeremy Kerr <jk@ozlabs.org>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2, or (at your option)
  12. * any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23. #include <linux/sched.h>
  24. #include <linux/mm.h>
  25. #include <linux/module.h>
  26. #include <asm/spu.h>
  27. #include <asm/spu_csa.h>
  28. /*
  29. * This ought to be kept in sync with the powerpc specific do_page_fault
  30. * function. Currently, there are a few corner cases that we haven't had
  31. * to handle fortunately.
  32. */
  33. int spu_handle_mm_fault(struct mm_struct *mm, unsigned long ea,
  34. unsigned long dsisr, unsigned *flt)
  35. {
  36. struct vm_area_struct *vma;
  37. unsigned long is_write;
  38. int ret;
  39. #if 0
  40. if (!IS_VALID_EA(ea)) {
  41. return -EFAULT;
  42. }
  43. #endif /* XXX */
  44. if (mm == NULL) {
  45. return -EFAULT;
  46. }
  47. if (mm->pgd == NULL) {
  48. return -EFAULT;
  49. }
  50. down_read(&mm->mmap_sem);
  51. vma = find_vma(mm, ea);
  52. if (!vma)
  53. goto bad_area;
  54. if (vma->vm_start <= ea)
  55. goto good_area;
  56. if (!(vma->vm_flags & VM_GROWSDOWN))
  57. goto bad_area;
  58. if (expand_stack(vma, ea))
  59. goto bad_area;
  60. good_area:
  61. is_write = dsisr & MFC_DSISR_ACCESS_PUT;
  62. if (is_write) {
  63. if (!(vma->vm_flags & VM_WRITE))
  64. goto bad_area;
  65. } else {
  66. if (dsisr & MFC_DSISR_ACCESS_DENIED)
  67. goto bad_area;
  68. if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
  69. goto bad_area;
  70. }
  71. ret = 0;
  72. *flt = handle_mm_fault(mm, vma, ea, is_write);
  73. if (unlikely(*flt & VM_FAULT_ERROR)) {
  74. if (*flt & VM_FAULT_OOM) {
  75. ret = -ENOMEM;
  76. goto bad_area;
  77. } else if (*flt & VM_FAULT_SIGBUS) {
  78. ret = -EFAULT;
  79. goto bad_area;
  80. }
  81. BUG();
  82. }
  83. if (*flt & VM_FAULT_MAJOR)
  84. current->maj_flt++;
  85. else
  86. current->min_flt++;
  87. up_read(&mm->mmap_sem);
  88. return ret;
  89. bad_area:
  90. up_read(&mm->mmap_sem);
  91. return -EFAULT;
  92. }
  93. EXPORT_SYMBOL_GPL(spu_handle_mm_fault);