08 Feb, 2016

1 commit

  • Commit 4b4b4512da2a ("arm/arm64: KVM: Rework the arch timer to use
    level-triggered semantics") brought the virtual architected timer
    closer to the VGIC. There is one occasion were we don't properly
    check for the VGIC actually having been initialized before, but
    instead go on to check the active state of some IRQ number.
    If userland hasn't instantiated a virtual GIC, we end up with a
    kernel NULL pointer dereference:
    =========
    Unable to handle kernel NULL pointer dereference at virtual address 00000000
    pgd = ffffffc9745c5000
    [00000000] *pgd=00000009f631e003, *pud=00000009f631e003, *pmd=0000000000000000
    Internal error: Oops: 96000006 [#2] PREEMPT SMP
    Modules linked in:
    CPU: 0 PID: 2144 Comm: kvm_simplest-ar Tainted: G D 4.5.0-rc2+ #1300
    Hardware name: ARM Juno development board (r1) (DT)
    task: ffffffc976da8000 ti: ffffffc976e28000 task.ti: ffffffc976e28000
    PC is at vgic_bitmap_get_irq_val+0x78/0x90
    LR is at kvm_vgic_map_is_active+0xac/0xc8
    pc : [] lr : [] pstate: 20000145
    ....
    =========

    Fix this by bailing out early of kvm_timer_flush_hwstate() if we don't
    have a VGIC at all.

    Reported-by: Cosmin Gorgovan
    Acked-by: Marc Zyngier
    Signed-off-by: Andre Przywara
    Signed-off-by: Marc Zyngier
    Cc: # 4.4.x

    Andre Przywara
     

16 Jan, 2016

1 commit

  • To date, we have implemented two I/O usage models for persistent memory,
    PMEM (a persistent "ram disk") and DAX (mmap persistent memory into
    userspace). This series adds a third, DAX-GUP, that allows DAX mappings
    to be the target of direct-i/o. It allows userspace to coordinate
    DMA/RDMA from/to persistent memory.

    The implementation leverages the ZONE_DEVICE mm-zone that went into
    4.3-rc1 (also discussed at kernel summit) to flag pages that are owned
    and dynamically mapped by a device driver. The pmem driver, after
    mapping a persistent memory range into the system memmap via
    devm_memremap_pages(), arranges for DAX to distinguish pfn-only versus
    page-backed pmem-pfns via flags in the new pfn_t type.

    The DAX code, upon seeing a PFN_DEV+PFN_MAP flagged pfn, flags the
    resulting pte(s) inserted into the process page tables with a new
    _PAGE_DEVMAP flag. Later, when get_user_pages() is walking ptes it keys
    off _PAGE_DEVMAP to pin the device hosting the page range active.
    Finally, get_page() and put_page() are modified to take references
    against the device driver established page mapping.

    Finally, this need for "struct page" for persistent memory requires
    memory capacity to store the memmap array. Given the memmap array for a
    large pool of persistent may exhaust available DRAM introduce a
    mechanism to allocate the memmap from persistent memory. The new
    "struct vmem_altmap *" parameter to devm_memremap_pages() enables
    arch_add_memory() to use reserved pmem capacity rather than the page
    allocator.

    This patch (of 18):

    The core has developed a need for a "pfn_t" type [1]. Move the existing
    pfn_t in KVM to kvm_pfn_t [2].

    [1]: https://lists.01.org/pipermail/linux-nvdimm/2015-September/002199.html
    [2]: https://lists.01.org/pipermail/linux-nvdimm/2015-September/002218.html

    Signed-off-by: Dan Williams
    Acked-by: Christoffer Dall
    Cc: Paolo Bonzini
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Dan Williams
     

13 Jan, 2016

1 commit

  • Pull KVM updates from Paolo Bonzini:
    "PPC changes will come next week.

    - s390: Support for runtime instrumentation within guests, support of
    248 VCPUs.

    - ARM: rewrite of the arm64 world switch in C, support for 16-bit VM
    identifiers. Performance counter virtualization missed the boat.

    - x86: Support for more Hyper-V features (synthetic interrupt
    controller), MMU cleanups"

    * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (115 commits)
    kvm: x86: Fix vmwrite to SECONDARY_VM_EXEC_CONTROL
    kvm/x86: Hyper-V SynIC timers tracepoints
    kvm/x86: Hyper-V SynIC tracepoints
    kvm/x86: Update SynIC timers on guest entry only
    kvm/x86: Skip SynIC vector check for QEMU side
    kvm/x86: Hyper-V fix SynIC timer disabling condition
    kvm/x86: Reorg stimer_expiration() to better control timer restart
    kvm/x86: Hyper-V unify stimer_start() and stimer_restart()
    kvm/x86: Drop stimer_stop() function
    kvm/x86: Hyper-V timers fix incorrect logical operation
    KVM: move architecture-dependent requests to arch/
    KVM: renumber vcpu->request bits
    KVM: document which architecture uses each request bit
    KVM: Remove unused KVM_REQ_KICK to save a bit in vcpu->requests
    kvm: x86: Check kvm_write_guest return value in kvm_write_wall_clock
    KVM: s390: implement the RI support of guest
    kvm/s390: drop unpaired smp_mb
    kvm: x86: fix comment about {mmu,nested_mmu}.gva_to_gpa
    KVM: x86: MMU: Use clear_page() instead of init_shadow_page_table()
    arm/arm64: KVM: Detect vGIC presence at runtime
    ...

    Linus Torvalds
     

09 Jan, 2016

1 commit


07 Jan, 2016

1 commit


14 Dec, 2015

3 commits


12 Dec, 2015

1 commit

  • External inputs to the vgic from time to time need to poke into the
    state of a virtual interrupt, the prime example is the architected timer
    code.

    Since the IRQ's active state can be represented in two places; the LR or
    the distributor, we first loop over the LRs but if not active in the LRs
    we just return if *any* IRQ is active on the VCPU in question.

    This is of course bogus, as we should check if the specific IRQ in
    quesiton is active on the distributor instead.

    Reported-by: Eric Auger
    Acked-by: Marc Zyngier
    Signed-off-by: Christoffer Dall
    Signed-off-by: Marc Zyngier

    Christoffer Dall
     

30 Nov, 2015

2 commits

  • KVM creates debugfs files to export VM statistics to userland. To be
    able to remove them on kvm exit it tracks the files' dentries.

    Since their parent directory is also tracked and since each parent
    direntry knows its children we can easily remove them by using
    debugfs_remove_recursive(kvm_debugfs_dir). Therefore we don't
    need the extra tracking in the kvm_stats_debugfs_item anymore.

    Signed-off-by: Janosch Frank
    Reviewed-By: Sascha Silbe
    Acked-by: Christian Borntraeger
    Signed-off-by: Christian Borntraeger

    Janosch Frank
     
  • Let's reuse the new common function for VPCU lookup by id.

    Reviewed-by: Christian Borntraeger
    Reviewed-by: Dominik Dingel
    Signed-off-by: David Hildenbrand
    Signed-off-by: Christian Borntraeger
    [split out the new function into a separate patch]

    David Hildenbrand
     

26 Nov, 2015

3 commits

  • This patch makes kvm_is_visible_gfn return bool due to this particular
    function only using either one or zero as its return value.

    No functional change.

    Signed-off-by: Yaowei Bai
    Signed-off-by: Paolo Bonzini

    Yaowei Bai
     
  • The kmem_cache_destroy() function tests whether its argument is NULL
    and then returns immediately. Thus the test around the call is not needed.

    This issue was detected by using the Coccinelle software.

    Signed-off-by: Markus Elfring
    Signed-off-by: Paolo Bonzini

    Markus Elfring
     
  • Actually kvm_arch_irq_routing_update() should be
    kvm_arch_post_irq_routing_update() as it's called at the end
    of irq routing update.

    This renaming frees kvm_arch_irq_routing_update function name.
    kvm_arch_irq_routing_update() weak function which will be used
    to update mappings for arch-specific irq routing entries
    (in particular, the upcoming Hyper-V synthetic interrupts).

    Signed-off-by: Andrey Smetanin
    Reviewed-by: Roman Kagan
    Signed-off-by: Denis V. Lunev
    CC: Gleb Natapov
    CC: Paolo Bonzini
    CC: Roman Kagan
    CC: Denis V. Lunev
    CC: qemu-devel@nongnu.org
    Signed-off-by: Paolo Bonzini

    Andrey Smetanin
     

25 Nov, 2015

2 commits

  • We were probing the physial distributor state for the active state of a
    HW virtual IRQ, because we had seen evidence that the LR state was not
    cleared when the guest deactivated a virtual interrupted.

    However, this issue turned out to be a software bug in the GIC, which
    was solved by: 84aab5e68c2a5e1e18d81ae8308c3ce25d501b29
    (KVM: arm/arm64: arch_timer: Preserve physical dist. active
    state on LR.active, 2015-11-24)

    Therefore, get rid of the complexities and just look at the LR.

    Reviewed-by: Marc Zyngier
    Signed-off-by: Christoffer Dall

    Christoffer Dall
     
  • We were incorrectly removing the active state from the physical
    distributor on the timer interrupt when the timer output level was
    deasserted. We shouldn't be doing this without considering the virtual
    interrupt's active state, because the architecture requires that when an
    LR has the HW bit set and the pending or active bits set, then the
    physical interrupt must also have the corresponding bits set.

    This addresses an issue where we have been observing an inconsistency
    between the LR state and the physical distributor state where the LR
    state was active and the physical distributor was not active, which
    shouldn't happen.

    Reviewed-by: Marc Zyngier
    Signed-off-by: Christoffer Dall

    Christoffer Dall
     

06 Nov, 2015

1 commit

  • Pull KVM updates from Paolo Bonzini:
    "First batch of KVM changes for 4.4.

    s390:
    A bunch of fixes and optimizations for interrupt and time handling.

    PPC:
    Mostly bug fixes.

    ARM:
    No big features, but many small fixes and prerequisites including:

    - a number of fixes for the arch-timer

    - introducing proper level-triggered semantics for the arch-timers

    - a series of patches to synchronously halt a guest (prerequisite
    for IRQ forwarding)

    - some tracepoint improvements

    - a tweak for the EL2 panic handlers

    - some more VGIC cleanups getting rid of redundant state

    x86:
    Quite a few changes:

    - support for VT-d posted interrupts (i.e. PCI devices can inject
    interrupts directly into vCPUs). This introduces a new
    component (in virt/lib/) that connects VFIO and KVM together.
    The same infrastructure will be used for ARM interrupt
    forwarding as well.

    - more Hyper-V features, though the main one Hyper-V synthetic
    interrupt controller will have to wait for 4.5. These will let
    KVM expose Hyper-V devices.

    - nested virtualization now supports VPID (same as PCID but for
    vCPUs) which makes it quite a bit faster

    - for future hardware that supports NVDIMM, there is support for
    clflushopt, clwb, pcommit

    - support for "split irqchip", i.e. LAPIC in kernel +
    IOAPIC/PIC/PIT in userspace, which reduces the attack surface of
    the hypervisor

    - obligatory smattering of SMM fixes

    - on the guest side, stable scheduler clock support was rewritten
    to not require help from the hypervisor"

    * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: (123 commits)
    KVM: VMX: Fix commit which broke PML
    KVM: x86: obey KVM_X86_QUIRK_CD_NW_CLEARED in kvm_set_cr0()
    KVM: x86: allow RSM from 64-bit mode
    KVM: VMX: fix SMEP and SMAP without EPT
    KVM: x86: move kvm_set_irq_inatomic to legacy device assignment
    KVM: device assignment: remove pointless #ifdefs
    KVM: x86: merge kvm_arch_set_irq with kvm_set_msi_inatomic
    KVM: x86: zero apic_arb_prio on reset
    drivers/hv: share Hyper-V SynIC constants with userspace
    KVM: x86: handle SMBASE as physical address in RSM
    KVM: x86: add read_phys to x86_emulate_ops
    KVM: x86: removing unused variable
    KVM: don't pointlessly leave KVM_COMPAT=y in non-KVM configs
    KVM: arm/arm64: Merge vgic_set_lr() and vgic_sync_lr_elrsr()
    KVM: arm/arm64: Clean up vgic_retire_lr() and surroundings
    KVM: arm/arm64: Optimize away redundant LR tracking
    KVM: s390: use simple switch statement as multiplexer
    KVM: s390: drop useless newline in debugging data
    KVM: s390: SCA must not cross page boundaries
    KVM: arm: Do not indent the arguments of DECLARE_BITMAP
    ...

    Linus Torvalds
     

04 Nov, 2015

7 commits

  • We do not want to do too much work in atomic context, in particular
    not walking all the VCPUs of the virtual machine. So we want
    to distinguish the architecture-specific injection function for irqfd
    from kvm_set_msi. Since it's still empty, reuse the newly added
    kvm_arch_set_irq and rename it to kvm_arch_set_irq_inatomic.

    Reviewed-by: Radim Krčmář
    Signed-off-by: Paolo Bonzini

    Paolo Bonzini
     
  • The symbol was missing a KVM dependency.

    Signed-off-by: Jan Beulich
    Signed-off-by: Paolo Bonzini

    Jan Beulich
     
  • KVM/ARM Changes for v4.4-rc1

    Includes a number of fixes for the arch-timer, introducing proper
    level-triggered semantics for the arch-timers, a series of patches to
    synchronously halt a guest (prerequisite for IRQ forwarding), some tracepoint
    improvements, a tweak for the EL2 panic handlers, some more VGIC cleanups
    getting rid of redundant state, and finally a stylistic change that gets rid of
    some ctags warnings.

    Conflicts:
    arch/x86/include/asm/kvm_host.h

    Paolo Bonzini
     
  • Now we see that vgic_set_lr() and vgic_sync_lr_elrsr() are always used
    together. Merge them into one function, saving from second vgic_ops
    dereferencing every time.

    Signed-off-by: Pavel Fedin
    Signed-off-by: Christoffer Dall

    Pavel Fedin
     
  • 1. Remove unnecessary 'irq' argument, because irq number can be retrieved
    from the LR.
    2. Since cff9211eb1a1f58ce7f5a2d596b617928fd4be0e
    ("arm/arm64: KVM: Fix arch timer behavior for disabled interrupts ")
    LR_STATE_PENDING is queued back by vgic_retire_lr() itself. Also, it
    clears vlr.state itself. Therefore, we remove the same, now duplicated,
    check with all accompanying bit manipulations from vgic_unqueue_irqs().
    3. vgic_retire_lr() is always accompanied by vgic_irq_clear_queued(). Since
    it already does more than just clearing the LR, move
    vgic_irq_clear_queued() inside of it.

    Signed-off-by: Pavel Fedin
    Signed-off-by: Christoffer Dall

    Pavel Fedin
     
  • Currently we use vgic_irq_lr_map in order to track which LRs hold which
    IRQs, and lr_used bitmap in order to track which LRs are used or free.

    vgic_irq_lr_map is actually used only for piggy-back optimization, and
    can be easily replaced by iteration over lr_used. This is good because in
    future, when LPI support is introduced, number of IRQs will grow up to at
    least 16384, while numbers from 1024 to 8192 are never going to be used.
    This would be a huge memory waste.

    In its turn, lr_used is also completely redundant since
    ae705930fca6322600690df9dc1c7d0516145a93 ("arm/arm64: KVM: Keep elrsr/aisr
    in sync with software model"), because together with lr_used we also update
    elrsr. This allows to easily replace lr_used with elrsr, inverting all
    conditions (because in elrsr '1' means 'free').

    Signed-off-by: Pavel Fedin
    Signed-off-by: Christoffer Dall

    Pavel Fedin
     
  • Pull irq updates from Thomas Gleixner:
    "The irq departement delivers:

    - Rework the irqdomain core infrastructure to accomodate ACPI based
    systems. This is required to support ARM64 without creating
    artificial device tree nodes.

    - Sanitize the ACPI based ARM GIC initialization by making use of the
    new firmware independent irqdomain core

    - Further improvements to the generic MSI management

    - Generalize the irq migration on CPU hotplug

    - Improvements to the threaded interrupt infrastructure

    - Allow the migration of "chained" low level interrupt handlers

    - Allow optional force masking of interrupts in disable_irq[_nosysnc]

    - Support for two new interrupt chips - Sigh!

    - A larger set of errata fixes for ARM gicv3

    - The usual pile of fixes, updates, improvements and cleanups all
    over the place"

    * 'irq-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (71 commits)
    Document that IRQ_NONE should be returned when IRQ not actually handled
    PCI/MSI: Allow the MSI domain to be device-specific
    PCI: Add per-device MSI domain hook
    of/irq: Use the msi-map property to provide device-specific MSI domain
    of/irq: Split of_msi_map_rid to reuse msi-map lookup
    irqchip/gic-v3-its: Parse new version of msi-parent property
    PCI/MSI: Use of_msi_get_domain instead of open-coded "msi-parent" parsing
    of/irq: Use of_msi_get_domain instead of open-coded "msi-parent" parsing
    of/irq: Add support code for multi-parent version of "msi-parent"
    irqchip/gic-v3-its: Add handling of PCI requester id.
    PCI/MSI: Add helper function pci_msi_domain_get_msi_rid().
    of/irq: Add new function of_msi_map_rid()
    Docs: dt: Add PCI MSI map bindings
    irqchip/gic-v2m: Add support for multiple MSI frames
    irqchip/gic-v3: Fix translation of LPIs after conversion to irq_fwspec
    irqchip/mxs: Add Alphascale ASM9260 support
    irqchip/mxs: Prepare driver for hardware with different offsets
    irqchip/mxs: Panic if ioremap or domain creation fails
    irqdomain: Documentation updates
    irqdomain/msi: Use fwnode instead of of_node
    ...

    Linus Torvalds
     

23 Oct, 2015

8 commits

  • The VGIC and timer code for KVM arm/arm64 doesn't have any tracepoints
    or tracepoint infrastructure defined. Rewriting some of the timer code
    handling showed me how much we need this, so let's add these simple
    trace points once and for all and we can easily expand with additional
    trace points in these files as we go along.

    Cc: Wei Huang
    Signed-off-by: Christoffer Dall

    Christoffer Dall
     
  • We mark edge-triggered interrupts with the HW bit set as queued to
    prevent the VGIC code from injecting LRs with both the Active and
    Pending bits set at the same time while also setting the HW bit,
    because the hardware does not support this.

    However, this means that we must also clear the queued flag when we sync
    back a LR where the state on the physical distributor went from active
    to inactive because the guest deactivated the interrupt. At this point
    we must also check if the interrupt is pending on the distributor, and
    tell the VGIC to queue it again if it is.

    Since these actions on the sync path are extremely close to those for
    level-triggered interrupts, rename process_level_irq to
    process_queued_irq, allowing it to cater for both cases.

    Signed-off-by: Christoffer Dall

    Christoffer Dall
     
  • The arch timer currently uses edge-triggered semantics in the sense that
    the line is never sampled by the vgic and lowering the line from the
    timer to the vgic doesn't have any effect on the pending state of
    virtual interrupts in the vgic. This means that we do not support a
    guest with the otherwise valid behavior of (1) disable interrupts (2)
    enable the timer (3) disable the timer (4) enable interrupts. Such a
    guest would validly not expect to see any interrupts on real hardware,
    but will see interrupts on KVM.

    This patch fixes this shortcoming through the following series of
    changes.

    First, we change the flow of the timer/vgic sync/flush operations. Now
    the timer is always flushed/synced before the vgic, because the vgic
    samples the state of the timer output. This has the implication that we
    move the timer operations in to non-preempible sections, but that is
    fine after the previous commit getting rid of hrtimer schedules on every
    entry/exit.

    Second, we change the internal behavior of the timer, letting the timer
    keep track of its previous output state, and only lower/raise the line
    to the vgic when the state changes. Note that in theory this could have
    been accomplished more simply by signalling the vgic every time the
    state *potentially* changed, but we don't want to be hitting the vgic
    more often than necessary.

    Third, we get rid of the use of the map->active field in the vgic and
    instead simply set the interrupt as active on the physical distributor
    whenever the input to the GIC is asserted and conversely clear the
    physical active state when the input to the GIC is deasserted.

    Fourth, and finally, we now initialize the timer PPIs (and all the other
    unused PPIs for now), to be level-triggered, and modify the sync code to
    sample the line state on HW sync and re-inject a new interrupt if it is
    still pending at that time.

    Signed-off-by: Christoffer Dall

    Christoffer Dall
     
  • We currently initialize the SGIs to be enabled in the VGIC code, but we
    use the VGIC_NR_PPIS define for this purpose, instead of the the more
    natural VGIC_NR_SGIS. Change this slightly confusing use of the
    defines.

    Note: This should have no functional change, as both names are defined
    to the number 16.

    Acked-by: Marc Zyngier
    Signed-off-by: Christoffer Dall

    Christoffer Dall
     
  • The GICD_ICFGR allows the bits for the SGIs and PPIs to be read only.
    We currently simulate this behavior by writing a hardcoded value to the
    register for the SGIs and PPIs on every write of these bits to the
    register (ignoring what the guest actually wrote), and by writing the
    same value as the reset value to the register.

    This is a bit counter-intuitive, as the register is RO for these bits,
    and we can just implement it that way, allowing us to control the value
    of the bits purely in the reset code.

    Reviewed-by: Marc Zyngier
    Signed-off-by: Christoffer Dall

    Christoffer Dall
     
  • Currently vgic_process_maintenance() processes dealing with a completed
    level-triggered interrupt directly, but we are soon going to reuse this
    logic for level-triggered mapped interrupts with the HW bit set, so
    move this logic into a separate static function.

    Probably the most scary part of this commit is convincing yourself that
    the current flow is safe compared to the old one. In the following I
    try to list the changes and why they are harmless:

    Move vgic_irq_clear_queued after kvm_notify_acked_irq:
    Harmless because the only potential effect of clearing the queued
    flag wrt. kvm_set_irq is that vgic_update_irq_pending does not set
    the pending bit on the emulated CPU interface or in the
    pending_on_cpu bitmask if the function is called with level=1.
    However, the point of kvm_notify_acked_irq is to call kvm_set_irq
    with level=0, and we set the queued flag again in
    __kvm_vgic_sync_hwstate later on if the level is stil high.

    Move vgic_set_lr before kvm_notify_acked_irq:
    Also, harmless because the LR are cpu-local operations and
    kvm_notify_acked only affects the dist

    Move vgic_dist_irq_clear_soft_pend after kvm_notify_acked_irq:
    Also harmless, because now we check the level state in the
    clear_soft_pend function and lower the pending bits if the level is
    low.

    Reviewed-by: Eric Auger
    Reviewed-by: Marc Zyngier
    Signed-off-by: Christoffer Dall

    Christoffer Dall
     
  • We currently schedule a soft timer every time we exit the guest if the
    timer did not expire while running the guest. This is really not
    necessary, because the only work we do in the timer work function is to
    kick the vcpu.

    Kicking the vcpu does two things:
    (1) If the vpcu thread is on a waitqueue, make it runnable and remove it
    from the waitqueue.
    (2) If the vcpu is running on a different physical CPU from the one
    doing the kick, it sends a reschedule IPI.

    The second case cannot happen, because the soft timer is only ever
    scheduled when the vcpu is not running. The first case is only relevant
    when the vcpu thread is on a waitqueue, which is only the case when the
    vcpu thread has called kvm_vcpu_block().

    Therefore, we only need to make sure a timer is scheduled for
    kvm_vcpu_block(), which we do by encapsulating all calls to
    kvm_vcpu_block() with kvm_timer_{un}schedule calls.

    Additionally, we only schedule a soft timer if the timer is enabled and
    unmasked, since it is useless otherwise.

    Note that theoretically userspace can use the SET_ONE_REG interface to
    change registers that should cause the timer to fire, even if the vcpu
    is blocked without a scheduled timer, but this case was not supported
    before this patch and we leave it for future work for now.

    Signed-off-by: Christoffer Dall

    Christoffer Dall
     
  • Some times it is useful for architecture implementations of KVM to know
    when the VCPU thread is about to block or when it comes back from
    blocking (arm/arm64 needs to know this to properly implement timers, for
    example).

    Therefore provide a generic architecture callback function in line with
    what we do elsewhere for KVM generic-arch interactions.

    Reviewed-by: Marc Zyngier
    Signed-off-by: Christoffer Dall

    Christoffer Dall
     

21 Oct, 2015

4 commits

  • We currently do a single update of the vgic state when the distributor
    enable/disable control register is accessed and then bypass updating the
    state for as long as the distributor remains disabled.

    This is incorrect, because updating the state does not consider the
    distributor enable bit, and this you can end up in a situation where an
    interrupt is marked as pending on the CPU interface, but not pending on
    the distributor, which is an impossible state to be in, and triggers a
    warning. Consider for example the following sequence of events:

    1. An interrupt is marked as pending on the distributor
    - the interrupt is also forwarded to the CPU interface
    2. The guest turns off the distributor (it's about to do a reboot)
    - we stop updating the CPU interface state from now on
    3. The guest disables the pending interrupt
    - we remove the pending state from the distributor, but don't touch
    the CPU interface, see point 2.

    Since the distributor disable bit really means that no interrupts should
    be forwarded to the CPU interface, we modify the code to keep updating
    the internal VGIC state, but always set the CPU interface pending bits
    to zero when the distributor is disabled.

    Signed-off-by: Christoffer Dall

    Christoffer Dall
     
  • When a guest reboots or offlines/onlines CPUs, it is not uncommon for it
    to clear the pending and active states of an interrupt through the
    emulated VGIC distributor. However, since the architected timers are
    defined by the architecture to be level triggered and the guest
    rightfully expects them to be that, but we emulate them as
    edge-triggered, we have to mimic level-triggered behavior for an
    edge-triggered virtual implementation.

    We currently do not signal the VGIC when the map->active field is true,
    because it indicates that the guest has already been signalled of the
    interrupt as required. Normally this field is set to false when the
    guest deactivates the virtual interrupt through the sync path.

    We also need to catch the case where the guest deactivates the interrupt
    through the emulated distributor, again allowing guests to boot even if
    the original virtual timer signal hit before the guest's GIC
    initialization sequence is run.

    Reviewed-by: Eric Auger
    Signed-off-by: Christoffer Dall

    Christoffer Dall
     
  • We have an interesting issue when the guest disables the timer interrupt
    on the VGIC, which happens when turning VCPUs off using PSCI, for
    example.

    The problem is that because the guest disables the virtual interrupt at
    the VGIC level, we never inject interrupts to the guest and therefore
    never mark the interrupt as active on the physical distributor. The
    host also never takes the timer interrupt (we only use the timer device
    to trigger a guest exit and everything else is done in software), so the
    interrupt does not become active through normal means.

    The result is that we keep entering the guest with a programmed timer
    that will always fire as soon as we context switch the hardware timer
    state and run the guest, preventing forward progress for the VCPU.

    Since the active state on the physical distributor is really part of the
    timer logic, it is the job of our virtual arch timer driver to manage
    this state.

    The timer->map->active boolean field indicates whether we have signalled
    this interrupt to the vgic and if that interrupt is still pending or
    active. As long as that is the case, the hardware doesn't have to
    generate physical interrupts and therefore we mark the interrupt as
    active on the physical distributor.

    We also have to restore the pending state of an interrupt that was
    queued to an LR but was retired from the LR for some reason, while
    remaining pending in the LR.

    Cc: Marc Zyngier
    Reported-by: Lorenzo Pieralisi
    Signed-off-by: Christoffer Dall

    Christoffer Dall
     
  • When lowering a level-triggered line from userspace, we forgot to lower
    the pending bit on the emulated CPU interface and we also did not
    re-compute the pending_on_cpu bitmap for the CPU affected by the change.

    Update vgic_update_irq_pending() to fix the two issues above and also
    raise a warning in vgic_quue_irq_to_lr if we encounter an interrupt
    pending on a CPU which is neither marked active nor pending.

    [ Commit text reworked completely - Christoffer ]

    Signed-off-by: Pavel Fedin
    Signed-off-by: Christoffer Dall

    Pavel Fedin
     

16 Oct, 2015

4 commits

  • Any other irq routing types (MSI, S390_ADAPTER, upcoming Hyper-V
    SynIC) map one-to-one to GSI.

    Signed-off-by: Andrey Smetanin
    Reviewed-by: Roman Kagan
    Signed-off-by: Denis V. Lunev
    CC: Vitaly Kuznetsov
    CC: "K. Y. Srinivasan"
    CC: Gleb Natapov
    CC: Paolo Bonzini
    Signed-off-by: Paolo Bonzini

    Andrey Smetanin
     
  • Allow for arch-specific interrupt types to be set. For that, add
    kvm_arch_set_irq() which takes interrupt type-specific action if it
    recognizes the interrupt type given, and -EWOULDBLOCK otherwise.

    The default implementation always returns -EWOULDBLOCK.

    Signed-off-by: Andrey Smetanin
    Reviewed-by: Roman Kagan
    Signed-off-by: Denis V. Lunev
    CC: Vitaly Kuznetsov
    CC: "K. Y. Srinivasan"
    CC: Gleb Natapov
    CC: Paolo Bonzini
    Signed-off-by: Paolo Bonzini

    Andrey Smetanin
     
  • Factor out kvm_notify_acked_gsi() helper to iterate over EOI listeners
    and notify those matching the given gsi.

    It will be reused in the upcoming Hyper-V SynIC implementation.

    Signed-off-by: Andrey Smetanin
    Reviewed-by: Roman Kagan
    Signed-off-by: Denis V. Lunev
    CC: Vitaly Kuznetsov
    CC: "K. Y. Srinivasan"
    CC: Gleb Natapov
    CC: Paolo Bonzini
    Signed-off-by: Paolo Bonzini

    Andrey Smetanin
     
  • The loop(for) inside irqfd_update() is unnecessary
    because any other value for irq_entry.type will just trigger
    schedule_work(&irqfd->inject) in irqfd_wakeup.

    Signed-off-by: Andrey Smetanin
    Reviewed-by: Roman Kagan
    Signed-off-by: Denis V. Lunev
    CC: Vitaly Kuznetsov
    CC: "K. Y. Srinivasan"
    CC: Gleb Natapov
    CC: Paolo Bonzini
    Signed-off-by: Paolo Bonzini

    Andrey Smetanin