|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v3 2/2] xen: fail gnttab_grow_table() in case of missing allocations
From: Juergen Gross <jgross@xxxxxxxx>
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>
Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
V2:
- use gprintk() instead of gdprintk() (Roger Pau Monne)
- let gnttab_grow_table() return an error code (Andrew Cooper)
v3:
* Rebase over new precursor patch.
---
xen/common/grant_table.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
index 2e4b5e7..bbcffe2 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,8 @@ gnttab_grow_table(struct domain *d, unsigned int
req_nr_frames)
gt->active[i] = NULL;
}
gdprintk(XENLOG_INFO, "Allocation failure when expanding grant table.\n");
- return 0;
+
+ return -ENOMEM;
}
static int
@@ -1769,7 +1774,7 @@ 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. */
- ret = gnttab_grow_table(d, 0) ? 0 : -ENOMEM;
+ ret = gnttab_grow_table(d, 0);
out:
if ( ret )
@@ -1840,7 +1845,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.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |