Re: xfs : WARNING: possible circular locking dependency detected

From: Christoph Hellwig
Date: Thu Apr 18 2024 - 02:56:18 EST


Adding the KASAN maintainer so that we actuall have a chane of
fixing this instead of a rant that just gets lost on the xfs list..

On Thu, Apr 18, 2024 at 03:04:24PM +1000, Dave Chinner wrote:
> The only krealloc() in this path is:
>
> new = krealloc(ifp->if_data, new_size,
> GFP_KERNEL | __GFP_NOLOCKDEP | __GFP_NOFAIL);
>
> And it explicitly uses __GFP_NOLOCKDEP to tell lockdep not to warn
> about this allocation because of this false positive situation.
>
> Oh. I've seen this before. This is a KASAN bug, and I'm pretty sure
> I've posted a patch to fix it a fair while back that nobody seemed
> to care about enough to review or merge it.
>
> That is: kasan_save_stack() is doing a fixed GFP_KERNEL allocation
> in an context where GFP_KERNEL allocations are known to generate
> lockdep false positives. This occurs depsite the XFS and general
> memory allocation code doing exactly the right thing to avoid the
> lockdep false positives (i.e. using and obeying __GFP_NOLOCKDEP).
>
> The kasan code ends up in stack_depot_save_flags(), which does a
> GFP_KERNEL allocation but filters out __GFP_NOLOCKDEP and does not
> add it back. Hence kasan generates the false positive lockdep
> warnings, not the code doing the original allocation.
>
> kasan and/or stack_depot_save_flags() needs fixing here.
>
> -Dave.
> --
> Dave Chinner
> david@xxxxxxxxxxxxx
>
---end quoted text---