* [PATCH v2 1/2] target/riscv: Remove redundant check in pmp_is_locked
@ 2023-07-04 2:33 Ruibo Lu
2023-07-04 2:33 ` [PATCH v2 2/2] target/riscv: Optimize ambiguous local variable in pmp_hart_has_privs Ruibo Lu
2023-07-07 19:31 ` [PATCH v2 1/2] target/riscv: Remove redundant check in pmp_is_locked Daniel Henrique Barboza
0 siblings, 2 replies; 3+ messages in thread
From: Ruibo Lu @ 2023-07-04 2:33 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-riscv, luruibo2000, alistair.francis, liweiwei
the check of top PMP is redundant and will not influence the return
value, so consider remove it
Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Ruibo Lu <reaperlu@hust.edu.cn>
---
target/riscv/pmp.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
index 9d8db493e6..1a9279ba88 100644
--- a/target/riscv/pmp.c
+++ b/target/riscv/pmp.c
@@ -49,11 +49,6 @@ static inline int pmp_is_locked(CPURISCVState *env, uint32_t pmp_index)
return 1;
}
- /* Top PMP has no 'next' to check */
- if ((pmp_index + 1u) >= MAX_RISCV_PMPS) {
- return 0;
- }
-
return 0;
}
--
2.41.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v2 2/2] target/riscv: Optimize ambiguous local variable in pmp_hart_has_privs
2023-07-04 2:33 [PATCH v2 1/2] target/riscv: Remove redundant check in pmp_is_locked Ruibo Lu
@ 2023-07-04 2:33 ` Ruibo Lu
2023-07-07 19:31 ` [PATCH v2 1/2] target/riscv: Remove redundant check in pmp_is_locked Daniel Henrique Barboza
1 sibling, 0 replies; 3+ messages in thread
From: Ruibo Lu @ 2023-07-04 2:33 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, luruibo2000, alistair.francis, liweiwei,
Philippe Mathieu-Daudé
These two values represents whether start/end address is in pmp_range.
However, the type and name of them is ambiguous. This commit change the
name and type of them to improve code readability and accuracy.
Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Ruibo Lu <reaperlu@hust.edu.cn>
---
target/riscv/pmp.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
index 1a9279ba88..ea3d29217a 100644
--- a/target/riscv/pmp.c
+++ b/target/riscv/pmp.c
@@ -203,16 +203,16 @@ void pmp_update_rule_nums(CPURISCVState *env)
}
}
-static int pmp_is_in_range(CPURISCVState *env, int pmp_index,
- target_ulong addr)
+static bool pmp_is_in_range(CPURISCVState *env, int pmp_index,
+ target_ulong addr)
{
- int result = 0;
+ bool result = false;
if ((addr >= env->pmp_state.addr[pmp_index].sa) &&
(addr <= env->pmp_state.addr[pmp_index].ea)) {
- result = 1;
+ result = true;
} else {
- result = 0;
+ result = false;
}
return result;
@@ -287,8 +287,8 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
{
int i = 0;
int pmp_size = 0;
- target_ulong s = 0;
- target_ulong e = 0;
+ bool sa_in = false;
+ bool ea_in = false;
/* Short cut if no rules */
if (0 == pmp_get_num_rules(env)) {
@@ -314,11 +314,11 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
* from low to high
*/
for (i = 0; i < MAX_RISCV_PMPS; i++) {
- s = pmp_is_in_range(env, i, addr);
- e = pmp_is_in_range(env, i, addr + pmp_size - 1);
+ sa_in = pmp_is_in_range(env, i, addr);
+ ea_in = pmp_is_in_range(env, i, addr + pmp_size - 1);
/* partially inside */
- if ((s + e) == 1) {
+ if (sa_in ^ ea_in) {
qemu_log_mask(LOG_GUEST_ERROR,
"pmp violation - access is partially inside\n");
*allowed_privs = 0;
@@ -339,7 +339,7 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
(env->pmp_state.pmp[i].cfg_reg & PMP_WRITE) |
((env->pmp_state.pmp[i].cfg_reg & PMP_EXEC) >> 2);
- if (((s + e) == 2) && (PMP_AMATCH_OFF != a_field)) {
+ if (sa_in && ea_in && (PMP_AMATCH_OFF != a_field)) {
/*
* If the PMP entry is not off and the address is in range,
* do the priv check
--
2.41.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 1/2] target/riscv: Remove redundant check in pmp_is_locked
2023-07-04 2:33 [PATCH v2 1/2] target/riscv: Remove redundant check in pmp_is_locked Ruibo Lu
2023-07-04 2:33 ` [PATCH v2 2/2] target/riscv: Optimize ambiguous local variable in pmp_hart_has_privs Ruibo Lu
@ 2023-07-07 19:31 ` Daniel Henrique Barboza
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Henrique Barboza @ 2023-07-07 19:31 UTC (permalink / raw)
To: Ruibo Lu, qemu-devel; +Cc: qemu-riscv, luruibo2000, alistair.francis, liweiwei
On 7/3/23 23:33, Ruibo Lu wrote:
> the check of top PMP is redundant and will not influence the return
> value, so consider remove it
>
> Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn>
> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
> Signed-off-by: Ruibo Lu <reaperlu@hust.edu.cn>
> ---
I believe we might want to add:
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1733
> target/riscv/pmp.c | 5 -----
> 1 file changed, 5 deletions(-)
>
> diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
> index 9d8db493e6..1a9279ba88 100644
> --- a/target/riscv/pmp.c
> +++ b/target/riscv/pmp.c
> @@ -49,11 +49,6 @@ static inline int pmp_is_locked(CPURISCVState *env, uint32_t pmp_index)
> return 1;
> }
>
> - /* Top PMP has no 'next' to check */
> - if ((pmp_index + 1u) >= MAX_RISCV_PMPS) {
> - return 0;
> - }
> -
> return 0;
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-07 19:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-04 2:33 [PATCH v2 1/2] target/riscv: Remove redundant check in pmp_is_locked Ruibo Lu
2023-07-04 2:33 ` [PATCH v2 2/2] target/riscv: Optimize ambiguous local variable in pmp_hart_has_privs Ruibo Lu
2023-07-07 19:31 ` [PATCH v2 1/2] target/riscv: Remove redundant check in pmp_is_locked Daniel Henrique Barboza
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).