提交 12f4b608 编写于 作者: V Vinayak Menon 提交者: Xie XiuQi

mm/page_io.c: do not free shared swap slots

[ Upstream commit 5df373e95689b9519b8557da7c5bd0db0856d776 ]

The following race is observed due to which a processes faulting on a
swap entry, finds the page neither in swapcache nor swap.  This causes
zram to give a zero filled page that gets mapped to the process,
resulting in a user space crash later.

Consider parent and child processes Pa and Pb sharing the same swap slot
with swap_count 2.  Swap is on zram with SWP_SYNCHRONOUS_IO set.
Virtual address 'VA' of Pa and Pb points to the shared swap entry.

Pa                                       Pb

fault on VA                              fault on VA
do_swap_page                             do_swap_page
lookup_swap_cache fails                  lookup_swap_cache fails
                                         Pb scheduled out
swapin_readahead (deletes zram entry)
swap_free (makes swap_count 1)
                                         Pb scheduled in
                                         swap_readpage (swap_count == 1)
                                         Takes SWP_SYNCHRONOUS_IO path
                                         zram enrty absent
                                         zram gives a zero filled page

Fix this by making sure that swap slot is freed only when swap count
drops down to one.

Link: http://lkml.kernel.org/r/1571743294-14285-1-git-send-email-vinmenon@codeaurora.org
Fixes: aa8d22a1 ("mm: swap: SWP_SYNCHRONOUS_IO: skip swapcache only if swapped page has no other reference")
Signed-off-by: NVinayak Menon <vinmenon@codeaurora.org>
Suggested-by: NMinchan Kim <minchan@google.com>
Acked-by: NMinchan Kim <minchan@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Conflicts:
  mm/page_io.c
[yyl: remove __swap_count's parameter]
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
Reviewed-by: NKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 04d6a352
...@@ -76,6 +76,7 @@ static void swap_slot_free_notify(struct page *page) ...@@ -76,6 +76,7 @@ static void swap_slot_free_notify(struct page *page)
{ {
struct swap_info_struct *sis; struct swap_info_struct *sis;
struct gendisk *disk; struct gendisk *disk;
swp_entry_t entry;
/* /*
* There is no guarantee that the page is in swap cache - the software * There is no guarantee that the page is in swap cache - the software
...@@ -107,11 +108,11 @@ static void swap_slot_free_notify(struct page *page) ...@@ -107,11 +108,11 @@ static void swap_slot_free_notify(struct page *page)
* we again wish to reclaim it. * we again wish to reclaim it.
*/ */
disk = sis->bdev->bd_disk; disk = sis->bdev->bd_disk;
if (disk->fops->swap_slot_free_notify) { entry.val = page_private(page);
swp_entry_t entry; if (disk->fops->swap_slot_free_notify &&
__swap_count(entry) == 1) {
unsigned long offset; unsigned long offset;
entry.val = page_private(page);
offset = swp_offset(entry); offset = swp_offset(entry);
SetPageDirty(page); SetPageDirty(page);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册