target/riscv: Check PMP before updating PTE
PATCH 1/1 target/riscv: Check PMP before updating PTE
According to the RISC-V spec, the PTE update is a supervisor write operations, and it should also follow the CPU PMP configuration like the PTE read.
--- target/riscv/cpu_helper.c | 8 ++++++++ 1 file changed, 8 insertions(+)
target/riscv/cpu_helper.c +8 -0
@@ -1604,6 +1604,14 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,return TRANSLATE_FAIL ; } +int pmp_prot; +int pmp_ret =get_physical_address_pmp (env, &pmp_prot, pte_addr, + sxlen_bytes, +MMU_DATA_STORE ,PRV_S ); +if (pmp_ret !=TRANSLATE_SUCCESS ) { +return TRANSLATE_PMP_FAIL ; + } +/* * - if accessed or dirty bits need updating, and the PTE is * in RAM, then we do so atomically with a compare and swap.
--
2.54.0
Quoted 6 lines · Inochi Amaoto
According to the RISC-V spec, the PTE update is a supervisor write operations, and it should also follow the CPU PMP configuration like the PTE read.
Signed-off-by Inochi Amaoto <[email protected]>
Logic looks good
Quoted 9 lines
--- target/riscv/cpu_helper.c | 8 ++++++++ 1 file changed, 8 insertions(+)target/riscv/cpu_helper.c +0
-0
target/riscv/cpu_helper.c static int get_physical_address(CPURISCVState *env, hwaddr *physical, · line 1610
Quoted 7 lines
target/riscv/cpu_helper.c +4
-0@@ -1604,6 +1604,14 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,return TRANSLATE_FAIL ; } +int pmp_prot; +int pmp_ret =get_physical_address_pmp (env, &pmp_prot, pte_addr, + sxlen_bytes, +MMU_DATA_STORE ,PRV_S );
Please don't mix code statements and declarations inside a block:
https://qemu-project.gitlab.io/qemu/devel/style.html#declarations
./scripts/checkpatch.pl should catch these type of errors
Alistair
Quoted 11 lines
target/riscv/cpu_helper.c +4
-1+if (pmp_ret !=TRANSLATE_SUCCESS ) { +return TRANSLATE_PMP_FAIL ; + } +/* * - if accessed or dirty bits need updating, and the PTE is * in RAM, then we do so atomically with a compare and swap. -- 2.54.0
Quoted 30 lines · Alistair Francis
Quoted 6 lines · Inochi Amaoto
According to the RISC-V spec, the PTE update is a supervisor write operations, and it should also follow the CPU PMP configuration like the PTE read.
Signed-off-by Inochi Amaoto <[email protected]>Logic looks good
Quoted 9 lines
--- target/riscv/cpu_helper.c | 8 ++++++++ 1 file changed, 8 insertions(+)target/riscv/cpu_helper.c +0
-0target/riscv/cpu_helper.c static int get_physical_address(CPURISCVState *env, hwaddr *physical, · line 1610
Quoted 7 lines
target/riscv/cpu_helper.c +4
-0@@ -1604,6 +1604,14 @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical,return TRANSLATE_FAIL ; } +int pmp_prot; +int pmp_ret =get_physical_address_pmp (env, &pmp_prot, pte_addr, + sxlen_bytes, +MMU_DATA_STORE ,PRV_S );Please don't mix code statements and declarations inside a block:
https://qemu-project.gitlab.io/qemu/devel/style.html#declarations
Quoted 4 lines
./scripts/checkpatch.plshould catch these type of errorsAlistair
Thanks, but something weird, the checkpatch does not catch this. Maybe the script need a update?
This is the output from my branch:
$ ./scripts/checkpatch.pl --strict ./0001-target-riscv-Check-PMP-before-updating-PTE.patch total: 0 errors, 0 warnings, 14 lines checked
./0001-target-riscv-Check-PMP-before-updating-PTE.patch has no obvious style problems and is ready for submission.
Regards,
Inochi
Quoted 12 lines
Quoted 11 lines
target/riscv/cpu_helper.c +4
-1+if (pmp_ret !=TRANSLATE_SUCCESS ) { +return TRANSLATE_PMP_FAIL ; + } +/* * - if accessed or dirty bits need updating, and the PTE is * in RAM, then we do so atomically with a compare and swap. -- 2.54.0