kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sheng Yang <sheng@linux.intel.com>
To: Avi Kivity <avi@redhat.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>, kvm@vger.kernel.org
Subject: Re: [PATCH 2/3] KVM: Interrupt mask notifiers for ioapic
Date: Mon, 5 Jan 2009 15:06:14 +0800	[thread overview]
Message-ID: <200901051506.15661.sheng@linux.intel.com> (raw)
In-Reply-To: <1231085685-32201-3-git-send-email-avi@redhat.com>

On Monday 05 January 2009 00:14:44 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.

Hi Avi

Need a lock for this list? Seems kvm_fire_mask_notifiers() implicit holding 
kvm->lock, but register/unregister didn't. And I think we need some comments 
for the necessary of lock.

-- 
regards
Yang, Sheng

>
> Signed-off-by: Avi Kivity <avi@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);
> +	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);
>  		if (ioapic->irr & (1 << index))
>  			ioapic_service(ioapic, index);
>  		break;
> @@ -426,3 +430,4 @@ int kvm_ioapic_init(struct kvm *kvm)
>  	kvm_io_bus_register_dev(&kvm->mmio_bus, &ioapic->dev);
>  	return 0;
>  }
> +
> diff --git a/virt/kvm/irq_comm.c b/virt/kvm/irq_comm.c
> index aa5d1e5..2cbde68 100644
> --- a/virt/kvm/irq_comm.c
> +++ b/virt/kvm/irq_comm.c
> @@ -99,3 +99,27 @@ void kvm_free_irq_source_id(struct kvm *kvm, int
> irq_source_id) clear_bit(irq_source_id, &kvm->arch.irq_states[i]);
>  	clear_bit(irq_source_id, &kvm->arch.irq_sources_bitmap);
>  }
> +
> +void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq,
> +				    struct kvm_irq_mask_notifier *kimn)
> +{
> +	kimn->irq = irq;
> +	hlist_add_head(&kimn->link, &kvm->mask_notifier_list);
> +}
> +
> +void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq,
> +				      struct kvm_irq_mask_notifier *kimn)
> +{
> +	hlist_del(&kimn->link);
> +}
> +
> +void kvm_fire_mask_notifiers(struct kvm *kvm, int irq, int mask)
> +{
> +	struct kvm_irq_mask_notifier *kimn;
> +	struct hlist_node *n;
> +
> +	hlist_for_each_entry(kimn, n, &kvm->mask_notifier_list, link)
> +		if (kimn->irq == irq)
> +			kimn->func(kimn, mask);
> +}
> +
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 5703557..dcd58d6 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -806,6 +806,9 @@ static struct kvm *kvm_create_vm(void)
>
>  	if (IS_ERR(kvm))
>  		goto out;
> +#ifdef CONFIG_HAVE_KVM_IRQCHIP
> +	INIT_HLIST_HEAD(&kvm->mask_notifier_list);
> +#endif
>
>  #ifdef KVM_COALESCED_MMIO_PAGE_OFFSET
>  	page = alloc_page(GFP_KERNEL | __GFP_ZERO);


  reply	other threads:[~2009-01-05  7:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-04 16:14 [PATCH 0/3] Reset PIT reinjection logic on irq unmask Avi Kivity
2009-01-04 16:14 ` [PATCH 1/3] KVM: Add CONFIG_HAVE_KVM_IRQCHIP Avi Kivity
2009-01-04 16:14 ` [PATCH 2/3] KVM: Interrupt mask notifiers for ioapic Avi Kivity
2009-01-05  7:06   ` Sheng Yang [this message]
2009-01-05 13:24     ` Avi Kivity
2009-01-05 18:29   ` Marcelo Tosatti
2009-01-05 20:57     ` Avi Kivity
2009-01-04 16:14 ` [PATCH 3/3] KVM: Reset PIT irq injection logic when the PIT IRQ is unmasked Avi Kivity
2009-01-05 18:31   ` Marcelo Tosatti
2009-01-05 20:59     ` Avi Kivity
2009-01-05 21:58       ` Marcelo Tosatti
2009-01-06  8:25         ` Avi Kivity
2009-01-06  9:35           ` Dor Laor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200901051506.15661.sheng@linux.intel.com \
    --to=sheng@linux.intel.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).