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 <npitre@baylibre.com>
This commit is contained in:
Nicolas Pitre 2021-02-11 16:38:08 -05:00 committed by Anas Nashif
commit f2995bcca2

View file

@ -49,6 +49,42 @@ strlen_done:
str w4, [x2] str w4, [x2]
ret 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 * Routine to jump into userspace
* *