]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
plat/common: Add `flags` field to `ukplat_memregion_alloc`
authorSergiu Moga <sergiu.moga@protonmail.com>
Sat, 8 Apr 2023 09:55:25 +0000 (12:55 +0300)
committerUnikraft <monkey@unikraft.io>
Fri, 11 Aug 2023 10:18:44 +0000 (10:18 +0000)
Increase `ukplat_memregion_alloc`'s memory region allocation
flexibility by giving the caller the ability to customize
the memory region's flags.

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

include/uk/plat/memory.h
plat/common/memory.c
plat/kvm/x86/setup.c
plat/xen/x86/setup.c

index 3a137c9e5bbb367b6a252f4dd5257b9f42c12f4b..c1b32411eb8720a0d9eec1cc4fb37e8be80855a3 100644 (file)
@@ -229,11 +229,13 @@ struct uk_alloc *ukplat_memallocator_get(void);
  *   The size to allocate. Will be rounded up to next multiple of page size.
  * @param type
  *   Memory region type to use for the allocated memory. Can be 0.
+ * @param flags
+ *   Flags of the allocated memory region.
  *
  * @return
  *   A pointer to the allocated memory on success, NULL otherwise.
  */
-void *ukplat_memregion_alloc(__sz size, int type);
+void *ukplat_memregion_alloc(__sz size, int type, __u16 flags);
 
 #ifdef __cplusplus
 }
index 0b8e933883b2998d8c0c6b1055bbab6a3b12b781..c174a366e2d79830c37cdbdc97142086ef31f144 100644 (file)
@@ -59,7 +59,7 @@ struct uk_alloc *ukplat_memallocator_get(void)
        return plat_allocator;
 }
 
-void *ukplat_memregion_alloc(__sz size, int type)
+void *ukplat_memregion_alloc(__sz size, int type, __u16 flags)
 {
        struct ukplat_memregion_desc *mrd, alloc_mrd = {0};
        __vaddr_t unmap_start, unmap_end;
@@ -99,9 +99,7 @@ void *ukplat_memregion_alloc(__sz size, int type)
                        mrd->vbase = pstart;
                        mrd->len = pend - pstart;
                        mrd->type = type;
-                       mrd->flags = UKPLAT_MEMRF_READ |
-                                    UKPLAT_MEMRF_WRITE |
-                                    UKPLAT_MEMRF_MAP;
+                       mrd->flags = flags | UKPLAT_MEMRF_MAP;
 
                        return (void *)pstart;
                }
@@ -117,9 +115,7 @@ void *ukplat_memregion_alloc(__sz size, int type)
                alloc_mrd.pbase = pstart;
                alloc_mrd.len   = size;
                alloc_mrd.type  = type;
-               alloc_mrd.flags = UKPLAT_MEMRF_READ  |
-                                 UKPLAT_MEMRF_WRITE |
-                                 UKPLAT_MEMRF_MAP;
+               alloc_mrd.flags = flags | UKPLAT_MEMRF_MAP;
 
                bi = ukplat_bootinfo_get();
                if (unlikely(!bi))
index 7e63b274a90fda29b9262a837446bf86478c99d3..03c6d436d313bdb463cadbe4eb3e3f009fb57f4c 100644 (file)
@@ -224,7 +224,10 @@ static inline int cmdline_init(struct ukplat_bootinfo *bi)
         * by `ukplat_entry_argp` to obtain argc/argv. So mark it as a kernel
         * resource instead.
         */
-       cmdline = ukplat_memregion_alloc(cmdline_len + 1, UKPLAT_MEMRT_KERNEL);
+       cmdline = ukplat_memregion_alloc(cmdline_len + 1, UKPLAT_MEMRT_KERNEL,
+                                        UKPLAT_MEMRF_READ |
+                                        UKPLAT_MEMRF_WRITE |
+                                        UKPLAT_MEMRF_MAP);
        if (unlikely(!cmdline))
                return -ENOMEM;
 
@@ -272,7 +275,10 @@ void _ukplat_entry(struct lcpu *lcpu, struct ukplat_bootinfo *bi)
                UK_CRASH("Cmdline init failed: %d\n", rc);
 
        /* Allocate boot stack */
-       bstack = ukplat_memregion_alloc(__STACK_SIZE, UKPLAT_MEMRT_STACK);
+       bstack = ukplat_memregion_alloc(__STACK_SIZE, UKPLAT_MEMRT_STACK,
+                                       UKPLAT_MEMRF_READ |
+                                       UKPLAT_MEMRF_WRITE |
+                                       UKPLAT_MEMRF_MAP);
        if (unlikely(!bstack))
                UK_CRASH("Boot stack alloc failed\n");
 
index 15986e81e6b33c92e8c5e4a03f19fb07bff1c2d1..5baf1f28ce0718cf73a56855ccfe368ba4963f89 100644 (file)
@@ -204,7 +204,8 @@ static void _libxenplat_x86bootinfo_setup_cmdl(struct ukplat_bootinfo *bi)
        if (!cmdline_len)
                cmdline_len = sizeof(CONFIG_UK_NAME) - 1;
 
-       cmdline = ukplat_memregion_alloc(cmdline_len, UKPLAT_MEMRT_CMDLINE);
+       cmdline = ukplat_memregion_alloc(cmdline_len, UKPLAT_MEMRT_CMDLINE,
+                                        UKPLAT_MEMRF_READ | UKPLAT_MEMRF_MAP);
        if (unlikely(!cmdline))
                UK_CRASH("Could not allocate command-line memory");
 
@@ -218,7 +219,8 @@ static void _libxenplat_x86bootinfo_setup_cmdl(struct ukplat_bootinfo *bi)
        /* Tag this scratch cmdline as a kernel resource, to distinguish it
         * from the original cmdline obtained above
         */
-       cmdline = ukplat_memregion_alloc(cmdline_len, UKPLAT_MEMRT_KERNEL);
+       cmdline = ukplat_memregion_alloc(cmdline_len, UKPLAT_MEMRT_KERNEL,
+                                        UKPLAT_MEMRF_READ | UKPLAT_MEMRF_MAP);
        if (unlikely(!cmdline))
                UK_CRASH("Could not allocate scratch command-line memory");