tools/libxc: linux: Don't use getpagesize() when unmapping the grants
PATCH 1/1 tools/libxc: linux: Don't use getpagesize() when unmapping the grants
The grants are based on the Xen granularity (i.e 4KB). While the function to map grants for Linux (linux_gnttab_grant_map) is using the correct size (XC_PAGE_SIZE), the unmap one (linux_gnttab_munmap) is using getpagesize().
On domain using a page granularity different than Xen (this is the case for AARCH64 guest using 64KB page), the unmap will be called with the wrong size.
---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>
This is a candidate for Xen 4.6 and backport for Xen 4.5. There is no functional changes for 4KB domain (i.e x86, arm32, arm64 when 4KB is used) but fixes a latent problem when the domain is using 64KB page on ARM64.
The mmap is done correctly use XC_PAGE_SIZE but not the munmap. This will likely fail to unmap. I don't think it will unmap too much.
I grepped getpagesize in the tools, and so far I haven't found any other in Xen specific code. There is some in blktap2 and QEMU. I don't think the former is that important for ARM64. I will take care of the latter in a separate series.
--- tools/libxc/xc_linux_osdep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxc/xc_linux_osdep.c +1 -1
@@ -742,7 +742,7 @@ static int linux_gnttab_munmap(xc_gnttab *xcg, xc_osdep_handle h, }/* Next, unmap the memory. */ -if ( (rc =munmap (start_address, count *getpagesize ())) ) +if ( (rc =munmap (start_address, count *XC_PAGE_SIZE )) )return rc;/* Finally, unmap the driver slots used to store the grant information. */
Signature · 1 line
2.1.4
Quoted 9 lines · Julien Grall
The grants are based on the Xen granularity (i.e 4KB). While the function to map grants for Linux (
linux_gnttab_grant_map) is using the correct size (XC_PAGE_SIZE), the unmap one (linux_gnttab_munmap) is usinggetpagesize().On domain using a page granularity different than Xen (this is the case for AARCH64 guest using 64KB page), the unmap will be called with the wrong size.
Quoted 8 lines
Signed-off-by Julien Grall <[email protected]>---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>
I think this is a bug fix and should be applied for 4.6.
Ian Campbell
Acked-byQuoted 13 lines · Wei Liu
Quoted 12 lines · Julien Grall
The grants are based on the Xen granularity (i.e 4KB). While the function
to map grants for Linux (linux_gnttab_grant_map) is using the correct size (XC_PAGE_SIZE), the unmap one (linux_gnttab_munmap) is usinggetpagesize().On domain using a page granularity different than Xen (this is the case for AARCH64 guest using 64KB page), the unmap will be called with the wrong size.
Signed-off-by Julien Grall <[email protected]>
Quoted 8 lines
Quoted 6 lines
---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>Acked-by Wei Liu <[email protected]>
Quoted 1 line
I think this is a bug fix and should be applied for 4.6.
Agreed.
WRT to backports for 4.5 I'd appreciate being given a full list of required fixes once everything is in place and working for 4.6/devbranch rather than my tracking it piecemeal.
Ian.
Hi Ian,
Quoted 25 lines · Ian Campbell
Quoted 13 lines · Wei Liu
Quoted 12 lines · Julien Grall
The grants are based on the Xen granularity (i.e 4KB). While the function
to map grants for Linux (linux_gnttab_grant_map) is using the correct size (XC_PAGE_SIZE), the unmap one (linux_gnttab_munmap) is usinggetpagesize().On domain using a page granularity different than Xen (this is the case for AARCH64 guest using 64KB page), the unmap will be called with the wrong size.
Signed-off-by Julien Grall <[email protected]>Quoted 8 lines
Quoted 6 lines
---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>Acked-by Wei Liu <[email protected]>Acked-by Ian Campbell <[email protected]>
Quoted 7 lines
Quoted 1 line
I think this is a bug fix and should be applied for 4.6.
Agreed.
WRT to backports for 4.5 I'd appreciate being given a full list of required fixes once everything is in place and working for 4.6/devbranch rather than my tracking it piecemeal.
I have a working branch with Xen tools running on 64KB, and I didn't expected to find another problem.
I spotted this one by reading the code and see inconsistency between the mmap and the mmunmap. And I'm sure I haven't spot all the things because testing every configuration to see if 64KB guest are working is a huge work.
Anyway, I will send a mail with all the patch to backport.
Regards,
Signature · 1 line
Julien Grall
Quoted 22 lines · Ian Campbell
Quoted 21 lines · Wei Liu
Quoted 19 lines · Julien Grall
The grants are based on the Xen granularity (i.e 4KB). While the function
to map grants for Linux (linux_gnttab_grant_map) is using the correct size (XC_PAGE_SIZE), the unmap one (linux_gnttab_munmap) is usinggetpagesize().On domain using a page granularity different than Xen (this is the case
for AARCH64 guest using 64KB page), the unmap will be called with the wrong size.Signed-off-by Julien Grall <[email protected]>---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>
Quoted 5 lines
Quoted 1 line
Acked-by Wei Liu <[email protected]>Acked-by Ian Campbell <[email protected]>Quoted 1 line
I think this is a bug fix and should be applied for 4.6.
I took this as a release ack and applied.