* [PATCH v2 1/4] driver core: Add conditional guard support for device_lock()
2026-03-14 7:06 [PATCH v2 0/4] cxl: Consolidate cxlmd->endpoint accessing Li Ming
@ 2026-03-14 7:06 ` Li Ming
2026-03-14 7:06 ` [PATCH v2 2/4] cxl/memdev: Hold memdev lock during memdev poison injection/clear Li Ming
` (3 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Li Ming @ 2026-03-14 7:06 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Davidlohr Bueso, Jonathan Cameron, Dave Jiang, Alison Schofield,
Vishal Verma, Ira Weiny, Dan Williams, Bjorn Helgaas,
Ben Cheatham
Cc: driver-core, linux-kernel, linux-cxl, Jonathan Cameron, Li Ming
Introduce conditional guard version of device_lock() for scenarios that
require conditional device lock holding.
Suggested-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Li Ming <ming.li@zohomail.com>
---
include/linux/device.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/linux/device.h b/include/linux/device.h
index 0be95294b6e6..4fafee80524b 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -911,6 +911,7 @@ static inline void device_unlock(struct device *dev)
}
DEFINE_GUARD(device, struct device *, device_lock(_T), device_unlock(_T))
+DEFINE_GUARD_COND(device, _intr, device_lock_interruptible(_T), _RET == 0)
static inline void device_lock_assert(struct device *dev)
{
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 2/4] cxl/memdev: Hold memdev lock during memdev poison injection/clear
2026-03-14 7:06 [PATCH v2 0/4] cxl: Consolidate cxlmd->endpoint accessing Li Ming
2026-03-14 7:06 ` [PATCH v2 1/4] driver core: Add conditional guard support for device_lock() Li Ming
@ 2026-03-14 7:06 ` Li Ming
2026-03-17 15:00 ` Dave Jiang
2026-03-14 7:06 ` [PATCH v2 3/4] cxl/pci: Hold memdev lock in cxl_event_trace_record() Li Ming
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Li Ming @ 2026-03-14 7:06 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Davidlohr Bueso, Jonathan Cameron, Dave Jiang, Alison Schofield,
Vishal Verma, Ira Weiny, Dan Williams, Bjorn Helgaas,
Ben Cheatham
Cc: driver-core, linux-kernel, linux-cxl, Jonathan Cameron, Li Ming
CXL memdev poison injection/clearing debugfs interfaces are visible
before the CXL memdev endpoint initialization, If user accesses the
interfaces before cxlmd->endpoint updated, it is possible to access an
invalid endpoint in cxl_dpa_to_region().
Hold CXL memdev lock at the beginning of the interfaces, this blocks the
interfaces until CXL memdev probing completed.
The following patch will check the given endpoint validity in
cxl_dpa_to_region().
Suggested-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Signed-off-by: Li Ming <ming.li@zohomail.com>
---
drivers/cxl/mem.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c
index fcffe24dcb42..ab88eaa31d1d 100644
--- a/drivers/cxl/mem.c
+++ b/drivers/cxl/mem.c
@@ -48,6 +48,11 @@ static int cxl_mem_dpa_show(struct seq_file *file, void *data)
static int cxl_debugfs_poison_inject(void *data, u64 dpa)
{
struct cxl_memdev *cxlmd = data;
+ int rc;
+
+ ACQUIRE(device_intr, devlock)(&cxlmd->dev);
+ if ((rc = ACQUIRE_ERR(device_intr, &devlock)))
+ return rc;
return cxl_inject_poison(cxlmd, dpa);
}
@@ -58,6 +63,11 @@ DEFINE_DEBUGFS_ATTRIBUTE(cxl_poison_inject_fops, NULL,
static int cxl_debugfs_poison_clear(void *data, u64 dpa)
{
struct cxl_memdev *cxlmd = data;
+ int rc;
+
+ ACQUIRE(device_intr, devlock)(&cxlmd->dev);
+ if ((rc = ACQUIRE_ERR(device_intr, &devlock)))
+ return rc;
return cxl_clear_poison(cxlmd, dpa);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v2 2/4] cxl/memdev: Hold memdev lock during memdev poison injection/clear
2026-03-14 7:06 ` [PATCH v2 2/4] cxl/memdev: Hold memdev lock during memdev poison injection/clear Li Ming
@ 2026-03-17 15:00 ` Dave Jiang
2026-03-18 11:59 ` Li Ming
0 siblings, 1 reply; 10+ messages in thread
From: Dave Jiang @ 2026-03-17 15:00 UTC (permalink / raw)
To: Li Ming, Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Davidlohr Bueso, Jonathan Cameron, Alison Schofield, Vishal Verma,
Ira Weiny, Dan Williams, Bjorn Helgaas, Ben Cheatham
Cc: driver-core, linux-kernel, linux-cxl
On 3/14/26 12:06 AM, Li Ming wrote:
> CXL memdev poison injection/clearing debugfs interfaces are visible
> before the CXL memdev endpoint initialization, If user accesses the
> interfaces before cxlmd->endpoint updated, it is possible to access an
> invalid endpoint in cxl_dpa_to_region().
>
> Hold CXL memdev lock at the beginning of the interfaces, this blocks the
> interfaces until CXL memdev probing completed.
>
> The following patch will check the given endpoint validity in
> cxl_dpa_to_region().
>
> Suggested-by: Dan Williams <dan.j.williams@intel.com>
> Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> Reviewed-by: Alison Schofield <alison.schofield@intel.com>
> Signed-off-by: Li Ming <ming.li@zohomail.com>
Hi Ming, I dropped this patch with Dan's comments [1] and updated cxl/next. Please check and make sure everything looks ok to you. Thanks!
[1]: https://lore.kernel.org/linux-cxl/69b8b81621e16_452b100e@dwillia2-mobl4.notmuch/
> ---
> drivers/cxl/mem.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c
> index fcffe24dcb42..ab88eaa31d1d 100644
> --- a/drivers/cxl/mem.c
> +++ b/drivers/cxl/mem.c
> @@ -48,6 +48,11 @@ static int cxl_mem_dpa_show(struct seq_file *file, void *data)
> static int cxl_debugfs_poison_inject(void *data, u64 dpa)
> {
> struct cxl_memdev *cxlmd = data;
> + int rc;
> +
> + ACQUIRE(device_intr, devlock)(&cxlmd->dev);
> + if ((rc = ACQUIRE_ERR(device_intr, &devlock)))
> + return rc;
>
> return cxl_inject_poison(cxlmd, dpa);
> }
> @@ -58,6 +63,11 @@ DEFINE_DEBUGFS_ATTRIBUTE(cxl_poison_inject_fops, NULL,
> static int cxl_debugfs_poison_clear(void *data, u64 dpa)
> {
> struct cxl_memdev *cxlmd = data;
> + int rc;
> +
> + ACQUIRE(device_intr, devlock)(&cxlmd->dev);
> + if ((rc = ACQUIRE_ERR(device_intr, &devlock)))
> + return rc;
>
> return cxl_clear_poison(cxlmd, dpa);
> }
>
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v2 2/4] cxl/memdev: Hold memdev lock during memdev poison injection/clear
2026-03-17 15:00 ` Dave Jiang
@ 2026-03-18 11:59 ` Li Ming
2026-03-18 15:36 ` Dave Jiang
0 siblings, 1 reply; 10+ messages in thread
From: Li Ming @ 2026-03-18 11:59 UTC (permalink / raw)
To: Dave Jiang, Alison Schofield, Dan Williams
Cc: driver-core, linux-kernel, linux-cxl, Greg Kroah-Hartman,
Rafael J. Wysocki, Ira Weiny, Bjorn Helgaas, Danilo Krummrich,
Davidlohr Bueso, Jonathan Cameron, Vishal Verma, Ben Cheatham
在 2026/3/17 23:00, Dave Jiang 写道:
>
> On 3/14/26 12:06 AM, Li Ming wrote:
>> CXL memdev poison injection/clearing debugfs interfaces are visible
>> before the CXL memdev endpoint initialization, If user accesses the
>> interfaces before cxlmd->endpoint updated, it is possible to access an
>> invalid endpoint in cxl_dpa_to_region().
>>
>> Hold CXL memdev lock at the beginning of the interfaces, this blocks the
>> interfaces until CXL memdev probing completed.
>>
>> The following patch will check the given endpoint validity in
>> cxl_dpa_to_region().
>>
>> Suggested-by: Dan Williams <dan.j.williams@intel.com>
>> Reviewed-by: Dave Jiang <dave.jiang@intel.com>
>> Reviewed-by: Alison Schofield <alison.schofield@intel.com>
>> Signed-off-by: Li Ming <ming.li@zohomail.com>
> Hi Ming, I dropped this patch with Dan's comments [1] and updated cxl/next. Please check and make sure everything looks ok to you. Thanks!
>
> [1]: https://lore.kernel.org/linux-cxl/69b8b81621e16_452b100e@dwillia2-mobl4.notmuch/
Hi Dave,
I think there is no change needed in this patch, just need a independent
patch for holding memdev lock in cxl_region_debugfs_poison_inject/clear.
Or you want to review this patch again?
Ming
>
>> ---
>> drivers/cxl/mem.c | 10 ++++++++++
>> 1 file changed, 10 insertions(+)
>>
>> diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c
>> index fcffe24dcb42..ab88eaa31d1d 100644
>> --- a/drivers/cxl/mem.c
>> +++ b/drivers/cxl/mem.c
>> @@ -48,6 +48,11 @@ static int cxl_mem_dpa_show(struct seq_file *file, void *data)
>> static int cxl_debugfs_poison_inject(void *data, u64 dpa)
>> {
>> struct cxl_memdev *cxlmd = data;
>> + int rc;
>> +
>> + ACQUIRE(device_intr, devlock)(&cxlmd->dev);
>> + if ((rc = ACQUIRE_ERR(device_intr, &devlock)))
>> + return rc;
>>
>> return cxl_inject_poison(cxlmd, dpa);
>> }
>> @@ -58,6 +63,11 @@ DEFINE_DEBUGFS_ATTRIBUTE(cxl_poison_inject_fops, NULL,
>> static int cxl_debugfs_poison_clear(void *data, u64 dpa)
>> {
>> struct cxl_memdev *cxlmd = data;
>> + int rc;
>> +
>> + ACQUIRE(device_intr, devlock)(&cxlmd->dev);
>> + if ((rc = ACQUIRE_ERR(device_intr, &devlock)))
>> + return rc;
>>
>> return cxl_clear_poison(cxlmd, dpa);
>> }
>>
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v2 2/4] cxl/memdev: Hold memdev lock during memdev poison injection/clear
2026-03-18 11:59 ` Li Ming
@ 2026-03-18 15:36 ` Dave Jiang
2026-03-19 11:10 ` Li Ming
0 siblings, 1 reply; 10+ messages in thread
From: Dave Jiang @ 2026-03-18 15:36 UTC (permalink / raw)
To: Li Ming, Alison Schofield, Dan Williams
Cc: driver-core, linux-kernel, linux-cxl, Greg Kroah-Hartman,
Rafael J. Wysocki, Ira Weiny, Bjorn Helgaas, Danilo Krummrich,
Davidlohr Bueso, Jonathan Cameron, Vishal Verma, Ben Cheatham
On 3/18/26 4:59 AM, Li Ming wrote:
>
> 在 2026/3/17 23:00, Dave Jiang 写道:
>>
>> On 3/14/26 12:06 AM, Li Ming wrote:
>>> CXL memdev poison injection/clearing debugfs interfaces are visible
>>> before the CXL memdev endpoint initialization, If user accesses the
>>> interfaces before cxlmd->endpoint updated, it is possible to access an
>>> invalid endpoint in cxl_dpa_to_region().
>>>
>>> Hold CXL memdev lock at the beginning of the interfaces, this blocks the
>>> interfaces until CXL memdev probing completed.
>>>
>>> The following patch will check the given endpoint validity in
>>> cxl_dpa_to_region().
>>>
>>> Suggested-by: Dan Williams <dan.j.williams@intel.com>
>>> Reviewed-by: Dave Jiang <dave.jiang@intel.com>
>>> Reviewed-by: Alison Schofield <alison.schofield@intel.com>
>>> Signed-off-by: Li Ming <ming.li@zohomail.com>
>> Hi Ming, I dropped this patch with Dan's comments [1] and updated cxl/next. Please check and make sure everything looks ok to you. Thanks!
>>
>> [1]: https://lore.kernel.org/linux-cxl/69b8b81621e16_452b100e@dwillia2-mobl4.notmuch/
>
> Hi Dave,
>
> I think there is no change needed in this patch, just need a independent patch for holding memdev lock in cxl_region_debugfs_poison_inject/clear.
>
> Or you want to review this patch again?
No. Maybe I misunderstood the comment from Dan. So we should keep this patch?
DJ
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v2 2/4] cxl/memdev: Hold memdev lock during memdev poison injection/clear
2026-03-18 15:36 ` Dave Jiang
@ 2026-03-19 11:10 ` Li Ming
0 siblings, 0 replies; 10+ messages in thread
From: Li Ming @ 2026-03-19 11:10 UTC (permalink / raw)
To: Dave Jiang, Alison Schofield, Dan Williams
Cc: driver-core, linux-kernel, linux-cxl, Greg Kroah-Hartman,
Rafael J. Wysocki, Ira Weiny, Bjorn Helgaas, Danilo Krummrich,
Davidlohr Bueso, Jonathan Cameron, Vishal Verma, Ben Cheatham
在 2026/3/18 23:36, Dave Jiang 写道:
>
> On 3/18/26 4:59 AM, Li Ming wrote:
>> 在 2026/3/17 23:00, Dave Jiang 写道:
>>> On 3/14/26 12:06 AM, Li Ming wrote:
>>>> CXL memdev poison injection/clearing debugfs interfaces are visible
>>>> before the CXL memdev endpoint initialization, If user accesses the
>>>> interfaces before cxlmd->endpoint updated, it is possible to access an
>>>> invalid endpoint in cxl_dpa_to_region().
>>>>
>>>> Hold CXL memdev lock at the beginning of the interfaces, this blocks the
>>>> interfaces until CXL memdev probing completed.
>>>>
>>>> The following patch will check the given endpoint validity in
>>>> cxl_dpa_to_region().
>>>>
>>>> Suggested-by: Dan Williams <dan.j.williams@intel.com>
>>>> Reviewed-by: Dave Jiang <dave.jiang@intel.com>
>>>> Reviewed-by: Alison Schofield <alison.schofield@intel.com>
>>>> Signed-off-by: Li Ming <ming.li@zohomail.com>
>>> Hi Ming, I dropped this patch with Dan's comments [1] and updated cxl/next. Please check and make sure everything looks ok to you. Thanks!
>>>
>>> [1]: https://lore.kernel.org/linux-cxl/69b8b81621e16_452b100e@dwillia2-mobl4.notmuch/
>> Hi Dave,
>>
>> I think there is no change needed in this patch, just need a independent patch for holding memdev lock in cxl_region_debugfs_poison_inject/clear.
>>
>> Or you want to review this patch again?
> No. Maybe I misunderstood the comment from Dan. So we should keep this patch?
>
> DJ
Yes, I think so.
Ming
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 3/4] cxl/pci: Hold memdev lock in cxl_event_trace_record()
2026-03-14 7:06 [PATCH v2 0/4] cxl: Consolidate cxlmd->endpoint accessing Li Ming
2026-03-14 7:06 ` [PATCH v2 1/4] driver core: Add conditional guard support for device_lock() Li Ming
2026-03-14 7:06 ` [PATCH v2 2/4] cxl/memdev: Hold memdev lock during memdev poison injection/clear Li Ming
@ 2026-03-14 7:06 ` Li Ming
2026-03-14 7:06 ` [PATCH v2 4/4] cxl/pci: Check memdev driver binding status in cxl_reset_done() Li Ming
2026-03-16 17:57 ` [PATCH v2 0/4] cxl: Consolidate cxlmd->endpoint accessing Dave Jiang
4 siblings, 0 replies; 10+ messages in thread
From: Li Ming @ 2026-03-14 7:06 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Davidlohr Bueso, Jonathan Cameron, Dave Jiang, Alison Schofield,
Vishal Verma, Ira Weiny, Dan Williams, Bjorn Helgaas,
Ben Cheatham
Cc: driver-core, linux-kernel, linux-cxl, Jonathan Cameron, Li Ming
cxl_event_config() invokes cxl_mem_get_event_record() to get remain
event logs from CXL device during cxl_pci_probe(). If CXL memdev probing
failed before that, it is possible to access an invalid endpoint. So
adding a cxlmd->driver binding status checking inside
cxl_dpa_to_region() to ensure the corresponding endpoint is valid.
Besides, cxl_event_trace_record() needs to hold memdev lock to invoke
cxl_dpa_to_region() to ensure the memdev probing completed. It is
possible that cxl_event_trace_record() is invoked during the CXL memdev
probing, especially user or cxl_acpi triggers CXL memdev re-probing.
Suggested-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Li Ming <ming.li@zohomail.com>
---
drivers/cxl/core/mbox.c | 5 +++--
drivers/cxl/core/region.c | 8 +++++---
drivers/cxl/cxlmem.h | 2 +-
3 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
index e7a6452bf544..3f34bbabf4d3 100644
--- a/drivers/cxl/core/mbox.c
+++ b/drivers/cxl/core/mbox.c
@@ -893,7 +893,7 @@ int cxl_enumerate_cmds(struct cxl_memdev_state *mds)
}
EXPORT_SYMBOL_NS_GPL(cxl_enumerate_cmds, "CXL");
-void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
+void cxl_event_trace_record(struct cxl_memdev *cxlmd,
enum cxl_event_log_type type,
enum cxl_event_type event_type,
const uuid_t *uuid, union cxl_event *evt)
@@ -920,6 +920,7 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
* translations. Take topology mutation locks and lookup
* { HPA, REGION } from { DPA, MEMDEV } in the event record.
*/
+ guard(device)(&cxlmd->dev);
guard(rwsem_read)(&cxl_rwsem.region);
guard(rwsem_read)(&cxl_rwsem.dpa);
@@ -968,7 +969,7 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
}
EXPORT_SYMBOL_NS_GPL(cxl_event_trace_record, "CXL");
-static void __cxl_event_trace_record(const struct cxl_memdev *cxlmd,
+static void __cxl_event_trace_record(struct cxl_memdev *cxlmd,
enum cxl_event_log_type type,
struct cxl_event_record_raw *record)
{
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index 42874948b589..840d52a52c4e 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -2950,13 +2950,15 @@ static int __cxl_dpa_to_region(struct device *dev, void *arg)
struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa)
{
struct cxl_dpa_to_region_context ctx;
- struct cxl_port *port;
+ struct cxl_port *port = cxlmd->endpoint;
+
+ if (!cxlmd->dev.driver)
+ return NULL;
ctx = (struct cxl_dpa_to_region_context) {
.dpa = dpa,
};
- port = cxlmd->endpoint;
- if (port && is_cxl_endpoint(port) && cxl_num_decoders_committed(port))
+ if (cxl_num_decoders_committed(port))
device_for_each_child(&port->dev, &ctx, __cxl_dpa_to_region);
return ctx.cxlr;
diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
index e21d744d639b..7a34a19c02c8 100644
--- a/drivers/cxl/cxlmem.h
+++ b/drivers/cxl/cxlmem.h
@@ -864,7 +864,7 @@ void set_exclusive_cxl_commands(struct cxl_memdev_state *mds,
void clear_exclusive_cxl_commands(struct cxl_memdev_state *mds,
unsigned long *cmds);
void cxl_mem_get_event_records(struct cxl_memdev_state *mds, u32 status);
-void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
+void cxl_event_trace_record(struct cxl_memdev *cxlmd,
enum cxl_event_log_type type,
enum cxl_event_type event_type,
const uuid_t *uuid, union cxl_event *evt);
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 4/4] cxl/pci: Check memdev driver binding status in cxl_reset_done()
2026-03-14 7:06 [PATCH v2 0/4] cxl: Consolidate cxlmd->endpoint accessing Li Ming
` (2 preceding siblings ...)
2026-03-14 7:06 ` [PATCH v2 3/4] cxl/pci: Hold memdev lock in cxl_event_trace_record() Li Ming
@ 2026-03-14 7:06 ` Li Ming
2026-03-16 17:57 ` [PATCH v2 0/4] cxl: Consolidate cxlmd->endpoint accessing Dave Jiang
4 siblings, 0 replies; 10+ messages in thread
From: Li Ming @ 2026-03-14 7:06 UTC (permalink / raw)
To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Davidlohr Bueso, Jonathan Cameron, Dave Jiang, Alison Schofield,
Vishal Verma, Ira Weiny, Dan Williams, Bjorn Helgaas,
Ben Cheatham
Cc: driver-core, linux-kernel, linux-cxl, Jonathan Cameron, Li Ming
cxl_reset_done() accesses the endpoint of the corresponding CXL memdev
without endpoint validity checking. By default, cxlmd->endpoint is
initialized to -ENXIO, if cxl_reset_done() is triggered after the
corresponding CXL memdev probing failed, this results in access to an
invalid endpoint.
CXL subsystem can always check CXL memdev driver binding status to
confirm its endpoint validity. So adding the CXL memdev driver checking
inside cxl_reset_done() to avoid accessing an invalid endpoint.
Fixes: 934edcd436dc ("cxl: Add post-reset warning if reset results in loss of previously committed HDM decoders")
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Li Ming <ming.li@zohomail.com>
---
drivers/cxl/pci.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c
index fbb300a01830..a5922116db2a 100644
--- a/drivers/cxl/pci.c
+++ b/drivers/cxl/pci.c
@@ -1043,6 +1043,9 @@ static void cxl_reset_done(struct pci_dev *pdev)
* that no longer exists.
*/
guard(device)(&cxlmd->dev);
+ if (!cxlmd->dev.driver)
+ return;
+
if (cxlmd->endpoint &&
cxl_endpoint_decoder_reset_detected(cxlmd->endpoint)) {
dev_crit(dev, "SBR happened without memory regions removal.\n");
--
2.43.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v2 0/4] cxl: Consolidate cxlmd->endpoint accessing
2026-03-14 7:06 [PATCH v2 0/4] cxl: Consolidate cxlmd->endpoint accessing Li Ming
` (3 preceding siblings ...)
2026-03-14 7:06 ` [PATCH v2 4/4] cxl/pci: Check memdev driver binding status in cxl_reset_done() Li Ming
@ 2026-03-16 17:57 ` Dave Jiang
4 siblings, 0 replies; 10+ messages in thread
From: Dave Jiang @ 2026-03-16 17:57 UTC (permalink / raw)
To: Li Ming, Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
Davidlohr Bueso, Jonathan Cameron, Alison Schofield, Vishal Verma,
Ira Weiny, Dan Williams, Bjorn Helgaas, Ben Cheatham
Cc: driver-core, linux-kernel, linux-cxl
On 3/14/26 12:06 AM, Li Ming wrote:
> Currently, CXL subsystem implementation has some functions that may
> access CXL memdev's endpoint before the endpoint initialization
> completed or without checking the CXL memdev endpoint validity.
> This patchset fixes three scenarios as above description.
>
> 1. cxl_dpa_to_region() is possible to access an invalid CXL memdev
> endpoint.
> there are two scenarios that can trigger this issue:
> a. memdev poison injection/clearing debugfs interfaces:
> devm_cxl_add_endpoint() is used to register CXL memdev endpoint
> and update cxlmd->endpoint from -ENXIO to the endpoint structure.
> memdev poison injection/clearing debugfs interfaces are registered
> before devm_cxl_add_endpoint() is invoked in cxl_mem_probe().
> There is a small window where user can use the debugfs interfaces
> to access an invalid endpoint.
> b. cxl_event_config() in the end of cxl_pci_probe():
> cxl_event_config() invokes cxl_mem_get_event_record() to get
> remain event logs from CXL device during cxl_pci_probe(). If CXL
> memdev probing failed before that, it is also possible to access
> an invalid endpoint.
> To fix these two cases, cxl_dpa_to_region() requires callers holding
> CXL memdev lock to access it and check if CXL memdev driver bingding
> status. Holding CXL memdev lock ensures that CXL memdev probing has
> completed, and if CXL memdev driver is bound, it will mean
> cxlmd->endpoint is valid. (PATCH #1-#3)
>
> 2. cxl_reset_done() callback in cxl_pci module.
> cxl_reset_done() callback also accesses cxlmd->endpoint without any
> checking. If CXL memdev probing fails, then cxl_reset_done() is
> called by PCI subsystem, it will access an invalid endpoint. The
> solution is adding a CXL memdev driver binding status inside
> cxl_reset_done(). (PATCH #4)
>
> ---
> Changes in v2:
> - Move hoding CXL memdev lock to cxl_debugfs_poison_inject/clear(). (Alison)
> - Drop device_lock_assert() in cxl_inject/clear_poison_locked(). (Alison)
> - Remove device_lock_assert() in cxl_dpa_to_region() to remove patch
> "cxl/region: Hold memdev lock during region poison injection/clear". (Alison)
> - Squash patch "cxl/pci: Hold memdev lock in cxl_event_trace_record()"
> and patch "cxl/region: Ensure endpoint is valid in cxl_dpa_to_region()". (Dan & Dave)
> - Remove patch "cxl/port: Reset cxlmd->endpoint to -ENXIO by default".
> - Link to v1: https://lore.kernel.org/r/20260310-fix_access_endpoint_without_drv_check-v1-0-94fe919a0b87@zohomail.com
>
> ---
> Li Ming (4):
> driver core: Add conditional guard support for device_lock()
> cxl/memdev: Hold memdev lock during memdev poison injection/clear
> cxl/pci: Hold memdev lock in cxl_event_trace_record()
> cxl/pci: Check memdev driver binding status in cxl_reset_done()
>
> drivers/cxl/core/mbox.c | 5 +++--
> drivers/cxl/core/region.c | 8 +++++---
> drivers/cxl/cxlmem.h | 2 +-
> drivers/cxl/mem.c | 10 ++++++++++
> drivers/cxl/pci.c | 3 +++
> include/linux/device.h | 1 +
> 6 files changed, 23 insertions(+), 6 deletions(-)
> ---
> base-commit: 11439c4635edd669ae435eec308f4ab8a0804808
> change-id: 20260308-fix_access_endpoint_without_drv_check-f2e6ff4bdc48
Applied to cxl/next
43e4c205197e cxl/pci: Check memdev driver binding status in cxl_reset_done()
11ce2524b7f3 cxl/pci: Hold memdev lock in cxl_event_trace_record()
b227d1faed0a cxl/memdev: Hold memdev lock during memdev poison injection/clear
e5564e392075 Merge tag 'device_lock_cond_guard-7.1-rc1' into for-7.1/cxl-consolidate-endpoint
>
> Best regards,
^ permalink raw reply [flat|nested] 10+ messages in thread