Re: [PATCH] cxl/region: Fix self-deadlock when cxl_memdev_attach_region() fails

From: Cheatham, Benjamin

Date: Wed Nov 18 2026 - 12:43:47 EST


On 11/17/2026 8:36 PM, 차준호 wrote:
> [You don't often get email from junho.cha@xxxxxxxxx. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> 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.
>

Sorry I should've been clearer, I meant the circular dependency isn't related
to the hang.

I think I just missed the part at the end of the commit message where you mention the
lockdep warning goes away. That was reader error and looking at it again it's pretty clear.
If you feel the need to do something go ahead, but it's probably fine as-is.

>> 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.
>

I forgot about that restriction, good to see you can still hit that though!

>> 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.
>

Good point, I was thinking about preventing two concurrent type 2 devices racing but that's
not applicable here. Makes sense that it wouldn't work in the case you have above.

Thanks,
Ben

> In v2 I'll register the action under both rwsems as before, with
> devm_add_action(), and run the unwind only after dropping them.
>