linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Huang, Ying" <ying.huang@intel.com>
To: Miaohe Lin <linmiaohe@huawei.com>
Cc: Linux-MM <linux-mm@kvack.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Matthew Wilcox <willy@infradead.org>, Yu Zhao <yuzhao@google.com>,
	Shakeel Butt <shakeelb@google.com>,
	Alex Shi <alex.shi@linux.alibaba.com>,
	Minchan Kim <minchan@kernel.org>
Subject: Re: [Question] Is there a race window between swapoff vs synchronous swap_readpage
Date: Tue, 30 Mar 2021 09:57:55 +0800	[thread overview]
Message-ID: <8735wdbdy4.fsf@yhuang6-desk1.ccr.corp.intel.com> (raw)
In-Reply-To: <364d7ce9-ccb7-fa04-7067-44a96be87060@huawei.com> (Miaohe Lin's message of "Mon, 29 Mar 2021 21:18:20 +0800")

Hi, Miaohe,

Miaohe Lin <linmiaohe@huawei.com> writes:

> Hi all,
> I am investigating the swap code, and I found the below possible race window:
>
> CPU 1							CPU 2
> -----							-----
> do_swap_page
>   skip swapcache case (synchronous swap_readpage)
>     alloc_page_vma
> 							swapoff
> 							  release swap_file, bdev, or ...
>       swap_readpage
> 	check sis->flags is ok
> 	  access swap_file, bdev or ...[oops!]
> 							    si->flags = 0
>
> The swapcache case is ok because swapoff will wait on the page_lock of swapcache page.
> Is this will really happen or Am I miss something ?
> Any reply would be really grateful. Thanks! :)

This appears possible.  Even for swapcache case, we can't guarantee the
swap entry gotten from the page table is always valid too.  The
underlying swap device can be swapped off at the same time.  So we use
get/put_swap_device() for that.  Maybe we need similar stuff here.

Best Regards,
Huang, Ying

  reply	other threads:[~2021-03-30  1:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-29 13:18 [Question] Is there a race window between swapoff vs synchronous swap_readpage Miaohe Lin
2021-03-30  1:57 ` Huang, Ying [this message]
2021-03-30  3:15   ` Miaohe Lin
2021-03-30  3:44     ` Huang, Ying
2021-03-30  5:47       ` Yu Zhao
2021-03-30  6:57         ` Huang, Ying
2021-03-30  7:27           ` Yu Zhao
2021-04-12  3:12             ` Miaohe Lin
2021-03-30 11:21       ` Miaohe Lin

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=8735wdbdy4.fsf@yhuang6-desk1.ccr.corp.intel.com \
    --to=ying.huang@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex.shi@linux.alibaba.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=shakeelb@google.com \
    --cc=willy@infradead.org \
    --cc=yuzhao@google.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;
as well as URLs for NNTP newsgroup(s).