Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RISC-V] Allow enabling CFG_TEE_CORE_DEBUG #7028

Merged
merged 5 commits into from
Sep 16, 2024

Conversation

lyctw
Copy link
Contributor

@lyctw lyctw commented Sep 5, 2024

This series enables CFG_TEE_CORE_DEBUG, a crucial feature for early error detection on RISC-V platforms, such as assertions.

@lyctw lyctw force-pushed the CFG_TEE_CORE_DEBUG_v2 branch 3 times, most recently from f10127c to f27f728 Compare September 9, 2024 06:06
Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For commit "core: riscv: core_mmu_arch: fix arch_va2pa_helper() on superpage translation": commit message header line is a bit too long: could you shorten, e.g.:
"core: riscv: mm: fix arch_va2pa_helper() on superpage translation"

@@ -466,6 +466,7 @@ bool arch_va2pa_helper(void *va, paddr_t *pa)
int level = 0;
unsigned int idx = 0;
struct mmu_partition *prtn = core_mmu_get_prtn();
vaddr_t offset_mask = 0; /* page offset mask */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicking: I don't think the inline comment is really useful.

core/arch/riscv/mm/core_mmu_arch.c Outdated Show resolved Hide resolved
* Moreover, if arch_va2pa_helper() returns true, it implies
* the va2pa mapping is matched, no need to check again.
*/
#if defined(CFG_TEE_CORE_DEBUG) && !defined(RV64)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only for RV64, not for RV32? it seems the implementation of the same for these 2 configurations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, fixed it by using gcc pre-defined macro !defined(__riscv)

Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acked-by: Etienne Carriere <[email protected]> for the series.

@etienne-lms
Copy link
Contributor

CI Code style error report seems due to a false positive.

Any level of PTE may be a leaf PTE in RISC-V page table, if the
page is not 4KiB, the page offset should be extended to VPN fields
of virtual address.

e.g. on Sv39, if there is a leaf PTE on level-1 (2MiB megapage),
it maps to physical page with (va[20:12] | va[11:0]) as the page
offset.

 Sv39 Virtual address:
                           |<--- superpage offset --->|
     38_______30_29______21|20______12_11____________0|
     |  VPN[2]  |  VPN[1]  |  VPN[0]  |  page offset  |
      ‾‾‾‾9‾‾‾‾‾‾‾‾‾‾9‾‾‾‾‾|‾‾‾‾9‾‾‾‾‾‾‾‾‾‾‾‾12‾‾‾‾‾‾‾|
                           |                          |
 Physical address:         |                          |
                           |                          |
 55___________30_29______21|20______12_11____________0|
 |     PPN[2]   |  PPN[1]  |  PPN[0]  |  page offset  |
  ‾‾‾‾‾‾26‾‾‾‾‾‾‾‾‾‾‾9‾‾‾‾‾'‾‾‾‾9‾‾‾‾‾‾‾‾‾‾‾‾12‾‾‾‾‾‾‾'

Signed-off-by: Yu Chien Peter Lin <[email protected]>
Reviewed-by: Alvin Chang <[email protected]>
Tested-by: Alvin Chang <[email protected]>
Acked-by: Etienne Carriere <[email protected]>
Fix the compile error in the bit_test() macro, which mistakenly
uses the address of g_asid as the parameter.

Signed-off-by: Yu Chien Peter Lin <[email protected]>
Reviewed-by: Alvin Chang <[email protected]>
Tested-by: Alvin Chang <[email protected]>
Acked-by: Etienne Carriere <[email protected]>
The function hasn't been implemented for RISC-V, so move the
core_mmu_user_va_range_is_defined() definition to generic
core_mmu.h and function implementations to arch-specific files.

Also, update the assertions where checks if user va range is defined.

Signed-off-by: Yu Chien Peter Lin <[email protected]>
Reviewed-by: Alvin Chang <[email protected]>
Tested-by: Alvin Chang <[email protected]>
Acked-by: Etienne Carriere <[email protected]>
The arch_va2pa_helper() in the RISC-V implements a software page table
walker. It requires phys_to_virt() to convert the physical page on the
PTE to the virtual address of the next level page table. The process
can lead to a stack overflow caused by indirect recursion as below:

 phys_to_virt() <--------------------------------.
   -> check_va_matches_pa()                      |
      -> virt_to_phys()                          |
         -> arch_va2pa_helper()                  |
            -> core_mmu_xlat_table_entry_pa2va()-'

As arch_va2pa_helper() can return true if va matches pa, we
don't use and check_va_matches_pa() when CFG_TEE_CORE_DEBUG
is enabled.

Signed-off-by: Yu Chien Peter Lin <[email protected]>
Reviewed-by: Alvin Chang <[email protected]>
Tested-by: Alvin Chang <[email protected]>
Acked-by: Etienne Carriere <[email protected]>
Allow enabling CFG_TEE_CORE_DEBUG to make assertions useful.

Signed-off-by: Yu Chien Peter Lin <[email protected]>
Reviewed-by: Alvin Chang <[email protected]>
Tested-by: Alvin Chang <[email protected]>
Acked-by: Etienne Carriere <[email protected]>
@lyctw
Copy link
Contributor Author

lyctw commented Sep 16, 2024

Acked-by: Etienne Carriere <[email protected]> for the series.

Tag applied, thanks!

@jforissier jforissier merged commit 16b9b1e into OP-TEE:master Sep 16, 2024
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants