target/arm: Permit accesses to ELR_Hyp from Hyp mode via MSR/MRS (banked)

The MSR (banked) and MRS (banked) instructions allow accesses to ELR_Hyp
from either Monitor or Hyp mode. Our translate time check
was overly strict and only permitted access from Monitor mode.

The runtime check we do in msr_mrs_banked_exc_checks() had the
correct code in it, but never got there because of the earlier
"currmode == tgtmode" check. Special case ELR_Hyp.

Backports commit aec4dd09f172ee64c19222b78269d5952fd9c1dc from qemu
This commit is contained in:
Peter Maydell 2018-08-22 12:51:39 -04:00 committed by Lioncash
parent 858aa2d094
commit 8c41572624
No known key found for this signature in database
GPG Key ID: 4E3C3CC1031BA9C7
2 changed files with 18 additions and 14 deletions

View File

@ -613,6 +613,14 @@ static void msr_mrs_banked_exc_checks(CPUARMState *env, uint32_t tgtmode,
*/
int curmode = env->uncached_cpsr & CPSR_M;
if (regno == 17) {
/* ELR_Hyp: a special case because access from tgtmode is OK */
if (curmode != ARM_CPU_MODE_HYP && curmode != ARM_CPU_MODE_MON) {
goto undef;
}
return;
}
if (curmode == tgtmode) {
goto undef;
}
@ -640,17 +648,9 @@ static void msr_mrs_banked_exc_checks(CPUARMState *env, uint32_t tgtmode,
}
if (tgtmode == ARM_CPU_MODE_HYP) {
switch (regno) {
case 17: /* ELR_Hyp */
if (curmode != ARM_CPU_MODE_HYP && curmode != ARM_CPU_MODE_MON) {
goto undef;
}
break;
default:
if (curmode != ARM_CPU_MODE_MON) {
goto undef;
}
break;
/* SPSR_Hyp, r13_hyp: accessible from Monitor mode only */
if (curmode != ARM_CPU_MODE_MON) {
goto undef;
}
}

View File

@ -4640,10 +4640,14 @@ static bool msr_banked_access_decode(DisasContext *s, int r, int sysm, int rn,
}
break;
case ARM_CPU_MODE_HYP:
/* Note that we can forbid accesses from EL2 here because they
* must be from Hyp mode itself
/*
* SPSR_hyp and r13_hyp can only be accessed from Monitor mode
* (and so we can forbid accesses from EL2 or below). elr_hyp
* can be accessed also from Hyp mode, so forbid accesses from
* EL0 or EL1.
*/
if (!arm_dc_feature(s, ARM_FEATURE_EL2) || s->current_el < 3) {
if (!arm_dc_feature(s, ARM_FEATURE_EL2) || s->current_el < 2 ||
(s->current_el < 3 && *regno != 17)) {
goto undef;
}
break;