struct radix_tree_root maptrack_tree;
/* Domain to which this struct grant_table belongs. */
- const struct domain *domain;
+ struct domain *domain;
struct grant_table_arch arch;
};
{
int rc = gfn_eq(gfn, INVALID_GFN)
? 0
- : guest_physmap_remove_page(d, gfn,
- page_to_mfn(pg), 0);
+ : gnttab_set_frame_gfn(gt, true, i, INVALID_GFN,
+ page_to_mfn(pg));
if ( rc )
{
domain_crash(d);
return rc;
}
- gnttab_set_frame_gfn(gt, true, i, INVALID_GFN);
}
BUG_ON(page_get_owner(pg) != d);
struct grant_table *gt = d->grant_table;
bool status = false;
+ if ( gfn_eq(gfn, INVALID_GFN) )
+ return -EINVAL;
+
grant_write_lock(gt);
if ( evaluate_nospec(gt->gt_version == 2) && (idx & XENMAPIDX_grant_table_status) )
else
rc = gnttab_get_shared_frame_mfn(d, idx, mfn);
- if ( !rc && paging_mode_translate(d) )
- {
- gfn_t gfn = gnttab_get_frame_gfn(gt, status, idx);
-
- if ( !gfn_eq(gfn, INVALID_GFN) )
- rc = guest_physmap_remove_page(d, gfn, *mfn, 0);
- }
-
if ( !rc )
{
+ struct page_info *pg = mfn_to_page(*mfn);
+
/*
* Make sure gnttab_unpopulate_status_frames() won't (successfully)
* free the page until our caller has completed its operation.
*/
- if ( get_page(mfn_to_page(*mfn), d) )
- gnttab_set_frame_gfn(gt, status, idx, gfn);
- else
+ if ( !get_page(pg, d) )
rc = -EBUSY;
+ else if ( (rc = gnttab_set_frame_gfn(gt, status, idx, gfn, *mfn)) )
+ put_page(pg);
}
grant_write_unlock(gt);
XFREE((gt)->arch.status_gfn); \
} while ( 0 )
-#define gnttab_set_frame_gfn(gt, st, idx, gfn) \
- do { \
- ((st) ? (gt)->arch.status_gfn : (gt)->arch.shared_gfn)[idx] = \
- (gfn); \
- } while ( 0 )
+#define gnttab_set_frame_gfn(gt, st, idx, gfn, mfn) \
+ ({ \
+ int rc_ = 0; \
+ gfn_t ogfn = gnttab_get_frame_gfn(gt, st, idx); \
+ if ( gfn_eq(ogfn, INVALID_GFN) || gfn_eq(ogfn, gfn) || \
+ (rc_ = guest_physmap_remove_page((gt)->domain, ogfn, mfn, \
+ 0)) == 0 ) \
+ ((st) ? (gt)->arch.status_gfn \
+ : (gt)->arch.shared_gfn)[idx] = (gfn); \
+ rc_; \
+ })
#define gnttab_get_frame_gfn(gt, st, idx) ({ \
(st) ? gnttab_status_gfn(NULL, gt, idx) \
#define gnttab_init_arch(gt) 0
#define gnttab_destroy_arch(gt) do {} while ( 0 )
-#define gnttab_set_frame_gfn(gt, st, idx, gfn) do {} while ( 0 )
+#define gnttab_set_frame_gfn(gt, st, idx, gfn, mfn) \
+ (gfn_eq(gfn, INVALID_GFN) \
+ ? guest_physmap_remove_page((gt)->domain, \
+ gnttab_get_frame_gfn(gt, st, idx), \
+ mfn, 0) \
+ : 0 /* Handled in add_to_physmap_one(). */)
#define gnttab_get_frame_gfn(gt, st, idx) ({ \
mfn_t mfn_ = (st) ? gnttab_status_mfn(gt, idx) \
: gnttab_shared_mfn(gt, idx); \