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

Re: [Xen-devel] [PATCH 6/7] x86: add iommu_op to query reserved ranges



>>> On 12.02.18 at 11:47, <paul.durrant@xxxxxxxxxx> wrote:
> --- a/xen/arch/x86/iommu_op.c
> +++ b/xen/arch/x86/iommu_op.c
> @@ -22,6 +22,58 @@
>  #include <xen/event.h>
>  #include <xen/guest_access.h>
>  #include <xen/hypercall.h>
> +#include <xen/iommu.h>
> +
> +struct get_rdm_ctxt {
> +    unsigned int max_entries;
> +    unsigned int nr_entries;
> +    XEN_GUEST_HANDLE(xen_iommu_reserved_region_t) regions;
> +};
> +
> +static int get_rdm(xen_pfn_t start, xen_ulong_t nr, u32 id, void *arg)
> +{
> +    struct get_rdm_ctxt *ctxt = arg;
> +
> +    if ( ctxt->nr_entries < ctxt->max_entries )
> +    {
> +        xen_iommu_reserved_region_t region = {
> +            .start_bfn = start,
> +            .nr_frames = nr,
> +        };
> +
> +        if ( copy_to_guest_offset(ctxt->regions, ctxt->nr_entries, &region,
> +                                  1) )
> +            return -EFAULT;
> +    }
> +
> +    ctxt->nr_entries++;
> +
> +    return 1;
> +}
> +
> +static int iommuop_query_reserved(struct xen_iommu_op_query_reserved *op)
> +{
> +    struct get_rdm_ctxt ctxt = {
> +        .max_entries = op->nr_entries,
> +        .regions = op->regions,
> +    };
> +    int rc;
> +
> +    if (op->pad != 0)
> +        return -EINVAL;
> +
> +    rc = iommu_get_reserved_device_memory(get_rdm, &ctxt);
> +    if ( rc )
> +        return rc;
> +
> +    /* Pass back the actual number of reserved regions */
> +    op->nr_entries = ctxt.nr_entries;
> +
> +    if ( ctxt.nr_entries > ctxt.max_entries )
> +        return -ENOBUFS;
> +
> +    return 0;
> +}

One more note here: As it looks we can only hope there won't be
too many RMRRs, as the number of entries that can be requested
here is basically unbounded.

Jan


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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