Skip to contentSkip to conversation

xen: fail gnttab_grow_table() in case of missing allocations

PATCH Superseded Juergen Gross 3 participants 7 messages Sep 29, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: fail gnttab_grow_table() in case of missing allocations

In case gnttab_grow_table() is being called without grant_table_init() having been called for the domain, e.g. in case of a toolstack error, fail the function instead of crashing the system.

---
 xen/common/grant_table.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
xen/common/grant_table.c +5 -1
index 71706f5cba..f2598a902f 100644
@@ -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) )
+    {
+        gdprintk(XENLOG_WARNING, "grant_table_set_limits() call missing.\n");
+        return 0;
+    }
 
     if ( req_nr_frames < INITIAL_NR_GRANT_FRAMES )
         req_nr_frames = INITIAL_NR_GRANT_FRAMES;
Signature · 7 lines
2.12.3


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 14 lines · Juergen Gross

In case gnttab_grow_table() is being called without grant_table_init() having been called for the domain, e.g. in case of a toolstack error, fail the function instead of crashing the system.

---
 xen/common/grant_table.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
xen/common/grant_table.c +0 -0
index 71706f5cba..f2598a902f 100644

xen/common/grant_table.c gnttab_grow_table(struct domain *d, unsigned int req_nr_frames) · line 1674

Quoted 7 lines
xen/common/grant_table.c +3 -1
@@ -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) )
+    {
+        gdprintk(XENLOG_WARNING, "grant_table_set_limits() call missing.\n");

In the commit message you mention 'grant_table_init', yet the error message here says grant_table_set_limits. Shouldn't both mention the same precursor function?

Also I think this might be better as gprintk instead of gdprintk.

xen/common/grant_table.c gnttab_grow_table(struct domain *d, unsigned int req_nr_frames) · line 1675

Quoted 1 line
xen/common/grant_table.c +1 -0
+        return 0;

This return 0 has confused me, I was going to ask to return ENODEV, but then I saw this is actually treated like a boolean. Might be good to make gnttab_grow_table return bool, or either make it return proper error codes.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw
Quoted 18 lines · Roger Pau Monné
Quoted 17 lines · Juergen Gross

In case gnttab_grow_table() is being called without grant_table_init() having been called for the domain, e.g. in case of a toolstack error, fail the function instead of crashing the system.

---
 xen/common/grant_table.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
xen/common/grant_table.c +0 -0
index 71706f5cba..f2598a902f 100644
@@ -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;
 
Quoted 8 lines

xen/common/grant_table.c gnttab_grow_table(struct domain *d, unsigned int req_nr_frames) · line 1674

Quoted 4 lines
xen/common/grant_table.c +3 -1
-    ASSERT(gt->active);
+    if ( unlikely(!gt->active) )
+    {
+        gdprintk(XENLOG_WARNING, "grant_table_set_limits() call missing.\n");

In the commit message you mention 'grant_table_init', yet the error message here says grant_table_set_limits. Shouldn't both mention the same precursor function?

Aah, sorry. Will update the commit message.

Quoted 1 line

Also I think this might be better as gprintk instead of gdprintk.

Okay.

Quoted 6 lines

xen/common/grant_table.c gnttab_grow_table(struct domain *d, unsigned int req_nr_frames) · line 1675

Quoted 1 line
xen/common/grant_table.c +1 -0
+        return 0;

This return 0 has confused me, I was going to ask to return ENODEV, but then I saw this is actually treated like a boolean. Might be good to make gnttab_grow_table return bool, or either make it return proper error codes.

I wanted to keep the patch small.

I can either send a cleanup patch after 4.10 or do it in this patch (in which case I'd like to know whether this patch or the last one of my grant series will be applied first).

Thoughts?

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
Quoted 9 lines · Juergen Gross
Quoted 7 lines · Roger Pau Monné
Quoted 1 line · Juergen Gross

+ return 0;

This return 0 has confused me, I was going to ask to return ENODEV, but then I saw this is actually treated like a boolean. Might be good to make gnttab_grow_table return bool, or either make it return proper error codes.

Quoted 7 lines

I wanted to keep the patch small.

I can either send a cleanup patch after 4.10 or do it in this patch (in which case I'd like to know whether this patch or the last one of my grant series will be applied first).

Thoughts?

Oh sorry. It was a rant rather than a request. No need for you to change this.

Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw
In reply to Juergen Gross
Quoted 36 lines · Juergen Gross
Quoted 18 lines · Roger Pau Monné
Quoted 17 lines · Juergen Gross

In case gnttab_grow_table() is being called without grant_table_init() having been called for the domain, e.g. in case of a toolstack error, fail the function instead of crashing the system.

---
 xen/common/grant_table.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
xen/common/grant_table.c +0 -0
index 71706f5cba..f2598a902f 100644
@@ -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;
 
Quoted 7 lines

xen/common/grant_table.c gnttab_grow_table(struct domain *d, unsigned int req_nr_frames) · line 1674

Quoted 4 lines
xen/common/grant_table.c +3 -1
-    ASSERT(gt->active);
+    if ( unlikely(!gt->active) )
+    {
+        gdprintk(XENLOG_WARNING, "grant_table_set_limits() call missing.\n");

In the commit message you mention 'grant_table_init', yet the error message here says grant_table_set_limits. Shouldn't both mention the same precursor function?

Aah, sorry. Will update the commit message.

Quoted 1 line

Also I think this might be better as gprintk instead of gdprintk.

Okay.

Quoted 5 lines

xen/common/grant_table.c gnttab_grow_table(struct domain *d, unsigned int req_nr_frames) · line 1675

Quoted 1 line
xen/common/grant_table.c +1 -0
+        return 0;

This return 0 has confused me, I was going to ask to return ENODEV, but then I saw this is actually treated like a boolean. Might be good to make gnttab_grow_table return bool, or either make it return proper error codes.

Quoted 7 lines

I wanted to keep the patch small.

I can either send a cleanup patch after 4.10 or do it in this patch (in which case I'd like to know whether this patch or the last one of my grant series will be applied first).

Thoughts?

This function is new in 4.10.  I'm not concerned about absolute size of the patch, but I would prefer not to introduce new (mis)uses of int functions which actually have boolean properties.  (Wei and I have spent a large quantity of time removing functions like this.)

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw
Quoted 39 lines · Andrew Cooper
Quoted 38 lines · Juergen Gross
Quoted 18 lines · Roger Pau Monné
Quoted 17 lines · Juergen Gross

In case gnttab_grow_table() is being called without grant_table_init() having been called for the domain, e.g. in case of a toolstack error, fail the function instead of crashing the system.

---
 xen/common/grant_table.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
xen/common/grant_table.c +0 -0
index 71706f5cba..f2598a902f 100644
@@ -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;
 
Quoted 7 lines

xen/common/grant_table.c gnttab_grow_table(struct domain *d, unsigned int req_nr_frames) · line 1674

Quoted 4 lines
xen/common/grant_table.c +3 -1
-    ASSERT(gt->active);
+    if ( unlikely(!gt->active) )
+    {
+        gdprintk(XENLOG_WARNING, "grant_table_set_limits() call missing.\n");

In the commit message you mention 'grant_table_init', yet the error message here says grant_table_set_limits. Shouldn't both mention the same precursor function?

Aah, sorry. Will update the commit message.

Quoted 1 line

Also I think this might be better as gprintk instead of gdprintk.

Okay.

Quoted 5 lines

xen/common/grant_table.c gnttab_grow_table(struct domain *d, unsigned int req_nr_frames) · line 1675

Quoted 1 line
xen/common/grant_table.c +1 -0
+        return 0;

This return 0 has confused me, I was going to ask to return ENODEV, but then I saw this is actually treated like a boolean. Might be good to make gnttab_grow_table return bool, or either make it return proper error codes.

I wanted to keep the patch small.

Quoted 7 lines
Quoted 5 lines

I can either send a cleanup patch after 4.10 or do it in this patch (in which case I'd like to know whether this patch or the last one of my grant series will be applied first).

Thoughts?

This function is new in 4.10.

Umm, not really. Its rather old.

Quoted 4 lines

I'm not concerned about absolute size of
the patch, but I would prefer not to introduce new (mis)uses of int functions which actually have boolean properties.  (Wei and I have spent a large quantity of time removing functions like this.)

I'd rather return a proper error code.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#6 lore raw
Quoted 40 lines · Juergen Gross
Quoted 39 lines · Andrew Cooper
Quoted 38 lines · Juergen Gross
Quoted 18 lines · Roger Pau Monné
Quoted 17 lines · Juergen Gross

In case gnttab_grow_table() is being called without grant_table_init() having been called for the domain, e.g. in case of a toolstack error, fail the function instead of crashing the system.

---
 xen/common/grant_table.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
xen/common/grant_table.c +0 -0
index 71706f5cba..f2598a902f 100644
@@ -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;
 
Quoted 7 lines

xen/common/grant_table.c gnttab_grow_table(struct domain *d, unsigned int req_nr_frames) · line 1674

Quoted 4 lines
xen/common/grant_table.c +3 -1
-    ASSERT(gt->active);
+    if ( unlikely(!gt->active) )
+    {
+        gdprintk(XENLOG_WARNING, "grant_table_set_limits() call missing.\n");

In the commit message you mention 'grant_table_init', yet the error message here says grant_table_set_limits. Shouldn't both mention the same precursor function?

Aah, sorry. Will update the commit message.

Quoted 1 line

Also I think this might be better as gprintk instead of gdprintk.

Okay.

Quoted 5 lines

xen/common/grant_table.c gnttab_grow_table(struct domain *d, unsigned int req_nr_frames) · line 1675

Quoted 1 line
xen/common/grant_table.c +1 -0
+        return 0;

This return 0 has confused me, I was going to ask to return ENODEV, but then I saw this is actually treated like a boolean. Might be good to make gnttab_grow_table return bool, or either make it return proper error codes.

I wanted to keep the patch small.

Quoted 7 lines
Quoted 6 lines
Quoted 5 lines

I can either send a cleanup patch after 4.10 or do it in this patch (in which case I'd like to know whether this patch or the last one of my grant series will be applied first).

Thoughts?

This function is new in 4.10.

Umm, not really. Its rather old.

Oh - so it is.

Quoted 6 lines
Quoted 5 lines

I'm not concerned about absolute size of
the patch, but I would prefer not to introduce new (mis)uses of int functions which actually have boolean properties.  (Wei and I have spent a large quantity of time removing functions like this.)

I'd rather return a proper error code.

Fine by me.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel