putuser.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * __put_user functions.
  4. *
  5. * (C) Copyright 2005 Linus Torvalds
  6. * (C) Copyright 2005 Andi Kleen
  7. * (C) Copyright 2008 Glauber Costa
  8. *
  9. * These functions have a non-standard call interface
  10. * to make them more efficient, especially as they
  11. * return an error value in addition to the "real"
  12. * return value.
  13. */
  14. #include <linux/linkage.h>
  15. #include <asm/thread_info.h>
  16. #include <asm/errno.h>
  17. #include <asm/asm.h>
  18. #include <asm/smap.h>
  19. #include <asm/export.h>
  20. /*
  21. * __put_user_X
  22. *
  23. * Inputs: %eax[:%edx] contains the data
  24. * %ecx contains the address
  25. *
  26. * Outputs: %ecx is error code (0 or -EFAULT)
  27. *
  28. * Clobbers: %ebx needed for task pointer
  29. *
  30. * These functions should not modify any other registers,
  31. * as they get called from within inline assembly.
  32. */
  33. #ifdef CONFIG_X86_5LEVEL
  34. #define LOAD_TASK_SIZE_MINUS_N(n) \
  35. ALTERNATIVE __stringify(mov $((1 << 47) - 4096 - (n)),%rbx), \
  36. __stringify(mov $((1 << 56) - 4096 - (n)),%rbx), X86_FEATURE_LA57
  37. #else
  38. #define LOAD_TASK_SIZE_MINUS_N(n) \
  39. mov $(TASK_SIZE_MAX - (n)),%_ASM_BX
  40. #endif
  41. .text
  42. SYM_FUNC_START(__put_user_1)
  43. LOAD_TASK_SIZE_MINUS_N(0)
  44. cmp %_ASM_BX,%_ASM_CX
  45. jae .Lbad_put_user
  46. SYM_INNER_LABEL(__put_user_nocheck_1, SYM_L_GLOBAL)
  47. ENDBR
  48. ASM_STAC
  49. 1: movb %al,(%_ASM_CX)
  50. xor %ecx,%ecx
  51. ASM_CLAC
  52. RET
  53. SYM_FUNC_END(__put_user_1)
  54. EXPORT_SYMBOL(__put_user_1)
  55. EXPORT_SYMBOL(__put_user_nocheck_1)
  56. SYM_FUNC_START(__put_user_2)
  57. LOAD_TASK_SIZE_MINUS_N(1)
  58. cmp %_ASM_BX,%_ASM_CX
  59. jae .Lbad_put_user
  60. SYM_INNER_LABEL(__put_user_nocheck_2, SYM_L_GLOBAL)
  61. ENDBR
  62. ASM_STAC
  63. 2: movw %ax,(%_ASM_CX)
  64. xor %ecx,%ecx
  65. ASM_CLAC
  66. RET
  67. SYM_FUNC_END(__put_user_2)
  68. EXPORT_SYMBOL(__put_user_2)
  69. EXPORT_SYMBOL(__put_user_nocheck_2)
  70. SYM_FUNC_START(__put_user_4)
  71. LOAD_TASK_SIZE_MINUS_N(3)
  72. cmp %_ASM_BX,%_ASM_CX
  73. jae .Lbad_put_user
  74. SYM_INNER_LABEL(__put_user_nocheck_4, SYM_L_GLOBAL)
  75. ENDBR
  76. ASM_STAC
  77. 3: movl %eax,(%_ASM_CX)
  78. xor %ecx,%ecx
  79. ASM_CLAC
  80. RET
  81. SYM_FUNC_END(__put_user_4)
  82. EXPORT_SYMBOL(__put_user_4)
  83. EXPORT_SYMBOL(__put_user_nocheck_4)
  84. SYM_FUNC_START(__put_user_8)
  85. LOAD_TASK_SIZE_MINUS_N(7)
  86. cmp %_ASM_BX,%_ASM_CX
  87. jae .Lbad_put_user
  88. SYM_INNER_LABEL(__put_user_nocheck_8, SYM_L_GLOBAL)
  89. ENDBR
  90. ASM_STAC
  91. 4: mov %_ASM_AX,(%_ASM_CX)
  92. #ifdef CONFIG_X86_32
  93. 5: movl %edx,4(%_ASM_CX)
  94. #endif
  95. xor %ecx,%ecx
  96. ASM_CLAC
  97. RET
  98. SYM_FUNC_END(__put_user_8)
  99. EXPORT_SYMBOL(__put_user_8)
  100. EXPORT_SYMBOL(__put_user_nocheck_8)
  101. SYM_CODE_START_LOCAL(.Lbad_put_user_clac)
  102. ASM_CLAC
  103. .Lbad_put_user:
  104. movl $-EFAULT,%ecx
  105. RET
  106. SYM_CODE_END(.Lbad_put_user_clac)
  107. _ASM_EXTABLE_UA(1b, .Lbad_put_user_clac)
  108. _ASM_EXTABLE_UA(2b, .Lbad_put_user_clac)
  109. _ASM_EXTABLE_UA(3b, .Lbad_put_user_clac)
  110. _ASM_EXTABLE_UA(4b, .Lbad_put_user_clac)
  111. #ifdef CONFIG_X86_32
  112. _ASM_EXTABLE_UA(5b, .Lbad_put_user_clac)
  113. #endif