spu_fault.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/export.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 (mm == NULL)
  40. return -EFAULT;
  41. if (mm->pgd == NULL)
  42. return -EFAULT;
  43. down_read(&mm->mmap_sem);
  44. ret = -EFAULT;
  45. vma = find_vma(mm, ea);
  46. if (!vma)
  47. goto out_unlock;
  48. if (ea < vma->vm_start) {
  49. if (!(vma->vm_flags & VM_GROWSDOWN))
  50. goto out_unlock;
  51. if (expand_stack(vma, ea))
  52. goto out_unlock;
  53. }
  54. is_write = dsisr & MFC_DSISR_ACCESS_PUT;
  55. if (is_write) {
  56. if (!(vma->vm_flags & VM_WRITE))
  57. goto out_unlock;
  58. } else {
  59. if (dsisr & MFC_DSISR_ACCESS_DENIED)
  60. goto out_unlock;
  61. if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
  62. goto out_unlock;
  63. }
  64. ret = 0;
  65. *flt = handle_mm_fault(mm, vma, ea, is_write ? FAULT_FLAG_WRITE : 0);
  66. if (unlikely(*flt & VM_FAULT_ERROR)) {
  67. if (*flt & VM_FAULT_OOM) {
  68. ret = -ENOMEM;
  69. goto out_unlock;
  70. } else if (*flt & (VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV)) {
  71. ret = -EFAULT;
  72. goto out_unlock;
  73. }
  74. BUG();
  75. }
  76. if (*flt & VM_FAULT_MAJOR)
  77. current->maj_flt++;
  78. else
  79. current->min_flt++;
  80. out_unlock:
  81. up_read(&mm->mmap_sem);
  82. return ret;
  83. }
  84. EXPORT_SYMBOL_GPL(spu_handle_mm_fault);