From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>,
Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>,
Artyom Tarasenko <atar4qemu@gmail.com>
Subject: [Qemu-devel] [PATCH 4/7] target/sparc: Correctly handle bus errors in page table walks
Date: Thu, 1 Aug 2019 19:30:09 +0100 [thread overview]
Message-ID: <20190801183012.17564-5-peter.maydell@linaro.org> (raw)
In-Reply-To: <20190801183012.17564-1-peter.maydell@linaro.org>
Currently we use the ldl_phys() function to read page table entries.
With the unassigned_access hook in place, if these hit an unassigned
area of memory then the hook will cause us to wrongly generate
an exception with a fault address matching the address of the
page table entry.
Change to using address_space_ldl() so we can detect and correctly
handle bus errors and give them their correct behaviour of
causing a translation error with a suitable fault status register.
Note that this won't actually take effect until we switch the
over to using the do_translation_failed hook.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/sparc/mmu_helper.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/target/sparc/mmu_helper.c b/target/sparc/mmu_helper.c
index cbd1e911796..351055a09b1 100644
--- a/target/sparc/mmu_helper.c
+++ b/target/sparc/mmu_helper.c
@@ -98,6 +98,7 @@ static int get_physical_address(CPUSPARCState *env, hwaddr *physical,
int error_code = 0, is_dirty, is_user;
unsigned long page_offset;
CPUState *cs = env_cpu(env);
+ MemTxResult result;
is_user = mmu_idx == MMU_USER_IDX;
@@ -120,7 +121,10 @@ static int get_physical_address(CPUSPARCState *env, hwaddr *physical,
/* SPARC reference MMU table walk: Context table->L1->L2->PTE */
/* Context base + context number */
pde_ptr = (env->mmuregs[1] << 4) + (env->mmuregs[2] << 2);
- pde = ldl_phys(cs->as, pde_ptr);
+ pde = address_space_ldl(cs->as, pde_ptr, MEMTXATTRS_UNSPECIFIED, &result);
+ if (result != MEMTX_OK) {
+ return 4 << 2; /* Translation fault, L = 0 */
+ }
/* Ctx pde */
switch (pde & PTE_ENTRYTYPE_MASK) {
@@ -132,7 +136,11 @@ static int get_physical_address(CPUSPARCState *env, hwaddr *physical,
return 4 << 2;
case 1: /* L0 PDE */
pde_ptr = ((address >> 22) & ~3) + ((pde & ~3) << 4);
- pde = ldl_phys(cs->as, pde_ptr);
+ pde = address_space_ldl(cs->as, pde_ptr,
+ MEMTXATTRS_UNSPECIFIED, &result);
+ if (result != MEMTX_OK) {
+ return (1 << 8) | (4 << 2); /* Translation fault, L = 1 */
+ }
switch (pde & PTE_ENTRYTYPE_MASK) {
default:
@@ -142,7 +150,11 @@ static int get_physical_address(CPUSPARCState *env, hwaddr *physical,
return (1 << 8) | (4 << 2);
case 1: /* L1 PDE */
pde_ptr = ((address & 0xfc0000) >> 16) + ((pde & ~3) << 4);
- pde = ldl_phys(cs->as, pde_ptr);
+ pde = address_space_ldl(cs->as, pde_ptr,
+ MEMTXATTRS_UNSPECIFIED, &result);
+ if (result != MEMTX_OK) {
+ return (2 << 8) | (4 << 2); /* Translation fault, L = 2 */
+ }
switch (pde & PTE_ENTRYTYPE_MASK) {
default:
@@ -152,7 +164,11 @@ static int get_physical_address(CPUSPARCState *env, hwaddr *physical,
return (2 << 8) | (4 << 2);
case 1: /* L2 PDE */
pde_ptr = ((address & 0x3f000) >> 10) + ((pde & ~3) << 4);
- pde = ldl_phys(cs->as, pde_ptr);
+ pde = address_space_ldl(cs->as, pde_ptr,
+ MEMTXATTRS_UNSPECIFIED, &result);
+ if (result != MEMTX_OK) {
+ return (3 << 8) | (4 << 2); /* Translation fault, L = 3 */
+ }
switch (pde & PTE_ENTRYTYPE_MASK) {
default:
--
2.20.1
next prev parent reply other threads:[~2019-08-01 18:36 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-01 18:30 [Qemu-devel] [PATCH 0/7] target/sparc: Convert to do_transaction_failed hook Peter Maydell
2019-08-01 18:30 ` [Qemu-devel] [PATCH 1/7] target/sparc: Factor out the body of sparc_cpu_unassigned_access() Peter Maydell
2019-08-01 20:16 ` Richard Henderson
2019-08-01 18:30 ` [Qemu-devel] [PATCH 2/7] target/sparc: Check for transaction failures in MMU passthrough ASIs Peter Maydell
2019-08-01 20:18 ` Richard Henderson
2019-08-01 18:30 ` [Qemu-devel] [PATCH 3/7] target/sparc: Check for transaction failures in MXCC stream ASI accesses Peter Maydell
2019-08-01 20:23 ` Richard Henderson
2019-08-01 18:30 ` Peter Maydell [this message]
2019-08-01 20:25 ` [Qemu-devel] [PATCH 4/7] target/sparc: Correctly handle bus errors in page table walks Richard Henderson
2019-08-01 18:30 ` [Qemu-devel] [PATCH 5/7] target/sparc: Handle bus errors in mmu_probe() Peter Maydell
2019-08-01 20:40 ` Richard Henderson
2019-08-01 18:30 ` [Qemu-devel] [PATCH 6/7] target/sparc: Remove unused ldl_phys from dump_mmu() Peter Maydell
2019-08-01 20:44 ` Richard Henderson
2019-08-01 18:30 ` [Qemu-devel] [PATCH 7/7] target/sparc: Switch to do_transaction_failed() hook Peter Maydell
2019-08-01 20:47 ` Richard Henderson
2019-09-03 13:15 ` [Qemu-devel] [PATCH 0/7] target/sparc: Convert to do_transaction_failed hook Peter Maydell
2019-09-03 16:55 ` Mark Cave-Ayland
2019-09-04 8:14 ` Peter Maydell
2019-09-06 14:29 ` Mark Cave-Ayland
2019-09-17 13:56 ` Peter Maydell
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=20190801183012.17564-5-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=atar4qemu@gmail.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/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).