[PATCH v2 08/11] arm64: vdso: Simplify pagelist allocation
Mark Brown
broonie at kernel.org
Wed Jul 1 16:28:43 EDT 2020
Currently we allocate a single array for the struct page * for the vDSO
and then do the lookup for code and data in slightly different ways. Make
this more regular by factoring out the array allocation and struct page *
lookup into a function and using it for both. We don't currently rely on
everything being in one array so there should be no functional change.
Signed-off-by: Mark Brown <broonie at kernel.org>
---
arch/arm64/kernel/vdso.c | 42 ++++++++++++++++++++--------------------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c
index 032249f70460..f78349faa6c4 100644
--- a/arch/arm64/kernel/vdso.c
+++ b/arch/arm64/kernel/vdso.c
@@ -88,12 +88,23 @@ static int __vdso_remap(enum vdso_abi abi,
return 0;
}
-static int __vdso_init(enum vdso_abi abi)
+static struct page **vdso_get_pages(unsigned long pfn, size_t pages)
{
+ struct page **pagelist;
int i;
- struct page **vdso_pagelist;
- unsigned long pfn;
+ pagelist = kcalloc(pages, sizeof(struct page *), GFP_KERNEL);
+ if (!pagelist)
+ return NULL;
+
+ for (i = 0; i < pages; i++)
+ pagelist[i] = pfn_to_page(pfn + i);
+
+ return pagelist;
+}
+
+static int __vdso_init(enum vdso_abi abi)
+{
if (memcmp(vdso_info[abi].vdso_code_start, "\177ELF", 4)) {
pr_err("vDSO is not a valid ELF object!\n");
return -EINVAL;
@@ -113,25 +124,14 @@ static int __vdso_init(enum vdso_abi abi)
vdso_info[abi].vdso_code_start) >>
PAGE_SHIFT;
- /* Allocate the vDSO pagelist, plus a page for the data. */
- vdso_pagelist = kcalloc(vdso_info[abi].vdso_text_pages + 1,
- sizeof(struct page *),
- GFP_KERNEL);
- if (vdso_pagelist == NULL)
- return -ENOMEM;
-
- /* Grab the vDSO data page. */
- vdso_pagelist[0] = phys_to_page(__pa_symbol(vdso_data));
-
+ vdso_info[abi].dm->pages =
+ vdso_get_pages(sym_to_pfn(vdso_data), 1);
+ vdso_info[abi].cm->pages =
+ vdso_get_pages(sym_to_pfn(vdso_info[abi].vdso_code_start),
+ vdso_info[abi].vdso_text_pages);
- /* Grab the vDSO code pages. */
- pfn = sym_to_pfn(vdso_info[abi].vdso_code_start);
-
- for (i = 0; i < vdso_info[abi].vdso_text_pages; i++)
- vdso_pagelist[i + 1] = pfn_to_page(pfn + i);
-
- vdso_info[abi].dm->pages = &vdso_pagelist[0];
- vdso_info[abi].cm->pages = &vdso_pagelist[1];
+ if (!vdso_info[abi].cm->pages || !vdso_info[abi].dm->pages)
+ return -ENOMEM;
return 0;
}
--
2.20.1
More information about the linux-arm-kernel
mailing list