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.
Unified · Split
| @@ -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 might | 932 | * 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 | |||
| 953 | uninitialized: | ||
| 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); |