clear_user.S 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2021 Arm Ltd.
  4. */
  5. #include <linux/linkage.h>
  6. #include <asm/asm-uaccess.h>
  7. .text
  8. /* Prototype: int __arch_clear_user(void *addr, size_t sz)
  9. * Purpose : clear some user memory
  10. * Params : addr - user memory address to clear
  11. * : sz - number of bytes to clear
  12. * Returns : number of bytes NOT cleared
  13. *
  14. * Alignment fixed up by hardware.
  15. */
  16. .p2align 4
  17. // Alignment is for the loop, but since the prologue (including BTI)
  18. // is also 16 bytes we can keep any padding outside the function
  19. SYM_FUNC_START(__arch_clear_user)
  20. add x2, x0, x1
  21. subs x1, x1, #8
  22. b.mi 2f
  23. 1:
  24. USER(9f, sttr xzr, [x0])
  25. add x0, x0, #8
  26. subs x1, x1, #8
  27. b.hi 1b
  28. USER(9f, sttr xzr, [x2, #-8])
  29. mov x0, #0
  30. ret
  31. 2: tbz x1, #2, 3f
  32. USER(9f, sttr wzr, [x0])
  33. USER(8f, sttr wzr, [x2, #-4])
  34. mov x0, #0
  35. ret
  36. 3: tbz x1, #1, 4f
  37. USER(9f, sttrh wzr, [x0])
  38. 4: tbz x1, #0, 5f
  39. USER(7f, sttrb wzr, [x2, #-1])
  40. 5: mov x0, #0
  41. ret
  42. // Exception fixups
  43. 7: sub x0, x2, #5 // Adjust for faulting on the final byte...
  44. 8: add x0, x0, #4 // ...or the second word of the 4-7 byte case
  45. 9: sub x0, x2, x0
  46. ret
  47. SYM_FUNC_END(__arch_clear_user)
  48. EXPORT_SYMBOL(__arch_clear_user)