Skip to content

Commit

Permalink
MIPS: KVM: Restore host EBase from ebase variable
Browse files Browse the repository at this point in the history
The host kernel's exception vector base address is currently saved in
the VCPU structure at creation time, and restored on a guest exit.
However it doesn't change and can already be easily accessed from the
'ebase' variable (arch/mips/kernel/traps.c), so drop the host_ebase
member of kvm_vcpu_arch, export the 'ebase' variable to modules and load
from there instead.

This does result in a single extra instruction (lui) on the guest exit
path, but simplifies the code a bit and removes the redundant storage of
the host exception base address.

Credit for the idea goes to Cavium's VZ KVM implementation.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
James Hogan authored and Paolo Bonzini committed Jun 14, 2016
1 parent 26ee17f commit 878edf0
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion arch/mips/include/asm/kvm_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ struct kvm_mips_tlb {

#define KVM_MIPS_GUEST_TLB_SIZE 64
struct kvm_vcpu_arch {
void *host_ebase, *guest_ebase;
void *guest_ebase;
int (*vcpu_run)(struct kvm_run *run, struct kvm_vcpu *vcpu);
unsigned long host_stack;
unsigned long host_gp;
Expand Down
1 change: 0 additions & 1 deletion arch/mips/kernel/asm-offsets.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ void output_kvm_defines(void)
OFFSET(VCPU_RUN, kvm_vcpu, run);
OFFSET(VCPU_HOST_ARCH, kvm_vcpu, arch);

OFFSET(VCPU_HOST_EBASE, kvm_vcpu_arch, host_ebase);
OFFSET(VCPU_GUEST_EBASE, kvm_vcpu_arch, guest_ebase);

OFFSET(VCPU_HOST_STACK, kvm_vcpu_arch, host_stack);
Expand Down
1 change: 1 addition & 0 deletions arch/mips/kernel/traps.c
Original file line number Diff line number Diff line change
Expand Up @@ -1859,6 +1859,7 @@ void __noreturn nmi_exception_handler(struct pt_regs *regs)
#define VECTORSPACING 0x100 /* for EI/VI mode */

unsigned long ebase;
EXPORT_SYMBOL_GPL(ebase);
unsigned long exception_handlers[32];
unsigned long vi_handlers[64];

Expand Down
2 changes: 1 addition & 1 deletion arch/mips/kvm/locore.S
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ NESTED (MIPSX(GuestException), CALLFRAME_SIZ, ra)
mtc0 k0, CP0_STATUS
ehb

LONG_L k0, VCPU_HOST_EBASE(k1)
LONG_L k0, ebase
mtc0 k0,CP0_EBASE

/*
Expand Down
3 changes: 0 additions & 3 deletions arch/mips/kvm/mips.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,6 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
else
size = 0x4000;

/* Save Linux EBASE */
vcpu->arch.host_ebase = (void *)read_c0_ebase();

gebase = kzalloc(ALIGN(size, PAGE_SIZE), GFP_KERNEL);

if (!gebase) {
Expand Down

0 comments on commit 878edf0

Please sign in to comment.