RE: [PATCH] cxl/region: Fix self-deadlock when cxl_memdev_attach_region() fails
From: 차준호
Date: Tue Nov 17 2026 - 21:37:01 EST
On Tue, Nov 17, 2026 at 03:49:39PM -0600, Cheatham, Benjamin wrote:
> On 11/16/2026 8:59 PM, Junho Cha via B4 Relay wrote:
>> The task then waits for a write lock while holding the same rwsem for
>> read, and never makes progress. Before it hangs, lockdep also reports
>> a circular dependency: endpoint_unregister_region() takes
>> cxlrd->regions_lock under cxl_rwsem.dpa, while cxl_add_to_region()
>> takes cxlrd->regions_lock before both rwsems.
>
> I don't think the lockdep dependency is related to this, it's in a completely
> different code path. That said, it may be fixable by converting the guard() on
> the cxlrd->regions_lock in cxl_add_to_region() to a scoped_guard().
Hi Ben,
Thanks for the review.
The report does come from this failure path. The new dependency is
endpoint_unregister_region() taking regions_lock while
cxl_memdev_attach_region() still holds both rwsems:
-> #0 (&cxlrd->regions_lock){+.+.}-{4:4}:
endpoint_unregister_region+0x2a/0x60 [cxl_core]
cxl_memdev_attach_region+0x1ca/0x200 [cxl_core]
It goes away with the fix, and changing cxl_add_to_region() would not
fix the hang itself. I'll make that clearer in the changelog.
> I think this could cause an issue if you have multiple type 2 cards in the same region. Imagine this scenario:
[...]
> 3. The second card then successfully adds the action and passes back an HPA range attached to a dead region
Two cards can't share the region here, since nr_targets > 1 is
rejected. But the window is real with one card: with a delay added
before the registration, writing to region0/target0 detached the
target before the action was registered, and the attach still
returned the region's range.
> Maybe you can get past this by keeping just the cxl_rwsem.dpa lock through the end of the function? I don't
> know if that's too hacky, but I don't recall seeing the dpa lock taken by anything after endpoint_unregister_region()
> gets called so it may work.
Detaching a target doesn't take cxl_rwsem.dpa, so that wouldn't close
the window, and the unwind would again take regions_lock under it.
In v2 I'll register the action under both rwsems as before, with
devm_add_action(), and run the unwind only after dropping them.
Thanks,
Junho