[PATCH 0/7] Introduce DEFINE_ACQUIRE(), a scoped_cond_guard() replacement

Dan Williams posted 7 patches 7 months, 1 week ago
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(-)
[PATCH 0/7] Introduce DEFINE_ACQUIRE(), a scoped_cond_guard() replacement
Posted by Dan Williams 7 months, 1 week ago
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
-- 
2.49.0