Lines Matching full:buffer
50 static struct binder_buffer *binder_buffer_next(struct binder_buffer *buffer) in binder_buffer_next() argument
52 return list_entry(buffer->entry.next, struct binder_buffer, entry); in binder_buffer_next()
55 static struct binder_buffer *binder_buffer_prev(struct binder_buffer *buffer) in binder_buffer_prev() argument
57 return list_entry(buffer->entry.prev, struct binder_buffer, entry); in binder_buffer_prev()
61 struct binder_buffer *buffer) in binder_alloc_buffer_size() argument
63 if (list_is_last(&buffer->entry, &alloc->buffers)) in binder_alloc_buffer_size()
64 return alloc->buffer + alloc->buffer_size - buffer->user_data; in binder_alloc_buffer_size()
65 return binder_buffer_next(buffer)->user_data - buffer->user_data; in binder_alloc_buffer_size()
73 struct binder_buffer *buffer; in binder_insert_free_buffer() local
82 "%d: add free buffer, size %zd, at %pK\n", in binder_insert_free_buffer()
87 buffer = rb_entry(parent, struct binder_buffer, rb_node); in binder_insert_free_buffer()
88 BUG_ON(!buffer->free); in binder_insert_free_buffer()
90 buffer_size = binder_alloc_buffer_size(alloc, buffer); in binder_insert_free_buffer()
106 struct binder_buffer *buffer; in binder_insert_allocated_buffer_locked() local
112 buffer = rb_entry(parent, struct binder_buffer, rb_node); in binder_insert_allocated_buffer_locked()
113 BUG_ON(buffer->free); in binder_insert_allocated_buffer_locked()
115 if (new_buffer->user_data < buffer->user_data) in binder_insert_allocated_buffer_locked()
117 else if (new_buffer->user_data > buffer->user_data) in binder_insert_allocated_buffer_locked()
131 struct binder_buffer *buffer; in binder_alloc_prepare_to_free_locked() local
137 buffer = rb_entry(n, struct binder_buffer, rb_node); in binder_alloc_prepare_to_free_locked()
138 BUG_ON(buffer->free); in binder_alloc_prepare_to_free_locked()
140 if (uptr < buffer->user_data) in binder_alloc_prepare_to_free_locked()
142 else if (uptr > buffer->user_data) in binder_alloc_prepare_to_free_locked()
147 * free the buffer when in use by kernel or in binder_alloc_prepare_to_free_locked()
150 if (!buffer->allow_user_free) in binder_alloc_prepare_to_free_locked()
152 buffer->allow_user_free = 0; in binder_alloc_prepare_to_free_locked()
153 return buffer; in binder_alloc_prepare_to_free_locked()
160 * binder_alloc_prepare_to_free() - get buffer given user ptr
162 * @user_ptr: User pointer to buffer data
164 * Validate userspace pointer to buffer data and return buffer corresponding to
165 * that user pointer. Search the rb tree for buffer that matches user data
168 * Return: Pointer to buffer or NULL
173 struct binder_buffer *buffer; in binder_alloc_prepare_to_free() local
176 buffer = binder_alloc_prepare_to_free_locked(alloc, user_ptr); in binder_alloc_prepare_to_free()
178 return buffer; in binder_alloc_prepare_to_free()
204 page = &alloc->pages[(page_addr - alloc->buffer) / PAGE_SIZE]; in binder_update_page_range()
231 index = (page_addr - alloc->buffer) / PAGE_SIZE; in binder_update_page_range()
283 index = (page_addr - alloc->buffer) / PAGE_SIZE; in binder_update_page_range()
319 * If we see alloc->vma is not NULL, buffer data structures set up in binder_alloc_set_vma()
351 struct binder_buffer *buffer; in debug_low_async_space_locked() local
357 buffer = rb_entry(n, struct binder_buffer, rb_node); in debug_low_async_space_locked()
358 if (buffer->pid != pid) in debug_low_async_space_locked()
360 if (!buffer->async_transaction) in debug_low_async_space_locked()
362 total_alloc_size += binder_alloc_buffer_size(alloc, buffer) in debug_low_async_space_locked()
369 * async space (which is 25% of total buffer size). in debug_low_async_space_locked()
387 struct binder_buffer *buffer; in binder_alloc_new_buf_locked() local
430 buffer = rb_entry(n, struct binder_buffer, rb_node); in binder_alloc_new_buf_locked()
431 BUG_ON(!buffer->free); in binder_alloc_new_buf_locked()
432 buffer_size = binder_alloc_buffer_size(alloc, buffer); in binder_alloc_new_buf_locked()
454 buffer = rb_entry(n, struct binder_buffer, rb_node); in binder_alloc_new_buf_locked()
455 buffer_size = binder_alloc_buffer_size(alloc, buffer); in binder_alloc_new_buf_locked()
463 buffer = rb_entry(n, struct binder_buffer, rb_node); in binder_alloc_new_buf_locked()
464 buffer_size = binder_alloc_buffer_size(alloc, buffer); in binder_alloc_new_buf_locked()
481 buffer = rb_entry(best_fit, struct binder_buffer, rb_node); in binder_alloc_new_buf_locked()
482 buffer_size = binder_alloc_buffer_size(alloc, buffer); in binder_alloc_new_buf_locked()
486 "%d: binder_alloc_buf size %zd got buffer %pK size %zd\n", in binder_alloc_new_buf_locked()
487 alloc->pid, size, buffer, buffer_size); in binder_alloc_new_buf_locked()
490 (((uintptr_t)buffer->user_data + buffer_size) & PAGE_MASK); in binder_alloc_new_buf_locked()
493 (void __user *)PAGE_ALIGN((uintptr_t)buffer->user_data + size); in binder_alloc_new_buf_locked()
497 PAGE_ALIGN((uintptr_t)buffer->user_data), end_page_addr); in binder_alloc_new_buf_locked()
504 new_buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); in binder_alloc_new_buf_locked()
506 pr_err("%s: %d failed to alloc new buffer struct\n", in binder_alloc_new_buf_locked()
510 new_buffer->user_data = (u8 __user *)buffer->user_data + size; in binder_alloc_new_buf_locked()
511 list_add(&new_buffer->entry, &buffer->entry); in binder_alloc_new_buf_locked()
517 buffer->free = 0; in binder_alloc_new_buf_locked()
518 buffer->allow_user_free = 0; in binder_alloc_new_buf_locked()
519 binder_insert_allocated_buffer_locked(alloc, buffer); in binder_alloc_new_buf_locked()
522 alloc->pid, size, buffer); in binder_alloc_new_buf_locked()
523 buffer->data_size = data_size; in binder_alloc_new_buf_locked()
524 buffer->offsets_size = offsets_size; in binder_alloc_new_buf_locked()
525 buffer->async_transaction = is_async; in binder_alloc_new_buf_locked()
526 buffer->extra_buffers_size = extra_buffers_size; in binder_alloc_new_buf_locked()
527 buffer->pid = pid; in binder_alloc_new_buf_locked()
537 * buffer size). in binder_alloc_new_buf_locked()
542 return buffer; in binder_alloc_new_buf_locked()
546 PAGE_ALIGN((uintptr_t)buffer->user_data), in binder_alloc_new_buf_locked()
552 * binder_alloc_new_buf() - Allocate a new binder buffer
554 * @data_size: size of user data buffer
555 * @offsets_size: user specified buffer offset
557 * @is_async: buffer for async transaction
560 * Allocate a new buffer given the requested sizes. Returns
561 * the kernel version of the buffer pointer. The size allocated
565 * Return: The allocated buffer or %NULL if error
574 struct binder_buffer *buffer; in binder_alloc_new_buf() local
577 buffer = binder_alloc_new_buf_locked(alloc, data_size, offsets_size, in binder_alloc_new_buf()
580 return buffer; in binder_alloc_new_buf()
583 static void __user *buffer_start_page(struct binder_buffer *buffer) in buffer_start_page() argument
585 return (void __user *)((uintptr_t)buffer->user_data & PAGE_MASK); in buffer_start_page()
588 static void __user *prev_buffer_end_page(struct binder_buffer *buffer) in prev_buffer_end_page() argument
591 (((uintptr_t)(buffer->user_data) - 1) & PAGE_MASK); in prev_buffer_end_page()
595 struct binder_buffer *buffer) in binder_delete_free_buffer() argument
600 BUG_ON(alloc->buffers.next == &buffer->entry); in binder_delete_free_buffer()
601 prev = binder_buffer_prev(buffer); in binder_delete_free_buffer()
603 if (prev_buffer_end_page(prev) == buffer_start_page(buffer)) { in binder_delete_free_buffer()
606 "%d: merge free, buffer %pK share page with %pK\n", in binder_delete_free_buffer()
607 alloc->pid, buffer->user_data, in binder_delete_free_buffer()
611 if (!list_is_last(&buffer->entry, &alloc->buffers)) { in binder_delete_free_buffer()
612 next = binder_buffer_next(buffer); in binder_delete_free_buffer()
613 if (buffer_start_page(next) == buffer_start_page(buffer)) { in binder_delete_free_buffer()
616 "%d: merge free, buffer %pK share page with %pK\n", in binder_delete_free_buffer()
618 buffer->user_data, in binder_delete_free_buffer()
623 if (PAGE_ALIGNED(buffer->user_data)) { in binder_delete_free_buffer()
625 "%d: merge free, buffer start %pK is page aligned\n", in binder_delete_free_buffer()
626 alloc->pid, buffer->user_data); in binder_delete_free_buffer()
632 "%d: merge free, buffer %pK do not share page with %pK or %pK\n", in binder_delete_free_buffer()
633 alloc->pid, buffer->user_data, in binder_delete_free_buffer()
636 binder_update_page_range(alloc, 0, buffer_start_page(buffer), in binder_delete_free_buffer()
637 buffer_start_page(buffer) + PAGE_SIZE); in binder_delete_free_buffer()
639 list_del(&buffer->entry); in binder_delete_free_buffer()
640 kfree(buffer); in binder_delete_free_buffer()
644 struct binder_buffer *buffer) in binder_free_buf_locked() argument
648 buffer_size = binder_alloc_buffer_size(alloc, buffer); in binder_free_buf_locked()
650 size = ALIGN(buffer->data_size, sizeof(void *)) + in binder_free_buf_locked()
651 ALIGN(buffer->offsets_size, sizeof(void *)) + in binder_free_buf_locked()
652 ALIGN(buffer->extra_buffers_size, sizeof(void *)); in binder_free_buf_locked()
656 alloc->pid, buffer, size, buffer_size); in binder_free_buf_locked()
658 BUG_ON(buffer->free); in binder_free_buf_locked()
660 BUG_ON(buffer->transaction != NULL); in binder_free_buf_locked()
661 BUG_ON(buffer->user_data < alloc->buffer); in binder_free_buf_locked()
662 BUG_ON(buffer->user_data > alloc->buffer + alloc->buffer_size); in binder_free_buf_locked()
664 if (buffer->async_transaction) { in binder_free_buf_locked()
673 (void __user *)PAGE_ALIGN((uintptr_t)buffer->user_data), in binder_free_buf_locked()
675 buffer->user_data + buffer_size) & PAGE_MASK)); in binder_free_buf_locked()
677 rb_erase(&buffer->rb_node, &alloc->allocated_buffers); in binder_free_buf_locked()
678 buffer->free = 1; in binder_free_buf_locked()
679 if (!list_is_last(&buffer->entry, &alloc->buffers)) { in binder_free_buf_locked()
680 struct binder_buffer *next = binder_buffer_next(buffer); in binder_free_buf_locked()
687 if (alloc->buffers.next != &buffer->entry) { in binder_free_buf_locked()
688 struct binder_buffer *prev = binder_buffer_prev(buffer); in binder_free_buf_locked()
691 binder_delete_free_buffer(alloc, buffer); in binder_free_buf_locked()
693 buffer = prev; in binder_free_buf_locked()
696 binder_insert_free_buffer(alloc, buffer); in binder_free_buf_locked()
700 struct binder_buffer *buffer);
702 * binder_alloc_free_buf() - free a binder buffer
704 * @buffer: kernel pointer to buffer
706 * Free the buffer allocated via binder_alloc_new_buf()
709 struct binder_buffer *buffer) in binder_alloc_free_buf() argument
719 if (buffer->clear_on_free) { in binder_alloc_free_buf()
720 binder_alloc_clear_buf(alloc, buffer); in binder_alloc_free_buf()
721 buffer->clear_on_free = false; in binder_alloc_free_buf()
724 binder_free_buf_locked(alloc, buffer); in binder_alloc_free_buf()
746 struct binder_buffer *buffer; in binder_alloc_mmap_handler() local
758 alloc->buffer = (void __user *)vma->vm_start; in binder_alloc_mmap_handler()
769 buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); in binder_alloc_mmap_handler()
770 if (!buffer) { in binder_alloc_mmap_handler()
772 failure_string = "alloc buffer struct"; in binder_alloc_mmap_handler()
776 buffer->user_data = alloc->buffer; in binder_alloc_mmap_handler()
777 list_add(&buffer->entry, &alloc->buffers); in binder_alloc_mmap_handler()
778 buffer->free = 1; in binder_alloc_mmap_handler()
779 binder_insert_free_buffer(alloc, buffer); in binder_alloc_mmap_handler()
790 alloc->buffer = NULL; in binder_alloc_mmap_handler()
807 struct binder_buffer *buffer; in binder_alloc_deferred_release() local
814 buffer = rb_entry(n, struct binder_buffer, rb_node); in binder_alloc_deferred_release()
817 BUG_ON(buffer->transaction); in binder_alloc_deferred_release()
819 if (buffer->clear_on_free) { in binder_alloc_deferred_release()
820 binder_alloc_clear_buf(alloc, buffer); in binder_alloc_deferred_release()
821 buffer->clear_on_free = false; in binder_alloc_deferred_release()
823 binder_free_buf_locked(alloc, buffer); in binder_alloc_deferred_release()
828 buffer = list_first_entry(&alloc->buffers, in binder_alloc_deferred_release()
830 WARN_ON(!buffer->free); in binder_alloc_deferred_release()
832 list_del(&buffer->entry); in binder_alloc_deferred_release()
834 kfree(buffer); in binder_alloc_deferred_release()
850 page_addr = alloc->buffer + i * PAGE_SIZE; in binder_alloc_deferred_release()
870 struct binder_buffer *buffer) in print_binder_buffer() argument
873 prefix, buffer->debug_id, buffer->user_data, in print_binder_buffer()
874 buffer->data_size, buffer->offsets_size, in print_binder_buffer()
875 buffer->extra_buffers_size, in print_binder_buffer()
876 buffer->transaction ? "active" : "delivered"); in print_binder_buffer()
880 * binder_alloc_print_allocated() - print buffer info
884 * Prints information about every buffer associated with
894 print_binder_buffer(m, " buffer", in binder_alloc_print_allocated()
998 page_addr = (uintptr_t)alloc->buffer + index * PAGE_SIZE; in binder_alloc_free_page()
1094 * check_buffer() - verify that buffer/offset is safe to access
1096 * @buffer: binder buffer to be accessed
1097 * @offset: offset into @buffer data
1101 * @buffer and that the buffer is currently active and not freeable.
1103 * allowed to touch the buffer in two cases:
1105 * 1) when the buffer is being created:
1106 * (buffer->free == 0 && buffer->allow_user_free == 0)
1107 * 2) when the buffer is being torn down:
1108 * (buffer->free == 0 && buffer->transaction == NULL).
1110 * Return: true if the buffer is safe to access
1113 struct binder_buffer *buffer, in check_buffer() argument
1116 size_t buffer_size = binder_alloc_buffer_size(alloc, buffer); in check_buffer()
1121 !buffer->free && in check_buffer()
1122 (!buffer->allow_user_free || !buffer->transaction); in check_buffer()
1126 * binder_alloc_get_page() - get kernel pointer for given buffer offset
1128 * @buffer: binder buffer to be accessed
1129 * @buffer_offset: offset into @buffer data
1133 * at @buffer_offset into @buffer->user_data. If @pgoffp is not
1137 * to a valid address within the @buffer and that @buffer is
1145 struct binder_buffer *buffer, in binder_alloc_get_page() argument
1150 (buffer->user_data - alloc->buffer); in binder_alloc_get_page()
1161 * binder_alloc_clear_buf() - zero out buffer
1163 * @buffer: binder buffer to be cleared
1165 * memset the given buffer to 0
1168 struct binder_buffer *buffer) in binder_alloc_clear_buf() argument
1170 size_t bytes = binder_alloc_buffer_size(alloc, buffer); in binder_alloc_clear_buf()
1179 page = binder_alloc_get_page(alloc, buffer, in binder_alloc_clear_buf()
1193 * @buffer: binder buffer to be accessed
1194 * @buffer_offset: offset into @buffer data
1195 * @from: userspace pointer to source buffer
1198 * Copy bytes from source userspace to target buffer.
1204 struct binder_buffer *buffer, in binder_alloc_copy_user_to_buffer() argument
1209 if (!check_buffer(alloc, buffer, buffer_offset, bytes)) in binder_alloc_copy_user_to_buffer()
1219 page = binder_alloc_get_page(alloc, buffer, in binder_alloc_copy_user_to_buffer()
1236 struct binder_buffer *buffer, in binder_alloc_do_buffer_copy() argument
1242 if (!check_buffer(alloc, buffer, buffer_offset, bytes)) in binder_alloc_do_buffer_copy()
1252 page = binder_alloc_get_page(alloc, buffer, in binder_alloc_do_buffer_copy()
1275 struct binder_buffer *buffer, in binder_alloc_copy_to_buffer() argument
1280 return binder_alloc_do_buffer_copy(alloc, true, buffer, buffer_offset, in binder_alloc_copy_to_buffer()
1286 struct binder_buffer *buffer, in binder_alloc_copy_from_buffer() argument
1290 return binder_alloc_do_buffer_copy(alloc, false, buffer, buffer_offset, in binder_alloc_copy_from_buffer()