From: Sultan Alsawaf <sultan@kerneltoast.com>
To: Minchan Kim <minchan@kernel.org>
Cc: stable@vger.kernel.org, Nitin Gupta <ngupta@vflare.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] zsmalloc: Fix races between asynchronous zspage free and page migration
Date: Wed, 11 May 2022 12:50:20 -0700 [thread overview]
Message-ID: <YnwTfBLn+6vYSe59@sultan-box.localdomain> (raw)
In-Reply-To: <Ynv53fkx8cG0ixaE@google.com>
On Wed, May 11, 2022 at 11:01:01AM -0700, Minchan Kim wrote:
> On Sun, May 08, 2022 at 07:47:02PM -0700, Sultan Alsawaf wrote:
> > Cc: stable@vger.kernel.org
> > Fixes: 48b4800a1c6a ("zsmalloc: page migration support")
>
> Shouldn't the fix be Fixes: 77ff465799c6 ("zsmalloc: zs_page_migrate: skip
> unnecessary loops but not return -EBUSY if zspage is not inuse)?
> Because we didn't migrate ZS_EMPTY pages before.
Hi,
Yeah, 77ff465799c6 indeed seems like the commit that introduced the bug.
> I couldn't get the point here. Why couldn't we simple lock zspage migration?
>
> diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> index 9152fbde33b5..05ff2315b7b1 100644
> --- a/mm/zsmalloc.c
> +++ b/mm/zsmalloc.c
> @@ -1987,7 +1987,10 @@ static void async_free_zspage(struct work_struct *work)
>
> list_for_each_entry_safe(zspage, tmp, &free_pages, list) {
> list_del(&zspage->list);
> +
> + migrate_read_lock(zspage);
> lock_zspage(zspage);
> + migrate_read_unlock(zspage);
>
> get_zspage_mapping(zspage, &class_idx, &fullness);
> VM_BUG_ON(fullness != ZS_EMPTY);
There are two problems with this:
1. migrate_read_lock() is a rwlock and lock_page() can sleep.
2. This will cause a deadlock because it violates the lock ordering in
zs_page_migrate(), since zs_page_migrate() takes migrate_write_lock() under
the page lock.
Sultan
next prev parent reply other threads:[~2022-05-11 19:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20220509024703.243847-1-sultan@kerneltoast.com>
2022-05-10 0:06 ` Andrew Morton
2022-05-10 1:22 ` Sultan Alsawaf
2022-05-11 18:01 ` Minchan Kim
2022-05-11 19:50 ` Sultan Alsawaf [this message]
2022-05-11 20:43 ` Andrew Morton
2022-05-11 23:12 ` Minchan Kim
2022-05-11 21:07 ` Minchan Kim
2022-05-11 21:45 ` Sultan Alsawaf
2022-05-11 23:11 ` Minchan Kim
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=YnwTfBLn+6vYSe59@sultan-box.localdomain \
--to=sultan@kerneltoast.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=ngupta@vflare.org \
--cc=senozhatsky@chromium.org \
--cc=stable@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