cxl/pci: Skip reset detection for DVSEC emulated decoders
PATCH v4 1/1 cxl/pci: Skip reset detection for DVSEC emulated decoders
After an FLR or SBR, __cxl_endpoint_decoder_reset_detected() samples the Committed bit at cxlhdm->regs.hdm_decoder for every decoder that has CXL_DECODER_F_ENABLE set. Decoders emulated from the CXL DVSEC range registers carry that flag too, but their state does not live in the HDM decoder registers. When the component registers expose no HDM decoder capability, regs.hdm_decoder is NULL and the readl() oopses in the reset completion path. When the capability is present but firmware left Mem_Enable set with the global HDM decoder enable clear, the Committed bit reads zero and cxl_reset_done() reports a reset that never happened: it taints the kernel and strips CXL_DECODER_F_ENABLE and CXL_DECODER_F_LOCK from every endpoint decoder, even though the driver still cannot reprogram the DVSEC ranges.
Skip the check when cxld->commit is NULL. Only cxl_setup_hdm_decoder_from_dvsec() leaves that callback unset, so that one test covers both emulation paths, and a DVSEC-described range has no Committed bit for a reset to clear.
---
This was patch 4/8 of the "cxl: Assorted fixes" series [1], resent individually per review feedback.
The two synchronisation concerns the review bot raised on v2 - the missing exclusion against a cxl_port unbind freeing the devm allocated cxl_hdm, and the plain read-modify-write of cxld->flags in cxl_endpoint_decoder_clear_reset_flags() while the region paths update the same word under cxl_rwsem.region - are still untouched here. Both are about the reset handler's locking rather than about which registers it reads, and neither fix is local; happy to follow up with separate patches.
v1->v2:
- rebase onto cxl/next
- rewrite the commit message to describe the behaviour rather than narrate the code change (Alison Schofield)
v2->v3:
- test cxld->commit instead of cxlhdm->regs.hdm_decoder, so that decoders emulated from the DVSEC ranges are also skipped when the HDM decoder registers exist but are globally disabled (Richard Cheng)
- update the subject and the commit message for the widened scope
v3->v4:
- shorten the commit message (Dave Jiang)
[1] https://lore.kernel.org/linux-cxl/[email protected]/
drivers/cxl/core/pci.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/cxl/core/pci.c +7 -0
@@ -683,6 +683,13 @@ static int __cxl_endpoint_decoder_reset_detected(struct device *dev, void *data)if ((cxld->flags &CXL_DECODER_F_ENABLE ) ==0 )return 0 ; +/* +* Decoders emulated from the DVSEC range registers have no commit +* callback and no HDM decoder registers to consult. +*/ +if (!cxld->commit) +return 0 ; + cxlhdm =dev_get_drvdata (&port->dev); hdm = cxlhdm->regs.hdm_decoder; ctrl =readl (hdm +CXL_HDM_DECODER0_CTRL_OFFSET (cxld->id));
base-commit: 7098e9cd98a05c0c5de2fae0c2465f9d966fdd07
Signature · 1 line
2.43.7
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing exclusion against cxl_port unbind in __cxl_endpoint_decoder_reset_detected() can lead to a Use-After-Free or NULL pointer dereference of cxlhdm.
- [High] Unsynchronized read-modify-write of cxld->flags in cxl_endpoint_decoder_clear_reset_flags() races with concurrent updates.
--
--- Patch [1]: [PATCH v4] cxl/pci: Skip reset detection for DVSEC emulated decoders --- commit b6f7c04ddbcccfb809033bdab75f996fc7c78db7
Author: Guixin Liu <[email protected]>
cxl/pci: Skip reset detection for DVSEC emulated decoders
This commit skips the reset detection check for decoders emulated from the CXL DVSEC range registers, as they lack HDM decoder registers and commit callbacks. This prevents a kernel oops when checking for a reset on these emulated decoders.
Quoted 5 lines
drivers/cxl/core/pci.c +0
-0@@ -683,6 +683,13 @@ static int __cxl_endpoint_decoder_reset_detected(struct device *dev, void *data)
[ ... ]
drivers/cxl/core/pci.c static int __cxl_endpoint_decoder_reset_detected(struct device *dev, void *data) · line 694
Quoted 9 lines
drivers/cxl/core/pci.c +7
-0+/* +* Decoders emulated from the DVSEC range registers have no commit +* callback and no HDM decoder registers to consult. +*/ +if (!cxld->commit) +return 0 ; + cxlhdm =dev_get_drvdata (&port->dev); hdm = cxlhdm->regs.hdm_decoder;
[Severity: High]
This is a pre-existing issue, but could this missing exclusion against a cxl_port unbind lead to a Use-After-Free or NULL pointer dereference of cxlhdm?
If a concurrent sysfs unbind of the cxl_port driver occurs while a PCI reset handler iterates over the endpoint's children in cxl_reset_done(), the devm-allocated memory for cxlhdm could be freed and driver data cleared before it is accessed here.
drivers/cxl/core/pci.c
Quoted 4 lines
drivers/cxl/core/pci.c +0
-0ctrl =readl (hdm +CXL_HDM_DECODER0_CTRL_OFFSET (cxld->id));return !FIELD_GET (CXL_HDM_DECODER0_CTRL_COMMITTED , ctrl); }
For the pre-existing read-modify-write synchronization issue in cxl_endpoint_decoder_clear_reset_flags():
drivers/cxl/pci.c:cxl_endpoint_decoder_clear_reset_flags() {
...
cxled = to_cxl_endpoint_decoder(dev);
cxled->cxld.flags &= ~CXL_DECODER_F_RESET_MASK;
...
}[Severity: High]
This is a pre-existing issue, but does this function have an unsynchronized read-modify-write of cxld->flags?
If a concurrent region setup or teardown operation occurs simultaneously with a PCI reset, the plain bitwise update on cxld->flags in the asynchronous PCI reset path ignores the cxl_rwsem.region semaphore used by region paths.
Could this race with concurrent updates and lead to state corruption due to lost flag updates, potentially leaving decoders in an invalid state?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Jonathan Cameron
maintainerQuoted 13 lines · On Fri, 21 Aug 2026 10:10:29 +0800 Guixin Liu <[email protected]> wrote:
After an FLR or SBR,
__cxl_endpoint_decoder_reset_detected()samples the Committed bit atcxlhdm->regs.hdm_decoderfor every decoder that hasCXL_DECODER_F_ENABLEset. Decoders emulated from the CXL DVSEC range registers carry that flag too, but their state does not live in the HDM decoder registers. When the component registers expose no HDM decoder capability, regs.hdm_decoder is NULL and thereadl()oopses in the reset completion path. When the capability is present but firmware leftMem_Enableset with the global HDM decoder enable clear, the Committed bit reads zero andcxl_reset_done()reports a reset that never happened: it taints the kernel and stripsCXL_DECODER_F_ENABLEandCXL_DECODER_F_LOCKfrom every endpoint decoder, even though the driver still cannot reprogram the DVSEC ranges.
Quoted 5 lines
Skip the check when
cxld->commitis NULL. Onlycxl_setup_hdm_decoder_from_dvsec()leaves that callback unset, so that one test covers both emulation paths, and a DVSEC-described range has no Committed bit for a reset to clear.
This is still a lot of text to read - I'll have stab an what I think would be sufficient. Take this perhaps as inspiration, not a precise suggestion!
When HDM decoders are emulated from DVSEC range registers either (a) there are no HDM decoder registers present or (b) the DVSEC registers were in use at driver load.
After FLR or SBR, __cxl_endpoint_decoder_reset_detected() checks the HDM decoder committed bit for any previously committed decoders. This includes emulated decoders: (a) results in a NULL pointer dereference, (b) in a false detection of reset when they are present and not in use as the committed bit was never set.
Use absence of cxld->commit to elide the reset check for emulated decoders.
Quoted 2 lines
Fixes 934edcd436dc ("cxl: Add post-reset warning if reset results in loss of previously committed HDM decoders")Signed-off-by Guixin Liu <[email protected]>
This does make me wonder if we should be doing something similar to check the dvsec based decoding reset. The memory_base_high should reset to 0 for example.
Can we actually do anything with such devices? Not sure we can today. That is not a reason to crash however so this fix still makes sense.
Jonathan
Quoted 52 lines
---
This was patch 4/8 of the "cxl: Assorted fixes" series [1], resent individually per review feedback.The two synchronisation concerns the review bot raised on v2 - the missing exclusion against a
cxl_portunbind freeing the devm allocatedcxl_hdm, and the plain read-modify-write ofcxld->flagsincxl_endpoint_decoder_clear_reset_flags()while the region paths update the same word under cxl_rwsem.region - are still untouched here. Both are about the reset handler's locking rather than about which registers it reads, and neither fix is local; happy to follow up with separate patches.
v1->v2:
- rebase onto cxl/next
- rewrite the commit message to describe the behaviour rather than narrate the code change (Alison Schofield)
v2->v3:
- testcxld->commitinstead ofcxlhdm->regs.hdm_decoder, so that decoders emulated from the DVSEC ranges are also skipped when the HDM decoder registers exist but are globally disabled (Richard Cheng)
- update the subject and the commit message for the widened scope
v3->v4:
- shorten the commit message (Dave Jiang)[1] https://lore.kernel.org/linux-cxl/[email protected]/
drivers/cxl/core/pci.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/cxl/core/pci.c +7
-0@@ -683,6 +683,13 @@ static int __cxl_endpoint_decoder_reset_detected(struct device *dev, void *data)if ((cxld->flags &CXL_DECODER_F_ENABLE ) ==0 )return 0 ; +/* +* Decoders emulated from the DVSEC range registers have no commit +* callback and no HDM decoder registers to consult. +*/ +if (!cxld->commit) +return 0 ; + cxlhdm =dev_get_drvdata (&port->dev); hdm = cxlhdm->regs.hdm_decoder; ctrl =readl (hdm +CXL_HDM_DECODER0_CTRL_OFFSET (cxld->id));base-commit:
7098e9cd98a05c0c5de2fae0c2465f9d966fdd07
Quoted 16 lines · On Fri, 21 Aug 2026 23:33:05 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 13 lines · On Fri, 21 Aug 2026 10:10:29 +0800 Guixin Liu <[email protected]> wrote:
After an FLR or SBR,
__cxl_endpoint_decoder_reset_detected()samples the Committed bit atcxlhdm->regs.hdm_decoderfor every decoder that hasCXL_DECODER_F_ENABLEset. Decoders emulated from the CXL DVSEC range registers carry that flag too, but their state does not live in the HDM decoder registers. When the component registers expose no HDM decoder capability, regs.hdm_decoder is NULL and thereadl()oopses in the reset completion path. When the capability is present but firmware leftMem_Enableset with the global HDM decoder enable clear, the Committed bit reads zero andcxl_reset_done()reports a reset that never happened: it taints the kernel and stripsCXL_DECODER_F_ENABLEandCXL_DECODER_F_LOCKfrom every endpoint decoder, even though the driver still cannot reprogram the DVSEC ranges.
Quoted 7 lines
Quoted 5 lines
Skip the check when
cxld->commitis NULL. Onlycxl_setup_hdm_decoder_from_dvsec()leaves that callback unset, so that one test covers both emulation paths, and a DVSEC-described range has no Committed bit for a reset to clear.This is still a lot of text to read - I'll have stab an what I think would be sufficient. Take this perhaps as inspiration, not a precise suggestion!
Ah I see this was the cut down text Dave suggested. That's fine (though I think he could have gone further!)
I think it is still worth thinking about the question on what it means to try and recover below. Though looking at how this is used, it is just to complain that something crazy happened - so maybe none of this matters!
Jonathan
Quoted 79 lines
When HDM decoders are emulated from DVSEC range registers either (a) there are no HDM decoder registers present or (b) the DVSEC registers were in use at driver load.
After FLR or SBR,
__cxl_endpoint_decoder_reset_detected()checks the HDM decoder committed bit for any previously committed decoders. This includes emulated decoders: (a) results in a NULL pointer dereference, (b) in a false detection of reset when they are present and not in use as the committed bit was never set.Use absence of
cxld->committo elide the reset check for emulated decoders.Quoted 2 lines
Fixes 934edcd436dc ("cxl: Add post-reset warning if reset results in loss of previously committed HDM decoders")Signed-off-by Guixin Liu <[email protected]>This does make me wonder if we should be doing something similar to check the dvsec based decoding reset. The
memory_base_highshould reset to 0 for example.Can we actually do anything with such devices? Not sure we can today. That is not a reason to crash however so this fix still makes sense.
Jonathan
Quoted 52 lines
---
This was patch 4/8 of the "cxl: Assorted fixes" series [1], resent individually per review feedback.The two synchronisation concerns the review bot raised on v2 - the missing exclusion against a
cxl_portunbind freeing the devm allocatedcxl_hdm, and the plain read-modify-write ofcxld->flagsincxl_endpoint_decoder_clear_reset_flags()while the region paths update the same word under cxl_rwsem.region - are still untouched here. Both are about the reset handler's locking rather than about which registers it reads, and neither fix is local; happy to follow up with separate patches.
v1->v2:
- rebase onto cxl/next
- rewrite the commit message to describe the behaviour rather than narrate the code change (Alison Schofield)
v2->v3:
- testcxld->commitinstead ofcxlhdm->regs.hdm_decoder, so that decoders emulated from the DVSEC ranges are also skipped when the HDM decoder registers exist but are globally disabled (Richard Cheng)
- update the subject and the commit message for the widened scope
v3->v4:
- shorten the commit message (Dave Jiang)[1] https://lore.kernel.org/linux-cxl/[email protected]/
drivers/cxl/core/pci.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/cxl/core/pci.c +7
-0@@ -683,6 +683,13 @@ static int __cxl_endpoint_decoder_reset_detected(struct device *dev, void *data)if ((cxld->flags &CXL_DECODER_F_ENABLE ) ==0 )return 0 ; +/* +* Decoders emulated from the DVSEC range registers have no commit +* callback and no HDM decoder registers to consult. +*/ +if (!cxld->commit) +return 0 ; + cxlhdm =dev_get_drvdata (&port->dev); hdm = cxlhdm->regs.hdm_decoder; ctrl =readl (hdm +CXL_HDM_DECODER0_CTRL_OFFSET (cxld->id));base-commit:
7098e9cd98a05c0c5de2fae0c2465f9d966fdd07
Dave Jiang
maintainerQuoted 24 lines · Jonathan Cameron
Quoted 21 lines · On Fri, 21 Aug 2026 23:33:05 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 18 lines · On Fri, 21 Aug 2026 10:10:29 +0800 Guixin Liu <[email protected]> wrote:
After an FLR or SBR,
__cxl_endpoint_decoder_reset_detected()samples the Committed bit atcxlhdm->regs.hdm_decoderfor every decoder that hasCXL_DECODER_F_ENABLEset. Decoders emulated from the CXL DVSEC range registers carry that flag too, but their state does not live in the HDM decoder registers. When the component registers expose no HDM decoder capability, regs.hdm_decoder is NULL and thereadl()oopses in the reset completion path. When the capability is present but firmware leftMem_Enableset with the global HDM decoder enable clear, the Committed bit reads zero andcxl_reset_done()reports a reset that never happened: it taints the kernel and stripsCXL_DECODER_F_ENABLEandCXL_DECODER_F_LOCKfrom every endpoint decoder, even though the driver still cannot reprogram the DVSEC ranges.Skip the check when
cxld->commitis NULL. Onlycxl_setup_hdm_decoder_from_dvsec()leaves that callback unset, so that one test covers both emulation paths, and a DVSEC-described range has no Committed bit for a reset to clear.
Quoted 4 lines
Quoted 2 lines
This is still a lot of text to read - I'll have stab an what I think would be sufficient. Take this perhaps as inspiration, not a precise suggestion!
Ah I see this was the cut down text Dave suggested. That's fine (though I think he could have gone further!)
I have no issues if you are able to condense it further. :)
DJ
Quoted 91 lines
Reviewed-by Jonathan Cameron <[email protected]>I think it is still worth thinking about the question on what it means to try and recover below. Though looking at how this is used, it is just to complain that something crazy happened - so maybe none of this matters!
Jonathan
Quoted 79 lines
When HDM decoders are emulated from DVSEC range registers either (a) there are no HDM decoder registers present or (b) the DVSEC registers were in use at driver load.
After FLR or SBR,
__cxl_endpoint_decoder_reset_detected()checks the HDM decoder committed bit for any previously committed decoders. This includes emulated decoders: (a) results in a NULL pointer dereference, (b) in a false detection of reset when they are present and not in use as the committed bit was never set.Use absence of
cxld->committo elide the reset check for emulated decoders.Quoted 2 lines
Fixes 934edcd436dc ("cxl: Add post-reset warning if reset results in loss of previously committed HDM decoders")Signed-off-by Guixin Liu <[email protected]>This does make me wonder if we should be doing something similar to check the dvsec based decoding reset. The
memory_base_highshould reset to 0 for example.Can we actually do anything with such devices? Not sure we can today. That is not a reason to crash however so this fix still makes sense.
Jonathan
Quoted 52 lines
---
This was patch 4/8 of the "cxl: Assorted fixes" series [1], resent individually per review feedback.The two synchronisation concerns the review bot raised on v2 - the missing exclusion against a
cxl_portunbind freeing the devm allocatedcxl_hdm, and the plain read-modify-write ofcxld->flagsincxl_endpoint_decoder_clear_reset_flags()while the region paths update the same word under cxl_rwsem.region - are still untouched here. Both are about the reset handler's locking rather than about which registers it reads, and neither fix is local; happy to follow up with separate patches.
v1->v2:
- rebase onto cxl/next
- rewrite the commit message to describe the behaviour rather than narrate the code change (Alison Schofield)
v2->v3:
- testcxld->commitinstead ofcxlhdm->regs.hdm_decoder, so that decoders emulated from the DVSEC ranges are also skipped when the HDM decoder registers exist but are globally disabled (Richard Cheng)
- update the subject and the commit message for the widened scope
v3->v4:
- shorten the commit message (Dave Jiang)[1] https://lore.kernel.org/linux-cxl/[email protected]/
drivers/cxl/core/pci.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/cxl/core/pci.c +7
-0@@ -683,6 +683,13 @@ static int __cxl_endpoint_decoder_reset_detected(struct device *dev, void *data)if ((cxld->flags &CXL_DECODER_F_ENABLE ) ==0 )return 0 ; +/* +* Decoders emulated from the DVSEC range registers have no commit +* callback and no HDM decoder registers to consult. +*/ +if (!cxld->commit) +return 0 ; + cxlhdm =dev_get_drvdata (&port->dev); hdm = cxlhdm->regs.hdm_decoder; ctrl =readl (hdm +CXL_HDM_DECODER0_CTRL_OFFSET (cxld->id));base-commit:
7098e9cd98a05c0c5de2fae0c2465f9d966fdd07
Quoted 26 lines · Dave Jiang
Quoted 24 lines · Jonathan Cameron
Quoted 21 lines · On Fri, 21 Aug 2026 23:33:05 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 18 lines · On Fri, 21 Aug 2026 10:10:29 +0800 Guixin Liu <[email protected]> wrote:
After an FLR or SBR,
__cxl_endpoint_decoder_reset_detected()samples the Committed bit atcxlhdm->regs.hdm_decoderfor every decoder that hasCXL_DECODER_F_ENABLEset. Decoders emulated from the CXL DVSEC range registers carry that flag too, but their state does not live in the HDM decoder registers. When the component registers expose no HDM decoder capability, regs.hdm_decoder is NULL and thereadl()oopses in the reset completion path. When the capability is present but firmware leftMem_Enableset with the global HDM decoder enable clear, the Committed bit reads zero andcxl_reset_done()reports a reset that never happened: it taints the kernel and stripsCXL_DECODER_F_ENABLEandCXL_DECODER_F_LOCKfrom every endpoint decoder, even though the driver still cannot reprogram the DVSEC ranges.Skip the check when
cxld->commitis NULL. Onlycxl_setup_hdm_decoder_from_dvsec()leaves that callback unset, so that one test covers both emulation paths, and a DVSEC-described range has no Committed bit for a reset to clear.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
This is still a lot of text to read - I'll have stab an what I think would be sufficient. Take this perhaps as inspiration, not a precise suggestion!
Ah I see this was the cut down text Dave suggested. That's fine (though I think he could have gone further!)
I have no issues if you are able to condense it further. :)
DJ
Hi Jonathan, Hi Dave, I condense the commit body in v5, thanks. Best Regards, Guixin Liu
Quoted 86 lines
Quoted 86 lines
Reviewed-by Jonathan Cameron <[email protected]>I think it is still worth thinking about the question on what it means to try and recover below. Though looking at how this is used, it is just to complain that something crazy happened - so maybe none of this matters!
Jonathan
Quoted 75 lines
When HDM decoders are emulated from DVSEC range registers either (a) there are no HDM decoder registers present or (b) the DVSEC registers were in use at driver load.
After FLR or SBR,
__cxl_endpoint_decoder_reset_detected()checks the HDM decoder committed bit for any previously committed decoders. This includes emulated decoders: (a) results in a NULL pointer dereference, (b) in a false detection of reset when they are present and not in use as the committed bit was never set.Use absence of
cxld->committo elide the reset check for emulated decoders.Quoted 2 lines
Fixes 934edcd436dc ("cxl: Add post-reset warning if reset results in loss of previously committed HDM decoders")Signed-off-by Guixin Liu <[email protected]>This does make me wonder if we should be doing something similar to check the dvsec based decoding reset. The
memory_base_highshould reset to 0 for example.Can we actually do anything with such devices? Not sure we can today. That is not a reason to crash however so this fix still makes sense.
Jonathan
Quoted 51 lines
---
This was patch 4/8 of the "cxl: Assorted fixes" series [1], resent individually per review feedback.The two synchronisation concerns the review bot raised on v2 - the missing exclusion against a
cxl_portunbind freeing the devm allocatedcxl_hdm, and the plain read-modify-write ofcxld->flagsincxl_endpoint_decoder_clear_reset_flags()while the region paths update the same word under cxl_rwsem.region - are still untouched here. Both are about the reset handler's locking rather than about which registers it reads, and neither fix is local; happy to follow up with separate patches.
v1->v2:
- rebase onto cxl/next
- rewrite the commit message to describe the behaviour rather than narrate the code change (Alison Schofield)
v2->v3:
- testcxld->commitinstead ofcxlhdm->regs.hdm_decoder, so that decoders emulated from the DVSEC ranges are also skipped when the HDM decoder registers exist but are globally disabled (Richard Cheng)
- update the subject and the commit message for the widened scope
v3->v4:
- shorten the commit message (Dave Jiang)[1] https://lore.kernel.org/linux-cxl/[email protected]/
drivers/cxl/core/pci.c | 7 +++++++ 1 file changed, 7 insertions(+)drivers/cxl/core/pci.c +7
-0@@ -683,6 +683,13 @@ static int __cxl_endpoint_decoder_reset_detected(struct device *dev, void *data)if ((cxld->flags &CXL_DECODER_F_ENABLE ) ==0 )return 0 ; +/* +* Decoders emulated from the DVSEC range registers have no commit +* callback and no HDM decoder registers to consult. +*/ +if (!cxld->commit) +return 0 ; + cxlhdm =dev_get_drvdata (&port->dev); hdm = cxlhdm->regs.hdm_decoder; ctrl =readl (hdm +CXL_HDM_DECODER0_CTRL_OFFSET (cxld->id));base-commit:
7098e9cd98a05c0c5de2fae0c2465f9d966fdd07