On 18/03/2019 17:37, Roger Pau Monne wrote:
> Or if it's not possible to honor the hinted address an error is returned
> instead. This makes it easier to spot the actual failure, instead of
> failing later on when the caller of xen_remap_bucket realizes the
> mapping has not been created at the requested address.
> 
> Also note that at least on FreeBSD using MAP_FIXED will cause mmap to
> try harder to honor the passed address.
> 
> Signed-off-by: Roger Pau Monné <roger....@citrix.com>
> Reviewed-by: Paul Durrant <paul.durr...@citrix.com>
> ---
> Cc: Stefano Stabellini <sstabell...@kernel.org>
> Cc: Anthony Perard <anthony.per...@citrix.com>
> Cc: Paul Durrant <paul.durr...@citrix.com>
> Cc: Igor Druzhinin <igor.druzhi...@citrix.com>
> Cc: Paolo Bonzini <pbonz...@redhat.com>
> Cc: Richard Henderson <r...@twiddle.net>
> Cc: Eduardo Habkost <ehabk...@redhat.com>
> Cc: "Michael S. Tsirkin" <m...@redhat.com>
> Cc: Marcel Apfelbaum <marcel.apfelb...@gmail.com>
> Cc: xen-de...@lists.xenproject.org
> ---
> Changes since v2:
>  - Move comment position.
> 
> Changes since v1:
>  - Use MAP_FIXED for the dummy mmap call also if a specific virtual
>    address is requested.
> ---
>  hw/i386/xen/xen-mapcache.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/i386/xen/xen-mapcache.c b/hw/i386/xen/xen-mapcache.c
> index 349f72d00c..254759f776 100644
> --- a/hw/i386/xen/xen-mapcache.c
> +++ b/hw/i386/xen/xen-mapcache.c
> @@ -184,9 +184,14 @@ static void xen_remap_bucket(MapCacheEntry *entry,
>          pfns[i] = (address_index << (MCACHE_BUCKET_SHIFT-XC_PAGE_SHIFT)) + i;
>      }
>  
> +    /*
> +     * If the caller has requested the mapping at a specific address use
> +     * MAP_FIXED to make sure it's honored.
> +     */
>      if (!dummy) {
>          vaddr_base = xenforeignmemory_map2(xen_fmem, xen_domid, vaddr,
> -                                           PROT_READ | PROT_WRITE, 0,
> +                                           PROT_READ | PROT_WRITE,
> +                                           vaddr ? MAP_FIXED : 0,
>                                             nb_pfn, pfns, err);
>          if (vaddr_base == NULL) {
>              perror("xenforeignmemory_map2");
> @@ -198,7 +203,8 @@ static void xen_remap_bucket(MapCacheEntry *entry,
>           * mapping immediately due to certain circumstances (i.e. on resume 
> now)
>           */
>          vaddr_base = mmap(vaddr, size, PROT_READ | PROT_WRITE,
> -                          MAP_ANON | MAP_SHARED, -1, 0);
> +                          MAP_ANON | MAP_SHARED | (vaddr ? MAP_FIXED : 0),
> +                          -1, 0);
>          if (vaddr_base == MAP_FAILED) {
>              perror("mmap");
>              exit(-1);
> 

Reviewed-by: Igor Druzhinin <igor.druzhi...@cirtix.com>

Igor

Reply via email to