Skip to content

Commit c0fd210

Browse files
Carlos Llamasgregkh
authored andcommitted
Revert "android: binder: stop saving a pointer to the VMA"
This reverts commit a43cfc8. This patch fixed an issue reported by syzkaller in [1]. However, this turned out to be only a band-aid in binder. The root cause, as bisected by syzkaller, was fixed by commit 5789151 ("mm/mmap: undo ->mmap() when mas_preallocate() fails"). We no longer need the patch for binder. Reverting such patch allows us to have a lockless access to alloc->vma in specific cases where the mmap_lock is not required. This approach avoids the contention that caused a performance regression. [1] https://lore.kernel.org/all/0000000000004a0dbe05e1d749e0@google.com [cmllamas: resolved conflicts with rework of alloc->mm and removal of binder_alloc_set_vma() also fixed comment section] Fixes: a43cfc8 ("android: binder: stop saving a pointer to the VMA") Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Suren Baghdasaryan <surenb@google.com> Cc: stable@vger.kernel.org Signed-off-by: Carlos Llamas <cmllamas@google.com> Link: https://lore.kernel.org/r/20230502201220.1756319-2-cmllamas@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b15655b commit c0fd210

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

drivers/android/binder_alloc.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static int binder_update_page_range(struct binder_alloc *alloc, int allocate,
213213

214214
if (mm) {
215215
mmap_read_lock(mm);
216-
vma = vma_lookup(mm, alloc->vma_addr);
216+
vma = alloc->vma;
217217
}
218218

219219
if (!vma && need_mm) {
@@ -314,9 +314,11 @@ static inline struct vm_area_struct *binder_alloc_get_vma(
314314
{
315315
struct vm_area_struct *vma = NULL;
316316

317-
if (alloc->vma_addr)
318-
vma = vma_lookup(alloc->mm, alloc->vma_addr);
319-
317+
if (alloc->vma) {
318+
/* Look at description in binder_alloc_set_vma */
319+
smp_rmb();
320+
vma = alloc->vma;
321+
}
320322
return vma;
321323
}
322324

@@ -775,7 +777,7 @@ int binder_alloc_mmap_handler(struct binder_alloc *alloc,
775777
buffer->free = 1;
776778
binder_insert_free_buffer(alloc, buffer);
777779
alloc->free_async_space = alloc->buffer_size / 2;
778-
alloc->vma_addr = vma->vm_start;
780+
alloc->vma = vma;
779781

780782
return 0;
781783

@@ -805,8 +807,7 @@ void binder_alloc_deferred_release(struct binder_alloc *alloc)
805807

806808
buffers = 0;
807809
mutex_lock(&alloc->mutex);
808-
BUG_ON(alloc->vma_addr &&
809-
vma_lookup(alloc->mm, alloc->vma_addr));
810+
BUG_ON(alloc->vma);
810811

811812
while ((n = rb_first(&alloc->allocated_buffers))) {
812813
buffer = rb_entry(n, struct binder_buffer, rb_node);
@@ -958,7 +959,7 @@ int binder_alloc_get_allocated_count(struct binder_alloc *alloc)
958959
*/
959960
void binder_alloc_vma_close(struct binder_alloc *alloc)
960961
{
961-
alloc->vma_addr = 0;
962+
alloc->vma = 0;
962963
}
963964

964965
/**

drivers/android/binder_alloc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct binder_lru_page {
7575
/**
7676
* struct binder_alloc - per-binder proc state for binder allocator
7777
* @mutex: protects binder_alloc fields
78-
* @vma_addr: vm_area_struct->vm_start passed to mmap_handler
78+
* @vma: vm_area_struct passed to mmap_handler
7979
* (invariant after mmap)
8080
* @mm: copy of task->mm (invariant after open)
8181
* @buffer: base of per-proc address space mapped via mmap
@@ -99,7 +99,7 @@ struct binder_lru_page {
9999
*/
100100
struct binder_alloc {
101101
struct mutex mutex;
102-
unsigned long vma_addr;
102+
struct vm_area_struct *vma;
103103
struct mm_struct *mm;
104104
void __user *buffer;
105105
struct list_head buffers;

drivers/android/binder_alloc_selftest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ void binder_selftest_alloc(struct binder_alloc *alloc)
287287
if (!binder_selftest_run)
288288
return;
289289
mutex_lock(&binder_selftest_lock);
290-
if (!binder_selftest_run || !alloc->vma_addr)
290+
if (!binder_selftest_run || !alloc->vma)
291291
goto done;
292292
pr_info("STARTED\n");
293293
binder_selftest_alloc_offset(alloc, end_offset, 0);

0 commit comments

Comments
 (0)