1. 06 11月, 2017 9 次提交
    • C
      KVM: arm/arm64: Avoid timer save/restore in vcpu entry/exit · b103cc3f
      Christoffer Dall 提交于
      We don't need to save and restore the hardware timer state and examine
      if it generates interrupts on on every entry/exit to the guest.  The
      timer hardware is perfectly capable of telling us when it has expired
      by signaling interrupts.
      
      When taking a vtimer interrupt in the host, we don't want to mess with
      the timer configuration, we just want to forward the physical interrupt
      to the guest as a virtual interrupt.  We can use the split priority drop
      and deactivate feature of the GIC to do this, which leaves an EOI'ed
      interrupt active on the physical distributor, making sure we don't keep
      taking timer interrupts which would prevent the guest from running.  We
      can then forward the physical interrupt to the VM using the HW bit in
      the LR of the GIC, like we do already, which lets the guest directly
      deactivate both the physical and virtual timer simultaneously, allowing
      the timer hardware to exit the VM and generate a new physical interrupt
      when the timer output is again asserted later on.
      
      We do need to capture this state when migrating VCPUs between physical
      CPUs, however, which we use the vcpu put/load functions for, which are
      called through preempt notifiers whenever the thread is scheduled away
      from the CPU or called directly if we return from the ioctl to
      userspace.
      
      One caveat is that we have to save and restore the timer state in both
      kvm_timer_vcpu_[put/load] and kvm_timer_[schedule/unschedule], because
      we can have the following flows:
      
        1. kvm_vcpu_block
        2. kvm_timer_schedule
        3. schedule
        4. kvm_timer_vcpu_put (preempt notifier)
        5. schedule (vcpu thread gets scheduled back)
        6. kvm_timer_vcpu_load (preempt notifier)
        7. kvm_timer_unschedule
      
      And a version where we don't actually call schedule:
      
        1. kvm_vcpu_block
        2. kvm_timer_schedule
        7. kvm_timer_unschedule
      
      Since kvm_timer_[schedule/unschedule] may not be followed by put/load,
      but put/load also may be called independently, we call the timer
      save/restore functions from both paths.  Since they rely on the loaded
      flag to never save/restore when unnecessary, this doesn't cause any
      harm, and we ensure that all invokations of either set of functions work
      as intended.
      
      An added benefit beyond not having to read and write the timer sysregs
      on every entry and exit is that we no longer have to actively write the
      active state to the physical distributor, because we configured the
      irq for the vtimer to only get a priority drop when handling the
      interrupt in the GIC driver (we called irq_set_vcpu_affinity()), and
      the interrupt stays active after firing on the host.
      Reviewed-by: NMarc Zyngier <marc.zyngier@arm.com>
      Signed-off-by: NChristoffer Dall <cdall@linaro.org>
      b103cc3f
    • C
      KVM: arm/arm64: Set VCPU affinity for virt timer irq · 40f4cba9
      Christoffer Dall 提交于
      As we are about to take physical interrupts for the virtual timer on the
      host but want to leave those active while running the VM (and let the VM
      deactivate them), we need to set the vtimer PPI affinity accordingly.
      Signed-off-by: NChristoffer Dall <cdall@linaro.org>
      Reviewed-by: NMarc Zyngier <marc.zyngier@arm.com>
      40f4cba9
    • C
      KVM: arm/arm64: Move timer save/restore out of the hyp code · 688c50aa
      Christoffer Dall 提交于
      As we are about to be lazy with saving and restoring the timer
      registers, we prepare by moving all possible timer configuration logic
      out of the hyp code.  All virtual timer registers can be programmed from
      EL1 and since the arch timer is always a level triggered interrupt we
      can safely do this with interrupts disabled in the host kernel on the
      way to the guest without taking vtimer interrupts in the host kernel
      (yet).
      
      The downside is that the cntvoff register can only be programmed from
      hyp mode, so we jump into hyp mode and back to program it.  This is also
      safe, because the host kernel doesn't use the virtual timer in the KVM
      code.  It may add a little performance performance penalty, but only
      until following commits where we move this operation to vcpu load/put.
      Signed-off-by: NChristoffer Dall <cdall@linaro.org>
      Reviewed-by: NMarc Zyngier <marc.zyngier@arm.com>
      688c50aa
    • C
      KVM: arm/arm64: Use separate timer for phys timer emulation · f2a2129e
      Christoffer Dall 提交于
      We were using the same hrtimer for emulating the physical timer and for
      making sure a blocking VCPU thread would be eventually woken up.  That
      worked fine in the previous arch timer design, but as we are about to
      actually use the soft timer expire function for the physical timer
      emulation, change the logic to use a dedicated hrtimer.
      
      This has the added benefit of not having to cancel any work in the sync
      path, which in turn allows us to run the flush and sync with IRQs
      disabled.
      
      Note that the hrtimer used to program the host kernel's timer to
      generate an exit from the guest when the emulated physical timer fires
      never has to inject any work, and to share the soft_timer_cancel()
      function with the bg_timer, we change the function to only cancel any
      pending work if the pointer to the work struct is not null.
      Acked-by: NMarc Zyngier <marc.zyngier@arm.com>
      Signed-off-by: NChristoffer Dall <cdall@linaro.org>
      f2a2129e
    • C
      KVM: arm/arm64: Move timer/vgic flush/sync under disabled irq · ee9bb9a1
      Christoffer Dall 提交于
      As we are about to play tricks with the timer to be more lazy in saving
      and restoring state, we need to move the timer sync and flush functions
      under a disabled irq section and since we have to flush the vgic state
      after the timer and PMU state, we do the whole flush/sync sequence with
      disabled irqs.
      
      The only downside is a slightly longer delay before being able to
      process hardware interrupts and run softirqs.
      Signed-off-by: NChristoffer Dall <cdall@linaro.org>
      Reviewed-by: NMarc Zyngier <marc.zyngier@arm.com>
      ee9bb9a1
    • C
      KVM: arm/arm64: Rename soft timer to bg_timer · 14d61fa9
      Christoffer Dall 提交于
      As we are about to introduce a separate hrtimer for the physical timer,
      call this timer bg_timer, because we refer to this timer as the
      background timer in the code and comments elsewhere.
      Signed-off-by: NChristoffer Dall <cdall@linaro.org>
      Acked-by: NMarc Zyngier <marc.zyngier@arm.com>
      14d61fa9
    • C
      KVM: arm/arm64: Make timer_arm and timer_disarm helpers more generic · 8409a06f
      Christoffer Dall 提交于
      We are about to add an additional soft timer to the arch timer state for
      a VCPU and would like to be able to reuse the functions to program and
      cancel a timer, so we make them slightly more generic and rename to make
      it more clear that these functions work on soft timers and not the
      hardware resource that this code is managing.
      
      The armed flag on the timer state is only used to assert a condition,
      and we don't rely on this assertion in any meaningful way, so we can
      simply get rid of this flack and slightly reduce complexity.
      Acked-by: NMarc Zyngier <marc.zyngier@arm.com>
      Signed-off-by: NChristoffer Dall <cdall@linaro.org>
      8409a06f
    • C
      KVM: arm/arm64: Support calling vgic_update_irq_pending from irq context · 006df0f3
      Christoffer Dall 提交于
      We are about to optimize our timer handling logic which involves
      injecting irqs to the vgic directly from the irq handler.
      
      Unfortunately, the injection path can take any AP list lock and irq lock
      and we must therefore make sure to use spin_lock_irqsave where ever
      interrupts are enabled and we are taking any of those locks, to avoid
      deadlocking between process context and the ISR.
      
      This changes a lot of the VGIC code, but the good news are that the
      changes are mostly mechanical.
      Acked-by: NMarc Zyngier <marc,zyngier@arm.com>
      Signed-off-by: NChristoffer Dall <cdall@linaro.org>
      006df0f3
    • C
      KVM: arm/arm64: Guard kvm_vgic_map_is_active against !vgic_initialized · f39d16cb
      Christoffer Dall 提交于
      If the vgic is not initialized, don't try to grab its spinlocks or
      traverse its data structures.
      
      This is important because we soon have to start considering the active
      state of a virtual interrupts when doing vcpu_load, which may happen
      early on before the vgic is initialized.
      Signed-off-by: NChristoffer Dall <cdall@linaro.org>
      Acked-by: NMarc Zyngier <marc.zyngier@arm.com>
      f39d16cb
  2. 19 9月, 2017 1 次提交
  3. 15 9月, 2017 3 次提交
  4. 13 9月, 2017 1 次提交
    • C
      KVM: fix rcu warning on VM_CREATE errors · 021086e3
      Christian Borntraeger 提交于
      commit 3898da94 ("KVM: avoid using rcu_dereference_protected") can
      trigger the following lockdep/rcu splat if the VM_CREATE ioctl fails,
      for example if kvm_arch_init_vm fails:
      
      WARNING: suspicious RCU usage
      4.13.0+ #105 Not tainted
      -----------------------------
      ./include/linux/kvm_host.h:481 suspicious rcu_dereference_check() usage!
      
      other info that might help us debug this:
      
      rcu_scheduler_active = 2, debug_locks = 1
      no locks held by qemu-system-s39/79.
      stack backtrace:
      CPU: 0 PID: 79 Comm: qemu-system-s39 Not tainted 4.13.0+ #105
      Hardware name: IBM 2964 NC9 704 (KVM/Linux)
      Call Trace:
      ([<00000000001140b2>] show_stack+0xea/0xf0)
       [<00000000008a68a4>] dump_stack+0x94/0xd8
       [<0000000000134c12>] kvm_dev_ioctl+0x372/0x7a0
       [<000000000038f940>] do_vfs_ioctl+0xa8/0x6c8
       [<0000000000390004>] SyS_ioctl+0xa4/0xb8
       [<00000000008c7a8c>] system_call+0xc4/0x27c
      no locks held by qemu-system-s39/79.
      
      We have to reset the just created users_count back to 0 to
      tell the check to not trigger.
      Reported-by: NStefan Haberland <sth@linux.vnet.ibm.com>
      Signed-off-by: NChristian Borntraeger <borntraeger@de.ibm.com>
      Fixes: 3898da94 ("KVM: avoid using rcu_dereference_protected")
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Reviewed-by: NDavid Hildenbrand <david@redhat.com>
      Signed-off-by: NRadim Krčmář <rkrcmar@redhat.com>
      021086e3
  5. 05 9月, 2017 5 次提交
  6. 01 9月, 2017 1 次提交
  7. 16 8月, 2017 1 次提交
    • A
      kvm: avoid uninitialized-variable warnings · 076b925d
      Arnd Bergmann 提交于
      When PAGE_OFFSET is not a compile-time constant, we run into
      warnings from the use of kvm_is_error_hva() that the compiler
      cannot optimize out:
      
      arch/arm/kvm/../../../virt/kvm/kvm_main.c: In function '__kvm_gfn_to_hva_cache_init':
      arch/arm/kvm/../../../virt/kvm/kvm_main.c:1978:14: error: 'nr_pages_avail' may be used uninitialized in this function [-Werror=maybe-uninitialized]
      arch/arm/kvm/../../../virt/kvm/kvm_main.c: In function 'gfn_to_page_many_atomic':
      arch/arm/kvm/../../../virt/kvm/kvm_main.c:1660:5: error: 'entry' may be used uninitialized in this function [-Werror=maybe-uninitialized]
      
      This adds fake initializations to the two instances I ran into.
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Signed-off-by: NRadim Krčmář <rkrcmar@redhat.com>
      076b925d
  8. 08 8月, 2017 2 次提交
  9. 03 8月, 2017 2 次提交
  10. 27 7月, 2017 1 次提交
  11. 25 7月, 2017 3 次提交
  12. 13 7月, 2017 1 次提交
    • C
      KVM: trigger uevents when creating or destroying a VM · 286de8f6
      Claudio Imbrenda 提交于
      This patch adds a few lines to the KVM common code to fire a
      KOBJ_CHANGE uevent whenever a KVM VM is created or destroyed. The event
      carries five environment variables:
      
      CREATED indicates how many times a new VM has been created. It is
      	useful for example to trigger specific actions when the first
      	VM is started
      COUNT indicates how many VMs are currently active. This can be used for
      	logging or monitoring purposes
      PID has the pid of the KVM process that has been started or stopped.
      	This can be used to perform process-specific tuning.
      STATS_PATH contains the path in debugfs to the directory with all the
      	runtime statistics for this VM. This is useful for performance
      	monitoring and profiling.
      EVENT described the type of event, its value can be either "create" or
      	"destroy"
      
      Specific udev rules can be then set up in userspace to deal with the
      creation or destruction of VMs as needed.
      Signed-off-by: NClaudio Imbrenda <imbrenda@linux.vnet.ibm.com>
      Signed-off-by: NRadim Krčmář <rkrcmar@redhat.com>
      286de8f6
  13. 10 7月, 2017 1 次提交
  14. 07 7月, 2017 4 次提交
  15. 29 6月, 2017 2 次提交
  16. 27 6月, 2017 2 次提交
  17. 23 6月, 2017 1 次提交