Skip to contentSkip to conversation

binder: reduce mmap_sem write-side lock

PATCH In review Minchan Kim 3 participants 4 messages Feb 18, 2019 – Feb 19, 2019 Android drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 binder: reduce mmap_sem write-side lock

binder has used write-side mmap_sem semaphore to release memory mapped at address space of the process. However, right lock to release pages is down_read, not down_write because page table lock already protects the race for parallel freeing.

Please do not use mmap_sem write-side lock which is well known contented lock.

Cc Todd Kjos <[email protected]>
Cc Martijn Coenen <[email protected]>
Cc Arve Hjønnevåg <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/android/binder_alloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/android/binder_alloc.c +2 -2
index 022cd80e80cc3..2a62553b20fcc 100644
@@ -964,7 +964,7 @@ enum lru_status binder_alloc_free_page(struct list_head *item,
 		if (!mmget_not_zero(alloc->vma_vm_mm))
 			goto err_mmget;
 		mm = alloc->vma_vm_mm;
-		if (!down_write_trylock(&mm->mmap_sem))
+		if (!down_read_trylock(&mm->mmap_sem))
 			goto err_down_write_mmap_sem_failed;
 	}
 
@@ -980,7 +980,7 @@ enum lru_status binder_alloc_free_page(struct list_head *item,
 
 		trace_binder_unmap_user_end(alloc, index);
 
-		up_write(&mm->mmap_sem);
+		up_read(&mm->mmap_sem);
 		mmput(mm);
 	}
 
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
maintainer
#1 lore raw
Quoted 8 lines · Minchan Kim

binder has used write-side mmap_sem semaphore to release memory mapped at address space of the process. However, right lock to release pages is down_read, not down_write because page table lock already protects the race for parallel freeing.

Please do not use mmap_sem write-side lock which is well known contented lock.

Quoted 8 lines
Cc Todd Kjos <[email protected]>
Cc Martijn Coenen <[email protected]>
Cc Arve Hjønnevåg <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/android/binder_alloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Is this just needed for the recent binder changes that are in linux-next, or for older kernels as well?

thanks,

greg k-h

#2 lore raw
Quoted 18 lines · Greg KH
Quoted 8 lines · Minchan Kim

binder has used write-side mmap_sem semaphore to release memory mapped at address space of the process. However, right lock to release pages is down_read, not down_write because page table lock already protects the race for parallel freeing.

Please do not use mmap_sem write-side lock which is well known contented lock.

Quoted 8 lines
Cc Todd Kjos <[email protected]>
Cc Martijn Coenen <[email protected]>
Cc Arve Hjønnevåg <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/android/binder_alloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 2 lines

Is this just needed for the recent binder changes that are in linux-next, or for older kernels as well?

It has been there for several years but no need to fix older kernels because down_write of mmap_sem is technically not a bug to stop the working of binder. Rather than, it's just abuse of the lock so it's okay to fix only recent kernel.

Thanks.

Acked-by
#3 lore raw
Quoted 8 lines · Minchan Kim
Quoted 6 lines · Greg KH
Quoted 5 lines · Minchan Kim

binder has used write-side mmap_sem semaphore to release memory mapped at address space of the process. However, right lock to release pages is down_read, not down_write because page table lock already protects the race for parallel freeing.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Please do not use mmap_sem write-side lock which is well known contented lock.

Cc Todd Kjos <[email protected]>
Cc Martijn Coenen <[email protected]>
Cc Arve Hjønnevåg <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Quoted 13 lines
Quoted 6 lines
Quoted 3 lines
---
 drivers/android/binder_alloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Is this just needed for the recent binder changes that are in linux-next, or for older kernels as well?

It has been there for several years but no need to fix older kernels because down_write of mmap_sem is technically not a bug to stop the working of binder. Rather than, it's just abuse of the lock so it's okay to fix only recent kernel.

Thanks.