1. 22 Jun, 2023 1 commit
  2. 16 Jun, 2023 4 commits
  3. 15 Jun, 2023 13 commits
    • Oliver Upton's avatar
      Merge branch kvm-arm64/misc into kvmarm/next · e1e315c4
      Oliver Upton authored
      * kvm-arm64/misc:
        : Miscellaneous updates
        :
        :  - Avoid trapping CTR_EL0 on systems with FEAT_EVT, as the register is
        :    commonly read by userspace
        :
        :  - Make use of FEAT_BTI at hyp stage-1, setting the Guard Page bit to 1
        :    for executable mappings
        :
        :  - Use a separate set of pointer authentication keys for the hypervisor
        :    when running in protected mode (i.e. pKVM)
        :
        :  - Plug a few holes in timer initialization where KVM fails to free the
        :    timer IRQ(s)
        KVM: arm64: Use different pointer authentication keys for pKVM
        KVM: arm64: timers: Fix resource leaks in kvm_timer_hyp_init()
        KVM: arm64: Use BTI for nvhe
        KVM: arm64: Relax trapping of CTR_EL0 when FEAT_EVT is available
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      e1e315c4
    • Oliver Upton's avatar
      Merge branch kvm-arm64/configurable-id-regs into kvmarm/next · 89a734b5
      Oliver Upton authored
      * kvm-arm64/configurable-id-regs:
        : Configurable ID register infrastructure, courtesy of Jing Zhang
        :
        : Create generalized infrastructure for allowing userspace to select the
        : supported feature set for a VM, so long as the feature set is a subset
        : of what hardware + KVM allows. This does not add any new features that
        : are user-configurable, and instead focuses on the necessary refactoring
        : to enable future work.
        :
        : As a consequence of the series, feature asymmetry is now deliberately
        : disallowed for KVM. It is unlikely that VMMs ever configured VMs with
        : asymmetry, nor does it align with the kernel's overall stance that
        : features must be uniform across all cores in the system.
        :
        : Furthermore, KVM incorrectly advertised an IMP_DEF PMU to guests for
        : some time. Migrations from affected kernels was supported by explicitly
        : allowing such an ID register value from userspace, and forwarding that
        : along to the guest. KVM now allows an IMP_DEF PMU version to be restored
        : through the ID register interface, but reinterprets the user value as
        : not implemented (0).
        KVM: arm64: Rip out the vestiges of the 'old' ID register scheme
        KVM: arm64: Handle ID register reads using the VM-wide values
        KVM: arm64: Use generic sanitisation for ID_AA64PFR0_EL1
        KVM: arm64: Use generic sanitisation for ID_(AA64)DFR0_EL1
        KVM: arm64: Use arm64_ftr_bits to sanitise ID register writes
        KVM: arm64: Save ID registers' sanitized value per guest
        KVM: arm64: Reuse fields of sys_reg_desc for idreg
        KVM: arm64: Rewrite IMPDEF PMU version as NI
        KVM: arm64: Make vCPU feature flags consistent VM-wide
        KVM: arm64: Relax invariance of KVM_ARM_VCPU_POWER_OFF
        KVM: arm64: Separate out feature sanitisation and initialisation
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      89a734b5
    • Oliver Upton's avatar
      Merge branch for-next/module-alloc into kvmarm/next · acfdf34c
      Oliver Upton authored
      * for-next/module-alloc:
        : Drag in module VA rework to handle conflicts w/ sw feature refactor
        arm64: module: rework module VA range selection
        arm64: module: mandate MODULE_PLTS
        arm64: module: move module randomization to module.c
        arm64: kaslr: split kaslr/module initialization
        arm64: kasan: remove !KASAN_VMALLOC remnants
        arm64: module: remove old !KASAN_VMALLOC logic
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      acfdf34c
    • Oliver Upton's avatar
      Merge branch kvm-arm64/hvhe into kvmarm/next · b710fe0d
      Oliver Upton authored
      * kvm-arm64/hvhe:
        : Support for running split-hypervisor w/VHE, courtesy of Marc Zyngier
        :
        : From the cover letter:
        :
        : KVM (on ARMv8.0) and pKVM (on all revisions of the architecture) use
        : the split hypervisor model that makes the EL2 code more or less
        : standalone. In the later case, we totally ignore the VHE mode and
        : stick with the good old v8.0 EL2 setup.
        :
        : We introduce a new "mode" for KVM called hVHE, in reference to the
        : nVHE mode, and indicating that only the hypervisor is using VHE.
        KVM: arm64: Fix hVHE init on CPUs where HCR_EL2.E2H is not RES1
        arm64: Allow arm64_sw.hvhe on command line
        KVM: arm64: Force HCR_E2H in guest context when ARM64_KVM_HVHE is set
        KVM: arm64: Program the timer traps with VHE layout in hVHE mode
        KVM: arm64: Rework CPTR_EL2 programming for HVHE configuration
        KVM: arm64: Adjust EL2 stage-1 leaf AP bits when ARM64_KVM_HVHE is set
        KVM: arm64: Disable TTBR1_EL2 when using ARM64_KVM_HVHE
        KVM: arm64: Force HCR_EL2.E2H when ARM64_KVM_HVHE is set
        KVM: arm64: Key use of VHE instructions in nVHE code off ARM64_KVM_HVHE
        KVM: arm64: Remove alternatives from sysreg accessors in VHE hypervisor context
        arm64: Use CPACR_EL1 format to set CPTR_EL2 when E2H is set
        arm64: Allow EL1 physical timer access when running VHE
        arm64: Don't enable VHE for the kernel if OVERRIDE_HVHE is set
        arm64: Add KVM_HVHE capability and has_hvhe() predicate
        arm64: Turn kaslr_feature_override into a generic SW feature override
        arm64: Prevent the use of is_kernel_in_hyp_mode() in hypervisor code
        KVM: arm64: Drop is_kernel_in_hyp_mode() from __invalidate_icache_guest_page()
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      b710fe0d
    • Oliver Upton's avatar
      Merge branch kvm-arm64/ffa-proxy into kvmarm/next · 1a08f492
      Oliver Upton authored
      * kvm-arm64/ffa-proxy:
        : pKVM FF-A Proxy, courtesy Will Deacon and Andrew Walbran
        :
        : From the cover letter:
        :
        : pKVM's primary goal is to protect guest pages from a compromised host by
        : enforcing access control restrictions using stage-2 page-tables. Sadly,
        : this cannot prevent TrustZone from accessing non-secure memory, and a
        : compromised host could, for example, perform a 'confused deputy' attack
        : by asking TrustZone to use pages that have been donated to protected
        : guests. This would effectively allow the host to have TrustZone
        : exfiltrate guest secrets on its behalf, hence breaking the isolation
        : that pKVM intends to provide.
        :
        : This series addresses this problem by providing pKVM with the ability to
        : monitor SMCs following the Arm FF-A protocol. FF-A provides (among other
        : things) a set of memory management APIs allowing the Normal World to
        : share, donate or lend pages with Secure. By monitoring these SMCs, pKVM
        : can ensure that the pages that are shared, lent or donated to Secure by
        : the host kernel are only pages that it owns.
        KVM: arm64: pkvm: Add support for fragmented FF-A descriptors
        KVM: arm64: Handle FFA_FEATURES call from the host
        KVM: arm64: Handle FFA_MEM_LEND calls from the host
        KVM: arm64: Handle FFA_MEM_RECLAIM calls from the host
        KVM: arm64: Handle FFA_MEM_SHARE calls from the host
        KVM: arm64: Add FF-A helpers to share/unshare memory with secure world
        KVM: arm64: Handle FFA_RXTX_MAP and FFA_RXTX_UNMAP calls from the host
        KVM: arm64: Allocate pages for hypervisor FF-A mailboxes
        KVM: arm64: Probe FF-A version and host/hyp partition ID during init
        KVM: arm64: Block unsafe FF-A calls from the host
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      1a08f492
    • Oliver Upton's avatar
      Merge branch kvm-arm64/eager-page-splitting into kvmarm/next · 83510396
      Oliver Upton authored
      * kvm-arm64/eager-page-splitting:
        : Eager Page Splitting, courtesy of Ricardo Koller.
        :
        : Dirty logging performance is dominated by the cost of splitting
        : hugepages to PTE granularity. On systems that mere mortals can get their
        : hands on, each fault incurs the cost of a full break-before-make
        : pattern, wherein the broadcast invalidation and ensuing serialization
        : significantly increases fault latency.
        :
        : The goal of eager page splitting is to move the cost of hugepage
        : splitting out of the stage-2 fault path and instead into the ioctls
        : responsible for managing the dirty log:
        :
        :  - If manual protection is enabled for the VM, hugepage splitting
        :    happens in the KVM_CLEAR_DIRTY_LOG ioctl. This is desirable as it
        :    provides userspace granular control over hugepage splitting.
        :
        :  - Otherwise, if userspace relies on the legacy dirty log behavior
        :    (clear on collection), hugepage splitting is done at the moment dirty
        :    logging is enabled for a particular memslot.
        :
        : Support for eager page splitting requires explicit opt-in from
        : userspace, which is realized through the
        : KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE capability.
        arm64: kvm: avoid overflow in integer division
        KVM: arm64: Use local TLBI on permission relaxation
        KVM: arm64: Split huge pages during KVM_CLEAR_DIRTY_LOG
        KVM: arm64: Open-code kvm_mmu_write_protect_pt_masked()
        KVM: arm64: Split huge pages when dirty logging is enabled
        KVM: arm64: Add kvm_uninit_stage2_mmu()
        KVM: arm64: Refactor kvm_arch_commit_memory_region()
        KVM: arm64: Add kvm_pgtable_stage2_split()
        KVM: arm64: Add KVM_CAP_ARM_EAGER_SPLIT_CHUNK_SIZE
        KVM: arm64: Export kvm_are_all_memslots_empty()
        KVM: arm64: Add helper for creating unlinked stage2 subtrees
        KVM: arm64: Add KVM_PGTABLE_WALK flags for skipping CMOs and BBM TLBIs
        KVM: arm64: Rename free_removed to free_unlinked
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      83510396
    • Oliver Upton's avatar
      KVM: arm64: Rip out the vestiges of the 'old' ID register scheme · 68667240
      Oliver Upton authored
      There's no longer a need for the baggage of the old scheme for handling
      configurable ID register fields. Rip it all out in favor of the
      generalized infrastructure.
      
      Link: https://lore.kernel.org/r/20230609190054.1542113-12-oliver.upton@linux.devSigned-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      68667240
    • Oliver Upton's avatar
      KVM: arm64: Handle ID register reads using the VM-wide values · 6db7af0d
      Oliver Upton authored
      Everything is in place now to use the generic ID register
      infrastructure. Use the VM-wide values to service ID register reads.
      The ID registers are invariant after the VM has started, so there is no
      need for locking in that case. This is rather desirable for VM live
      migration, as the needless lock contention could prolong the VM blackout
      period.
      
      Link: https://lore.kernel.org/r/20230609190054.1542113-11-oliver.upton@linux.devSigned-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      6db7af0d
    • Jing Zhang's avatar
      KVM: arm64: Use generic sanitisation for ID_AA64PFR0_EL1 · c39f5974
      Jing Zhang authored
      KVM allows userspace to write to the CSV2 and CSV3 fields of
      ID_AA64PFR0_EL1 so long as it doesn't over-promise on the
      Spectre/Meltdown mitigation state. Switch over to the new way of the
      world for screening user writes. Leave the old plumbing in place until
      we actually start handling ID register reads from the VM-wide values.
      Signed-off-by: default avatarJing Zhang <jingzhangos@google.com>
      Link: https://lore.kernel.org/r/20230609190054.1542113-10-oliver.upton@linux.dev
      [Oliver: split from monster patch, added commit description]
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      c39f5974
    • Jing Zhang's avatar
      KVM: arm64: Use generic sanitisation for ID_(AA64)DFR0_EL1 · c118cead
      Jing Zhang authored
      KVM allows userspace to specify a PMU version for the guest by writing
      to the corresponding ID registers. Currently the validation of these
      writes is done manuallly, but there's no reason we can't switch over to
      the generic sanitisation infrastructure.
      
      Start screening user writes through arm64_check_features() to prevent
      userspace from over-promising in terms of vPMU support. Leave the old
      masking in place for now, as we aren't completely ready to serve reads
      from the VM-wide values.
      Signed-off-by: default avatarJing Zhang <jingzhangos@google.com>
      Link: https://lore.kernel.org/r/20230609190054.1542113-9-oliver.upton@linux.dev
      [Oliver: split off from monster patch, cleaned up handling of NI vPMU
       values, wrote commit description]
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      c118cead
    • Jing Zhang's avatar
      KVM: arm64: Use arm64_ftr_bits to sanitise ID register writes · 2e8bf0cb
      Jing Zhang authored
      Rather than reinventing the wheel in KVM to do ID register sanitisation
      we can rely on the work already done in the core kernel. Implement a
      generalized sanitisation of ID registers based on the combination of the
      arm64_ftr_bits definitions from the core kernel and (optionally) a set
      of KVM-specific overrides.
      
      This all amounts to absolutely nothing for now, but will be used in
      subsequent changes to realize user-configurable ID registers.
      Signed-off-by: default avatarJing Zhang <jingzhangos@google.com>
      Link: https://lore.kernel.org/r/20230609190054.1542113-8-oliver.upton@linux.dev
      [Oliver: split off from monster patch, rewrote commit description,
       reworked RAZ handling, return EINVAL to userspace]
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      2e8bf0cb
    • Jing Zhang's avatar
      KVM: arm64: Save ID registers' sanitized value per guest · 47334146
      Jing Zhang authored
      Initialize the default ID register values upon the first call to
      KVM_ARM_VCPU_INIT. The vCPU feature flags are finalized at that point,
      so it is possible to determine the maximum feature set supported by a
      particular VM configuration. Do nothing with these values for now, as we
      need to rework the plumbing of what's already writable to be compatible
      with the generic infrastructure.
      Co-developed-by: default avatarReiji Watanabe <reijiw@google.com>
      Signed-off-by: default avatarReiji Watanabe <reijiw@google.com>
      Signed-off-by: default avatarJing Zhang <jingzhangos@google.com>
      Link: https://lore.kernel.org/r/20230609190054.1542113-7-oliver.upton@linux.dev
      [Oliver: Hoist everything into KVM_ARM_VCPU_INIT time, so the features
       are final]
      Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      47334146
    • Marc Zyngier's avatar
      KVM: arm64: Fix hVHE init on CPUs where HCR_EL2.E2H is not RES1 · 1700f89c
      Marc Zyngier authored
      On CPUs where E2H is RES1, we very quickly set the scene for
      running EL2 with a VHE configuration, as we do not have any other
      choice.
      
      However, CPUs that conform to the current writing of the architecture
      start with E2H=0, and only later upgrade with E2H=1. This is all
      good, but nothing there is actually reconfiguring EL2 to be able
      to correctly run the kernel at EL1. Huhuh...
      
      The "obvious" solution is not to just reinitialise the timer
      controls like we do, but to really intitialise *everything*
      unconditionally.
      
      This requires a bit of surgery, and is a good opportunity to
      remove the macro that messes with SPSR_EL2 in init_el2_state.
      
      With that, hVHE now works correctly on my trusted A55 machine!
      Reported-by: default avatarOliver Upton <oliver.upton@linux.dev>
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      Link: https://lore.kernel.org/r/20230614155129.2697388-1-maz@kernel.orgSigned-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      1700f89c
  4. 14 Jun, 2023 1 commit
    • Mostafa Saleh's avatar
      KVM: arm64: Use different pointer authentication keys for pKVM · 8c15c2a0
      Mostafa Saleh authored
      When the use of pointer authentication is enabled in the kernel it
      applies to both the kernel itself as well as KVM's nVHE hypervisor. The
      same keys are used for both the kernel and the nVHE hypervisor, which is
      less than desirable for pKVM as the host is not trusted at runtime.
      
      Naturally, the fix is to use a different set of keys for the hypervisor
      when running in protected mode. Have the host generate a new set of keys
      for the hypervisor before deprivileging the kernel. While there might be
      other sources of random directly available at EL2, this keeps the
      implementation simple, and the host is trusted anyways until it is
      deprivileged.
      
      Since the host and hypervisor no longer share a set of pointer
      authentication keys, start context switching them on the host entry/exit
      path exactly as we do for guest entry/exit. There is no need to handle
      CPU migration as the nVHE code is not migratable in the first place.
      Signed-off-by: default avatarMostafa Saleh <smostafa@google.com>
      Link: https://lore.kernel.org/r/20230614122600.2098901-1-smostafa@google.comSigned-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
      8c15c2a0
  5. 13 Jun, 2023 1 commit
  6. 12 Jun, 2023 20 commits