From 2797fcf18f171e9c92bb822668f8ace60473b3c2 Mon Sep 17 00:00:00 2001
From: Roger Pau Monne <roger.pau@citrix.com>
Date: Thu, 19 Dec 2013 12:17:54 +0100
Subject: [PATCH 8/9] xen: changes to gnttab for PVH

On PVH grant table frames are allocated from system memory.

Sponsored by: Citrix Systems R&D

xen/gnttab.c:
 - Allocate contiguous memory for grant table frames.
---
 sys/xen/gnttab.c |   24 +++++++++++++++++++-----
 1 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/sys/xen/gnttab.c b/sys/xen/gnttab.c
index 03c32b7..23916cb 100644
--- a/sys/xen/gnttab.c
+++ b/sys/xen/gnttab.c
@@ -25,6 +25,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/lock.h>
 #include <sys/malloc.h>
 #include <sys/mman.h>
+#include <sys/limits.h>
 
 #include <xen/xen-os.h>
 #include <xen/hypervisor.h>
@@ -607,6 +608,7 @@ gnttab_resume(void)
 {
 	int error;
 	unsigned int max_nr_gframes, nr_gframes;
+	void *alloc_mem;
 
 	nr_gframes = nr_grant_frames;
 	max_nr_gframes = max_nr_grant_frames();
@@ -614,11 +616,23 @@ gnttab_resume(void)
 		return (ENOSYS);
 
 	if (!resume_frames) {
-		error = xenpci_alloc_space(PAGE_SIZE * max_nr_gframes,
-		    &resume_frames);
-		if (error) {
-			printf("error mapping gnttab share frames\n");
-			return (error);
+		if (xen_pv_domain()) {
+			/*
+			 * This is a waste of physical memory,
+			 * we should use ballooned pages instead,
+			 * but it will do for now.
+			 */
+			alloc_mem = contigmalloc(max_nr_gframes * PAGE_SIZE,
+			    M_DEVBUF, M_WAITOK | M_ZERO, 0, ULONG_MAX,
+			    PAGE_SIZE, 0);
+			resume_frames = vtophys(alloc_mem);
+		} else {
+			error = xenpci_alloc_space(PAGE_SIZE * max_nr_gframes,
+			    &resume_frames);
+			if (error) {
+				printf("error mapping gnttab share frames\n");
+				return (error);
+			}
 		}
 	}
 
-- 
1.7.7.5 (Apple Git-26)

