Skip to content

Commit 8038a92

Browse files
committed
Merge tag 'kvmarm-fixes-5.8-3' of git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm into kvm-master
KVM/arm fixes for 5.8, take #3 - Disable preemption on context-switching PMU EL0 state happening on system register trap - Don't clobber X0 when tearing down KVM via a soft reset (kexec)
2 parents fa71e95 + b9e10d4 commit 8038a92

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

arch/arm64/kvm/hyp-init.S

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,15 @@ SYM_CODE_START(__kvm_handle_stub_hvc)
136136

137137
1: cmp x0, #HVC_RESET_VECTORS
138138
b.ne 1f
139-
reset:
139+
140140
/*
141-
* Reset kvm back to the hyp stub. Do not clobber x0-x4 in
142-
* case we coming via HVC_SOFT_RESTART.
141+
* Set the HVC_RESET_VECTORS return code before entering the common
142+
* path so that we do not clobber x0-x2 in case we are coming via
143+
* HVC_SOFT_RESTART.
143144
*/
145+
mov x0, xzr
146+
reset:
147+
/* Reset kvm back to the hyp stub. */
144148
mrs x5, sctlr_el2
145149
mov_q x6, SCTLR_ELx_FLAGS
146150
bic x5, x5, x6 // Clear SCTL_M and etc
@@ -151,7 +155,6 @@ reset:
151155
/* Install stub vectors */
152156
adr_l x5, __hyp_stub_vectors
153157
msr vbar_el2, x5
154-
mov x0, xzr
155158
eret
156159

157160
1: /* Bad stub call */

arch/arm64/kvm/pmu.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ static void kvm_vcpu_pmu_disable_el0(unsigned long events)
159159
}
160160

161161
/*
162-
* On VHE ensure that only guest events have EL0 counting enabled
162+
* On VHE ensure that only guest events have EL0 counting enabled.
163+
* This is called from both vcpu_{load,put} and the sysreg handling.
164+
* Since the latter is preemptible, special care must be taken to
165+
* disable preemption.
163166
*/
164167
void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu)
165168
{
@@ -169,12 +172,14 @@ void kvm_vcpu_pmu_restore_guest(struct kvm_vcpu *vcpu)
169172
if (!has_vhe())
170173
return;
171174

175+
preempt_disable();
172176
host = this_cpu_ptr(&kvm_host_data);
173177
events_guest = host->pmu_events.events_guest;
174178
events_host = host->pmu_events.events_host;
175179

176180
kvm_vcpu_pmu_enable_el0(events_guest);
177181
kvm_vcpu_pmu_disable_el0(events_host);
182+
preempt_enable();
178183
}
179184

180185
/*

0 commit comments

Comments
 (0)