xen/grant-table: Use put_page instead of free_page
authorRoss Lagerwall <ross.lagerwall@citrix.com>
Thu, 11 Jan 2018 09:36:37 +0000 (09:36 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 26 Apr 2018 09:02:17 +0000 (11:02 +0200)
[ Upstream commit 3ac7292a25db1c607a50752055a18aba32ac2176 ]

The page given to gnttab_end_foreign_access() to free could be a
compound page so use put_page() instead of free_page() since it can
handle both compound and single pages correctly.

This bug was discovered when migrating a Xen VM with several VIFs and
CONFIG_DEBUG_VM enabled. It hits a BUG usually after fewer than 10
iterations. All netfront devices disconnect from the backend during a
suspend/resume and this will call gnttab_end_foreign_access() if a
netfront queue has an outstanding skb. The mismatch between calling
get_page() and free_page() on a compound page causes a reference
counting error which is detected when DEBUG_VM is enabled.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/xen/grant-table.c

index 2c6a9114d332c74a85e2d679b9c2672a7447e188..1fb374466e8437d93d83a87a7d329b2ad2d365fa 100644 (file)
@@ -328,7 +328,7 @@ static void gnttab_handle_deferred(unsigned long unused)
                        if (entry->page) {
                                pr_debug("freeing g.e. %#x (pfn %#lx)\n",
                                         entry->ref, page_to_pfn(entry->page));
-                               __free_page(entry->page);
+                               put_page(entry->page);
                        } else
                                pr_info("freeing g.e. %#x\n", entry->ref);
                        kfree(entry);
@@ -384,7 +384,7 @@ void gnttab_end_foreign_access(grant_ref_t ref, int readonly,
        if (gnttab_end_foreign_access_ref(ref, readonly)) {
                put_free_entry(ref);
                if (page != 0)
-                       free_page(page);
+                       put_page(virt_to_page(page));
        } else
                gnttab_add_deferred(ref, readonly,
                                    page ? virt_to_page(page) : NULL);