[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH V2 9/25] tools/libxl: build DMAR table for a guest with one virtual VTD



On Wed, Aug 09, 2017 at 04:34:10PM -0400, Lan Tianyu wrote:
> diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c
> index f54fd49..94c9196 100644
> --- a/tools/libxl/libxl_dom.c
> +++ b/tools/libxl/libxl_dom.c
> @@ -1060,6 +1060,42 @@ static int libxl__domain_firmware(libxl__gc *gc,
>          }
>      }
>  
> +    /*
> +     * If a guest has one virtual VTD, build DMAR table for it and joint this
> +     * table with existing content in acpi_modules in order to employ HVM
> +     * firmware pass-through mechanism to pass-through DMAR table.
> +     */
> +    if (info->viommu.type == LIBXL_VIOMMU_TYPE_INTEL_VTD) {
> +        datalen = 0;
> +        e = libxl__dom_build_dmar(gc, info, dom, &data, &datalen);
> +        if (e) {
> +            LOGEV(ERROR, e, "failed to build DMAR table");
> +            rc = ERROR_FAIL;
> +            goto out;
> +        }
> +        if (datalen) {
> +            libxl__ptr_add(gc, data);
> +            if (!dom->acpi_modules[0].data) {
> +                dom->acpi_modules[0].data = data;
> +                dom->acpi_modules[0].length = (uint32_t)datalen;
> +            } else {
> +                /* joint tables */
> +                void *newdata;
> +                newdata = malloc(datalen + dom->acpi_modules[0].length);

All memory allocations in libxl should use libxl__*lloc wrappers.

> +                if (!newdata) {
> +                    LOGE(ERROR, "failed to joint DMAR table to acpi 
> modules");
> +                    rc = ERROR_FAIL;
> +                    goto out;
> +                }
> +                memcpy(newdata, dom->acpi_modules[0].data,
> +                       dom->acpi_modules[0].length);
> +                memcpy(newdata + dom->acpi_modules[0].length, data, datalen);
> +                dom->acpi_modules[0].data = newdata;
> +                dom->acpi_modules[0].length += (uint32_t)datalen;
> +            }
> +        }
> +    }

This still looks wrong to me. How do you know acpi_modules[0] is DMAR
table?

You should have a look at libxl_x86_acpi.c and work out a proper
solution.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.