1. 15 Jun, 2016 13 commits
    • James Hogan's avatar
      MIPS: KVM: Add KScratch registers · 05108709
      James Hogan authored
      Allow up to 6 KVM guest KScratch registers to be enabled and accessed
      via the KVM guest register API and from the guest itself (the fallback
      reading and writing of commpage registers is sufficient for KScratch
      registers to work as expected).
      
      User mode can expose the registers by setting the appropriate bits of
      the guest Config4.KScrExist field. KScratch registers that aren't usable
      won't be writeable via the KVM Ioctl API.
      Signed-off-by: default avatarJames 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      05108709
    • James Hogan's avatar
      MIPS: KVM: Emulate RDHWR CPUNum register · cf1fb0f2
      James Hogan authored
      Actually provide the VCPU number when emulating the RDHWR CPUNum
      register, so that it will match the CPUNum field of CP0_EBase register,
      rather than always returning 0.
      Signed-off-by: default avatarJames 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      cf1fb0f2
    • James Hogan's avatar
      MIPS: KVM: Allow ULRI to restrict UserLocal register · cef061d0
      James Hogan authored
      The ULRI bit in Config3 specifies whether the UserLocal register is
      implemented, but it is assumed to always be set. Now that the Config
      registers can be modified by userland, allow Config3.ULRI to be cleared
      and check ULRI before allowing the corresponding bit to be set in
      HWREna.
      
      In fact any HWREna bits corresponding to unimplemented RDHWR registers
      should read as zero and be ignored on write, so we actually prevent
      other unimplemented bits being set too.
      Signed-off-by: default avatarJames 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      cef061d0
    • James Hogan's avatar
      MIPS: KVM: Don't hardcode restored HWREna · b937ff62
      James Hogan authored
      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: default avatarJames Hogan <james.hogan@imgtec.com>
      Acked-by: default avatarRalf 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      b937ff62
    • James Hogan's avatar
      MIPS: Clean up RDHWR handling · aff565aa
      James Hogan authored
      No preprocessor definitions are used in the handling of the registers
      accessible with the RDHWR instruction, nor the corresponding bits in the
      CP0 HWREna register.
      
      Add definitions for both the register numbers (MIPS_HWR_*) and HWREna
      bits (MIPS_HWRENA_*) in asm/mipsregs.h and make use of them in the
      initialisation of HWREna and emulation of the RDHWR instruction.
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Acked-by: default avatarRalf Baechle <ralf@linux-mips.org>
      Cc: David Daney <david.daney@cavium.com>
      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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      aff565aa
    • James Hogan's avatar
      MIPS: KVM: List FPU/MSA registers · e5775930
      James Hogan authored
      Make KVM_GET_REG_LIST list FPU & MSA registers. Specifically we list all
      32 vector registers when MSA can be enabled, 32 single-precision FP
      registers when FPU can be enabled, and either 16 or 32 double-precision
      FP registers when FPU can be enabled depending on whether FR mode is
      supported (which provides 32 doubles instead of 16 even doubles).
      
      Note, these registers may still be inaccessible depending on the current
      FP mode of the guest.
      Signed-off-by: default avatarJames 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      e5775930
    • James Hogan's avatar
      MIPS: KVM: Use raw_cpu_has_fpu in kvm_mips_guest_can_have_fpu() · 19451e51
      James Hogan authored
      We need to use kvm_mips_guest_can_have_fpu() when deciding which
      registers to list with KVM_GET_REG_LIST, however it causes warnings with
      preemption since it uses cpu_has_fpu. KVM is only really supported on
      CPUs which have symmetric FPUs, so switch to raw_cpu_has_fpu to avoid
      the warning.
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Cc: 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      19451e51
    • James Hogan's avatar
      MIPS: KVM: Make KVM_GET_REG_LIST dynamic · f5c43bd4
      James Hogan authored
      Make the implementation of KVM_GET_REG_LIST more dynamic so that only
      the subset of registers actually available can be exposed to user mode.
      This is important for VZ where some of the guest register state may not
      be possible to prevent the guest from accessing, therefore the user
      process may need to be aware of the state even if it doesn't understand
      what the state is for.
      
      This also allows different MIPS KVM implementations to provide different
      registers to one another, by way of new num_regs(vcpu) and
      copy_reg_indices(vcpu, indices) callback functions, currently just
      stubbed for trap & emulate.
      Signed-off-by: default avatarJames 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      f5c43bd4
    • James Hogan's avatar
      MIPS: KVM: Pass all unknown registers to callbacks · cc68d22f
      James Hogan authored
      Pass all unrecognised register IDs through to the set_one_reg() and
      get_one_reg() callbacks, not just select ones. This allows
      implementation specific registers to be more easily added without having
      to modify arch/mips/kvm/mips.c.
      Signed-off-by: default avatarJames 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      cc68d22f
    • James Hogan's avatar
      MIPS: KVM: Convert emulation to use asm/inst.h · 258f3a2e
      James Hogan authored
      Convert various MIPS KVM guest instruction emulation functions to decode
      instructions (and encode translations) using the union mips_instruction
      and related enumerations in asm/inst.h rather than #defines and
      hardcoded values.
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Acked-by: default avatarRalf 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      258f3a2e
    • James Hogan's avatar
      MIPS: KVM: Factor writing of translated guest instructions · d5cd26bc
      James Hogan authored
      The code in kvm_mips_dyntrans.c to write a translated guest instruction
      to guest memory depending on the segment is duplicated between each of
      the functions. Additionally the cache op translation functions assume
      the instruction is in the KSEG0/1 segment rather than KSEG2/3, which is
      generally true but isn't guaranteed.
      
      Factor that code into a new kvm_mips_trans_replace() which handles both
      KSEG0/1 and KSEG2/3.
      Signed-off-by: default avatarJames 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      d5cd26bc
    • James Hogan's avatar
      MIPS: KVM: Fix translation of MFC0 ErrCtl · 66ffc50c
      James Hogan authored
      The MIPS KVM dynamic translation is meant to translate "MFC0 rt, ErrCtl"
      instructions into "ADD rt, zero, zero" to zero the destination register,
      however the rt register number was copied into rt of the ADD instruction
      encoding, which is the 2nd source operand. This results in "ADD zero,
      zero, rt" which is a no-op, so only the first execution of each such
      MFC0 from ErrCtl will actually read 0.
      
      Fix the shift to put the rt from the MFC0 encoding into the rd field of
      the ADD.
      
      Fixes: 50c83085 ("KVM/MIPS32: Binary patching of select privileged instructions.")
      Signed-off-by: default avatarJames 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      66ffc50c
    • Paolo Bonzini's avatar
      Merge tag 'kvm-s390-next-4.8-1' of... · f26ed983
      Paolo Bonzini authored
      Merge tag 'kvm-s390-next-4.8-1' of git://git.kernel.org/pub/scm/linux/kernel/git/kvms390/linux into HEAD
      
      KVM: s390: Features and fixes for 4.8 part1
      
      Four bigger things:
      1. The implementation of the STHYI opcode in the kernel. This is used
         in libraries like qclib [1] to provide enough information for a
         capacity and usage based software licence pricing. The STHYI content
         is defined by the related z/VM documentation [2]. Its data can be
         composed by accessing several other interfaces provided by LPAR or
         the machine. This information is partially sensitive or root-only
         so the kernel does the necessary filtering.
      2. Preparation for nested virtualization (VSIE). KVM should query the
         proper sclp interfaces for the availability of some features before
         using it. In the past we have been sloppy and simply assumed that
         several features are available. With this we should be able to handle
         most cases of a missing feature.
      3. CPU model interfaces extended by some additional features that are
         not covered by a facility bit in STFLE. For example all the crypto
         instructions of the coprocessor provide a query function. As reality
         tends to be more complex (e.g. export regulations might block some
         algorithms) we have to provide additional interfaces to query or
         set these non-stfle features.
      4. Several fixes and changes detected and fixed when doing 1-3.
      
      All features change base s390 code. All relevant patches have an ACK
      from the s390 or component maintainers.
      
      The next pull request for 4.8 (part2) will contain the implementation
      of VSIE.
      
      [1] http://www.ibm.com/developerworks/linux/linux390/qclib.html
      [2] https://www.ibm.com/support/knowledgecenter/SSB27U_6.3.0/com.ibm.zvm.v630.hcpb4/hcpb4sth.htm
      f26ed983
  2. 14 Jun, 2016 27 commits
    • Andrea Gelmini's avatar
      KVM: x86: Fix typos · bb3541f1
      Andrea Gelmini authored
      Signed-off-by: default avatarAndrea Gelmini <andrea.gelmini@gelma.net>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      bb3541f1
    • Andrea Gelmini's avatar
      KVM: S390: Fix typo · 960cb306
      Andrea Gelmini authored
      Signed-off-by: default avatarAndrea Gelmini <andrea.gelmini@gelma.net>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      960cb306
    • Andrea Gelmini's avatar
      KVM: ARM64: Fix typos · edce2292
      Andrea Gelmini authored
      Signed-off-by: default avatarAndrea Gelmini <andrea.gelmini@gelma.net>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      edce2292
    • Andrea Gelmini's avatar
      KVM: ARM: Fix typos · 6a727b0b
      Andrea Gelmini authored
      Signed-off-by: default avatarAndrea Gelmini <andrea.gelmini@gelma.net>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      6a727b0b
    • James Hogan's avatar
      MIPS: KVM: Print unknown load/store encodings · d86c1ebe
      James Hogan authored
      When trying to emulate an unrecognised load or store instruction, print
      the encoding to aid debug.
      Signed-off-by: default avatarJames 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      d86c1ebe
    • James Hogan's avatar
      MIPS: KVM: Dump guest tlbs if kvm_get_inst() fails · eafc4ed2
      James Hogan authored
      If kvm_get_inst() fails to find a guest TLB mapping for the guest PC
      then dump the guest TLB entries. The contents of the guest TLB is likely
      to be more interesting than the host TLB entries.
      Signed-off-by: default avatarJames 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: kvm@vger.kernel.org
      Cc: linux-mips@linux-mips.org
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      eafc4ed2
    • James Hogan's avatar
      MIPS: KVM: Trace guest register access emulation · 6398da13
      James Hogan authored
      Trace emulation of guest access to various registers via
      MFC0/MTC0/DMFC0/DMTC0 instructions (coprocessor 0) and the RDHWR
      instruction (hardware registers exposed to userland), replacing some
      existing kvm_debug calls. Trace events are much more practical for this
      kind of debug output.
      Signed-off-by: default avatarJames 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: Steven Rostedt <rostedt@goodmis.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: linux-mips@linux-mips.org
      Cc: kvm@vger.kernel.org
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      6398da13
    • James Hogan's avatar
      MIPS: KVM: Add guest mode switch trace events · 93258604
      James Hogan authored
      Add a few trace events for entering and coming out of guest mode, as well
      as re-entering it from a guest exit exception.
      Signed-off-by: default avatarJames 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: Steven Rostedt <rostedt@goodmis.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: kvm@vger.kernel.org
      Cc: linux-mips@linux-mips.org
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      93258604
    • James Hogan's avatar
      MIPS: KVM: Add kvm_asid_change trace event · 9887d1c7
      James Hogan authored
      Add a trace event for guest ASID changes, replacing the existing
      kvm_debug call.
      Signed-off-by: default avatarJames 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: Steven Rostedt <rostedt@goodmis.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: kvm@vger.kernel.org
      Cc: linux-mips@linux-mips.org
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      9887d1c7
    • James Hogan's avatar
      MIPS: KVM: Clean up kvm_exit trace event · 1e09e86a
      James Hogan authored
      Clean up the MIPS kvm_exit trace event so that the exit reasons are
      specified in a trace friendly way (via __print_symbolic), and so that
      the exit reasons that derive straight from Cause.ExcCode values map
      directly, allowing a single trace_kvm_exit() call to replace a bunch of
      individual ones.
      Signed-off-by: default avatarJames 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: Steven Rostedt <rostedt@goodmis.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: kvm@vger.kernel.org
      Cc: linux-mips@linux-mips.org
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      1e09e86a
    • James Hogan's avatar
      MIPS: KVM: Add kvm_aux trace event · 04ebebf4
      James Hogan authored
      Add a MIPS specific trace event for auxiliary context operations
      (notably FPU and MSA). Unfortunately the generic kvm_fpu trace event
      isn't flexible enough to handle the range of interesting things that can
      happen with FPU and MSA context.
      
      The type of state being operated on is traced:
      - FPU: Just the FPU registers.
      - MSA: Just the upper half of the MSA vector registers (low half already
             loaded with FPU state).
      - FPU & MSA: Full MSA vector state (includes FPU state).
      
      As is the type of operation:
      - Restore: State was enabled and restored.
      - Save: State was saved and disabled.
      - Enable: State was enabled (already loaded).
      - Disable: State was disabled (kept loaded).
      - Discard: State was discarded and disabled.
      Signed-off-by: default avatarJames 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: Steven Rostedt <rostedt@goodmis.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: linux-mips@linux-mips.org
      Cc: kvm@vger.kernel.org
      [Fix remaining occurrence of "fpu_msa", change to "aux". - Paolo]
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      04ebebf4
    • James Hogan's avatar
      MIPS: KVM: Generalise fpu_inuse for other state · f943176a
      James Hogan authored
      Rename fpu_inuse and the related definitions to aux_inuse so it can be
      used for lazy context management of other auxiliary processor state too,
      such as VZ guest timer, watchpoints and performance counters.
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Cc: 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      f943176a
    • James Hogan's avatar
      MIPS: KVM: Use va in kvm_get_inst() · 35fec262
      James Hogan authored
      Like other functions, make use of a local unsigned long va, for the
      virtual address of the PC. This reduces the amount of verbose casting of
      the opc pointer to an unsigned long.
      Signed-off-by: default avatarJames 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      35fec262
    • James Hogan's avatar
      MIPS: KVM: Combine handle_tlb_ld/st_miss · 3b08aec5
      James Hogan authored
      The handle_tlb_ld/st_miss handlers are logically equivalent and
      textually almost identical, so combine their implementations into a
      single kvm_trap_emul_handle_tlb_miss().
      Signed-off-by: default avatarJames 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      3b08aec5
    • James Hogan's avatar
      MIPS: KVM: Use MIPS_ENTRYLO_* defs from mipsregs.h · e6207bbe
      James Hogan authored
      Convert KVM to use the MIPS_ENTRYLO_* definitions from <asm/mipsregs.h>
      rather than custom definitions in kvm_host.h
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Cc: 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      e6207bbe
    • James Hogan's avatar
      MIPS: KVM: Simplify TLB_* macros · 19d194c6
      James Hogan authored
      Simplify some of the TLB_ macros making use of the arrayification of
      tlb_lo. Basically we index the array by the bit of the virtual address
      which determines whether the even or odd entry is used, instead of
      having a conditional.
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Cc: 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      19d194c6
    • James Hogan's avatar
      MIPS: KVM: Arrayify struct kvm_mips_tlb::tlb_lo* · 9fbfb06a
      James Hogan authored
      The values of the EntryLo0 and EntryLo1 registers for a TLB entry are
      stored in separate members of struct kvm_mips_tlb called tlb_lo0 and
      tlb_lo1 respectively. To allow future code which needs to manipulate
      arbitrary EntryLo data in the TLB entry to be simpler and less
      conditional, replace these members with an array of two elements.
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Cc: 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      9fbfb06a
    • James Hogan's avatar
      MIPS: KVM: Use dump_tlb_all() for kvm_mips_dump_host_tlbs() · e922a4cb
      James Hogan authored
      KVM implements its own routine for dumping the host TLB entries, but we
      already have dump_tlb_all() which does something very similar (although
      it only prints out TLB entries which match the current ASID or are
      global).
      
      Make KVM use dump_tlb_all() along with dump_tlb_regs() to avoid the
      duplication and inevitable bitrot, allowing TLB dumping enhancements
      (e.g. for VZ and GuestIDs) to be made in a single place.
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Cc: 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      e922a4cb
    • James Hogan's avatar
      MIPS: KVM: Clean up TLB management hazards · 138f7ad9
      James Hogan authored
      KVM's host TLB handling routines were using tlbw hazard barrier macros
      around tlb_read(). Now that hazard barrier macros exist for tlbr, update
      this case to use them.
      
      Also fix various other unnecessary hazard barriers in this code.
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Cc: 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      138f7ad9
    • James Hogan's avatar
      MIPS: KVM: Restore host EBase from ebase variable · 878edf01
      James Hogan authored
      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: default avatarJames 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      878edf01
    • James Hogan's avatar
      MIPS: KVM: Drop unused hpa0/hpa1 args from function · 26ee17ff
      James Hogan authored
      The function kvm_mips_handle_mapped_seg_tlb_fault() has two completely
      unused pointer arguments, hpa0 and hpa1, for which all users always pass
      NULL.
      
      Drop these two arguments and update the callers.
      Signed-off-by: default avatarJames 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      26ee17ff
    • James Hogan's avatar
      MIPS: KVM: Simplify even/odd TLB handling · 021df206
      James Hogan authored
      When handling TLB faults in the guest KSeg0 region, a pair of physical
      addresses are read from the guest physical address map. However that
      process is rather convoluted with an if/then/else statement. Simplify it
      to just clear the lowest bit for the even entry and set the lowest bit
      for the odd entry.
      Signed-off-by: default avatarJames 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      021df206
    • James Hogan's avatar
      MIPS: KVM: Don't indirect KVM functions · 9befad23
      James Hogan authored
      Several KVM module functions are indirected so that they can be accessed
      from tlb.c which is statically built into the kernel. This is no longer
      necessary as the relevant bits of code have moved into mmu.c which is
      part of the KVM module, so drop the indirections.
      
      Note: is_error_pfn() is defined inline in kvm_host.h, so didn't actually
      require the KVM module to be loaded for it to work anyway.
      Signed-off-by: default avatarJames 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      9befad23
    • James Hogan's avatar
      MIPS: KVM: Move non-TLB handling code out of tlb.c · 403015b3
      James Hogan authored
      Various functions in tlb.c perform higher level MMU handling, but don't
      strictly need to be statically built into the kernel as they don't
      directly manipulate TLB entries. Move these functions out into a
      separate mmu.c which will be built into the KVM kernel module. This
      allows them to directly reference KVM functions in the KVM kernel module
      in future.
      
      Module exports of these functions have been removed, since they aren't
      needed outside of KVM.
      Signed-off-by: default avatarJames 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      403015b3
    • James Hogan's avatar
      MIPS: KVM: Make various Cause variables 32-bit · 31cf7498
      James Hogan authored
      The CP0 Cause register is passed around in KVM quite a bit, often as an
      unsigned long, even though it is always 32-bits long.
      
      Resize it to u32 throughout MIPS KVM.
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Cc: 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      31cf7498
    • James Hogan's avatar
      MIPS: KVM: Convert code to kernel sized types · 8cffd197
      James Hogan authored
      Convert the MIPS KVM C code to use standard kernel sized types (e.g.
      u32) instead of inttypes.h style ones (e.g. uint32_t) or other types as
      appropriate.
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Cc: 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      8cffd197
    • James Hogan's avatar
      MIPS: KVM: Convert headers to kernel sized types · bdb7ed86
      James Hogan authored
      Convert the MIPS kvm_host.h structs, function declaration prototypes and
      associated definition prototypes to use standard kernel sized types
      (e.g. u32) instead of inttypes.h style ones (e.g. uint32_t).
      Signed-off-by: default avatarJames Hogan <james.hogan@imgtec.com>
      Cc: 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: default avatarPaolo Bonzini <pbonzini@redhat.com>
      bdb7ed86