linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yosry Ahmed <yosryahmed@google.com>
To: Barry Song <baohua@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Johannes Weiner <hannes@cmpxchg.org>,
	 Nhat Pham <nphamcs@gmail.com>,
	Chengming Zhou <chengming.zhou@linux.dev>,
	 Vitaly Wool <vitalywool@gmail.com>,
	Sam Sun <samsun1006219@gmail.com>,
	 Kanchana P Sridhar <kanchana.p.sridhar@intel.com>,
	linux-mm@kvack.org,  linux-kernel@vger.kernel.org,
	syzbot <syzkaller@googlegroups.com>
Subject: Re: [PATCH v2 1/2] Revert "mm: zswap: fix race between [de]compression and CPU hotunplug"
Date: Tue, 7 Jan 2025 16:54:02 -0800	[thread overview]
Message-ID: <CAJD7tkY=ztvdozH-yC55YFM4NvCUa77bH42ZYu_ewJYCff0TKw@mail.gmail.com> (raw)
In-Reply-To: <CAGsJ_4xhXtoDRW0W4uKTPU61yTBB-EEdRdvg-ENp_tg+GYu8BQ@mail.gmail.com>

On Tue, Jan 7, 2025 at 4:34 PM Barry Song <baohua@kernel.org> wrote:
>
> On Wed, Jan 8, 2025 at 12:39 PM Yosry Ahmed <yosryahmed@google.com> wrote:
> >
> > On Tue, Jan 7, 2025 at 3:01 PM Barry Song <baohua@kernel.org> wrote:
> > >
> > > On Wed, Jan 8, 2025 at 11:22 AM Yosry Ahmed <yosryahmed@google.com> wrote:
> > > >
> > > > This reverts commit eaebeb93922ca6ab0dd92027b73d0112701706ef.
> > > >
> > > > Commit eaebeb93922c ("mm: zswap: fix race between [de]compression and
> > > > CPU hotunplug") used the CPU hotplug lock in zswap compress/decompress
> > > > operations to protect against a race with CPU hotunplug making some
> > > > per-CPU resources go away.
> > > >
> > > > However, zswap compress/decompress can be reached through reclaim while
> > > > the lock is held, resulting in a potential deadlock as reported by
> > > > syzbot:
> > > > ======================================================
> > > > WARNING: possible circular locking dependency detected
> > > > 6.13.0-rc6-syzkaller-00006-g5428dc1906dd #0 Not tainted
> > > > ------------------------------------------------------
> > > > kswapd0/89 is trying to acquire lock:
> > > >  ffffffff8e7d2ed0 (cpu_hotplug_lock){++++}-{0:0}, at: acomp_ctx_get_cpu mm/zswap.c:886 [inline]
> > > >  ffffffff8e7d2ed0 (cpu_hotplug_lock){++++}-{0:0}, at: zswap_compress mm/zswap.c:908 [inline]
> > > >  ffffffff8e7d2ed0 (cpu_hotplug_lock){++++}-{0:0}, at: zswap_store_page mm/zswap.c:1439 [inline]
> > > >  ffffffff8e7d2ed0 (cpu_hotplug_lock){++++}-{0:0}, at: zswap_store+0xa74/0x1ba0 mm/zswap.c:1546
> > > >
> > > > but task is already holding lock:
> > > >  ffffffff8ea355a0 (fs_reclaim){+.+.}-{0:0}, at: balance_pgdat mm/vmscan.c:6871 [inline]
> > > >  ffffffff8ea355a0 (fs_reclaim){+.+.}-{0:0}, at: kswapd+0xb58/0x2f30 mm/vmscan.c:7253
> > > >
> > > > which lock already depends on the new lock.
> > >
> > > We have functions like percpu_is_write_locked(),
> > > percpu_is_read_locked(), and cpus_read_trylock().
> > > Could they help prevent circular locking dependencies if we perform a
> > > check before acquiring the lock?
> >
> > Yeah we can do that but it feels a bit hacky, we may have to
> > unnecessarily fail the operation in some cases, right? Not sure tbh.
>
> Not sure if it can be as simple as the following:
>
>     locked = cpus_read_trylock();
>     ....
>     if (locked)
>         cpus_read_unlock();
>
> If this works, it seems better than migrate_disable(), which could affect
> the scheduler's select_rq especially given that swap is a hot path :-)

I didn't look too closely into this, but I'd prefer the simpler fix
unless it causes any noticeable regressions. Unless others are also
concerned about disabling migration..

>
> Thanks
> Barry


  reply	other threads:[~2025-01-08  0:54 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-07 22:22 Yosry Ahmed
2025-01-07 22:22 ` [PATCH v2 2/2] mm: zswap: disable migration while using per-CPU acomp_ctx Yosry Ahmed
2025-01-07 22:47   ` Barry Song
2025-01-07 23:25     ` Yosry Ahmed
2025-01-07 23:38       ` Barry Song
2025-01-07 23:56         ` Barry Song
2025-01-08  0:01           ` Yosry Ahmed
2025-01-07 23:26     ` Barry Song
2025-01-08  0:01   ` Sridhar, Kanchana P
2025-01-08  0:12     ` Yosry Ahmed
2025-01-08  1:10       ` Sridhar, Kanchana P
2025-01-08  1:18         ` Yosry Ahmed
2025-01-08  2:33           ` Yosry Ahmed
2025-01-08  4:46             ` Nhat Pham
2025-01-08  5:00               ` Chengming Zhou
2025-01-08  5:34                 ` Yosry Ahmed
2025-01-08  5:55                   ` Yosry Ahmed
2025-01-08  7:56                     ` Barry Song
2025-01-08 15:36                       ` Yosry Ahmed
2025-01-08 15:49                         ` Nhat Pham
2025-01-08 16:17                           ` Yosry Ahmed
2025-01-08  6:00                   ` Chengming Zhou
2025-01-08 15:36                   ` Nhat Pham
2025-01-08  5:06               ` Barry Song
2025-01-08  5:25                 ` Barry Song
2025-01-07 23:01 ` [PATCH v2 1/2] Revert "mm: zswap: fix race between [de]compression and CPU hotunplug" Barry Song
2025-01-07 23:39   ` Yosry Ahmed
2025-01-08  0:34     ` Barry Song
2025-01-08  0:54       ` Yosry Ahmed [this message]
2025-01-08  1:11         ` Barry Song

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='CAJD7tkY=ztvdozH-yC55YFM4NvCUa77bH42ZYu_ewJYCff0TKw@mail.gmail.com' \
    --to=yosryahmed@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=chengming.zhou@linux.dev \
    --cc=hannes@cmpxchg.org \
    --cc=kanchana.p.sridhar@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=samsun1006219@gmail.com \
    --cc=syzkaller@googlegroups.com \
    --cc=vitalywool@gmail.com \
    /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