Skip to content

Commit d5dc915

Browse files
gagachangjforissier
authored andcommitted
core: riscv: Fix PTE creation when freeing PTE
The core_mmu_pte_create() is also called when MM core frees the pages, which means the PTE should be zero. Current implementation always sets valid bit (V), which is not proper way when clearing PTE. Fix it by only honoring pte_bits parameter, which may be constructed in mattr_to_pte_bits(). The core_mmu_ptp_create() is used to create non-leaf PTE, which points to the next level of the page table. According to RISC-V privilege Spec, non-leaf PTE only needs V bit. Therefore, we just give the V bit to core_mmu_pte_create() when we want to create non-leaf PTE. Signed-off-by: Alvin Chang <alvinga@andestech.com> Reviewed-by: Yu Chien Peter Lin <peterlin@andestech.com> Reviewed-by: Marouene Boubakri <marouene.boubakri@nxp.com>
1 parent e6a66e3 commit d5dc915

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

core/arch/riscv/mm/core_mmu_arch.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,23 @@ static bool __maybe_unused core_mmu_entry_is_branch(struct mmu_pte *pte)
113113
return !core_mmu_entry_is_leaf(pte);
114114
}
115115

116-
static unsigned long core_mmu_pte_create(unsigned long ppn, uint8_t perm)
116+
static unsigned long core_mmu_pte_create(unsigned long ppn, uint8_t pte_bits)
117117
{
118-
return SHIFT_U64(ppn, PTE_PPN_SHIFT) | PTE_V | perm;
118+
/*
119+
* This function may be called from core_mmu_set_entry(). There is a
120+
* case that MM core wants to clear PTE by calling core_mmu_set_entry()
121+
* with zero physical address and zero memory attributes, which turns
122+
* @ppn and @pte_bits in this function to be both zero. In this case, we
123+
* should create zero PTE without setting its V bit.
124+
*/
125+
126+
return SHIFT_U64(ppn, PTE_PPN_SHIFT) | pte_bits;
119127
}
120128

121129
static unsigned long core_mmu_ptp_create(unsigned long ppn)
122130
{
123-
/* set perms to 0 since core_mmu_pte_create() already adds PTE_V */
124-
return core_mmu_pte_create(ppn, 0);
131+
/* Set V bit to create PTE points to next level of the page table. */
132+
return core_mmu_pte_create(ppn, PTE_V);
125133
}
126134

127135
static unsigned long core_mmu_pte_ppn(struct mmu_pte *pte)

0 commit comments

Comments
 (0)