Linux CXL
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: <linux-cxl@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>,
	Alison Schofield <alison.schofield@intel.com>,
	Dave Jiang <dave.jiang@intel.com>,
	"David Lechner" <dlechner@baylibre.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	"Fabio M. De Francesco"
	<fabio.maria.de.francesco@linux.intel.com>,
	Ingo Molnar <mingo@kernel.org>, Ira Weiny <ira.weiny@intel.com>,
	Jonathan Cameron <jonathan.cameron@huawei.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Vishal Verma <vishal.l.verma@intel.com>
Subject: [PATCH 0/7] Introduce DEFINE_ACQUIRE(), a scoped_cond_guard() replacement
Date: Wed, 7 May 2025 00:21:38 -0700	[thread overview]
Message-ID: <20250507072145.3614298-1-dan.j.williams@intel.com> (raw)

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


             reply	other threads:[~2025-05-07  7:23 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-07  7:21 Dan Williams [this message]
2025-05-07  7:21 ` [PATCH 1/7] cleanup: Introduce DEFINE_ACQUIRE() a CLASS() for conditional locking Dan Williams
2025-05-07  9:32   ` Peter Zijlstra
2025-05-07 21:18     ` Dan Williams
2025-05-08 11:00       ` Peter Zijlstra
2025-05-09  5:04         ` Dan Williams
2025-05-09 10:40           ` Peter Zijlstra
2025-05-10  1:11             ` dan.j.williams
2025-05-12 10:50               ` Peter Zijlstra
2025-05-12 18:25                 ` Peter Zijlstra
2025-05-12 18:58                   ` Peter Zijlstra
2025-05-12 20:39                     ` Linus Torvalds
2025-05-13  7:09                       ` Peter Zijlstra
2025-05-13  8:50                         ` Peter Zijlstra
2025-05-13 19:46                           ` Linus Torvalds
2025-05-13 20:06                             ` Al Viro
2025-05-13 20:31                               ` Al Viro
2025-05-13 21:28                                 ` Linus Torvalds
2025-05-17  9:17                                   ` David Laight
2025-05-14  6:46                             ` Peter Zijlstra
2025-05-13  3:32                     ` dan.j.williams
2025-05-09 19:10   ` kernel test robot
2025-05-07  7:21 ` [PATCH 2/7] cxl/decoder: Move decoder register programming to a helper Dan Williams
2025-05-07  7:21 ` [PATCH 3/7] cxl/decoder: Drop pointless locking Dan Williams
2025-05-07  7:21 ` [PATCH 4/7] cxl/region: Split commit_store() into __commit() and queue_reset() helpers Dan Williams
2025-05-07  7:21 ` [PATCH 5/7] cxl/region: Move ready-to-probe state check to a helper Dan Williams
2025-05-07  7:21 ` [PATCH 6/7] cxl/region: Introduce CLASS(cxl_decoder_detach...) consolidate multiple paths Dan Williams
2025-05-08  7:44   ` kernel test robot
2025-05-07  7:21 ` [PATCH 7/7] cleanup: Create an rwsem conditional acquisition class Dan Williams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250507072145.3614298-1-dan.j.williams@intel.com \
    --to=dan.j.williams@intel.com \
    --cc=alison.schofield@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=dlechner@baylibre.com \
    --cc=fabio.maria.de.francesco@linux.intel.com \
    --cc=ira.weiny@intel.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=torvalds@linux-foundation.org \
    --cc=vishal.l.verma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox