linux_gntshr_munmap: munmap takes a length, not a page count
PATCH 1/1 linux_gntshr_munmap: munmap takes a length, not a page count
This fixes a bug where if a client shares more than 1 page, the munmap call fails to clean up everything. A process which does a lot of sharing and unsharing can run out of resources.
--- tools/libxc/xc_linux_osdep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxc/xc_linux_osdep.c +1 -1
@@ -847,7 +847,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.7.10.4
Quoted 5 lines · David Scott
This fixes a bug where if a client shares more than 1 page, the munmap call fails to clean up everything. A process which does a lot of sharing and unsharing can run out of resources.
Signed-off-by David Scott <[email protected]>
Great catch!
Quoted 19 lines
tools/libxc/xc_linux_osdep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/libxc/xc_linux_osdep.c +1
-1@@ -847,7 +847,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.7.10.4
Quoted 3 lines · David Scott
This fixes a bug where if a client shares more than 1 page, the munmap call fails to clean up everything. A process which does a lot of sharing and unsharing can run out of resources.
The doc comment on xc_gntshr_munmap does say count is in pages, so your change is correct but all of the in tree callers seem to pass a number of bytes not a number of pages. i.e. everything in tools/libvchan passes n*PAGE_SIZE.
So I don't think this change is complete without also updating those.
Ian.
Quoted 19 lines
Signed-off-by David Scott <[email protected]>--- tools/libxc/xc_linux_osdep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/libxc/xc_linux_osdep.c +1
-1@@ -847,7 +847,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 = {
Quoted 11 lines · Ian Campbell
Quoted 3 lines · David Scott
This fixes a bug where if a client shares more than 1 page, the munmap call fails to clean up everything. A process which does a lot of sharing and unsharing can run out of resources.
The doc comment on
xc_gntshr_munmapdoes say count is in pages, so your change is correct but all of the in tree callers seem to pass a number of bytes not a number of pages. i.e. everything intools/libvchanpasses n*PAGE_SIZE.So I don't think this change is complete without also updating those.
Would the corrent non-ABI/API-breaking fix be to just update the documentation?
David
Quoted 11 lines · David Vrabel
Quoted 10 lines · Ian Campbell
Quoted 3 lines · David Scott
This fixes a bug where if a client shares more than 1 page, the munmap call fails to clean up everything. A process which does a lot of sharing and unsharing can run out of resources.
The doc comment on
xc_gntshr_munmapdoes say count is in pages, so your change is correct but all of the in tree callers seem to pass a number of bytes not a number of pages. i.e. everything intools/libvchanpasses n*PAGE_SIZE.
Quoted 4 lines
Quoted 1 line
So I don't think this change is complete without also updating those.
Would the corrent non-ABI/API-breaking fix be to just update the documentation?
libxc doesn't have a stable API or ABI.
My thinking in this case was that @count being pages was consistent with other related functions in the API and also avoids issues of what to do if count%4096 != 0.
Ian.
Quoted 12 lines · Ian Campbell
Quoted 11 lines · David Vrabel
Quoted 10 lines · Ian Campbell
Quoted 3 lines · David Scott
This fixes a bug where if a client shares more than 1 page, the munmap call fails to clean up everything. A process which does a lot of sharing and unsharing can run out of resources.
The doc comment on
xc_gntshr_munmapdoes say count is in pages, so your change is correct but all of the in tree callers seem to pass a number of bytes not a number of pages. i.e. everything intools/libvchanpasses n*PAGE_SIZE.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
So I don't think this change is complete without also updating those.
Would the corrent non-ABI/API-breaking fix be to just update the documentation?
libxc doesn't have a stable API or ABI.
xc_gntshr_*() really should be part of a separate libxc-for-domu that does have a stable ABI. But since it isn't yet...
Quoted 3 lines
My thinking in this case was that @count being pages was consistent with other related functions in the API and also avoids issues of what to do if count%4096 != 0.
...this sounds reasonable.
David
Quoted 15 lines · David Vrabel
Quoted 14 lines · Ian Campbell
Quoted 13 lines · David Vrabel
Quoted 11 lines · Ian Campbell
Quoted 3 lines · David Scott
This fixes a bug where if a client shares more than 1 page, the munmap call fails to clean up everything. A process which does a lot of sharing and unsharing can run out of resources.
The doc comment on
xc_gntshr_munmapdoes say count is in pages, so your change is correct but all of the in tree callers seem to pass a number of bytes not a number of pages. i.e. everything intools/libvchanpasses n*PAGE_SIZE.So I don't think this change is complete without also updating those.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Would the corrent non-ABI/API-breaking fix be to just update the documentation?
libxc doesn't have a stable API or ABI.
xc_gntshr_*() really should be part of a separate libxc-for-domu that does have a stable ABI.
This hadn't occurred to me, but yes, this does sound sensible.
Quoted 7 lines
But since it isn't yet...
Quoted 3 lines
My thinking in this case was that @count being pages was consistent with other related functions in the API and also avoids issues of what to do if count%4096 != 0.
...this sounds reasonable.
Thanks.
Ian
Quoted 13 lines · Ian Campbell
Quoted 12 lines · David Vrabel
Quoted 11 lines · Ian Campbell
Quoted 10 lines · David Vrabel
Quoted 9 lines · Ian Campbell
Quoted 3 lines · David Scott
This fixes a bug where if a client shares more than 1 page, the munmap call fails to clean up everything. A process which does a lot of sharing and unsharing can run out of resources.
The doc comment on
xc_gntshr_munmapdoes say count is in pages, so your change is correct but all of the in tree callers seem to pass a number of bytes not a number of pages. i.e. everything intools/libvchanpasses n*PAGE_SIZE.
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
So I don't think this change is complete without also updating those.
Would the corrent non-ABI/API-breaking fix be to just update the documentation?
libxc doesn't have a stable API or ABI.
xc_gntshr_*() really should be part of a separate libxc-for-domu that does have a stable ABI.
This hadn't occurred to me, but yes, this does sound sensible.
Currently, all domU event and grant operations require libxc, including the use of libxenstore.
I have raised this before, and believe there is a line item defered until 4.6 to cleave libxc into several pieces, to avoid needing to put libxc into all domUs to use the xenstore-* binaries. libxenevent and libxengrant seem like plausible library names.
~Andrew
Quoted 9 lines · Ian Campbell
Quoted 3 lines · David Scott
This fixes a bug where if a client shares more than 1 page, the munmap call fails to clean up everything. A process which does a lot of sharing and unsharing can run out of resources.
The doc comment on
xc_gntshr_munmapdoes say count is in pages, so your change is correct but all of the in tree callers seem to pass a number of bytes not a number of pages. i.e. everything intools/libvchanpasses n*PAGE_SIZE.
Good point.
Quoted 1 line
So I don't think this change is complete without also updating those.
I’ll resubmit with the in-tree callers fixed.
Thanks,
Dave
Quoted 24 lines
Ian.
Quoted 19 lines
Signed-off-by David Scott <[email protected]>---
tools/libxc/xc_linux_osdep.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)tools/libxc/xc_linux_osdep.c +1
-1@@ -847,7 +847,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 = {
Quoted 13 lines · David Scott
Quoted 9 lines · Ian Campbell
Quoted 3 lines · David Scott
This fixes a bug where if a client shares more than 1 page, the munmap call fails to clean up everything. A process which does a lot of sharing and unsharing can run out of resources.
The doc comment on
xc_gntshr_munmapdoes say count is in pages, so your change is correct but all of the in tree callers seem to pass a number of bytes not a number of pages. i.e. everything intools/libvchanpasses n*PAGE_SIZE.
Quoted 5 lines
Good point.
Quoted 1 line
So I don't think this change is complete without also updating those.
I’ll resubmit with the in-tree callers fixed.
Also it looks like xc_gnttab_munmap (gnttab not gntshr) uses pages in both the API and implementation, but libvchan is supplying bytes. I’ll fix vchan here too.
Dave
Quoted 29 lines
Thanks,
DaveQuoted 24 lines
Ian.
Quoted 19 lines
Signed-off-by David Scott <[email protected]>---
tools/libxc/xc_linux_osdep.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)tools/libxc/xc_linux_osdep.c +1
-1@@ -847,7 +847,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 = {
PATCH v2 1/1 linux_gntshr_munmap: munmap takes a length, not a page count
In reply to David ScottThis fixes a bug where if a client shares more than 1 page, the munmap call fails to clean up everything. A process which does a lot of sharing and unsharing can run out of resources.
This patch also fixes in-tree callers of
- xc_gntshr_munmap
- xc_gnttab_munmap
to supply page counts rather than lengths.
--- tools/libvchan/init.c | 8 ++++---- tools/libvchan/io.c | 4 ++-- tools/libxc/xc_linux_osdep.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-)
tools/libvchan/init.c +4 -4
@@ -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 ;
@@ -204,9 +204,9 @@ static int init_gnt_cli(struct libxenvchan *ctrl, int domain, uint32_t ring_ref) out_unmap_left:if (ctrl->write.order >=PAGE_SHIFT )xc_gnttab_munmap (ctrl->gnttab, ctrl->write.buffer, -1 << ctrl->write.order); +1 << (ctrl->write.order -PAGE_SHIFT )); out_unmap_ring: -xc_gnttab_munmap (ctrl->gnttab, ctrl->ring,PAGE_SIZE ); +xc_gnttab_munmap (ctrl->gnttab, ctrl->ring,1 ); ctrl->ring =0 ; ctrl->write.order = ctrl->read.order =0 ; rv =-1 ;
tools/libvchan/io.c +2 -2
@@ -365,10 +365,10 @@ void libxenvchan_close(struct libxenvchan *ctrl)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
@@ -847,7 +847,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.7.10.4
Quoted 10 lines · David Scott
This fixes a bug where if a client shares more than 1 page, the munmap call fails to clean up everything. A process which does a lot of sharing and unsharing can run out of resources.
This patch also fixes in-tree callers of
-xc_gntshr_munmap
-xc_gnttab_munmap
to supply page counts rather than lengths.Signed-off-by David Scott <[email protected]>
Acked + applied, thanks.