Skip to contentSkip to conversation

bug in xc_gntshr_munmap?

PATCH In review Marek Marczykowski 3 participants 15 messages Apr 26, 2013 – Apr 30, 2013

lore
Share & tools
lore
#0 lore raw

Hi,

Header says:
/*
* Unmaps the @count pages starting at @start_address, which were mapped by a
* call to xc_gntshr_share_*. Never logs.
*/
int xc_gntshr_munmap(xc_gntshr *xcg, void *start_address, uint32_t count);

But implementation calls:
static int linux_gntshr_munmap(xc_gntshr *xcg, xc_osdep_handle h,
void *start_address, uint32_t count)

{
    return munmap(start_address, count);
}

munmap(2) expect second argument to be size of mapped area (in bytes), not pages count.

Users of xc_gntshr_munmap (the only one I'm aware of is libxenvchan) already uses that broken semantic.

Is it going to be fixed (I can send trivial patch for both libxc and libxenvchan), or the comment in header should be updated?

Signature · 3 lines
Best Regards / Pozdrawiam,
Marek Marczykowski
Invisible Things Lab

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw

PATCH 1/1 libxc: fix xc_gntshr_munmap semantic

In reply to Marek Marczykowski

"count" parameter should be pages count (as stated in comment in xenctrl.h), not bytes count.
This patch fixes also the only user of this function (in xen sources) - libvchan.

---
 tools/libvchan/init.c        |  4 ++--
 tools/libvchan/io.c          | 10 ++++++----
 tools/libxc/xc_linux_osdep.c |  2 +-
 3 files changed, 9 insertions(+), 7 deletions(-)
tools/libvchan/init.c +2 -2
index 0c7cff6..f0d2505 100644
@@ -129,9 +129,9 @@ out:
 	return ring_ref;
 out_unmap_left:
 	if (pages_left)
-		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer, pages_left * PAGE_SIZE);
+		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer, pages_left);
 out_ring:
-	xc_gntshr_munmap(ctrl->gntshr, ring, PAGE_SIZE);
+	xc_gntshr_munmap(ctrl->gntshr, ring, 1);
 	ring_ref = -1;
 	ctrl->ring = NULL;
 	ctrl->write.order = ctrl->read.order = 0;
tools/libvchan/io.c +6 -4
index 3c8d236..3040099 100644
@@ -324,16 +324,18 @@ void libxenvchan_close(struct libxenvchan *ctrl)
 	if (!ctrl)
 		return;
 	if (ctrl->read.order >= PAGE_SHIFT)
-		munmap(ctrl->read.buffer, 1 << ctrl->read.order);
+		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer,
+				1 << (ctrl->read.order - PAGE_SHIFT));
 	if (ctrl->write.order >= PAGE_SHIFT)
-		munmap(ctrl->write.buffer, 1 << ctrl->write.order);
+		xc_gntshr_munmap(ctrl->gntshr, ctrl->write.buffer,
+				1 << (ctrl->write.order - PAGE_SHIFT));
 	if (ctrl->ring) {
 		if (ctrl->is_server) {
 			ctrl->ring->srv_live = 0;
-			xc_gntshr_munmap(ctrl->gntshr, ctrl->ring, PAGE_SIZE);
+			xc_gntshr_munmap(ctrl->gntshr, ctrl->ring, 1);
 		} else {
 			ctrl->ring->cli_live = 0;
-			xc_gnttab_munmap(ctrl->gnttab, ctrl->ring, PAGE_SIZE);
+			xc_gnttab_munmap(ctrl->gnttab, ctrl->ring, 1);
 		}
 	}
 	if (ctrl->event) {
tools/libxc/xc_linux_osdep.c +1 -1
index 36832b6..3c43fca 100644
@@ -825,7 +825,7 @@ static void *linux_gntshr_share_pages(xc_gntshr *xch, xc_osdep_handle h,
 static int linux_gntshr_munmap(xc_gntshr *xcg, xc_osdep_handle h,
                                void *start_address, uint32_t count)
 {
-    return munmap(start_address, count);
+    return munmap(start_address, count * XC_PAGE_SIZE);
 }
 
 static struct xc_osdep_ops linux_gntshr_ops = {
Signature · 1 line
1.8.1.4
#1 lore raw
In reply to Marek Marczykowski
Quoted 16 lines · Marek Marczykowski

Hi,

Header says:
/*
* Unmaps the @count pages starting at @start_address, which were mapped by a
* call to xc_gntshr_share_*. Never logs.
*/
int xc_gntshr_munmap(xc_gntshr *xcg, void *start_address, uint32_t count);

But implementation calls:
static int linux_gntshr_munmap(xc_gntshr *xcg, xc_osdep_handle h,
void *start_address, uint32_t count)

{
    return munmap(start_address, count);
}
Quoted 8 lines

munmap(2) expect second argument to be size of mapped area (in bytes), not pages count.

Users of xc_gntshr_munmap (the only one I'm aware of is libxenvchan) already uses that broken semantic.

Is it going to be fixed (I can send trivial patch for both libxc and libxenvchan), or the comment in header should be updated?

I think the function should behave the same as the map side, whichever that is.

Ian.

#2 lore raw
Quoted 20 lines · Ian Campbell
Quoted 19 lines · Marek Marczykowski

Hi,

Header says:
/*
* Unmaps the @count pages starting at @start_address, which were mapped by a
* call to xc_gntshr_share_*. Never logs.
*/
int xc_gntshr_munmap(xc_gntshr *xcg, void *start_address, uint32_t count);

But implementation calls:
static int linux_gntshr_munmap(xc_gntshr *xcg, xc_osdep_handle h,
void *start_address, uint32_t count)

{
    return munmap(start_address, count);
}

munmap(2) expect second argument to be size of mapped area (in bytes), not pages count.

Quoted 8 lines
Quoted 5 lines

Users of xc_gntshr_munmap (the only one I'm aware of is libxenvchan) already uses that broken semantic.

Is it going to be fixed (I can send trivial patch for both libxc and libxenvchan), or the comment in header should be updated?

I think the function should behave the same as the map side, whichever that is.

Map side uses pages count.
Also xc_gnttab_{grant_map,munmap} both uses pages count. So I assume it is a bug. The question is can it be simply changed - some software can already depend on that broken semantic...

Anyway I will send a patch in a moment.

Signature · 3 lines
Best Regards / Pozdrawiam,
Marek Marczykowski
Invisible Things Lab

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#14 lore raw
Quoted 27 lines · Marek Marczykowski
Quoted 26 lines · Ian Campbell
Quoted 24 lines · Marek Marczykowski

Hi,

Header says:
/*
* Unmaps the @count pages starting at @start_address, which were mapped by a
* call to xc_gntshr_share_*. Never logs.
*/
int xc_gntshr_munmap(xc_gntshr *xcg, void *start_address, uint32_t count);

But implementation calls:
static int linux_gntshr_munmap(xc_gntshr *xcg, xc_osdep_handle h,
void *start_address, uint32_t count)

{
    return munmap(start_address, count);
}

munmap(2) expect second argument to be size of mapped area (in bytes), not pages count.

Users of xc_gntshr_munmap (the only one I'm aware of is libxenvchan) already uses that broken semantic.

Is it going to be fixed (I can send trivial patch for both libxc and libxenvchan), or the comment in header should be updated?

Quoted 7 lines
Quoted 2 lines

I think the function should behave the same as the map side, whichever that is.

Map side uses pages count.
Also xc_gnttab_{grant_map,munmap} both uses pages count. So I assume it is a bug. The question is can it be simply changed - some software can already depend on that broken semantic...

libxc does not provide a stable API/ABI so it is OK to change as long as you update the intree callers. We'll bump the SONAMEs before release if we haven't already this cycle...

Quoted 2 lines

Anyway I will send a patch in a moment.

#4 lore raw

Re: [PATCH] libxc: fix xc_gntshr_munmap semantic

In reply to Marek Marczykowski

CC'ed Ian.

Quoted 69 lines · Marek Marczykowski

"count" parameter should be pages count (as stated in comment in xenctrl.h), not bytes count.
This patch fixes also the only user of this function (in xen sources) - libvchan.

---
 tools/libvchan/init.c        |  4 ++--
 tools/libvchan/io.c          | 10 ++++++----
 tools/libxc/xc_linux_osdep.c |  2 +-
 3 files changed, 9 insertions(+), 7 deletions(-)
tools/libvchan/init.c +2 -2
index 0c7cff6..f0d2505 100644
@@ -129,9 +129,9 @@ out:
 	return ring_ref;
 out_unmap_left:
 	if (pages_left)
-		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer, pages_left * PAGE_SIZE);
+		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer, pages_left);
 out_ring:
-	xc_gntshr_munmap(ctrl->gntshr, ring, PAGE_SIZE);
+	xc_gntshr_munmap(ctrl->gntshr, ring, 1);
 	ring_ref = -1;
 	ctrl->ring = NULL;
 	ctrl->write.order = ctrl->read.order = 0;
tools/libvchan/io.c +6 -4
index 3c8d236..3040099 100644
@@ -324,16 +324,18 @@ void libxenvchan_close(struct libxenvchan *ctrl)
 	if (!ctrl)
 		return;
 	if (ctrl->read.order >= PAGE_SHIFT)
-		munmap(ctrl->read.buffer, 1 << ctrl->read.order);
+		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer,
+				1 << (ctrl->read.order - PAGE_SHIFT));
 	if (ctrl->write.order >= PAGE_SHIFT)
-		munmap(ctrl->write.buffer, 1 << ctrl->write.order);
+		xc_gntshr_munmap(ctrl->gntshr, ctrl->write.buffer,
+				1 << (ctrl->write.order - PAGE_SHIFT));
 	if (ctrl->ring) {
 		if (ctrl->is_server) {
 			ctrl->ring->srv_live = 0;
-			xc_gntshr_munmap(ctrl->gntshr, ctrl->ring, PAGE_SIZE);
+			xc_gntshr_munmap(ctrl->gntshr, ctrl->ring, 1);
 		} else {
 			ctrl->ring->cli_live = 0;
-			xc_gnttab_munmap(ctrl->gnttab, ctrl->ring, PAGE_SIZE);
+			xc_gnttab_munmap(ctrl->gnttab, ctrl->ring, 1);
 		}
 	}
 	if (ctrl->event) {
tools/libxc/xc_linux_osdep.c +1 -1
index 36832b6..3c43fca 100644
@@ -825,7 +825,7 @@ static void *linux_gntshr_share_pages(xc_gntshr *xch, xc_osdep_handle h,
 static int linux_gntshr_munmap(xc_gntshr *xcg, xc_osdep_handle h,
                                void *start_address, uint32_t count)
 {
-    return munmap(start_address, count);
+    return munmap(start_address, count * XC_PAGE_SIZE);
 }
 
 static struct xc_osdep_ops linux_gntshr_ops = {
Signature · 3 lines
Best Regards / Pozdrawiam,
Marek Marczykowski
Invisible Things Lab

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#5 lore raw

Re: [PATCH] libxc: fix xc_gntshr_munmap semantic

In reply to Marek Marczykowski
Quoted 4 lines · Marek Marczykowski

"count" parameter should be pages count (as stated in comment in xenctrl.h), not bytes count.
This patch fixes also the only user of this function (in xen sources) - libvchan.

Looks ok to me but Daniel De Graaf wrote all this stuff, Ccing him.

Quoted 64 lines
---
 tools/libvchan/init.c        |  4 ++--
 tools/libvchan/io.c          | 10 ++++++----
 tools/libxc/xc_linux_osdep.c |  2 +-
 3 files changed, 9 insertions(+), 7 deletions(-)
tools/libvchan/init.c +2 -2
index 0c7cff6..f0d2505 100644
@@ -129,9 +129,9 @@ out:
 	return ring_ref;
 out_unmap_left:
 	if (pages_left)
-		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer, pages_left * PAGE_SIZE);
+		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer, pages_left);
 out_ring:
-	xc_gntshr_munmap(ctrl->gntshr, ring, PAGE_SIZE);
+	xc_gntshr_munmap(ctrl->gntshr, ring, 1);
 	ring_ref = -1;
 	ctrl->ring = NULL;
 	ctrl->write.order = ctrl->read.order = 0;
tools/libvchan/io.c +6 -4
index 3c8d236..3040099 100644
@@ -324,16 +324,18 @@ void libxenvchan_close(struct libxenvchan *ctrl)
 	if (!ctrl)
 		return;
 	if (ctrl->read.order >= PAGE_SHIFT)
-		munmap(ctrl->read.buffer, 1 << ctrl->read.order);
+		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer,
+				1 << (ctrl->read.order - PAGE_SHIFT));
 	if (ctrl->write.order >= PAGE_SHIFT)
-		munmap(ctrl->write.buffer, 1 << ctrl->write.order);
+		xc_gntshr_munmap(ctrl->gntshr, ctrl->write.buffer,
+				1 << (ctrl->write.order - PAGE_SHIFT));
 	if (ctrl->ring) {
 		if (ctrl->is_server) {
 			ctrl->ring->srv_live = 0;
-			xc_gntshr_munmap(ctrl->gntshr, ctrl->ring, PAGE_SIZE);
+			xc_gntshr_munmap(ctrl->gntshr, ctrl->ring, 1);
 		} else {
 			ctrl->ring->cli_live = 0;
-			xc_gnttab_munmap(ctrl->gnttab, ctrl->ring, PAGE_SIZE);
+			xc_gnttab_munmap(ctrl->gnttab, ctrl->ring, 1);
 		}
 	}
 	if (ctrl->event) {
tools/libxc/xc_linux_osdep.c +1 -1
index 36832b6..3c43fca 100644
@@ -825,7 +825,7 @@ static void *linux_gntshr_share_pages(xc_gntshr *xch, xc_osdep_handle h,
 static int linux_gntshr_munmap(xc_gntshr *xcg, xc_osdep_handle h,
                                void *start_address, uint32_t count)
 {
-    return munmap(start_address, count);
+    return munmap(start_address, count * XC_PAGE_SIZE);
 }
 
 static struct xc_osdep_ops linux_gntshr_ops = {
#6 lore raw

Re: [PATCH] libxc: fix xc_gntshr_munmap semantic

Quoted 7 lines · Ian Campbell
Quoted 4 lines · Marek Marczykowski

"count" parameter should be pages count (as stated in comment in xenctrl.h), not bytes count.
This patch fixes also the only user of this function (in xen sources) - libvchan.

Looks ok to me but Daniel De Graaf wrote all this stuff, Ccing him.

This also looks good to me.

Quoted 65 lines
Quoted 64 lines
---
  tools/libvchan/init.c        |  4 ++--
  tools/libvchan/io.c          | 10 ++++++----
  tools/libxc/xc_linux_osdep.c |  2 +-
  3 files changed, 9 insertions(+), 7 deletions(-)
tools/libvchan/init.c +2 -2
index 0c7cff6..f0d2505 100644
@@ -129,9 +129,9 @@ out:
  	return ring_ref;
  out_unmap_left:
  	if (pages_left)
-		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer, pages_left * PAGE_SIZE);
+		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer, pages_left);
  out_ring:
-	xc_gntshr_munmap(ctrl->gntshr, ring, PAGE_SIZE);
+	xc_gntshr_munmap(ctrl->gntshr, ring, 1);
  	ring_ref = -1;
  	ctrl->ring = NULL;
  	ctrl->write.order = ctrl->read.order = 0;
tools/libvchan/io.c +6 -4
index 3c8d236..3040099 100644
@@ -324,16 +324,18 @@ void libxenvchan_close(struct libxenvchan *ctrl)
  	if (!ctrl)
  		return;
  	if (ctrl->read.order >= PAGE_SHIFT)
-		munmap(ctrl->read.buffer, 1 << ctrl->read.order);
+		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer,
+				1 << (ctrl->read.order - PAGE_SHIFT));
  	if (ctrl->write.order >= PAGE_SHIFT)
-		munmap(ctrl->write.buffer, 1 << ctrl->write.order);
+		xc_gntshr_munmap(ctrl->gntshr, ctrl->write.buffer,
+				1 << (ctrl->write.order - PAGE_SHIFT));
  	if (ctrl->ring) {
  		if (ctrl->is_server) {
  			ctrl->ring->srv_live = 0;
-			xc_gntshr_munmap(ctrl->gntshr, ctrl->ring, PAGE_SIZE);
+			xc_gntshr_munmap(ctrl->gntshr, ctrl->ring, 1);
  		} else {
  			ctrl->ring->cli_live = 0;
-			xc_gnttab_munmap(ctrl->gnttab, ctrl->ring, PAGE_SIZE);
+			xc_gnttab_munmap(ctrl->gnttab, ctrl->ring, 1);
  		}
  	}
  	if (ctrl->event) {
tools/libxc/xc_linux_osdep.c +1 -1
index 36832b6..3c43fca 100644
@@ -825,7 +825,7 @@ static void *linux_gntshr_share_pages(xc_gntshr *xch, xc_osdep_handle h,
  static int linux_gntshr_munmap(xc_gntshr *xcg, xc_osdep_handle h,
                                 void *start_address, uint32_t count)
  {
-    return munmap(start_address, count);
+    return munmap(start_address, count * XC_PAGE_SIZE);
  }
 
  static struct xc_osdep_ops linux_gntshr_ops = {
Signature · 2 lines
Daniel De Graaf
National Security Agency
#7 lore raw

Re: [PATCH] libxc: fix xc_gntshr_munmap semantic

Quoted 10 lines · Daniel De Graaf
Quoted 7 lines · Ian Campbell
Quoted 4 lines · Marek Marczykowski

"count" parameter should be pages count (as stated in comment in xenctrl.h), not bytes count.
This patch fixes also the only user of this function (in xen sources) - libvchan.

Looks ok to me but Daniel De Graaf wrote all this stuff, Ccing him.

This also looks good to me.

May I take that as an Ack (or a Reviewed-by if you prefer)?

Quoted 68 lines
Quoted 66 lines
Quoted 65 lines
---
  tools/libvchan/init.c        |  4 ++--
  tools/libvchan/io.c          | 10 ++++++----
  tools/libxc/xc_linux_osdep.c |  2 +-
  3 files changed, 9 insertions(+), 7 deletions(-)
tools/libvchan/init.c +2 -2
index 0c7cff6..f0d2505 100644
@@ -129,9 +129,9 @@ out:
  	return ring_ref;
  out_unmap_left:
  	if (pages_left)
-		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer, pages_left * PAGE_SIZE);
+		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer, pages_left);
  out_ring:
-	xc_gntshr_munmap(ctrl->gntshr, ring, PAGE_SIZE);
+	xc_gntshr_munmap(ctrl->gntshr, ring, 1);
  	ring_ref = -1;
  	ctrl->ring = NULL;
  	ctrl->write.order = ctrl->read.order = 0;
tools/libvchan/io.c +6 -4
index 3c8d236..3040099 100644
@@ -324,16 +324,18 @@ void libxenvchan_close(struct libxenvchan *ctrl)
  	if (!ctrl)
  		return;
  	if (ctrl->read.order >= PAGE_SHIFT)
-		munmap(ctrl->read.buffer, 1 << ctrl->read.order);
+		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer,
+				1 << (ctrl->read.order - PAGE_SHIFT));
  	if (ctrl->write.order >= PAGE_SHIFT)
-		munmap(ctrl->write.buffer, 1 << ctrl->write.order);
+		xc_gntshr_munmap(ctrl->gntshr, ctrl->write.buffer,
+				1 << (ctrl->write.order - PAGE_SHIFT));
  	if (ctrl->ring) {
  		if (ctrl->is_server) {
  			ctrl->ring->srv_live = 0;
-			xc_gntshr_munmap(ctrl->gntshr, ctrl->ring, PAGE_SIZE);
+			xc_gntshr_munmap(ctrl->gntshr, ctrl->ring, 1);
  		} else {
  			ctrl->ring->cli_live = 0;
-			xc_gnttab_munmap(ctrl->gnttab, ctrl->ring, PAGE_SIZE);
+			xc_gnttab_munmap(ctrl->gnttab, ctrl->ring, 1);
  		}
  	}
  	if (ctrl->event) {
tools/libxc/xc_linux_osdep.c +1 -1
index 36832b6..3c43fca 100644
@@ -825,7 +825,7 @@ static void *linux_gntshr_share_pages(xc_gntshr *xch, xc_osdep_handle h,
  static int linux_gntshr_munmap(xc_gntshr *xcg, xc_osdep_handle h,
                                 void *start_address, uint32_t count)
  {
-    return munmap(start_address, count);
+    return munmap(start_address, count * XC_PAGE_SIZE);
  }
 
  static struct xc_osdep_ops linux_gntshr_ops = {
#8 lore raw

Re: [PATCH] libxc: fix xc_gntshr_munmap semantic

Quoted 8 lines · Ian Campbell
Quoted 7 lines · Daniel De Graaf
Quoted 6 lines · Ian Campbell
Quoted 4 lines · Marek Marczykowski

"count" parameter should be pages count (as stated in comment in xenctrl.h), not bytes count.
This patch fixes also the only user of this function (in xen sources) - libvchan.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Looks ok to me but Daniel De Graaf wrote all this stuff, Ccing him.

This also looks good to me.

May I take that as an Ack (or a Reviewed-by if you prefer)?

Yes, either one is fine.

Quoted 68 lines
Quoted 67 lines
Quoted 66 lines
Quoted 65 lines
---
   tools/libvchan/init.c        |  4 ++--
   tools/libvchan/io.c          | 10 ++++++----
   tools/libxc/xc_linux_osdep.c |  2 +-
   3 files changed, 9 insertions(+), 7 deletions(-)
tools/libvchan/init.c +2 -2
index 0c7cff6..f0d2505 100644
@@ -129,9 +129,9 @@ out:
   	return ring_ref;
   out_unmap_left:
   	if (pages_left)
-		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer, pages_left * PAGE_SIZE);
+		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer, pages_left);
   out_ring:
-	xc_gntshr_munmap(ctrl->gntshr, ring, PAGE_SIZE);
+	xc_gntshr_munmap(ctrl->gntshr, ring, 1);
   	ring_ref = -1;
   	ctrl->ring = NULL;
   	ctrl->write.order = ctrl->read.order = 0;
tools/libvchan/io.c +6 -4
index 3c8d236..3040099 100644
@@ -324,16 +324,18 @@ void libxenvchan_close(struct libxenvchan *ctrl)
   	if (!ctrl)
   		return;
   	if (ctrl->read.order >= PAGE_SHIFT)
-		munmap(ctrl->read.buffer, 1 << ctrl->read.order);
+		xc_gntshr_munmap(ctrl->gntshr, ctrl->read.buffer,
+				1 << (ctrl->read.order - PAGE_SHIFT));
   	if (ctrl->write.order >= PAGE_SHIFT)
-		munmap(ctrl->write.buffer, 1 << ctrl->write.order);
+		xc_gntshr_munmap(ctrl->gntshr, ctrl->write.buffer,
+				1 << (ctrl->write.order - PAGE_SHIFT));
   	if (ctrl->ring) {
   		if (ctrl->is_server) {
   			ctrl->ring->srv_live = 0;
-			xc_gntshr_munmap(ctrl->gntshr, ctrl->ring, PAGE_SIZE);
+			xc_gntshr_munmap(ctrl->gntshr, ctrl->ring, 1);
   		} else {
   			ctrl->ring->cli_live = 0;
-			xc_gnttab_munmap(ctrl->gnttab, ctrl->ring, PAGE_SIZE);
+			xc_gnttab_munmap(ctrl->gnttab, ctrl->ring, 1);
   		}
   	}
   	if (ctrl->event) {
tools/libxc/xc_linux_osdep.c +1 -1
index 36832b6..3c43fca 100644
@@ -825,7 +825,7 @@ static void *linux_gntshr_share_pages(xc_gntshr *xch, xc_osdep_handle h,
   static int linux_gntshr_munmap(xc_gntshr *xcg, xc_osdep_handle h,
                                  void *start_address, uint32_t count)
   {
-    return munmap(start_address, count);
+    return munmap(start_address, count * XC_PAGE_SIZE);
   }
 
   static struct xc_osdep_ops linux_gntshr_ops = {
#9 lore raw

Re: [PATCH] libxc: fix xc_gntshr_munmap semantic

Quoted 11 lines · Daniel De Graaf
Quoted 10 lines · Ian Campbell
Quoted 9 lines · Daniel De Graaf
Quoted 7 lines · Ian Campbell
Quoted 4 lines · Marek Marczykowski

"count" parameter should be pages count (as stated in comment in xenctrl.h), not bytes count.
This patch fixes also the only user of this function (in xen sources) - libvchan.

Looks ok to me but Daniel De Graaf wrote all this stuff, Ccing him.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

This also looks good to me.

May I take that as an Ack (or a Reviewed-by if you prefer)?

Yes, either one is fine.

Is the change from munmap to xc_gntshr_munmap, which wasn't mentioned in the changelog description (tut tut), correct? It seems like these mappings can either be establish with xc_gntshr_share_pages or with "= ((void*)ctrl->ring) + LARGE_RING_OFFSET", with the second one being the case I'm concerned about... Should it not duplicate the switch used at mapping time?

Ian.

#10 lore raw

Re: [PATCH] libxc: fix xc_gntshr_munmap semantic

Quoted 20 lines · Ian Campbell
Quoted 11 lines · Daniel De Graaf
Quoted 10 lines · Ian Campbell
Quoted 9 lines · Daniel De Graaf
Quoted 7 lines · Ian Campbell
Quoted 4 lines · Marek Marczykowski

"count" parameter should be pages count (as stated in comment in xenctrl.h), not bytes count.
This patch fixes also the only user of this function (in xen sources) - libvchan.

Looks ok to me but Daniel De Graaf wrote all this stuff, Ccing him.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

This also looks good to me.

May I take that as an Ack (or a Reviewed-by if you prefer)?

Yes, either one is fine.

Quoted 9 lines

Is the change from munmap to xc_gntshr_munmap, which wasn't mentioned in the changelog description (tut tut), correct? It seems like these mappings can either be establish with xc_gntshr_share_pages or with "= ((void*)ctrl->ring) + LARGE_RING_OFFSET", with the second one being the case I'm concerned about... Should it not duplicate the switch used at mapping time?

Ian.

The unmap is only done if (ctrl->read.order >= PAGE_SHIFT), which is a functional duplicate of the switch statement. However, this does bring up a different issue: the munmap() should be replaced with the correct one of xc_gntshr_munmap and xc_gnttab_munmap depending on ctrl->is_server, in the same way as ctrl->ring is unmapped.

Signature · 2 lines
Daniel De Graaf
National Security Agency
#11 lore raw

Re: [PATCH] libxc: fix xc_gntshr_munmap semantic

Quoted 28 lines · Daniel De Graaf
Quoted 27 lines · Ian Campbell
Quoted 11 lines · Daniel De Graaf
Quoted 10 lines · Ian Campbell
Quoted 9 lines · Daniel De Graaf
Quoted 7 lines · Ian Campbell
Quoted 4 lines · Marek Marczykowski

"count" parameter should be pages count (as stated in comment in xenctrl.h), not bytes count.
This patch fixes also the only user of this function (in xen sources) - libvchan.

Looks ok to me but Daniel De Graaf wrote all this stuff, Ccing him.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

This also looks good to me.

May I take that as an Ack (or a Reviewed-by if you prefer)?

Yes, either one is fine.

Is the change from munmap to xc_gntshr_munmap, which wasn't mentioned in the changelog description (tut tut), correct? It seems like these mappings can either be establish with xc_gntshr_share_pages or with "= ((void*)ctrl->ring) + LARGE_RING_OFFSET", with the second one being the case I'm concerned about... Should it not duplicate the switch used at mapping time?

Quoted 5 lines
Quoted 2 lines

Ian.

The unmap is only done if (ctrl->read.order >= PAGE_SHIFT), which is a functional duplicate of the switch statement.

It's a pretty opaque transformation ;-)

But for e.g. order 9, it isn't the same is it? The switch on alloc will hit the default case while the free won't hit this if statement.

Quoted 4 lines

However, this does bring
up a different issue: the munmap() should be replaced with the correct one of xc_gntshr_munmap and xc_gnttab_munmap depending on ctrl->is_server, in the same way as ctrl->ring is unmapped.

OK, I take it the Ack is rescinded for the time being?

Ian.

#12 lore raw

Re: [PATCH] libxc: fix xc_gntshr_munmap semantic

Quoted 32 lines · Ian Campbell
Quoted 31 lines · Daniel De Graaf
Quoted 29 lines · Ian Campbell
Quoted 11 lines · Daniel De Graaf
Quoted 10 lines · Ian Campbell
Quoted 9 lines · Daniel De Graaf
Quoted 7 lines · Ian Campbell
Quoted 4 lines · Marek Marczykowski

"count" parameter should be pages count (as stated in comment in xenctrl.h), not bytes count.
This patch fixes also the only user of this function (in xen sources) - libvchan.

Looks ok to me but Daniel De Graaf wrote all this stuff, Ccing him.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

This also looks good to me.

May I take that as an Ack (or a Reviewed-by if you prefer)?

Yes, either one is fine.

Is the change from munmap to xc_gntshr_munmap, which wasn't mentioned in the changelog description (tut tut), correct? It seems like these mappings can either be establish with xc_gntshr_share_pages or with "= ((void*)ctrl->ring) + LARGE_RING_OFFSET", with the second one being the case I'm concerned about... Should it not duplicate the switch used at mapping time?

Ian.

Quoted 7 lines
Quoted 2 lines

The unmap is only done if (ctrl->read.order >= PAGE_SHIFT), which is a functional duplicate of the switch statement.

It's a pretty opaque transformation ;-)

But for e.g. order 9, it isn't the same is it? The switch on alloc will hit the default case while the free won't hit this if statement.

Order 9 isn't valid: the only permitted values are 10, 11, and 12+, all of which are handled correctly here.

Quoted 7 lines
Quoted 4 lines

However, this does bring
up a different issue: the munmap() should be replaced with the correct one of xc_gntshr_munmap and xc_gnttab_munmap depending on ctrl->is_server, in the same way as ctrl->ring is unmapped.

OK, I take it the Ack is rescinded for the time being?

The change is still a strict improvement over the old code, but since more changes are needed to complete the fix, it is rescinded for now.

Signature · 2 lines
Daniel De Graaf
National Security Agency
#13 lore raw

Re: [PATCH] libxc: fix xc_gntshr_munmap semantic

Quoted 36 lines · Daniel De Graaf
Quoted 35 lines · Ian Campbell
Quoted 33 lines · Daniel De Graaf
Quoted 20 lines · Ian Campbell
Quoted 11 lines · Daniel De Graaf
Quoted 10 lines · Ian Campbell
Quoted 9 lines · Daniel De Graaf
Quoted 7 lines · Ian Campbell
Quoted 4 lines · Marek Marczykowski

"count" parameter should be pages count (as stated in comment in xenctrl.h), not bytes count.
This patch fixes also the only user of this function (in xen sources) - libvchan.

Looks ok to me but Daniel De Graaf wrote all this stuff, Ccing him.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

This also looks good to me.

May I take that as an Ack (or a Reviewed-by if you prefer)?

Yes, either one is fine.

Quoted 9 lines

Is the change from munmap to xc_gntshr_munmap, which wasn't mentioned in the changelog description (tut tut), correct? It seems like these mappings can either be establish with xc_gntshr_share_pages or with "= ((void*)ctrl->ring) + LARGE_RING_OFFSET", with the second one being the case I'm concerned about... Should it not duplicate the switch used at mapping time?

Ian.

The unmap is only done if (ctrl->read.order >= PAGE_SHIFT), which is a functional duplicate of the switch statement.

Quoted 7 lines
Quoted 4 lines

It's a pretty opaque transformation ;-)

But for e.g. order 9, it isn't the same is it? The switch on alloc will hit the default case while the free won't hit this if statement.

Order 9 isn't valid: the only permitted values are 10, 11, and 12+, all of which are handled correctly here.

Ah, I missed the limit check just above, good.

Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

However, this does bring
up a different issue: the munmap() should be replaced with the correct one of xc_gntshr_munmap and xc_gnttab_munmap depending on ctrl->is_server, in the same way as ctrl->ring is unmapped.

OK, I take it the Ack is rescinded for the time being?

The change is still a strict improvement over the old code, but since more changes are needed to complete the fix, it is rescinded for now.

It might be best to get the mechanical API change as a separate patch (e.g. without adding new callers of the function, correct or otherwise) and handle the correction of the munmap calls separately.

Ian.