[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v2] xen: fail gnttab_grow_table() in case of missing allocations
In case gnttab_grow_table() is being called without grant_table_set_limits() having been called for the domain, e.g. in case of a toolstack error, fail the function instead of crashing the system. While at it let gnttab_grow_table() return a proper error code instead of 1 for success. Signed-off-by: Juergen Gross <jgross@xxxxxxxx> --- V2: - use gprintk() instead of gdprintk() (Roger Pau Monne) - let gnttab_grow_table() return an error code (Andrew Cooper) --- xen/common/grant_table.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 71706f5cba..144fa7c50f 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -1669,7 +1669,11 @@ gnttab_grow_table(struct domain *d, unsigned int req_nr_frames) struct grant_table *gt = d->grant_table; unsigned int i, j; - ASSERT(gt->active); + if ( unlikely(!gt->active) ) + { + gprintk(XENLOG_WARNING, "grant_table_set_limits() call missing.\n"); + return -ENODEV; + } if ( req_nr_frames < INITIAL_NR_GRANT_FRAMES ) req_nr_frames = INITIAL_NR_GRANT_FRAMES; @@ -1710,7 +1714,7 @@ gnttab_grow_table(struct domain *d, unsigned int req_nr_frames) gnttab_create_shared_page(d, gt, i); gt->nr_grant_frames = req_nr_frames; - return 1; + return 0; shared_alloc_failed: for ( i = nr_grant_frames(gt); i < req_nr_frames; i++ ) @@ -1726,7 +1730,7 @@ active_alloc_failed: gt->active[i] = NULL; } gdprintk(XENLOG_INFO, "Allocation failure when expanding grant table.\n"); - return 0; + return -ENOMEM; } static int @@ -1769,8 +1773,10 @@ grant_table_init(struct domain *d, struct grant_table *gt) goto out; /* gnttab_grow_table() allocates a min number of frames, so 0 is okay. */ - if ( gnttab_grow_table(d, 0) ) - goto unlock; + ret = gnttab_grow_table(d, 0); + if (ret) + goto out; + goto unlock; no_mem: ret = -ENOMEM; @@ -1841,7 +1847,7 @@ gnttab_setup_table( if ( (op.nr_frames > nr_grant_frames(gt) || ((gt->gt_version > 1) && (grant_to_status_frames(op.nr_frames) > nr_status_frames(gt)))) && - !gnttab_grow_table(d, op.nr_frames) ) + gnttab_grow_table(d, op.nr_frames) ) { gdprintk(XENLOG_INFO, "Expand grant table to %u failed. Current: %u Max: %u\n", -- 2.12.3 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |