Re: [PATCH] ocfs2: cluster: don't sleep while holding o2hb_live_lock in o2hb_region_pin()

Joseph Qi <[email protected]> Wed, 22 Jul 2026 10:29:53 +0800
Newsgroups dev.linux.lists.ocfs2-devel,org.kernel.vger.linux-kernel
Message-ID <[email protected]>

On 7/22/26 1:56 AM, Andrew Morton wrote:
> On Tue, 21 Jul 2026 19:49:16 +0800 Joseph Qi <[email protected]> wrote:
> 
>> o2hb_region_pin() is always called with the o2hb_live_lock spinlock held
>> (from o2hb_region_inc_user() and o2hb_heartbeat_group_drop_item()), but it
>> calls o2nm_depend_item() -> configfs_depend_item(), which sleeps: it pins
>> the configfs filesystem and takes the configfs root inode rwsem. Under
>> CONFIG_DEBUG_ATOMIC_SLEEP this triggers:
>>
>>   BUG: sleeping function called from invalid context at kernel/locking/rwsem.c
>>   in_atomic(): 1, ... name: mount.ocfs2
>>     down_write
>>     configfs_depend_item
>>     o2hb_region_pin
>>     o2hb_region_inc_user
>>     o2hb_register_callback
>>     dlm_register_domain_handlers
>>     ...
>>     ocfs2_dlm_init
>>     ocfs2_mount_volume
>>     ocfs2_fill_super
>>
>> Rework o2hb_region_pin() to pin one region at a time with the lock
>> dropped across the sleeping call: under o2hb_live_lock find the next
>> eligible region and take a config_item reference to keep it alive, drop
>> the lock, call o2nm_depend_item(), then retake the lock and record the
>> pin. The config_item_put() is done with the lock released as well, since
>> o2hb_region_release() also acquires o2hb_live_lock and can sleep. The
>> region list may change while unlocked, so the scan restarts from the
>> top after each pin. Local heartbeat still pins only the matching region;
>> global heartbeat pins all eligible regions.
> 
> Thanks, I'll add cc:stable to this.
> 
> Sashiko might have a found a couple of pre-existing issues in there:
> 
> https://sashiko.dev/#/patchset/[email protected]

Thanks, the two comments seems real pre-existing issues.
I'll look into them later.

Thanks,
Joseph