target/arm: fix crash on pmu register access

Fix a QEMU NULL derefence that occurs when the guest attempts to
enable PMU counters with a non-v8 cpu model or a v8 cpu model
which has not configured a PMU.

Backports commit cbbb3041fe2f57a475cef5d6b0ef836118aad106 from qemu
This commit is contained in:
Andrew Jones 2019-03-26 20:32:41 -04:00 committed by Lioncash
parent 2427ace0c0
commit 3c50e72c40
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -1117,6 +1117,10 @@ static bool pmu_counter_enabled(CPUARMState *env, uint8_t counter)
int el = arm_current_el(env);
uint8_t hpmn = env->cp15.mdcr_el2 & MDCR_HPMN;
if (!arm_feature(env, ARM_FEATURE_PMU)) {
return false;
}
if (!arm_feature(env, ARM_FEATURE_EL2) ||
(counter < hpmn || counter == 31)) {
e = env->cp15.c9_pmcr & PMCRE;