diff --git a/tools/tests/resource/test-resource.c b/tools/tests/resource/test-resource.c index 1caaa60e62..bf485baff2 100644 --- a/tools/tests/resource/test-resource.c +++ b/tools/tests/resource/test-resource.c @@ -63,6 +63,21 @@ static void test_gnttab(uint32_t domid, unsigned int nr_frames) rc = xenforeignmemory_unmap_resource(fh, res); if ( rc ) return fail(" Fail: Unmap %d - %s\n", errno, strerror(errno)); + + /* + * Verify that an attempt to map the status frames fails, as the domain is + * in gnttab v1 mode. + */ + res = xenforeignmemory_map_resource( + fh, domid, XENMEM_resource_grant_table, + XENMEM_resource_grant_table_id_status, 0, 1, + (void **)&gnttab, PROT_READ | PROT_WRITE, 0); + + if ( res ) + { + fail(" Fail: Managed to map gnttab v2 status frames in v1 mode\n"); + xenforeignmemory_unmap_resource(fh, res); + } } static void test_domain_configurations(void) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 0523beb9b7..01e426c67f 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -4138,7 +4138,7 @@ int gnttab_acquire_resource( * on non-error paths, and hence it needs setting to NULL at the top of the * function. Leave some runtime safety. */ - if ( !vaddrs ) + if ( !rc && !vaddrs ) { ASSERT_UNREACHABLE(); rc = -ENODATA;