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()
333 struct binder_buffer *buffer; in debug_low_async_space_locked() local
339 buffer = rb_entry(n, struct binder_buffer, rb_node); in debug_low_async_space_locked()
340 if (buffer->pid != pid) in debug_low_async_space_locked()
342 if (!buffer->async_transaction) in debug_low_async_space_locked()
344 total_alloc_size += binder_alloc_buffer_size(alloc, buffer) in debug_low_async_space_locked()
351 * async space (which is 25% of total buffer size). Oneway spam is only in debug_low_async_space_locked()
375 struct binder_buffer *buffer; in binder_alloc_new_buf_locked() local
421 buffer = rb_entry(n, struct binder_buffer, rb_node); in binder_alloc_new_buf_locked()
422 BUG_ON(!buffer->free); in binder_alloc_new_buf_locked()
423 buffer_size = binder_alloc_buffer_size(alloc, buffer); in binder_alloc_new_buf_locked()
445 buffer = rb_entry(n, struct binder_buffer, rb_node); in binder_alloc_new_buf_locked()
446 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()
472 buffer = rb_entry(best_fit, struct binder_buffer, rb_node); in binder_alloc_new_buf_locked()
473 buffer_size = binder_alloc_buffer_size(alloc, buffer); in binder_alloc_new_buf_locked()
477 "%d: binder_alloc_buf size %zd got buffer %pK size %zd\n", in binder_alloc_new_buf_locked()
478 alloc->pid, size, buffer, buffer_size); in binder_alloc_new_buf_locked()
481 (((uintptr_t)buffer->user_data + buffer_size) & PAGE_MASK); in binder_alloc_new_buf_locked()
484 (void __user *)PAGE_ALIGN((uintptr_t)buffer->user_data + size); in binder_alloc_new_buf_locked()
488 PAGE_ALIGN((uintptr_t)buffer->user_data), end_page_addr); in binder_alloc_new_buf_locked()
495 new_buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); in binder_alloc_new_buf_locked()
497 pr_err("%s: %d failed to alloc new buffer struct\n", in binder_alloc_new_buf_locked()
501 new_buffer->user_data = (u8 __user *)buffer->user_data + size; in binder_alloc_new_buf_locked()
502 list_add(&new_buffer->entry, &buffer->entry); in binder_alloc_new_buf_locked()
508 buffer->free = 0; in binder_alloc_new_buf_locked()
509 buffer->allow_user_free = 0; in binder_alloc_new_buf_locked()
510 binder_insert_allocated_buffer_locked(alloc, buffer); in binder_alloc_new_buf_locked()
513 alloc->pid, size, buffer); in binder_alloc_new_buf_locked()
514 buffer->data_size = data_size; in binder_alloc_new_buf_locked()
515 buffer->offsets_size = offsets_size; in binder_alloc_new_buf_locked()
516 buffer->async_transaction = is_async; in binder_alloc_new_buf_locked()
517 buffer->extra_buffers_size = extra_buffers_size; in binder_alloc_new_buf_locked()
518 buffer->pid = pid; in binder_alloc_new_buf_locked()
519 buffer->oneway_spam_suspect = false; in binder_alloc_new_buf_locked()
529 * buffer size). in binder_alloc_new_buf_locked()
531 buffer->oneway_spam_suspect = debug_low_async_space_locked(alloc, pid); in binder_alloc_new_buf_locked()
536 return buffer; in binder_alloc_new_buf_locked()
540 PAGE_ALIGN((uintptr_t)buffer->user_data), in binder_alloc_new_buf_locked()
546 * binder_alloc_new_buf() - Allocate a new binder buffer
548 * @data_size: size of user data buffer
549 * @offsets_size: user specified buffer offset
551 * @is_async: buffer for async transaction
554 * Allocate a new buffer given the requested sizes. Returns
555 * the kernel version of the buffer pointer. The size allocated
559 * Return: The allocated buffer or %NULL if error
568 struct binder_buffer *buffer; in binder_alloc_new_buf() local
571 buffer = binder_alloc_new_buf_locked(alloc, data_size, offsets_size, in binder_alloc_new_buf()
574 return buffer; in binder_alloc_new_buf()
577 static void __user *buffer_start_page(struct binder_buffer *buffer) in buffer_start_page() argument
579 return (void __user *)((uintptr_t)buffer->user_data & PAGE_MASK); in buffer_start_page()
582 static void __user *prev_buffer_end_page(struct binder_buffer *buffer) in prev_buffer_end_page() argument
585 (((uintptr_t)(buffer->user_data) - 1) & PAGE_MASK); in prev_buffer_end_page()
589 struct binder_buffer *buffer) in binder_delete_free_buffer() argument
594 BUG_ON(alloc->buffers.next == &buffer->entry); in binder_delete_free_buffer()
595 prev = binder_buffer_prev(buffer); in binder_delete_free_buffer()
597 if (prev_buffer_end_page(prev) == buffer_start_page(buffer)) { in binder_delete_free_buffer()
600 "%d: merge free, buffer %pK share page with %pK\n", in binder_delete_free_buffer()
601 alloc->pid, buffer->user_data, in binder_delete_free_buffer()
605 if (!list_is_last(&buffer->entry, &alloc->buffers)) { in binder_delete_free_buffer()
606 next = binder_buffer_next(buffer); in binder_delete_free_buffer()
607 if (buffer_start_page(next) == buffer_start_page(buffer)) { in binder_delete_free_buffer()
610 "%d: merge free, buffer %pK share page with %pK\n", in binder_delete_free_buffer()
612 buffer->user_data, in binder_delete_free_buffer()
617 if (PAGE_ALIGNED(buffer->user_data)) { in binder_delete_free_buffer()
619 "%d: merge free, buffer start %pK is page aligned\n", in binder_delete_free_buffer()
620 alloc->pid, buffer->user_data); in binder_delete_free_buffer()
626 "%d: merge free, buffer %pK do not share page with %pK or %pK\n", in binder_delete_free_buffer()
627 alloc->pid, buffer->user_data, in binder_delete_free_buffer()
630 binder_update_page_range(alloc, 0, buffer_start_page(buffer), in binder_delete_free_buffer()
631 buffer_start_page(buffer) + PAGE_SIZE); in binder_delete_free_buffer()
633 list_del(&buffer->entry); in binder_delete_free_buffer()
634 kfree(buffer); in binder_delete_free_buffer()
638 struct binder_buffer *buffer) in binder_free_buf_locked() argument
642 buffer_size = binder_alloc_buffer_size(alloc, buffer); in binder_free_buf_locked()
644 size = ALIGN(buffer->data_size, sizeof(void *)) + in binder_free_buf_locked()
645 ALIGN(buffer->offsets_size, sizeof(void *)) + in binder_free_buf_locked()
646 ALIGN(buffer->extra_buffers_size, sizeof(void *)); in binder_free_buf_locked()
650 alloc->pid, buffer, size, buffer_size); in binder_free_buf_locked()
652 BUG_ON(buffer->free); in binder_free_buf_locked()
654 BUG_ON(buffer->transaction != NULL); in binder_free_buf_locked()
655 BUG_ON(buffer->user_data < alloc->buffer); in binder_free_buf_locked()
656 BUG_ON(buffer->user_data > alloc->buffer + alloc->buffer_size); in binder_free_buf_locked()
658 if (buffer->async_transaction) { in binder_free_buf_locked()
667 (void __user *)PAGE_ALIGN((uintptr_t)buffer->user_data), in binder_free_buf_locked()
669 buffer->user_data + buffer_size) & PAGE_MASK)); in binder_free_buf_locked()
671 rb_erase(&buffer->rb_node, &alloc->allocated_buffers); in binder_free_buf_locked()
672 buffer->free = 1; in binder_free_buf_locked()
673 if (!list_is_last(&buffer->entry, &alloc->buffers)) { in binder_free_buf_locked()
674 struct binder_buffer *next = binder_buffer_next(buffer); in binder_free_buf_locked()
681 if (alloc->buffers.next != &buffer->entry) { in binder_free_buf_locked()
682 struct binder_buffer *prev = binder_buffer_prev(buffer); in binder_free_buf_locked()
685 binder_delete_free_buffer(alloc, buffer); in binder_free_buf_locked()
687 buffer = prev; in binder_free_buf_locked()
690 binder_insert_free_buffer(alloc, buffer); in binder_free_buf_locked()
694 struct binder_buffer *buffer);
696 * binder_alloc_free_buf() - free a binder buffer
698 * @buffer: kernel pointer to buffer
700 * Free the buffer allocated via binder_alloc_new_buf()
703 struct binder_buffer *buffer) in binder_alloc_free_buf() argument
713 if (buffer->clear_on_free) { in binder_alloc_free_buf()
714 binder_alloc_clear_buf(alloc, buffer); in binder_alloc_free_buf()
715 buffer->clear_on_free = false; in binder_alloc_free_buf()
718 binder_free_buf_locked(alloc, buffer); in binder_alloc_free_buf()
740 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()
789 alloc->buffer = NULL; in binder_alloc_mmap_handler()
807 struct binder_buffer *buffer; in binder_alloc_deferred_release() local
815 buffer = rb_entry(n, struct binder_buffer, rb_node); in binder_alloc_deferred_release()
818 BUG_ON(buffer->transaction); in binder_alloc_deferred_release()
820 if (buffer->clear_on_free) { in binder_alloc_deferred_release()
821 binder_alloc_clear_buf(alloc, buffer); in binder_alloc_deferred_release()
822 buffer->clear_on_free = false; in binder_alloc_deferred_release()
824 binder_free_buf_locked(alloc, buffer); in binder_alloc_deferred_release()
829 buffer = list_first_entry(&alloc->buffers, in binder_alloc_deferred_release()
831 WARN_ON(!buffer->free); in binder_alloc_deferred_release()
833 list_del(&buffer->entry); in binder_alloc_deferred_release()
835 kfree(buffer); in binder_alloc_deferred_release()
851 page_addr = alloc->buffer + i * PAGE_SIZE; in binder_alloc_deferred_release()
871 struct binder_buffer *buffer) in print_binder_buffer() argument
874 prefix, buffer->debug_id, buffer->user_data, in print_binder_buffer()
875 buffer->data_size, buffer->offsets_size, in print_binder_buffer()
876 buffer->extra_buffers_size, in print_binder_buffer()
877 buffer->transaction ? "active" : "delivered"); in print_binder_buffer()
881 * binder_alloc_print_allocated() - print buffer info
885 * Prints information about every buffer associated with
895 print_binder_buffer(m, " buffer", in binder_alloc_print_allocated()
1007 page_addr = (uintptr_t)alloc->buffer + index * PAGE_SIZE; in binder_alloc_free_page()
1097 * check_buffer() - verify that buffer/offset is safe to access
1099 * @buffer: binder buffer to be accessed
1100 * @offset: offset into @buffer data
1104 * @buffer and that the buffer is currently active and not freeable.
1106 * allowed to touch the buffer in two cases:
1108 * 1) when the buffer is being created:
1109 * (buffer->free == 0 && buffer->allow_user_free == 0)
1110 * 2) when the buffer is being torn down:
1111 * (buffer->free == 0 && buffer->transaction == NULL).
1113 * Return: true if the buffer is safe to access
1116 struct binder_buffer *buffer, in check_buffer() argument
1119 size_t buffer_size = binder_alloc_buffer_size(alloc, buffer); in check_buffer()
1124 !buffer->free && in check_buffer()
1125 (!buffer->allow_user_free || !buffer->transaction); in check_buffer()
1129 * binder_alloc_get_page() - get kernel pointer for given buffer offset
1131 * @buffer: binder buffer to be accessed
1132 * @buffer_offset: offset into @buffer data
1136 * at @buffer_offset into @buffer->user_data. If @pgoffp is not
1140 * to a valid address within the @buffer and that @buffer is
1148 struct binder_buffer *buffer, in binder_alloc_get_page() argument
1153 (buffer->user_data - alloc->buffer); in binder_alloc_get_page()
1164 * binder_alloc_clear_buf() - zero out buffer
1166 * @buffer: binder buffer to be cleared
1168 * memset the given buffer to 0
1171 struct binder_buffer *buffer) in binder_alloc_clear_buf() argument
1173 size_t bytes = binder_alloc_buffer_size(alloc, buffer); in binder_alloc_clear_buf()
1181 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()
1250 page = binder_alloc_get_page(alloc, buffer, in binder_alloc_do_buffer_copy()
1266 struct binder_buffer *buffer, in binder_alloc_copy_to_buffer() argument
1271 return binder_alloc_do_buffer_copy(alloc, true, buffer, buffer_offset, in binder_alloc_copy_to_buffer()
1277 struct binder_buffer *buffer, in binder_alloc_copy_from_buffer() argument
1281 return binder_alloc_do_buffer_copy(alloc, false, buffer, buffer_offset, in binder_alloc_copy_from_buffer()