[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [RFC v3 7/8] hw: vfio: common: vfio_prepare_msi_mapping
From: |
Auger Eric |
Subject: |
Re: [Qemu-devel] [RFC v3 7/8] hw: vfio: common: vfio_prepare_msi_mapping |
Date: |
Thu, 6 Oct 2016 12:51:48 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 |
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 <address@hidden>
>
> ---
>
> 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 */
>
- [Qemu-devel] [RFC v3 0/8] KVM PCI/MSI passthrough with mach-virt, Eric Auger, 2016/10/06
- [Qemu-devel] [RFC v3 2/8] hw: vfio: common: vfio_get_iommu_type1_info, Eric Auger, 2016/10/06
- [Qemu-devel] [RFC v3 1/8] linux-headers: Partial update for MSI IOVA handling, Eric Auger, 2016/10/06
- [Qemu-devel] [RFC v3 3/8] hw: vfio: common: Introduce vfio_register_msi_iova, Eric Auger, 2016/10/06
- [Qemu-devel] [RFC v3 4/8] memory: Add reserved_iova region type, Eric Auger, 2016/10/06
- [Qemu-devel] [RFC v3 5/8] memory: memory_region_find_by_name, Eric Auger, 2016/10/06
- [Qemu-devel] [RFC v3 6/8] hw: platform-bus: Enable to map any memory region onto the platform-bus, Eric Auger, 2016/10/06
- [Qemu-devel] [RFC v3 8/8] hw: vfio: common: Adapt vfio_listeners for reserved_iova region, Eric Auger, 2016/10/06
- [Qemu-devel] [RFC v3 7/8] hw: vfio: common: vfio_prepare_msi_mapping, Eric Auger, 2016/10/06
- Re: [Qemu-devel] [RFC v3 7/8] hw: vfio: common: vfio_prepare_msi_mapping,
Auger Eric <=