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 * binder_alloc_free_buf() - free a binder buffer
702 * @buffer: kernel pointer to buffer
704 * Free the buffer allocated via binder_alloc_new_buf()
707 struct binder_buffer *buffer) in binder_alloc_free_buf() argument
710 binder_free_buf_locked(alloc, buffer); in binder_alloc_free_buf()
732 struct binder_buffer *buffer; in binder_alloc_mmap_handler() local
744 alloc->buffer = (void __user *)vma->vm_start; in binder_alloc_mmap_handler()
755 buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); in binder_alloc_mmap_handler()
756 if (!buffer) { in binder_alloc_mmap_handler()
758 failure_string = "alloc buffer struct"; in binder_alloc_mmap_handler()
762 buffer->user_data = alloc->buffer; in binder_alloc_mmap_handler()
763 list_add(&buffer->entry, &alloc->buffers); in binder_alloc_mmap_handler()
764 buffer->free = 1; in binder_alloc_mmap_handler()
765 binder_insert_free_buffer(alloc, buffer); in binder_alloc_mmap_handler()
776 alloc->buffer = NULL; in binder_alloc_mmap_handler()
793 struct binder_buffer *buffer; in binder_alloc_deferred_release() local
800 buffer = rb_entry(n, struct binder_buffer, rb_node); in binder_alloc_deferred_release()
803 BUG_ON(buffer->transaction); in binder_alloc_deferred_release()
805 binder_free_buf_locked(alloc, buffer); in binder_alloc_deferred_release()
810 buffer = list_first_entry(&alloc->buffers, in binder_alloc_deferred_release()
812 WARN_ON(!buffer->free); in binder_alloc_deferred_release()
814 list_del(&buffer->entry); in binder_alloc_deferred_release()
816 kfree(buffer); in binder_alloc_deferred_release()
832 page_addr = alloc->buffer + i * PAGE_SIZE; in binder_alloc_deferred_release()
852 struct binder_buffer *buffer) in print_binder_buffer() argument
855 prefix, buffer->debug_id, buffer->user_data, in print_binder_buffer()
856 buffer->data_size, buffer->offsets_size, in print_binder_buffer()
857 buffer->extra_buffers_size, in print_binder_buffer()
858 buffer->transaction ? "active" : "delivered"); in print_binder_buffer()
862 * binder_alloc_print_allocated() - print buffer info
866 * Prints information about every buffer associated with
876 print_binder_buffer(m, " buffer", in binder_alloc_print_allocated()
980 page_addr = (uintptr_t)alloc->buffer + index * PAGE_SIZE; in binder_alloc_free_page()
1072 * check_buffer() - verify that buffer/offset is safe to access
1074 * @buffer: binder buffer to be accessed
1075 * @offset: offset into @buffer data
1079 * @buffer and that the buffer is currently active and not freeable.
1081 * allowed to touch the buffer in two cases:
1083 * 1) when the buffer is being created:
1084 * (buffer->free == 0 && buffer->allow_user_free == 0)
1085 * 2) when the buffer is being torn down:
1086 * (buffer->free == 0 && buffer->transaction == NULL).
1088 * Return: true if the buffer is safe to access
1091 struct binder_buffer *buffer, in check_buffer() argument
1094 size_t buffer_size = binder_alloc_buffer_size(alloc, buffer); in check_buffer()
1099 !buffer->free && in check_buffer()
1100 (!buffer->allow_user_free || !buffer->transaction); in check_buffer()
1104 * binder_alloc_get_page() - get kernel pointer for given buffer offset
1106 * @buffer: binder buffer to be accessed
1107 * @buffer_offset: offset into @buffer data
1111 * at @buffer_offset into @buffer->user_data. If @pgoffp is not
1115 * to a valid address within the @buffer and that @buffer is
1123 struct binder_buffer *buffer, in binder_alloc_get_page() argument
1128 (buffer->user_data - alloc->buffer); in binder_alloc_get_page()
1141 * @buffer: binder buffer to be accessed
1142 * @buffer_offset: offset into @buffer data
1143 * @from: userspace pointer to source buffer
1146 * Copy bytes from source userspace to target buffer.
1152 struct binder_buffer *buffer, in binder_alloc_copy_user_to_buffer() argument
1157 if (!check_buffer(alloc, buffer, buffer_offset, bytes)) in binder_alloc_copy_user_to_buffer()
1167 page = binder_alloc_get_page(alloc, buffer, in binder_alloc_copy_user_to_buffer()
1184 struct binder_buffer *buffer, in binder_alloc_do_buffer_copy() argument
1190 if (!check_buffer(alloc, buffer, buffer_offset, bytes)) in binder_alloc_do_buffer_copy()
1200 page = binder_alloc_get_page(alloc, buffer, in binder_alloc_do_buffer_copy()
1223 struct binder_buffer *buffer, in binder_alloc_copy_to_buffer() argument
1228 return binder_alloc_do_buffer_copy(alloc, true, buffer, buffer_offset, in binder_alloc_copy_to_buffer()
1234 struct binder_buffer *buffer, in binder_alloc_copy_from_buffer() argument
1238 return binder_alloc_do_buffer_copy(alloc, false, buffer, buffer_offset, in binder_alloc_copy_from_buffer()