Re: [PATCH v6 2/2] riscv: Map the kernel with correct permissions the first time
From: Christoph Hellwig
Date: Mon Jun 21 2021 - 11:08:26 EST
On Thu, Jun 17, 2021 at 03:17:34PM +0200, Alexandre Ghiti wrote:
>
> void free_initmem(void)
> {
> if (IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
> + set_kernel_memory(lm_alias(__init_begin), lm_alias(__init_end),
> + IS_ENABLED(CONFIG_64BIT) ? set_memory_rw : set_memory_rw_nx);
Breaking the second line up woul help a lot with readability:
set_kernel_memory(lm_alias(__init_begin), lm_alias(__init_end),
IS_ENABLED(CONFIG_64BIT) ?
set_memory_rw : set_memory_rw_nx);
> +#ifdef CONFIG_STRICT_KERNEL_RWX
> +static __init pgprot_t pgprot_from_va(uintptr_t va)
> +{
> + if (is_va_kernel_text(va))
> + return PAGE_KERNEL_READ_EXEC;
> +
> + /*
> + * In 64b kernel, the kernel mapping is outside the linear mapping so we
Spelling out 64-bit would be nice.
> + * must protect its linear mapping alias from being executed and written.
And please never spill comments over 80 characters, as that makes them
completely unreadable.
Besides a few more overly long lines this looks great.