Browse Source

MIPS: KVM: Don't hardcode restored HWREna

KVM modifies CP0_HWREna during guest execution so it can trap and
emulate RDHWR instructions, however it always restores the hardcoded
value 0x2000000F. This assumes the presence of the UserLocal register,
and the absence of any implementation dependent or future HW registers.

Fix by exporting the value that traps.c write into CP0_HWREna, and
loading from there instead of hard coding.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Acked-by: Ralf Baechle <ralf@linux-mips.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
James Hogan 9 years ago
parent
commit
b937ff628f
3 changed files with 7 additions and 3 deletions
  1. 1 0
      arch/mips/include/asm/setup.h
  2. 4 1
      arch/mips/kernel/traps.c
  3. 2 2
      arch/mips/kvm/locore.S

+ 1 - 0
arch/mips/include/asm/setup.h

@@ -21,6 +21,7 @@ extern void *set_vi_handler(int n, vi_handler_t addr);
 
 
 extern void *set_except_vector(int n, void *addr);
 extern void *set_except_vector(int n, void *addr);
 extern unsigned long ebase;
 extern unsigned long ebase;
+extern unsigned int hwrena;
 extern void per_cpu_trap_init(bool);
 extern void per_cpu_trap_init(bool);
 extern void cpu_cache_init(void);
 extern void cpu_cache_init(void);
 
 

+ 4 - 1
arch/mips/kernel/traps.c

@@ -2064,10 +2064,13 @@ static void configure_status(void)
 			 status_set);
 			 status_set);
 }
 }
 
 
+unsigned int hwrena;
+EXPORT_SYMBOL_GPL(hwrena);
+
 /* configure HWRENA register */
 /* configure HWRENA register */
 static void configure_hwrena(void)
 static void configure_hwrena(void)
 {
 {
-	unsigned int hwrena = cpu_hwrena_impl_bits;
+	hwrena = cpu_hwrena_impl_bits;
 
 
 	if (cpu_has_mips_r2_r6)
 	if (cpu_has_mips_r2_r6)
 		hwrena |= MIPS_HWRENA_CPUNUM |
 		hwrena |= MIPS_HWRENA_CPUNUM |

+ 2 - 2
arch/mips/kvm/locore.S

@@ -381,7 +381,7 @@ NESTED (MIPSX(GuestException), CALLFRAME_SIZ, ra)
 	mtc0	k0, CP0_DDATA_LO
 	mtc0	k0, CP0_DDATA_LO
 
 
 	/* Restore RDHWR access */
 	/* Restore RDHWR access */
-	PTR_LI	k0, 0x2000000F
+	INT_L	k0, hwrena
 	mtc0	k0, CP0_HWRENA
 	mtc0	k0, CP0_HWRENA
 
 
 	/* Jump to handler */
 	/* Jump to handler */
@@ -553,7 +553,7 @@ __kvm_mips_return_to_host:
 	mtlo	k0
 	mtlo	k0
 
 
 	/* Restore RDHWR access */
 	/* Restore RDHWR access */
-	PTR_LI	k0, 0x2000000F
+	INT_L	k0, hwrena
 	mtc0	k0, CP0_HWRENA
 	mtc0	k0, CP0_HWRENA
 
 
 	/* Restore RA, which is the address we will return to */
 	/* Restore RA, which is the address we will return to */