From: Zenghui Yu <zenghui.yu@linux.dev>
To: qemu-arm@nongnu.org, qemu-devel@nongnu.org
Cc: agraf@csgraf.de, peter.maydell@linaro.org,
Zenghui Yu <zenghui.yu@linux.dev>
Subject: [PATCH rfc] hvf: arm: Inject SEA when executing insn in invalid memory range
Date: Mon, 16 Mar 2026 00:38:40 +0800 [thread overview]
Message-ID: <20260315163840.30741-1-zenghui.yu@linux.dev> (raw)
It seems that hvf doesn't deal with the abort generated when guest tries to
execute instructions outside of the valid physical memory range, for
unknown reason. The abort is forwarded to userspace and QEMU doesn't handle
it either, which ends up with faulting on the same instruction infinitely.
This was noticed by the kvm-unit-tests/selftest-vectors-kernel failure:
timeout -k 1s --foreground 90s /opt/homebrew/bin/qemu-system-aarch64 \
-nodefaults -machine virt -accel hvf -cpu host \
-device virtio-serial-device -device virtconsole,chardev=ctd \
-chardev testdev,id=ctd -device pci-testdev -display none \
-serial stdio -kernel arm/selftest.flat -smp 1 -append vectors-kernel
PASS: selftest: vectors-kernel: und
PASS: selftest: vectors-kernel: svc
qemu-system-aarch64: 0xffffc000: unhandled exception ec=0x20
qemu-system-aarch64: 0xffffc000: unhandled exception ec=0x20
qemu-system-aarch64: 0xffffc000: unhandled exception ec=0x20
[...]
It's apparent that the guest is braindead and it's unsure what prevents hvf
from injecting an abort directly in that case. Try to deal with the insane
guest in QEMU by injecting an SEA back into it in the EC_INSNABORT
emulation path.
Signed-off-by: Zenghui Yu <zenghui.yu@linux.dev>
---
target/arm/hvf/hvf.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index aabc7d32c1..54d6ea469c 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -2332,9 +2332,32 @@ static int hvf_handle_exception(CPUState *cpu, hv_vcpu_exit_exception_t *excp)
bool ea = (syndrome >> 9) & 1;
bool s1ptw = (syndrome >> 7) & 1;
uint32_t ifsc = (syndrome >> 0) & 0x3f;
+ uint64_t ipa = excp->physical_address;
+ AddressSpace *as = cpu_get_address_space(cpu, ARMASIdx_NS);
+ hwaddr xlat;
+ MemoryRegion *mr;
+
+ cpu_synchronize_state(cpu);
trace_hvf_insn_abort(env->pc, set, fnv, ea, s1ptw, ifsc);
+ /*
+ * TODO: If s1ptw, this is an error in the guest os page tables.
+ * Inject the exception into the guest.
+ */
+ assert(!s1ptw);
+
+ mr = address_space_translate(as, ipa, &xlat, NULL, false,
+ MEMTXATTRS_UNSPECIFIED);
+ if (unlikely(!memory_region_is_ram(mr))) {
+ uint32_t syn;
+
+ /* inject an SEA back into the guest */
+ syn = syn_insn_abort(arm_current_el(env) == 1, ea, false, 0x10);
+ hvf_raise_exception(cpu, EXCP_PREFETCH_ABORT, syn, 1);
+ break;
+ }
+
/* fall through */
}
default:
--
2.53.0
next reply other threads:[~2026-03-15 16:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-15 16:38 Zenghui Yu [this message]
2026-03-16 9:40 ` [PATCH rfc] hvf: arm: Inject SEA when executing insn in invalid memory range Alex Bennée
2026-03-16 10:05 ` Mohamed Mediouni
2026-03-16 10:54 ` Zenghui Yu
2026-03-20 10:52 ` Peter Maydell
2026-03-21 17:09 ` Zenghui Yu
2026-03-21 17:26 ` Mohamed Mediouni
2026-03-21 17:39 ` Zenghui Yu
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=20260315163840.30741-1-zenghui.yu@linux.dev \
--to=zenghui.yu@linux.dev \
--cc=agraf@csgraf.de \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.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