[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stable-8.1.5 05/11] target/riscv: Fix mcycle/minstret increment behavio
From: |
Michael Tokarev |
Subject: |
[Stable-8.1.5 05/11] target/riscv: Fix mcycle/minstret increment behavior |
Date: |
Thu, 18 Jan 2024 15:50:43 +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>
(cherry picked from commit 5cb0e7abe1635cb82e0033260dac2b910d142f8c)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/target/riscv/csr.c b/target/riscv/csr.c
index ea7585329e..cbb73863d6 100644
--- a/target/riscv/csr.c
+++ b/target/riscv/csr.c
@@ -898,11 +898,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))) {
/*
@@ -910,12 +910,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
- [Stable-8.1.5 00/11] Patch Round-up for stable 8.1.5, freeze on 2024-01-27, Michael Tokarev, 2024/01/18
- [Stable-8.1.5 01/11] block: Fix crash when loading snapshot on inactive node, Michael Tokarev, 2024/01/18
- [Stable-8.1.5 02/11] vl: Improve error message for conflicting -incoming and -loadvm, Michael Tokarev, 2024/01/18
- [Stable-8.1.5 03/11] iotests: Basic tests for internal snapshots, Michael Tokarev, 2024/01/18
- [Stable-8.1.5 04/11] hw/net/can/sja1000: fix bug for single acceptance filter and standard frame, Michael Tokarev, 2024/01/18
- [Stable-8.1.5 05/11] target/riscv: Fix mcycle/minstret increment behavior,
Michael Tokarev <=
- [Stable-8.1.5 06/11] chardev/char.c: fix "abstract device type" error message, Michael Tokarev, 2024/01/18
- [Stable-8.1.5 07/11] hw/intc/arm_gicv3_cpuif: handle LPIs in in the list registers, Michael Tokarev, 2024/01/18
- [Stable-8.1.5 08/11] util: fix build with musl libc on ppc64le, Michael Tokarev, 2024/01/18
- [Stable-8.1.5 09/11] tests/qtest/virtio-ccw: Fix device presence checking, Michael Tokarev, 2024/01/18
- [Stable-8.1.5 10/11] target/s390x: Fix LAE setting a wrong access register, Michael Tokarev, 2024/01/18
- [Stable-8.1.5 11/11] .gitlab-ci.d/buildtest.yml: Work around htags bug when environment is large, Michael Tokarev, 2024/01/18