sys_compat.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Based on arch/arm/kernel/sys_arm.c
  4. *
  5. * Copyright (C) People who wrote linux/arch/i386/kernel/sys_i386.c
  6. * Copyright (C) 1995, 1996 Russell King.
  7. * Copyright (C) 2012 ARM Ltd.
  8. */
  9. #include <linux/compat.h>
  10. #include <linux/cpufeature.h>
  11. #include <linux/sched.h>
  12. #include <linux/sched/signal.h>
  13. #include <linux/slab.h>
  14. #include <linux/syscalls.h>
  15. #include <linux/uaccess.h>
  16. #include <asm/cacheflush.h>
  17. #include <asm/system_misc.h>
  18. #include <asm/tlbflush.h>
  19. #include <asm/unistd.h>
  20. static long
  21. __do_compat_cache_op(unsigned long start, unsigned long end)
  22. {
  23. long ret;
  24. do {
  25. unsigned long chunk = min(PAGE_SIZE, end - start);
  26. if (fatal_signal_pending(current))
  27. return 0;
  28. if (cpus_have_const_cap(ARM64_WORKAROUND_1542419)) {
  29. /*
  30. * The workaround requires an inner-shareable tlbi.
  31. * We pick the reserved-ASID to minimise the impact.
  32. */
  33. __tlbi(aside1is, __TLBI_VADDR(0, 0));
  34. dsb(ish);
  35. }
  36. ret = caches_clean_inval_user_pou(start, start + chunk);
  37. if (ret)
  38. return ret;
  39. cond_resched();
  40. start += chunk;
  41. } while (start < end);
  42. return 0;
  43. }
  44. static inline long
  45. do_compat_cache_op(unsigned long start, unsigned long end, int flags)
  46. {
  47. if (end < start || flags)
  48. return -EINVAL;
  49. if (!access_ok((const void __user *)start, end - start))
  50. return -EFAULT;
  51. return __do_compat_cache_op(start, end);
  52. }
  53. /*
  54. * Handle all unrecognised system calls.
  55. */
  56. long compat_arm_syscall(struct pt_regs *regs, int scno)
  57. {
  58. unsigned long addr;
  59. switch (scno) {
  60. /*
  61. * Flush a region from virtual address 'r0' to virtual address 'r1'
  62. * _exclusive_. There is no alignment requirement on either address;
  63. * user space does not need to know the hardware cache layout.
  64. *
  65. * r2 contains flags. It should ALWAYS be passed as ZERO until it
  66. * is defined to be something else. For now we ignore it, but may
  67. * the fires of hell burn in your belly if you break this rule. ;)
  68. *
  69. * (at a later date, we may want to allow this call to not flush
  70. * various aspects of the cache. Passing '0' will guarantee that
  71. * everything necessary gets flushed to maintain consistency in
  72. * the specified region).
  73. */
  74. case __ARM_NR_compat_cacheflush:
  75. return do_compat_cache_op(regs->regs[0], regs->regs[1], regs->regs[2]);
  76. case __ARM_NR_compat_set_tls:
  77. current->thread.uw.tp_value = regs->regs[0];
  78. /*
  79. * Protect against register corruption from context switch.
  80. * See comment in tls_thread_flush.
  81. */
  82. barrier();
  83. write_sysreg(regs->regs[0], tpidrro_el0);
  84. return 0;
  85. default:
  86. /*
  87. * Calls 0xf0xxx..0xf07ff are defined to return -ENOSYS
  88. * if not implemented, rather than raising SIGILL. This
  89. * way the calling program can gracefully determine whether
  90. * a feature is supported.
  91. */
  92. if (scno < __ARM_NR_COMPAT_END)
  93. return -ENOSYS;
  94. break;
  95. }
  96. addr = instruction_pointer(regs) - (compat_thumb_mode(regs) ? 2 : 4);
  97. arm64_notify_die("Oops - bad compat syscall(2)", regs,
  98. SIGILL, ILL_ILLTRP, addr, 0);
  99. return 0;
  100. }