diff --git a/drivers/xen/core/gnttab.c b/drivers/xen/core/gnttab.c index 5314932..5f27756 100644 --- a/drivers/xen/core/gnttab.c +++ b/drivers/xen/core/gnttab.c @@ -654,28 +654,31 @@ static inline unsigned int max_nr_grant_frames(void) return xen_max; } -static void gnttab_request_version(void) +static int gnttab_request_version(void) { int rc; struct gnttab_set_version gsv; + int version = 2; - gsv.version = 2; + gsv.version = version; rc = HYPERVISOR_grant_table_op(GNTTABOP_set_version, &gsv, 1); if (rc == 0) { - grant_table_version = 2; - printk("<0>Grant table version 2.\n"); + grant_table_version = version; + printk("<0>Grant table version %d.\n", grant_table_version); } else { - if (grant_table_version == 2) { + if (rc == -ENOSYS && grant_table_version == 2) { /* If we've already used version 2 features, but then suddenly discover that they're not available (e.g. migrating to an older version of Xen), almost unbounded badness can happen. */ panic("we need grant tables version 2, but only version 1 is available"); + grant_table_version = 1; + printk("<0>Grant table version 1.\n"); + rc = 0; } - grant_table_version = 1; - printk("<0>Grant table version 1.\n"); } + return rc; } #ifdef CONFIG_XEN @@ -1011,7 +1014,10 @@ EXPORT_SYMBOL(gnttab_post_map_adjust); int gnttab_resume(void) { - gnttab_request_version(); + int rc; + + if (rc = gnttab_request_version()) + return rc; if (max_nr_grant_frames() < nr_grant_frames) return -ENOSYS; return gnttab_map(0, nr_grant_frames - 1); @@ -1092,8 +1098,10 @@ int gnttab_resume(void) { unsigned int max_nr_gframes, nr_gframes; unsigned int max_nr_sframes, nr_sframes; + int rc; - gnttab_request_version(); + if (rc = gnttab_request_version()) + return rc; nr_gframes = nr_grant_frames; max_nr_gframes = max_nr_grant_frames();