tests/resource: Extend to check that the grant frames are mapped correctly
PATCH 1/1 tests/resource: Extend to check that the grant frames are mapped correctly
Previously, we checked that we could map 40 pages with nothing complaining. Now we're adding extra logic to check that those 40 frames are "correct".
---
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>
--- tools/tests/resource/Makefile | 2 + tools/tests/resource/test-resource.c | 81 +++++++++++++++++++++++++++++++++--- 2 files changed, 77 insertions(+), 6 deletions(-)
tools/tests/resource/Makefile +2 -0
@@ -31,10 +31,12 @@ CFLAGS += -Werror CFLAGS += $(CFLAGS_xeninclude) CFLAGS += $(CFLAGS_libxenctrl) CFLAGS += $(CFLAGS_libxenforeginmemory) +CFLAGS += $(CFLAGS_libxengnttab) CFLAGS += $(APPEND_CFLAGS) LDFLAGS += $(LDLIBS_libxenctrl) LDFLAGS += $(LDLIBS_libxenforeignmemory) +LDFLAGS += $(LDLIBS_libxengnttab) LDFLAGS += $(APPEND_LDFLAGS) %.o: Makefile
tools/tests/resource/test-resource.c +75 -6
139 lines not on this page · raw message
Signature · 1 line
2.11.0
tools/tests/resource/test-resource.c static void test_gnttab(uint32_t domid, unsigned int nr_frames) · line 58
Quoted 6 lines · Jane Malalane
tools/tests/resource/test-resource.c +1
-1@@ -51,18 +55,52 @@ static void test_gnttab(uint32_t domid, unsigned int nr_frames) res =xenforeignmemory_map_resource ( fh, domid, XENMEM_resource_grant_table, XENMEM_resource_grant_table_id_shared,0 , size >>XC_PAGE_SHIFT , - &addr,PROT_READ |PROT_WRITE ,0 ); + (void *)&gnttab,PROT_READ |PROT_WRITE ,0 );
While in testing code I'm not as concerned about casts, I think it would be better to cast to a visibly correct type, i.e. maintaining the levels of indirection (void **). Alternatively you could (ab)use grants here, allowing to drop the cast, by then assigning grants to gnttab.
Quoted 10 lines
tools/tests/resource/test-resource.c +3
-1/* * Failure here with E2BIG indicates Xen is missing the bugfix to map * resources larger than 32 frames. */ if ( !res ) -return fail (" Fail: Map %d - %s\n" , errno,strerror (errno)); +return fail (" Fail: Map grant table %d - %s\n" , errno,strerror (errno)); +/* Put each gref at a unique offset in its frame. */ +for (unsigned int i =0 ; i < nr_frames; i++ )
tools/tests/resource/test-resource.c static void test_gnttab(uint32_t domid, unsigned int nr_frames) · line 78
Quoted 10 lines
tools/tests/resource/test-resource.c +10
-0+ { +unsigned int gref = i * (XC_PAGE_SIZE /sizeof (*gnttab)) + i; + + refs[i] = gref; + domids[i] = domid; + + gnttab[gref].domid =0 ; + gnttab[gref].frame = gfn; + gnttab[gref].flags = GTF_permit_access; + }
To make obvious that you're done with gnttab[], perhaps better unmap it here rather than at the bottom?
tools/tests/resource/test-resource.c static void test_gnttab(uint32_t domid, unsigned int nr_frames) · line 86
Quoted 7 lines
tools/tests/resource/test-resource.c +7
-0+/* Map grants. */ + grants =xengnttab_map_grant_refs (gh, nr_frames, domids, refs,PROT_READ |PROT_WRITE ); + +/* Failure here indicates either that the frames were not mapped +* in the correct order or xenforeignmemory_map_resource() didn't +* give us the frames we asked for to begin with. +*/
Nit: Comment style.
tools/tests/resource/test-resource.c static void test_domain_configurations(void) · line 165
Quoted 6 lines
tools/tests/resource/test-resource.c +1
-1@@ -123,8 +162,25 @@ static void test_domain_configurations(void)printf (" Created d%u\n" , domid); -test_gnttab (domid, t->create.max_grant_frames); + rc =xc_domain_setmaxmem (xch, domid,-1 );
That's an unbelievably large upper bound that you set. Since you populate ...
tools/tests/resource/test-resource.c static void test_domain_configurations(void) · line 173
Quoted 8 lines
tools/tests/resource/test-resource.c +8
-0+if ( rc ) + { +fail (" Failed to set max memory for domain: %d - %s\n" , + errno,strerror (errno)); + goto test_done; + } + + rc =xc_domain_populate_physmap_exact (xch, domid,ARRAY_SIZE (ram),0 ,0 , ram);
... only a single page, can't you get away with a much smaller value? And without engaging truncation from uint64_t to unsigned int in XEN_DOMCTL_max_mem handling in the hypervisor (which imo would better yield an error)?
Jan
Quoted 10 lines · Jan Beulich
Quoted 8 lines · Jane Malalane
/* * Failure here with E2BIG indicates Xen is missing the bugfix to map * resources larger than 32 frames. */ if ( !res )tools/tests/resource/test-resource.c +1
-1-return fail (" Fail: Map %d - %s\n" , errno,strerror (errno)); +return fail (" Fail: Map grant table %d - %s\n" , errno,strerror (errno));
Quoted 14 lines
tools/tests/resource/test-resource.c static void test_gnttab(uint32_t domid, unsigned int nr_frames) · line 78
Quoted 12 lines
tools/tests/resource/test-resource.c +12
-0+/* Put each gref at a unique offset in its frame. */ +for (unsigned int i =0 ; i < nr_frames; i++ ) + { +unsigned int gref = i * (XC_PAGE_SIZE /sizeof (*gnttab)) + i; + + refs[i] = gref; + domids[i] = domid; + + gnttab[gref].domid =0 ; + gnttab[gref].frame = gfn; + gnttab[gref].flags = GTF_permit_access; + }To make obvious that you're done with gnttab[], perhaps better unmap it here rather than at the bottom?
This is just test code. We could unmap it earlier, but that makes it irritating if you ever need to insert printk()'s.
Quoted 17 lines
tools/tests/resource/test-resource.c static void test_domain_configurations(void) · line 165
Quoted 6 lines
tools/tests/resource/test-resource.c +1
-1@@ -123,8 +162,25 @@ static void test_domain_configurations(void)printf (" Created d%u\n" , domid); -test_gnttab (domid, t->create.max_grant_frames); + rc =xc_domain_setmaxmem (xch, domid,-1 );That's an unbelievably large upper bound that you set. Since you populate ...
tools/tests/resource/test-resource.c static void test_domain_configurations(void) · line 173
Quoted 8 lines
tools/tests/resource/test-resource.c +8
-0+if ( rc ) + { +fail (" Failed to set max memory for domain: %d - %s\n" , + errno,strerror (errno)); + goto test_done; + } + + rc =xc_domain_populate_physmap_exact (xch, domid,ARRAY_SIZE (ram),0 ,0 , ram);
Quoted 1 line
... only a single page, can't you get away with a much smaller value?
Yes, but again, this is test code.
Furthermore, there are other plans for further testing which would mean 1 wouldn't be appropriate here. All we want is "don't choke on limits while we're performing testing".
~Andrew
Quoted 6 lines · Jane Malalane
Previously, we checked that we could map 40 pages with nothing complaining. Now we're adding extra logic to check that those 40 frames are "correct".
Suggested-by Andrew Cooper <[email protected]>Signed-off-by Jane Malalane <[email protected]>
Ian: I'd like this to be considered for 4.16. It is extending an existing test case with better error detection.
It was a task I didn't get around to at the time, because of the 4.15 release freeze... How time flies.
Anyway, it is very low risk to the release, and 0 risk for anyone who doesn't run the tests...
~Andrew
Andrew Cooper writes ("Re: [PATCH for-4.16] tests/resource: Extend to check that the grant frames are mapped correctly"):
Quoted 8 lines · Jane Malalane
Quoted 6 lines
Previously, we checked that we could map 40 pages with nothing complaining. Now we're adding extra logic to check that those 40 frames are "correct".
Suggested-by Andrew Cooper <[email protected]>Signed-off-by Jane Malalane <[email protected]>
Quoted 8 lines
Ian: I'd like this to be considered for 4.16. It is extending an existing test case with better error detection.
It was a task I didn't get around to at the time, because of the 4.15 release freeze... How time flies.
Anyway, it is very low risk to the release, and 0 risk for anyone who doesn't run the tests...
Of course.
Ian.