Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xen: privcmd: do not return pages which we have failed to unmap

This failure represents a hypervisor issue, but if it does occur then nothing
good can come of returning pages which still refer to a foreign owned page
into the general allocation pool.

Instead we are forced to leak them. Log that we have done so.

The potential for failure only exists for autotranslated guest (e.g. ARM and
x86 PVH).

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Reviewed-by: David Vrabel <david.vrabel@citrix.com>

authored by

Ian Campbell and committed by
Stefano Stabellini
b6497b38 c94cae53

+7 -2
+7 -2
drivers/xen/privcmd.c
··· 533 533 { 534 534 struct page **pages = vma->vm_private_data; 535 535 int numpgs = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT; 536 + int rc; 536 537 537 538 if (!xen_feature(XENFEAT_auto_translated_physmap) || !numpgs || !pages) 538 539 return; 539 540 540 - xen_unmap_domain_mfn_range(vma, numpgs, pages); 541 - free_xenballooned_pages(numpgs, pages); 541 + rc = xen_unmap_domain_mfn_range(vma, numpgs, pages); 542 + if (rc == 0) 543 + free_xenballooned_pages(numpgs, pages); 544 + else 545 + pr_crit("unable to unmap MFN range: leaking %d pages. rc=%d\n", 546 + numpgs, rc); 542 547 kfree(pages); 543 548 } 544 549