]> xenbits.xensource.com Git - xen.git/commit
xen/riscv: update mfn calculation in pt_mapping_level()
authorOleksii Kurochko <oleksii.kurochko@gmail.com>
Wed, 26 Feb 2025 11:24:26 +0000 (12:24 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 26 Feb 2025 11:24:26 +0000 (12:24 +0100)
commit96a86ebcf5add89f24ece8d8c9657a72f2c1ff4f
tree17f85530bac5d9eaa535e5a7ee1b3e6b17e5e725
parente365749ebad539424afa4a7de06961b8cc87335c
xen/riscv: update mfn calculation in pt_mapping_level()

When pt_update() is called with arguments (..., INVALID_MFN, ..., 0 or 1),
it indicates that a mapping is being destroyed/modifyed.

In the case when modifying or destroying a mapping, it is necessary to
search until a leaf node is found, instead of searching for a page table
entry based on the precalculated `level` and `order`(look at pt_update()).
This is because when `mfn` == INVALID_MFN, the `mask` (in pt_mapping_level())
will take into account only `vfn`, which could accidentally return an
incorrect level, leading to the discovery of an incorrect page table entry.

For example, if `vfn` is page table level 1 aligned, but it was mapped as
page table level 0, then pt_mapping_level() will return `level` = 1, since
only `vfn` (which is page table level 1 aligned) is taken into account when
`mfn` == INVALID_MFN (look at pt_mapping_level()).

Have unmap_table() check for NULL, such that individual callers don't need
to.

Fixes: c2f1ded524 ("xen/riscv: page table handling")
Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
Reviewed-by: Jan Beulich<jbeulich@suse.com>
xen/arch/riscv/pt.c