From patchwork Thu Mar 5 17:18:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Arcangeli X-Patchwork-Id: 446820 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 325C71400F1 for ; Fri, 6 Mar 2015 04:22:06 +1100 (AEDT) Received: from localhost ([::1]:53173 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTZTI-0008Or-2X for incoming@patchwork.ozlabs.org; Thu, 05 Mar 2015 12:22:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40397) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTZQU-00045S-3L for qemu-devel@nongnu.org; Thu, 05 Mar 2015 12:19:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YTZQS-0007cu-1W for qemu-devel@nongnu.org; Thu, 05 Mar 2015 12:19:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59678) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YTZQR-0007cR-QG for qemu-devel@nongnu.org; Thu, 05 Mar 2015 12:19:07 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t25HIDam031703 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 5 Mar 2015 12:18:13 -0500 Received: from mail.random (ovpn-116-22.ams2.redhat.com [10.36.116.22]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t25HIBvW005672 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 5 Mar 2015 12:18:12 -0500 From: Andrea Arcangeli To: qemu-devel@nongnu.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-api@vger.kernel.org, Android Kernel Team Date: Thu, 5 Mar 2015 18:18:00 +0100 Message-Id: <1425575884-2574-18-git-send-email-aarcange@redhat.com> In-Reply-To: <1425575884-2574-1-git-send-email-aarcange@redhat.com> References: <1425575884-2574-1-git-send-email-aarcange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Robert Love , Dave Hansen , Jan Kara , Neil Brown , Stefan Hajnoczi , Andrew Jones , Sanidhya Kashyap , KOSAKI Motohiro , Michel Lespinasse , Taras Glek , zhang.zhanghailiang@huawei.com, Pavel Emelyanov , Hugh Dickins , Mel Gorman , Sasha Levin , "Dr. David Alan Gilbert" , "Huangpeng \(Peter\)" , Andres Lagar-Cavilla , Christopher Covington , Anthony Liguori , Paolo Bonzini , "Kirill A. Shutemov" , Keith Packard , Wenchao Xia , Juan Quintela , Andy Lutomirski , Minchan Kim , Dmitry Adamushko , Johannes Weiner , Mike Hommey , Andrew Morton , Linus Torvalds , Peter Feiner Subject: [Qemu-devel] [PATCH 17/21] userfaultfd: remap_pages: swp_entry_swapcount() preparation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Provide a new swapfile method for remap_pages() to verify the swap entry is mapped only in one vma before relocating the swap entry in a different virtual address. Otherwise if the swap entry is mapped in multiple vmas, when the page is swapped back in, it could get mapped in a non linear way in some anon_vma. Signed-off-by: Andrea Arcangeli --- include/linux/swap.h | 6 ++++++ mm/swapfile.c | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/linux/swap.h b/include/linux/swap.h index 4759491..9adda11 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -436,6 +436,7 @@ extern unsigned int count_swap_pages(int, int); extern sector_t map_swap_page(struct page *, struct block_device **); extern sector_t swapdev_block(int, pgoff_t); extern int page_swapcount(struct page *); +extern int swp_entry_swapcount(swp_entry_t entry); extern struct swap_info_struct *page_swap_info(struct page *); extern int reuse_swap_page(struct page *); extern int try_to_free_swap(struct page *); @@ -527,6 +528,11 @@ static inline int page_swapcount(struct page *page) return 0; } +static inline int swp_entry_swapcount(swp_entry_t entry) +{ + return 0; +} + #define reuse_swap_page(page) (page_mapcount(page) == 1) static inline int try_to_free_swap(struct page *page) diff --git a/mm/swapfile.c b/mm/swapfile.c index 63f55cc..04c7621 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -874,6 +874,19 @@ int page_swapcount(struct page *page) return count; } +int swp_entry_swapcount(swp_entry_t entry) +{ + int count = 0; + struct swap_info_struct *p; + + p = swap_info_get(entry); + if (p) { + count = swap_count(p->swap_map[swp_offset(entry)]); + spin_unlock(&p->lock); + } + return count; +} + /* * We can write to an anon page without COW if there are no other references * to it. And as a side-effect, free up its swap: because the old content