[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH 2/5] plat/xen: Xen Balloon Driver



From: Cason Schindler <cason.j.schindler@xxxxxxxxx>

Add balloon driver to interface with Xen hypervisor using hypercalls.
Implement inflate and deflate API calls.

Signed-off-by: Jack Raney <raney.jack99@xxxxxxxxx>
Signed-off-by: Cason Schindler <cason.j.schindler@xxxxxxxxx>
---
 plat/xen/memory.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)

diff --git a/plat/xen/memory.c b/plat/xen/memory.c
index 8e7a7dd..fdb8aff 100644
--- a/plat/xen/memory.c
+++ b/plat/xen/memory.c
@@ -40,11 +40,15 @@
 #if (defined __X86_32__) || (defined __X86_64__)
 #include <xen-x86/setup.h>
 #include <xen-x86/mm_pv.h>
+#include <xen-x86/mm.h>
 #elif (defined __ARM_32__) || (defined __ARM_64__)
 #include <xen-arm/setup.h>
 #include <xen-arm/mm.h>
 #endif
 
+#include <xen/memory.h>
+#include <common/hypervisor.h>
+
 #include <uk/assert.h>
 
 int ukplat_memregion_count(void)
@@ -163,3 +167,77 @@ void ukplat_stack_set_current_thread(void *thread_addr)
        extern char irqstack[];
        *((unsigned long *) irqstack) = (unsigned long) thread_addr;
 }
+
+/**
+ * set up and call Xen hypercall to ask for memory back from Xen
+*/
+int xenmem_reservation_increase(int count, xen_pfn_t *frames, int order)
+{
+        struct xen_memory_reservation res = {
+#if __XEN_INTERFACE_VERSION__ >= 0x00030209
+                .memflags = 0;
+#else
+                .address_bits = 0,
+#endif
+                .extent_order = order,
+                .domid        = DOMID_SELF
+        };
+
+        set_xen_guest_handle(res.extent_start, frames);
+        res.nr_extents = count;
+
+               /* Needs physical frame number */
+        int r = HYPERVISOR_memory_op(XENMEM_populate_physmap, &res);
+        return r;
+}
+
+/**
+ * set up and call Xen hypercall to give memory to Xen
+*/
+int xenmem_reservation_decrease(int count, xen_pfn_t *frames, int order)
+{
+        struct xen_memory_reservation res = {
+#if __XEN_INTERFACE_VERSION__ >= 0x00030209
+                .mem_flags = 0,
+#else
+                .address_bits = 0,
+#endif
+                .extent_order = order,
+                .domid        = DOMID_SELF
+        };
+
+        set_xen_guest_handle(res.extent_start, frames);
+        res.nr_extents = count;
+
+               /* Needs guest frame number */
+        int r = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &res);
+        return r;
+}
+
+/**
+ * When we inflate we will be decreasing the memory available to the VM
+ * We will give the extent of extent order = order starting at va to the host.
+*/
+int ukplat_inflate(void* va, int order)
+{
+
+       xen_pfn_t pfn = virt_to_pfn(va);
+       int r = xenmem_reservation_decrease(1, &pfn, order);
+
+       return r;
+}
+
+/**
+ * When we deflate we will be increasing the memory available to the VM
+ * We will ask for 1 extent of extent order = order back from the host. It 
will map
+ * The extent to the address va.
+*/
+int ukplat_deflate(void* va, int order)
+{
+       /* Make sure we are sending the correct frame number. Should be a GFN */
+       //xen_pfn_t pfn = virt_to_pfn(va);
+       int r = xenmem_reservation_increase(1, &va, order);
+
+       return r;
+}
+
-- 
2.24.0


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.