[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3 2/3] xen/riscv: introduce function for physical offset calculation


  • To: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 17 Jul 2023 16:58:46 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kZPoecbJRYlRk6sfmVlBwFwGvOQqhrFi6GDzPvdfhZQ=; b=CI+3Xnf9BGTCZbkup+QH5Yn9JvtuDJ8BFc5u6JPkHI0RF3DFsVkj79KarOTkeX97BaWHI8cxbamOfG/2BFzGbIhzrR3TV8DOP0fnpVYTGcukAtTfZPLREH5Z8XCF+ruJ1NXrQ5/d29HUjRwWIZ3gr0b9ClUPXEIYAAR+rXiEsLk5ltg38uIeJBcEW9+27HIhBsMUxPtRb6+BXR/NoTZFHMyb4ibb2LXIMmvsqQQUZ29KexXPjxz7V9SJZsv6xTpdJG4k+XSaCYNlqINQ5pAGP9s89GA867D/jrNo6nC7gMFIIMHaVC7ycimTOm8CaOVf+UCQzGvF/y/EUdXQ+yhx4Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bh0vG7yO+97d/69SQ9kw6t1j0s6engY/m4BNr86+IGqqRuTOei+LVonot5lzCw8ibZquzl8pkIOVGp52H2PA/yVNq35a8p3zu1rrnnp5zlW3KB5nMcgFNXvG4A8zSz9hlKWMRDh+BS1n94J37TzhzXMUMN/xWCP52xTejFxbGrmtM3XkXWXsQFFKT3wCplcZEO6vimDNFjsmHYZiRO7+byvPihYrPxjhPL3gibiMakQ69PbxaP0T85+iWXy/OR7u3UibfmnjY+S/ACEL49L3HBh9efK9rX0062/LSzlAn/W7RT/GbmWIH4F+0lMRNvgZdqQMRd/3v27f4octaD4FZA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Bob Eshleman <bobbyeshleman@xxxxxxxxx>, Alistair Francis <alistair.francis@xxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Mon, 17 Jul 2023 14:59:16 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 17.07.2023 16:40, Oleksii Kurochko wrote:
> The function was introduced to 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.
> 
> Signed-off-by: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
> ---
> Changes in V3:
>  - save/restore of a0/a1 registers before C first function call.
> ---
> Changes in V2:
>   - add __ro_after_init for phys_offset variable.
>   - remove double blank lines.
>   - add __init for calc_phys_offset().
>   - update the commit message.
>   - declaring variable phys_off as non static as it will be used in head.S.
> ---
>  xen/arch/riscv/include/asm/mm.h |  2 ++
>  xen/arch/riscv/mm.c             | 18 +++++++++++++++---
>  xen/arch/riscv/riscv64/head.S   | 14 ++++++++++++++
>  3 files changed, 31 insertions(+), 3 deletions(-)
> 
> diff --git a/xen/arch/riscv/include/asm/mm.h b/xen/arch/riscv/include/asm/mm.h
> index 5e3ac5cde3..d9c4205103 100644
> --- a/xen/arch/riscv/include/asm/mm.h
> +++ b/xen/arch/riscv/include/asm/mm.h
> @@ -15,4 +15,6 @@ void setup_initial_pagetables(void);
>  void enable_mmu(void);
>  void cont_after_mmu_is_enabled(void);
>  
> +void calc_phys_offset(void);
> +
>  #endif /* _ASM_RISCV_MM_H */
> diff --git a/xen/arch/riscv/mm.c b/xen/arch/riscv/mm.c
> index fddb3cd0bd..c84a8a7c3c 100644
> --- a/xen/arch/riscv/mm.c
> +++ b/xen/arch/riscv/mm.c
> @@ -1,5 +1,6 @@
>  /* SPDX-License-Identifier: GPL-2.0-only */
>  
> +#include <xen/cache.h>
>  #include <xen/compiler.h>
>  #include <xen/init.h>
>  #include <xen/kernel.h>
> @@ -19,9 +20,10 @@ struct mmu_desc {
>      pte_t *pgtbl_base;
>  };
>  
> -#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)
> +unsigned long __ro_after_init phys_offset;
> +
> +#define LOAD_TO_LINK(addr) ((unsigned long)(addr) - phys_offset)
> +#define LINK_TO_LOAD(addr) ((unsigned long)(addr) + phys_offset)
>  
>  /*
>   * It is expected that Xen won't be more then 2 MB.
> @@ -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 __init calc_phys_offset(void)
> +{
> +    phys_offset = (unsigned long)start - XEN_VIRT_START;
> +}
> diff --git a/xen/arch/riscv/riscv64/head.S b/xen/arch/riscv/riscv64/head.S
> index 2c0304646a..9015d06233 100644
> --- a/xen/arch/riscv/riscv64/head.S
> +++ b/xen/arch/riscv/riscv64/head.S
> @@ -29,6 +29,20 @@ ENTRY(start)
>  
>          jal     reset_stack
>  
> +        /*
> +         * save hart_id and dtb_base as a0 and a1 register can be used
> +         * by C code ( f.e. setup_initial_pagetables will update a0 and
> +         * a1 )

I'd recommend dropping the part in parentheses - for one the function
doesn't exist yet, and then you're merely restating what the ABI has.

> +         */
> +        mv      s0, a0
> +        mv      s1, a1
> +
> +        jal     calc_phys_offset
> +
> +        /* restore bootcpu_id and dtb address */

Is the first name here intentionally different from that in the other
comment (where it's "hart_id")?

Jan

> +        mv      a0, s0
> +        mv      a1, s1
> +
>          tail    start_xen
>  
>          .section .text, "ax", %progbits




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.