Re: Lockdep circular dependency: btrfs_swap_activate() calls sysfs_notify()

Qu Wenruo <[email protected]> Mon, 3 Aug 2026 19:14:30 +0930
Newsgroups org.kernel.vger.linux-btrfs,org.kernel.vger.linux-kernel
Message-ID <[email protected]>

=E5=9C=A8 2026/8/3 18:37, Christian Borntraeger =E5=86=99=E9=81=93:
>=20
>=20
> Am 31.07.26 um 13:14 schrieb Christian Borntraeger:
>>
>>
>> Am 31.07.26 um 13:12 schrieb Qu Wenruo:
>>>
>>>
>>> =E5=9C=A8 2026/7/31 20:27, Christian Borntraeger =E5=86=99=E9=81=93:
>>>> One or more of the following files ( btrfs-swapon-kernfs-repro.sh )=
=20
>>>> violates IBM policy and all attachment(s) have been removed from the=
=20
>>>> message.
>>
>> Oh.
>>
>>
>> Lets try this:
>> #!/bin/bash
>> # Reproducer for the lockdep circular dependency
>> #
> Can you reproduce the lockdep message?
>=20

Sorry, I am on vacation since the last reply, until Wednesday.

However the script seems to have several minor problems that got=20
rejected by my VM:

- EOF not matching
   The involved python scripts expects "EOF" without any other prefix,
   but the script is using "\tEOF", which failed to end the file.

   My bash version is 5.3.3, not sure if this is version specific.

- Bad indent rejected by python3
   The python version is 3.13.7, which rejects any weird indent, so
   it fails like:

     File "<stdin>", line 1
       import mmap, os, sys
   IndentationError: unexpected indent

Even with all those minor problems fixed, it still didn't trigger on my VM=
.

I tried 128 runs, the script is triggered for a newly created btrfs in a=
=20
loop, no lockdep warning triggered, all the same successful runs:

[repro] kernel 7.2.0-rc5-custom+, lockdep active
[repro] using existing btrfs at /mnt/btrfs/
[repro] dirtying a btrfs file mapping (mmap_lock -> sb_pagefaults ->=20
i_mmap_lock)
[repro] reading sysfs directories (kernfs_rwsem -> mmap_lock)
[repro] creating swap file /mnt/btrfs//lockdep-swapfile
[repro] swapon -- this is the call that closes the cycle
[repro] swapon succeeded
[repro] no lockdep splat
[repro] PASS: the i_mmap_lock -> kernfs_rwsem edge was not taken
[repro] (expected on a kernel carrying btrfs-swapon-kernfs-fix.patch)
[repro] swapoff /mnt/btrfs//lockdep-swapfile

The kernel has LOCKDEP and DEBUG_ATOMIC_SLEEP set.

Although this is on a newer branch, based on btrfs' for-next.

Thus not sure if there is anything new, or if it's really too timing=20
specific.

You may want to send out your fix for extra reviews, other developers=20
may provide extra review on the fix.

Thanks,
Qu