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

Re: [Xen-devel] [v6][PATCH 3/7] tools/libxc: check if mmio BAR is out of reserved device memory maps



> From: Chen, Tiejun
> Sent: Tuesday, September 09, 2014 10:50 PM
> 
> We need to avoid allocating MMIO BAR conflicting to all reserved device
> memory range.

besides checking MMIO BAR confliction, you also need check guest memory
confliction with reserved device memory ranges.

> 
> Signed-off-by: Tiejun Chen <tiejun.chen@xxxxxxxxx>
> 
> diff --git a/tools/libxc/xc_hvm_build_x86.c b/tools/libxc/xc_hvm_build_x86.c
> index c81a25b..299e33a 100644
> --- a/tools/libxc/xc_hvm_build_x86.c
> +++ b/tools/libxc/xc_hvm_build_x86.c
> @@ -239,6 +239,73 @@ static int check_mmio_hole(uint64_t start, uint64_t
> memsize,
>          return 1;
>  }
> 
> +/*
> + * Check whether there exists mmio overplap with the reserved device
> + * memory map
> + */
> +static int check_rdm_overlap(xc_interface *xch, uint64_t mmio_start,
> +                             uint64_t mmio_size)
> +{
> +    struct xen_mem_reserved_device_memory *map = NULL;

If there are multiple callers of this call, better to move the structure out of
this function to avoid multiple calls.

> +    uint64_t rdm_start = 0, rdm_end = 0;
> +    unsigned int i = 0;
> +    int rc = 0;
> +    /* Assume we have one entry if not enough we'll expand.*/
> +    uint32_t nr_entries = 1;
> +
> +    /* We should check if mmio range is out of RDM mapping. */
> +    if ( (map = malloc(nr_entries *
> +                       sizeof(xen_mem_reserved_device_memory_t)))
> == NULL )
> +    {
> +        PERROR("Could not allocate memory for map.");
> +        return -1;
> +    }
> +    rc = xc_reserved_device_memory_map(xch, map, &nr_entries);
> +    if ( rc < 0 )
> +    {
> +        /* DRM doesn't exist. */
> +        if ( rc == -ENOENT )
> +            rc = 0;
> +        else if ( rc == -ENOBUFS)
> +        {
> +            free(map);
> +            /* Now we need more space to map all RDM mappings. */
> +            if ( (map = malloc(nr_entries *
> +
> sizeof(xen_mem_reserved_device_memory_t))) == NULL )
> +            {
> +                PERROR("Could not allocate memory for map.");
> +                return -1;
> +            }
> +            rc = xc_reserved_device_memory_map(xch, map,
> &nr_entries);
> +            if ( rc < 0 )
> +            {
> +                PERROR("Could not get DRM info on domain");
> +                free(map);
> +                return rc;
> +            }
> +        }
> +        else
> +            PERROR("Could not get RDM info on domain");
> +    }
> +
> +    for ( i = 0; i < rc; i++ )
> +    {
> +        rdm_start = map[i].start_pfn << PAGE_SHIFT;
> +        rdm_end = rdm_start + map[i].nr_pages * PAGE_SIZE;
> +        if ( check_mmio_hole(rdm_start, map[i].nr_pages * PAGE_SIZE,
> +                             mmio_start, mmio_size) )
> +        {
> +            PERROR("MMIO: [%lx]<->[%lx] overlap DRM [%lx]<->[%lx]\n",
> +                   mmio_start, (mmio_start + mmio_size), rdm_start,
> rdm_end);
> +            free(map);
> +            return -1;
> +        }
> +    }
> +
> +    free(map);
> +    return rc;
> +}
> +
>  static int setup_guest(xc_interface *xch,
>                         uint32_t dom, struct xc_hvm_build_args *args,
>                         char *image, unsigned long image_size)
> @@ -300,6 +367,10 @@ static int setup_guest(xc_interface *xch,
>          goto error_out;
>      }
> 
> +    rc = check_rdm_overlap(xch, mmio_start, mmio_start);

mmio_start -> mmio_size.

> +    if ( rc < 0 )
> +        goto error_out;
> +
>      for ( i = 0; i < nr_pages; i++ )
>          page_array[i] = i;
>      for ( i = mmio_start >> PAGE_SHIFT; i < nr_pages; i++ )
> --
> 1.9.1


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


 


Rackspace

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