[PATCH v7 0/2] xen/riscv: introduce identity mapping

Oleksii Kurochko posted 2 patches 8 months, 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/cover.1691507564.git.oleksii.kurochko@gmail.com
xen/arch/riscv/include/asm/acpi.h   |   6 ++
xen/arch/riscv/include/asm/config.h |   2 +
xen/arch/riscv/include/asm/mm.h     |   7 +-
xen/arch/riscv/mm.c                 | 109 +++++++++++++++++-----------
xen/arch/riscv/riscv64/head.S       |  44 +++++++++++
xen/arch/riscv/setup.c              |  14 +---
xen/arch/riscv/xen.lds.S            |  11 +++
7 files changed, 136 insertions(+), 57 deletions(-)
create mode 100644 xen/arch/riscv/include/asm/acpi.h
[PATCH v7 0/2] xen/riscv: introduce identity mapping
Posted by Oleksii Kurochko 8 months, 3 weeks ago
The patch series introduces things necessary to implement identity mapping:
  1. Make identity mapping for the entire Xen.
  2. Enable MMU.
  3. Jump to the virtual address world
  4. Remove identity mapping.

Also current patch series introduces the calculation of physical offset before
MMU is enabled as access to physical offset will be calculated wrong after
MMU will be enabled because access to phys_off variable is PC-relative and
in the case when linker address != load address, it will cause MMU fault.

The reason for this patch series can be found here:
https://lore.kernel.org/xen-devel/4e336121-fc0c-b007-bf7b-430352563d55@citrix.com/

---
Changes in V7:
 - use srli instruction to be consistent with slli instruction in turn_on_mmu()
---
Changes in V6:
  - Update calc_phys_offset() after rebase.
  - Refactor turn_on_mmu() and a way how an argument of turn_on_mmu() is
    calculated.
---
Changes in V5:
	- update the algo of identity mapping removing.
	- introduce IDENT_AREA_SIZE.
	- introduce turn_on_mmu() function to enable and switch from 1:1 mapping.
	- fix typo in PGTBL_INITIAL_COUNT define.
	- update the comment above PGTBL_INITIAL_COUNT.
	- update prototype of calc_phys_offset(). now it returns phys_offset.
	- declare phys_offset as static.
	- save returned value of calc_phys_offset to register s2.
---
Changes in V4:
  - drop patch 	[PATCH v3 1/3] xen/riscv: add SPDX tag to config.h as it was
    merged to staging
  - remove definition of ARRAY_SIZE and ROUNDUP as <xen/macors.h> was introduced where these macros are located now.
	- update definition of PGTBL_INITIAL_COUNT
	- update the commit message for patch 'xen/riscv: introduce identity mapping'
	- update the comments in head.S
  - update the algo of identity mapping removing 
---
Changes in V3:
 - Update the patch series message.
 - The following patches were merged to staging so droped from the patch series:
   * xen/riscv: add .sbss section to .bss
   * xen/riscv: introduce reset_stack() function
   * xen/riscv: move extern of cpu0_boot_stack to header
   * xen/riscv: add SPDX tags
 - move save/restore of a0/a1 registers from patch 4 to patch 2 ( numbers are
   from the previous patch series version )
 - add SPDX tag in config.h
 - update definition of PGTBL_INITIAL_COUNT taking into account identity mapping.
 - refactor remove_identity_mapping() function.
 - add explanatory comments in xen.lds.S and mm.c.
---
Changes in V2:
 - update the patch series message.
 - drop patches from the previous version of the patch series:
   * xen/riscv: add __ASSEMBLY__ guards". ( merged )
   * xen/riscv: make sure that identity mapping isn't bigger then page size
     ( entire Xen is 1:1 mapped so there is no need for the checks from the patch )
 - add .sbss.* and put it befor .bss* .
 - move out reset_stack() to .text section.
 - add '__ro_after_init' for phys_offset variable.
 - add '__init' for calc_phys_offset().
 - declaring variable phys_off as non static as it will be used in head.S.
 - update definition of PGTBL_INITIAL_COUNT and the comment above.
 - code style fixes.
 - remove id_addrs array becase entire Xen is mapped.
 - reverse condition for cycle inside remove_identity_mapping().
 - fix page table walk in remove_identity_mapping().
 - save hart_id and dtb_addr before call MMU related C functions
 - use phys_offset variable instead of doing calcultations to get phys offset
   in head.S file. ( it can be easily done as entire Xen is 1:1 mapped now )
 - declare enable_muu() as __init.
 - Update SPDX tags.
 - Add Review-By/Suggested-By for some patches.
 - code style fixes.

Oleksii Kurochko (2):
  xen/riscv: introduce function for physical offset calculation
  xen/riscv: introduce identity mapping

 xen/arch/riscv/include/asm/acpi.h   |   6 ++
 xen/arch/riscv/include/asm/config.h |   2 +
 xen/arch/riscv/include/asm/mm.h     |   7 +-
 xen/arch/riscv/mm.c                 | 109 +++++++++++++++++-----------
 xen/arch/riscv/riscv64/head.S       |  44 +++++++++++
 xen/arch/riscv/setup.c              |  14 +---
 xen/arch/riscv/xen.lds.S            |  11 +++
 7 files changed, 136 insertions(+), 57 deletions(-)
 create mode 100644 xen/arch/riscv/include/asm/acpi.h

-- 
2.41.0
Re: [PATCH v7 0/2] xen/riscv: introduce identity mapping
Posted by Jan Beulich 6 months, 1 week ago
On 08.08.2023 17:14, Oleksii Kurochko wrote:
> The patch series introduces things necessary to implement identity mapping:
>   1. Make identity mapping for the entire Xen.
>   2. Enable MMU.
>   3. Jump to the virtual address world
>   4. Remove identity mapping.
> 
> Also current patch series introduces the calculation of physical offset before
> MMU is enabled as access to physical offset will be calculated wrong after
> MMU will be enabled because access to phys_off variable is PC-relative and
> in the case when linker address != load address, it will cause MMU fault.
> 
> The reason for this patch series can be found here:
> https://lore.kernel.org/xen-devel/4e336121-fc0c-b007-bf7b-430352563d55@citrix.com/
> 
> ---
> Changes in V7:
>  - use srli instruction to be consistent with slli instruction in turn_on_mmu()
> ---
> Changes in V6:
>   - Update calc_phys_offset() after rebase.
>   - Refactor turn_on_mmu() and a way how an argument of turn_on_mmu() is
>     calculated.
> ---
> Changes in V5:
> 	- update the algo of identity mapping removing.
> 	- introduce IDENT_AREA_SIZE.
> 	- introduce turn_on_mmu() function to enable and switch from 1:1 mapping.
> 	- fix typo in PGTBL_INITIAL_COUNT define.
> 	- update the comment above PGTBL_INITIAL_COUNT.
> 	- update prototype of calc_phys_offset(). now it returns phys_offset.
> 	- declare phys_offset as static.
> 	- save returned value of calc_phys_offset to register s2.
> ---
> Changes in V4:
>   - drop patch 	[PATCH v3 1/3] xen/riscv: add SPDX tag to config.h as it was
>     merged to staging
>   - remove definition of ARRAY_SIZE and ROUNDUP as <xen/macors.h> was introduced where these macros are located now.
> 	- update definition of PGTBL_INITIAL_COUNT
> 	- update the commit message for patch 'xen/riscv: introduce identity mapping'
> 	- update the comments in head.S
>   - update the algo of identity mapping removing 
> ---
> Changes in V3:
>  - Update the patch series message.
>  - The following patches were merged to staging so droped from the patch series:
>    * xen/riscv: add .sbss section to .bss
>    * xen/riscv: introduce reset_stack() function
>    * xen/riscv: move extern of cpu0_boot_stack to header
>    * xen/riscv: add SPDX tags
>  - move save/restore of a0/a1 registers from patch 4 to patch 2 ( numbers are
>    from the previous patch series version )
>  - add SPDX tag in config.h
>  - update definition of PGTBL_INITIAL_COUNT taking into account identity mapping.
>  - refactor remove_identity_mapping() function.
>  - add explanatory comments in xen.lds.S and mm.c.
> ---
> Changes in V2:
>  - update the patch series message.
>  - drop patches from the previous version of the patch series:
>    * xen/riscv: add __ASSEMBLY__ guards". ( merged )
>    * xen/riscv: make sure that identity mapping isn't bigger then page size
>      ( entire Xen is 1:1 mapped so there is no need for the checks from the patch )
>  - add .sbss.* and put it befor .bss* .
>  - move out reset_stack() to .text section.
>  - add '__ro_after_init' for phys_offset variable.
>  - add '__init' for calc_phys_offset().
>  - declaring variable phys_off as non static as it will be used in head.S.
>  - update definition of PGTBL_INITIAL_COUNT and the comment above.
>  - code style fixes.
>  - remove id_addrs array becase entire Xen is mapped.
>  - reverse condition for cycle inside remove_identity_mapping().
>  - fix page table walk in remove_identity_mapping().
>  - save hart_id and dtb_addr before call MMU related C functions
>  - use phys_offset variable instead of doing calcultations to get phys offset
>    in head.S file. ( it can be easily done as entire Xen is 1:1 mapped now )
>  - declare enable_muu() as __init.
>  - Update SPDX tags.
>  - Add Review-By/Suggested-By for some patches.
>  - code style fixes.
> 
> Oleksii Kurochko (2):
>   xen/riscv: introduce function for physical offset calculation
>   xen/riscv: introduce identity mapping

Acked-by: Jan Beulich <jbeulich@suse.com>
Re: [PATCH v7 0/2] xen/riscv: introduce identity mapping
Posted by Oleksii 6 months, 1 week ago
On Thu, 2023-10-19 at 12:32 +0200, Jan Beulich wrote:
> On 08.08.2023 17:14, Oleksii Kurochko wrote:
> > The patch series introduces things necessary to implement identity
> > mapping:
> >   1. Make identity mapping for the entire Xen.
> >   2. Enable MMU.
> >   3. Jump to the virtual address world
> >   4. Remove identity mapping.
> > 
> > Also current patch series introduces the calculation of physical
> > offset before
> > MMU is enabled as access to physical offset will be calculated
> > wrong after
> > MMU will be enabled because access to phys_off variable is PC-
> > relative and
> > in the case when linker address != load address, it will cause MMU
> > fault.
> > 
> > The reason for this patch series can be found here:
> > https://lore.kernel.org/xen-devel/4e336121-fc0c-b007-bf7b-430352563d55@citrix.com/
> > 
> > ---
> > Changes in V7:
> >  - use srli instruction to be consistent with slli instruction in
> > turn_on_mmu()
> > ---
> > Changes in V6:
> >   - Update calc_phys_offset() after rebase.
> >   - Refactor turn_on_mmu() and a way how an argument of
> > turn_on_mmu() is
> >     calculated.
> > ---
> > Changes in V5:
> >         - update the algo of identity mapping removing.
> >         - introduce IDENT_AREA_SIZE.
> >         - introduce turn_on_mmu() function to enable and switch
> > from 1:1 mapping.
> >         - fix typo in PGTBL_INITIAL_COUNT define.
> >         - update the comment above PGTBL_INITIAL_COUNT.
> >         - update prototype of calc_phys_offset(). now it returns
> > phys_offset.
> >         - declare phys_offset as static.
> >         - save returned value of calc_phys_offset to register s2.
> > ---
> > Changes in V4:
> >   - drop patch  [PATCH v3 1/3] xen/riscv: add SPDX tag to config.h
> > as it was
> >     merged to staging
> >   - remove definition of ARRAY_SIZE and ROUNDUP as <xen/macors.h>
> > was introduced where these macros are located now.
> >         - update definition of PGTBL_INITIAL_COUNT
> >         - update the commit message for patch 'xen/riscv: introduce
> > identity mapping'
> >         - update the comments in head.S
> >   - update the algo of identity mapping removing 
> > ---
> > Changes in V3:
> >  - Update the patch series message.
> >  - The following patches were merged to staging so droped from the
> > patch series:
> >    * xen/riscv: add .sbss section to .bss
> >    * xen/riscv: introduce reset_stack() function
> >    * xen/riscv: move extern of cpu0_boot_stack to header
> >    * xen/riscv: add SPDX tags
> >  - move save/restore of a0/a1 registers from patch 4 to patch 2 (
> > numbers are
> >    from the previous patch series version )
> >  - add SPDX tag in config.h
> >  - update definition of PGTBL_INITIAL_COUNT taking into account
> > identity mapping.
> >  - refactor remove_identity_mapping() function.
> >  - add explanatory comments in xen.lds.S and mm.c.
> > ---
> > Changes in V2:
> >  - update the patch series message.
> >  - drop patches from the previous version of the patch series:
> >    * xen/riscv: add __ASSEMBLY__ guards". ( merged )
> >    * xen/riscv: make sure that identity mapping isn't bigger then
> > page size
> >      ( entire Xen is 1:1 mapped so there is no need for the checks
> > from the patch )
> >  - add .sbss.* and put it befor .bss* .
> >  - move out reset_stack() to .text section.
> >  - add '__ro_after_init' for phys_offset variable.
> >  - add '__init' for calc_phys_offset().
> >  - declaring variable phys_off as non static as it will be used in
> > head.S.
> >  - update definition of PGTBL_INITIAL_COUNT and the comment above.
> >  - code style fixes.
> >  - remove id_addrs array becase entire Xen is mapped.
> >  - reverse condition for cycle inside remove_identity_mapping().
> >  - fix page table walk in remove_identity_mapping().
> >  - save hart_id and dtb_addr before call MMU related C functions
> >  - use phys_offset variable instead of doing calcultations to get
> > phys offset
> >    in head.S file. ( it can be easily done as entire Xen is 1:1
> > mapped now )
> >  - declare enable_muu() as __init.
> >  - Update SPDX tags.
> >  - Add Review-By/Suggested-By for some patches.
> >  - code style fixes.
> > 
> > Oleksii Kurochko (2):
> >   xen/riscv: introduce function for physical offset calculation
> >   xen/riscv: introduce identity mapping
> 
> Acked-by: Jan Beulich <jbeulich@suse.com>
Thanks for Ack.

Should be the patch series re-send with Ack after the end of code
freeze?

~ Oleksii
Re: [PATCH v7 0/2] xen/riscv: introduce identity mapping
Posted by Jan Beulich 6 months, 1 week ago
On 20.10.2023 15:52, Oleksii wrote:
> On Thu, 2023-10-19 at 12:32 +0200, Jan Beulich wrote:
>> On 08.08.2023 17:14, Oleksii Kurochko wrote:
>>> Oleksii Kurochko (2):
>>>   xen/riscv: introduce function for physical offset calculation
>>>   xen/riscv: introduce identity mapping
>>
>> Acked-by: Jan Beulich <jbeulich@suse.com>
> Thanks for Ack.
> 
> Should be the patch series re-send with Ack after the end of code
> freeze?

If what was sent still applies, I don't think there's a need.

Jan

Re: [PATCH v7 0/2] xen/riscv: introduce identity mapping
Posted by Oleksii 6 months, 1 week ago
On Fri, 2023-10-20 at 15:53 +0200, Jan Beulich wrote:
> On 20.10.2023 15:52, Oleksii wrote:
> > On Thu, 2023-10-19 at 12:32 +0200, Jan Beulich wrote:
> > > On 08.08.2023 17:14, Oleksii Kurochko wrote:
> > > > Oleksii Kurochko (2):
> > > >   xen/riscv: introduce function for physical offset calculation
> > > >   xen/riscv: introduce identity mapping
> > > 
> > > Acked-by: Jan Beulich <jbeulich@suse.com>
> > Thanks for Ack.
> > 
> > Should be the patch series re-send with Ack after the end of code
> > freeze?
> 
> If what was sent still applies, I don't think there's a need.
I pulled staging and rebased the identity mapping patch series. All is
still applied and worked.

~ Oleksii
Re: [PATCH v7 0/2] xen/riscv: introduce identity mapping
Posted by Julien Grall 6 months, 1 week ago
Hi,

On 08/08/2023 16:14, Oleksii Kurochko wrote:
> The patch series introduces things necessary to implement identity mapping:
>    1. Make identity mapping for the entire Xen.
>    2. Enable MMU.
>    3. Jump to the virtual address world
>    4. Remove identity mapping.
> 
> Also current patch series introduces the calculation of physical offset before
> MMU is enabled as access to physical offset will be calculated wrong after
> MMU will be enabled because access to phys_off variable is PC-relative and
> in the case when linker address != load address, it will cause MMU fault.
> 
> The reason for this patch series can be found here:
> https://lore.kernel.org/xen-devel/4e336121-fc0c-b007-bf7b-430352563d55@citrix.com/

During the last community call it was pointed out that this is missing a 
formal ack. Now that we have no RISC-V maintainers, this would fall to 
the REST.

@Jan, you reviewed the previous version of the series. Would you be able 
to provide a formal ack?

Cheers,

-- 
Julien Grall
Re: [PATCH v7 0/2] xen/riscv: introduce identity mapping
Posted by Oleksii 7 months, 3 weeks ago
Hello Bobby and Alistair,

Could you kindly take a moment to examine this series of patches?
Your input would be highly valued.

Thanks in advance.

~ Oleksii

On Tue, 2023-08-08 at 18:14 +0300, Oleksii Kurochko wrote:
> The patch series introduces things necessary to implement identity
> mapping:
>   1. Make identity mapping for the entire Xen.
>   2. Enable MMU.
>   3. Jump to the virtual address world
>   4. Remove identity mapping.
> 
> Also current patch series introduces the calculation of physical
> offset before
> MMU is enabled as access to physical offset will be calculated wrong
> after
> MMU will be enabled because access to phys_off variable is PC-
> relative and
> in the case when linker address != load address, it will cause MMU
> fault.
> 
> The reason for this patch series can be found here:
> https://lore.kernel.org/xen-devel/4e336121-fc0c-b007-bf7b-430352563d55@citrix.com/
> 
> ---
> Changes in V7:
>  - use srli instruction to be consistent with slli instruction in
> turn_on_mmu()
> ---
> Changes in V6:
>   - Update calc_phys_offset() after rebase.
>   - Refactor turn_on_mmu() and a way how an argument of turn_on_mmu()
> is
>     calculated.
> ---
> Changes in V5:
>         - update the algo of identity mapping removing.
>         - introduce IDENT_AREA_SIZE.
>         - introduce turn_on_mmu() function to enable and switch from
> 1:1 mapping.
>         - fix typo in PGTBL_INITIAL_COUNT define.
>         - update the comment above PGTBL_INITIAL_COUNT.
>         - update prototype of calc_phys_offset(). now it returns
> phys_offset.
>         - declare phys_offset as static.
>         - save returned value of calc_phys_offset to register s2.
> ---
> Changes in V4:
>   - drop patch  [PATCH v3 1/3] xen/riscv: add SPDX tag to config.h as
> it was
>     merged to staging
>   - remove definition of ARRAY_SIZE and ROUNDUP as <xen/macors.h> was
> introduced where these macros are located now.
>         - update definition of PGTBL_INITIAL_COUNT
>         - update the commit message for patch 'xen/riscv: introduce
> identity mapping'
>         - update the comments in head.S
>   - update the algo of identity mapping removing 
> ---
> Changes in V3:
>  - Update the patch series message.
>  - The following patches were merged to staging so droped from the
> patch series:
>    * xen/riscv: add .sbss section to .bss
>    * xen/riscv: introduce reset_stack() function
>    * xen/riscv: move extern of cpu0_boot_stack to header
>    * xen/riscv: add SPDX tags
>  - move save/restore of a0/a1 registers from patch 4 to patch 2 (
> numbers are
>    from the previous patch series version )
>  - add SPDX tag in config.h
>  - update definition of PGTBL_INITIAL_COUNT taking into account
> identity mapping.
>  - refactor remove_identity_mapping() function.
>  - add explanatory comments in xen.lds.S and mm.c.
> ---
> Changes in V2:
>  - update the patch series message.
>  - drop patches from the previous version of the patch series:
>    * xen/riscv: add __ASSEMBLY__ guards". ( merged )
>    * xen/riscv: make sure that identity mapping isn't bigger then
> page size
>      ( entire Xen is 1:1 mapped so there is no need for the checks
> from the patch )
>  - add .sbss.* and put it befor .bss* .
>  - move out reset_stack() to .text section.
>  - add '__ro_after_init' for phys_offset variable.
>  - add '__init' for calc_phys_offset().
>  - declaring variable phys_off as non static as it will be used in
> head.S.
>  - update definition of PGTBL_INITIAL_COUNT and the comment above.
>  - code style fixes.
>  - remove id_addrs array becase entire Xen is mapped.
>  - reverse condition for cycle inside remove_identity_mapping().
>  - fix page table walk in remove_identity_mapping().
>  - save hart_id and dtb_addr before call MMU related C functions
>  - use phys_offset variable instead of doing calcultations to get
> phys offset
>    in head.S file. ( it can be easily done as entire Xen is 1:1
> mapped now )
>  - declare enable_muu() as __init.
>  - Update SPDX tags.
>  - Add Review-By/Suggested-By for some patches.
>  - code style fixes.
> 
> Oleksii Kurochko (2):
>   xen/riscv: introduce function for physical offset calculation
>   xen/riscv: introduce identity mapping
> 
>  xen/arch/riscv/include/asm/acpi.h   |   6 ++
>  xen/arch/riscv/include/asm/config.h |   2 +
>  xen/arch/riscv/include/asm/mm.h     |   7 +-
>  xen/arch/riscv/mm.c                 | 109 +++++++++++++++++---------
> --
>  xen/arch/riscv/riscv64/head.S       |  44 +++++++++++
>  xen/arch/riscv/setup.c              |  14 +---
>  xen/arch/riscv/xen.lds.S            |  11 +++
>  7 files changed, 136 insertions(+), 57 deletions(-)
>  create mode 100644 xen/arch/riscv/include/asm/acpi.h
>