1. 11 Jul, 2023 1 commit
  2. 12 Jun, 2023 1 commit
    • Oliver Upton's avatar
      KVM: arm64: Make vCPU feature flags consistent VM-wide · 2251e9ff
      Oliver Upton authored
      To date KVM has allowed userspace to construct asymmetric VMs where
      particular features may only be supported on a subset of vCPUs. This
      wasn't really the intened usage pattern, and it is a total pain in the
      ass to keep working in the kernel. What's more, this is at odds with CPU
      features in host userspace, where asymmetric features are largely hidden
      or disabled.
      
      It's time to put an end to the whole game. Require all vCPUs in the VM
      to have the same feature set, rejecting deviants in the
      KVM_ARM_VCPU_INIT ioctl. Preserve some of the vestiges of per-vCPU
      feature flags in case we need to reinstate the old behavior for some
      limited configurations. Yes, this is a sign of cowardice around a
      user-visibile change.
      
      Hoist all of the 32-bit limitations into kvm_vcpu_init_check_features()
      to avoid nested attempts to acquire the config_lock, which won't end
      well.
      
      Link: https://lore.kernel.org/r/20230609190054.1542113-4-oliver.upton@linux.dev
      
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      2251e9ff
  3. 29 Mar, 2023 2 commits
    • Oliver Upton's avatar
      KVM: arm64: Avoid lock inversion when setting the VM register width · c43120af
      Oliver Upton authored
      kvm->lock must be taken outside of the vcpu->mutex. Of course, the
      locking documentation for KVM makes this abundantly clear. Nonetheless,
      the locking order in KVM/arm64 has been wrong for quite a while; we
      acquire the kvm->lock while holding the vcpu->mutex all over the shop.
      
      All was seemingly fine until commit 42a90008
      
       ("KVM: Ensure lockdep
      knows about kvm->lock vs. vcpu->mutex ordering rule") caught us with our
      pants down, leading to lockdep barfing:
      
       ======================================================
       WARNING: possible circular locking dependency detected
       6.2.0-rc7+ #19 Not tainted
       ------------------------------------------------------
       qemu-system-aar/859 is trying to acquire lock:
       ffff5aa69269eba0 (&host_kvm->lock){+.+.}-{3:3}, at: kvm_reset_vcpu+0x34/0x274
      
       but task is already holding lock:
       ffff5aa68768c0b8 (&vcpu->mutex){+.+.}-{3:3}, at: kvm_vcpu_ioctl+0x8c/0xba0
      
       which lock already depends on the new lock.
      
      Add a dedicated lock to serialize writes to VM-scoped configuration from
      the context of a vCPU. Protect the register width flags with the new
      lock, thus avoiding the need to grab the kvm->lock while holding
      vcpu->mutex in kvm_reset_vcpu().
      
      Cc: stable@vger.kernel.org
      Reported-by: default avatarJeremy Linton <jeremy.linton@arm.com>
      Link: https://lore.kernel.org/kvmarm/f6452cdd-65ff-34b8-bab0-5c06416da5f6@arm.com/
      
      Tested-by: default avatarJeremy Linton <jeremy.linton@arm.com>
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      Link: https://lore.kernel.org/r/20230327164747.2466958-3-oliver.upton@linux.dev
      c43120af
    • Oliver Upton's avatar
      KVM: arm64: Avoid vcpu->mutex v. kvm->lock inversion in CPU_ON · 0acc7239
      Oliver Upton authored
      
      KVM/arm64 had the lock ordering backwards on vcpu->mutex and kvm->lock
      from the very beginning. One such example is the way vCPU resets are
      handled: the kvm->lock is acquired while handling a guest CPU_ON PSCI
      call.
      
      Add a dedicated lock to serialize writes to kvm_vcpu_arch::{mp_state,
      reset_state}. Promote all accessors of mp_state to {READ,WRITE}_ONCE()
      as readers do not acquire the mp_state_lock. While at it, plug yet
      another race by taking the mp_state_lock in the KVM_SET_MP_STATE ioctl
      handler.
      
      As changes to MP state are now guarded with a dedicated lock, drop the
      kvm->lock acquisition from the PSCI CPU_ON path. Similarly, move the
      reader of reset_state outside of the kvm->lock and instead protect it
      with the mp_state_lock. Note that writes to reset_state::reset have been
      demoted to regular stores as both readers and writers acquire the
      mp_state_lock.
      
      While the kvm->lock inversion still exists in kvm_reset_vcpu(), at least
      now PSCI CPU_ON no longer depends on it for serializing vCPU reset.
      
      Cc: stable@vger.kernel.org
      Tested-by: default avatarJeremy Linton <jeremy.linton@arm.com>
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      Link: https://lore.kernel.org/r/20230327164747.2466958-2-oliver.upton@linux.dev
      0acc7239
  4. 11 Feb, 2023 1 commit
  5. 21 Jan, 2023 1 commit
  6. 29 Dec, 2022 1 commit
    • Sean Christopherson's avatar
      KVM: x86: Unify pr_fmt to use module name for all KVM modules · 8d20bd63
      Sean Christopherson authored
      
      Define pr_fmt using KBUILD_MODNAME for all KVM x86 code so that printks
      use consistent formatting across common x86, Intel, and AMD code.  In
      addition to providing consistent print formatting, using KBUILD_MODNAME,
      e.g. kvm_amd and kvm_intel, allows referencing SVM and VMX (and SEV and
      SGX and ...) as technologies without generating weird messages, and
      without causing naming conflicts with other kernel code, e.g. "SEV: ",
      "tdx: ", "sgx: " etc.. are all used by the kernel for non-KVM subsystems.
      
      Opportunistically move away from printk() for prints that need to be
      modified anyways, e.g. to drop a manual "kvm: " prefix.
      
      Opportunistically convert a few SGX WARNs that are similarly modified to
      WARN_ONCE; in the very unlikely event that the WARNs fire, odds are good
      that they would fire repeatedly and spam the kernel log without providing
      unique information in each print.
      
      Note, defining pr_fmt yields undesirable results for code that uses KVM's
      printk wrappers, e.g. vcpu_unimpl().  But, that's a pre-existing problem
      as SVM/kvm_amd already defines a pr_fmt, and thankfully use of KVM's
      wrappers is relatively limited in KVM x86 code.
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Reviewed-by: default avatarPaul Durrant <paul@xen.org>
      Message-Id: <20221130230934.1014142-35-seanjc@google.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      8d20bd63
  7. 11 Nov, 2022 1 commit
  8. 09 Sep, 2022 1 commit
  9. 09 Jun, 2022 1 commit
  10. 06 Apr, 2022 1 commit
    • Reiji Watanabe's avatar
      KVM: arm64: mixed-width check should be skipped for uninitialized vCPUs · 26bf74bd
      Reiji Watanabe authored
      KVM allows userspace to configure either all EL1 32bit or 64bit vCPUs
      for a guest.  At vCPU reset, vcpu_allowed_register_width() checks
      if the vcpu's register width is consistent with all other vCPUs'.
      Since the checking is done even against vCPUs that are not initialized
      (KVM_ARM_VCPU_INIT has not been done) yet, the uninitialized vCPUs
      are erroneously treated as 64bit vCPU, which causes the function to
      incorrectly detect a mixed-width VM.
      
      Introduce KVM_ARCH_FLAG_EL1_32BIT and KVM_ARCH_FLAG_REG_WIDTH_CONFIGURED
      bits for kvm->arch.flags.  A value of the EL1_32BIT bit indicates that
      the guest needs to be configured with all 32bit or 64bit vCPUs, and
      a value of the REG_WIDTH_CONFIGURED bit indicates if a value of the
      EL1_32BIT bit is valid (already set up). Values in those bits are set at
      the first KVM_ARM_VCPU_INIT for the guest based on KVM_ARM_VCPU_EL1_32BIT
      configuration for the vCPU.
      
      Check vcpu's register width against those new bits at the vcpu's
      KVM_ARM_VCPU_INIT (instead of against other vCPUs' register width).
      
      Fixes: 66e94d5c
      
       ("KVM: arm64: Prevent mixed-width VM creation")
      Signed-off-by: default avatarReiji Watanabe <reijiw@google.com>
      Reviewed-by: default avatarOliver Upton <oupton@google.com>
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      Link: https://lore.kernel.org/r/20220329031924.619453-2-reijiw@google.com
      26bf74bd
  11. 04 Jan, 2022 1 commit
  12. 20 Dec, 2021 1 commit
  13. 16 Dec, 2021 2 commits
  14. 14 Dec, 2021 1 commit
  15. 08 Dec, 2021 1 commit
  16. 01 Dec, 2021 1 commit
  17. 21 Oct, 2021 1 commit
    • Mark Brown's avatar
      arm64/sve: Put system wide vector length information into structs · b5bc00ff
      Mark Brown authored
      
      With the introduction of SME we will have a second vector length in the
      system, enumerated and configured in a very similar fashion to the
      existing SVE vector length.  While there are a few differences in how
      things are handled this is a relatively small portion of the overall
      code so in order to avoid code duplication we factor out
      
      We create two structs, one vl_info for the static hardware properties
      and one vl_config for the runtime configuration, with an array
      instantiated for each and update all the users to reference these. Some
      accessor functions are provided where helpful for readability, and the
      write to set the vector length is put into a function since the system
      register being updated needs to be chosen at compile time.
      
      This is a mostly mechanical replacement, further work will be required
      to actually make things generic, ensuring that we handle those places
      where there are differences properly.
      Signed-off-by: default avatarMark Brown <broonie@kernel.org>
      Link: https://lore.kernel.org/r/20211019172247.3045838-8-broonie@kernel.org
      
      Signed-off-by: default avatarWill Deacon <will@kernel.org>
      b5bc00ff
  18. 17 Oct, 2021 1 commit
  19. 19 Aug, 2021 1 commit
  20. 18 Aug, 2021 1 commit
  21. 11 Aug, 2021 2 commits
  22. 22 Jun, 2021 1 commit
  23. 27 May, 2021 1 commit
  24. 09 Apr, 2021 1 commit
    • Marc Zyngier's avatar
      KVM: arm64: Fully zero the vcpu state on reset · 85d70374
      Marc Zyngier authored
      On vcpu reset, we expect all the registers to be brought back
      to their initial state, which happens to be a bunch of zeroes.
      
      However, some recent commit broke this, and is now leaving a bunch
      of registers (such as the FP state) with whatever was left by the
      guest. My bad.
      
      Zero the reset of the state (32bit SPSRs and FPSIMD state).
      
      Cc: stable@vger.kernel.org
      Fixes: e47c2055
      
       ("KVM: arm64: Make struct kvm_regs userspace-only")
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      85d70374
  25. 19 Mar, 2021 1 commit
  26. 18 Mar, 2021 1 commit
  27. 12 Mar, 2021 1 commit
    • Marc Zyngier's avatar
      KVM: arm64: Reject VM creation when the default IPA size is unsupported · 7d717558
      Marc Zyngier authored
      KVM/arm64 has forever used a 40bit default IPA space, partially
      due to its 32bit heritage (where the only choice is 40bit).
      
      However, there are implementations in the wild that have a *cough*
      much smaller *cough* IPA space, which leads to a misprogramming of
      VTCR_EL2, and a guest that is stuck on its first memory access
      if userspace dares to ask for the default IPA setting (which most
      VMMs do).
      
      Instead, blundly reject the creation of such VM, as we can't
      satisfy the requirements from userspace (with a one-off warning).
      Also clarify the boot warning, and document that the VM creation
      will fail when an unsupported IPA size is provided.
      
      Although this is an ABI change, it doesn't really change much
      for userspace:
      
      - the guest couldn't run before this change, but no error was
        returned. At least userspace knows what is happening.
      
      - a memory slot that was accepted because it did fit the default
        IPA space now doesn't even get a chance to be registered.
      
      The other thing that is left doing is to convince userspace to
      actually use the IPA space setting instead of relying on the
      antiquated default.
      
      Fixes: 233a7cb2
      
       ("kvm: arm64: Allow tuning the physical address size for VM")
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      Cc: stable@vger.kernel.org
      Reviewed-by: default avatarAndrew Jones <drjones@redhat.com>
      Reviewed-by: default avatarEric Auger <eric.auger@redhat.com>
      Link: https://lore.kernel.org/r/20210311100016.3830038-2-maz@kernel.org
      7d717558
  28. 10 Mar, 2021 1 commit
  29. 27 Nov, 2020 2 commits
  30. 10 Nov, 2020 1 commit
  31. 29 Sep, 2020 1 commit
  32. 11 Sep, 2020 1 commit
  33. 07 Jul, 2020 1 commit
  34. 22 Jun, 2020 2 commits
  35. 28 May, 2020 1 commit