From: Hugo Lefeuvre Date: Sun, 16 Apr 2023 13:08:17 +0000 (+0200) Subject: plat/*, lib/ukalloc: Use PAGE_ALIGN_UP(), PAGE_ALIGN_DOWN() X-Git-Tag: RELEASE-0.13.0~25 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=c04312c813a9ce47476f3ea7ece77f22cd888dcd;p=unikraft%2Funikraft.git plat/*, lib/ukalloc: Use PAGE_ALIGN_UP(), PAGE_ALIGN_DOWN() 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 Reviewed-by: Dragos Petre Reviewed-by: Alexandru Calciu Approved-by: Simon Kuenzer Tested-by: Unikraft CI GitHub-Closes: #842 --- diff --git a/lib/ukalloc/alloc.c b/lib/ukalloc/alloc.c index 4c580bfd7..e097e980d 100644 --- a/lib/ukalloc/alloc.c +++ b/lib/ukalloc/alloc.c @@ -41,13 +41,14 @@ #include #include #include +#include #if CONFIG_HAVE_MEMTAG #include #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 diff --git a/plat/kvm/arm/setup.c b/plat/kvm/arm/setup.c index cee4b76d4..6cd8b671f 100644 --- a/plat/kvm/arm/setup.c +++ b/plat/kvm/arm/setup.c @@ -32,6 +32,7 @@ #include #include #include +#include #ifdef CONFIG_ARM64_FEAT_PAUTH #include @@ -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; diff --git a/plat/xen/x86/mm.c b/plat/xen/x86/mm.c index f4b7d1a09..e940fbab9 100644 --- a/plat/xen/x86/mm.c +++ b/plat/xen/x86/mm.c @@ -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;