Skip to content
  1. Aug 10, 2022
    • Yang Yingliang's avatar
      KVM: arm64: Fix compile error due to sign extension · ae3b1da9
      Yang Yingliang authored
      Use GENMASK() to generate the masks of device type and device id,
      fixing compilation errors due to the sign extension when using
      older versions of GCC (such as is 7.5):
      
      In function ‘kvm_vm_ioctl_set_device_addr.isra.38’,
          inlined from ‘kvm_arch_vm_ioctl’ at arch/arm64/kvm/arm.c:1454:10:
      ././include/linux/compiler_types.h:354:38: error: call to ‘__compiletime_assert_599’ \
      declared with attribute error: FIELD_GET: mask is not constant
        _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
      
      Fixes: 9f968c92
      
       ("KVM: arm64: vgic-v2: Add helper for legacy dist/cpuif base address setting")
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      [maz: tidy up commit message]
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      Link: https://lore.kernel.org/r/20220810013435.1525363-1-yangyingliang@huawei.com
      ae3b1da9
  2. Jul 28, 2022
  3. Jul 26, 2022
  4. Jul 17, 2022
    • Marc Zyngier's avatar
      Merge branch kvm-arm64/sysreg-cleanup-5.20 into kvmarm-master/next · ae98a4a9
      Marc Zyngier authored
      
      
      * kvm-arm64/sysreg-cleanup-5.20:
        : .
        : Long overdue cleanup of the sysreg userspace access,
        : with extra scrubbing on the vgic side of things.
        : From the cover letter:
        :
        : "Schspa Shi recently reported[1] that some of the vgic code interacting
        : with userspace was reading uninitialised stack memory, and although
        : that read wasn't used any further, it prompted me to revisit this part
        : of the code.
        :
        : Needless to say, this area of the kernel is pretty crufty, and shows a
        : bunch of issues in other parts of the KVM/arm64 infrastructure. This
        : series tries to remedy a bunch of them:
        :
        : - Sanitise the way we deal with sysregs from userspace: at the moment,
        :   each and every .set_user/.get_user callback has to implement its own
        :   userspace accesses (directly or indirectly). It'd be much better if
        :   that was centralised so that we can reason about it.
        :
        : - Enforce that all AArch64 sysregs are 64bit. Always. This was sort of
        :   implied by the code, but it took some effort to convince myself that
        :   this was actually the case.
        :
        : - Move the vgic-v3 sysreg userspace accessors to the userspace
        :   callbacks instead of hijacking the vcpu trap callback. This allows
        :   us to reuse the sysreg infrastructure.
        :
        : - Consolidate userspace accesses for both GICv2, GICv3 and common code
        :   as much as possible.
        :
        : - Cleanup a bunch of not-very-useful helpers, tidy up some of the code
        :   as we touch it.
        :
        : [1] https://lore.kernel.org/r/m2h740zz1i.fsf@gmail.com"
        : .
        KVM: arm64: Get rid or outdated comments
        KVM: arm64: Descope kvm_arm_sys_reg_{get,set}_reg()
        KVM: arm64: Get rid of find_reg_by_id()
        KVM: arm64: vgic: Tidy-up calls to vgic_{get,set}_common_attr()
        KVM: arm64: vgic: Consolidate userspace access for base address setting
        KVM: arm64: vgic-v2: Add helper for legacy dist/cpuif base address setting
        KVM: arm64: vgic: Use {get,put}_user() instead of copy_{from.to}_user
        KVM: arm64: vgic-v2: Consolidate userspace access for MMIO registers
        KVM: arm64: vgic-v3: Consolidate userspace access for MMIO registers
        KVM: arm64: vgic-v3: Use u32 to manage the line level from userspace
        KVM: arm64: vgic-v3: Convert userspace accessors over to FIELD_GET/FIELD_PREP
        KVM: arm64: vgic-v3: Make the userspace accessors use sysreg API
        KVM: arm64: vgic-v3: Push user access into vgic_v3_cpu_sysregs_uaccess()
        KVM: arm64: vgic-v3: Simplify vgic_v3_has_cpu_sysregs_attr()
        KVM: arm64: Get rid of reg_from/to_user()
        KVM: arm64: Consolidate sysreg userspace accesses
        KVM: arm64: Rely on index_to_param() for size checks on userspace access
        KVM: arm64: Introduce generic get_user/set_user helpers for system registers
        KVM: arm64: Reorder handling of invariant sysregs from userspace
        KVM: arm64: Add get_reg_by_id() as a sys_reg_desc retrieving helper
      
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      ae98a4a9
    • Marc Zyngier's avatar
      KVM: arm64: Get rid or outdated comments · 4274d427
      Marc Zyngier authored
      
      
      Once apon a time, the 32bit KVM/arm port was the reference, while
      the arm64 version was the new kid on the block, without a clear
      future... This was a long time ago.
      
      "The times, they are a-changing."
      
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      4274d427
    • Marc Zyngier's avatar
      KVM: arm64: Descope kvm_arm_sys_reg_{get,set}_reg() · c5332898
      Marc Zyngier authored
      
      
      Having kvm_arm_sys_reg_get_reg and co in kvm_host.h gives the
      impression that these functions are free to be called from
      anywhere.
      
      Not quite. They really are tied to out internal sysreg handling,
      and they would be better off in the sys_regs.h header, which is
      private. kvm_host.h could also get a bit of a diet, so let's
      just do that.
      
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      c5332898
    • Marc Zyngier's avatar
      KVM: arm64: Get rid of find_reg_by_id() · f6dddbb2
      Marc Zyngier authored
      
      
      This helper doesn't have a user anymore, let's get rid of it.
      
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      f6dddbb2
    • Marc Zyngier's avatar
      KVM: arm64: vgic: Tidy-up calls to vgic_{get,set}_common_attr() · 619064af
      Marc Zyngier authored
      
      
      The userspace accessors have an early call to vgic_{get,set}_common_attr()
      that makes the code hard to follow. Move it to the default: clause of
      the decoding switch statement, which results in a nice cleanup.
      
      This requires us to move the handling of the pending table into the
      common handling, even if it is strictly a GICv3 feature (it has the
      benefit of keeping the whole control group handling in the same
      function).
      
      Also cleanup vgic_v3_{get,set}_attr() while we're at it, deduplicating
      the calls to vgic_v3_attr_regs_access().
      
      Suggested-by: default avatarReiji Watanabe <reijiw@google.com>
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      619064af
    • Marc Zyngier's avatar
      KVM: arm64: vgic: Consolidate userspace access for base address setting · 4b85080f
      Marc Zyngier authored
      
      
      Align kvm_vgic_addr() with the rest of the code by moving the
      userspace accesses into it. kvm_vgic_addr() is also made static.
      
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      4b85080f
    • Marc Zyngier's avatar
      KVM: arm64: vgic-v2: Add helper for legacy dist/cpuif base address setting · 9f968c92
      Marc Zyngier authored
      
      
      We carry a legacy interface to set the base addresses for GICv2.
      As this is currently plumbed into the same handling code as
      the modern interface, it limits the evolution we can make there.
      
      Add a helper dedicated to this handling, with a view of maybe
      removing this in the future.
      
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      9f968c92
    • Marc Zyngier's avatar
      KVM: arm64: vgic: Use {get,put}_user() instead of copy_{from.to}_user · d7df6f28
      Marc Zyngier authored
      
      
      Tidy-up vgic_get_common_attr() and vgic_set_common_attr() to use
      {get,put}_user() instead of the more complex (and less type-safe)
      copy_{from,to}_user().
      
      Reviewed-by: default avatarReiji Watanabe <reijiw@google.com>
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      d7df6f28
    • Marc Zyngier's avatar
      KVM: arm64: vgic-v2: Consolidate userspace access for MMIO registers · 7e9f723c
      Marc Zyngier authored
      
      
      Align the GICv2 MMIO accesses from userspace with the way the GICv3
      code is now structured.
      
      Reviewed-by: default avatarReiji Watanabe <reijiw@google.com>
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      7e9f723c
    • Marc Zyngier's avatar
      KVM: arm64: vgic-v3: Consolidate userspace access for MMIO registers · e1246f3f
      Marc Zyngier authored
      
      
      For userspace accesses to GICv3 MMIO registers (and related data),
      vgic_v3_{get,set}_attr are littered with {get,put}_user() calls,
      making it hard to audit and reason about.
      
      Consolidate all userspace accesses in vgic_v3_attr_regs_access(),
      making the code far simpler to audit.
      
      Reviewed-by: default avatarReiji Watanabe <reijiw@google.com>
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      e1246f3f
    • Marc Zyngier's avatar
      KVM: arm64: vgic-v3: Use u32 to manage the line level from userspace · 38cf0bb7
      Marc Zyngier authored
      
      
      Despite the userspace ABI clearly defining the bits dealt with by
      KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO as a __u32, the kernel uses a u64.
      
      Use a u32 to match the userspace ABI, which will subsequently lead
      to some simplifications.
      
      Reviewed-by: default avatarReiji Watanabe <reijiw@google.com>
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      38cf0bb7
    • Marc Zyngier's avatar
      KVM: arm64: vgic-v3: Convert userspace accessors over to FIELD_GET/FIELD_PREP · 71c3c775
      Marc Zyngier authored
      
      
      The GICv3 userspace accessors are all about dealing with conversion
      between fields from architectural registers and internal representations.
      
      However, and owing to the age of this code, the accessors use
      a combination of shift/mask that is hard to read. It is nonetheless
      easy to make it better by using the FIELD_{GET,PREP} macros that solely
      rely on a mask.
      
      This results in somewhat nicer looking code, and is probably easier
      to maintain.
      
      Reviewed-by: default avatarReiji Watanabe <reijiw@google.com>
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      71c3c775
    • Marc Zyngier's avatar
      KVM: arm64: vgic-v3: Make the userspace accessors use sysreg API · cbcf14dd
      Marc Zyngier authored
      
      
      The vgic-v3 sysreg accessors have been ignored as the rest of the
      sysreg internal API was evolving, and are stuck with the .access
      method (which is normally reserved to the guest's own access)
      for the userspace accesses (which should use the .set/.get_user()
      methods).
      
      Catch up with the program and repaint all the accessors so that
      they fit into the normal userspace model, and plug the result into
      the helpers that have been introduced earlier.
      
      Reviewed-by: default avatarReiji Watanabe <reijiw@google.com>
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      cbcf14dd
    • Marc Zyngier's avatar
      KVM: arm64: vgic-v3: Push user access into vgic_v3_cpu_sysregs_uaccess() · db25081e
      Marc Zyngier authored
      
      
      In order to start making the vgic sysreg access from userspace
      similar to all the other sysregs, push the userspace memory
      access one level down into vgic_v3_cpu_sysregs_uaccess().
      
      The next step will be to rely on the sysreg infrastructure
      to perform this task.
      
      Reviewed-by: default avatarReiji Watanabe <reijiw@google.com>
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      db25081e
    • Marc Zyngier's avatar
      KVM: arm64: vgic-v3: Simplify vgic_v3_has_cpu_sysregs_attr() · b61fc085
      Marc Zyngier authored
      
      
      Finding out whether a sysreg exists has little to do with that
      register being accessed, so drop the is_write parameter.
      
      Also, the reg pointer is completely unused, and we're better off
      just passing the attr pointer to the function.
      
      This result in a small cleanup of the calling site, with a new
      helper converting the vGIC view of a sysreg into the canonical
      one (this is purely cosmetic, as the encoding is the same).
      
      Reviewed-by: default avatarReiji Watanabe <reijiw@google.com>
      Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
      b61fc085