From f2995bcca2a81e599300f5796af13c0d00f7fa30 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Thu, 11 Feb 2021 16:38:08 -0500 Subject: [PATCH] aarch64: arch_buffer_validate() implementation This leverages the AT (address translation) instruction to test for given access permission. The result is then provided in the PAR_EL1 register. Thanks to @jharris-intel for the suggestion. Signed-off-by: Nicolas Pitre --- arch/arm/core/aarch64/userspace.S | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/arch/arm/core/aarch64/userspace.S b/arch/arm/core/aarch64/userspace.S index ae42734a722..f24801fd54d 100644 --- a/arch/arm/core/aarch64/userspace.S +++ b/arch/arm/core/aarch64/userspace.S @@ -49,6 +49,42 @@ strlen_done: str w4, [x2] ret +/* + * int arch_buffer_validate(void *addr, size_t size, int write) + */ + +GTEXT(arch_buffer_validate) +SECTION_FUNC(TEXT, arch_buffer_validate) + + add x1, x1, x0 + mrs x3, DAIF + msr DAIFSET, #DAIFSET_IRQ_BIT + +abv_loop: + cbnz w2, 1f + at S1E0R, x0 + b 2f +1: at S1E0W, x0 + +2: orr x0, x0, #(CONFIG_MMU_PAGE_SIZE - 1) + add x0, x0, #1 + + isb + mrs x4, PAR_EL1 + tbnz x4, #0, abv_fail + + cmp x0, x1 + blo abv_loop + + msr DAIF, x3 + mov x0, #0 + ret + +abv_fail: + msr DAIF, x3 + mov x0, #-1 + ret + /* * Routine to jump into userspace *