]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
plat/*, lib/ukalloc: Use PAGE_ALIGN_UP(), PAGE_ALIGN_DOWN()
authorHugo Lefeuvre <hugo.lefeuvre@manchester.ac.uk>
Sun, 16 Apr 2023 13:08:17 +0000 (15:08 +0200)
committerUnikraft <monkey@unikraft.io>
Wed, 10 May 2023 13:32:28 +0000 (13:32 +0000)
We have PAGE_ALIGN_DOWN, PAGE_ALIGN_UP, and PAGE_ALIGN macros, but don't
use them consistently. At places we still have code that does custom
ALIGN_DOWN, ALIGN_UP, and masks. Use appropriate macros everywhere.

This patch was generated by the following Coccinelle rule:

    @@
    expression E;
    @@

    - ALIGN_DOWN(E, __PAGE_SIZE)
    + PAGE_ALIGN_DOWN(E)

    @@
    expression E;
    type T;
    @@

    - ALIGN_DOWN(E, (T) __PAGE_SIZE)
    + PAGE_ALIGN_DOWN(E)

    @@
    expression E;
    @@

    - ALIGN_UP(E, __PAGE_SIZE)
    + PAGE_ALIGN_UP(E)

    @@
    expression E;
    type T;
    @@

    - ALIGN_UP(E, (T) __PAGE_SIZE)
    + PAGE_ALIGN_UP(E)

    @@
    expression E;
    @@

    - (E + PAGE_SIZE - 1) & PAGE_MASK
    + PAGE_ALIGN(E)

Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@manchester.ac.uk>
Reviewed-by: Dragos Petre <dragos.petre27@gmailcom>
Reviewed-by: Alexandru Calciu <alxcalciu@gmail.com>
Approved-by: Simon Kuenzer <simon@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #842

lib/ukalloc/alloc.c
plat/kvm/arm/setup.c
plat/xen/x86/mm.c

index 4c580bfd7438a1757f8af32460cf3e066ec7253d..e097e980d4f0669cbe61898369d0ea61dc6779a0 100644 (file)
 #include <uk/assert.h>
 #include <uk/arch/limits.h>
 #include <uk/arch/lcpu.h>
+#include <uk/arch/paging.h>
 
 #if CONFIG_HAVE_MEMTAG
 #include <uk/arch/memtag.h>
 #endif
 
 #define size_to_num_pages(size) \
-       (ALIGN_UP((unsigned long)(size), __PAGE_SIZE) / __PAGE_SIZE)
+       (PAGE_ALIGN_UP((unsigned long)(size)) / __PAGE_SIZE)
 #define page_off(x) ((unsigned long)(x) & (__PAGE_SIZE - 1))
 
 struct uk_alloc *_uk_alloc_head;
@@ -108,7 +109,7 @@ static struct metadata_ifpages *uk_get_metadata(const void *ptr)
        UK_ASSERT((__uptr) ptr >= __PAGE_SIZE +
                  METADATA_IFPAGES_SIZE_POW2);
 
-       metadata = ALIGN_DOWN((__uptr) ptr, (__uptr) __PAGE_SIZE);
+       metadata = PAGE_ALIGN_DOWN((__uptr)ptr);
        if (metadata == (__uptr) ptr) {
                /* special case: the memory was page-aligned.
                 * In this case the metadata lies at the start of the
index cee4b76d4396d1001730b192b0a89417e76b8aa6..6cd8b671fa2011e4d7e9814f7b89e63ffdce0e05 100644 (file)
@@ -32,6 +32,7 @@
 #include <arm/arm64/cpu.h>
 #include <arm/smccc.h>
 #include <uk/arch/limits.h>
+#include <uk/arch/paging.h>
 
 #ifdef CONFIG_ARM64_FEAT_PAUTH
 #include <arm/arm64/pauth.h>
@@ -175,7 +176,7 @@ static void _init_dtb_mem(void)
        _libkvmplat_cfg.bstack.start = _libkvmplat_cfg.bstack.end
                                       - _libkvmplat_cfg.bstack.len;
 
-       _libkvmplat_cfg.heap.start = ALIGN_DOWN((uintptr_t)__END, __PAGE_SIZE);
+       _libkvmplat_cfg.heap.start = PAGE_ALIGN_DOWN((uintptr_t)__END);
        _libkvmplat_cfg.heap.end   = _libkvmplat_cfg.bstack.start;
        _libkvmplat_cfg.heap.len   = _libkvmplat_cfg.heap.end
                                     - _libkvmplat_cfg.heap.start;
index f4b7d1a09cc279ae7c31aa730a3c997c8300f1e0..e940fbab9c962330c51b646e5644544ae943803c 100644 (file)
@@ -537,7 +537,7 @@ extern struct shared_info _libxenplat_shared_info;
 void _init_mem_set_readonly(void *text, void *etext)
 {
     unsigned long start_address =
-        ((unsigned long) text + PAGE_SIZE - 1) & PAGE_MASK;
+        PAGE_ALIGN((unsigned long)text);
     unsigned long end_address = (unsigned long) etext;
     pgentry_t *tab = pt_base, page;
     unsigned long mfn;