Update CONFIG_PROVE_CXL_LOCKING to use the common device-core helpers
for device_lock validation.

When CONFIG_PROVE_LOCKING is enabled, and device_set_lock_class() is
passed a non-zero lock class , the core acquires the 'struct device'
@lockdep_mutex everywhere it acquires the device_lock. Where
lockdep_mutex does not skip lockdep validation like device_lock.

cxl_set_lock_class() arranges to turn off CXL lock validation depending
on the value of CONFIG_PROVE_CXL_LOCKING, which is a Kconfig 'choice'
between the all subsystems that want to use dev->lockdep_mutex for
lockdep validation. For now, that 'choice' is just between the NVDIMM
and CXL subsystems.

Cc: Alison Schofield <alison.schofi...@intel.com>
Cc: Vishal Verma <vishal.l.ve...@intel.com>
Cc: Ira Weiny <ira.we...@intel.com>
Cc: Ben Widawsky <ben.widaw...@intel.com>
Reviewed-by: Dave Jiang <dave.ji...@intel.com>
Reviewed-by: Kevin Tian <kevin.t...@intel.com>
Signed-off-by: Dan Williams <dan.j.willi...@intel.com>
---
 drivers/cxl/core/memdev.c |    1 +
 drivers/cxl/core/pmem.c   |    2 ++
 drivers/cxl/core/port.c   |    2 ++
 drivers/cxl/cxl.h         |    9 +++++++++
 4 files changed, 14 insertions(+)

diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
index 1f76b28f9826..ad8c9f61c38a 100644
--- a/drivers/cxl/core/memdev.c
+++ b/drivers/cxl/core/memdev.c
@@ -343,6 +343,7 @@ struct cxl_memdev *devm_cxl_add_memdev(struct cxl_dev_state 
*cxlds)
        cxlmd->cxlds = cxlds;
 
        cdev = &cxlmd->cdev;
+       cxl_set_lock_class(dev);
        rc = cdev_device_add(cdev, dev);
        if (rc)
                goto err;
diff --git a/drivers/cxl/core/pmem.c b/drivers/cxl/core/pmem.c
index 60f71caa5dbd..b0eb0b795140 100644
--- a/drivers/cxl/core/pmem.c
+++ b/drivers/cxl/core/pmem.c
@@ -165,6 +165,7 @@ struct cxl_nvdimm_bridge *devm_cxl_add_nvdimm_bridge(struct 
device *host,
        if (rc)
                goto err;
 
+       cxl_set_lock_class(dev);
        rc = device_add(dev);
        if (rc)
                goto err;
@@ -261,6 +262,7 @@ int devm_cxl_add_nvdimm(struct device *host, struct 
cxl_memdev *cxlmd)
        if (rc)
                goto err;
 
+       cxl_set_lock_class(dev);
        rc = device_add(dev);
        if (rc)
                goto err;
diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
index 437e8a71e5dc..eb450397104b 100644
--- a/drivers/cxl/core/port.c
+++ b/drivers/cxl/core/port.c
@@ -469,6 +469,7 @@ struct cxl_port *devm_cxl_add_port(struct device *host, 
struct device *uport,
        if (rc)
                goto err;
 
+       cxl_set_lock_class(dev);
        rc = device_add(dev);
        if (rc)
                goto err;
@@ -1349,6 +1350,7 @@ int cxl_decoder_add_locked(struct cxl_decoder *cxld, int 
*target_map)
        if (is_root_decoder(dev))
                cxld->platform_res.name = dev_name(dev);
 
+       cxl_set_lock_class(dev);
        return device_add(dev);
 }
 EXPORT_SYMBOL_NS_GPL(cxl_decoder_add_locked, CXL);
diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h
index b86aac8cde4f..fddbcb380e84 100644
--- a/drivers/cxl/cxl.h
+++ b/drivers/cxl/cxl.h
@@ -456,5 +456,14 @@ static inline int cxl_lock_class(struct device *dev)
        else
                return CXL_ANON_LOCK;
 }
+
+static inline void cxl_set_lock_class(struct device *dev)
+{
+       device_set_lock_class(dev, cxl_lock_class(dev));
+}
+#else
+static inline void cxl_set_lock_class(struct device *dev)
+{
+}
 #endif
 #endif /* __CXL_H__ */


Reply via email to