qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Auger Eric <eric.auger@redhat.com>
To: eric.auger.pro@gmail.com, peter.maydell@linaro.org,
	qemu-arm@nongnu.org, qemu-devel@nongnu.org,
	alex.williamson@redhat.com, pranav.sawargaonkar@gmail.com
Cc: diana.craciun@freescale.com, Bharat.Bhushan@freescale.com,
	drjones@redhat.com, christoffer.dall@linaro.org
Subject: Re: [Qemu-devel] [RFC v3 7/8] hw: vfio: common: vfio_prepare_msi_mapping
Date: Thu, 6 Oct 2016 12:51:48 +0200	[thread overview]
Message-ID: <6bf03996-bade-6a19-cc39-2e5bda8b59d5@redhat.com> (raw)
In-Reply-To: <1475747444-12552-8-git-send-email-eric.auger@redhat.com>

Hi,

On 06/10/2016 11:50, Eric Auger wrote:
> Introduce an helper function to retrieve the iommu type1 capability
> chain info.
> 
> The first capability ready to be exploited is the msi geometry
> capability. vfio_prepare_msi_mapping allocates a MemoryRegion
> dedicated to host MSI IOVA mapping. Its size matches the host needs.
> This region is mapped on guest side on the platform bus memory container.
> 
> Signed-off-by: Eric Auger <eric.auger@redhat.com>
> 
> ---
> 
> v3: creation
> ---
>  hw/vfio/common.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 74 insertions(+)
> 
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index fe8a855..7d20c33 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -34,6 +34,8 @@
>  #include "qemu/range.h"
>  #include "sysemu/kvm.h"
>  #include "trace.h"
> +#include "hw/platform-bus.h"
> +#include "qapi/error.h"
>  
>  struct vfio_group_head vfio_group_list =
>      QLIST_HEAD_INITIALIZER(vfio_group_list);
> @@ -948,12 +950,76 @@ retry:
>      return 0;
>  }
>  
> +static struct vfio_info_cap_header *
> +vfio_get_iommu_type1_info_cap(struct vfio_iommu_type1_info *info, uint16_t id)
> +{
> +    struct vfio_info_cap_header *hdr;
> +    void *ptr = info;
> +
> +    if (!(info->flags & VFIO_IOMMU_INFO_CAPS)) {
> +        return NULL;
> +    }
> +
> +    for (hdr = ptr + info->cap_offset; hdr != ptr; hdr = ptr + hdr->next) {
> +        if (hdr->id == id) {
> +            return hdr;
> +        }
> +    }
> +    return NULL;
> +}
> +
> +static void vfio_prepare_msi_mapping(struct vfio_iommu_type1_info *info,
> +                                     AddressSpace *as, Error **errp)
> +{
> +    struct vfio_iommu_type1_info_cap_msi_geometry *msi_geometry;
> +    MemoryRegion *pbus_region, *reserved_reg;
> +    struct vfio_info_cap_header *hdr;
> +    PlatformBusDevice *pbus;
> +
> +    hdr = vfio_get_iommu_type1_info_cap(info,
> +                                        VFIO_IOMMU_TYPE1_INFO_CAP_MSI_GEOMETRY);
> +    if (!hdr) {
> +        return;
> +    }
> +
> +    msi_geometry = container_of(hdr,
> +                                struct vfio_iommu_type1_info_cap_msi_geometry,
> +                                header);
> +
> +    if (msi_geometry->flags & VFIO_IOMMU_MSI_GEOMETRY_RESERVED) {
> +        return;
> +    }
> +
> +    /*
> +     * MSI must be iommu mapped: allocate a GPA region located on the
> +     * platform bus that the host will be able to use for MSI IOVA allocation
> +     */
> +    reserved_reg = memory_region_find_by_name(as->root, "reserved-iova");
> +    if (reserved_reg) {
> +        memory_region_unref(reserved_reg);
> +        return;
> +    }
> +
> +    pbus_region = memory_region_find_by_name(as->root, "platform bus");
> +    if (!pbus_region) {
> +        error_setg(errp, "no platform bus memory container found");
> +        return;
> +    }
> +    pbus = container_of(pbus_region, PlatformBusDevice, mmio);
> +    reserved_reg = g_new0(MemoryRegion, 1);
> +    memory_region_init_reserved_iova(reserved_reg, OBJECT(pbus),
> +                                     "reserved-iova",
> +                                     msi_geometry->size, &error_fatal);
> +    platform_bus_map_region(pbus, reserved_reg);
> +    memory_region_unref(pbus_region);
> +}
>  
>  static int vfio_connect_container(VFIOGroup *group, AddressSpace *as)
>  {
>      VFIOContainer *container;
>      int ret, fd;
>      VFIOAddressSpace *space;
> +    Error *err;
A last minute change related to future vfio realize migration that I
forgot to test. err needs to be initialized to NULL here.

Will re-post. Sorry for the inconvience.

Thanks

Eric
>  
>      space = vfio_get_address_space(as);
>  
> @@ -1011,6 +1077,14 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as)
>           * going to actually try in practice.
>           */
>          vfio_get_iommu_type1_info(fd, &pinfo);
> +        vfio_prepare_msi_mapping(pinfo, as, &err);
> +        if (err) {
> +            error_append_hint(&err,
> +                      "Make sure your machine instantiate a platform bus\n");
> +            error_report_err(err);
> +            goto free_container_exit;
> +        }
> +
>          /* Ignore errors */
>          if (ret || !(pinfo->flags & VFIO_IOMMU_INFO_PGSIZES)) {
>              /* Assume 4k IOVA page size */
> 

  reply	other threads:[~2016-10-06 10:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-06  9:50 [Qemu-devel] [RFC v3 0/8] KVM PCI/MSI passthrough with mach-virt Eric Auger
2016-10-06  9:50 ` [Qemu-devel] [RFC v3 1/8] linux-headers: Partial update for MSI IOVA handling Eric Auger
2016-10-06  9:50 ` [Qemu-devel] [RFC v3 2/8] hw: vfio: common: vfio_get_iommu_type1_info Eric Auger
2016-10-06  9:50 ` [Qemu-devel] [RFC v3 3/8] hw: vfio: common: Introduce vfio_register_msi_iova Eric Auger
2016-10-06  9:50 ` [Qemu-devel] [RFC v3 4/8] memory: Add reserved_iova region type Eric Auger
2016-10-06  9:50 ` [Qemu-devel] [RFC v3 5/8] memory: memory_region_find_by_name Eric Auger
2016-10-06  9:50 ` [Qemu-devel] [RFC v3 6/8] hw: platform-bus: Enable to map any memory region onto the platform-bus Eric Auger
2016-10-06  9:50 ` [Qemu-devel] [RFC v3 7/8] hw: vfio: common: vfio_prepare_msi_mapping Eric Auger
2016-10-06 10:51   ` Auger Eric [this message]
2016-10-06  9:50 ` [Qemu-devel] [RFC v3 8/8] hw: vfio: common: Adapt vfio_listeners for reserved_iova region Eric Auger

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=6bf03996-bade-6a19-cc39-2e5bda8b59d5@redhat.com \
    --to=eric.auger@redhat.com \
    --cc=Bharat.Bhushan@freescale.com \
    --cc=alex.williamson@redhat.com \
    --cc=christoffer.dall@linaro.org \
    --cc=diana.craciun@freescale.com \
    --cc=drjones@redhat.com \
    --cc=eric.auger.pro@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=pranav.sawargaonkar@gmail.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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).