]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
plat/common: Make `ukplat_memregion_alloc` aware of memory holes
authorSergiu Moga <sergiu.moga@protonmail.com>
Sat, 8 Apr 2023 09:57:03 +0000 (12:57 +0300)
committerUnikraft <monkey@unikraft.io>
Fri, 11 Aug 2023 10:18:44 +0000 (10:18 +0000)
In case we are somehow able to allocate memory from an in-image
memory hole, make sure we do not give it the `UKPLAT_MEMRF_MAP`
flag, since it is already mapped, which causes the paging
initialization phase to exit with an `-EEXIST` error code.

Signed-off-by: Sergiu Moga <sergiu.moga@protonmail.com>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #848

plat/common/memory.c

index c174a366e2d79830c37cdbdc97142086ef31f144..e92c3228b8ac35d66e801df98791e7790b203e2a 100644 (file)
@@ -32,6 +32,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <uk/plat/common/sections.h>
 #include <uk/plat/common/bootinfo.h>
 #include <uk/asm/limits.h>
 #include <uk/alloc.h>
@@ -91,6 +92,13 @@ void *ukplat_memregion_alloc(__sz size, int type, __u16 flags)
                ostart = mrd->pbase;
                olen   = mrd->len;
 
+               /* Check whether we are allocating from an in-image memory hole
+                * or not. If no, then it is not already mapped.
+                */
+               if (!RANGE_CONTAIN(__BASE_ADDR, __END - __BASE_ADDR,
+                                  pstart, size))
+                       flags |= UKPLAT_MEMRF_MAP;
+
                /* If fragmenting this memory region leaves it with length 0,
                 * then simply overwrite and return it instead.
                 */
@@ -99,7 +107,7 @@ void *ukplat_memregion_alloc(__sz size, int type, __u16 flags)
                        mrd->vbase = pstart;
                        mrd->len = pend - pstart;
                        mrd->type = type;
-                       mrd->flags = flags | UKPLAT_MEMRF_MAP;
+                       mrd->flags = flags;
 
                        return (void *)pstart;
                }