1. 19 3月, 2018 2 次提交
    • C
      KVM: arm64: Rewrite system register accessors to read/write functions · 8d404c4c
      Christoffer Dall 提交于
      Currently we access the system registers array via the vcpu_sys_reg()
      macro.  However, we are about to change the behavior to some times
      modify the register file directly, so let's change this to two
      primitives:
      
       * Accessor macros vcpu_write_sys_reg() and vcpu_read_sys_reg()
       * Direct array access macro __vcpu_sys_reg()
      
      The accessor macros should be used in places where the code needs to
      access the currently loaded VCPU's state as observed by the guest.  For
      example, when trapping on cache related registers, a write to a system
      register should go directly to the VCPU version of the register.
      
      The direct array access macro can be used in places where the VCPU is
      known to never be running (for example userspace access) or for
      registers which are never context switched (for example all the PMU
      system registers).
      
      This rewrites all users of vcpu_sys_regs to one of the macros described
      above.
      
      No functional change.
      Acked-by: NMarc Zyngier <marc.zyngier@arm.com>
      Reviewed-by: NAndrew Jones <drjones@redhat.com>
      Signed-off-by: NChristoffer Dall <cdall@cs.columbia.edu>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      8d404c4c
    • C
      KVM: arm64: Change 32-bit handling of VM system registers · 52f6c4f0
      Christoffer Dall 提交于
      We currently handle 32-bit accesses to trapped VM system registers using
      the 32-bit index into the coproc array on the vcpu structure, which is a
      union of the coproc array and the sysreg array.
      
      Since all the 32-bit coproc indices are created to correspond to the
      architectural mapping between 64-bit system registers and 32-bit
      coprocessor registers, and because the AArch64 system registers are the
      double in size of the AArch32 coprocessor registers, we can always find
      the system register entry that we must update by dividing the 32-bit
      coproc index by 2.
      
      This is going to make our lives much easier when we have to start
      accessing system registers that use deferred save/restore and might
      have to be read directly from the physical CPU.
      Reviewed-by: NAndrew Jones <drjones@redhat.com>
      Reviewed-by: NMarc Zyngier <marc.zyngier@arm.com>
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      52f6c4f0
  2. 26 2月, 2018 2 次提交
    • J
      KVM: arm64: Enable the EL1 physical timer for AArch32 guests · eac137b4
      Jérémy Fanguède 提交于
      Some 32bits guest OS can use the CNTP timer, however KVM does not
      handle the accesses, injecting a fault instead.
      
      Use the proper handlers to emulate the EL1 Physical Timer (CNTP)
      register accesses of AArch32 guests.
      Signed-off-by: NJérémy Fanguède <j.fanguede@virtualopensystems.com>
      Signed-off-by: NAlvise Rigo <a.rigo@virtualopensystems.com>
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      eac137b4
    • M
      arm64/kvm: Prohibit guest LOR accesses · cc33c4e2
      Mark Rutland 提交于
      We don't currently limit guest accesses to the LOR registers, which we
      neither virtualize nor context-switch. As such, guests are provided with
      unusable information/controls, and are not isolated from each other (or
      the host).
      
      To prevent these issues, we can trap register accesses and present the
      illusion LORegions are unssupported by the CPU. To do this, we mask
      ID_AA64MMFR1.LO, and set HCR_EL2.TLOR to trap accesses to the following
      registers:
      
      * LORC_EL1
      * LOREA_EL1
      * LORID_EL1
      * LORN_EL1
      * LORSA_EL1
      
      ... when trapped, we inject an UNDEFINED exception to EL1, simulating
      their non-existence.
      
      As noted in D7.2.67, when no LORegions are implemented, LoadLOAcquire
      and StoreLORelease must behave as LoadAcquire and StoreRelease
      respectively. We can ensure this by clearing LORC_EL1.EN when a CPU's
      EL2 is first initialized, as the host kernel will not modify this.
      Signed-off-by: NMark Rutland <mark.rutland@arm.com>
      Cc: Vladimir Murzin <vladimir.murzin@arm.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Christoffer Dall <christoffer.dall@linaro.org>
      Cc: Marc Zyngier <marc.zyngier@arm.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: kvmarm@lists.cs.columbia.edu
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      cc33c4e2
  3. 16 1月, 2018 2 次提交
  4. 08 1月, 2018 1 次提交
  5. 02 1月, 2018 1 次提交
  6. 06 11月, 2017 1 次提交
  7. 03 11月, 2017 2 次提交
    • D
      arm64/sve: KVM: Hide SVE from CPU features exposed to guests · 07d79fe7
      Dave Martin 提交于
      KVM guests cannot currently use SVE, because SVE is always
      configured to trap to EL2.
      
      However, a guest that sees SVE reported as present in
      ID_AA64PFR0_EL1 may legitimately expect that SVE works and try to
      use it.  Instead of working, the guest will receive an injected
      undef exception, which may cause the guest to oops or go into a
      spin.
      
      To avoid misleading the guest into believing that SVE will work,
      this patch masks out the SVE field from ID_AA64PFR0_EL1 when a
      guest attempts to read this register.  No support is explicitly
      added for ID_AA64ZFR0_EL1 either, so that is still emulated as
      reading as zero, which is consistent with SVE not being
      implemented.
      
      This is a temporary measure, and will be removed in a later series
      when full KVM support for SVE is implemented.
      Signed-off-by: NDave Martin <Dave.Martin@arm.com>
      Reviewed-by: NAlex Bennée <alex.bennee@linaro.org>
      Acked-by: NMarc Zyngier <marc.zyngier@arm.com>
      Acked-by: NCatalin Marinas <catalin.marinas@arm.com>
      Acked-by: NChristoffer Dall <christoffer.dall@linaro.org>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      07d79fe7
    • D
      arm64: KVM: Hide unsupported AArch64 CPU features from guests · 93390c0a
      Dave Martin 提交于
      Currently, a guest kernel sees the true CPU feature registers
      (ID_*_EL1) when it reads them using MRS instructions.  This means
      that the guest may observe features that are present in the
      hardware but the host doesn't understand or doesn't provide support
      for.  A guest may legimitately try to use such a feature as per the
      architecture, but use of the feature may trap instead of working
      normally, triggering undef injection into the guest.
      
      This is not a problem for the host, but the guest may go wrong when
      running on newer hardware than the host knows about.
      
      This patch hides from guest VMs any AArch64-specific CPU features
      that the host doesn't support, by exposing to the guest the
      sanitised versions of the registers computed by the cpufeatures
      framework, instead of the true hardware registers.  To achieve
      this, HCR_EL2.TID3 is now set for AArch64 guests, and emulation
      code is added to KVM to report the sanitised versions of the
      affected registers in response to MRS and register reads from
      userspace.
      
      The affected registers are removed from invariant_sys_regs[] (since
      the invariant_sys_regs handling is no longer quite correct for
      them) and added to sys_reg_desgs[], with appropriate access(),
      get_user() and set_user() methods.  No runtime vcpu storage is
      allocated for the registers: instead, they are read on demand from
      the cpufeatures framework.  This may need modification in the
      future if there is a need for userspace to customise the features
      visible to the guest.
      
      Attempts by userspace to write the registers are handled similarly
      to the current invariant_sys_regs handling: writes are permitted,
      but only if they don't attempt to change the value.  This is
      sufficient to support VM snapshot/restore from userspace.
      
      Because of the additional registers, restoring a VM on an older
      kernel may not work unless userspace knows how to handle the extra
      VM registers exposed to the KVM user ABI by this patch.
      
      Under the principle of least damage, this patch makes no attempt to
      handle any of the other registers currently in
      invariant_sys_regs[], or to emulate registers for AArch32: however,
      these could be handled in a similar way in future, as necessary.
      Signed-off-by: NDave Martin <Dave.Martin@arm.com>
      Reviewed-by: NMarc Zyngier <marc.zyngier@arm.com>
      Acked-by: NCatalin Marinas <catalin.marinas@arm.com>
      Acked-by: NChristoffer Dall <christoffer.dall@linaro.org>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      93390c0a
  8. 25 7月, 2017 1 次提交
    • A
      KVM: arm/arm64: PMU: Fix overflow interrupt injection · d9f89b4e
      Andrew Jones 提交于
      kvm_pmu_overflow_set() is called from perf's interrupt handler,
      making the call of kvm_vgic_inject_irq() from it introduced with
      "KVM: arm/arm64: PMU: remove request-less vcpu kick" a really bad
      idea, as it's quite easy to try and retake a lock that the
      interrupted context is already holding. The fix is to use a vcpu
      kick, leaving the interrupt injection to kvm_pmu_sync_hwstate(),
      like it was doing before the refactoring. We don't just revert,
      though, because before the kick was request-less, leaving the vcpu
      exposed to the request-less vcpu kick race, and also because the
      kick was used unnecessarily from register access handlers.
      Reviewed-by: NChristoffer Dall <cdall@linaro.org>
      Signed-off-by: NAndrew Jones <drjones@redhat.com>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      d9f89b4e
  9. 15 6月, 2017 2 次提交
  10. 02 5月, 2017 1 次提交
  11. 09 4月, 2017 7 次提交
  12. 04 4月, 2017 1 次提交
  13. 23 3月, 2017 7 次提交
  14. 08 2月, 2017 2 次提交
  15. 30 1月, 2017 1 次提交
  16. 18 11月, 2016 1 次提交
  17. 09 9月, 2016 1 次提交
    • M
      arm64/kvm: use {read,write}_sysreg() · 1f3d8699
      Mark Rutland 提交于
      A while back we added {read,write}_sysreg accessors to handle accesses
      to system registers, without the usual boilerplate asm volatile,
      temporary variable, etc.
      
      This patch makes use of these in the arm64 KVM code to make the code
      shorter and clearer.
      
      At the same time, a comment style violation next to a system register
      access is fixed up in reset_pmcr, and comments describing whether
      operations are reads or writes are removed as this is now painfully
      obvious.
      
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: Marc Zyngier <marc.zyngier@arm.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Acked-by: NChristoffer Dall <christoffer.dall@linaro.org>
      Signed-off-by: NMark Rutland <mark.rutland@arm.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      1f3d8699
  18. 17 8月, 2016 2 次提交
  19. 14 7月, 2016 1 次提交
  20. 31 5月, 2016 1 次提交
  21. 01 3月, 2016 1 次提交
    • M
      arm64: KVM: Switch the sys_reg search to be a binary search · 623eefa8
      Marc Zyngier 提交于
      Our 64bit sys_reg table is about 90 entries long (so far, and the
      PMU support is likely to increase this). This means that on average,
      it takes 45 comparaisons to find the right entry (and actually the
      full 90 if we have to search the invariant table).
      
      Not the most efficient thing. Specially when you think that this
      table is already sorted. Switching to a binary search effectively
      reduces the search to about 7 comparaisons. Slightly better!
      
      As an added bonus, the comparison is done by comparing all the
      fields at once, instead of one at a time.
      Reviewed-by: NChristoffer Dall <christoffer.dall@linaro.org>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      623eefa8