On Sun, Jan 04, 2009 at 06:14:44PM +0200, Avi Kivity wrote:
> Allow clients to request notifications when the guest masks or unmasks a
> particular irq line.  This complements irq ack notifications, as the guest
> will not ack an irq line that is masked.
> 
> Currently implemented for the ioapic only.
> 
> Signed-off-by: Avi Kivity <a...@redhat.com>
> ---
>  include/linux/kvm_host.h |   17 +++++++++++++++++
>  virt/kvm/ioapic.c        |    7 ++++++-
>  virt/kvm/irq_comm.c      |   24 ++++++++++++++++++++++++
>  virt/kvm/kvm_main.c      |    3 +++
>  4 files changed, 50 insertions(+), 1 deletions(-)
> 
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 545a133..43385fa 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -127,6 +127,10 @@ struct kvm {
>       struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
>  #endif
>  
> +#ifdef CONFIG_HAVE_KVM_IRQCHIP
> +     struct hlist_head mask_notifier_list;
> +#endif
> +
>  #ifdef KVM_ARCH_WANT_MMU_NOTIFIER
>       struct mmu_notifier mmu_notifier;
>       unsigned long mmu_notifier_seq;
> @@ -320,6 +324,19 @@ struct kvm_assigned_dev_kernel {
>       struct pci_dev *dev;
>       struct kvm *kvm;
>  };
> +
> +struct kvm_irq_mask_notifier {
> +     void (*func)(struct kvm_irq_mask_notifier *kimn, int masked);

bool masked?

> +     int irq;
> +     struct hlist_node link;
> +};
> +
> +void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq,
> +                                 struct kvm_irq_mask_notifier *kimn);
> +void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq,
> +                                   struct kvm_irq_mask_notifier *kimn);
> +void kvm_fire_mask_notifiers(struct kvm *kvm, int irq, int mask);
> +
>  void kvm_set_irq(struct kvm *kvm, int irq_source_id, int irq, int level);
>  void kvm_notify_acked_irq(struct kvm *kvm, unsigned gsi);
>  void kvm_register_irq_ack_notifier(struct kvm *kvm,
> diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c
> index 23b81cf..15b9ddd 100644
> --- a/virt/kvm/ioapic.c
> +++ b/virt/kvm/ioapic.c
> @@ -100,7 +100,7 @@ static void ioapic_service(struct kvm_ioapic *ioapic, 
> unsigned int idx)
>  
>  static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val)
>  {
> -     unsigned index;
> +     unsigned index, mask_before, mask_after;
>  
>       switch (ioapic->ioregsel) {
>       case IOAPIC_REG_VERSION:
> @@ -120,6 +120,7 @@ static void ioapic_write_indirect(struct kvm_ioapic 
> *ioapic, u32 val)
>               ioapic_debug("change redir index %x val %x\n", index, val);
>               if (index >= IOAPIC_NUM_PINS)
>                       return;
> +             mask_before = ioapic->redirtbl[index].fields.mask;
>               if (ioapic->ioregsel & 1) {
>                       ioapic->redirtbl[index].bits &= 0xffffffff;
>                       ioapic->redirtbl[index].bits |= (u64) val << 32;
> @@ -128,6 +129,9 @@ static void ioapic_write_indirect(struct kvm_ioapic 
> *ioapic, u32 val)
>                       ioapic->redirtbl[index].bits |= (u32) val;
>                       ioapic->redirtbl[index].fields.remote_irr = 0;
>               }
> +             mask_after = ioapic->redirtbl[index].fields.mask;
> +             if (mask_before != mask_after)
> +                     kvm_fire_mask_notifiers(ioapic->kvm, index, mask_after);

This can generate "spurious acks", for example:

- inject irq
- guest masks, mask notifier cleans internal state to "acked".
- guest writes EOI

But I suppose thats fine, since PIT (for example) is getting spurious
acks even without mask notifiers and so has to handle them.

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to