1 diff -durN -x '*~' -x '*.orig' -x '*.rej' xen-4.4.0.orig/tools/libxc/xc_mem_access.c xen-4.4.0/tools/libxc/xc_mem_access.c
2 --- xen-4.4.0.orig/tools/libxc/xc_mem_access.c 2014-03-10 11:43:57.000000000 +0100
3 +++ xen-4.4.0/tools/libxc/xc_mem_access.c 2014-06-18 10:19:54.000000000 +0200
5 #include "xc_private.h"
8 -int xc_mem_access_enable(xc_interface *xch, domid_t domain_id,
10 +void *xc_mem_access_enable(xc_interface *xch, domid_t domain_id, uint32_t *port)
18 - return xc_mem_event_control(xch, domain_id,
19 - XEN_DOMCTL_MEM_EVENT_OP_ACCESS_ENABLE,
20 - XEN_DOMCTL_MEM_EVENT_OP_ACCESS,
22 + return xc_mem_event_enable(xch, domain_id, HVM_PARAM_ACCESS_RING_PFN, port);
25 int xc_mem_access_disable(xc_interface *xch, domid_t domain_id)
26 diff -durN -x '*~' -x '*.orig' -x '*.rej' xen-4.4.0.orig/tools/libxc/xc_mem_event.c xen-4.4.0/tools/libxc/xc_mem_event.c
27 --- xen-4.4.0.orig/tools/libxc/xc_mem_event.c 2014-03-10 11:43:57.000000000 +0100
28 +++ xen-4.4.0/tools/libxc/xc_mem_event.c 2014-06-18 10:19:54.000000000 +0200
30 return do_memory_op(xch, mode, &meo, sizeof(meo));
33 +void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,
36 + void *ring_page = NULL;
37 + unsigned long ring_pfn, mmap_pfn;
38 + unsigned int op, mode;
39 + int rc1, rc2, saved_errno;
47 + /* Pause the domain for ring page setup */
48 + rc1 = xc_domain_pause(xch, domain_id);
51 + PERROR("Unable to pause domain\n");
55 + /* Get the pfn of the ring page */
56 + rc1 = xc_get_hvm_param(xch, domain_id, param, &ring_pfn);
59 + PERROR("Failed to get pfn of ring page\n");
63 + mmap_pfn = ring_pfn;
64 + ring_page = xc_map_foreign_batch(xch, domain_id, PROT_READ | PROT_WRITE,
66 + if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
68 + /* Map failed, populate ring page */
69 + rc1 = xc_domain_populate_physmap_exact(xch, domain_id, 1, 0, 0,
73 + PERROR("Failed to populate ring pfn\n");
77 + mmap_pfn = ring_pfn;
78 + ring_page = xc_map_foreign_batch(xch, domain_id, PROT_READ | PROT_WRITE,
80 + if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
82 + PERROR("Could not map the ring page\n");
89 + case HVM_PARAM_PAGING_RING_PFN:
90 + op = XEN_DOMCTL_MEM_EVENT_OP_PAGING_ENABLE;
91 + mode = XEN_DOMCTL_MEM_EVENT_OP_PAGING;
94 + case HVM_PARAM_ACCESS_RING_PFN:
95 + op = XEN_DOMCTL_MEM_EVENT_OP_ACCESS_ENABLE;
96 + mode = XEN_DOMCTL_MEM_EVENT_OP_ACCESS;
99 + case HVM_PARAM_SHARING_RING_PFN:
100 + op = XEN_DOMCTL_MEM_EVENT_OP_SHARING_ENABLE;
101 + mode = XEN_DOMCTL_MEM_EVENT_OP_SHARING;
105 + * This is for the outside chance that the HVM_PARAM is valid but is invalid
106 + * as far as mem_event goes.
114 + rc1 = xc_mem_event_control(xch, domain_id, op, mode, port);
117 + PERROR("Failed to enable mem_event\n");
121 + /* Remove the ring_pfn from the guest's physmap */
122 + rc1 = xc_domain_decrease_reservation_exact(xch, domain_id, 1, 0, &ring_pfn);
124 + PERROR("Failed to remove ring page from guest physmap");
127 + saved_errno = errno;
129 + rc2 = xc_domain_unpause(xch, domain_id);
130 + if ( rc1 != 0 || rc2 != 0 )
135 + saved_errno = errno;
136 + PERROR("Unable to unpause domain");
140 + munmap(ring_page, XC_PAGE_SIZE);
143 + errno = saved_errno;
148 diff -durN -x '*~' -x '*.orig' -x '*.rej' xen-4.4.0.orig/tools/libxc/xenctrl.h xen-4.4.0/tools/libxc/xenctrl.h
149 --- xen-4.4.0.orig/tools/libxc/xenctrl.h 2014-03-10 11:43:57.000000000 +0100
150 +++ xen-4.4.0/tools/libxc/xenctrl.h 2014-06-18 10:19:54.000000000 +0200
151 @@ -2040,6 +2040,12 @@
152 int xc_mem_event_memop(xc_interface *xch, domid_t domain_id,
153 unsigned int op, unsigned int mode,
154 uint64_t gfn, void *buffer);
156 + * Enables mem_event and returns the mapped ring page indicated by param.
157 + * param can be HVM_PARAM_PAGING/ACCESS/SHARING_RING_PFN
159 +void *xc_mem_event_enable(xc_interface *xch, domid_t domain_id, int param,
163 * Mem paging operations.
164 @@ -2060,7 +2066,13 @@
165 * Access tracking operations.
166 * Supported only on Intel EPT 64 bit processors.
168 -int xc_mem_access_enable(xc_interface *xch, domid_t domain_id, uint32_t *port);
171 + * Enables mem_access and returns the mapped ring page.
172 + * Will return NULL on error.
173 + * Caller has to unmap this page when done.
175 +void *xc_mem_access_enable(xc_interface *xch, domid_t domain_id, uint32_t *port);
176 int xc_mem_access_disable(xc_interface *xch, domid_t domain_id);
177 int xc_mem_access_resume(xc_interface *xch, domid_t domain_id,
179 diff -durN -x '*~' -x '*.orig' -x '*.rej' xen-4.4.0.orig/tools/tests/xen-access/xen-access.c xen-4.4.0/tools/tests/xen-access/xen-access.c
180 --- xen-4.4.0.orig/tools/tests/xen-access/xen-access.c 2014-03-10 11:43:57.000000000 +0100
181 +++ xen-4.4.0/tools/tests/xen-access/xen-access.c 2014-06-18 10:20:55.000000000 +0200
183 xenaccess_t *xenaccess = 0;
186 - unsigned long ring_pfn, mmap_pfn;
188 xch = xc_interface_open(NULL, NULL, 0);
190 @@ -253,40 +252,12 @@
191 /* Initialise lock */
192 mem_event_ring_lock_init(&xenaccess->mem_event);
194 - /* Map the ring page */
195 - xc_get_hvm_param(xch, xenaccess->mem_event.domain_id,
196 - HVM_PARAM_ACCESS_RING_PFN, &ring_pfn);
197 - mmap_pfn = ring_pfn;
198 - xenaccess->mem_event.ring_page =
199 - xc_map_foreign_batch(xch, xenaccess->mem_event.domain_id,
200 - PROT_READ | PROT_WRITE, &mmap_pfn, 1);
201 - if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
203 - /* Map failed, populate ring page */
204 - rc = xc_domain_populate_physmap_exact(xenaccess->xc_handle,
205 - xenaccess->mem_event.domain_id,
206 - 1, 0, 0, &ring_pfn);
209 - PERROR("Failed to populate ring gfn\n");
213 - mmap_pfn = ring_pfn;
214 - xenaccess->mem_event.ring_page =
215 - xc_map_foreign_batch(xch, xenaccess->mem_event.domain_id,
216 - PROT_READ | PROT_WRITE, &mmap_pfn, 1);
217 - if ( mmap_pfn & XEN_DOMCTL_PFINFO_XTAB )
219 - PERROR("Could not map the ring page\n");
224 - /* Initialise Xen */
225 - rc = xc_mem_access_enable(xenaccess->xc_handle, xenaccess->mem_event.domain_id,
226 - &xenaccess->mem_event.evtchn_port);
228 + /* Enable mem_access */
229 + xenaccess->mem_event.ring_page =
230 + xc_mem_access_enable(xenaccess->xc_handle,
231 + xenaccess->mem_event.domain_id,
232 + &xenaccess->mem_event.evtchn_port);
233 + if ( xenaccess->mem_event.ring_page == NULL )
238 ERROR("EPT not supported for this guest");
241 - perror("Error initialising shared page");
242 + perror("Error enabling mem_access");
247 (mem_event_sring_t *)xenaccess->mem_event.ring_page,
250 - /* Now that the ring is set, remove it from the guest's physmap */
251 - if ( xc_domain_decrease_reservation_exact(xch,
252 - xenaccess->mem_event.domain_id, 1, 0, &ring_pfn) )
253 - PERROR("Failed to remove ring from guest physmap");
255 /* Get platform info */
256 xenaccess->platform_info = malloc(sizeof(xc_platform_info_t));
257 if ( xenaccess->platform_info == NULL )