Skip to contentSkip to conversation

KVM: PPC: Book3S HV: Fix KVM_RUN clobbering FP/VEC user registers

PATCH Applied Nicholas Piggin 2 participants 2 messages Nov 22, 2023 – Dec 2, 2023 PowerPC

lore
Share & tools
lore

Nicholas Piggin

author reviewer
#0 lore raw

PATCH 1/1 KVM: PPC: Book3S HV: Fix KVM_RUN clobbering FP/VEC user registers

Before running a guest, the host process (e.g., QEMU) FP/VEC registers are saved if they were being used, similarly to when the kernel uses FP registers. The guest values are then be loaded into regs, and the host process registers will be restored lazily when it uses FP/VEC.

KVM HV has a bug here: the host process registers do get saved, but the user MSR bits remain enabled, which indicates the registers are valid for the process. After they are clobbered by running the guest, this valid indication causes the host process to take on the FP/VEC regiter values of the guest.

Fixes de2a20aa7237b ("powerpc: Prepare for splitting giveup_{fpu, altivec, vsx} in two")
---
 arch/powerpc/kernel/process.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/powerpc/kernel/process.c +3 -3
index 392404688cec..9452a54d356c 100644
@@ -1198,11 +1198,11 @@ void kvmppc_save_user_regs(void)
 
 	usermsr = current->thread.regs->msr;
 
+	/* Caller has enabled FP/VEC/VSX/TM in MSR */
 	if (usermsr & MSR_FP)
-		save_fpu(current);
-
+		__giveup_fpu(current);
 	if (usermsr & MSR_VEC)
-		save_altivec(current);
+		__giveup_altivec(current);
 
 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
 	if (usermsr & MSR_TM) {
Signature · 1 line
2.42.0
#1 lore raw
Quoted 5 lines · Nicholas Piggin

Before running a guest, the host process (e.g., QEMU) FP/VEC registers are saved if they were being used, similarly to when the kernel uses FP registers. The guest values are then be loaded into regs, and the host process registers will be restored lazily when it uses FP/VEC.

Quoted 7 lines

KVM HV has a bug here: the host process registers do get saved, but the user MSR bits remain enabled, which indicates the registers are valid for the process. After they are clobbered by running the guest, this valid indication causes the host process to take on the FP/VEC regiter values of the guest.

[...]

Applied to powerpc/fixes.

[1/1] KVM: PPC: Book3S HV: Fix KVM_RUN clobbering FP/VEC user registers

      https://git.kernel.org/powerpc/c/dc158d23b33df9033bcc8e7117e8591dd2f9d125

cheers