Skip to content

binder: convert alloc->mutex to spinlock

Carlos Llamas lkml oe-kbuild-all stable 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest28 patches 30 repliesIn review
  2. v121 patches 35 repliesSuperseded

Changes in v2 from the cover letter

- New fix for wasted alloc->free_sync_space calculation
- Fix issues pointed out by Alice: incorrect size overflow check, data race in buffer->async_transaction, reorder of __free_page(page) and new_buffer leak in some error paths.
- Better naming and comments to accommodate the new scope of things e.g. binder_lru_freelist_add() and binder_install_single_page().
- Dropped patch ("binder: do not add pages to LRU in release path") since it is not worth the added complexity.
- Avoid _new_ logs of unhashed userspace addresses.
- More minor cosmeting changes.
- Add Reviewed-by tags.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/28binder: use EPOLLERR from eventpoll.hdrivers/android/binder.c+1 -10 replies
2/28binder: fix use-after-free in shinker's callbackdrivers/android/binder_alloc.c+5 -10 replies
3/28binder: fix race between mmput() and do_exit()drivers/android/binder_alloc.c+2 -26 replies
4/28binder: fix async space check for 0-sized buffersdrivers/android/binder_alloc.c+4 -34 replies
5/28binder: fix unused alloc->free_async_spacedrivers/android/binder_alloc.c+4 -78 replies
6/28binder: fix trivial typo of binder_free_buf_locked()drivers/android/binder_alloc.c+1 -10 replies
7/28binder: fix comment on binder_alloc_new_buf() return valuedrivers/android/binder_alloc.c+1 -10 replies
8/28binder: remove extern from function prototypesdrivers/android/binder_alloc.h+19 -190 replies
9/28binder: keep vma addresses type as unsigned longdrivers/android/binder.c drivers/android/binder_alloc.c drivers/android/binder_alloc.h +2 more+57 -691 reply
10/28binder: split up binder_update_page_range()drivers/android/binder_alloc.c+40 -390 replies
11/28binder: do unlocked work in binder_alloc_new_buf()drivers/android/binder_alloc.c+56 -393 replies
12/28binder: remove pid param in binder_alloc_new_buf()drivers/android/binder.c drivers/android/binder_alloc.c drivers/android/binder_alloc.h +1 more+12 -170 replies
13/28binder: separate the no-space debugging logicdrivers/android/binder_alloc.c+40 -310 replies
14/28binder: relocate low space calculationdrivers/android/binder_alloc.c+11 -100 replies
15/28binder: relocate binder_alloc_clear_buf()drivers/android/binder_alloc.c+61 -630 replies
16/28binder: refactor page range allocationdrivers/android/binder_alloc.c+47 -600 replies
17/28binder: malloc new_buffer outside of locksdrivers/android/binder_alloc.c+23 -211 reply
18/28binder: initialize lru pages in mmap callbackdrivers/android/binder_alloc.c+7 -50 replies
19/28binder: perform page installation outside of locksdrivers/android/binder_alloc.c+73 -281 reply
20/28binder: remove redundant debug logdrivers/android/binder_alloc.c+0 -31 reply
21/28binder: make oversized buffer code more readabledrivers/android/binder_alloc.c+10 -111 reply
22/28binder: rename lru shrinker utilitiesdrivers/android/binder_alloc.c drivers/android/binder_alloc.h drivers/android/binder_alloc_selftest.c+25 -251 reply
23/28binder: document the final page calculationdrivers/android/binder_alloc.c+11 -74 replies
24/28binder: collapse print_binder_buffer() into callerdrivers/android/binder_alloc.c+9 -131 reply
25/28binder: refactor binder_delete_free_buffer()drivers/android/binder_alloc.c+11 -331 reply
26/28binder: avoid user addresses in debug logsdrivers/android/binder.c drivers/android/binder_alloc.c+8 -111 reply
27/28binder: reverse locking order in shrinker callbackdrivers/android/binder_alloc.c+22 -244 replies
28/28binder: switch alloc->mutex to spinlock_tdrivers/android/binder_alloc.c drivers/android/binder_alloc.h+28 -280 replies

Reviews trailers per patch

27 of 28 patches have a Reviewed-by or Acked-by.

PatchAlice Ryhl
1/28R-b
2/28R-b
3/28R-b
4/28R-b
5/28R-b
6/28R-b
7/28R-b
8/28R-b
9/28R-b
10/28R-b
11/28R-b
12/28R-b
13/28R-b
14/28R-b
15/28R-b
16/28R-b
17/28R-b
18/28R-b
19/28R-b
20/28R-b
21/28R-b
22/28R-b
23/28
24/28R-b
25/28R-b
26/28R-b
27/28R-b
28/28R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 00/28] binder: convert alloc->mutex to spinlock

This series refactors the binder buffer allocation space to be able to convert the alloc->mutex into a spinlock. Doing so decreases the latency of binder transactions seen under worst-case scenarios.

I attempted to organize and improve readability of things that were touched during this process. I also include a couple of fixes (unrelated to the lock conversion) for issues I found along the way.

Regards,
Carlos Llamas

Cc Todd Kjos <[email protected]>
Cc Alice Ryhl <[email protected]>
Cc John Stultz <[email protected]>
Cc Suren Baghdasaryan <[email protected]>
Cc Tim Murray <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>

v2:
- New fix for wasted alloc->free_sync_space calculation
- Fix issues pointed out by Alice: incorrect size overflow check, data race in buffer->async_transaction, reorder of __free_page(page) and new_buffer leak in some error paths.
- Better naming and comments to accommodate the new scope of things e.g. binder_lru_freelist_add() and binder_install_single_page().
- Dropped patch ("binder: do not add pages to LRU in release path") since it is not worth the added complexity.
- Avoid _new_ logs of unhashed userspace addresses.
- More minor cosmeting changes.
- Add Reviewed-by tags.

v1:
https://lore.kernel.org/all/[email protected]/

Carlos Llamas (28):
binder: use EPOLLERR from eventpoll.h
binder: fix use-after-free in shinker's callback
binder: fix race between mmput() and do_exit()
binder: fix async space check for 0-sized buffers
binder: fix unused alloc->free_async_space
binder: fix trivial typo of binder_free_buf_locked()
binder: fix comment on binder_alloc_new_buf() return value
binder: remove extern from function prototypes
binder: keep vma addresses type as unsigned long
binder: split up binder_update_page_range()
binder: do unlocked work in binder_alloc_new_buf()
binder: remove pid param in binder_alloc_new_buf()
binder: separate the no-space debugging logic
binder: relocate low space calculation
binder: relocate binder_alloc_clear_buf()
binder: refactor page range allocation
binder: malloc new_buffer outside of locks
binder: initialize lru pages in mmap callback
binder: perform page installation outside of locks
binder: remove redundant debug log
binder: make oversized buffer code more readable
binder: rename lru shrinker utilities
binder: document the final page calculation
binder: collapse print_binder_buffer() into caller
binder: refactor binder_delete_free_buffer()
binder: avoid user addresses in debug logs
binder: reverse locking order in shrinker callback
binder: switch alloc->mutex to spinlock_t

 drivers/android/binder.c                |  27 +-
 drivers/android/binder_alloc.c          | 858 ++++++++++++------------
 drivers/android/binder_alloc.h          |  61 +-
 drivers/android/binder_alloc_selftest.c |  14 +-
 drivers/android/binder_trace.h          |   2 +-
 5 files changed, 489 insertions(+), 473 deletions(-)

base-commit: 994d5c58e50e91bb02c7be4a91d5186292a895c8

Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog