public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Yafang Shao <laoar.shao@gmail.com>
Cc: chandan.babu@oracle.com, djwong@kernel.org, linux-xfs@vger.kernel.org
Subject: Re: [PATCH] xfs: Fix circular locking during xfs inode reclamation
Date: Tue, 1 Oct 2024 08:53:35 +1000	[thread overview]
Message-ID: <Zvsr76vifZeNDArE@dread.disaster.area> (raw)
In-Reply-To: <20240930034406.7600-1-laoar.shao@gmail.com>

On Mon, Sep 30, 2024 at 11:44:06AM +0800, Yafang Shao wrote:
> I encountered the following error messages on our test servers:
> 
> [ 2553.303035] ======================================================
> [ 2553.303692] WARNING: possible circular locking dependency detected
> [ 2553.304363] 6.11.0+ #27 Not tainted
> [ 2553.304732] ------------------------------------------------------
> [ 2553.305398] python/129251 is trying to acquire lock:
> [ 2553.305940] ffff89b18582e318 (&xfs_nondir_ilock_class){++++}-{3:3}, at: xfs_ilock+0x70/0x190 [xfs]
> [ 2553.307066]
> but task is already holding lock:
> [ 2553.307682] ffffffffb4324de0 (fs_reclaim){+.+.}-{0:0}, at: __alloc_pages_slowpath.constprop.0+0x368/0xb10
> [ 2553.308670]
> which lock already depends on the new lock.

.....

> [ 2553.342664]  Possible unsafe locking scenario:
> 
> [ 2553.343621]        CPU0                    CPU1
> [ 2553.344300]        ----                    ----
> [ 2553.344957]   lock(fs_reclaim);
> [ 2553.345510]                                lock(&xfs_nondir_ilock_class);
> [ 2553.346326]                                lock(fs_reclaim);
> [ 2553.347015]   rlock(&xfs_nondir_ilock_class);
> [ 2553.347639]
>  *** DEADLOCK ***
> 
> The deadlock is as follows,
> 
>     CPU0                                  CPU1
>    ------                                ------
> 
>   alloc_anon_folio()
>     vma_alloc_folio(__GFP_FS)
>      fs_reclaim_acquire(__GFP_FS);
>        __fs_reclaim_acquire();
> 
>                                     xfs_attr_list()
>                                       xfs_ilock()
>                                       kmalloc(__GFP_FS);
>                                         __fs_reclaim_acquire();
> 
>        xfs_ilock

Yet another lockdep false positive. listxattr() is not in a
transaction context on a referenced inode, so GFP_KERNEL is correct.
The problem is lockdep has no clue that fs_reclaim context can only
lock unreferenced inodes, so we can actualy run GFP_KERNEL context
memory allocation with a locked, referenced inode safely.

We typically use __GFP_NOLOCKDEP on these sorts of allocations, but
the long term fix is to address the lockdep annotations to take
reclaim context into account. We can't do that until the realtime
inode subclasses are removed which will give use the spare lockdep
subclasses to add a reclaim context subclass. That is buried in the
middle of a much large rework:

https://lore.kernel.org/linux-xfs/172437087542.59588.13853236455832390956.stgit@frogsfrogsfrogs/

-Dave.


-- 
Dave Chinner
david@fromorbit.com

  reply	other threads:[~2024-09-30 22:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-30  3:44 [PATCH] xfs: Fix circular locking during xfs inode reclamation Yafang Shao
2024-09-30 22:53 ` Dave Chinner [this message]
2024-10-05  6:24   ` Yafang Shao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Zvsr76vifZeNDArE@dread.disaster.area \
    --to=david@fromorbit.com \
    --cc=chandan.babu@oracle.com \
    --cc=djwong@kernel.org \
    --cc=laoar.shao@gmail.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox