1. 06 11月, 2017 2 次提交
  2. 08 6月, 2017 4 次提交
    • C
      KVM: arm/arm64: Disallow userspace control of in-kernel IRQ lines · cb3f0ad8
      Christoffer Dall 提交于
      When injecting an IRQ to the VGIC, you now have to present an owner
      token for that IRQ line to show that you are the owner of that line.
      
      IRQ lines driven from userspace or via an irqfd do not have an owner and
      will simply pass a NULL pointer.
      
      Also get rid of the unused kvm_vgic_inject_mapped_irq prototype.
      Signed-off-by: NChristoffer Dall <cdall@linaro.org>
      Acked-by: NMarc Zyngier <marc.zyngier@arm.com>
      cb3f0ad8
    • C
      KVM: arm/arm64: Check if irq lines to the GIC are already used · abcb851d
      Christoffer Dall 提交于
      We check if other in-kernel devices have already been connected to the
      GIC for a particular interrupt line when possible.
      
      For the PMU, we can do this whenever setting the PMU interrupt number
      from userspace.
      
      For the timers, we have to wait until we try to enable the timer,
      because we have a concept of default IRQ numbers that userspace
      shouldn't have to work around in the initialization phase.
      Signed-off-by: NChristoffer Dall <cdall@linaro.org>
      Reviewed-by: NMarc Zyngier <marc.zyngier@arm.com>
      abcb851d
    • 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
    • C
      KVM: arm/arm64: Move timer IRQ default init to arch_timer.c · 85e69ad7
      Christoffer Dall 提交于
      We currently initialize the arch timer IRQ numbers from the reset code,
      presumably because we once intended to model multiple CPU or SoC types
      from within the kernel and have hard-coded reset values in the reset
      code.
      
      As we are moving towards userspace being in charge of more fine-grained
      CPU emulation and stitching together the pieces needed to emulate a
      particular type of CPU, we should no longer have a tight coupling
      between resetting a VCPU and setting IRQ numbers.
      
      Therefore, move the logic to define and use the default IRQ numbers to
      the timer code and set the IRQ number immediately when creating the
      VCPU.
      Signed-off-by: NChristoffer Dall <cdall@linaro.org>
      Reviewed-by: NMarc Zyngier <marc.zyngier@arm.com>
      85e69ad7
  3. 04 6月, 2017 1 次提交
  4. 09 4月, 2017 3 次提交
    • C
      KVM: arm/arm64: Report PMU overflow interrupts to userspace irqchip · 3dbbdf78
      Christoffer Dall 提交于
      When not using an in-kernel VGIC, but instead emulating an interrupt
      controller in userspace, we should report the PMU overflow status to
      that userspace interrupt controller using the KVM_CAP_ARM_USER_IRQ
      feature.
      Reviewed-by: NAlexander Graf <agraf@suse.de>
      Reviewed-by: NMarc Zyngier <marc.zyngier@arm.com>
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      3dbbdf78
    • A
      KVM: arm/arm64: Support arch timers with a userspace gic · d9e13977
      Alexander Graf 提交于
      If you're running with a userspace gic or other interrupt controller
      (that is no vgic in the kernel), then you have so far not been able to
      use the architected timers, because the output of the architected
      timers, which are driven inside the kernel, was a kernel-only construct
      between the arch timer code and the vgic.
      
      This patch implements the new KVM_CAP_ARM_USER_IRQ feature, where we use a
      side channel on the kvm_run structure, run->s.regs.device_irq_level, to
      always notify userspace of the timer output levels when using a userspace
      irqchip.
      
      This works by ensuring that before we enter the guest, if the timer
      output level has changed compared to what we last told userspace, we
      don't enter the guest, but instead return to userspace to notify it of
      the new level.  If we are exiting, because of an MMIO for example, and
      the level changed at the same time, the value is also updated and
      userspace can sample the line as it needs.  This is nicely achieved
      simply always updating the timer_irq_level field after the main run
      loop.
      
      Note that the kvm_timer_update_irq trace event is changed to show the
      host IRQ number for the timer instead of the guest IRQ number, because
      the kernel no longer know which IRQ userspace wires up the timer signal
      to.
      
      Also note that this patch implements all required functionality but does
      not yet advertise the capability.
      Reviewed-by: NAlexander Graf <agraf@suse.de>
      Reviewed-by: NMarc Zyngier <marc.zyngier@arm.com>
      Signed-off-by: NAlexander Graf <agraf@suse.de>
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      d9e13977
    • C
      KVM: arm/arm64: Cleanup the arch timer code's irqchip checking · b22e7df2
      Christoffer Dall 提交于
      Currently we check if we have an in-kernel irqchip and if the vgic was
      properly implemented several places in the arch timer code.  But, we
      already predicate our enablement of the arm timers on having a valid
      and initialized gic, so we can simply check if the timers are enabled or
      not.
      
      This also gets rid of the ugly "error that's not an error but used to
      signal that the timer shouldn't poke the gic" construct we have.
      Reviewed-by: NAlexander Graf <agraf@suse.de>
      Reviewed-by: NMarc Zyngier <marc.zyngier@arm.com>
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      b22e7df2
  5. 08 2月, 2017 8 次提交
  6. 01 2月, 2017 1 次提交
  7. 13 1月, 2017 2 次提交
    • J
      KVM: arm64: Access CNTHCTL_EL2 bit fields correctly on VHE systems · 488f94d7
      Jintack Lim 提交于
      Current KVM world switch code is unintentionally setting wrong bits to
      CNTHCTL_EL2 when E2H == 1, which may allow guest OS to access physical
      timer.  Bit positions of CNTHCTL_EL2 are changing depending on
      HCR_EL2.E2H bit.  EL1PCEN and EL1PCTEN are 1st and 0th bits when E2H is
      not set, but they are 11th and 10th bits respectively when E2H is set.
      
      In fact, on VHE we only need to set those bits once, not for every world
      switch. This is because the host kernel runs in EL2 with HCR_EL2.TGE ==
      1, which makes those bits have no effect for the host kernel execution.
      So we just set those bits once for guests, and that's it.
      Signed-off-by: NJintack Lim <jintack@cs.columbia.edu>
      Reviewed-by: NMarc Zyngier <marc.zyngier@arm.com>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      488f94d7
    • C
      KVM: arm/arm64: Fix occasional warning from the timer work function · 63e41226
      Christoffer Dall 提交于
      When a VCPU blocks (WFI) and has programmed the vtimer, we program a
      soft timer to expire in the future to wake up the vcpu thread when
      appropriate.  Because such as wake up involves a vcpu kick, and the
      timer expire function can get called from interrupt context, and the
      kick may sleep, we have to schedule the kick in the work function.
      
      The work function currently has a warning that gets raised if it turns
      out that the timer shouldn't fire when it's run, which was added because
      the idea was that in that case the work should never have been cancelled.
      
      However, it turns out that this whole thing is racy and we can get
      spurious warnings.  The problem is that we clear the armed flag in the
      work function, which may run in parallel with the
      kvm_timer_unschedule->timer_disarm() call.  This results in a possible
      situation where the timer_disarm() call does not call
      cancel_work_sync(), which effectively synchronizes the completion of the
      work function with running the VCPU.  As a result, the VCPU thread
      proceeds before the work function completees, causing changes to the
      timer state such that kvm_timer_should_fire(vcpu) returns false in the
      work function.
      
      All we do in the work function is to kick the VCPU, and an occasional
      rare extra kick never harmed anyone.  Since the race above is extremely
      rare, we don't bother checking if the race happens but simply remove the
      check and the clearing of the armed flag from the work function.
      Reported-by: NMatthias Brugger <mbrugger@suse.com>
      Reviewed-by: NMarc Zyngier <marc.zyngier@arm.com>
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      63e41226
  8. 25 12月, 2016 2 次提交
  9. 09 12月, 2016 1 次提交
  10. 15 11月, 2016 1 次提交
  11. 08 9月, 2016 2 次提交
    • P
      KVM: ARM: cleanup kvm_timer_hyp_init · 5d947a14
      Paolo Bonzini 提交于
      Remove two unnecessary labels now that kvm_timer_hyp_init is not
      creating its own workqueue anymore.
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      5d947a14
    • B
      KVM: Remove deprecated create_singlethread_workqueue · 3706feac
      Bhaktipriya Shridhar 提交于
      The workqueue "irqfd_cleanup_wq" queues a single work item
      &irqfd->shutdown and hence doesn't require ordering. It is a host-wide
      workqueue for issuing deferred shutdown requests aggregated from all
      vm* instances. It is not being used on a memory reclaim path.
      Hence, it has been converted to use system_wq.
      The work item has been flushed in kvm_irqfd_release().
      
      The workqueue "wqueue" queues a single work item &timer->expired
      and hence doesn't require ordering. Also, it is not being used on
      a memory reclaim path. Hence, it has been converted to use system_wq.
      
      System workqueues have been able to handle high level of concurrency
      for a long time now and hence it's not required to have a singlethreaded
      workqueue just to gain concurrency. Unlike a dedicated per-cpu workqueue
      created with create_singlethread_workqueue(), system_wq allows multiple
      work items to overlap executions even on the same CPU; however, a
      per-cpu workqueue doesn't have any CPU locality or global ordering
      guarantee unless the target CPU is explicitly specified and thus the
      increase of local concurrency shouldn't make any difference.
      Signed-off-by: NBhaktipriya Shridhar <bhaktipriya96@gmail.com>
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      3706feac
  12. 17 8月, 2016 1 次提交
  13. 15 7月, 2016 1 次提交
  14. 20 5月, 2016 7 次提交
  15. 03 5月, 2016 1 次提交
  16. 06 4月, 2016 1 次提交
    • M
      KVM: arm/arm64: Handle forward time correction gracefully · 1c5631c7
      Marc Zyngier 提交于
      On a host that runs NTP, corrections can have a direct impact on
      the background timer that we program on the behalf of a vcpu.
      
      In particular, NTP performing a forward correction will result in
      a timer expiring sooner than expected from a guest point of view.
      Not a big deal, we kick the vcpu anyway.
      
      But on wake-up, the vcpu thread is going to perform a check to
      find out whether or not it should block. And at that point, the
      timer check is going to say "timer has not expired yet, go back
      to sleep". This results in the timer event being lost forever.
      
      There are multiple ways to handle this. One would be record that
      the timer has expired and let kvm_cpu_has_pending_timer return
      true in that case, but that would be fairly invasive. Another is
      to check for the "short sleep" condition in the hrtimer callback,
      and restart the timer for the remaining time when the condition
      is detected.
      
      This patch implements the latter, with a bit of refactoring in
      order to avoid too much code duplication.
      
      Cc: <stable@vger.kernel.org>
      Reported-by: NAlexander Graf <agraf@suse.de>
      Reviewed-by: NAlexander Graf <agraf@suse.de>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      Signed-off-by: NChristoffer Dall <christoffer.dall@linaro.org>
      1c5631c7
  17. 03 3月, 2016 1 次提交
  18. 01 3月, 2016 1 次提交
    • M
      KVM: arm/arm64: timer: Add active state caching · 9b4a3004
      Marc Zyngier 提交于
      Programming the active state in the (re)distributor can be an
      expensive operation so it makes some sense to try and reduce
      the number of accesses as much as possible. So far, we
      program the active state on each VM entry, but there is some
      opportunity to do less.
      
      An obvious solution is to cache the active state in memory,
      and only program it in the HW when conditions change. But
      because the HW can also change things under our feet (the active
      state can transition from 1 to 0 when the guest does an EOI),
      some precautions have to be taken, which amount to only caching
      an "inactive" state, and always programing it otherwise.
      
      With this in place, we observe a reduction of around 700 cycles
      on a 2GHz GICv2 platform for a NULL hypercall.
      Reviewed-by: NChristoffer Dall <christoffer.dall@linaro.org>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      9b4a3004