1. 17 3月, 2020 1 次提交
    • P
      KVM: Remove unnecessary asm/kvm_host.h includes · 4d395762
      Peter Xu 提交于
      Remove includes of asm/kvm_host.h from files that already include
      linux/kvm_host.h to make it more obvious that there is no ordering issue
      between the two headers.  linux/kvm_host.h includes asm/kvm_host.h to
      pick up architecture specific settings, and this will never change, i.e.
      including asm/kvm_host.h after linux/kvm_host.h may seem problematic,
      but in practice is simply redundant.
      Signed-off-by: NPeter Xu <peterx@redhat.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      4d395762
  2. 28 1月, 2020 1 次提交
  3. 28 10月, 2019 1 次提交
  4. 22 10月, 2019 2 次提交
    • S
      KVM: arm64: Provide VCPU attributes for stolen time · 58772e9a
      Steven Price 提交于
      Allow user space to inform the KVM host where in the physical memory
      map the paravirtualized time structures should be located.
      
      User space can set an attribute on the VCPU providing the IPA base
      address of the stolen time structure for that VCPU. This must be
      repeated for every VCPU in the VM.
      
      The address is given in terms of the physical address visible to
      the guest and must be 64 byte aligned. The guest will discover the
      address via a hypercall.
      Signed-off-by: NSteven Price <steven.price@arm.com>
      Signed-off-by: NMarc Zyngier <maz@kernel.org>
      58772e9a
    • C
      KVM: arm/arm64: Allow user injection of external data aborts · da345174
      Christoffer Dall 提交于
      In some scenarios, such as buggy guest or incorrect configuration of the
      VMM and firmware description data, userspace will detect a memory access
      to a portion of the IPA, which is not mapped to any MMIO region.
      
      For this purpose, the appropriate action is to inject an external abort
      to the guest.  The kernel already has functionality to inject an
      external abort, but we need to wire up a signal from user space that
      lets user space tell the kernel to do this.
      
      It turns out, we already have the set event functionality which we can
      perfectly reuse for this.
      Signed-off-by: NChristoffer Dall <christoffer.dall@arm.com>
      Signed-off-by: NMarc Zyngier <maz@kernel.org>
      da345174
  5. 05 7月, 2019 1 次提交
    • Z
      KVM: arm64/sve: Fix vq_present() macro to yield a bool · e644fa18
      Zhang Lei 提交于
      The original implementation of vq_present() relied on aggressive
      inlining in order for the compiler to know that the code is
      correct, due to some const-casting issues.  This was causing sparse
      and clang to complain, while GCC compiled cleanly.
      
      Commit 0c529ff7 addressed this problem, but since vq_present()
      is no longer a function, there is now no implicit casting of the
      returned value to the return type (bool).
      
      In set_sve_vls(), this uncast bit value is compared against a bool,
      and so may spuriously compare as unequal when both are nonzero.  As
      a result, KVM may reject valid SVE vector length configurations as
      invalid, and vice versa.
      
      Fix it by forcing the returned value to a bool.
      Signed-off-by: NZhang Lei <zhang.lei@jp.fujitsu.com>
      Fixes: 0c529ff7 ("KVM: arm64: Implement vq_present() as a macro")
      Signed-off-by: Dave Martin <Dave.Martin@arm.com> [commit message rewrite]
      Cc: Viresh Kumar <viresh.kumar@linaro.org>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      e644fa18
  6. 19 6月, 2019 1 次提交
  7. 12 6月, 2019 2 次提交
  8. 19 4月, 2019 6 次提交
    • D
      KVM: arm64/sve: Explain validity checks in set_sve_vls() · ecfb6ed4
      Dave Martin 提交于
      Correct virtualization of SVE relies for correctness on code in
      set_sve_vls() that verifies consistency between the set of vector
      lengths requested by userspace and the set of vector lengths
      available on the host.
      
      However, the purpose of this code is not obvious, and not likely to
      be apparent at all to people who do not have detailed knowledge of
      the SVE system-level architecture.
      
      This patch adds a suitable comment to explain what these checks are
      for.
      
      No functional change.
      Suggested-by: NAndrew Jones <drjones@redhat.com>
      Signed-off-by: NDave Martin <Dave.Martin@arm.com>
      Reviewed-by: NAndrew Jones <drjones@redhat.com>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      ecfb6ed4
    • D
      KVM: arm64/sve: Simplify KVM_REG_ARM64_SVE_VLS array sizing · 4bd774e5
      Dave Martin 提交于
      A complicated DIV_ROUND_UP() expression is currently written out
      explicitly in multiple places in order to specify the size of the
      bitmap exchanged with userspace to represent the value of the
      KVM_REG_ARM64_SVE_VLS pseudo-register.
      
      Userspace currently has no direct way to work this out either: for
      documentation purposes, the size is just quoted as 8 u64s.
      
      To make this more intuitive, this patch replaces these with a
      single define, which is also exported to userspace as
      KVM_ARM64_SVE_VLS_WORDS.
      
      Since the number of words in a bitmap is just the index of the last
      word used + 1, this patch expresses the bound that way instead.
      This should make it clearer what is being expressed.
      
      For userspace convenience, the minimum and maximum possible vector
      lengths relevant to the KVM ABI are exposed to UAPI as
      KVM_ARM64_SVE_VQ_MIN, KVM_ARM64_SVE_VQ_MAX.  Since the only direct
      use for these at present is manipulation of KVM_REG_ARM64_SVE_VLS,
      no corresponding _VL_ macros are defined.  They could be added
      later if a need arises.
      
      Since use of DIV_ROUND_UP() was the only reason for including
      <linux/kernel.h> in guest.c, this patch also removes that #include.
      Suggested-by: NAndrew Jones <drjones@redhat.com>
      Signed-off-by: NDave Martin <Dave.Martin@arm.com>
      Reviewed-by: NAndrew Jones <drjones@redhat.com>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      4bd774e5
    • D
      KVM: arm64/sve: WARN when avoiding divide-by-zero in sve_reg_to_region() · 55ffad3b
      Dave Martin 提交于
      sve_reg_to_region() currently passes the result of
      vcpu_sve_state_size() to array_index_nospec(), effectively
      leading to a divide / modulo operation.
      
      Currently the code bails out and returns -EINVAL if
      vcpu_sve_state_size() turns out to be zero, in order to avoid going
      ahead and attempting to divide by zero.  This is reasonable, but it
      should only happen if the kernel contains some other bug that
      allowed this code to be reached without the vcpu having been
      properly initialised.
      
      To make it clear that this is a defence against bugs rather than
      something that the user should be able to trigger, this patch marks
      the check with WARN_ON().
      Suggested-by: NAndrew Jones <drjones@redhat.com>
      Signed-off-by: NDave Martin <Dave.Martin@arm.com>
      Reviewed-by: NAndrew Jones <drjones@redhat.com>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      55ffad3b
    • D
      KVM: arm64/sve: Make register ioctl access errors more consistent · 52110aa9
      Dave Martin 提交于
      Currently, the way error codes are generated when processing the
      SVE register access ioctls in a bit haphazard.
      
      This patch refactors the code so that the behaviour is more
      consistent: now, -EINVAL should be returned only for unrecognised
      register IDs or when some other runtime error occurs.  -ENOENT is
      returned for register IDs that are recognised, but whose
      corresponding register (or slice) does not exist for the vcpu.
      
      To this end, in {get,set}_sve_reg() we now delegate the
      vcpu_has_sve() check down into {get,set}_sve_vls() and
      sve_reg_to_region().  The KVM_REG_ARM64_SVE_VLS special case is
      picked off first, then sve_reg_to_region() plays the role of
      exhaustively validating or rejecting the register ID and (where
      accepted) computing the applicable register region as before.
      
      sve_reg_to_region() is rearranged so that -ENOENT or -EPERM is not
      returned prematurely, before checking whether reg->id is in a
      recognised range.
      
      -EPERM is now only returned when an attempt is made to access an
      actually existing register slice on an unfinalized vcpu.
      
      Fixes: e1c9c983 ("KVM: arm64/sve: Add SVE support to register access ioctl interface")
      Fixes: 9033bba4 ("KVM: arm64/sve: Add pseudo-register for the guest's vector lengths")
      Suggested-by: NAndrew Jones <drjones@redhat.com>
      Signed-off-by: NDave Martin <Dave.Martin@arm.com>
      Reviewed-by: NAndrew Jones <drjones@redhat.com>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      52110aa9
    • D
      KVM: arm64/sve: Miscellaneous tidyups in guest.c · f8d4635a
      Dave Martin 提交于
       * Remove a few redundant blank lines that are stylistically
         inconsistent with code already in guest.c and are just taking up
         space.
      
       * Delete a couple of pointless empty default cases from switch
         statements whose behaviour is otherwise obvious anyway.
      
       * Fix some typos and consolidate some redundantly duplicated
         comments.
      
       * Respell the slice index check in sve_reg_to_region() as "> 0"
         to be more consistent with what is logically being checked here
         (i.e., "is the slice index too large"), even though we don't try
         to cope with multiple slices yet.
      
      No functional change.
      Suggested-by: NAndrew Jones <drjones@redhat.com>
      Signed-off-by: NDave Martin <Dave.Martin@arm.com>
      Reviewed-by: NAndrew Jones <drjones@redhat.com>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      f8d4635a
    • D
      KVM: arm64/sve: Clean up UAPI register ID definitions · 8ae6efdd
      Dave Martin 提交于
      Currently, the SVE register ID macros are not all defined in the
      same way, and advertise the fact that FFR maps onto the nonexistent
      predicate register P16.  This is really just for kernel
      convenience, and may lead userspace into bad habits.
      
      Instead, this patch masks the ID macro arguments so that
      architecturally invalid register numbers will not be passed through
      any more, and uses a literal KVM_REG_ARM64_SVE_FFR_BASE macro to
      define KVM_REG_ARM64_SVE_FFR(), similarly to the way the _ZREG()
      and _PREG() macros are defined.
      
      Rather than plugging in magic numbers for the number of Z- and P-
      registers and the maximum possible number of register slices, this
      patch provides definitions for those too.  Userspace is going to
      need them in any case, and it makes sense for them to come from
      <uapi/asm/kvm.h>.
      
      sve_reg_to_region() uses convenience constants that are defined in
      a different way, and also makes use of the fact that the FFR IDs
      are really contiguous with the P15 IDs, so this patch retains the
      existing convenience constants in guest.c, supplemented with a
      couple of sanity checks to check for consistency with the UAPI
      header.
      
      Fixes: e1c9c983 ("KVM: arm64/sve: Add SVE support to register access ioctl interface")
      Suggested-by: NAndrew Jones <drjones@redhat.com>
      Signed-off-by: NDave Martin <Dave.Martin@arm.com>
      Reviewed-by: NAndrew Jones <drjones@redhat.com>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      8ae6efdd
  9. 02 4月, 2019 1 次提交
    • M
      arm64: KVM: Fix system register enumeration · 5d8d4af2
      Marc Zyngier 提交于
      The introduction of the SVE registers to userspace started with a
      refactoring of the way we expose any register via the ONE_REG
      interface.
      
      Unfortunately, this change doesn't exactly behave as expected
      if the number of registers is non-zero and consider everything
      to be an error. The visible result is that QEMU barfs very early
      when creating vcpus.
      
      Make sure we only exit early in case there is an actual error, rather
      than a positive number of registers...
      
      Fixes: be25bbb3 ("KVM: arm64: Factor out core register ID enumeration")
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      5d8d4af2
  10. 29 3月, 2019 7 次提交
  11. 03 10月, 2018 1 次提交
  12. 01 10月, 2018 2 次提交
  13. 21 7月, 2018 2 次提交
  14. 06 7月, 2018 1 次提交
  15. 20 4月, 2018 1 次提交
    • M
      arm/arm64: KVM: Add PSCI version selection API · 85bd0ba1
      Marc Zyngier 提交于
      Although we've implemented PSCI 0.1, 0.2 and 1.0, we expose either 0.1
      or 1.0 to a guest, defaulting to the latest version of the PSCI
      implementation that is compatible with the requested version. This is
      no different from doing a firmware upgrade on KVM.
      
      But in order to give a chance to hypothetical badly implemented guests
      that would have a fit by discovering something other than PSCI 0.2,
      let's provide a new API that allows userspace to pick one particular
      version of the API.
      
      This is implemented as a new class of "firmware" registers, where
      we expose the PSCI version. This allows the PSCI version to be
      save/restored as part of a guest migration, and also set to
      any supported version if the guest requires it.
      
      Cc: stable@vger.kernel.org #4.16
      Reviewed-by: NChristoffer Dall <cdall@kernel.org>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      85bd0ba1
  16. 19 3月, 2018 1 次提交
  17. 15 3月, 2018 1 次提交
    • C
      KVM: arm/arm64: Avoid vcpu_load for other vcpu ioctls than KVM_RUN · e21a4f3a
      Christoffer Dall 提交于
      Calling vcpu_load() registers preempt notifiers for this vcpu and calls
      kvm_arch_vcpu_load().  The latter will soon be doing a lot of heavy
      lifting on arm/arm64 and will try to do things such as enabling the
      virtual timer and setting us up to handle interrupts from the timer
      hardware.
      
      Loading state onto hardware registers and enabling hardware to signal
      interrupts can be problematic when we're not actually about to run the
      VCPU, because it makes it difficult to establish the right context when
      handling interrupts from the timer, and it makes the register access
      code difficult to reason about.
      
      Luckily, now when we call vcpu_load in each ioctl implementation, we can
      simply remove the call from the non-KVM_RUN vcpu ioctls, and our
      kvm_arch_vcpu_load() is only used for loading vcpu content to the
      physical CPU when we're actually going to run the vcpu.
      
      Cc: stable@vger.kernel.org
      Fixes: 9b062471 ("KVM: Move vcpu_load to arch-specific kvm_arch_vcpu_ioctl")
      Reviewed-by: NJulien Grall <julien.grall@arm.com>
      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>
      e21a4f3a
  18. 14 12月, 2017 1 次提交
  19. 08 6月, 2017 1 次提交
    • C
      KVM: arm/arm64: Allow setting the timer IRQ numbers from userspace · 99a1db7a
      Christoffer Dall 提交于
      First we define an ABI using the vcpu devices that lets userspace set
      the interrupt numbers for the various timers on both the 32-bit and
      64-bit KVM/ARM implementations.
      
      Second, we add the definitions for the groups and attributes introduced
      by the above ABI.  (We add the PMU define on the 32-bit side as well for
      symmetry and it may get used some day.)
      
      Third, we set up the arch-specific vcpu device operation handlers to
      call into the timer code for anything related to the
      KVM_ARM_VCPU_TIMER_CTRL group.
      
      Fourth, we implement support for getting and setting the timer interrupt
      numbers using the above defined ABI in the arch timer code.
      
      Fifth, we introduce error checking upon enabling the arch timer (which
      is called when first running a VCPU) to check that all VCPUs are
      configured to use the same PPI for the timer (as mandated by the
      architecture) and that the virtual and physical timers are not
      configured to use the same IRQ number.
      Signed-off-by: NChristoffer Dall <cdall@linaro.org>
      Reviewed-by: NMarc Zyngier <marc.zyngier@arm.com>
      99a1db7a
  20. 25 12月, 2016 1 次提交
  21. 14 6月, 2016 1 次提交
  22. 01 3月, 2016 1 次提交
  23. 29 2月, 2016 1 次提交
  24. 14 12月, 2015 2 次提交