[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 05/21] xen: Preserve reserved grant entries when switching versions
In order for the toolstack to use reserved grant table entries, the grant table for a guest must be initialized prior to the guest's boot. When the guest switches grant table versions (necessary if the guest is using v2 grant tables, or on kexec if switching grant versions), these initial grants will be cleared. Instead of clearing them, preserve the grants across the type change. Attempting to preserve v2-only features such as sub-page grants will produce a warning and invalidate the resulting v1 grant entry. Signed-off-by: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx> --- xen/common/grant_table.c | 48 +++++++++++++++++++++++++++++++++---- xen/include/public/grant_table.h | 7 +++++ 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 34a49db..dd9f904 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -2110,6 +2110,7 @@ gnttab_set_version(XEN_GUEST_HANDLE(gnttab_set_version_t uop)) struct domain *d = current->domain; struct grant_table *gt = d->grant_table; struct active_grant_entry *act; + grant_entry_v1_t reserved_entries[GNTTAB_NR_RESERVED_ENTRIES]; long res; int i; @@ -2130,7 +2131,7 @@ gnttab_set_version(XEN_GUEST_HANDLE(gnttab_set_version_t uop)) /* (You need to change the version number for e.g. kexec.) */ if ( gt->gt_version != 0 ) { - for ( i = 0; i < nr_grant_entries(gt); i++ ) + for ( i = GNTTAB_NR_RESERVED_ENTRIES; i < nr_grant_entries(gt); i++ ) { act = &active_entry(gt, i); if ( act->pin != 0 ) @@ -2155,15 +2156,50 @@ gnttab_set_version(XEN_GUEST_HANDLE(gnttab_set_version_t uop)) goto out_unlock; } + /* Preserve the first 8 entries (toolstack reserved grants) */ + if (gt->gt_version == 1) + { + memcpy(reserved_entries, gt->shared_v1[0], sizeof(reserved_entries)); + } + else if (gt->gt_version == 2) + { + for ( i = 0; i < GNTTAB_NR_RESERVED_ENTRIES && i < nr_grant_entries(gt); i++ ) + { + reserved_entries[i].flags = shared_entry_v2(gt, i).hdr.flags; + reserved_entries[i].domid = shared_entry_v2(gt, i).hdr.domid; + reserved_entries[i].frame = shared_entry_v2(gt, i).full_page.frame; + reserved_entries[i].flags |= status_entry(gt, i); + if ((reserved_entries[i].flags & GTF_type_mask) > GTF_permit_access) + { + gdprintk(XENLOG_INFO, "d%d: bad flags %x in grant %d when switching grant version\n", + d->domain_id, reserved_entries[i].flags, i); + reserved_entries[i].flags = GTF_invalid; + } + } + } + if ( op.version < 2 && gt->gt_version == 2 ) gnttab_unpopulate_status_frames(d, gt); - if ( op.version != gt->gt_version ) + /* Make sure there's no crud left over in the table from the + old version. */ + for ( i = 0; i < nr_grant_frames(gt); i++ ) + memset(gt->shared_raw[i], 0, PAGE_SIZE); + + /* Restore the first 8 entries (toolstack reserved grants) */ + if (gt->gt_version != 0 && op.version == 1) { - /* Make sure there's no crud left over in the table from the - old version. */ - for ( i = 0; i < nr_grant_frames(gt); i++ ) - memset(gt->shared_raw[i], 0, PAGE_SIZE); + memcpy(gt->shared_v1[0], reserved_entries, sizeof(reserved_entries)); + } + else if (gt->gt_version != 0 && op.version == 2) + { + for ( i = 0; i < GNTTAB_NR_RESERVED_ENTRIES; i++ ) + { + status_entry(gt, i) = reserved_entries[i].flags & (GTF_reading|GTF_writing); + shared_entry_v2(gt, i).hdr.flags = reserved_entries[i].flags & ~(GTF_reading|GTF_writing); + shared_entry_v2(gt, i).hdr.domid = reserved_entries[i].domid; + shared_entry_v2(gt, i).full_page.frame = reserved_entries[i].frame; + } } gt->gt_version = op.version; diff --git a/xen/include/public/grant_table.h b/xen/include/public/grant_table.h index 0bf20bc..5604638 100644 --- a/xen/include/public/grant_table.h +++ b/xen/include/public/grant_table.h @@ -117,6 +117,13 @@ struct grant_entry_v1 { }; typedef struct grant_entry_v1 grant_entry_v1_t; +/* The first few grant table entries will be preserved across grant table + * version changes and may be pre-populated at domain creation by tools. + */ +#define GNTTAB_NR_RESERVED_ENTRIES 8 +#define GNTTAB_RESERVED_CONSOLE 0 +#define GNTTAB_RESERVED_XENSTORE 1 + /* * Type of grant entry. * GTF_invalid: This grant entry grants no privileges. -- 1.7.7.5 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |