From: Alistair Francis <alistair23@gmail.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: "open list:RISC-V" <qemu-riscv@nongnu.org>,
Sagar Karandikar <sagark@eecs.berkeley.edu>,
Bastian Koppelmann <kbastian@mail.uni-paderborn.de>,
Palmer Dabbelt <palmer@sifive.com>,
"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>,
KONRAD Frederic <frederic.konrad@adacore.com>,
Alistair Francis <Alistair.Francis@wdc.com>
Subject: Re: [Qemu-devel] [PATCH-for-4.2 2/2] target/riscv/pmp: Convert qemu_log_mask(LOG_TRACE) to trace events
Date: Tue, 23 Jul 2019 11:06:49 -0700 [thread overview]
Message-ID: <CAKmqyKNrJgUBVB93dHvsoDcksj0r9ckwLpmSHMhZFdcdtYx_HQ@mail.gmail.com> (raw)
In-Reply-To: <20190723120816.1361-3-philmd@redhat.com>
On Tue, Jul 23, 2019 at 5:08 AM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> Use the always-compiled trace events, remove the now unused
> RISCV_DEBUG_PMP definition.
>
> Note pmpaddr_csr_read() could previously do out-of-bound accesses
> passing addr_index >= MAX_RISCV_PMPS.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> target/riscv/pmp.c | 31 ++++++++++---------------------
> target/riscv/trace-events | 6 ++++++
> 2 files changed, 16 insertions(+), 21 deletions(-)
>
> diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c
> index d836288cb4..d4f1007109 100644
> --- a/target/riscv/pmp.c
> +++ b/target/riscv/pmp.c
> @@ -27,14 +27,7 @@
> #include "qemu/log.h"
> #include "qapi/error.h"
> #include "cpu.h"
> -
> -#define RISCV_DEBUG_PMP 0
> -#define PMP_DEBUG(fmt, ...) \
> - do { \
> - if (RISCV_DEBUG_PMP) { \
> - qemu_log_mask(LOG_TRACE, "%s: " fmt "\n", __func__, ##__VA_ARGS__);\
> - } \
> - } while (0)
> +#include "trace.h"
>
> static void pmp_write_cfg(CPURISCVState *env, uint32_t addr_index,
> uint8_t val);
> @@ -302,8 +295,7 @@ void pmpcfg_csr_write(CPURISCVState *env, uint32_t reg_index,
> int i;
> uint8_t cfg_val;
>
> - PMP_DEBUG("hart " TARGET_FMT_ld ": reg%d, val: 0x" TARGET_FMT_lx,
> - env->mhartid, reg_index, val);
> + trace_pmpcfg_csr_write(env->mhartid, reg_index, val);
>
> if ((reg_index & 1) && (sizeof(target_ulong) == 8)) {
> qemu_log_mask(LOG_GUEST_ERROR,
> @@ -332,9 +324,7 @@ target_ulong pmpcfg_csr_read(CPURISCVState *env, uint32_t reg_index)
> val = pmp_read_cfg(env, (reg_index * sizeof(target_ulong)) + i);
> cfg_val |= (val << (i * 8));
> }
> -
> - PMP_DEBUG("hart " TARGET_FMT_ld ": reg%d, val: 0x" TARGET_FMT_lx,
> - env->mhartid, reg_index, cfg_val);
> + trace_pmpcfg_csr_read(env->mhartid, reg_index, cfg_val);
>
> return cfg_val;
> }
> @@ -346,9 +336,7 @@ target_ulong pmpcfg_csr_read(CPURISCVState *env, uint32_t reg_index)
> void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index,
> target_ulong val)
> {
> - PMP_DEBUG("hart " TARGET_FMT_ld ": addr%d, val: 0x" TARGET_FMT_lx,
> - env->mhartid, addr_index, val);
> -
> + trace_pmpaddr_csr_write(env->mhartid, addr_index, val);
> if (addr_index < MAX_RISCV_PMPS) {
> if (!pmp_is_locked(env, addr_index)) {
> env->pmp_state.pmp[addr_index].addr_reg = val;
> @@ -369,14 +357,15 @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index,
> */
> target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index)
> {
> - PMP_DEBUG("hart " TARGET_FMT_ld ": addr%d, val: 0x" TARGET_FMT_lx,
> - env->mhartid, addr_index,
> - env->pmp_state.pmp[addr_index].addr_reg);
> + target_ulong val = 0;
> +
> if (addr_index < MAX_RISCV_PMPS) {
> - return env->pmp_state.pmp[addr_index].addr_reg;
> + val = env->pmp_state.pmp[addr_index].addr_reg;
> + trace_pmpaddr_csr_read(env->mhartid, addr_index, val);
> } else {
> qemu_log_mask(LOG_GUEST_ERROR,
> "ignoring pmpaddr read - out of bounds\n");
> - return 0;
> }
> +
> + return val;
> }
> diff --git a/target/riscv/trace-events b/target/riscv/trace-events
> index 48af0373df..4b6c652ae9 100644
> --- a/target/riscv/trace-events
> +++ b/target/riscv/trace-events
> @@ -1,2 +1,8 @@
> # target/riscv/cpu_helper.c
> riscv_trap(uint64_t hartid, bool async, uint64_t cause, uint64_t epc, uint64_t tval, const char *desc) "hart:%"PRId64", async:%d, cause:%"PRId64", epc:0x%"PRIx64", tval:0x%"PRIx64", desc=%s"
> +
> +# pmp.c
> +pmpcfg_csr_read(uint64_t mhartid, uint32_t reg_index, uint64_t val) "hart %" PRIu64 ": read reg%" PRIu32", val: 0x%" PRIx64
> +pmpcfg_csr_write(uint64_t mhartid, uint32_t reg_index, uint64_t val) "hart %" PRIu64 ": write reg%" PRIu32", val: 0x%" PRIx64
> +pmpaddr_csr_read(uint64_t mhartid, uint32_t addr_index, uint64_t val) "hart %" PRIu64 ": read addr%" PRIu32", val: 0x%" PRIx64
> +pmpaddr_csr_write(uint64_t mhartid, uint32_t addr_index, uint64_t val) "hart %" PRIu64 ": write addr%" PRIu32", val: 0x%" PRIx64
> --
> 2.20.1
>
>
prev parent reply other threads:[~2019-07-23 18:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-23 12:08 [Qemu-devel] [PATCH-for-4.2 0/2] target/riscv/pmp: Convert to trace events Philippe Mathieu-Daudé
2019-07-23 12:08 ` [Qemu-devel] [PATCH-for-4.2 1/2] target/riscv/pmp: Restrict priviledged PMP to system-mode emulation Philippe Mathieu-Daudé
2019-07-23 18:05 ` Alistair Francis
2019-07-23 12:08 ` [Qemu-devel] [PATCH-for-4.2 2/2] target/riscv/pmp: Convert qemu_log_mask(LOG_TRACE) to trace events Philippe Mathieu-Daudé
2019-07-23 18:06 ` Alistair Francis [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAKmqyKNrJgUBVB93dHvsoDcksj0r9ckwLpmSHMhZFdcdtYx_HQ@mail.gmail.com \
--to=alistair23@gmail.com \
--cc=Alistair.Francis@wdc.com \
--cc=frederic.konrad@adacore.com \
--cc=kbastian@mail.uni-paderborn.de \
--cc=palmer@sifive.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=sagark@eecs.berkeley.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).