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

[Minios-devel] [UNIKRAFT PATCH v2 3/6] plat: Introduce API for setting platform default allocator


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Thu, 28 Jun 2018 15:38:32 +0300
  • Cc: simon.kuenzer@xxxxxxxxx, sharan.santhanam@xxxxxxxxx, yuri.volchkov@xxxxxxxxx
  • Delivery-date: Thu, 28 Jun 2018 12:38:50 +0000
  • Ironport-phdr: 9a23:qNZ1fx/Lgmgcg/9uRHKM819IXTAuvvDOBiVQ1KB20OwcTK2v8tzYMVDF4r011RmVBduds6oMotGVmpioYXYH75eFvSJKW713fDhBt/8rmRc9CtWOE0zxIa2iRSU7GMNfSA0tpCnjYgBaF8nkelLdvGC54yIMFRXjLwp1Ifn+FpLPg8it2O2+55zebx9UiDahfLh/MAi4oQLNu8cMnIBsMLwxyhzHontJf+RZ22ZlLk+Nkhj/+8m94odt/zxftPw9+cFAV776f7kjQrxDEDsmKWE169b1uhTFUACC+2ETUmQSkhpPHgjF8BT3VYr/vyfmquZw3jSRMMvrRr42RDui9b9mRh/2hikaOTA382bZhc5+jK9AvB6tuwZyz5LObY2JKPZzeL7Wc9MARWpGW8ZcTzJMAoSnb4sTDuoBO/tToY/gp1sWsBu1GA6hC//oyj9Tmn/23Ks63/4lEQHbxAwgAskDv2jPrNnvLKcSTPu6wLPSzTXEdv5b3yr25ovQch05vP2BUq98fdDSxEQvDQ/JkEucpI7/Mz6bzugBrmeW4/d6We+si2MrsR99rzahy8s2l4XEiZwZx1bZ/itj2ok1P8e3SEtjbN6hF5tfqj+VOpNtQsMnX2FooCE6yqAauZKjfCgF1pAnxxnHZvyZdoiH+BPjVOKLLThkn3JpYqq/hwup/kS60O38UdG40FdMriVbjtnBrm0B2hPO5sSdSfZw/l2t1SiR2w3R8O1JL1g4la/BJJ4gxr4wmIATsUPGHiLuhEr2i7SWdlkl+uiu8ejnZqjmpoeBN4Jvlg7+Kb4imtSiAesjKAQORW+b9fym1LL/5U35XKlKjvoun6ncsZDaI8UbpqmiAwNMz4ks9Qi/ACmi0NkDmXkHLUlFeA6cj4TzNFDBPvb4Ae24g1S2nzdh3+rGMaH5ApXRMnjDl6/sfa1960FG0go819Zf64hPCr4bJvLzRk/xu8beDhAjNgy52ODnB8th2YMaQ22AGbWVP73PsVWQ/OIgP/GMZJMJuDb6M/Ul/P/ujXo+mV8bZ6Wp3oYXZ26+HvVnPUqZe2HhgtEfHmgWugoxVvflhEecXj5Of3yyRb4z5iknCIK6CofOXoCsgKGb3Ce6BJFWeGdGClSQHnfodIWEXOkMZTmUIsB/jjMEUaKuRJQ72R6wqQ+pg4Zge+/V/Cwfrtfv2cZ448XXlAou7npkAsLb1HuCHE9umWZdbDgtwKF56Whg0krLhaN/mOBZE5pX+utUegwhc4bBxapgDIahCUr6Yt6VRQP+EZ2dCjYrQ4dpzg==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

Kernel subsystems may require memory allocation for internal
initializations and therefore such operations cannot occur before a
memory allocator is initialized. We introduce the platform memory
allocator which should be set right after initializing the default
memory allocator. Setting the platform allocator also triggers the
creation of internal memory mappings which would be essential for
platform setup before running the application. An example of subsystem
which would need  such mappings is the grants subsystem for Xen. The
current patch contains changes for all platforms.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 include/uk/plat/memory.h     | 15 ++++++++++++
 plat/common/include/memory.h | 47 ++++++++++++++++++++++++++++++++++++
 plat/common/memory.c         | 57 ++++++++++++++++++++++++++++++++++++++++++++
 plat/kvm/Makefile.uk         |  1 +
 plat/kvm/memory.c            |  5 ++++
 plat/linuxu/memory.c         |  5 ++++
 plat/xen/Makefile.uk         |  1 +
 plat/xen/memory.c            |  5 ++++
 8 files changed, 136 insertions(+)
 create mode 100644 plat/common/include/memory.h
 create mode 100644 plat/common/memory.c

diff --git a/include/uk/plat/memory.h b/include/uk/plat/memory.h
index 4678eb6..60e52e6 100644
--- a/include/uk/plat/memory.h
+++ b/include/uk/plat/memory.h
@@ -37,6 +37,7 @@
 #define __UKPLAT_MEMORY_H__
 
 #include <uk/arch/types.h>
+#include <uk/alloc.h>
 #include <uk/config.h>
 
 #ifdef __cplusplus
@@ -77,6 +78,20 @@ int ukplat_memregion_count(void);
  */
 int ukplat_memregion_get(int i, struct ukplat_memregion_desc *mrd);
 
+/**
+ * Sets the platform memory allocator and triggers the platform memory mappings
+ * for which an allocator is needed.
+ * @param a Memory allocator
+ * @return 0 on success, < 0 otherwise
+ */
+int ukplat_memallocator_set(struct uk_alloc *a);
+
+/**
+ * Returns the platform memory allocator
+ * @return Platform memory allocator address
+ */
+struct uk_alloc *ukplat_memallocator_get(void);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/plat/common/include/memory.h b/plat/common/include/memory.h
new file mode 100644
index 0000000..f627348
--- /dev/null
+++ b/plat/common/include/memory.h
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Costin Lupu <costin.lupu@xxxxxxxxx>
+ *
+ * Copyright (c) 2018, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
+#ifndef __PLAT_CMN_MEMORY_H__
+#define __PLAT_CMN_MEMORY_H__
+
+/**
+ * Initializes the platform memory mappings which require an allocator. This
+ * function must always be called after initializing a memory allocator and
+ * before initializing the subsystems that require memory allocation. It is an
+ * internal function common to all platforms.
+ * @return 0 on success, < 0 otherwise
+ */
+int _ukplat_mem_mappings_init(void);
+
+#endif /* __PLAT_CMN_MEMORY_H__ */
diff --git a/plat/common/memory.c b/plat/common/memory.c
new file mode 100644
index 0000000..30983a7
--- /dev/null
+++ b/plat/common/memory.c
@@ -0,0 +1,57 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/*
+ * Authors: Costin Lupu <costin.lupu@xxxxxxxxx>
+ *
+ * Copyright (c) 2018, NEC Europe Ltd., NEC Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the names of its
+ *    contributors may be used to endorse or promote products derived from
+ *    this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
+ */
+
+#include <uk/plat/memory.h>
+#include <memory.h>
+
+static struct uk_alloc *plat_allocator;
+
+int ukplat_memallocator_set(struct uk_alloc *a)
+{
+       UK_ASSERT(a != NULL);
+
+       if (plat_allocator != NULL)
+               return -1;
+
+       plat_allocator = a;
+
+       _ukplat_mem_mappings_init();
+
+       return 0;
+}
+
+struct uk_alloc *ukplat_memallocator_get(void)
+{
+       return plat_allocator;
+}
diff --git a/plat/kvm/Makefile.uk b/plat/kvm/Makefile.uk
index 2705fd1..9bedb37 100644
--- a/plat/kvm/Makefile.uk
+++ b/plat/kvm/Makefile.uk
@@ -40,5 +40,6 @@ LIBKVMPLAT_SRCS-y              += $(LIBKVMPLAT_BASE)/irq.c
 LIBKVMPLAT_SRCS-y              += $(LIBKVMPLAT_BASE)/time.c
 LIBKVMPLAT_SRCS-y              += $(LIBKVMPLAT_BASE)/tscclock.c
 LIBKVMPLAT_SRCS-y              += $(UK_PLAT_COMMON_BASE)/lcpu.c|common
+LIBKVMPLAT_SRCS-y              += $(UK_PLAT_COMMON_BASE)/memory.c|common
 
 LIBKVMPCI_SRCS-y                     += $(UK_PLAT_COMMON_BASE)/pci_bus.c|common
diff --git a/plat/kvm/memory.c b/plat/kvm/memory.c
index 3fe1558..11c993d 100644
--- a/plat/kvm/memory.c
+++ b/plat/kvm/memory.c
@@ -131,3 +131,8 @@ int ukplat_memregion_get(int i, struct 
ukplat_memregion_desc *m)
 
        return ret;
 }
+
+int _ukplat_mem_mappings_init(void)
+{
+       return 0;
+}
diff --git a/plat/linuxu/memory.c b/plat/linuxu/memory.c
index b7dbc43..35d0d95 100644
--- a/plat/linuxu/memory.c
+++ b/plat/linuxu/memory.c
@@ -69,3 +69,8 @@ int ukplat_memregion_get(int i, struct ukplat_memregion_desc 
*m)
 
        return ret;
 }
+
+int _ukplat_mem_mappings_init(void)
+{
+       return 0;
+}
diff --git a/plat/xen/Makefile.uk b/plat/xen/Makefile.uk
index 1341da8..3305a84 100644
--- a/plat/xen/Makefile.uk
+++ b/plat/xen/Makefile.uk
@@ -28,6 +28,7 @@ LIBXENPLAT_CINCLUDES-y         += 
-I$(UK_PLAT_COMMON_BASE)/include
 LIBXENPLAT_SRCS-y              += $(LIBXENPLAT_BASE)/hypervisor.c
 LIBXENPLAT_SRCS-y              += $(LIBXENPLAT_BASE)/memory.c
 LIBXENPLAT_SRCS-y              += $(UK_PLAT_COMMON_BASE)/lcpu.c|common
+LIBXENPLAT_SRCS-y              += $(UK_PLAT_COMMON_BASE)/memory.c|common
 
 ifneq (,$(filter x86_32 x86_64,$(CONFIG_UK_ARCH)))
 LIBXENPLAT_SRCS-$(CONFIG_ARCH_X86_64) += 
$(UK_PLAT_COMMON_BASE)/x86/trace.c|common
diff --git a/plat/xen/memory.c b/plat/xen/memory.c
index 18df5da..6ae92f4 100644
--- a/plat/xen/memory.c
+++ b/plat/xen/memory.c
@@ -119,3 +119,8 @@ int ukplat_memregion_get(int i, struct 
ukplat_memregion_desc *m)
 
        return 0;
 }
+
+int _ukplat_mem_mappings_init(void)
+{
+       return 0;
+}
-- 
2.11.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®.