In order to set up the grant table for HVM guests, libxc needs to map
the grant table temporarily. At the moment, it does this by adding the
grant page to the HVM guest's p2m table in the MMIO hole (at gfn 0xFFFFE),
then mapping that gfn, setting up the table, then unmapping the gfn and
removing it from the p2m table.
This breaks with PVH guests with 4G or more of ram, because there is
no MMIO hole; so it ends up clobbering a valid RAM p2m entry, then
leaving a "hole" when it removes the grant map from the p2m table.
Since the guest thinks this is normal ram, when it maps it and tries
to access the page, it crashes.
This patch maps the page at max_gfn+1 instead.
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Tim Deegan <tim@xen.org>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Keir Fraser <keir@xen.org>
Acked-by: Eddie Dong <eddie.dong@intel.com>
#define INVALID_P2M_ENTRY ((xen_pfn_t)-1)
-/* Scrach PFN for temporary mappings in HVM */
-#define SCRATCH_PFN_GNTTAB 0xFFFFE
-
/* --- typedefs and structs ---------------------------------------- */
typedef uint64_t xen_vaddr_t;
domid_t xenstore_domid)
{
int rc;
+ xen_pfn_t max_gfn;
struct xen_add_to_physmap xatp = {
.domid = domid,
.space = XENMAPSPACE_grant_table,
.idx = 0,
- .gpfn = SCRATCH_PFN_GNTTAB
};
struct xen_remove_from_physmap xrfp = {
.domid = domid,
- .gpfn = SCRATCH_PFN_GNTTAB
};
+ max_gfn = xc_domain_maximum_gpfn(xch, domid);
+ if ( max_gfn <= 0 ) {
+ xc_dom_panic(xch, XC_INTERNAL_ERROR,
+ "%s: failed to get max gfn "
+ "[errno=%d]\n",
+ __FUNCTION__, errno);
+ return -1;
+ }
+ xatp.gpfn = max_gfn + 1;
+ xrfp.gpfn = max_gfn + 1;
+
rc = do_memory_op(xch, XENMEM_add_to_physmap, &xatp, sizeof(xatp));
if ( rc != 0 )
{