Fix qemu-system-aarch64 crash
cover Fix qemu-system-aarch64 crash
The sequence of events was
(1) Kernel executed a disabled sve insn,
(2) Undefined Instruction trap went to EL3,
(3) Lookup of the exception handler saw el3 and returned asidx 1,
(4) Which hadn't been set up.
So there's definitely a bug with SVE exception routing. That said...
With just the first patch, the kernel goes into a silly exception loop which is understandable. With just the second patch, qemu gets SIGABRT instead of SIGSEGV, which is definitely easier to debug.
I think I'm in favor of both patches, but you might say we shouldn't have to have the first one and just apply the second.
r~
Richard Henderson (2):
target/arm: Always return ARMASIdx_NS when num_ases == 1
cpu: Assert asidx_from_attrs return value in range
include/qom/cpu.h | 6 ++++-- target/arm/cpu.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/2 target/arm: Always return ARMASIdx_NS when num_ases == 1
--- target/arm/cpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/cpu.h +1 -1
@@ -2915,7 +2915,7 @@ enum {/* Return the address space index to use for a memory access */ static inline int arm_asidx_from_attrs (CPUState *cs,MemTxAttrs attrs) { -return attrs.secure ? ARMASIdx_S : ARMASIdx_NS; +return cs->num_ases >1 && attrs.secure ? ARMASIdx_S : ARMASIdx_NS; }/* Return the AddressSpace to use for a memory access
Signature · 1 line
2.17.1
PATCH 2/2 cpu: Assert asidx_from_attrs return value in range
In reply to Richard Henderson--- include/qom/cpu.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
include/qom/cpu.h +4 -2
@@ -620,11 +620,13 @@ static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)static inline int cpu_asidx_from_attrs (CPUState *cpu,MemTxAttrs attrs) {CPUClass *cc =CPU_GET_CLASS (cpu); +int ret =0 ;if (cc->asidx_from_attrs) { -return cc->asidx_from_attrs (cpu, attrs); + ret = cc->asidx_from_attrs (cpu, attrs); +assert (ret < cpu->num_ases && ret >=0 ); } -return 0 ; +return ret; }#endif
Signature · 1 line
2.17.1
Re: [Qemu-devel] [PATCH 2/2] cpu: Assert asidx_from_attrs return value in range
Quoted 15 lines · Richard Henderson
Signed-off-by Richard Henderson <[email protected]>--- include/qom/cpu.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)include/qom/cpu.h +1
-0@@ -620,11 +620,13 @@ static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)static inline int cpu_asidx_from_attrs (CPUState *cpu,MemTxAttrs attrs) {CPUClass *cc =CPU_GET_CLASS (cpu); +int ret =0 ;
include/qom/cpu.h static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr) · line 632
Quoted 10 lines
include/qom/cpu.h +3
-2if (cc->asidx_from_attrs) { -return cc->asidx_from_attrs (cpu, attrs); + ret = cc->asidx_from_attrs (cpu, attrs); +assert (ret < cpu->num_ases && ret >=0 ); } - return 0; + return ret; }#endif
thanks
-- PMM
Quoted 9 lines · Richard Henderson
The sequence of events was
(1) Kernel executed a disabled sve insn,
(2) Undefined Instruction trap went to EL3,
(3) Lookup of the exception handler saw el3 and returned asidx 1,
(4) Which hadn't been set up.So there's definitely a bug with SVE exception routing. That said...
Quoted 6 lines
With just the first patch, the kernel goes into a silly exception loop which is understandable. With just the second patch, qemu gets SIGABRT instead of SIGSEGV, which is definitely easier to debug.
I think I'm in favor of both patches, but you might say we shouldn't have to have the first one and just apply the second.
I think my vote is for just the second -- a CPU without the security extensions should never be emitting transactions with attrs.secure true, so that's a bug we want to track down. Suitably placed assert()s do a better job of that than sweeping the problem under the carpet by squashing the attributes in arm_asidx_from_attrs().
thanks
-- PMM