From: Marcelo Tosatti <mtosatti@redhat.com>
To: Sheng Yang <sheng@linux.intel.com>
Cc: Avi Kivity <avi@redhat.com>, kvm@vger.kernel.org
Subject: Re: [PATCH 2/3] KVM: Add gsi_msg_pending_bitmap for MSI-X
Date: Thu, 12 Feb 2009 17:51:18 -0200 [thread overview]
Message-ID: <20090212195118.GA19749@amt.cnet> (raw)
In-Reply-To: <1234339731-3195-3-git-send-email-sheng@linux.intel.com>
Hi Sheng,
On Wed, Feb 11, 2009 at 04:08:50PM +0800, Sheng Yang wrote:
> We have to handle more than one interrupt with one handler for MSI-X. So we
> need a bitmap to track the triggered interrupts.
>
> Signed-off-by: Sheng Yang <sheng@linux.intel.com>
> ---
> include/linux/kvm_host.h | 5 +-
> virt/kvm/kvm_main.c | 103 ++++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 103 insertions(+), 5 deletions(-)
>
> @@ -335,6 +337,7 @@ struct kvm_assigned_dev_kernel {
> #define KVM_ASSIGNED_DEV_GUEST_MSI (1 << 1)
> #define KVM_ASSIGNED_DEV_HOST_INTX (1 << 8)
> #define KVM_ASSIGNED_DEV_HOST_MSI (1 << 9)
> +#define KVM_ASSIGNED_DEV_MSIX ((1 << 2) | (1 << 10))
Can you explain the usage of the two bits?
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index ea96690..961603f 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -95,25 +95,113 @@ static struct kvm_assigned_dev_kernel *kvm_find_assigned_dev(struct list_head *h
> return NULL;
> }
>
> +static int find_host_irq_from_gsi(struct kvm_assigned_dev_kernel *assigned_dev,
> + u32 gsi)
> +{
> + int i, entry, irq;
> + struct msix_entry *host_msix_entries, *guest_msix_entries;
> +
> + host_msix_entries = assigned_dev->host_msix_entries;
> + guest_msix_entries = assigned_dev->guest_msix_entries;
> +
> + entry = -1;
> + irq = 0;
> + for (i = 0; i < assigned_dev->entries_nr; i++)
> + if (gsi == (guest_msix_entries + i)->vector) {
> + entry = (guest_msix_entries + i)->entry;
> + break;
> + }
> + if (entry < 0) {
> + printk(KERN_WARNING "Fail to find correlated MSI-X entry!\n");
> + return 0;
> + }
> + for (i = 0; i < assigned_dev->entries_nr; i++)
> + if (entry == (host_msix_entries + i)->entry) {
> + irq = (host_msix_entries + i)->vector;
> + break;
> + }
> + if (irq == 0) {
> + printk(KERN_WARNING "Fail to find correlated MSI-X irq!\n");
> + return 0;
> + }
Can drop the printk's (also from find_gsi_from_host_irq).
> struct kvm_assigned_dev_kernel *assigned_dev;
> + struct kvm *kvm;
> + u32 gsi;
> + int irq;
>
> assigned_dev = container_of(work, struct kvm_assigned_dev_kernel,
> interrupt_work);
> + kvm = assigned_dev->kvm;
>
> /* This is taken to safely inject irq inside the guest. When
> * the interrupt injection (or the ioapic code) uses a
> * finer-grained lock, update this
> */
> - mutex_lock(&assigned_dev->kvm->lock);
> - kvm_set_irq(assigned_dev->kvm, assigned_dev->irq_source_id,
> - assigned_dev->guest_irq, 1);
> + mutex_lock(&kvm->lock);
> +handle_irq:
> + if (assigned_dev->irq_requested_type & KVM_ASSIGNED_DEV_MSIX) {
> + gsi = find_first_bit(kvm->irq_routes_pending_bitmap,
> + KVM_MAX_IRQ_ROUTES);
> + BUG_ON(gsi >= KVM_MAX_IRQ_ROUTES);
> + clear_bit(gsi, kvm->irq_routes_pending_bitmap);
> + } else
> + gsi = assigned_dev->guest_irq;
> +
> + kvm_set_irq(assigned_dev->kvm, assigned_dev->irq_source_id, gsi, 1);
>
> if (assigned_dev->irq_requested_type & KVM_ASSIGNED_DEV_GUEST_MSI) {
> enable_irq(assigned_dev->host_irq);
> assigned_dev->host_irq_disabled = false;
> + } else if (assigned_dev->irq_requested_type & KVM_ASSIGNED_DEV_MSIX) {
> + irq = find_host_irq_from_gsi(assigned_dev, gsi);
Check the return value?
> + enable_irq(irq);
Do you guarantee that particular irq you're enable_irq'ing is not bogus?
Its has been passed from userspace after all.
In a later patch you can assign KVM_ASSIGNED_DEV_MSIX if the irqchip is
not in-kernel in assigned_device_update_msix:
+ adev->irq_requested_type |= KVM_ASSIGNED_DEV_MSIX;
+
Just trying to harden the code against bogosity elsewhere.
> + assigned_dev->host_irq_disabled = false;
> + gsi = find_first_bit(kvm->irq_routes_pending_bitmap,
> + KVM_MAX_IRQ_ROUTES);
> + if (gsi < KVM_MAX_IRQ_ROUTES)
> + goto handle_irq;
> }
> +
> mutex_unlock(&assigned_dev->kvm->lock);
> }
>
> @@ -121,6 +209,15 @@ static irqreturn_t kvm_assigned_dev_intr(int irq, void *dev_id)
> {
> struct kvm_assigned_dev_kernel *assigned_dev =
> (struct kvm_assigned_dev_kernel *) dev_id;
> + struct kvm *kvm = assigned_dev->kvm;
> +
> + if (assigned_dev->irq_requested_type == KVM_ASSIGNED_DEV_MSIX) {
> + u32 gsi;
> + gsi = find_gsi_from_host_irq(assigned_dev, irq);
> + if (gsi == 0)
> + return IRQ_HANDLED;
So you chose GSI == 0 as invalid because of x86 assumptions? Or is there
any other reason?
IRQ sharing in the host side is not supported correct?
next prev parent reply other threads:[~2009-02-12 19:51 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-11 8:08 [PATCH 0/3 v2] MSI-X enabling Sheng Yang
2009-02-11 8:08 ` [PATCH 1/3] KVM: Ioctls for init MSI-X entry Sheng Yang
2009-02-11 12:44 ` Avi Kivity
2009-02-12 6:28 ` Sheng Yang
2009-02-12 10:07 ` Sheng Yang
2009-02-12 18:46 ` Marcelo Tosatti
2009-02-16 3:18 ` Sheng Yang
2009-02-16 5:49 ` Sheng Yang
2009-02-16 23:23 ` Marcelo Tosatti
2009-02-17 1:35 ` Sheng Yang
2009-02-17 1:36 ` Sheng Yang
2009-02-11 8:08 ` [PATCH 2/3] KVM: Add gsi_msg_pending_bitmap for MSI-X Sheng Yang
2009-02-12 19:51 ` Marcelo Tosatti [this message]
2009-02-13 3:37 ` Sheng Yang
2009-02-13 17:10 ` Marcelo Tosatti
2009-02-17 18:09 ` Avi Kivity
2009-02-18 1:33 ` Sheng Yang
2009-02-11 8:08 ` [PATCH 3/3] KVM: Enable MSI-X for KVM assigned device Sheng Yang
2009-02-11 12:48 ` Avi Kivity
2009-02-12 6:03 ` Sheng Yang
2009-02-12 20:40 ` Marcelo Tosatti
2009-02-13 5:29 ` Sheng Yang
2009-02-13 17:13 ` Marcelo Tosatti
-- strict thread matches above, loose matches on Subject: below --
2009-02-18 9:44 [PATCH 0/3 v3] MSI-X enabling Sheng Yang
2009-02-18 9:44 ` [PATCH 2/3] KVM: Add gsi_msg_pending_bitmap for MSI-X Sheng Yang
2009-02-18 11:00 ` Avi Kivity
2009-02-18 11:13 ` Sheng Yang
2009-02-18 11:29 ` Avi Kivity
2009-02-18 11:38 ` Sheng Yang
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=20090212195118.GA19749@amt.cnet \
--to=mtosatti@redhat.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=sheng@linux.intel.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