2022-03-01 03:09:56

by Dan Williams

[permalink] [raw]
Subject: [PATCH 02/11] cxl/core: Refactor a cxl_lock_class() out of cxl_nested_lock()

In preparation for upleveling device_lock() lockdep annotation support into
the core, provide a helper to retrieve the lock class. This lock_class
will be used with device_set_lock_class() to idenify the CXL nested
locking rules.

Cc: Alison Schofield <[email protected]>
Cc: Vishal Verma <[email protected]>
Cc: Ira Weiny <[email protected]>
Cc: Ben Widawsky <[email protected]>
Signed-off-by: Dan Williams <[email protected]>
---
drivers/cxl/cxl.h | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
index 5486fb6aebd4..ca8a61a623b7 100644
--- a/drivers/cxl/cxl.h
+++ b/drivers/cxl/cxl.h
@@ -509,13 +509,12 @@ enum cxl_lock_class {
*/
};

-static inline void cxl_nested_lock(struct device *dev)
+static inline int cxl_lock_class(struct device *dev)
{
if (is_cxl_port(dev)) {
struct cxl_port *port = to_cxl_port(dev);

- mutex_lock_nested(&dev->lockdep_mutex,
- CXL_PORT_LOCK + port->depth);
+ return CXL_PORT_LOCK + port->depth;
} else if (is_cxl_decoder(dev)) {
struct cxl_port *port = to_cxl_port(dev->parent);

@@ -523,14 +522,18 @@ static inline void cxl_nested_lock(struct device *dev)
* A decoder is the immediate child of a port, so set
* its lock class equal to other child device siblings.
*/
- mutex_lock_nested(&dev->lockdep_mutex,
- CXL_PORT_LOCK + port->depth + 1);
+ return CXL_PORT_LOCK + port->depth + 1;
} else if (is_cxl_nvdimm_bridge(dev))
- mutex_lock_nested(&dev->lockdep_mutex, CXL_NVDIMM_BRIDGE_LOCK);
+ return CXL_NVDIMM_BRIDGE_LOCK;
else if (is_cxl_nvdimm(dev))
- mutex_lock_nested(&dev->lockdep_mutex, CXL_NVDIMM_LOCK);
+ return CXL_NVDIMM_LOCK;
else
- mutex_lock_nested(&dev->lockdep_mutex, CXL_ANON_LOCK);
+ return CXL_ANON_LOCK;
+}
+
+static inline void cxl_nested_lock(struct device *dev)
+{
+ mutex_lock_nested(&dev->lockdep_mutex, cxl_lock_class(dev));
}

static inline void cxl_nested_unlock(struct device *dev)


2022-03-09 19:18:59

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 02/11] cxl/core: Refactor a cxl_lock_class() out of cxl_nested_lock()

On Mon, 28 Feb 2022 18:49:00 -0800
Dan Williams <[email protected]> wrote:

> In preparation for upleveling device_lock() lockdep annotation support into
> the core, provide a helper to retrieve the lock class. This lock_class
> will be used with device_set_lock_class() to idenify the CXL nested

idenify?

> locking rules.
>
> Cc: Alison Schofield <[email protected]>
> Cc: Vishal Verma <[email protected]>
> Cc: Ira Weiny <[email protected]>
> Cc: Ben Widawsky <[email protected]>
> Signed-off-by: Dan Williams <[email protected]>

Otherwise looks fine to me.

Reviewed-by: Jonathan Cameron <[email protected]>

> ---
> drivers/cxl/cxl.h | 19 +++++++++++--------
> 1 file changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
> index 5486fb6aebd4..ca8a61a623b7 100644
> --- a/drivers/cxl/cxl.h
> +++ b/drivers/cxl/cxl.h
> @@ -509,13 +509,12 @@ enum cxl_lock_class {
> */
> };
>
> -static inline void cxl_nested_lock(struct device *dev)
> +static inline int cxl_lock_class(struct device *dev)
> {
> if (is_cxl_port(dev)) {
> struct cxl_port *port = to_cxl_port(dev);
>
> - mutex_lock_nested(&dev->lockdep_mutex,
> - CXL_PORT_LOCK + port->depth);
> + return CXL_PORT_LOCK + port->depth;
> } else if (is_cxl_decoder(dev)) {
> struct cxl_port *port = to_cxl_port(dev->parent);
>
> @@ -523,14 +522,18 @@ static inline void cxl_nested_lock(struct device *dev)
> * A decoder is the immediate child of a port, so set
> * its lock class equal to other child device siblings.
> */
> - mutex_lock_nested(&dev->lockdep_mutex,
> - CXL_PORT_LOCK + port->depth + 1);
> + return CXL_PORT_LOCK + port->depth + 1;
> } else if (is_cxl_nvdimm_bridge(dev))
> - mutex_lock_nested(&dev->lockdep_mutex, CXL_NVDIMM_BRIDGE_LOCK);
> + return CXL_NVDIMM_BRIDGE_LOCK;
> else if (is_cxl_nvdimm(dev))
> - mutex_lock_nested(&dev->lockdep_mutex, CXL_NVDIMM_LOCK);
> + return CXL_NVDIMM_LOCK;
> else
> - mutex_lock_nested(&dev->lockdep_mutex, CXL_ANON_LOCK);
> + return CXL_ANON_LOCK;
> +}
> +
> +static inline void cxl_nested_lock(struct device *dev)
> +{
> + mutex_lock_nested(&dev->lockdep_mutex, cxl_lock_class(dev));
> }
>
> static inline void cxl_nested_unlock(struct device *dev)
>

2022-03-09 21:42:59

by Dan Williams

[permalink] [raw]
Subject: Re: [PATCH 02/11] cxl/core: Refactor a cxl_lock_class() out of cxl_nested_lock()

On Wed, Mar 9, 2022 at 10:19 AM Jonathan Cameron
<[email protected]> wrote:
>
> On Mon, 28 Feb 2022 18:49:00 -0800
> Dan Williams <[email protected]> wrote:
>
> > In preparation for upleveling device_lock() lockdep annotation support into
> > the core, provide a helper to retrieve the lock class. This lock_class
> > will be used with device_set_lock_class() to idenify the CXL nested
>
> idenify?

Indeed.

>
> > locking rules.
> >
> > Cc: Alison Schofield <[email protected]>
> > Cc: Vishal Verma <[email protected]>
> > Cc: Ira Weiny <[email protected]>
> > Cc: Ben Widawsky <[email protected]>
> > Signed-off-by: Dan Williams <[email protected]>
>
> Otherwise looks fine to me.
>
> Reviewed-by: Jonathan Cameron <[email protected]>

Thanks!