uaccess.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /*
  2. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef _ASM_TILE_UACCESS_H
  15. #define _ASM_TILE_UACCESS_H
  16. /*
  17. * User space memory access functions
  18. */
  19. #include <linux/sched.h>
  20. #include <linux/mm.h>
  21. #include <asm-generic/uaccess-unaligned.h>
  22. #include <asm/processor.h>
  23. #include <asm/page.h>
  24. #define VERIFY_READ 0
  25. #define VERIFY_WRITE 1
  26. /*
  27. * The fs value determines whether argument validity checking should be
  28. * performed or not. If get_fs() == USER_DS, checking is performed, with
  29. * get_fs() == KERNEL_DS, checking is bypassed.
  30. *
  31. * For historical reasons, these macros are grossly misnamed.
  32. */
  33. #define MAKE_MM_SEG(a) ((mm_segment_t) { (a) })
  34. #define KERNEL_DS MAKE_MM_SEG(-1UL)
  35. #define USER_DS MAKE_MM_SEG(PAGE_OFFSET)
  36. #define get_ds() (KERNEL_DS)
  37. #define get_fs() (current_thread_info()->addr_limit)
  38. #define set_fs(x) (current_thread_info()->addr_limit = (x))
  39. #define segment_eq(a, b) ((a).seg == (b).seg)
  40. #ifndef __tilegx__
  41. /*
  42. * We could allow mapping all 16 MB at 0xfc000000, but we set up a
  43. * special hack in arch_setup_additional_pages() to auto-create a mapping
  44. * for the first 16 KB, and it would seem strange to have different
  45. * user-accessible semantics for memory at 0xfc000000 and above 0xfc004000.
  46. */
  47. static inline int is_arch_mappable_range(unsigned long addr,
  48. unsigned long size)
  49. {
  50. return (addr >= MEM_USER_INTRPT &&
  51. addr < (MEM_USER_INTRPT + INTRPT_SIZE) &&
  52. size <= (MEM_USER_INTRPT + INTRPT_SIZE) - addr);
  53. }
  54. #define is_arch_mappable_range is_arch_mappable_range
  55. #else
  56. #define is_arch_mappable_range(addr, size) 0
  57. #endif
  58. /*
  59. * Test whether a block of memory is a valid user space address.
  60. * Returns 0 if the range is valid, nonzero otherwise.
  61. */
  62. int __range_ok(unsigned long addr, unsigned long size);
  63. /**
  64. * access_ok: - Checks if a user space pointer is valid
  65. * @type: Type of access: %VERIFY_READ or %VERIFY_WRITE. Note that
  66. * %VERIFY_WRITE is a superset of %VERIFY_READ - if it is safe
  67. * to write to a block, it is always safe to read from it.
  68. * @addr: User space pointer to start of block to check
  69. * @size: Size of block to check
  70. *
  71. * Context: User context only. This function may sleep.
  72. *
  73. * Checks if a pointer to a block of memory in user space is valid.
  74. *
  75. * Returns true (nonzero) if the memory block may be valid, false (zero)
  76. * if it is definitely invalid.
  77. *
  78. * Note that, depending on architecture, this function probably just
  79. * checks that the pointer is in the user space range - after calling
  80. * this function, memory access functions may still return -EFAULT.
  81. */
  82. #define access_ok(type, addr, size) ({ \
  83. __chk_user_ptr(addr); \
  84. likely(__range_ok((unsigned long)(addr), (size)) == 0); \
  85. })
  86. /*
  87. * The exception table consists of pairs of addresses: the first is the
  88. * address of an instruction that is allowed to fault, and the second is
  89. * the address at which the program should continue. No registers are
  90. * modified, so it is entirely up to the continuation code to figure out
  91. * what to do.
  92. *
  93. * All the routines below use bits of fixup code that are out of line
  94. * with the main instruction path. This means when everything is well,
  95. * we don't even have to jump over them. Further, they do not intrude
  96. * on our cache or tlb entries.
  97. */
  98. struct exception_table_entry {
  99. unsigned long insn, fixup;
  100. };
  101. extern int fixup_exception(struct pt_regs *regs);
  102. /*
  103. * Support macros for __get_user().
  104. *
  105. * Implementation note: The "case 8" logic of casting to the type of
  106. * the result of subtracting the value from itself is basically a way
  107. * of keeping all integer types the same, but casting any pointers to
  108. * ptrdiff_t, i.e. also an integer type. This way there are no
  109. * questionable casts seen by the compiler on an ILP32 platform.
  110. *
  111. * Note that __get_user() and __put_user() assume proper alignment.
  112. */
  113. #ifdef __LP64__
  114. #define _ASM_PTR ".quad"
  115. #else
  116. #define _ASM_PTR ".long"
  117. #endif
  118. #define __get_user_asm(OP, x, ptr, ret) \
  119. asm volatile("1: {" #OP " %1, %2; movei %0, 0 }\n" \
  120. ".pushsection .fixup,\"ax\"\n" \
  121. "0: { movei %1, 0; movei %0, %3 }\n" \
  122. "j 9f\n" \
  123. ".section __ex_table,\"a\"\n" \
  124. _ASM_PTR " 1b, 0b\n" \
  125. ".popsection\n" \
  126. "9:" \
  127. : "=r" (ret), "=r" (x) \
  128. : "r" (ptr), "i" (-EFAULT))
  129. #ifdef __tilegx__
  130. #define __get_user_1(x, ptr, ret) __get_user_asm(ld1u, x, ptr, ret)
  131. #define __get_user_2(x, ptr, ret) __get_user_asm(ld2u, x, ptr, ret)
  132. #define __get_user_4(x, ptr, ret) __get_user_asm(ld4s, x, ptr, ret)
  133. #define __get_user_8(x, ptr, ret) __get_user_asm(ld, x, ptr, ret)
  134. #else
  135. #define __get_user_1(x, ptr, ret) __get_user_asm(lb_u, x, ptr, ret)
  136. #define __get_user_2(x, ptr, ret) __get_user_asm(lh_u, x, ptr, ret)
  137. #define __get_user_4(x, ptr, ret) __get_user_asm(lw, x, ptr, ret)
  138. #ifdef __LITTLE_ENDIAN
  139. #define __lo32(a, b) a
  140. #define __hi32(a, b) b
  141. #else
  142. #define __lo32(a, b) b
  143. #define __hi32(a, b) a
  144. #endif
  145. #define __get_user_8(x, ptr, ret) \
  146. ({ \
  147. unsigned int __a, __b; \
  148. asm volatile("1: { lw %1, %3; addi %2, %3, 4 }\n" \
  149. "2: { lw %2, %2; movei %0, 0 }\n" \
  150. ".pushsection .fixup,\"ax\"\n" \
  151. "0: { movei %1, 0; movei %2, 0 }\n" \
  152. "{ movei %0, %4; j 9f }\n" \
  153. ".section __ex_table,\"a\"\n" \
  154. ".word 1b, 0b\n" \
  155. ".word 2b, 0b\n" \
  156. ".popsection\n" \
  157. "9:" \
  158. : "=r" (ret), "=r" (__a), "=&r" (__b) \
  159. : "r" (ptr), "i" (-EFAULT)); \
  160. (x) = (__typeof(x))(__typeof((x)-(x))) \
  161. (((u64)__hi32(__a, __b) << 32) | \
  162. __lo32(__a, __b)); \
  163. })
  164. #endif
  165. extern int __get_user_bad(void)
  166. __attribute__((warning("sizeof __get_user argument not 1, 2, 4 or 8")));
  167. /**
  168. * __get_user: - Get a simple variable from user space, with less checking.
  169. * @x: Variable to store result.
  170. * @ptr: Source address, in user space.
  171. *
  172. * Context: User context only. This function may sleep.
  173. *
  174. * This macro copies a single simple variable from user space to kernel
  175. * space. It supports simple types like char and int, but not larger
  176. * data types like structures or arrays.
  177. *
  178. * @ptr must have pointer-to-simple-variable type, and the result of
  179. * dereferencing @ptr must be assignable to @x without a cast.
  180. *
  181. * Returns zero on success, or -EFAULT on error.
  182. * On error, the variable @x is set to zero.
  183. *
  184. * Caller must check the pointer with access_ok() before calling this
  185. * function.
  186. */
  187. #define __get_user(x, ptr) \
  188. ({ \
  189. int __ret; \
  190. __chk_user_ptr(ptr); \
  191. switch (sizeof(*(ptr))) { \
  192. case 1: __get_user_1(x, ptr, __ret); break; \
  193. case 2: __get_user_2(x, ptr, __ret); break; \
  194. case 4: __get_user_4(x, ptr, __ret); break; \
  195. case 8: __get_user_8(x, ptr, __ret); break; \
  196. default: __ret = __get_user_bad(); break; \
  197. } \
  198. __ret; \
  199. })
  200. /* Support macros for __put_user(). */
  201. #define __put_user_asm(OP, x, ptr, ret) \
  202. asm volatile("1: {" #OP " %1, %2; movei %0, 0 }\n" \
  203. ".pushsection .fixup,\"ax\"\n" \
  204. "0: { movei %0, %3; j 9f }\n" \
  205. ".section __ex_table,\"a\"\n" \
  206. _ASM_PTR " 1b, 0b\n" \
  207. ".popsection\n" \
  208. "9:" \
  209. : "=r" (ret) \
  210. : "r" (ptr), "r" (x), "i" (-EFAULT))
  211. #ifdef __tilegx__
  212. #define __put_user_1(x, ptr, ret) __put_user_asm(st1, x, ptr, ret)
  213. #define __put_user_2(x, ptr, ret) __put_user_asm(st2, x, ptr, ret)
  214. #define __put_user_4(x, ptr, ret) __put_user_asm(st4, x, ptr, ret)
  215. #define __put_user_8(x, ptr, ret) __put_user_asm(st, x, ptr, ret)
  216. #else
  217. #define __put_user_1(x, ptr, ret) __put_user_asm(sb, x, ptr, ret)
  218. #define __put_user_2(x, ptr, ret) __put_user_asm(sh, x, ptr, ret)
  219. #define __put_user_4(x, ptr, ret) __put_user_asm(sw, x, ptr, ret)
  220. #define __put_user_8(x, ptr, ret) \
  221. ({ \
  222. u64 __x = (__typeof((x)-(x)))(x); \
  223. int __lo = (int) __x, __hi = (int) (__x >> 32); \
  224. asm volatile("1: { sw %1, %2; addi %0, %1, 4 }\n" \
  225. "2: { sw %0, %3; movei %0, 0 }\n" \
  226. ".pushsection .fixup,\"ax\"\n" \
  227. "0: { movei %0, %4; j 9f }\n" \
  228. ".section __ex_table,\"a\"\n" \
  229. ".word 1b, 0b\n" \
  230. ".word 2b, 0b\n" \
  231. ".popsection\n" \
  232. "9:" \
  233. : "=&r" (ret) \
  234. : "r" (ptr), "r" (__lo32(__lo, __hi)), \
  235. "r" (__hi32(__lo, __hi)), "i" (-EFAULT)); \
  236. })
  237. #endif
  238. extern int __put_user_bad(void)
  239. __attribute__((warning("sizeof __put_user argument not 1, 2, 4 or 8")));
  240. /**
  241. * __put_user: - Write a simple value into user space, with less checking.
  242. * @x: Value to copy to user space.
  243. * @ptr: Destination address, in user space.
  244. *
  245. * Context: User context only. This function may sleep.
  246. *
  247. * This macro copies a single simple value from kernel space to user
  248. * space. It supports simple types like char and int, but not larger
  249. * data types like structures or arrays.
  250. *
  251. * @ptr must have pointer-to-simple-variable type, and @x must be assignable
  252. * to the result of dereferencing @ptr.
  253. *
  254. * Caller must check the pointer with access_ok() before calling this
  255. * function.
  256. *
  257. * Returns zero on success, or -EFAULT on error.
  258. */
  259. #define __put_user(x, ptr) \
  260. ({ \
  261. int __ret; \
  262. __chk_user_ptr(ptr); \
  263. switch (sizeof(*(ptr))) { \
  264. case 1: __put_user_1(x, ptr, __ret); break; \
  265. case 2: __put_user_2(x, ptr, __ret); break; \
  266. case 4: __put_user_4(x, ptr, __ret); break; \
  267. case 8: __put_user_8(x, ptr, __ret); break; \
  268. default: __ret = __put_user_bad(); break; \
  269. } \
  270. __ret; \
  271. })
  272. /*
  273. * The versions of get_user and put_user without initial underscores
  274. * check the address of their arguments to make sure they are not
  275. * in kernel space.
  276. */
  277. #define put_user(x, ptr) \
  278. ({ \
  279. __typeof__(*(ptr)) __user *__Pu_addr = (ptr); \
  280. access_ok(VERIFY_WRITE, (__Pu_addr), sizeof(*(__Pu_addr))) ? \
  281. __put_user((x), (__Pu_addr)) : \
  282. -EFAULT; \
  283. })
  284. #define get_user(x, ptr) \
  285. ({ \
  286. __typeof__(*(ptr)) const __user *__Gu_addr = (ptr); \
  287. access_ok(VERIFY_READ, (__Gu_addr), sizeof(*(__Gu_addr))) ? \
  288. __get_user((x), (__Gu_addr)) : \
  289. ((x) = 0, -EFAULT); \
  290. })
  291. /**
  292. * __copy_to_user() - copy data into user space, with less checking.
  293. * @to: Destination address, in user space.
  294. * @from: Source address, in kernel space.
  295. * @n: Number of bytes to copy.
  296. *
  297. * Context: User context only. This function may sleep.
  298. *
  299. * Copy data from kernel space to user space. Caller must check
  300. * the specified block with access_ok() before calling this function.
  301. *
  302. * Returns number of bytes that could not be copied.
  303. * On success, this will be zero.
  304. *
  305. * An alternate version - __copy_to_user_inatomic() - is designed
  306. * to be called from atomic context, typically bracketed by calls
  307. * to pagefault_disable() and pagefault_enable().
  308. */
  309. extern unsigned long __must_check __copy_to_user_inatomic(
  310. void __user *to, const void *from, unsigned long n);
  311. static inline unsigned long __must_check
  312. __copy_to_user(void __user *to, const void *from, unsigned long n)
  313. {
  314. might_fault();
  315. return __copy_to_user_inatomic(to, from, n);
  316. }
  317. static inline unsigned long __must_check
  318. copy_to_user(void __user *to, const void *from, unsigned long n)
  319. {
  320. if (access_ok(VERIFY_WRITE, to, n))
  321. n = __copy_to_user(to, from, n);
  322. return n;
  323. }
  324. /**
  325. * __copy_from_user() - copy data from user space, with less checking.
  326. * @to: Destination address, in kernel space.
  327. * @from: Source address, in user space.
  328. * @n: Number of bytes to copy.
  329. *
  330. * Context: User context only. This function may sleep.
  331. *
  332. * Copy data from user space to kernel space. Caller must check
  333. * the specified block with access_ok() before calling this function.
  334. *
  335. * Returns number of bytes that could not be copied.
  336. * On success, this will be zero.
  337. *
  338. * If some data could not be copied, this function will pad the copied
  339. * data to the requested size using zero bytes.
  340. *
  341. * An alternate version - __copy_from_user_inatomic() - is designed
  342. * to be called from atomic context, typically bracketed by calls
  343. * to pagefault_disable() and pagefault_enable(). This version
  344. * does *NOT* pad with zeros.
  345. */
  346. extern unsigned long __must_check __copy_from_user_inatomic(
  347. void *to, const void __user *from, unsigned long n);
  348. extern unsigned long __must_check __copy_from_user_zeroing(
  349. void *to, const void __user *from, unsigned long n);
  350. static inline unsigned long __must_check
  351. __copy_from_user(void *to, const void __user *from, unsigned long n)
  352. {
  353. might_fault();
  354. return __copy_from_user_zeroing(to, from, n);
  355. }
  356. static inline unsigned long __must_check
  357. _copy_from_user(void *to, const void __user *from, unsigned long n)
  358. {
  359. if (access_ok(VERIFY_READ, from, n))
  360. n = __copy_from_user(to, from, n);
  361. else
  362. memset(to, 0, n);
  363. return n;
  364. }
  365. #ifdef CONFIG_DEBUG_COPY_FROM_USER
  366. extern void copy_from_user_overflow(void)
  367. __compiletime_warning("copy_from_user() size is not provably correct");
  368. static inline unsigned long __must_check copy_from_user(void *to,
  369. const void __user *from,
  370. unsigned long n)
  371. {
  372. int sz = __compiletime_object_size(to);
  373. if (likely(sz == -1 || sz >= n))
  374. n = _copy_from_user(to, from, n);
  375. else
  376. copy_from_user_overflow();
  377. return n;
  378. }
  379. #else
  380. #define copy_from_user _copy_from_user
  381. #endif
  382. #ifdef __tilegx__
  383. /**
  384. * __copy_in_user() - copy data within user space, with less checking.
  385. * @to: Destination address, in user space.
  386. * @from: Source address, in user space.
  387. * @n: Number of bytes to copy.
  388. *
  389. * Context: User context only. This function may sleep.
  390. *
  391. * Copy data from user space to user space. Caller must check
  392. * the specified blocks with access_ok() before calling this function.
  393. *
  394. * Returns number of bytes that could not be copied.
  395. * On success, this will be zero.
  396. */
  397. extern unsigned long __copy_in_user_inatomic(
  398. void __user *to, const void __user *from, unsigned long n);
  399. static inline unsigned long __must_check
  400. __copy_in_user(void __user *to, const void __user *from, unsigned long n)
  401. {
  402. might_sleep();
  403. return __copy_in_user_inatomic(to, from, n);
  404. }
  405. static inline unsigned long __must_check
  406. copy_in_user(void __user *to, const void __user *from, unsigned long n)
  407. {
  408. if (access_ok(VERIFY_WRITE, to, n) && access_ok(VERIFY_READ, from, n))
  409. n = __copy_in_user(to, from, n);
  410. return n;
  411. }
  412. #endif
  413. /**
  414. * strlen_user: - Get the size of a string in user space.
  415. * @str: The string to measure.
  416. *
  417. * Context: User context only. This function may sleep.
  418. *
  419. * Get the size of a NUL-terminated string in user space.
  420. *
  421. * Returns the size of the string INCLUDING the terminating NUL.
  422. * On exception, returns 0.
  423. *
  424. * If there is a limit on the length of a valid string, you may wish to
  425. * consider using strnlen_user() instead.
  426. */
  427. extern long strnlen_user_asm(const char __user *str, long n);
  428. static inline long __must_check strnlen_user(const char __user *str, long n)
  429. {
  430. might_fault();
  431. return strnlen_user_asm(str, n);
  432. }
  433. #define strlen_user(str) strnlen_user(str, LONG_MAX)
  434. /**
  435. * strncpy_from_user: - Copy a NUL terminated string from userspace, with less checking.
  436. * @dst: Destination address, in kernel space. This buffer must be at
  437. * least @count bytes long.
  438. * @src: Source address, in user space.
  439. * @count: Maximum number of bytes to copy, including the trailing NUL.
  440. *
  441. * Copies a NUL-terminated string from userspace to kernel space.
  442. * Caller must check the specified block with access_ok() before calling
  443. * this function.
  444. *
  445. * On success, returns the length of the string (not including the trailing
  446. * NUL).
  447. *
  448. * If access to userspace fails, returns -EFAULT (some data may have been
  449. * copied).
  450. *
  451. * If @count is smaller than the length of the string, copies @count bytes
  452. * and returns @count.
  453. */
  454. extern long strncpy_from_user_asm(char *dst, const char __user *src, long);
  455. static inline long __must_check __strncpy_from_user(
  456. char *dst, const char __user *src, long count)
  457. {
  458. might_fault();
  459. return strncpy_from_user_asm(dst, src, count);
  460. }
  461. static inline long __must_check strncpy_from_user(
  462. char *dst, const char __user *src, long count)
  463. {
  464. if (access_ok(VERIFY_READ, src, 1))
  465. return __strncpy_from_user(dst, src, count);
  466. return -EFAULT;
  467. }
  468. /**
  469. * clear_user: - Zero a block of memory in user space.
  470. * @mem: Destination address, in user space.
  471. * @len: Number of bytes to zero.
  472. *
  473. * Zero a block of memory in user space.
  474. *
  475. * Returns number of bytes that could not be cleared.
  476. * On success, this will be zero.
  477. */
  478. extern unsigned long clear_user_asm(void __user *mem, unsigned long len);
  479. static inline unsigned long __must_check __clear_user(
  480. void __user *mem, unsigned long len)
  481. {
  482. might_fault();
  483. return clear_user_asm(mem, len);
  484. }
  485. static inline unsigned long __must_check clear_user(
  486. void __user *mem, unsigned long len)
  487. {
  488. if (access_ok(VERIFY_WRITE, mem, len))
  489. return __clear_user(mem, len);
  490. return len;
  491. }
  492. /**
  493. * flush_user: - Flush a block of memory in user space from cache.
  494. * @mem: Destination address, in user space.
  495. * @len: Number of bytes to flush.
  496. *
  497. * Returns number of bytes that could not be flushed.
  498. * On success, this will be zero.
  499. */
  500. extern unsigned long flush_user_asm(void __user *mem, unsigned long len);
  501. static inline unsigned long __must_check __flush_user(
  502. void __user *mem, unsigned long len)
  503. {
  504. int retval;
  505. might_fault();
  506. retval = flush_user_asm(mem, len);
  507. mb_incoherent();
  508. return retval;
  509. }
  510. static inline unsigned long __must_check flush_user(
  511. void __user *mem, unsigned long len)
  512. {
  513. if (access_ok(VERIFY_WRITE, mem, len))
  514. return __flush_user(mem, len);
  515. return len;
  516. }
  517. /**
  518. * inv_user: - Invalidate a block of memory in user space from cache.
  519. * @mem: Destination address, in user space.
  520. * @len: Number of bytes to invalidate.
  521. *
  522. * Returns number of bytes that could not be invalidated.
  523. * On success, this will be zero.
  524. *
  525. * Note that on Tile64, the "inv" operation is in fact a
  526. * "flush and invalidate", so cache write-backs will occur prior
  527. * to the cache being marked invalid.
  528. */
  529. extern unsigned long inv_user_asm(void __user *mem, unsigned long len);
  530. static inline unsigned long __must_check __inv_user(
  531. void __user *mem, unsigned long len)
  532. {
  533. int retval;
  534. might_fault();
  535. retval = inv_user_asm(mem, len);
  536. mb_incoherent();
  537. return retval;
  538. }
  539. static inline unsigned long __must_check inv_user(
  540. void __user *mem, unsigned long len)
  541. {
  542. if (access_ok(VERIFY_WRITE, mem, len))
  543. return __inv_user(mem, len);
  544. return len;
  545. }
  546. /**
  547. * finv_user: - Flush-inval a block of memory in user space from cache.
  548. * @mem: Destination address, in user space.
  549. * @len: Number of bytes to invalidate.
  550. *
  551. * Returns number of bytes that could not be flush-invalidated.
  552. * On success, this will be zero.
  553. */
  554. extern unsigned long finv_user_asm(void __user *mem, unsigned long len);
  555. static inline unsigned long __must_check __finv_user(
  556. void __user *mem, unsigned long len)
  557. {
  558. int retval;
  559. might_fault();
  560. retval = finv_user_asm(mem, len);
  561. mb_incoherent();
  562. return retval;
  563. }
  564. static inline unsigned long __must_check finv_user(
  565. void __user *mem, unsigned long len)
  566. {
  567. if (access_ok(VERIFY_WRITE, mem, len))
  568. return __finv_user(mem, len);
  569. return len;
  570. }
  571. #endif /* _ASM_TILE_UACCESS_H */