Skip to content

Introduce DEFINE_ACQUIRE(), a scoped_cond_guard() replacement

Dan Williams linux-cxl lkml llvm oe-kbuild-all 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest7 patches 19 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7cleanup: Introduce DEFINE_ACQUIRE() a CLASS() for conditional lockingdrivers/cxl/core/mbox.c drivers/cxl/cxlmem.h include/linux/cleanup.h +1 more+91 -619 replies
2/7cxl/decoder: Move decoder register programming to a helperdrivers/cxl/core/hdm.c+42 -350 replies
3/7cxl/decoder: Drop pointless lockingdrivers/cxl/core/hdm.c+0 -20 replies
4/7cxl/region: Split commit_store() into __commit() and queue_reset() helpersdrivers/cxl/core/region.c+70 -290 replies
5/7cxl/region: Move ready-to-probe state check to a helperdrivers/cxl/core/region.c+18 -60 replies
6/7cxl/region: Introduce CLASS(cxl_decoder_detach...) consolidate multiple pathsdrivers/cxl/core/core.h drivers/cxl/core/port.c drivers/cxl/core/region.c+83 -540 replies
7/7cleanup: Create an rwsem conditional acquisition classdrivers/cxl/core/cdat.c drivers/cxl/core/core.h drivers/cxl/core/hdm.c +5 more+219 -2620 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

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