uaccess.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  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_STRICT_USER_COPY_CHECKS
  366. /*
  367. * There are still unprovable places in the generic code as of 2.6.34, so this
  368. * option is not really compatible with -Werror, which is more useful in
  369. * general.
  370. */
  371. extern void copy_from_user_overflow(void)
  372. __compiletime_warning("copy_from_user() size is not provably correct");
  373. static inline unsigned long __must_check copy_from_user(void *to,
  374. const void __user *from,
  375. unsigned long n)
  376. {
  377. int sz = __compiletime_object_size(to);
  378. if (likely(sz == -1 || sz >= n))
  379. n = _copy_from_user(to, from, n);
  380. else
  381. copy_from_user_overflow();
  382. return n;
  383. }
  384. #else
  385. #define copy_from_user _copy_from_user
  386. #endif
  387. #ifdef __tilegx__
  388. /**
  389. * __copy_in_user() - copy data within user space, with less checking.
  390. * @to: Destination address, in user space.
  391. * @from: Source address, in user space.
  392. * @n: Number of bytes to copy.
  393. *
  394. * Context: User context only. This function may sleep.
  395. *
  396. * Copy data from user space to user space. Caller must check
  397. * the specified blocks with access_ok() before calling this function.
  398. *
  399. * Returns number of bytes that could not be copied.
  400. * On success, this will be zero.
  401. */
  402. extern unsigned long __copy_in_user_inatomic(
  403. void __user *to, const void __user *from, unsigned long n);
  404. static inline unsigned long __must_check
  405. __copy_in_user(void __user *to, const void __user *from, unsigned long n)
  406. {
  407. might_fault();
  408. return __copy_in_user_inatomic(to, from, n);
  409. }
  410. static inline unsigned long __must_check
  411. copy_in_user(void __user *to, const void __user *from, unsigned long n)
  412. {
  413. if (access_ok(VERIFY_WRITE, to, n) && access_ok(VERIFY_READ, from, n))
  414. n = __copy_in_user(to, from, n);
  415. return n;
  416. }
  417. #endif
  418. /**
  419. * strlen_user: - Get the size of a string in user space.
  420. * @str: The string to measure.
  421. *
  422. * Context: User context only. This function may sleep.
  423. *
  424. * Get the size of a NUL-terminated string in user space.
  425. *
  426. * Returns the size of the string INCLUDING the terminating NUL.
  427. * On exception, returns 0.
  428. *
  429. * If there is a limit on the length of a valid string, you may wish to
  430. * consider using strnlen_user() instead.
  431. */
  432. extern long strnlen_user_asm(const char __user *str, long n);
  433. static inline long __must_check strnlen_user(const char __user *str, long n)
  434. {
  435. might_fault();
  436. return strnlen_user_asm(str, n);
  437. }
  438. #define strlen_user(str) strnlen_user(str, LONG_MAX)
  439. /**
  440. * strncpy_from_user: - Copy a NUL terminated string from userspace, with less checking.
  441. * @dst: Destination address, in kernel space. This buffer must be at
  442. * least @count bytes long.
  443. * @src: Source address, in user space.
  444. * @count: Maximum number of bytes to copy, including the trailing NUL.
  445. *
  446. * Copies a NUL-terminated string from userspace to kernel space.
  447. * Caller must check the specified block with access_ok() before calling
  448. * this function.
  449. *
  450. * On success, returns the length of the string (not including the trailing
  451. * NUL).
  452. *
  453. * If access to userspace fails, returns -EFAULT (some data may have been
  454. * copied).
  455. *
  456. * If @count is smaller than the length of the string, copies @count bytes
  457. * and returns @count.
  458. */
  459. extern long strncpy_from_user_asm(char *dst, const char __user *src, long);
  460. static inline long __must_check __strncpy_from_user(
  461. char *dst, const char __user *src, long count)
  462. {
  463. might_fault();
  464. return strncpy_from_user_asm(dst, src, count);
  465. }
  466. static inline long __must_check strncpy_from_user(
  467. char *dst, const char __user *src, long count)
  468. {
  469. if (access_ok(VERIFY_READ, src, 1))
  470. return __strncpy_from_user(dst, src, count);
  471. return -EFAULT;
  472. }
  473. /**
  474. * clear_user: - Zero a block of memory in user space.
  475. * @mem: Destination address, in user space.
  476. * @len: Number of bytes to zero.
  477. *
  478. * Zero a block of memory in user space.
  479. *
  480. * Returns number of bytes that could not be cleared.
  481. * On success, this will be zero.
  482. */
  483. extern unsigned long clear_user_asm(void __user *mem, unsigned long len);
  484. static inline unsigned long __must_check __clear_user(
  485. void __user *mem, unsigned long len)
  486. {
  487. might_fault();
  488. return clear_user_asm(mem, len);
  489. }
  490. static inline unsigned long __must_check clear_user(
  491. void __user *mem, unsigned long len)
  492. {
  493. if (access_ok(VERIFY_WRITE, mem, len))
  494. return __clear_user(mem, len);
  495. return len;
  496. }
  497. /**
  498. * flush_user: - Flush a block of memory in user space from cache.
  499. * @mem: Destination address, in user space.
  500. * @len: Number of bytes to flush.
  501. *
  502. * Returns number of bytes that could not be flushed.
  503. * On success, this will be zero.
  504. */
  505. extern unsigned long flush_user_asm(void __user *mem, unsigned long len);
  506. static inline unsigned long __must_check __flush_user(
  507. void __user *mem, unsigned long len)
  508. {
  509. int retval;
  510. might_fault();
  511. retval = flush_user_asm(mem, len);
  512. mb_incoherent();
  513. return retval;
  514. }
  515. static inline unsigned long __must_check flush_user(
  516. void __user *mem, unsigned long len)
  517. {
  518. if (access_ok(VERIFY_WRITE, mem, len))
  519. return __flush_user(mem, len);
  520. return len;
  521. }
  522. /**
  523. * inv_user: - Invalidate a block of memory in user space from cache.
  524. * @mem: Destination address, in user space.
  525. * @len: Number of bytes to invalidate.
  526. *
  527. * Returns number of bytes that could not be invalidated.
  528. * On success, this will be zero.
  529. *
  530. * Note that on Tile64, the "inv" operation is in fact a
  531. * "flush and invalidate", so cache write-backs will occur prior
  532. * to the cache being marked invalid.
  533. */
  534. extern unsigned long inv_user_asm(void __user *mem, unsigned long len);
  535. static inline unsigned long __must_check __inv_user(
  536. void __user *mem, unsigned long len)
  537. {
  538. int retval;
  539. might_fault();
  540. retval = inv_user_asm(mem, len);
  541. mb_incoherent();
  542. return retval;
  543. }
  544. static inline unsigned long __must_check inv_user(
  545. void __user *mem, unsigned long len)
  546. {
  547. if (access_ok(VERIFY_WRITE, mem, len))
  548. return __inv_user(mem, len);
  549. return len;
  550. }
  551. /**
  552. * finv_user: - Flush-inval a block of memory in user space from cache.
  553. * @mem: Destination address, in user space.
  554. * @len: Number of bytes to invalidate.
  555. *
  556. * Returns number of bytes that could not be flush-invalidated.
  557. * On success, this will be zero.
  558. */
  559. extern unsigned long finv_user_asm(void __user *mem, unsigned long len);
  560. static inline unsigned long __must_check __finv_user(
  561. void __user *mem, unsigned long len)
  562. {
  563. int retval;
  564. might_fault();
  565. retval = finv_user_asm(mem, len);
  566. mb_incoherent();
  567. return retval;
  568. }
  569. static inline unsigned long __must_check finv_user(
  570. void __user *mem, unsigned long len)
  571. {
  572. if (access_ok(VERIFY_WRITE, mem, len))
  573. return __finv_user(mem, len);
  574. return len;
  575. }
  576. #endif /* _ASM_TILE_UACCESS_H */