1. 09 8月, 2019 1 次提交
    • M
      KVM: arm64: Don't write junk to sysregs on reset · 03fdfb26
      Marc Zyngier 提交于
      At the moment, the way we reset system registers is mildly insane:
      We write junk to them, call the reset functions, and then check that
      we have something else in them.
      
      The "fun" thing is that this can happen while the guest is running
      (PSCI, for example). If anything in KVM has to evaluate the state
      of a system register while junk is in there, bad thing may happen.
      
      Let's stop doing that. Instead, we track that we have called a
      reset function for that register, and assume that the reset
      function has done something. This requires fixing a couple of
      sysreg refinition in the trap table.
      
      In the end, the very need of this reset check is pretty dubious,
      as it doesn't check everything (a lot of the sysregs leave outside of
      the sys_regs[] array). It may well be axed in the near future.
      Tested-by: NZenghui Yu <yuzenghui@huawei.com>
      Signed-off-by: NMarc Zyngier <maz@kernel.org>
      03fdfb26
  2. 05 7月, 2019 2 次提交
  3. 19 6月, 2019 1 次提交
  4. 02 5月, 2019 1 次提交
  5. 24 4月, 2019 2 次提交
    • A
      arm64: KVM: Enable VHE support for :G/:H perf event modifiers · 435e53fb
      Andrew Murray 提交于
      With VHE different exception levels are used between the host (EL2) and
      guest (EL1) with a shared exception level for userpace (EL0). We can take
      advantage of this and use the PMU's exception level filtering to avoid
      enabling/disabling counters in the world-switch code. Instead we just
      modify the counter type to include or exclude EL0 at vcpu_{load,put} time.
      
      We also ensure that trapped PMU system register writes do not re-enable
      EL0 when reconfiguring the backing perf events.
      
      This approach completely avoids blackout windows seen with !VHE.
      Suggested-by: NChristoffer Dall <christoffer.dall@arm.com>
      Signed-off-by: NAndrew Murray <andrew.murray@arm.com>
      Acked-by: NWill Deacon <will.deacon@arm.com>
      Reviewed-by: NSuzuki K Poulose <suzuki.poulose@arm.com>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      435e53fb
    • M
      KVM: arm/arm64: Context-switch ptrauth registers · 384b40ca
      Mark Rutland 提交于
      When pointer authentication is supported, a guest may wish to use it.
      This patch adds the necessary KVM infrastructure for this to work, with
      a semi-lazy context switch of the pointer auth state.
      
      Pointer authentication feature is only enabled when VHE is built
      in the kernel and present in the CPU implementation so only VHE code
      paths are modified.
      
      When we schedule a vcpu, we disable guest usage of pointer
      authentication instructions and accesses to the keys. While these are
      disabled, we avoid context-switching the keys. When we trap the guest
      trying to use pointer authentication functionality, we change to eagerly
      context-switching the keys, and enable the feature. The next time the
      vcpu is scheduled out/in, we start again. However the host key save is
      optimized and implemented inside ptrauth instruction/register access
      trap.
      
      Pointer authentication consists of address authentication and generic
      authentication, and CPUs in a system might have varied support for
      either. Where support for either feature is not uniform, it is hidden
      from guests via ID register emulation, as a result of the cpufeature
      framework in the host.
      
      Unfortunately, address authentication and generic authentication cannot
      be trapped separately, as the architecture provides a single EL2 trap
      covering both. If we wish to expose one without the other, we cannot
      prevent a (badly-written) guest from intermittently using a feature
      which is not uniformly supported (when scheduled on a physical CPU which
      supports the relevant feature). Hence, this patch expects both type of
      authentication to be present in a cpu.
      
      This switch of key is done from guest enter/exit assembly as preparation
      for the upcoming in-kernel pointer authentication support. Hence, these
      key switching routines are not implemented in C code as they may cause
      pointer authentication key signing error in some situations.
      Signed-off-by: NMark Rutland <mark.rutland@arm.com>
      [Only VHE, key switch in full assembly, vcpu_has_ptrauth checks
      , save host key in ptrauth exception trap]
      Signed-off-by: NAmit Daniel Kachhap <amit.kachhap@arm.com>
      Reviewed-by: NJulien Thierry <julien.thierry@arm.com>
      Cc: Christoffer Dall <christoffer.dall@arm.com>
      Cc: kvmarm@lists.cs.columbia.edu
      [maz: various fixups]
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      384b40ca
  6. 19 4月, 2019 1 次提交
  7. 29 3月, 2019 3 次提交
    • D
      KVM: arm64/sve: System register context switch and access support · 73433762
      Dave Martin 提交于
      This patch adds the necessary support for context switching ZCR_EL1
      for each vcpu.
      
      ZCR_EL1 is trapped alongside the FPSIMD/SVE registers, so it makes
      sense for it to be handled as part of the guest FPSIMD/SVE context
      for context switch purposes instead of handling it as a general
      system register.  This means that it can be switched in lazily at
      the appropriate time.  No effort is made to track host context for
      this register, since SVE requires VHE: thus the hosts's value for
      this register lives permanently in ZCR_EL2 and does not alias the
      guest's value at any time.
      
      The Hyp switch and fpsimd context handling code is extended
      appropriately.
      
      Accessors are added in sys_regs.c to expose the SVE system
      registers and ID register fields.  Because these need to be
      conditionally visible based on the guest configuration, they are
      implemented separately for now rather than by use of the generic
      system register helpers.  This may be abstracted better later on
      when/if there are more features requiring this model.
      
      ID_AA64ZFR0_EL1 is RO-RAZ for MRS/MSR when SVE is disabled for the
      guest, but for compatibility with non-SVE aware KVM implementations
      the register should not be enumerated at all for KVM_GET_REG_LIST
      in this case.  For consistency we also reject ioctl access to the
      register.  This ensures that a non-SVE-enabled guest looks the same
      to userspace, irrespective of whether the kernel KVM implementation
      supports SVE.
      Signed-off-by: NDave Martin <Dave.Martin@arm.com>
      Reviewed-by: NJulien Thierry <julien.thierry@arm.com>
      Tested-by: Nzhang.lei <zhang.lei@jp.fujitsu.com>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      73433762
    • D
      KVM: arm64: Support runtime sysreg visibility filtering · 7f34e409
      Dave Martin 提交于
      Some optional features of the Arm architecture add new system
      registers that are not present in the base architecture.
      
      Where these features are optional for the guest, the visibility of
      these registers may need to depend on some runtime configuration,
      such as a flag passed to KVM_ARM_VCPU_INIT.
      
      For example, ZCR_EL1 and ID_AA64ZFR0_EL1 need to be hidden if SVE
      is not enabled for the guest, even though these registers may be
      present in the hardware and visible to the host at EL2.
      
      Adding special-case checks all over the place for individual
      registers is going to get messy as the number of conditionally-
      visible registers grows.
      
      In order to help solve this problem, this patch adds a new sysreg
      method visibility() that can be used to hook in any needed runtime
      visibility checks.  This method can currently return
      REG_HIDDEN_USER to inhibit enumeration and ioctl access to the
      register for userspace, and REG_HIDDEN_GUEST to inhibit runtime
      access by the guest using MSR/MRS.  Wrappers are added to allow
      these flags to be conveniently queried.
      
      This approach allows a conditionally modified view of individual
      system registers such as the CPU ID registers, in addition to
      completely hiding register where appropriate.
      Signed-off-by: NDave Martin <Dave.Martin@arm.com>
      Tested-by: Nzhang.lei <zhang.lei@jp.fujitsu.com>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      7f34e409
    • D
      KVM: arm64: Propagate vcpu into read_id_reg() · 1c199913
      Dave Martin 提交于
      Architecture features that are conditionally visible to the guest
      will require run-time checks in the ID register accessor functions.
      In particular, read_id_reg() will need to perform checks in order
      to generate the correct emulated value for certain ID register
      fields such as ID_AA64PFR0_EL1.SVE for example.
      
      This patch propagates vcpu into read_id_reg() so that future
      patches can add run-time checks on the guest configuration here.
      
      For now, there is no functional change.
      Signed-off-by: NDave Martin <Dave.Martin@arm.com>
      Reviewed-by: NAlex Bennée <alex.bennee@linaro.org>
      Tested-by: Nzhang.lei <zhang.lei@jp.fujitsu.com>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      1c199913
  8. 22 2月, 2019 1 次提交
    • D
      arm64: KVM: Fix architecturally invalid reset value for FPEXC32_EL2 · c88b0936
      Dave Martin 提交于
      Due to what looks like a typo dating back to the original addition
      of FPEXC32_EL2 handling, KVM currently initialises this register to
      an architecturally invalid value.
      
      As a result, the VECITR field (RES1) in bits [10:8] is initialised
      with 0, and the two reserved (RES0) bits [6:5] are initialised with
      1.  (In the Common VFP Subarchitecture as specified by ARMv7-A,
      these two bits were IMP DEF.  ARMv8-A removes them.)
      
      This patch changes the reset value from 0x70 to 0x700, which
      reflects the architectural constraints and is presumably what was
      originally intended.
      
      Cc: <stable@vger.kernel.org> # 4.12.x-
      Cc: Christoffer Dall <christoffer.dall@arm.com>
      Fixes: 62a89c44 ("arm64: KVM: 32bit handling of coprocessor traps")
      Signed-off-by: NDave Martin <Dave.Martin@arm.com>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      c88b0936
  9. 20 2月, 2019 4 次提交
  10. 07 2月, 2019 1 次提交
  11. 25 1月, 2019 1 次提交
  12. 20 12月, 2018 2 次提交
  13. 18 12月, 2018 1 次提交
  14. 14 12月, 2018 1 次提交
  15. 12 8月, 2018 3 次提交
  16. 09 7月, 2018 1 次提交
    • M
      arm64: KVM: Handle Set/Way CMOs as NOPs if FWB is present · 09605e94
      Marc Zyngier 提交于
      Set/Way handling is one of the ugliest corners of KVM. We shouldn't
      have to handle that, but better safe than sorry.
      
      Thankfully, FWB fixes this for us by not requiering any maintenance
      (the guest is forced to use cacheable memory, no matter what it says,
      and the whole system is garanteed to be cache coherent), which means
      we don't have to emulate S/W CMOs, and don't have to track VM ops either.
      
      We still have to trap S/W though, if only to prevent the guest from
      doing something bad.
      Reviewed-by: NChristoffer Dall <christoffer.dall@arm.com>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      09605e94
  17. 25 5月, 2018 1 次提交
    • D
      KVM: arm64: Repurpose vcpu_arch.debug_flags for general-purpose flags · fa89d31c
      Dave Martin 提交于
      In struct vcpu_arch, the debug_flags field is used to store
      debug-related flags about the vcpu state.
      
      Since we are about to add some more flags related to FPSIMD and
      SVE, it makes sense to add them to the existing flags field rather
      than adding new fields.  Since there is only one debug_flags flag
      defined so far, there is plenty of free space for expansion.
      
      In preparation for adding more flags, this patch renames the
      debug_flags field to simply "flags", and updates comments
      appropriately.
      
      The flag definitions are also moved to <asm/kvm_host.h>, since
      their presence in <asm/kvm_asm.h> was for purely historical
      reasons:  these definitions are not used from asm any more, and not
      very likely to be as more Hyp asm is migrated to C.
      
      KVM_ARM64_DEBUG_DIRTY_SHIFT has not been used since commit
      1ea66d27 ("arm64: KVM: Move away from the assembly version of
      the world switch"), so this patch gets rid of that too.
      
      No functional change.
      Signed-off-by: NDave Martin <Dave.Martin@arm.com>
      Reviewed-by: NMarc Zyngier <marc.zyngier@arm.com>
      Reviewed-by: NAlex Bennée <alex.bennee@linaro.org>
      Acked-by: NChristoffer Dall <christoffer.dall@arm.com>
      [maz: fixed minor conflict]
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      fa89d31c
  18. 17 4月, 2018 1 次提交
  19. 19 3月, 2018 5 次提交
    • C
      KVM: arm64: Defer saving/restoring 32-bit sysregs to vcpu load/put · b9f8ca4d
      Christoffer Dall 提交于
      When running a 32-bit VM (EL1 in AArch32), the AArch32 system registers
      can be deferred to vcpu load/put on VHE systems because neither
      the host kernel nor host userspace uses these registers.
      
      Note that we can't save DBGVCR32_EL2 conditionally based on the state of
      the debug dirty flag on VHE after this change, because during
      vcpu_load() we haven't calculated a valid debug flag yet, and when we've
      restored the register during vcpu_load() we also have to save it during
      vcpu_put().  This means that we'll always restore/save the register for
      VHE on load/put, but luckily vcpu load/put are called rarely, so saving
      an extra register unconditionally shouldn't significantly hurt
      performance.
      
      We can also not defer saving FPEXC32_32 because this register only holds
      a guest-valid value for 32-bit guests during the exit path when the
      guest has used FPSIMD registers and restored the register in the early
      assembly handler from taking the EL2 fault, and therefore we have to
      check if fpsimd is enabled for the guest in the exit path and save the
      register then, for both VHE and non-VHE guests.
      Reviewed-by: NMarc Zyngier <marc.zyngier@arm.com>
      Reviewed-by: NAndrew Jones <drjones@redhat.com>
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      b9f8ca4d
    • C
      KVM: arm64: Defer saving/restoring 64-bit sysregs to vcpu load/put on VHE · fc7563b3
      Christoffer Dall 提交于
      Some system registers do not affect the host kernel's execution and can
      therefore be loaded when we are about to run a VCPU and we don't have to
      restore the host state to the hardware before the time when we are
      actually about to return to userspace or schedule out the VCPU thread.
      
      The EL1 system registers and the userspace state registers only
      affecting EL0 execution do not need to be saved and restored on every
      switch between the VM and the host, because they don't affect the host
      kernel's execution.
      
      We mark all registers which are now deffered as such in the
      vcpu_{read,write}_sys_reg accessors in sys-regs.c to ensure the most
      up-to-date copy is always accessed.
      
      Note MPIDR_EL1 (controlled via VMPIDR_EL2) is accessed from other vcpu
      threads, for example via the GIC emulation, and therefore must be
      declared as immediate, which is fine as the guest cannot modify this
      value.
      
      The 32-bit sysregs can also be deferred but we do this in a separate
      patch as it requires a bit more infrastructure.
      Reviewed-by: NAndrew Jones <drjones@redhat.com>
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      fc7563b3
    • C
      KVM: arm64: Introduce framework for accessing deferred sysregs · d47533da
      Christoffer Dall 提交于
      We are about to defer saving and restoring some groups of system
      registers to vcpu_put and vcpu_load on supported systems.  This means
      that we need some infrastructure to access system registes which
      supports either accessing the memory backing of the register or directly
      accessing the system registers, depending on the state of the system
      when we access the register.
      
      We do this by defining read/write accessor functions, which can handle
      both "immediate" and "deferrable" system registers.  Immediate registers
      are always saved/restored in the world-switch path, but deferrable
      registers are only saved/restored in vcpu_put/vcpu_load when supported
      and sysregs_loaded_on_cpu will be set in that case.
      
      Note that we don't use the deferred mechanism yet in this patch, but only
      introduce infrastructure.  This is to improve convenience of review in
      the subsequent patches where it is clear which registers become
      deferred.
      Reviewed-by: NMarc Zyngier <marc.zyngier@arm.com>
      Reviewed-by: NAndrew Jones <drjones@redhat.com>
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      d47533da
    • 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
  20. 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
  21. 16 1月, 2018 2 次提交
  22. 08 1月, 2018 1 次提交
  23. 02 1月, 2018 1 次提交
  24. 06 11月, 2017 1 次提交