Skip to contentSkip to conversation

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

PATCH In review Ian Campbell 4 participants 7 messages Dec 4, 2013 – Dec 6, 2013 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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 foced to leak them. Log that we have done so.

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

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc David Vrabel <[email protected]>
Cc Stefano Stabellini <[email protected]>
---
 drivers/xen/privcmd.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/xen/privcmd.c +7 -1
index 8e74590..2efc720 100644
@@ -533,11 +533,17 @@ static void privcmd_close(struct vm_area_struct *vma)
 {
 	struct page **pages = vma->vm_private_data;
 	int numpgs = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
+	int rc;
 
 	if (!xen_feature(XENFEAT_auto_translated_physmap) || !numpgs || !pages)
 		return;
 
-	xen_unmap_domain_mfn_range(vma, numpgs, pages);
+	rc = xen_unmap_domain_mfn_range(vma, numpgs, pages);
+	if (rc < 0) {
+		pr_crit("unable to unmap MFN range: leaking %d pages\n",
+			numpgs);
+		return;
+	}
 	free_xenballooned_pages(numpgs, pages);
 	kfree(pages);
 }
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 5 lines · Ian Campbell

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 foced to leak them. Log that we have done so.

^forced

Quoted 3 lines

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

[...]

Quoted 6 lines
drivers/xen/privcmd.c +0 -0
@@ -533,11 +533,17 @@ static void privcmd_close(struct vm_area_struct *vma)
 {
 	struct page **pages = vma->vm_private_data;
 	int numpgs = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;

drivers/xen/privcmd.c static void privcmd_close(struct vm_area_struct *vma) · line 544

Quoted 10 lines
drivers/xen/privcmd.c +5 -1
+	int rc;
 
 	if (!xen_feature(XENFEAT_auto_translated_physmap) || !numpgs || !pages)
 		return;
 
-	xen_unmap_domain_mfn_range(vma, numpgs, pages);
+	rc = xen_unmap_domain_mfn_range(vma, numpgs, pages);
+	if (rc < 0) {
+		pr_crit("unable to unmap MFN range: leaking %d pages\n",
+			numpgs);

kfree(pages) here? I think that would be safe. Although at this point it probably doesn't really matter.

David

#2 lore raw
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +4 -1
-	xen_unmap_domain_mfn_range(vma, numpgs, pages);
+	rc = xen_unmap_domain_mfn_range(vma, numpgs, pages);
+	if (rc < 0) {
+		pr_crit("unable to unmap MFN range: leaking %d pages\n",
+			numpgs);

kfree(pages) here? I think that would be safe. Although at this point it probably doesn't really matter.

I suppose we might as well not make it any worse than it needs to be and it's easy enough to arrange.

---------------------8<---------------------

Quoted 1 line

From 900f1e903bacf376800b078aef03e8d5ff524562 Mon Sep 17 00:00:00 2001

From: Ian Campbell <[email protected]>
Date: Wed, 4 Dec 2013 14:19:52 +0000
Subject: [PATCH] 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).

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc David Vrabel <[email protected]>
Cc Stefano Stabellini <[email protected]>

---
v2: Don't leak the actual pages array as well
Log rc

---
 drivers/xen/privcmd.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/xen/privcmd.c +7 -2
index 8e74590..569a13b 100644
@@ -533,12 +533,17 @@ static void privcmd_close(struct vm_area_struct *vma)
 {
 	struct page **pages = vma->vm_private_data;
 	int numpgs = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
+	int rc;
 
 	if (!xen_feature(XENFEAT_auto_translated_physmap) || !numpgs || !pages)
 		return;
 
-	xen_unmap_domain_mfn_range(vma, numpgs, pages);
-	free_xenballooned_pages(numpgs, pages);
+	rc = xen_unmap_domain_mfn_range(vma, numpgs, pages);
+	if (rc == 0)
+		free_xenballooned_pages(numpgs, pages);
+	else
+		pr_crit("unable to unmap MFN range: leaking %d pages. rc=%d\n",
+			numpgs, rc);
 	kfree(pages);
 }
 
Signature · 1 line
1.7.10.4
Reviewed-by
#3 lore raw
Quoted 11 lines · Ian Campbell

Subject: [PATCH] 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).

David

#4 lore raw
In reply to Ian Campbell
Quoted 21 lines · Ian Campbell
Quoted 1 line

From 900f1e903bacf376800b078aef03e8d5ff524562 Mon Sep 17 00:00:00 2001

From: Ian Campbell <[email protected]>
Date: Wed, 4 Dec 2013 14:19:52 +0000
Subject: [PATCH] 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).

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc David Vrabel <[email protected]>
Cc Stefano Stabellini <[email protected]>
Quoted 3 lines

---
v2: Don't leak the actual pages array as well
Log rc

Konrad, you can go ahead and add it to xentip, unless you would rather have me do it.

Quoted 32 lines
 drivers/xen/privcmd.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/xen/privcmd.c +7 -2
index 8e74590..569a13b 100644
@@ -533,12 +533,17 @@ static void privcmd_close(struct vm_area_struct *vma)
 {
 	struct page **pages = vma->vm_private_data;
 	int numpgs = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
+	int rc;
 
 	if (!xen_feature(XENFEAT_auto_translated_physmap) || !numpgs || !pages)
 		return;
 
-	xen_unmap_domain_mfn_range(vma, numpgs, pages);
-	free_xenballooned_pages(numpgs, pages);
+	rc = xen_unmap_domain_mfn_range(vma, numpgs, pages);
+	if (rc == 0)
+		free_xenballooned_pages(numpgs, pages);
+	else
+		pr_crit("unable to unmap MFN range: leaking %d pages. rc=%d\n",
+			numpgs, rc);
 	kfree(pages);
 }
 
Signature · 1 line
1.7.10.4
#5 lore raw
Quoted 27 lines · Stefano Stabellini
Quoted 21 lines · Ian Campbell
Quoted 1 line

From 900f1e903bacf376800b078aef03e8d5ff524562 Mon Sep 17 00:00:00 2001

From: Ian Campbell <[email protected]>
Date: Wed, 4 Dec 2013 14:19:52 +0000
Subject: [PATCH] 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).

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc David Vrabel <[email protected]>
Cc Stefano Stabellini <[email protected]>
Quoted 3 lines

---
v2: Don't leak the actual pages array as well
Log rc

Quoted 4 lines

Konrad, you can go ahead and add it to xentip, unless you would rather have me do it.

Why don't you do it. Thanks!

Quoted 34 lines
Quoted 34 lines

 drivers/xen/privcmd.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/xen/privcmd.c +7 -2
index 8e74590..569a13b 100644
@@ -533,12 +533,17 @@ static void privcmd_close(struct vm_area_struct *vma)
 {
 	struct page **pages = vma->vm_private_data;
 	int numpgs = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
+	int rc;
 
 	if (!xen_feature(XENFEAT_auto_translated_physmap) || !numpgs || !pages)
 		return;
 
-	xen_unmap_domain_mfn_range(vma, numpgs, pages);
-	free_xenballooned_pages(numpgs, pages);
+	rc = xen_unmap_domain_mfn_range(vma, numpgs, pages);
+	if (rc == 0)
+		free_xenballooned_pages(numpgs, pages);
+	else
+		pr_crit("unable to unmap MFN range: leaking %d pages. rc=%d\n",
+			numpgs, rc);
 	kfree(pages);
 }
 
Signature · 1 line
1.7.10.4
#6 lore raw
Quoted 28 lines · Konrad Rzeszutek Wilk
Quoted 27 lines · Stefano Stabellini
Quoted 24 lines · Ian Campbell
Quoted 1 line

From 900f1e903bacf376800b078aef03e8d5ff524562 Mon Sep 17 00:00:00 2001

From: Ian Campbell <[email protected]>
Date: Wed, 4 Dec 2013 14:19:52 +0000
Subject: [PATCH] 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).

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc David Vrabel <[email protected]>
Cc Stefano Stabellini <[email protected]>

---
v2: Don't leak the actual pages array as well
Log rc

Quoted 6 lines
Quoted 4 lines

Konrad, you can go ahead and add it to xentip, unless you would rather have me do it.

Why don't you do it. Thanks!

done

Quoted 34 lines
Quoted 33 lines
Quoted 33 lines
 drivers/xen/privcmd.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/xen/privcmd.c +7 -2
index 8e74590..569a13b 100644
@@ -533,12 +533,17 @@ static void privcmd_close(struct vm_area_struct *vma)
 {
 	struct page **pages = vma->vm_private_data;
 	int numpgs = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
+	int rc;
 
 	if (!xen_feature(XENFEAT_auto_translated_physmap) || !numpgs || !pages)
 		return;
 
-	xen_unmap_domain_mfn_range(vma, numpgs, pages);
-	free_xenballooned_pages(numpgs, pages);
+	rc = xen_unmap_domain_mfn_range(vma, numpgs, pages);
+	if (rc == 0)
+		free_xenballooned_pages(numpgs, pages);
+	else
+		pr_crit("unable to unmap MFN range: leaking %d pages. rc=%d\n",
+			numpgs, rc);
 	kfree(pages);
 }
 
Signature · 1 line
1.7.10.4