From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
To: Dan Williams <dan.j.williams@intel.com>
Cc: <linux-cxl@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
David Lechner <dlechner@baylibre.com>,
Peter Zijlstra <peterz@infradead.org>,
"Linus Torvalds" <torvalds@linux-foundation.org>,
Ingo Molnar <mingo@kernel.org>,
"Fabio M. De Francesco"
<fabio.maria.de.francesco@linux.intel.com>,
Davidlohr Bueso <dave@stgolabs.net>,
Dave Jiang <dave.jiang@intel.com>,
Alison Schofield <alison.schofield@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>,
Ira Weiny <ira.weiny@intel.com>,
Shiju Jose <shiju.jose@huawei.com>
Subject: Re: [PATCH v2 8/8] cxl: Convert to ACQUIRE() for conditional rwsem locking
Date: Mon, 23 Jun 2025 11:32:08 +0100 [thread overview]
Message-ID: <20250623113208.0000768c@huawei.com> (raw)
In-Reply-To: <20250619050416.782871-9-dan.j.williams@intel.com>
On Wed, 18 Jun 2025 22:04:16 -0700
Dan Williams <dan.j.williams@intel.com> wrote:
> Use ACQUIRE() to cleanup conditional locking paths in the CXL driver
> The ACQUIRE() macro and its associated ACQUIRE_ERR() helpers, like
> scoped_cond_guard(), arrange for scoped-based conditional locking. Unlike
> scoped_cond_guard(), these macros arrange for an ERR_PTR() to be retrieved
> representing the state of the conditional lock.
>
> The goal of this conversion is to complete the removal of all explicit
> unlock calls in the subsystem. I.e. the methods to acquire a lock are
> solely via guard(), scoped_guard() (for limited cases), or ACQUIRE(). All
> unlock is implicit / scope-based. In order to make sure all lock sites are
> converted, the existing rwsem's are consolidated and renamed in 'struct
> cxl_rwsem'. While that makes the patch noisier it gives a clean cut-off
> between old-world (explicit unlock allowed), and new world (explicit unlock
> deleted).
>
> Cc: David Lechner <dlechner@baylibre.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: "Fabio M. De Francesco" <fabio.maria.de.francesco@linux.intel.com>
> Cc: Davidlohr Bueso <dave@stgolabs.net>
> Cc: Jonathan Cameron <jonathan.cameron@huawei.com>
> Cc: Dave Jiang <dave.jiang@intel.com>
> Cc: Alison Schofield <alison.schofield@intel.com>
> Cc: Vishal Verma <vishal.l.verma@intel.com>
> Cc: Ira Weiny <ira.weiny@intel.com>
> Cc: Shiju Jose <shiju.jose@huawei.com>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
A few comments inline.
> index 010964aa5489..a2ba19151d4f 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> static DEVICE_ATTR_RW(interleave_ways);
> @@ -561,15 +537,11 @@ static ssize_t interleave_granularity_show(struct device *dev,
> {
> struct cxl_region *cxlr = to_cxl_region(dev);
> struct cxl_region_params *p = &cxlr->params;
> - ssize_t rc;
> -
> - rc = down_read_interruptible(&cxl_region_rwsem);
> - if (rc)
> - return rc;
> - rc = sysfs_emit(buf, "%d\n", p->interleave_granularity);
> - up_read(&cxl_region_rwsem);
>
> - return rc;
> + ACQUIRE(rwsem_read_intr, rwsem)(&cxl_rwsem.region);
> + if (ACQUIRE_ERR(rwsem_read_intr, &rwsem))
> + return ACQUIRE_ERR(rwsem_read_intr, &rwsem);
Local variable?
> + return sysfs_emit(buf, "%d\n", p->interleave_granularity);
> }
> @@ -2212,19 +2167,19 @@ static int attach_target(struct cxl_region *cxlr,
> struct cxl_endpoint_decoder *cxled, int pos,
> unsigned int state)
> {
> - int rc = 0;
> -
> - if (state == TASK_INTERRUPTIBLE)
> - rc = down_write_killable(&cxl_region_rwsem);
> - else
> - down_write(&cxl_region_rwsem);
> - if (rc)
> - return rc;
> + int rc;
>
> - down_read(&cxl_dpa_rwsem);
> - rc = cxl_region_attach(cxlr, cxled, pos);
> - up_read(&cxl_dpa_rwsem);
> - up_write(&cxl_region_rwsem);
> + if (state == TASK_INTERRUPTIBLE) {
> + ACQUIRE(rwsem_write_kill, rwsem)(&cxl_rwsem.region);
> + if ((rc = ACQUIRE_ERR(rwsem_write_kill, &rwsem)) == 0) {
I'd lift the warning print to a wrapper function so that you can
return early in error case and avoid this rather messy line.
e.g.
static int do_attach_target(struct cxl_region *cxlr,
struct cxl_endpoint_decoder *cxled, int pos,
unsigned int state)
if (state == TASK_INTERRUPTIBLE) {
ACQUIRE(rwsem_write_kill, rwsem)(&cxl_rwsem.region);
rc = ACQUIRE_ERR(rwsem_write_kill, &rwsem);
if (rc)
return rc;
guard(rwsem_read)(&cxl_rwsem.dpa);
return cxl_region_attach(cxlr, cxled, pos);
}
guard(rwsem_write)(&cxl_rwsem.region);
guard(rwsem_read)(&cxl_rwsem.dpa);
return cxl_region_attach(cxlr, cxled, pos);
}
static int attach_target(struct cxl_region *cxlr,
struct cxl_endpoint_decoder *cxled, int pos,
unsigned int state)
{
int rc = do_attach_target(cxlr, cxled, pos, state);
if (rc)
dev_warn();
return rc;
}
> + guard(rwsem_read)(&cxl_rwsem.dpa);
> + rc = cxl_region_attach(cxlr, cxled, pos);
> + }
> + } else {
> + guard(rwsem_write)(&cxl_rwsem.region);
> + guard(rwsem_read)(&cxl_rwsem.dpa);
> + rc = cxl_region_attach(cxlr, cxled, pos);
> + }
>
> if (rc)
> dev_warn(cxled->cxld.dev.parent,
> @@ -3569,30 +3520,23 @@ static int cxl_region_can_probe(struct cxl_region *cxlr)
> struct cxl_region_params *p = &cxlr->params;
> int rc;
>
> - rc = down_read_interruptible(&cxl_region_rwsem);
> - if (rc) {
> + ACQUIRE(rwsem_read_intr, rwsem)(&cxl_rwsem.region);
Similar to earlier - I'd do this next bit in two lines for slightly
better readability. Same for the other cases. I don't care that strongly
though.
> + if ((rc = ACQUIRE_ERR(rwsem_read_intr, &rwsem))) {
> dev_dbg(&cxlr->dev, "probe interrupted\n");
> return rc;
> }
next prev parent reply other threads:[~2025-06-23 10:32 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-19 5:04 [PATCH v2 0/8] cleanup: Introduce ACQUIRE(), a guard() for conditional locks Dan Williams
2025-06-19 5:04 ` [PATCH v2 1/8] cleanup: Introduce ACQUIRE() and ACQUIRE_ERR() " Dan Williams
2025-06-19 21:17 ` Dan Williams
2025-06-23 10:05 ` Jonathan Cameron
2025-07-10 22:46 ` dan.j.williams
2025-06-19 5:04 ` [PATCH v2 2/8] cxl/mbox: Convert poison list mutex to ACQUIRE() Dan Williams
2025-06-20 20:43 ` Alison Schofield
2025-06-23 10:08 ` Jonathan Cameron
2025-07-10 22:25 ` dan.j.williams
2025-06-23 14:49 ` Dave Jiang
2025-06-19 5:04 ` [PATCH v2 3/8] cxl/decoder: Move decoder register programming to a helper Dan Williams
2025-06-20 21:00 ` Alison Schofield
2025-06-23 10:51 ` Jonathan Cameron
2025-06-23 14:50 ` Dave Jiang
2025-06-19 5:04 ` [PATCH v2 4/8] cxl/decoder: Drop pointless locking Dan Williams
2025-06-19 23:40 ` Davidlohr Bueso
2025-06-20 21:02 ` Alison Schofield
2025-06-23 10:53 ` Jonathan Cameron
2025-06-23 14:51 ` Dave Jiang
2025-06-19 5:04 ` [PATCH v2 5/8] cxl/region: Split commit_store() into __commit() and queue_reset() helpers Dan Williams
2025-06-20 21:32 ` Alison Schofield
2025-06-21 4:51 ` dan.j.williams
2025-06-23 10:59 ` Jonathan Cameron
2025-06-23 14:59 ` Dave Jiang
2025-06-19 5:04 ` [PATCH v2 6/8] cxl/region: Move ready-to-probe state check to a helper Dan Williams
2025-06-23 15:01 ` Dave Jiang
2025-06-19 5:04 ` [PATCH v2 7/8] cxl/region: Introduce CLASS(cxl_decoder_detach...) consolidate multiple paths Dan Williams
2025-06-23 10:49 ` Jonathan Cameron
2025-07-11 4:12 ` dan.j.williams
2025-06-19 5:04 ` [PATCH v2 8/8] cxl: Convert to ACQUIRE() for conditional rwsem locking Dan Williams
2025-06-23 10:32 ` Jonathan Cameron [this message]
2025-07-11 3:21 ` dan.j.williams
2025-06-19 11:13 ` [PATCH v2 0/8] cleanup: Introduce ACQUIRE(), a guard() for conditional locks Peter Zijlstra
2025-07-02 23:39 ` Alison Schofield
2025-07-11 4:28 ` dan.j.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=20250623113208.0000768c@huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=alison.schofield@intel.com \
--cc=dan.j.williams@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=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=shiju.jose@huawei.com \
--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
all inboxes | Powered by JetHome®