All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: David Kiarie <davidkiarie4@gmail.com>
Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org,
	ehabkost@redhat.com, mst@redhat.com, jan.kiszka@siemens.com,
	valentine.sinitsyn@gmail.com, pbonzini@redhat.com
Subject: Re: [Qemu-devel] [RFC 1/2] hw/msi: Allow platform devices to use explicit SID
Date: Wed, 10 Aug 2016 13:41:55 +0800	[thread overview]
Message-ID: <20160810054155.GH4201@pxdev.xzpeter.org> (raw)
In-Reply-To: <1470753137-18354-2-git-send-email-davidkiarie4@gmail.com>

On Tue, Aug 09, 2016 at 05:32:16PM +0300, David Kiarie wrote:
> When using IOMMU platform devices like IOAPIC are required to make
> interrupt remapping requests using explicit SID.We affiliate an MSI
> route with a requester ID and a PCI device if present which ensures
> that platform devices can call IOMMU interrupt remapping code with
> explicit SID while maintaining compatility with the original code
> which mainly dealt with PCI devices.
> 
> Signed-off-by: David Kiarie <davidkiarie4@gmail.com>

Hi,

This idea is good to me overall, with some tiny comments below.

[...]

> -static void ioapic_service(IOAPICCommonState *s)
> +static void ioapic_write_ioapic_as(IOAPICCommonState *s, uint32_t data, uint64_t addr)

Rename to ioapic_as_write()?

[...]

> @@ -385,12 +393,23 @@ static void ioapic_machine_done_notify(Notifier *notifier, void *data)
>  
>      if (kvm_irqchip_is_split()) {
>          X86IOMMUState *iommu = x86_iommu_get_default();
> +        MSIMessage msg = {0, 0};
> +        int i;
> +
>          if (iommu) {
>              /* Register this IOAPIC with IOMMU IEC notifier, so that
>               * when there are IR invalidates, we can be notified to
>               * update kernel IR cache. */
> -            x86_iommu_iec_register_notifier(iommu, ioapic_iec_notifier, s);
> +            s->devid = iommu->ioapic_bdf;
> +            /* update IOAPIC routes to the right SID */
> +            for (i = 0; i < IOAPIC_NUM_PINS; i++) {
> +                kvm_irqchip_update_msi_route(kvm_state, i, msg, NULL, s->devid);
> +            }
> +            kvm_irqchip_commit_routes(kvm_state);

Here, not sure whether it'll be better if we remove
kvm_irqchip_add_msi_route() in kvm_arch_init_irq_routing() directly
and call them here. So no extra update needed.

>          }
> +
> +        kvm_irqchip_update_msi_route(kvm_state, i, msg, NULL, s->devid);

What is this line used for?

> +        x86_iommu_iec_register_notifier(iommu, ioapic_iec_notifier, s);
>      }
>  #endif
>  }
> @@ -407,6 +426,7 @@ static void ioapic_realize(DeviceState *dev, Error **errp)
>  
>      memory_region_init_io(&s->io_memory, OBJECT(s), &ioapic_io_ops, s,
>                            "ioapic", 0x1000);
> +    s->devid = 0;

Nit: We can remove this line.

[...]

> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index 755f921..54e27fc 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -705,7 +705,8 @@ static int kvm_virtio_pci_vq_vector_use(VirtIOPCIProxy *proxy,
>      int ret;
>  
>      if (irqfd->users == 0) {
> -        ret = kvm_irqchip_add_msi_route(kvm_state, vector, &proxy->pci_dev);
> +        ret = kvm_irqchip_add_msi_route(kvm_state, vector, &proxy->pci_dev,
> +                pci_requester_id(&proxy->pci_dev));
>          if (ret < 0) {
>              return ret;
>          }
> @@ -838,7 +839,8 @@ static int virtio_pci_vq_vector_unmask(VirtIOPCIProxy *proxy,
>          irqfd = &proxy->vector_irqfd[vector];
>          if (irqfd->msg.data != msg.data || irqfd->msg.address != msg.address) {
>              ret = kvm_irqchip_update_msi_route(kvm_state, irqfd->virq, msg,
> -                                               &proxy->pci_dev);
> +                                        &proxy->pci_dev,

Nit: Here you changed indentation, I would suggest keep it, as well in
the next line.

> +                                        pci_requester_id(&proxy->pci_dev));
>              if (ret < 0) {
>                  return ret;
>              }
> diff --git a/include/hw/i386/ioapic_internal.h b/include/hw/i386/ioapic_internal.h
> index a11d86d..d68a24f 100644
> --- a/include/hw/i386/ioapic_internal.h
> +++ b/include/hw/i386/ioapic_internal.h
> @@ -103,6 +103,7 @@ typedef struct IOAPICCommonClass {
>  struct IOAPICCommonState {
>      SysBusDevice busdev;
>      MemoryRegion io_memory;
> +    uint16_t devid;
>      uint8_t id;
>      uint8_t ioregsel;
>      uint32_t irr;
> diff --git a/include/hw/i386/x86-iommu.h b/include/hw/i386/x86-iommu.h
> index c48e8dd..19454e0 100644
> --- a/include/hw/i386/x86-iommu.h
> +++ b/include/hw/i386/x86-iommu.h
> @@ -66,6 +66,7 @@ typedef struct IEC_Notifier IEC_Notifier;
>  
>  struct X86IOMMUState {
>      SysBusDevice busdev;
> +    uint16_t ioapic_bdf;        /* expected IOAPIC SID        */

If we do not init ioapic_bdf in this patch, I think it should break
system boot with IR? I'd suggest introduce ioapic_bdf with meaningful
value in the first patch.

Also, when you send the formal patches, please don't forget to CC
Paolo since he is the maintainer for irqchips and kvm stuffs.

-- peterx

  reply	other threads:[~2016-08-10  5:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-09 14:32 [Qemu-devel] [RFC 0/2] Explicit SID for IOAPIC David Kiarie
2016-08-09 14:32 ` [Qemu-devel] [RFC 1/2] hw/msi: Allow platform devices to use explicit SID David Kiarie
2016-08-10  5:41   ` Peter Xu [this message]
2016-08-10  6:35     ` David Kiarie
2016-08-10  7:23       ` Peter Xu
2016-08-09 14:32 ` [Qemu-devel] [RFC 2/2] hw/i386: enforce SID verification David Kiarie
2016-08-09 18:41   ` Valentine Sinitsyn
2016-08-09 18:46     ` David Kiarie
2016-08-10  5:49   ` Peter Xu
2016-08-10  6:30     ` David Kiarie
2016-08-10  7:09       ` Peter Xu
2016-08-09 14:39 ` [Qemu-devel] [RFC 0/2] Explicit SID for IOAPIC no-reply
2016-08-09 14:39 ` no-reply

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=20160810054155.GH4201@pxdev.xzpeter.org \
    --to=peterx@redhat.com \
    --cc=davidkiarie4@gmail.com \
    --cc=ehabkost@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=valentine.sinitsyn@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.