History

binder_alloc: add missing mmap_lock calls when using the VMA

Take the mmap_read_lock() when using the VMA in binder_alloc_print_pages() and when checking for a VMA in binder_alloc_new_buf_locked(). It is worth noting binder_alloc_new_buf_locked() drops the VMA read lock after it verifies a VMA exists, but may be taken again deeper in the call stack, if necessary.

Liam Howlett committed 4 years ago

Commit 44e602b1 parent fcab34b1 file · +21 −10Browse files

Unified · Split

drivers/android/binder_alloc.c+21−10
@@ -402,12 +402,15 @@ static struct binder_buffer *binder_alloc_new_buf_locked( · 401 unmodified lines
402 size_t size, data_offsets_size;402 size_t size, data_offsets_size;
403 int ret;403 int ret;
404 404
405 mmap_read_lock(alloc->vma_vm_mm);
405 if (!binder_alloc_get_vma(alloc)) {406 if (!binder_alloc_get_vma(alloc)) {
407 mmap_read_unlock(alloc->vma_vm_mm);
406 binder_alloc_debug(BINDER_DEBUG_USER_ERROR,408 binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
407 "%d: binder_alloc_buf, no vma\n",409 "%d: binder_alloc_buf, no vma\n",
408 alloc->pid);410 alloc->pid);
409 return ERR_PTR(-ESRCH);411 return ERR_PTR(-ESRCH);
410 }412 }
413 mmap_read_unlock(alloc->vma_vm_mm);
411 414
412 data_offsets_size = ALIGN(data_size, sizeof(void *)) +415 data_offsets_size = ALIGN(data_size, sizeof(void *)) +
413 ALIGN(offsets_size, sizeof(void *));416 ALIGN(offsets_size, sizeof(void *));
@@ -929,17 +932,25 @@ void binder_alloc_print_pages(struct seq_file *m, · 515 unmodified lines
929 * Make sure the binder_alloc is fully initialized, otherwise we might932 * Make sure the binder_alloc is fully initialized, otherwise we might
930 * read inconsistent state.933 * read inconsistent state.
931 */934 */
932 if (binder_alloc_get_vma(alloc) != NULL) {935
933 for (i = 0; i < alloc->buffer_size / PAGE_SIZE; i++) {936 mmap_read_lock(alloc->vma_vm_mm);
934 page = &alloc->pages[i];937 if (binder_alloc_get_vma(alloc) == NULL) {
935 if (!page->page_ptr)938 mmap_read_unlock(alloc->vma_vm_mm);
936 free++;939 goto uninitialized;
937 else if (list_empty(&page->lru))
938 active++;
939 else
940 lru++;
941 }
942 }940 }
941
942 mmap_read_unlock(alloc->vma_vm_mm);
943 for (i = 0; i < alloc->buffer_size / PAGE_SIZE; i++) {
944 page = &alloc->pages[i];
945 if (!page->page_ptr)
946 free++;
947 else if (list_empty(&page->lru))
948 active++;
949 else
950 lru++;
951 }
952
953uninitialized:
943 mutex_unlock(&alloc->mutex);954 mutex_unlock(&alloc->mutex);
944 seq_printf(m, " pages: %d:%d:%d\n", active, lru, free);955 seq_printf(m, " pages: %d:%d:%d\n", active, lru, free);
945 seq_printf(m, " pages high watermark: %zu\n", alloc->pages_high);956 seq_printf(m, " pages high watermark: %zu\n", alloc->pages_high);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t