From: Dayeol Lee <dayeol@berkeley.edu>
To: qemu-devel@nongnu.org
Cc: "open list:RISC-V TCG CPUs" <qemu-riscv@nongnu.org>,
Sagar Karandikar <sagark@eecs.berkeley.edu>,
Dayeol Lee <dayeol@berkeley.edu>,
Bastian Koppelmann <kbastian@mail.uni-paderborn.de>,
Palmer Dabbelt <palmer@sifive.com>,
Alistair Francis <Alistair.Francis@wdc.com>
Subject: [PATCH] target/riscv: PMP violation due to wrong size parameter
Date: Mon, 7 Oct 2019 05:28:13 +0000 [thread overview]
Message-ID: <20191007052813.25814-1-dayeol@berkeley.edu> (raw)
riscv_cpu_tlb_fill() uses the `size` parameter to check PMP violation
using pmp_hart_has_privs().
However, the size passed from tlb_fill(), which is called by
get_page_addr_code(), is always a hard-coded value 0.
This causes a false PMP violation if the instruction presents on a
PMP boundary.
In order to fix, simply correct the size to 4 if the access_type is
MMU_INST_FETCH.
Signed-off-by: Dayeol Lee <dayeol@berkeley.edu>
---
target/riscv/cpu.h | 1 +
target/riscv/cpu_helper.c | 9 ++++++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index 0adb307f32..386c80e764 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -88,6 +88,7 @@ enum {
#define MMU_USER_IDX 3
#define MAX_RISCV_PMPS (16)
+#define RISCV_INSN_LENGTH 4
typedef struct CPURISCVState CPURISCVState;
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
index e32b6126af..877e89dbf2 100644
--- a/target/riscv/cpu_helper.c
+++ b/target/riscv/cpu_helper.c
@@ -441,6 +441,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
CPURISCVState *env = &cpu->env;
hwaddr pa = 0;
int prot;
+ int pmp_size = 0;
bool pmp_violation = false;
int ret = TRANSLATE_FAIL;
int mode = mmu_idx;
@@ -460,9 +461,15 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
"%s address=%" VADDR_PRIx " ret %d physical " TARGET_FMT_plx
" prot %d\n", __func__, address, ret, pa, prot);
+ if (access_type == MMU_INST_FETCH) {
+ pmp_size = RISCV_INSN_LENGTH;
+ } else {
+ pmp_size = size;
+ }
+
if (riscv_feature(env, RISCV_FEATURE_PMP) &&
(ret == TRANSLATE_SUCCESS) &&
- !pmp_hart_has_privs(env, pa, size, 1 << access_type, mode)) {
+ !pmp_hart_has_privs(env, pa, pmp_size, 1 << access_type, mode)) {
ret = TRANSLATE_PMP_FAIL;
}
if (ret == TRANSLATE_PMP_FAIL) {
--
2.20.1
next reply other threads:[~2019-10-07 5:31 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-07 5:28 Dayeol Lee [this message]
2019-10-07 6:20 ` [PATCH] target/riscv: PMP violation due to wrong size parameter no-reply
2019-10-07 13:00 ` Richard Henderson
2019-10-07 17:19 ` Dayeol Lee
2019-10-07 18:25 ` Richard Henderson
2019-10-07 18:41 ` Dayeol Lee
2019-10-08 3:18 ` Richard Henderson
2019-10-11 23:14 Dayeol Lee
2019-10-12 2:37 ` Jonathan Behrens
2019-10-12 18:30 ` Dayeol Lee
2019-10-15 17:04 ` Dayeol Lee
2019-10-18 19:01 ` Palmer Dabbelt
2019-10-18 19:28 ` Dayeol Lee
2019-10-22 21:21 Dayeol Lee
2019-10-23 15:50 ` Palmer Dabbelt
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=20191007052813.25814-1-dayeol@berkeley.edu \
--to=dayeol@berkeley.edu \
--cc=Alistair.Francis@wdc.com \
--cc=kbastian@mail.uni-paderborn.de \
--cc=palmer@sifive.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).