[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250507072145.3614298-1-dan.j.williams@intel.com>
Date: Wed, 7 May 2025 00:21:38 -0700
From: Dan Williams <dan.j.williams@...el.com>
To: <linux-cxl@...r.kernel.org>
CC: <linux-kernel@...r.kernel.org>, Alison Schofield
<alison.schofield@...el.com>, Dave Jiang <dave.jiang@...el.com>, "David
Lechner" <dlechner@...libre.com>, Davidlohr Bueso <dave@...olabs.net>, "Fabio
M. De Francesco" <fabio.maria.de.francesco@...ux.intel.com>, Ingo Molnar
<mingo@...nel.org>, Ira Weiny <ira.weiny@...el.com>, Jonathan Cameron
<jonathan.cameron@...wei.com>, Linus Torvalds
<torvalds@...ux-foundation.org>, Peter Zijlstra <peterz@...radead.org>,
Vishal Verma <vishal.l.verma@...el.com>
Subject: [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
--
2.49.0
Powered by blists - more mailing lists