Introduce DEFINE_ACQUIRE(), a scoped_cond_guard() replacement
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest7 patches 19 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/7 | cleanup: Introduce DEFINE_ACQUIRE() a CLASS() for conditional lockingdrivers/ drivers/ include/ +1 more | +91 | 19 replies | |
| 2/7 | cxl/decoder: Move decoder register programming to a helperdrivers/ | +42 | 0 replies | |
| 3/7 | cxl/decoder: Drop pointless lockingdrivers/ | +0 | 0 replies | |
| 4/7 | cxl/region: Split commit_store() into __commit() and queue_reset() helpersdrivers/ | +70 | 0 replies | |
| 5/7 | cxl/region: Move ready-to-probe state check to a helperdrivers/ | +18 | 0 replies | |
| 6/7 | cxl/region: Introduce CLASS(cxl_decoder_detach...) consolidate multiple pathsdrivers/ drivers/ drivers/ | +83 | 0 replies | |
| 7/7 | cleanup: Create an rwsem conditional acquisition classdrivers/ drivers/ drivers/ +5 more | +219 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/7] Introduce DEFINE_ACQUIRE(), a scoped_cond_guard() replacement
As detailed in patch1, scoped_cond_guard() has some usability warts. The "if_not_guard()" effort tried to improve upon the situation, but was buggy and difficult to fix.
It turns out however that CLASS() already has the necessary semantics to address both the scoped_cond_guard() and if_not_guard() problems. CLASS() can be used to define an auto variable with a constructor (lock()), and a destructor (unlock()). This is what guard() does with a hidden variable for unconditional locks. For conditional locks, the variable is simply unhidden and evaluated with IS_ERR() to determine if the lock acquisition was successful.
The proposal goes one step further and forces conversions to this new scheme to be type-safe. So, if a subsystem using a mutex wants to use scope-based unlock for mutex_lock_interruptible() it needs to convert to the 'struct mutex_aquire' object and convert the entirety of the subsystem to using CLASS(), guard(), and/or scoped_guard() helpers. Note, scoped_cond_guard() is not defined for 'struct mutex_acquire'.
Reworks to accommodate type-safety enforcement is what makes this series 7 patches instead of 2. It converts all existing 'struct rw_semaphore' usage in the CXL subsystem to 'struct rw_semaphore_acquire'. That requires cleaning up some "reverse" locking patterns and "unlock in the middle of the function" patterns. The result is smaller and easier to reason about, once familiarity with CLASS() is established.
Dan Williams (7):
cleanup: Introduce DEFINE_ACQUIRE() a CLASS() for conditional locking cxl/decoder: Move decoder register programming to a helper cxl/decoder: Drop pointless locking
cxl/region: Split commit_store() into __commit() and queue_reset()
helpers
cxl/region: Move ready-to-probe state check to a helper cxl/region: Introduce CLASS(cxl_decoder_detach...) consolidate
multiple paths
cleanup: Create an rwsem conditional acquisition class
drivers/cxl/core/cdat.c | 6 +- drivers/cxl/core/core.h | 49 +++- drivers/cxl/core/hdm.c | 115 +++++----- drivers/cxl/core/mbox.c | 15 +- drivers/cxl/core/memdev.c | 62 ++--- drivers/cxl/core/port.c | 18 +- drivers/cxl/core/region.c | 463 ++++++++++++++++++-------------------- drivers/cxl/cxlmem.h | 2 +- include/linux/cleanup.h | 62 +++++ include/linux/mutex.h | 24 ++ include/linux/rwsem.h | 37 +++ 11 files changed, 491 insertions(+), 362 deletions(-)
base-commit: b4432656b36e5cc1d50a1f2dc15357543add530e
Signature · 1 line
2.49.0