Skip to contentSkip to conversation

common/gnttab: Explicitly default to gnttab v1 during domain creation

PATCH In review Andrew Cooper 4 participants 9 messages Aug 9, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common/gnttab: Explicitly default to gnttab v1 during domain creation

For reasons which appear to be exclusively down to poor review of the grant table v2 code, a grant table's version field was wasn't initialised during creation.

A number of problems (including XSAs) have occurred in the past trying trying to use a grant table which hasn't been properly set up, and various areas of the code cope with v0 by defaulting to v1.

In particular, the toolstack using GNTTABOP_setup_table to be able to fill in the store/console grants has a side effect of switching to v1.

In hindsight however, this "fixup if we see 0" is a very poor, with a substantial degree of risk. Explicitly default to grant table v1 during domain create, and let the rest of the code work safely in the knowledge that the version is sensibly set.

---
CC: Jan Beulich <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: George Dunlap <[email protected]>

This probably wants backporting, so I chose not to integrate it into my series which rearranges large chunks of DOMCTL_createdomain

---
 xen/common/grant_table.c | 40 +++++++---------------------------------
 1 file changed, 7 insertions(+), 33 deletions(-)
xen/common/grant_table.c +7 -33
index d9ec711..8bae656 100644
@@ -49,10 +49,7 @@ struct grant_table {
     percpu_rwlock_t       lock;
     /* Lock protecting the maptrack limit */
     spinlock_t            maptrack_lock;
-    /*
-     * The defined versions are 1 and 2.  Set to 0 if we don't know
-     * what version to use yet.
-     */
+    /* The defined versions are 1 and 2.  Any other value is invalid. */
     unsigned int          gt_version;
     /* Resource limits of the domain. */
     unsigned int          max_grant_frames;
@@ -222,7 +219,6 @@ nr_maptrack_frames(struct grant_table *t)
 static grant_entry_header_t *
 shared_entry_header(struct grant_table *t, grant_ref_t ref)
 {
-    ASSERT(t->gt_version != 0);
     if ( t->gt_version == 1 )
         return (grant_entry_header_t*)&shared_entry_v1(t, ref);
     else
@@ -1302,20 +1298,6 @@ unmap_common(
 
     grant_read_lock(rgt);
 
-    if ( rgt->gt_version == 0 )
-    {
-        /*
-         * This ought to be impossible, as such a mapping should not have
-         * been established (see the nr_grant_entries(rgt) bounds check in
-         * gnttab_map_grant_ref()). Doing this check only in
-         * gnttab_unmap_common_complete() - as it used to be done - would,
-         * however, be too late.
-         */
-        rc = GNTST_bad_gntref;
-        flags = 0;
-        goto unlock_out;
-    }
-
     op->rd = rd;
     op->ref = map->ref;
 
@@ -1932,9 +1914,6 @@ gnttab_setup_table(
         goto unlock;
     }
 
-    if ( gt->gt_version == 0 )
-        gt->gt_version = 1;
-
     if ( (op.nr_frames > nr_grant_frames(gt) ||
           ((gt->gt_version > 1) &&
            (grant_to_status_frames(op.nr_frames) > nr_status_frames(gt)))) &&
@@ -2991,15 +2970,11 @@ gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_version_t) uop)
 
     switch ( gt->gt_version )
     {
-    case 0:
-        if ( op.version == 2 )
-        {
     case 1:
-            /* XXX: We could maybe shrink the active grant table here. */
-            res = gnttab_populate_status_frames(currd, gt, nr_grant_frames(gt));
-            if ( res < 0)
-                goto out_unlock;
-        }
+        /* XXX: We could maybe shrink the active grant table here. */
+        res = gnttab_populate_status_frames(currd, gt, nr_grant_frames(gt));
+        if ( res < 0)
+            goto out_unlock;
         break;
     case 2:
         for ( i = 0; i < GNTTAB_NR_RESERVED_ENTRIES; i++ )
@@ -3594,6 +3569,8 @@ grant_table_create(
     percpu_rwlock_resource_init(&t->lock, grant_rwlock);
     spin_lock_init(&t->maptrack_lock);
 
+    t->gt_version = 1;
+
     /* Okay, install the structure. */
     t->domain = d;
     d->grant_table = t;
@@ -3869,9 +3846,6 @@ int gnttab_map_frame(struct domain *d, unsigned long idx, gfn_t gfn,
 
     grant_write_lock(gt);
 
-    if ( gt->gt_version == 0 )
-        gt->gt_version = 1;
-
     if ( gt->gt_version == 2 &&
          (idx & XENMAPIDX_grant_table_status) )
     {
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 09.08.18 at 12:31, <[email protected]> wrote:

For reasons which appear to be exclusively down to poor review of the grant table v2 code, a grant table's version field was wasn't initialised during creation.

A number of problems (including XSAs) have occurred in the past trying trying to use a grant table which hasn't been properly set up, and various areas of the code cope with v0 by defaulting to v1.

In particular, the toolstack using GNTTABOP_setup_table to be able to fill in the store/console grants has a side effect of switching to v1.

Quoted 6 lines

In hindsight however, this "fixup if we see 0" is a very poor, with a substantial degree of risk. Explicitly default to grant table v1 during domain create, and let the rest of the code work safely in the knowledge that the version is sensibly set.

Of course wants to be re-based over Paul's patch, or his over yours, depending on which one goes in earlier.

Jan

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

#2 lore raw
In reply to Andrew Cooper
Quoted 51 lines

-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 09 August 2018 11:32
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; George Dunlap <[email protected]>
Subject: [PATCH] common/gnttab: Explicitly default to gnttab v1 during domain creation

For reasons which appear to be exclusively down to poor review of the grant table v2 code, a grant table's version field was wasn't initialised during creation.

A number of problems (including XSAs) have occurred in the past trying trying
to use a grant table which hasn't been properly set up, and various areas of the code cope with v0 by defaulting to v1.

In particular, the toolstack using GNTTABOP_setup_table to be able to fill in the store/console grants has a side effect of switching to v1.

In hindsight however, this "fixup if we see 0" is a very poor, with a substantial degree of risk. Explicitly default to grant table v1 during domain create, and let the rest of the code work safely in the knowledge that
the version is sensibly set.

---
CC: Jan Beulich <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: George Dunlap <[email protected]>

This probably wants backporting, so I chose not to integrate it into my series which rearranges large chunks of DOMCTL_createdomain

---
 xen/common/grant_table.c | 40 +++++++---------------------------------
 1 file changed, 7 insertions(+), 33 deletions(-)
xen/common/grant_table.c +0 -0
index d9ec711..8bae656 100644

xen/common/grant_table.c struct grant_table { · line 55

Quoted 7 lines
xen/common/grant_table.c +0 -4
@@ -49,10 +49,7 @@ struct grant_table {
     percpu_rwlock_t       lock;
     /* Lock protecting the maptrack limit */
     spinlock_t            maptrack_lock;
-    /*
-     * The defined versions are 1 and 2.  Set to 0 if we don't know
-     * what version to use yet.
-     */

Given that only the guest can set the version by hypercall, it might be worth comment somewhere saying that grant table always start in v1 format and then get morphed if the guest sets v2. I guess it might be inferred that a v1 table is immutable (for those who don't look too hard).

xen/common/grant_table.c nr_maptrack_frames(struct grant_table *t) · line 225

Quoted 9 lines
xen/common/grant_table.c +1 -1
+    /* The defined versions are 1 and 2.  Any other value is invalid. */
     unsigned int          gt_version;
     /* Resource limits of the domain. */
     unsigned int          max_grant_frames;
@@ -222,7 +219,6 @@ nr_maptrack_frames(struct grant_table *t)
 static grant_entry_header_t *
 shared_entry_header(struct grant_table *t, grant_ref_t ref)
 {
-    ASSERT(t->gt_version != 0);

I think ASSERTs like this are probably still reasonable have. In fact we may want more of them now gt_version == 0 really really should be impossible.

Paul

Quoted 77 lines
xen/common/grant_table.c +4 -25
     if ( t->gt_version == 1 )
         return (grant_entry_header_t*)&shared_entry_v1(t, ref);
     else
@@ -1302,20 +1298,6 @@ unmap_common(
 
     grant_read_lock(rgt);
 
-    if ( rgt->gt_version == 0 )
-    {
-        /*
-         * This ought to be impossible, as such a mapping should not have
-         * been established (see the nr_grant_entries(rgt) bounds check in
-         * gnttab_map_grant_ref()). Doing this check only in
-         * gnttab_unmap_common_complete() - as it used to be done - would,
-         * however, be too late.
-         */
-        rc = GNTST_bad_gntref;
-        flags = 0;
-        goto unlock_out;
-    }
-
     op->rd = rd;
     op->ref = map->ref;
 
@@ -1932,9 +1914,6 @@ gnttab_setup_table(
         goto unlock;
     }
 
-    if ( gt->gt_version == 0 )
-        gt->gt_version = 1;
-
     if ( (op.nr_frames > nr_grant_frames(gt) ||
           ((gt->gt_version > 1) &&
            (grant_to_status_frames(op.nr_frames) > nr_status_frames(gt)))) &&
@@ -2991,15 +2970,11 @@
 gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_version_t)
 uop)
 
     switch ( gt->gt_version )
     {
-    case 0:
-        if ( op.version == 2 )
-        {
     case 1:
-            /* XXX: We could maybe shrink the active grant table here. */
-            res = gnttab_populate_status_frames(currd, gt,
 nr_grant_frames(gt));
-            if ( res < 0)
-                goto out_unlock;
-        }
+        /* XXX: We could maybe shrink the active grant table here. */
+        res = gnttab_populate_status_frames(currd, gt, nr_grant_frames(gt));
+        if ( res < 0)
+            goto out_unlock;
         break;
     case 2:
         for ( i = 0; i < GNTTAB_NR_RESERVED_ENTRIES; i++ )
xen/common/grant_table.c +2 -3
@@ -3594,6 +3569,8 @@ grant_table_create(
     percpu_rwlock_resource_init(&t->lock, grant_rwlock);
     spin_lock_init(&t->maptrack_lock);
 
+    t->gt_version = 1;
+
     /* Okay, install the structure. */
     t->domain = d;
     d->grant_table = t;
@@ -3869,9 +3846,6 @@ int gnttab_map_frame(struct domain *d, unsigned
 long idx, gfn_t gfn,
 
     grant_write_lock(gt);
 
-    if ( gt->gt_version == 0 )
-        gt->gt_version = 1;
-
     if ( gt->gt_version == 2 &&
          (idx & XENMAPIDX_grant_table_status) )
     {
Quoted 2 lines

--
2.1.4

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

#3 lore raw
Quoted 46 lines · Paul Durrant
Quoted 46 lines

-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 09 August 2018 11:32
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; George Dunlap <[email protected]>
Subject: [PATCH] common/gnttab: Explicitly default to gnttab v1 during domain creation

For reasons which appear to be exclusively down to poor review of the grant table v2 code, a grant table's version field was wasn't initialised during creation.

A number of problems (including XSAs) have occurred in the past trying trying
to use a grant table which hasn't been properly set up, and various areas of the code cope with v0 by defaulting to v1.

In particular, the toolstack using GNTTABOP_setup_table to be able to fill in the store/console grants has a side effect of switching to v1.

In hindsight however, this "fixup if we see 0" is a very poor, with a substantial degree of risk. Explicitly default to grant table v1 during domain create, and let the rest of the code work safely in the knowledge that
the version is sensibly set.

---
CC: Jan Beulich <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: George Dunlap <[email protected]>

This probably wants backporting, so I chose not to integrate it into my series which rearranges large chunks of DOMCTL_createdomain

---
 xen/common/grant_table.c | 40 +++++++---------------------------------
 1 file changed, 7 insertions(+), 33 deletions(-)
Quoted 13 lines

xen/common/grant_table.c struct grant_table { · line 55

Quoted 12 lines
xen/common/grant_table.c +0 -4
index d9ec711..8bae656 100644
@@ -49,10 +49,7 @@ struct grant_table {
     percpu_rwlock_t       lock;
     /* Lock protecting the maptrack limit */
     spinlock_t            maptrack_lock;
-    /*
-     * The defined versions are 1 and 2.  Set to 0 if we don't know
-     * what version to use yet.
-     */

Given that only the guest can set the version by hypercall, it might be worth comment somewhere saying that grant table always start in v1 format and then get morphed if the guest sets v2. I guess it might be inferred that a v1 table is immutable (for those who don't look too hard).

Really?  I don't think that's a reasonable inference to make, given GNTTABOP_set_version as a public interface.

~Andrew

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

#4 lore raw
Quoted 77 lines

-----Original Message-----
From: Andrew Cooper
Sent: 09 August 2018 12:14
To: Paul Durrant <[email protected]>; Xen-devel <xen- [email protected]>
Cc: Jan Beulich <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; George Dunlap <[email protected]>
Subject: Re: [PATCH] common/gnttab: Explicitly default to gnttab v1 during domain creation

Quoted 7 lines · Paul Durrant
Quoted 7 lines

-----Original Message-----
From: Andrew Cooper [mailto:[email protected]]
Sent: 09 August 2018 11:32
To: Xen-devel <[email protected]>
Cc: Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Paul Durrant <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>;

Wei

Quoted 6 lines
Quoted 6 lines

Liu <[email protected]>; Roger Pau Monne <[email protected]>; George Dunlap <[email protected]>
Subject: [PATCH] common/gnttab: Explicitly default to gnttab v1 during domain creation

For reasons which appear to be exclusively down to poor review of the

grant

Quoted 6 lines
Quoted 6 lines

table v2 code, a grant table's version field was wasn't initialised during creation.

A number of problems (including XSAs) have occurred in the past trying trying
to use a grant table which hasn't been properly set up, and various areas

of

Quoted 3 lines
Quoted 3 lines

the code cope with v0 by defaulting to v1.

In particular, the toolstack using GNTTABOP_setup_table to be able to fill

in

Quoted 18 lines
Quoted 18 lines

the store/console grants has a side effect of switching to v1.

In hindsight however, this "fixup if we see 0" is a very poor, with a substantial degree of risk. Explicitly default to grant table v1 during domain create, and let the rest of the code work safely in the knowledge that
the version is sensibly set.

---
CC: Jan Beulich <[email protected]>
CC: Paul Durrant <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: George Dunlap <[email protected]>

Quoted 1 line
Quoted 1 line

This probably wants backporting, so I chose not to integrate it into my

series

Quoted 5 lines
Quoted 5 lines

which rearranges large chunks of DOMCTL_createdomain

---
 xen/common/grant_table.c | 40 +++++++---------------------------------
 1 file changed, 7 insertions(+), 33 deletions(-)
Quoted 13 lines

xen/common/grant_table.c struct grant_table { · line 55

Quoted 12 lines
xen/common/grant_table.c +0 -4
index d9ec711..8bae656 100644
@@ -49,10 +49,7 @@ struct grant_table {
     percpu_rwlock_t       lock;
     /* Lock protecting the maptrack limit */
     spinlock_t            maptrack_lock;
-    /*
-     * The defined versions are 1 and 2.  Set to 0 if we don't know
-     * what version to use yet.
-     */

Given that only the guest can set the version by hypercall, it might be

Quoted 7 lines

worth comment somewhere saying that grant table always start in v1 format and then get morphed if the guest sets v2. I guess it might be inferred that a v1 table is immutable (for those who don't look too hard).

Really?  I don't think that's a reasonable inference to make, given GNTTABOP_set_version as a public interface.

If you think it is sufficiently evident then fine, but the comment you're removing implies that 0 -> 1 and 0 -> 2 are valid transitions but maybe 1 -> 2 is not (otherwise why would you have 0, right?)

Paul

Quoted 1 line

~Andrew

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

#5 lore raw
Quoted 19 lines · Paul Durrant
Quoted 19 lines
Quoted 19 lines
Quoted 11 lines

which rearranges large chunks of DOMCTL_createdomain

---
 xen/common/grant_table.c | 40 +++++++---------------------------------
 1 file changed, 7 insertions(+), 33 deletions(-)
xen/common/grant_table.c +0 -0
index d9ec711..8bae656 100644

xen/common/grant_table.c struct grant_table { · line 55

Quoted 7 lines
xen/common/grant_table.c +0 -4
@@ -49,10 +49,7 @@ struct grant_table {
     percpu_rwlock_t       lock;
     /* Lock protecting the maptrack limit */
     spinlock_t            maptrack_lock;
-    /*
-     * The defined versions are 1 and 2.  Set to 0 if we don't know
-     * what version to use yet.
-     */

Given that only the guest can set the version by hypercall, it might be

Quoted 8 lines
Quoted 7 lines

worth comment somewhere saying that grant table always start in v1 format and then get morphed if the guest sets v2. I guess it might be inferred that a v1 table is immutable (for those who don't look too hard).

Really?  I don't think that's a reasonable inference to make, given GNTTABOP_set_version as a public interface.

If you think it is sufficiently evident then fine, but the comment you're removing implies that 0 -> 1 and 0 -> 2 are valid transitions but maybe 1 -> 2 is not (otherwise why would you have 0, right?)

/* Defaults to v1.  May be changed with GNTTABOP_set_version.  All other values are invalid. */

?

~Andrew

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

#6 lore raw
Quoted 41 lines

-----Original Message-----
From: Andrew Cooper
Sent: 09 August 2018 12:22
To: Paul Durrant <[email protected]>; Xen-devel <xen- [email protected]>
Cc: Jan Beulich <[email protected]>; Stefano Stabellini <[email protected]>; Julien Grall <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>; George Dunlap <[email protected]>
Subject: Re: [PATCH] common/gnttab: Explicitly default to gnttab v1 during domain creation

Quoted 19 lines · Paul Durrant
Quoted 19 lines
Quoted 19 lines
Quoted 11 lines

which rearranges large chunks of DOMCTL_createdomain

---
 xen/common/grant_table.c | 40 +++++++---------------------------------
 1 file changed, 7 insertions(+), 33 deletions(-)
xen/common/grant_table.c +0 -0
index d9ec711..8bae656 100644

xen/common/grant_table.c struct grant_table { · line 55

Quoted 7 lines
xen/common/grant_table.c +0 -4
@@ -49,10 +49,7 @@ struct grant_table {
     percpu_rwlock_t       lock;
     /* Lock protecting the maptrack limit */
     spinlock_t            maptrack_lock;
-    /*
-     * The defined versions are 1 and 2.  Set to 0 if we don't know
-     * what version to use yet.
-     */

Given that only the guest can set the version by hypercall, it might be

Quoted 1 line
Quoted 1 line

worth comment somewhere saying that grant table always start in v1

format

Quoted 1 line
Quoted 1 line

and then get morphed if the guest sets v2. I guess it might be inferred

that a

Quoted 5 lines
Quoted 5 lines

v1 table is immutable (for those who don't look too hard).

Really?  I don't think that's a reasonable inference to make, given GNTTABOP_set_version as a public interface.

Quoted 8 lines
Quoted 1 line

If you think it is sufficiently evident then fine, but the comment you're

removing implies that 0 -> 1 and 0 -> 2 are valid transitions but maybe 1 -> 2 is not (otherwise why would you have 0, right?)

/* Defaults to v1.  May be changed with GNTTABOP_set_version.  All other values are invalid. */

?

LGTM.

Paul

Quoted 2 lines

~Andrew

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

Reviewed-by on v1 1/1
#7 lore raw
In reply to Andrew Cooper
Quoted 11 lines · Andrew Cooper

For reasons which appear to be exclusively down to poor review of the grant table v2 code, a grant table's version field was wasn't initialised during creation.

A number of problems (including XSAs) have occurred in the past trying trying to use a grant table which hasn't been properly set up, and various areas of the code cope with v0 by defaulting to v1.

In particular, the toolstack using GNTTABOP_setup_table to be able to fill in the store/console grants has a side effect of switching to v1.

Quoted 6 lines

In hindsight however, this "fixup if we see 0" is a very poor, with a substantial degree of risk. Explicitly default to grant table v1 during domain create, and let the rest of the code work safely in the knowledge that the version is sensibly set.

I would however keep the current gt_version != 0 asserts, and change the if ( gt_version == 0 ) into ASSERT(gt_version != 0);

Quoted 10 lines
xen/common/grant_table.c +0 -5
@@ -2991,15 +2970,11 @@ gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_version_t) uop)
 
     switch ( gt->gt_version )
     {
-    case 0:
-        if ( op.version == 2 )
-        {
     case 1:
-            /* XXX: We could maybe shrink the active grant table here. */
-            res = gnttab_populate_status_frames(currd, gt, nr_grant_frames(gt));

xen/common/grant_table.c gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_version_t) uop) · line 2980

Quoted 10 lines
xen/common/grant_table.c +4 -3
-            if ( res < 0)
-                goto out_unlock;
-        }
+        /* XXX: We could maybe shrink the active grant table here. */
+        res = gnttab_populate_status_frames(currd, gt, nr_grant_frames(gt));
+        if ( res < 0)
+            goto out_unlock;
         break;
     case 2:
         for ( i = 0; i < GNTTAB_NR_RESERVED_ENTRIES; i++ )

And I would add a default: ASSERT_UNREACHABLE(); here.

Thanks, Roger.

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

#8 lore raw
Quoted 17 lines · Roger Pau Monné
Quoted 16 lines · Andrew Cooper

For reasons which appear to be exclusively down to poor review of the grant table v2 code, a grant table's version field was wasn't initialised during creation.

A number of problems (including XSAs) have occurred in the past trying trying to use a grant table which hasn't been properly set up, and various areas of the code cope with v0 by defaulting to v1.

In particular, the toolstack using GNTTABOP_setup_table to be able to fill in the store/console grants has a side effect of switching to v1.

In hindsight however, this "fixup if we see 0" is a very poor, with a substantial degree of risk. Explicitly default to grant table v1 during domain create, and let the rest of the code work safely in the knowledge that the version is sensibly set.

Quoted 5 lines
Quoted 1 line

I would however keep the current gt_version != 0 asserts, and change the if ( gt_version == 0 ) into ASSERT(gt_version != 0);

No - they are not correct either, because they will pass for 3 or greater.

I've got some cleanup plans which will turn a load of this into

switch ( gt->gt_version )
{
case 1: ...
case 2: ...
default: ASSERT_UNREACHABLE();
}

but that is definitely work for later.

~Andrew

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