On 06.06.2023 21:55, Oleksii Kurochko wrote:
> The function was introduced to not calculate and save physical
> offset before MMU is enabled because access to start() is
> PC-relative and in case of linker_addr != load_addr it will result
> in incorrect value in phys_offset.
"... to _not_ calculate ..."?
> --- a/xen/arch/riscv/mm.c
> +++ b/xen/arch/riscv/mm.c
> @@ -19,9 +19,11 @@ struct mmu_desc {
>
> extern unsigned char cpu0_boot_stack[STACK_SIZE];
>
> -#define PHYS_OFFSET ((unsigned long)_start - XEN_VIRT_START)
> -#define LOAD_TO_LINK(addr) ((addr) - PHYS_OFFSET)
> -#define LINK_TO_LOAD(addr) ((addr) + PHYS_OFFSET)
> +static unsigned long phys_offset;
__ro_after_init?
> +#define LOAD_TO_LINK(addr) ((unsigned long)(addr) - phys_offset)
> +#define LINK_TO_LOAD(addr) ((unsigned long)(addr) + phys_offset)
> +
>
Nit: No double blank lines please.
> @@ -273,3 +275,13 @@ void __init noreturn noinline enable_mmu()
> switch_stack_and_jump((unsigned long)cpu0_boot_stack + STACK_SIZE,
> cont_after_mmu_is_enabled);
> }
> +
> +/*
> + * calc_phys_offset() should be used before MMU is enabled because access to
> + * start() is PC-relative and in case when load_addr != linker_addr
> phys_offset
> + * will have an incorrect value
> + */
> +void calc_phys_offset(void)
__init? And nit: No double blanks please.
Jan