Skip to contentSkip to conversation

Fix broken IOCTL_PRIVCMD_MMAPBATCH (old version).

PATCH In review Mats Petersson 3 participants 5 messages Nov 16, 2012 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Fix broken IOCTL_PRIVCMD_MMAPBATCH (old version).

Most code-paths prefer the MMAPBATCH_V2, so this wasn't very obvious that it broke. The return value is set early on to -EINVAL, and if all goes well, the "set top bits of the MFN's" never gets called, so the return value is still EINVAL when the function gets to the end, causing the caller to think it went wrong (which it didn't!)

Signed off by: Mats Petersson <[email protected]>

---
 drivers/xen/privcmd.c |   18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/xen/privcmd.c +12 -6
index 8adb9cc..b378343 100644
@@ -347,6 +347,7 @@ static long privcmd_ioctl_mmap_batch(void __user *udata, int version)
 
 	if (ret)
 		goto out;
+
 	if (list_empty(&pagelist)) {
 		ret = -EINVAL;
 		goto out;
@@ -383,12 +384,17 @@ static long privcmd_ioctl_mmap_batch(void __user *udata, int version)
 
 	up_write(&mm->mmap_sem);
 
-	if (state.global_error && (version == 1)) {
-		/* Write back errors in second pass. */
-		state.user_mfn = (xen_pfn_t *)m.arr;
-		state.err      = err_array;
-		ret = traverse_pages(m.num, sizeof(xen_pfn_t),
-				     &pagelist, mmap_return_errors_v1, &state);
+	if (version == 1) {
+		if (state.global_error) {
+			/* Write back errors in second pass. */
+			state.user_mfn = (xen_pfn_t *)m.arr;
+			state.err      = err_array;
+			ret = traverse_pages(m.num, sizeof(xen_pfn_t),
+					     &pagelist, mmap_return_errors_v1, &state);
+		}
+		else
+			ret = 0;
+
 	} else if (version == 2) {
 		ret = __copy_to_user(m.err, err_array, m.num * sizeof(int));
 		if (ret)
Signature · 1 line
1.7.9.5
Acked-by on v1 1/2
#1 lore raw
Quoted 5 lines · Mats Petersson

Most code-paths prefer the MMAPBATCH_V2, so this wasn't very obvious that it broke. The return value is set early on to -EINVAL, and if all goes well, the "set top bits of the MFN's" never gets called, so the return value is still EINVAL when the function gets to the end, causing the caller to think it went wrong (which it didn't!)

Better subject line:

"xen/privcmd: correctly return success from IOCTL_PRIVCMD_MMAPBATCH."

This is a regression introduced by ceb90fa0 (xen/privcmd: add PRIVCMD_MMAPBATCH_V2 ioctl). It broke xentrace as it used xc_map_foreign() instead of xc_map_foreign_bulk(). It would be nice if the commit message mentioned this.

Quoted 1 line

Signed off by: Mats Petersson <[email protected]>

If the subject/commit message is improved:

drivers/xen/privcmd.c static long privcmd_ioctl_mmap_batch(void __user *udata, int version) · line 350

Quoted 7 lines
drivers/xen/privcmd.c +1 -0
@@ -347,6 +347,7 @@ static long privcmd_ioctl_mmap_batch(void __user *udata, int version)
 
 	if (ret)
 		goto out;
+

Stray change, please remove.

drivers/xen/privcmd.c static long privcmd_ioctl_mmap_batch(void __user *udata, int version) · line 353

Quoted 3 lines
drivers/xen/privcmd.c +0 -0
 	if (list_empty(&pagelist)) {
 		ret = -EINVAL;
 		goto out;

David

#3 lore raw

Re: [PATCH] Correctly return success from IOCTL_PRIVCMD_MMAPBATCH

Quoted 1 line · Mats Petersson

Updated according to David Vrabel's comments.

Huh? Where is the patch?

#4 lore raw

PATCH 1/1 Correctly return success from IOCTL_PRIVCMD_MMAPBATCH

In reply to Mats Petersson

This is a regression introduced by ceb90fa0 (xen/privcmd: add PRIVCMD_MMAPBATCH_V2 ioctl). It broke xentrace as it used xc_map_foreign() instead of xc_map_foreign_bulk().

Most code-paths prefer the MMAPBATCH_V2, so this wasn't very obvious that it broke. The return value is set early on to -EINVAL, and if all goes well, the "set top bits of the MFN's" never gets called, so the return value is still EINVAL when the function gets to the end, causing the caller to think it went wrong (which it didn't!)

Signed off by: Mats Petersson <[email protected]>

---
 drivers/xen/privcmd.c |   16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/xen/privcmd.c +10 -6
index 8adb9cc..24aec2f 100644
@@ -383,12 +383,16 @@ static long privcmd_ioctl_mmap_batch(void __user *udata, int version)
 
 	up_write(&mm->mmap_sem);
 
-	if (state.global_error && (version == 1)) {
-		/* Write back errors in second pass. */
-		state.user_mfn = (xen_pfn_t *)m.arr;
-		state.err      = err_array;
-		ret = traverse_pages(m.num, sizeof(xen_pfn_t),
-				     &pagelist, mmap_return_errors_v1, &state);
+	if (version == 1) {
+		if (state.global_error) {
+			/* Write back errors in second pass. */
+			state.user_mfn = (xen_pfn_t *)m.arr;
+			state.err      = err_array;
+			ret = traverse_pages(m.num, sizeof(xen_pfn_t),
+					     &pagelist, mmap_return_errors_v1, &state);
+		} else
+			ret = 0;
+
 	} else if (version == 2) {
 		ret = __copy_to_user(m.err, err_array, m.num * sizeof(int));
 		if (ret)
Signature · 1 line
1.7.9.5