@@ -486,13 +486,11 @@ struct domain *alloc_domain_struct(void)
return NULL;
clear_page(d);
- d->arch.grant_table_gfn = xzalloc_array(gfn_t, max_grant_frames);
return d;
}
void free_domain_struct(struct domain *d)
{
- xfree(d->arch.grant_table_gfn);
free_xenheap_page(d);
}
@@ -72,6 +72,8 @@ struct grant_table {
struct active_grant_entry **active;
/* Mapping tracking table per vcpu. */
struct grant_mapping **maptrack;
+
+ struct grant_table_arch arch;
};
#ifndef DEFAULT_MAX_NR_GRANT_FRAMES /* to allow arch to override */
@@ -1730,6 +1732,8 @@ active_alloc_failed:
static int
grant_table_init(struct domain *d, struct grant_table *gt)
{
+ int ret = -ENOMEM;
+
if ( gt->active )
return -EBUSY;
@@ -1737,36 +1741,43 @@ grant_table_init(struct domain *d, struct grant_table *gt)
gt->active = xzalloc_array(struct active_grant_entry *,
max_nr_active_grant_frames);
if ( gt->active == NULL )
- goto no_mem;
+ goto out;
/* Tracking of mapped foreign frames table */
gt->maptrack = vzalloc(max_maptrack_frames * sizeof(*gt->maptrack));
if ( gt->maptrack == NULL )
- goto no_mem;
+ goto out;
/* Shared grant table. */
gt->shared_raw = xzalloc_array(void *, max_grant_frames);
if ( gt->shared_raw == NULL )
- goto no_mem;
+ goto out;
/* Status pages for grant table - for version 2 */
gt->status = xzalloc_array(grant_status_t *,
grant_to_status_frames(max_grant_frames));
if ( gt->status == NULL )
- goto no_mem;
+ goto out;
+
+ ret = gnttab_init_arch(gt);
+ if ( ret )
+ goto out;
/* gnttab_grow_table() allocates a min number of frames, so 0 is okay. */
if ( gnttab_grow_table(d, 0) )
return 0;
- no_mem:
+ out:
+ gnttab_destroy_arch(gt);
+ xfree(gt->status);
+ gt->status = NULL;
xfree(gt->shared_raw);
gt->shared_raw = NULL;
vfree(gt->maptrack);
gt->maptrack = NULL;
xfree(gt->active);
gt->active = NULL;
- return -ENOMEM;
+ return ret;
}
static long
@@ -3612,6 +3623,8 @@ grant_table_destroy(
if ( t == NULL )
return;
+ gnttab_destroy_arch(t);
+
for ( i = 0; i < nr_grant_frames(t); i++ )
free_xenheap_page(t->shared_raw[i]);
xfree(t->shared_raw);
@@ -3738,7 +3751,7 @@ int gnttab_map_frame(struct domain *d, unsigned long idx, gfn_t gfn,
}
if ( !rc )
- gnttab_set_frame_gfn(d, idx, gfn);
+ gnttab_set_frame_gfn(gt, idx, gfn);
grant_write_unlock(gt);
@@ -50,7 +50,6 @@ struct arch_domain
struct p2m_domain p2m;
struct hvm_domain hvm_domain;
- gfn_t *grant_table_gfn;
struct vmmio vmmio;
@@ -6,6 +6,10 @@
#define INITIAL_NR_GRANT_FRAMES 4
+struct grant_table_arch {
+ gfn_t *gfn;
+};
+
void gnttab_clear_flag(unsigned long nr, uint16_t *addr);
int create_grant_host_mapping(unsigned long gpaddr,
unsigned long mfn, unsigned int flags, unsigned int
@@ -22,11 +26,22 @@ static inline int replace_grant_supported(void)
return 1;
}
-static inline void gnttab_set_frame_gfn(struct domain *d, unsigned long idx,
- gfn_t gfn)
-{
- d->arch.grant_table_gfn[idx] = gfn;
-}
+#define gnttab_init_arch(gt) \
+({ \
+ (gt)->arch.gfn = xzalloc_array(gfn_t, max_grant_frames); \
+ ( (gt)->arch.gfn ? 0 : -ENOMEM ); \
+})
+
+#define gnttab_destroy_arch(gt) \
+ do { \
+ xfree((gt)->arch.gfn); \
+ (gt)->arch.gfn = NULL; \
+ } while ( 0 )
+
+#define gnttab_set_frame_gfn(gt, idx, gfn) \
+ do { \
+ (gt)->arch.gfn[idx] = gfn; \
+ } while ( 0 )
#define gnttab_create_shared_page(d, t, i) \
do { \
@@ -36,8 +51,8 @@ static inline void gnttab_set_frame_gfn(struct domain *d, unsigned long idx,
} while ( 0 )
#define gnttab_shared_gmfn(d, t, i) \
- ( ((i >= nr_grant_frames(d->grant_table)) && \
- (i < max_grant_frames)) ? 0 : gfn_x(d->arch.grant_table_gfn[i]))
+ ( ((i >= nr_grant_frames(t)) && \
+ (i < max_grant_frames)) ? 0 : gfn_x(t->arch.gfn[i]))
#define gnttab_need_iommu_mapping(d) \
(is_domain_direct_mapped(d) && need_iommu(d))
@@ -14,6 +14,9 @@
#define INITIAL_NR_GRANT_FRAMES 4
+struct grant_table_arch {
+};
+
/*
* Caller must own caller's BIGLOCK, is responsible for flushing the TLB, and
* must hold a reference to the page.
@@ -36,6 +39,10 @@ static inline int replace_grant_host_mapping(uint64_t addr, unsigned long frame,
return replace_grant_pv_mapping(addr, frame, new_addr, flags);
}
+#define gnttab_init_arch(gt) 0
+#define gnttab_destroy_arch(gt) do {} while ( 0 )
+#define gnttab_set_frame_gfn(gt, idx, gfn) do {} while ( 0 )
+
#define gnttab_create_shared_page(d, t, i) \
do { \
share_xen_page_with_guest( \
@@ -75,11 +82,6 @@ static inline void gnttab_clear_flag(unsigned int nr, uint16_t *st)
asm volatile ("lock btrw %w1,%0" : "=m" (*st) : "Ir" (nr), "m" (*st));
}
-static inline void gnttab_set_frame_gfn(struct domain *d, unsigned long idx,
- gfn_t gfn)
-{
-}
-
/* Foreign mappings of HHVM-guest pages do not modify the type count. */
#define gnttab_host_mapping_get_page_type(ro, ld, rd) \
(!(ro) && (((ld) == (rd)) || !paging_mode_external(rd)))
@@ -29,6 +29,8 @@
#include <asm/page.h>
#include <asm/grant_table.h>
+struct grant_table;
+
/* The maximum size of a grant table. */
extern unsigned int max_grant_frames;