binder_alloc.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* binder_alloc.c
  3. *
  4. * Android IPC Subsystem
  5. *
  6. * Copyright (C) 2007-2017 Google, Inc.
  7. */
  8. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  9. #include <linux/list.h>
  10. #include <linux/sched/mm.h>
  11. #include <linux/module.h>
  12. #include <linux/rtmutex.h>
  13. #include <linux/rbtree.h>
  14. #include <linux/seq_file.h>
  15. #include <linux/vmalloc.h>
  16. #include <linux/slab.h>
  17. #include <linux/sched.h>
  18. #include <linux/list_lru.h>
  19. #include <linux/ratelimit.h>
  20. #include <asm/cacheflush.h>
  21. #include <linux/uaccess.h>
  22. #include <linux/highmem.h>
  23. #include <linux/sizes.h>
  24. #include "binder_alloc.h"
  25. #include "binder_trace.h"
  26. struct list_lru binder_alloc_lru;
  27. static DEFINE_MUTEX(binder_alloc_mmap_lock);
  28. enum {
  29. BINDER_DEBUG_USER_ERROR = 1U << 0,
  30. BINDER_DEBUG_OPEN_CLOSE = 1U << 1,
  31. BINDER_DEBUG_BUFFER_ALLOC = 1U << 2,
  32. BINDER_DEBUG_BUFFER_ALLOC_ASYNC = 1U << 3,
  33. };
  34. static uint32_t binder_alloc_debug_mask = BINDER_DEBUG_USER_ERROR;
  35. module_param_named(debug_mask, binder_alloc_debug_mask,
  36. uint, 0644);
  37. #define binder_alloc_debug(mask, x...) \
  38. do { \
  39. if (binder_alloc_debug_mask & mask) \
  40. pr_info_ratelimited(x); \
  41. } while (0)
  42. static struct binder_buffer *binder_buffer_next(struct binder_buffer *buffer)
  43. {
  44. return list_entry(buffer->entry.next, struct binder_buffer, entry);
  45. }
  46. static struct binder_buffer *binder_buffer_prev(struct binder_buffer *buffer)
  47. {
  48. return list_entry(buffer->entry.prev, struct binder_buffer, entry);
  49. }
  50. static size_t binder_alloc_buffer_size(struct binder_alloc *alloc,
  51. struct binder_buffer *buffer)
  52. {
  53. if (list_is_last(&buffer->entry, &alloc->buffers))
  54. return alloc->buffer + alloc->buffer_size - buffer->user_data;
  55. return binder_buffer_next(buffer)->user_data - buffer->user_data;
  56. }
  57. static void binder_insert_free_buffer(struct binder_alloc *alloc,
  58. struct binder_buffer *new_buffer)
  59. {
  60. struct rb_node **p = &alloc->free_buffers.rb_node;
  61. struct rb_node *parent = NULL;
  62. struct binder_buffer *buffer;
  63. size_t buffer_size;
  64. size_t new_buffer_size;
  65. BUG_ON(!new_buffer->free);
  66. new_buffer_size = binder_alloc_buffer_size(alloc, new_buffer);
  67. binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
  68. "%d: add free buffer, size %zd, at %pK\n",
  69. alloc->pid, new_buffer_size, new_buffer);
  70. while (*p) {
  71. parent = *p;
  72. buffer = rb_entry(parent, struct binder_buffer, rb_node);
  73. BUG_ON(!buffer->free);
  74. buffer_size = binder_alloc_buffer_size(alloc, buffer);
  75. if (new_buffer_size < buffer_size)
  76. p = &parent->rb_left;
  77. else
  78. p = &parent->rb_right;
  79. }
  80. rb_link_node(&new_buffer->rb_node, parent, p);
  81. rb_insert_color(&new_buffer->rb_node, &alloc->free_buffers);
  82. }
  83. static void binder_insert_allocated_buffer_locked(
  84. struct binder_alloc *alloc, struct binder_buffer *new_buffer)
  85. {
  86. struct rb_node **p = &alloc->allocated_buffers.rb_node;
  87. struct rb_node *parent = NULL;
  88. struct binder_buffer *buffer;
  89. BUG_ON(new_buffer->free);
  90. while (*p) {
  91. parent = *p;
  92. buffer = rb_entry(parent, struct binder_buffer, rb_node);
  93. BUG_ON(buffer->free);
  94. if (new_buffer->user_data < buffer->user_data)
  95. p = &parent->rb_left;
  96. else if (new_buffer->user_data > buffer->user_data)
  97. p = &parent->rb_right;
  98. else
  99. BUG();
  100. }
  101. rb_link_node(&new_buffer->rb_node, parent, p);
  102. rb_insert_color(&new_buffer->rb_node, &alloc->allocated_buffers);
  103. }
  104. static struct binder_buffer *binder_alloc_prepare_to_free_locked(
  105. struct binder_alloc *alloc,
  106. uintptr_t user_ptr)
  107. {
  108. struct rb_node *n = alloc->allocated_buffers.rb_node;
  109. struct binder_buffer *buffer;
  110. void __user *uptr;
  111. uptr = (void __user *)user_ptr;
  112. while (n) {
  113. buffer = rb_entry(n, struct binder_buffer, rb_node);
  114. BUG_ON(buffer->free);
  115. if (uptr < buffer->user_data)
  116. n = n->rb_left;
  117. else if (uptr > buffer->user_data)
  118. n = n->rb_right;
  119. else {
  120. /*
  121. * Guard against user threads attempting to
  122. * free the buffer when in use by kernel or
  123. * after it's already been freed.
  124. */
  125. if (!buffer->allow_user_free)
  126. return ERR_PTR(-EPERM);
  127. buffer->allow_user_free = 0;
  128. return buffer;
  129. }
  130. }
  131. return NULL;
  132. }
  133. /**
  134. * binder_alloc_prepare_to_free() - get buffer given user ptr
  135. * @alloc: binder_alloc for this proc
  136. * @user_ptr: User pointer to buffer data
  137. *
  138. * Validate userspace pointer to buffer data and return buffer corresponding to
  139. * that user pointer. Search the rb tree for buffer that matches user data
  140. * pointer.
  141. *
  142. * Return: Pointer to buffer or NULL
  143. */
  144. struct binder_buffer *binder_alloc_prepare_to_free(struct binder_alloc *alloc,
  145. uintptr_t user_ptr)
  146. {
  147. struct binder_buffer *buffer;
  148. mutex_lock(&alloc->mutex);
  149. buffer = binder_alloc_prepare_to_free_locked(alloc, user_ptr);
  150. mutex_unlock(&alloc->mutex);
  151. return buffer;
  152. }
  153. static int binder_update_page_range(struct binder_alloc *alloc, int allocate,
  154. void __user *start, void __user *end)
  155. {
  156. void __user *page_addr;
  157. unsigned long user_page_addr;
  158. struct binder_lru_page *page;
  159. struct vm_area_struct *vma = NULL;
  160. struct mm_struct *mm = NULL;
  161. bool need_mm = false;
  162. binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
  163. "%d: %s pages %pK-%pK\n", alloc->pid,
  164. allocate ? "allocate" : "free", start, end);
  165. if (end <= start)
  166. return 0;
  167. trace_binder_update_page_range(alloc, allocate, start, end);
  168. if (allocate == 0)
  169. goto free_range;
  170. for (page_addr = start; page_addr < end; page_addr += PAGE_SIZE) {
  171. page = &alloc->pages[(page_addr - alloc->buffer) / PAGE_SIZE];
  172. if (!page->page_ptr) {
  173. need_mm = true;
  174. break;
  175. }
  176. }
  177. if (need_mm && mmget_not_zero(alloc->vma_vm_mm))
  178. mm = alloc->vma_vm_mm;
  179. if (mm) {
  180. down_read(&mm->mmap_sem);
  181. vma = alloc->vma;
  182. }
  183. if (!vma && need_mm) {
  184. binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
  185. "%d: binder_alloc_buf failed to map pages in userspace, no vma\n",
  186. alloc->pid);
  187. goto err_no_vma;
  188. }
  189. for (page_addr = start; page_addr < end; page_addr += PAGE_SIZE) {
  190. int ret;
  191. bool on_lru;
  192. size_t index;
  193. index = (page_addr - alloc->buffer) / PAGE_SIZE;
  194. page = &alloc->pages[index];
  195. if (page->page_ptr) {
  196. trace_binder_alloc_lru_start(alloc, index);
  197. on_lru = list_lru_del(&binder_alloc_lru, &page->lru);
  198. WARN_ON(!on_lru);
  199. trace_binder_alloc_lru_end(alloc, index);
  200. continue;
  201. }
  202. if (WARN_ON(!vma))
  203. goto err_page_ptr_cleared;
  204. trace_binder_alloc_page_start(alloc, index);
  205. page->page_ptr = alloc_page(GFP_KERNEL |
  206. __GFP_HIGHMEM |
  207. __GFP_ZERO);
  208. if (!page->page_ptr) {
  209. pr_err("%d: binder_alloc_buf failed for page at %pK\n",
  210. alloc->pid, page_addr);
  211. goto err_alloc_page_failed;
  212. }
  213. page->alloc = alloc;
  214. INIT_LIST_HEAD(&page->lru);
  215. user_page_addr = (uintptr_t)page_addr;
  216. ret = vm_insert_page(vma, user_page_addr, page[0].page_ptr);
  217. if (ret) {
  218. pr_err("%d: binder_alloc_buf failed to map page at %lx in userspace\n",
  219. alloc->pid, user_page_addr);
  220. goto err_vm_insert_page_failed;
  221. }
  222. if (index + 1 > alloc->pages_high)
  223. alloc->pages_high = index + 1;
  224. trace_binder_alloc_page_end(alloc, index);
  225. /* vm_insert_page does not seem to increment the refcount */
  226. }
  227. if (mm) {
  228. up_read(&mm->mmap_sem);
  229. mmput(mm);
  230. }
  231. return 0;
  232. free_range:
  233. for (page_addr = end - PAGE_SIZE; 1; page_addr -= PAGE_SIZE) {
  234. bool ret;
  235. size_t index;
  236. index = (page_addr - alloc->buffer) / PAGE_SIZE;
  237. page = &alloc->pages[index];
  238. trace_binder_free_lru_start(alloc, index);
  239. ret = list_lru_add(&binder_alloc_lru, &page->lru);
  240. WARN_ON(!ret);
  241. trace_binder_free_lru_end(alloc, index);
  242. if (page_addr == start)
  243. break;
  244. continue;
  245. err_vm_insert_page_failed:
  246. __free_page(page->page_ptr);
  247. page->page_ptr = NULL;
  248. err_alloc_page_failed:
  249. err_page_ptr_cleared:
  250. if (page_addr == start)
  251. break;
  252. }
  253. err_no_vma:
  254. if (mm) {
  255. up_read(&mm->mmap_sem);
  256. mmput(mm);
  257. }
  258. return vma ? -ENOMEM : -ESRCH;
  259. }
  260. static inline void binder_alloc_set_vma(struct binder_alloc *alloc,
  261. struct vm_area_struct *vma)
  262. {
  263. if (vma)
  264. alloc->vma_vm_mm = vma->vm_mm;
  265. /*
  266. * If we see alloc->vma is not NULL, buffer data structures set up
  267. * completely. Look at smp_rmb side binder_alloc_get_vma.
  268. * We also want to guarantee new alloc->vma_vm_mm is always visible
  269. * if alloc->vma is set.
  270. */
  271. smp_wmb();
  272. alloc->vma = vma;
  273. }
  274. static inline struct vm_area_struct *binder_alloc_get_vma(
  275. struct binder_alloc *alloc)
  276. {
  277. struct vm_area_struct *vma = NULL;
  278. if (alloc->vma) {
  279. /* Look at description in binder_alloc_set_vma */
  280. smp_rmb();
  281. vma = alloc->vma;
  282. }
  283. return vma;
  284. }
  285. static struct binder_buffer *binder_alloc_new_buf_locked(
  286. struct binder_alloc *alloc,
  287. size_t data_size,
  288. size_t offsets_size,
  289. size_t extra_buffers_size,
  290. int is_async)
  291. {
  292. struct rb_node *n = alloc->free_buffers.rb_node;
  293. struct binder_buffer *buffer;
  294. size_t buffer_size;
  295. struct rb_node *best_fit = NULL;
  296. void __user *has_page_addr;
  297. void __user *end_page_addr;
  298. size_t size, data_offsets_size;
  299. int ret;
  300. if (!binder_alloc_get_vma(alloc)) {
  301. binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
  302. "%d: binder_alloc_buf, no vma\n",
  303. alloc->pid);
  304. return ERR_PTR(-ESRCH);
  305. }
  306. data_offsets_size = ALIGN(data_size, sizeof(void *)) +
  307. ALIGN(offsets_size, sizeof(void *));
  308. if (data_offsets_size < data_size || data_offsets_size < offsets_size) {
  309. binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
  310. "%d: got transaction with invalid size %zd-%zd\n",
  311. alloc->pid, data_size, offsets_size);
  312. return ERR_PTR(-EINVAL);
  313. }
  314. size = data_offsets_size + ALIGN(extra_buffers_size, sizeof(void *));
  315. if (size < data_offsets_size || size < extra_buffers_size) {
  316. binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
  317. "%d: got transaction with invalid extra_buffers_size %zd\n",
  318. alloc->pid, extra_buffers_size);
  319. return ERR_PTR(-EINVAL);
  320. }
  321. if (is_async &&
  322. alloc->free_async_space < size + sizeof(struct binder_buffer)) {
  323. binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
  324. "%d: binder_alloc_buf size %zd failed, no async space left\n",
  325. alloc->pid, size);
  326. return ERR_PTR(-ENOSPC);
  327. }
  328. /* Pad 0-size buffers so they get assigned unique addresses */
  329. size = max(size, sizeof(void *));
  330. while (n) {
  331. buffer = rb_entry(n, struct binder_buffer, rb_node);
  332. BUG_ON(!buffer->free);
  333. buffer_size = binder_alloc_buffer_size(alloc, buffer);
  334. if (size < buffer_size) {
  335. best_fit = n;
  336. n = n->rb_left;
  337. } else if (size > buffer_size)
  338. n = n->rb_right;
  339. else {
  340. best_fit = n;
  341. break;
  342. }
  343. }
  344. if (best_fit == NULL) {
  345. size_t allocated_buffers = 0;
  346. size_t largest_alloc_size = 0;
  347. size_t total_alloc_size = 0;
  348. size_t free_buffers = 0;
  349. size_t largest_free_size = 0;
  350. size_t total_free_size = 0;
  351. for (n = rb_first(&alloc->allocated_buffers); n != NULL;
  352. n = rb_next(n)) {
  353. buffer = rb_entry(n, struct binder_buffer, rb_node);
  354. buffer_size = binder_alloc_buffer_size(alloc, buffer);
  355. allocated_buffers++;
  356. total_alloc_size += buffer_size;
  357. if (buffer_size > largest_alloc_size)
  358. largest_alloc_size = buffer_size;
  359. }
  360. for (n = rb_first(&alloc->free_buffers); n != NULL;
  361. n = rb_next(n)) {
  362. buffer = rb_entry(n, struct binder_buffer, rb_node);
  363. buffer_size = binder_alloc_buffer_size(alloc, buffer);
  364. free_buffers++;
  365. total_free_size += buffer_size;
  366. if (buffer_size > largest_free_size)
  367. largest_free_size = buffer_size;
  368. }
  369. binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
  370. "%d: binder_alloc_buf size %zd failed, no address space\n",
  371. alloc->pid, size);
  372. binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
  373. "allocated: %zd (num: %zd largest: %zd), free: %zd (num: %zd largest: %zd)\n",
  374. total_alloc_size, allocated_buffers,
  375. largest_alloc_size, total_free_size,
  376. free_buffers, largest_free_size);
  377. return ERR_PTR(-ENOSPC);
  378. }
  379. if (n == NULL) {
  380. buffer = rb_entry(best_fit, struct binder_buffer, rb_node);
  381. buffer_size = binder_alloc_buffer_size(alloc, buffer);
  382. }
  383. binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
  384. "%d: binder_alloc_buf size %zd got buffer %pK size %zd\n",
  385. alloc->pid, size, buffer, buffer_size);
  386. has_page_addr = (void __user *)
  387. (((uintptr_t)buffer->user_data + buffer_size) & PAGE_MASK);
  388. WARN_ON(n && buffer_size != size);
  389. end_page_addr =
  390. (void __user *)PAGE_ALIGN((uintptr_t)buffer->user_data + size);
  391. if (end_page_addr > has_page_addr)
  392. end_page_addr = has_page_addr;
  393. ret = binder_update_page_range(alloc, 1, (void __user *)
  394. PAGE_ALIGN((uintptr_t)buffer->user_data), end_page_addr);
  395. if (ret)
  396. return ERR_PTR(ret);
  397. if (buffer_size != size) {
  398. struct binder_buffer *new_buffer;
  399. new_buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
  400. if (!new_buffer) {
  401. pr_err("%s: %d failed to alloc new buffer struct\n",
  402. __func__, alloc->pid);
  403. goto err_alloc_buf_struct_failed;
  404. }
  405. new_buffer->user_data = (u8 __user *)buffer->user_data + size;
  406. list_add(&new_buffer->entry, &buffer->entry);
  407. new_buffer->free = 1;
  408. binder_insert_free_buffer(alloc, new_buffer);
  409. }
  410. rb_erase(best_fit, &alloc->free_buffers);
  411. buffer->free = 0;
  412. buffer->allow_user_free = 0;
  413. binder_insert_allocated_buffer_locked(alloc, buffer);
  414. binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
  415. "%d: binder_alloc_buf size %zd got %pK\n",
  416. alloc->pid, size, buffer);
  417. buffer->data_size = data_size;
  418. buffer->offsets_size = offsets_size;
  419. buffer->async_transaction = is_async;
  420. buffer->extra_buffers_size = extra_buffers_size;
  421. if (is_async) {
  422. alloc->free_async_space -= size + sizeof(struct binder_buffer);
  423. binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC_ASYNC,
  424. "%d: binder_alloc_buf size %zd async free %zd\n",
  425. alloc->pid, size, alloc->free_async_space);
  426. }
  427. return buffer;
  428. err_alloc_buf_struct_failed:
  429. binder_update_page_range(alloc, 0, (void __user *)
  430. PAGE_ALIGN((uintptr_t)buffer->user_data),
  431. end_page_addr);
  432. return ERR_PTR(-ENOMEM);
  433. }
  434. /**
  435. * binder_alloc_new_buf() - Allocate a new binder buffer
  436. * @alloc: binder_alloc for this proc
  437. * @data_size: size of user data buffer
  438. * @offsets_size: user specified buffer offset
  439. * @extra_buffers_size: size of extra space for meta-data (eg, security context)
  440. * @is_async: buffer for async transaction
  441. *
  442. * Allocate a new buffer given the requested sizes. Returns
  443. * the kernel version of the buffer pointer. The size allocated
  444. * is the sum of the three given sizes (each rounded up to
  445. * pointer-sized boundary)
  446. *
  447. * Return: The allocated buffer or %NULL if error
  448. */
  449. struct binder_buffer *binder_alloc_new_buf(struct binder_alloc *alloc,
  450. size_t data_size,
  451. size_t offsets_size,
  452. size_t extra_buffers_size,
  453. int is_async)
  454. {
  455. struct binder_buffer *buffer;
  456. mutex_lock(&alloc->mutex);
  457. buffer = binder_alloc_new_buf_locked(alloc, data_size, offsets_size,
  458. extra_buffers_size, is_async);
  459. mutex_unlock(&alloc->mutex);
  460. return buffer;
  461. }
  462. static void __user *buffer_start_page(struct binder_buffer *buffer)
  463. {
  464. return (void __user *)((uintptr_t)buffer->user_data & PAGE_MASK);
  465. }
  466. static void __user *prev_buffer_end_page(struct binder_buffer *buffer)
  467. {
  468. return (void __user *)
  469. (((uintptr_t)(buffer->user_data) - 1) & PAGE_MASK);
  470. }
  471. static void binder_delete_free_buffer(struct binder_alloc *alloc,
  472. struct binder_buffer *buffer)
  473. {
  474. struct binder_buffer *prev, *next = NULL;
  475. bool to_free = true;
  476. BUG_ON(alloc->buffers.next == &buffer->entry);
  477. prev = binder_buffer_prev(buffer);
  478. BUG_ON(!prev->free);
  479. if (prev_buffer_end_page(prev) == buffer_start_page(buffer)) {
  480. to_free = false;
  481. binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
  482. "%d: merge free, buffer %pK share page with %pK\n",
  483. alloc->pid, buffer->user_data,
  484. prev->user_data);
  485. }
  486. if (!list_is_last(&buffer->entry, &alloc->buffers)) {
  487. next = binder_buffer_next(buffer);
  488. if (buffer_start_page(next) == buffer_start_page(buffer)) {
  489. to_free = false;
  490. binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
  491. "%d: merge free, buffer %pK share page with %pK\n",
  492. alloc->pid,
  493. buffer->user_data,
  494. next->user_data);
  495. }
  496. }
  497. if (PAGE_ALIGNED(buffer->user_data)) {
  498. binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
  499. "%d: merge free, buffer start %pK is page aligned\n",
  500. alloc->pid, buffer->user_data);
  501. to_free = false;
  502. }
  503. if (to_free) {
  504. binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
  505. "%d: merge free, buffer %pK do not share page with %pK or %pK\n",
  506. alloc->pid, buffer->user_data,
  507. prev->user_data,
  508. next ? next->user_data : NULL);
  509. binder_update_page_range(alloc, 0, buffer_start_page(buffer),
  510. buffer_start_page(buffer) + PAGE_SIZE);
  511. }
  512. list_del(&buffer->entry);
  513. kfree(buffer);
  514. }
  515. static void binder_free_buf_locked(struct binder_alloc *alloc,
  516. struct binder_buffer *buffer)
  517. {
  518. size_t size, buffer_size;
  519. buffer_size = binder_alloc_buffer_size(alloc, buffer);
  520. size = ALIGN(buffer->data_size, sizeof(void *)) +
  521. ALIGN(buffer->offsets_size, sizeof(void *)) +
  522. ALIGN(buffer->extra_buffers_size, sizeof(void *));
  523. binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
  524. "%d: binder_free_buf %pK size %zd buffer_size %zd\n",
  525. alloc->pid, buffer, size, buffer_size);
  526. BUG_ON(buffer->free);
  527. BUG_ON(size > buffer_size);
  528. BUG_ON(buffer->transaction != NULL);
  529. BUG_ON(buffer->user_data < alloc->buffer);
  530. BUG_ON(buffer->user_data > alloc->buffer + alloc->buffer_size);
  531. if (buffer->async_transaction) {
  532. alloc->free_async_space += size + sizeof(struct binder_buffer);
  533. binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC_ASYNC,
  534. "%d: binder_free_buf size %zd async free %zd\n",
  535. alloc->pid, size, alloc->free_async_space);
  536. }
  537. binder_update_page_range(alloc, 0,
  538. (void __user *)PAGE_ALIGN((uintptr_t)buffer->user_data),
  539. (void __user *)(((uintptr_t)
  540. buffer->user_data + buffer_size) & PAGE_MASK));
  541. rb_erase(&buffer->rb_node, &alloc->allocated_buffers);
  542. buffer->free = 1;
  543. if (!list_is_last(&buffer->entry, &alloc->buffers)) {
  544. struct binder_buffer *next = binder_buffer_next(buffer);
  545. if (next->free) {
  546. rb_erase(&next->rb_node, &alloc->free_buffers);
  547. binder_delete_free_buffer(alloc, next);
  548. }
  549. }
  550. if (alloc->buffers.next != &buffer->entry) {
  551. struct binder_buffer *prev = binder_buffer_prev(buffer);
  552. if (prev->free) {
  553. binder_delete_free_buffer(alloc, buffer);
  554. rb_erase(&prev->rb_node, &alloc->free_buffers);
  555. buffer = prev;
  556. }
  557. }
  558. binder_insert_free_buffer(alloc, buffer);
  559. }
  560. static void binder_alloc_clear_buf(struct binder_alloc *alloc,
  561. struct binder_buffer *buffer);
  562. /**
  563. * binder_alloc_free_buf() - free a binder buffer
  564. * @alloc: binder_alloc for this proc
  565. * @buffer: kernel pointer to buffer
  566. *
  567. * Free the buffer allocated via binder_alloc_new_buffer()
  568. */
  569. void binder_alloc_free_buf(struct binder_alloc *alloc,
  570. struct binder_buffer *buffer)
  571. {
  572. /*
  573. * We could eliminate the call to binder_alloc_clear_buf()
  574. * from binder_alloc_deferred_release() by moving this to
  575. * binder_alloc_free_buf_locked(). However, that could
  576. * increase contention for the alloc mutex if clear_on_free
  577. * is used frequently for large buffers. The mutex is not
  578. * needed for correctness here.
  579. */
  580. if (buffer->clear_on_free) {
  581. binder_alloc_clear_buf(alloc, buffer);
  582. buffer->clear_on_free = false;
  583. }
  584. mutex_lock(&alloc->mutex);
  585. binder_free_buf_locked(alloc, buffer);
  586. mutex_unlock(&alloc->mutex);
  587. }
  588. /**
  589. * binder_alloc_mmap_handler() - map virtual address space for proc
  590. * @alloc: alloc structure for this proc
  591. * @vma: vma passed to mmap()
  592. *
  593. * Called by binder_mmap() to initialize the space specified in
  594. * vma for allocating binder buffers
  595. *
  596. * Return:
  597. * 0 = success
  598. * -EBUSY = address space already mapped
  599. * -ENOMEM = failed to map memory to given address space
  600. */
  601. int binder_alloc_mmap_handler(struct binder_alloc *alloc,
  602. struct vm_area_struct *vma)
  603. {
  604. int ret;
  605. const char *failure_string;
  606. struct binder_buffer *buffer;
  607. mutex_lock(&binder_alloc_mmap_lock);
  608. if (alloc->buffer_size) {
  609. ret = -EBUSY;
  610. failure_string = "already mapped";
  611. goto err_already_mapped;
  612. }
  613. alloc->buffer_size = min_t(unsigned long, vma->vm_end - vma->vm_start,
  614. SZ_4M);
  615. mutex_unlock(&binder_alloc_mmap_lock);
  616. alloc->buffer = (void __user *)vma->vm_start;
  617. alloc->pages = kcalloc(alloc->buffer_size / PAGE_SIZE,
  618. sizeof(alloc->pages[0]),
  619. GFP_KERNEL);
  620. if (alloc->pages == NULL) {
  621. ret = -ENOMEM;
  622. failure_string = "alloc page array";
  623. goto err_alloc_pages_failed;
  624. }
  625. buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
  626. if (!buffer) {
  627. ret = -ENOMEM;
  628. failure_string = "alloc buffer struct";
  629. goto err_alloc_buf_struct_failed;
  630. }
  631. buffer->user_data = alloc->buffer;
  632. list_add(&buffer->entry, &alloc->buffers);
  633. buffer->free = 1;
  634. binder_insert_free_buffer(alloc, buffer);
  635. alloc->free_async_space = alloc->buffer_size / 2;
  636. binder_alloc_set_vma(alloc, vma);
  637. mmgrab(alloc->vma_vm_mm);
  638. return 0;
  639. err_alloc_buf_struct_failed:
  640. kfree(alloc->pages);
  641. alloc->pages = NULL;
  642. err_alloc_pages_failed:
  643. alloc->buffer = NULL;
  644. mutex_lock(&binder_alloc_mmap_lock);
  645. alloc->buffer_size = 0;
  646. err_already_mapped:
  647. mutex_unlock(&binder_alloc_mmap_lock);
  648. binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
  649. "%s: %d %lx-%lx %s failed %d\n", __func__,
  650. alloc->pid, vma->vm_start, vma->vm_end,
  651. failure_string, ret);
  652. return ret;
  653. }
  654. void binder_alloc_deferred_release(struct binder_alloc *alloc)
  655. {
  656. struct rb_node *n;
  657. int buffers, page_count;
  658. struct binder_buffer *buffer;
  659. buffers = 0;
  660. mutex_lock(&alloc->mutex);
  661. BUG_ON(alloc->vma);
  662. while ((n = rb_first(&alloc->allocated_buffers))) {
  663. buffer = rb_entry(n, struct binder_buffer, rb_node);
  664. /* Transaction should already have been freed */
  665. BUG_ON(buffer->transaction);
  666. if (buffer->clear_on_free) {
  667. binder_alloc_clear_buf(alloc, buffer);
  668. buffer->clear_on_free = false;
  669. }
  670. binder_free_buf_locked(alloc, buffer);
  671. buffers++;
  672. }
  673. while (!list_empty(&alloc->buffers)) {
  674. buffer = list_first_entry(&alloc->buffers,
  675. struct binder_buffer, entry);
  676. WARN_ON(!buffer->free);
  677. list_del(&buffer->entry);
  678. WARN_ON_ONCE(!list_empty(&alloc->buffers));
  679. kfree(buffer);
  680. }
  681. page_count = 0;
  682. if (alloc->pages) {
  683. int i;
  684. for (i = 0; i < alloc->buffer_size / PAGE_SIZE; i++) {
  685. void __user *page_addr;
  686. bool on_lru;
  687. if (!alloc->pages[i].page_ptr)
  688. continue;
  689. on_lru = list_lru_del(&binder_alloc_lru,
  690. &alloc->pages[i].lru);
  691. page_addr = alloc->buffer + i * PAGE_SIZE;
  692. binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC,
  693. "%s: %d: page %d at %pK %s\n",
  694. __func__, alloc->pid, i, page_addr,
  695. on_lru ? "on lru" : "active");
  696. __free_page(alloc->pages[i].page_ptr);
  697. page_count++;
  698. }
  699. kfree(alloc->pages);
  700. }
  701. mutex_unlock(&alloc->mutex);
  702. if (alloc->vma_vm_mm)
  703. mmdrop(alloc->vma_vm_mm);
  704. binder_alloc_debug(BINDER_DEBUG_OPEN_CLOSE,
  705. "%s: %d buffers %d, pages %d\n",
  706. __func__, alloc->pid, buffers, page_count);
  707. }
  708. static void print_binder_buffer(struct seq_file *m, const char *prefix,
  709. struct binder_buffer *buffer)
  710. {
  711. seq_printf(m, "%s %d: %pK size %zd:%zd:%zd %s\n",
  712. prefix, buffer->debug_id, buffer->user_data,
  713. buffer->data_size, buffer->offsets_size,
  714. buffer->extra_buffers_size,
  715. buffer->transaction ? "active" : "delivered");
  716. }
  717. /**
  718. * binder_alloc_print_allocated() - print buffer info
  719. * @m: seq_file for output via seq_printf()
  720. * @alloc: binder_alloc for this proc
  721. *
  722. * Prints information about every buffer associated with
  723. * the binder_alloc state to the given seq_file
  724. */
  725. void binder_alloc_print_allocated(struct seq_file *m,
  726. struct binder_alloc *alloc)
  727. {
  728. struct rb_node *n;
  729. mutex_lock(&alloc->mutex);
  730. for (n = rb_first(&alloc->allocated_buffers); n != NULL; n = rb_next(n))
  731. print_binder_buffer(m, " buffer",
  732. rb_entry(n, struct binder_buffer, rb_node));
  733. mutex_unlock(&alloc->mutex);
  734. }
  735. /**
  736. * binder_alloc_print_pages() - print page usage
  737. * @m: seq_file for output via seq_printf()
  738. * @alloc: binder_alloc for this proc
  739. */
  740. void binder_alloc_print_pages(struct seq_file *m,
  741. struct binder_alloc *alloc)
  742. {
  743. struct binder_lru_page *page;
  744. int i;
  745. int active = 0;
  746. int lru = 0;
  747. int free = 0;
  748. mutex_lock(&alloc->mutex);
  749. /*
  750. * Make sure the binder_alloc is fully initialized, otherwise we might
  751. * read inconsistent state.
  752. */
  753. if (binder_alloc_get_vma(alloc) != NULL) {
  754. for (i = 0; i < alloc->buffer_size / PAGE_SIZE; i++) {
  755. page = &alloc->pages[i];
  756. if (!page->page_ptr)
  757. free++;
  758. else if (list_empty(&page->lru))
  759. active++;
  760. else
  761. lru++;
  762. }
  763. }
  764. mutex_unlock(&alloc->mutex);
  765. seq_printf(m, " pages: %d:%d:%d\n", active, lru, free);
  766. seq_printf(m, " pages high watermark: %zu\n", alloc->pages_high);
  767. }
  768. /**
  769. * binder_alloc_get_allocated_count() - return count of buffers
  770. * @alloc: binder_alloc for this proc
  771. *
  772. * Return: count of allocated buffers
  773. */
  774. int binder_alloc_get_allocated_count(struct binder_alloc *alloc)
  775. {
  776. struct rb_node *n;
  777. int count = 0;
  778. mutex_lock(&alloc->mutex);
  779. for (n = rb_first(&alloc->allocated_buffers); n != NULL; n = rb_next(n))
  780. count++;
  781. mutex_unlock(&alloc->mutex);
  782. return count;
  783. }
  784. /**
  785. * binder_alloc_vma_close() - invalidate address space
  786. * @alloc: binder_alloc for this proc
  787. *
  788. * Called from binder_vma_close() when releasing address space.
  789. * Clears alloc->vma to prevent new incoming transactions from
  790. * allocating more buffers.
  791. */
  792. void binder_alloc_vma_close(struct binder_alloc *alloc)
  793. {
  794. binder_alloc_set_vma(alloc, NULL);
  795. }
  796. /**
  797. * binder_alloc_free_page() - shrinker callback to free pages
  798. * @item: item to free
  799. * @lock: lock protecting the item
  800. * @cb_arg: callback argument
  801. *
  802. * Called from list_lru_walk() in binder_shrink_scan() to free
  803. * up pages when the system is under memory pressure.
  804. */
  805. enum lru_status binder_alloc_free_page(struct list_head *item,
  806. struct list_lru_one *lru,
  807. spinlock_t *lock,
  808. void *cb_arg)
  809. __must_hold(lock)
  810. {
  811. struct mm_struct *mm = NULL;
  812. struct binder_lru_page *page = container_of(item,
  813. struct binder_lru_page,
  814. lru);
  815. struct binder_alloc *alloc;
  816. uintptr_t page_addr;
  817. size_t index;
  818. struct vm_area_struct *vma;
  819. alloc = page->alloc;
  820. if (!mutex_trylock(&alloc->mutex))
  821. goto err_get_alloc_mutex_failed;
  822. if (!page->page_ptr)
  823. goto err_page_already_freed;
  824. index = page - alloc->pages;
  825. page_addr = (uintptr_t)alloc->buffer + index * PAGE_SIZE;
  826. mm = alloc->vma_vm_mm;
  827. if (!mmget_not_zero(mm))
  828. goto err_mmget;
  829. if (!down_read_trylock(&mm->mmap_sem))
  830. goto err_down_read_mmap_sem_failed;
  831. vma = binder_alloc_get_vma(alloc);
  832. list_lru_isolate(lru, item);
  833. spin_unlock(lock);
  834. if (vma) {
  835. trace_binder_unmap_user_start(alloc, index);
  836. zap_page_range(vma, page_addr, PAGE_SIZE);
  837. trace_binder_unmap_user_end(alloc, index);
  838. }
  839. up_read(&mm->mmap_sem);
  840. mmput_async(mm);
  841. trace_binder_unmap_kernel_start(alloc, index);
  842. __free_page(page->page_ptr);
  843. page->page_ptr = NULL;
  844. trace_binder_unmap_kernel_end(alloc, index);
  845. spin_lock(lock);
  846. mutex_unlock(&alloc->mutex);
  847. return LRU_REMOVED_RETRY;
  848. err_down_read_mmap_sem_failed:
  849. mmput_async(mm);
  850. err_mmget:
  851. err_page_already_freed:
  852. mutex_unlock(&alloc->mutex);
  853. err_get_alloc_mutex_failed:
  854. return LRU_SKIP;
  855. }
  856. static unsigned long
  857. binder_shrink_count(struct shrinker *shrink, struct shrink_control *sc)
  858. {
  859. unsigned long ret = list_lru_count(&binder_alloc_lru);
  860. return ret;
  861. }
  862. static unsigned long
  863. binder_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
  864. {
  865. unsigned long ret;
  866. ret = list_lru_walk(&binder_alloc_lru, binder_alloc_free_page,
  867. NULL, sc->nr_to_scan);
  868. return ret;
  869. }
  870. static struct shrinker binder_shrinker = {
  871. .count_objects = binder_shrink_count,
  872. .scan_objects = binder_shrink_scan,
  873. .seeks = DEFAULT_SEEKS,
  874. };
  875. /**
  876. * binder_alloc_init() - called by binder_open() for per-proc initialization
  877. * @alloc: binder_alloc for this proc
  878. *
  879. * Called from binder_open() to initialize binder_alloc fields for
  880. * new binder proc
  881. */
  882. void binder_alloc_init(struct binder_alloc *alloc)
  883. {
  884. alloc->pid = current->group_leader->pid;
  885. mutex_init(&alloc->mutex);
  886. INIT_LIST_HEAD(&alloc->buffers);
  887. }
  888. int binder_alloc_shrinker_init(void)
  889. {
  890. int ret = list_lru_init(&binder_alloc_lru);
  891. if (ret == 0) {
  892. ret = register_shrinker(&binder_shrinker);
  893. if (ret)
  894. list_lru_destroy(&binder_alloc_lru);
  895. }
  896. return ret;
  897. }
  898. /**
  899. * check_buffer() - verify that buffer/offset is safe to access
  900. * @alloc: binder_alloc for this proc
  901. * @buffer: binder buffer to be accessed
  902. * @offset: offset into @buffer data
  903. * @bytes: bytes to access from offset
  904. *
  905. * Check that the @offset/@bytes are within the size of the given
  906. * @buffer and that the buffer is currently active and not freeable.
  907. * Offsets must also be multiples of sizeof(u32). The kernel is
  908. * allowed to touch the buffer in two cases:
  909. *
  910. * 1) when the buffer is being created:
  911. * (buffer->free == 0 && buffer->allow_user_free == 0)
  912. * 2) when the buffer is being torn down:
  913. * (buffer->free == 0 && buffer->transaction == NULL).
  914. *
  915. * Return: true if the buffer is safe to access
  916. */
  917. static inline bool check_buffer(struct binder_alloc *alloc,
  918. struct binder_buffer *buffer,
  919. binder_size_t offset, size_t bytes)
  920. {
  921. size_t buffer_size = binder_alloc_buffer_size(alloc, buffer);
  922. return buffer_size >= bytes &&
  923. offset <= buffer_size - bytes &&
  924. IS_ALIGNED(offset, sizeof(u32)) &&
  925. !buffer->free &&
  926. (!buffer->allow_user_free || !buffer->transaction);
  927. }
  928. /**
  929. * binder_alloc_get_page() - get kernel pointer for given buffer offset
  930. * @alloc: binder_alloc for this proc
  931. * @buffer: binder buffer to be accessed
  932. * @buffer_offset: offset into @buffer data
  933. * @pgoffp: address to copy final page offset to
  934. *
  935. * Lookup the struct page corresponding to the address
  936. * at @buffer_offset into @buffer->user_data. If @pgoffp is not
  937. * NULL, the byte-offset into the page is written there.
  938. *
  939. * The caller is responsible to ensure that the offset points
  940. * to a valid address within the @buffer and that @buffer is
  941. * not freeable by the user. Since it can't be freed, we are
  942. * guaranteed that the corresponding elements of @alloc->pages[]
  943. * cannot change.
  944. *
  945. * Return: struct page
  946. */
  947. static struct page *binder_alloc_get_page(struct binder_alloc *alloc,
  948. struct binder_buffer *buffer,
  949. binder_size_t buffer_offset,
  950. pgoff_t *pgoffp)
  951. {
  952. binder_size_t buffer_space_offset = buffer_offset +
  953. (buffer->user_data - alloc->buffer);
  954. pgoff_t pgoff = buffer_space_offset & ~PAGE_MASK;
  955. size_t index = buffer_space_offset >> PAGE_SHIFT;
  956. struct binder_lru_page *lru_page;
  957. lru_page = &alloc->pages[index];
  958. *pgoffp = pgoff;
  959. return lru_page->page_ptr;
  960. }
  961. /**
  962. * binder_alloc_clear_buf() - zero out buffer
  963. * @alloc: binder_alloc for this proc
  964. * @buffer: binder buffer to be cleared
  965. *
  966. * memset the given buffer to 0
  967. */
  968. static void binder_alloc_clear_buf(struct binder_alloc *alloc,
  969. struct binder_buffer *buffer)
  970. {
  971. size_t bytes = binder_alloc_buffer_size(alloc, buffer);
  972. binder_size_t buffer_offset = 0;
  973. while (bytes) {
  974. unsigned long size;
  975. struct page *page;
  976. pgoff_t pgoff;
  977. void *kptr;
  978. page = binder_alloc_get_page(alloc, buffer,
  979. buffer_offset, &pgoff);
  980. size = min_t(size_t, bytes, PAGE_SIZE - pgoff);
  981. kptr = kmap(page) + pgoff;
  982. memset(kptr, 0, size);
  983. kunmap(page);
  984. bytes -= size;
  985. buffer_offset += size;
  986. }
  987. }
  988. /**
  989. * binder_alloc_copy_user_to_buffer() - copy src user to tgt user
  990. * @alloc: binder_alloc for this proc
  991. * @buffer: binder buffer to be accessed
  992. * @buffer_offset: offset into @buffer data
  993. * @from: userspace pointer to source buffer
  994. * @bytes: bytes to copy
  995. *
  996. * Copy bytes from source userspace to target buffer.
  997. *
  998. * Return: bytes remaining to be copied
  999. */
  1000. unsigned long
  1001. binder_alloc_copy_user_to_buffer(struct binder_alloc *alloc,
  1002. struct binder_buffer *buffer,
  1003. binder_size_t buffer_offset,
  1004. const void __user *from,
  1005. size_t bytes)
  1006. {
  1007. if (!check_buffer(alloc, buffer, buffer_offset, bytes))
  1008. return bytes;
  1009. while (bytes) {
  1010. unsigned long size;
  1011. unsigned long ret;
  1012. struct page *page;
  1013. pgoff_t pgoff;
  1014. void *kptr;
  1015. page = binder_alloc_get_page(alloc, buffer,
  1016. buffer_offset, &pgoff);
  1017. size = min_t(size_t, bytes, PAGE_SIZE - pgoff);
  1018. kptr = kmap(page) + pgoff;
  1019. ret = copy_from_user(kptr, from, size);
  1020. kunmap(page);
  1021. if (ret)
  1022. return bytes - size + ret;
  1023. bytes -= size;
  1024. from += size;
  1025. buffer_offset += size;
  1026. }
  1027. return 0;
  1028. }
  1029. static int binder_alloc_do_buffer_copy(struct binder_alloc *alloc,
  1030. bool to_buffer,
  1031. struct binder_buffer *buffer,
  1032. binder_size_t buffer_offset,
  1033. void *ptr,
  1034. size_t bytes)
  1035. {
  1036. /* All copies must be 32-bit aligned and 32-bit size */
  1037. if (!check_buffer(alloc, buffer, buffer_offset, bytes))
  1038. return -EINVAL;
  1039. while (bytes) {
  1040. unsigned long size;
  1041. struct page *page;
  1042. pgoff_t pgoff;
  1043. void *tmpptr;
  1044. void *base_ptr;
  1045. page = binder_alloc_get_page(alloc, buffer,
  1046. buffer_offset, &pgoff);
  1047. size = min_t(size_t, bytes, PAGE_SIZE - pgoff);
  1048. base_ptr = kmap_atomic(page);
  1049. tmpptr = base_ptr + pgoff;
  1050. if (to_buffer)
  1051. memcpy(tmpptr, ptr, size);
  1052. else
  1053. memcpy(ptr, tmpptr, size);
  1054. /*
  1055. * kunmap_atomic() takes care of flushing the cache
  1056. * if this device has VIVT cache arch
  1057. */
  1058. kunmap_atomic(base_ptr);
  1059. bytes -= size;
  1060. pgoff = 0;
  1061. ptr = ptr + size;
  1062. buffer_offset += size;
  1063. }
  1064. return 0;
  1065. }
  1066. int binder_alloc_copy_to_buffer(struct binder_alloc *alloc,
  1067. struct binder_buffer *buffer,
  1068. binder_size_t buffer_offset,
  1069. void *src,
  1070. size_t bytes)
  1071. {
  1072. return binder_alloc_do_buffer_copy(alloc, true, buffer, buffer_offset,
  1073. src, bytes);
  1074. }
  1075. int binder_alloc_copy_from_buffer(struct binder_alloc *alloc,
  1076. void *dest,
  1077. struct binder_buffer *buffer,
  1078. binder_size_t buffer_offset,
  1079. size_t bytes)
  1080. {
  1081. return binder_alloc_do_buffer_copy(alloc, false, buffer, buffer_offset,
  1082. dest, bytes);
  1083. }