[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 1/6] target/riscv: Fix mcycle/minstret increment behavior
|
From: |
Michael Tokarev |
|
Subject: |
[PULL 1/6] target/riscv: Fix mcycle/minstret increment behavior |
|
Date: |
Fri, 5 Jan 2024 22:30:33 +0300 |
From: Xu Lu <luxu.kernel@bytedance.com>
The mcycle/minstret counter's stop flag is mistakenly updated on a copy
on stack. Thus the counter increments even when the CY/IR bit in the
mcountinhibit register is set. This commit corrects its behavior.
Fixes: 3780e33732f88 (target/riscv: Support mcycle/minstret write operation)
Signed-off-by: Xu Lu <luxu.kernel@bytedance.com>
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
---
target/riscv/csr.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index fde7ce1a53..c50a33397c 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -907,11 +907,11 @@ static int write_mhpmcounterh(CPURISCVState *env, int
csrno, target_ulong val)
static RISCVException riscv_pmu_read_ctr(CPURISCVState *env, target_ulong *val,
bool upper_half, uint32_t ctr_idx)
{
- PMUCTRState counter = env->pmu_ctrs[ctr_idx];
- target_ulong ctr_prev = upper_half ? counter.mhpmcounterh_prev :
- counter.mhpmcounter_prev;
- target_ulong ctr_val = upper_half ? counter.mhpmcounterh_val :
- counter.mhpmcounter_val;
+ PMUCTRState *counter = &env->pmu_ctrs[ctr_idx];
+ target_ulong ctr_prev = upper_half ? counter->mhpmcounterh_prev :
+ counter->mhpmcounter_prev;
+ target_ulong ctr_val = upper_half ? counter->mhpmcounterh_val :
+ counter->mhpmcounter_val;
if (get_field(env->mcountinhibit, BIT(ctr_idx))) {
/*
@@ -919,12 +919,12 @@ static RISCVException riscv_pmu_read_ctr(CPURISCVState
*env, target_ulong *val,
* stop the icount counting. Just return the counter value written by
* the supervisor to indicate that counter was not incremented.
*/
- if (!counter.started) {
+ if (!counter->started) {
*val = ctr_val;
return RISCV_EXCP_NONE;
} else {
/* Mark that the counter has been stopped */
- counter.started = false;
+ counter->started = false;
}
}
--
2.39.2
- [PULL 0/6] Trivial patches for 2024-01-05, Michael Tokarev, 2024/01/05
- [PULL 1/6] target/riscv: Fix mcycle/minstret increment behavior,
Michael Tokarev <=
- [PULL 2/6] chardev/char.c: fix "abstract device type" error message, Michael Tokarev, 2024/01/05
- [PULL 3/6] audio/audio.c: remove trailing newline in error_setg, Michael Tokarev, 2024/01/05
- [PULL 4/6] hw/net: cadence_gem: Fix MDIO_OP_xxx values, Michael Tokarev, 2024/01/05
- [PULL 5/6] edu: fix DMA range upper bound check, Michael Tokarev, 2024/01/05
- [PULL 6/6] docs: use "buses" rather than "busses", Michael Tokarev, 2024/01/05
- Re: [PULL 0/6] Trivial patches for 2024-01-05, Peter Maydell, 2024/01/08