lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6870833aa1344_588c100dd@dwillia2-xfh.jf.intel.com.notmuch>
Date: Thu, 10 Jul 2025 20:21:30 -0700
From: <dan.j.williams@...el.com>
To: Jonathan Cameron <Jonathan.Cameron@...wei.com>, Dan Williams
	<dan.j.williams@...el.com>
CC: <linux-cxl@...r.kernel.org>, <linux-kernel@...r.kernel.org>, David Lechner
	<dlechner@...libre.com>, Peter Zijlstra <peterz@...radead.org>, "Linus
 Torvalds" <torvalds@...ux-foundation.org>, Ingo Molnar <mingo@...nel.org>,
	"Fabio M. De Francesco" <fabio.maria.de.francesco@...ux.intel.com>,
	"Davidlohr Bueso" <dave@...olabs.net>, Dave Jiang <dave.jiang@...el.com>,
	"Alison Schofield" <alison.schofield@...el.com>, Vishal Verma
	<vishal.l.verma@...el.com>, Ira Weiny <ira.weiny@...el.com>, Shiju Jose
	<shiju.jose@...wei.com>
Subject: Re: [PATCH v2 8/8] cxl: Convert to ACQUIRE() for conditional rwsem
 locking

Jonathan Cameron wrote:
> On Wed, 18 Jun 2025 22:04:16 -0700
> Dan Williams <dan.j.williams@...el.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@...libre.com>
> > Cc: Peter Zijlstra <peterz@...radead.org>
> > Cc: Linus Torvalds <torvalds@...ux-foundation.org>
> > Cc: Ingo Molnar <mingo@...nel.org>
> > Cc: "Fabio M. De Francesco" <fabio.maria.de.francesco@...ux.intel.com>
> > Cc: Davidlohr Bueso <dave@...olabs.net>
> > Cc: Jonathan Cameron <jonathan.cameron@...wei.com>
> > Cc: Dave Jiang <dave.jiang@...el.com>
> > Cc: Alison Schofield <alison.schofield@...el.com>
> > Cc: Vishal Verma <vishal.l.verma@...el.com>
> > Cc: Ira Weiny <ira.weiny@...el.com>
> > Cc: Shiju Jose <shiju.jose@...wei.com>
> > Signed-off-by: Dan Williams <dan.j.williams@...el.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?

Yeah, I think this was leftover from playing with ways to make this
more compact, will switch it to:

	if ((rc = ACQUIRE_ERR(@class, @lock))
		return rc;

> 
> > +	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;
> }

Yes, I like that better.

> 
> > +			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.

I want to keep the compactness, if only in the CXL subsystem.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ