1. 17 9月, 2015 1 次提交
    • M
      arm/arm64: KVM: Remove 'config KVM_ARM_MAX_VCPUS' · ef748917
      Ming Lei 提交于
      This patch removes config option of KVM_ARM_MAX_VCPUS,
      and like other ARCHs, just choose the maximum allowed
      value from hardware, and follows the reasons:
      
      1) from distribution view, the option has to be
      defined as the max allowed value because it need to
      meet all kinds of virtulization applications and
      need to support most of SoCs;
      
      2) using a bigger value doesn't introduce extra memory
      consumption, and the help text in Kconfig isn't accurate
      because kvm_vpu structure isn't allocated until request
      of creating VCPU is sent from QEMU;
      
      3) the main effect is that the field of vcpus[] in 'struct kvm'
      becomes a bit bigger(sizeof(void *) per vcpu) and need more cache
      lines to hold the structure, but 'struct kvm' is one generic struct,
      and it has worked well on other ARCHs already in this way. Also,
      the world switch frequecy is often low, for example, it is ~2000
      when running kernel building load in VM from APM xgene KVM host,
      so the effect is very small, and the difference can't be observed
      in my test at all.
      
      Cc: Dann Frazier <dann.frazier@canonical.com>
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Reviewed-by: NChristoffer Dall <christoffer.dall@linaro.org>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      ef748917
  2. 04 9月, 2015 2 次提交
  3. 12 8月, 2015 7 次提交
  4. 18 6月, 2015 1 次提交
  5. 17 6月, 2015 2 次提交
  6. 12 6月, 2015 1 次提交
  7. 10 6月, 2015 1 次提交
  8. 22 4月, 2015 2 次提交
    • A
      KVM: arm/arm64: check IRQ number on userland injection · fd1d0ddf
      Andre Przywara 提交于
      When userland injects a SPI via the KVM_IRQ_LINE ioctl we currently
      only check it against a fixed limit, which historically is set
      to 127. With the new dynamic IRQ allocation the effective limit may
      actually be smaller (64).
      So when now a malicious or buggy userland injects a SPI in that
      range, we spill over on our VGIC bitmaps and bytemaps memory.
      I could trigger a host kernel NULL pointer dereference with current
      mainline by injecting some bogus IRQ number from a hacked kvmtool:
      -----------------
      ....
      DEBUG: kvm_vgic_inject_irq(kvm, cpu=0, irq=114, level=1)
      DEBUG: vgic_update_irq_pending(kvm, cpu=0, irq=114, level=1)
      DEBUG: IRQ #114 still in the game, writing to bytemap now...
      Unable to handle kernel NULL pointer dereference at virtual address 00000000
      pgd = ffffffc07652e000
      [00000000] *pgd=00000000f658b003, *pud=00000000f658b003, *pmd=0000000000000000
      Internal error: Oops: 96000006 [#1] PREEMPT SMP
      Modules linked in:
      CPU: 1 PID: 1053 Comm: lkvm-msi-irqinj Not tainted 4.0.0-rc7+ #3027
      Hardware name: FVP Base (DT)
      task: ffffffc0774e9680 ti: ffffffc0765a8000 task.ti: ffffffc0765a8000
      PC is at kvm_vgic_inject_irq+0x234/0x310
      LR is at kvm_vgic_inject_irq+0x30c/0x310
      pc : [<ffffffc0000ae0a8>] lr : [<ffffffc0000ae180>] pstate: 80000145
      .....
      
      So this patch fixes this by checking the SPI number against the
      actual limit. Also we remove the former legacy hard limit of
      127 in the ioctl code.
      Signed-off-by: NAndre Przywara <andre.przywara@arm.com>
      Reviewed-by: NChristoffer Dall <christoffer.dall@linaro.org>
      CC: <stable@vger.kernel.org> # 4.0, 3.19, 3.18
      [maz: wrap KVM_ARM_IRQ_GIC_MAX with #ifndef __KERNEL__,
      as suggested by Christopher Covington]
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      fd1d0ddf
    • E
      KVM: arm: irqfd: fix value returned by kvm_irq_map_gsi · 0b3289eb
      Eric Auger 提交于
      irqfd/arm curently does not support routing. kvm_irq_map_gsi is
      supposed to return all the routing entries associated with the
      provided gsi and return the number of those entries. We should
      return 0 at this point.
      Signed-off-by: NEric Auger <eric.auger@linaro.org>
      Acked-by: NChristoffer Dall <christoffer.dall@linaro.org>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      0b3289eb
  9. 31 3月, 2015 3 次提交
  10. 27 3月, 2015 4 次提交
  11. 14 3月, 2015 4 次提交
  12. 13 3月, 2015 1 次提交
  13. 12 3月, 2015 2 次提交
  14. 11 3月, 2015 1 次提交
  15. 21 1月, 2015 8 次提交
    • A
      arm/arm64: KVM: force alignment of VGIC dist/CPU/redist addresses · 4fa96afd
      Andre Przywara 提交于
      Although the GIC architecture requires us to map the MMIO regions
      only at page aligned addresses, we currently do not enforce this from
      the kernel side.
      Restrict any vGICv2 regions to be 4K aligned and any GICv3 regions
      to be 64K aligned. Document this requirement.
      Signed-off-by: NAndre Przywara <andre.przywara@arm.com>
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      4fa96afd
    • A
      arm/arm64: KVM: allow userland to request a virtual GICv3 · ac3d3735
      Andre Przywara 提交于
      With all of the GICv3 code in place now we allow userland to ask the
      kernel for using a virtual GICv3 in the guest.
      Also we provide the necessary support for guests setting the memory
      addresses for the virtual distributor and redistributors.
      This requires some userland code to make use of that feature and
      explicitly ask for a virtual GICv3.
      Document that KVM_CREATE_IRQCHIP only works for GICv2, but is
      considered legacy and using KVM_CREATE_DEVICE is preferred.
      Signed-off-by: NAndre Przywara <andre.przywara@arm.com>
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      ac3d3735
    • A
      arm/arm64: KVM: enable kernel side of GICv3 emulation · b5d84ff6
      Andre Przywara 提交于
      With all the necessary GICv3 emulation code in place, we can now
      connect the code to the GICv3 backend in the kernel.
      The LR register handling is different depending on the emulated GIC
      model, so provide different implementations for each.
      Also allow non-v2-compatible GICv3 implementations (which don't
      provide MMIO regions for the virtual CPU interface in the DT), but
      restrict those hosts to support GICv3 guests only.
      If the device tree provides a GICv2 compatible GICV resource entry,
      but that one is faulty, just disable the GICv2 emulation and let the
      user use at least the GICv3 emulation for guests.
      To provide proper support for the legacy KVM_CREATE_IRQCHIP ioctl,
      note virtual GICv2 compatibility in struct vgic_params and use it
      on creating a VGICv2.
      Signed-off-by: NAndre Przywara <andre.przywara@arm.com>
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      b5d84ff6
    • A
      arm64: KVM: add SGI generation register emulation · 6d52f35a
      Andre Przywara 提交于
      While the generation of a (virtual) inter-processor interrupt (SGI)
      on a GICv2 works by writing to a MMIO register, GICv3 uses the system
      register ICC_SGI1R_EL1 to trigger them.
      Add a trap handler function that calls the new SGI register handler
      in the GICv3 code. As ICC_SRE_EL1.SRE at this point is still always 0,
      this will not trap yet, but will only be used later when all the data
      structures have been initialized properly.
      Signed-off-by: NAndre Przywara <andre.przywara@arm.com>
      Reviewed-by: NChristoffer Dall <christoffer.dall@linaro.org>
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      6d52f35a
    • A
      arm/arm64: KVM: add virtual GICv3 distributor emulation · a0675c25
      Andre Przywara 提交于
      With everything separated and prepared, we implement a model of a
      GICv3 distributor and redistributors by using the existing framework
      to provide handler functions for each register group.
      
      Currently we limit the emulation to a model enforcing a single
      security state, with SRE==1 (forcing system register access) and
      ARE==1 (allowing more than 8 VCPUs).
      
      We share some of the functions provided for GICv2 emulation, but take
      the different ways of addressing (v)CPUs into account.
      Save and restore is currently not implemented.
      
      Similar to the split-off of the GICv2 specific code, the new emulation
      code goes into a new file (vgic-v3-emul.c).
      Signed-off-by: NAndre Przywara <andre.przywara@arm.com>
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      a0675c25
    • A
      arm/arm64: KVM: add opaque private pointer to MMIO data · 9fedf146
      Andre Przywara 提交于
      For a GICv2 there is always only one (v)CPU involved: the one that
      does the access. On a GICv3 the access to a CPU redistributor is
      memory-mapped, but not banked, so the (v)CPU affected is determined by
      looking at the MMIO address region being accessed.
      To allow passing the affected CPU into the accessors later, extend
      struct kvm_exit_mmio to add an opaque private pointer parameter.
      The current GICv2 emulation just does not use it.
      Signed-off-by: NAndre Przywara <andre.przywara@arm.com>
      Acked-by: NChristoffer Dall <christoffer.dall@linaro.org>
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      9fedf146
    • A
      arm/arm64: KVM: split GICv2 specific emulation code from vgic.c · 1d916229
      Andre Przywara 提交于
      vgic.c is currently a mixture of generic vGIC emulation code and
      functions specific to emulating a GICv2. To ease the addition of
      GICv3, split off strictly v2 specific parts into a new file
      vgic-v2-emul.c.
      Signed-off-by: NAndre Przywara <andre.przywara@arm.com>
      Acked-by: NChristoffer Dall <christoffer.dall@linaro.org>
      
      -------
      As the diff isn't always obvious here (and to aid eventual rebases),
      here is a list of high-level changes done to the code:
      * added new file to respective arm/arm64 Makefiles
      * moved GICv2 specific functions to vgic-v2-emul.c:
        - handle_mmio_misc()
        - handle_mmio_set_enable_reg()
        - handle_mmio_clear_enable_reg()
        - handle_mmio_set_pending_reg()
        - handle_mmio_clear_pending_reg()
        - handle_mmio_priority_reg()
        - vgic_get_target_reg()
        - vgic_set_target_reg()
        - handle_mmio_target_reg()
        - handle_mmio_cfg_reg()
        - handle_mmio_sgi_reg()
        - vgic_v2_unqueue_sgi()
        - read_set_clear_sgi_pend_reg()
        - write_set_clear_sgi_pend_reg()
        - handle_mmio_sgi_set()
        - handle_mmio_sgi_clear()
        - vgic_v2_handle_mmio()
        - vgic_get_sgi_sources()
        - vgic_dispatch_sgi()
        - vgic_v2_queue_sgi()
        - vgic_v2_map_resources()
        - vgic_v2_init()
        - vgic_v2_add_sgi_source()
        - vgic_v2_init_model()
        - vgic_v2_init_emulation()
        - handle_cpu_mmio_misc()
        - handle_mmio_abpr()
        - handle_cpu_mmio_ident()
        - vgic_attr_regs_access()
        - vgic_create() (renamed to vgic_v2_create())
        - vgic_destroy() (renamed to vgic_v2_destroy())
        - vgic_has_attr() (renamed to vgic_v2_has_attr())
        - vgic_set_attr() (renamed to vgic_v2_set_attr())
        - vgic_get_attr() (renamed to vgic_v2_get_attr())
        - struct kvm_mmio_range vgic_dist_ranges[]
        - struct kvm_mmio_range vgic_cpu_ranges[]
        - struct kvm_device_ops kvm_arm_vgic_v2_ops {}
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      1d916229
    • A
      arm/arm64: KVM: add vgic.h header file · 83215812
      Andre Przywara 提交于
      vgic.c is currently a mixture of generic vGIC emulation code and
      functions specific to emulating a GICv2. To ease the addition of
      GICv3 later, we create new header file vgic.h, which holds constants
      and prototypes of commonly used functions.
      Rename some identifiers to avoid name space clutter.
      I removed the long-standing comment about using the kvm_io_bus API
      to tackle the GIC register ranges, as it wouldn't be a win for us
      anymore.
      Signed-off-by: NAndre Przywara <andre.przywara@arm.com>
      Acked-by: NChristoffer Dall <christoffer.dall@linaro.org>
      
      -------
      As the diff isn't always obvious here (and to aid eventual rebases),
      here is a list of high-level changes done to the code:
      * moved definitions and prototypes from vgic.c to vgic.h:
        - VGIC_ADDR_UNDEF
        - ACCESS_{READ,WRITE}_*
        - vgic_init()
        - vgic_update_state()
        - vgic_kick_vcpus()
        - vgic_get_vmcr()
        - vgic_set_vmcr()
        - struct mmio_range {} (renamed to struct kvm_mmio_range)
      * removed static keyword and exported prototype in vgic.h:
        - vgic_bitmap_get_reg()
        - vgic_bitmap_set_irq_val()
        - vgic_bitmap_get_shared_map()
        - vgic_bytemap_get_reg()
        - vgic_dist_irq_set_pending()
        - vgic_dist_irq_clear_pending()
        - vgic_cpu_irq_clear()
        - vgic_reg_access()
        - handle_mmio_raz_wi()
        - vgic_handle_enable_reg()
        - vgic_handle_set_pending_reg()
        - vgic_handle_clear_pending_reg()
        - vgic_handle_cfg_reg()
        - vgic_unqueue_irqs()
        - find_matching_range() (renamed to vgic_find_range)
        - vgic_handle_mmio_range()
        - vgic_update_state()
        - vgic_get_vmcr()
        - vgic_set_vmcr()
        - vgic_queue_irq()
        - vgic_kick_vcpus()
        - vgic_init()
        - vgic_v2_init_emulation()
        - vgic_has_attr_regs()
        - vgic_set_common_attr()
        - vgic_get_common_attr()
        - vgic_destroy()
        - vgic_create()
      * moved functions to vgic.h (static inline):
        - mmio_data_read()
        - mmio_data_write()
        - is_in_range()
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      83215812