qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v3 11/34] memory: add memory_region_is_mapped()


From: Peter Crosthwaite
Subject: Re: [Qemu-devel] [PATCH v3 11/34] memory: add memory_region_is_mapped() API
Date: Fri, 30 May 2014 00:22:26 +1000

On Tue, May 27, 2014 at 11:01 PM, Igor Mammedov <address@hidden> wrote:
> which allows to check if MemoryRegion is already mapped.
>
> Signed-off-by: Igor Mammedov <address@hidden>
> ---
>  include/exec/memory.h |    8 ++++++++
>  memory.c              |   15 ++++++++++++++-
>  2 files changed, 22 insertions(+), 1 deletions(-)
>
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index 1d55ad9..ab11c32 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -848,6 +848,14 @@ void memory_region_set_alias_offset(MemoryRegion *mr,
>  bool memory_region_present(MemoryRegion *parent, hwaddr addr);
>
>  /**
> + * memory_region_is_mapped: returns true if #MemoryRegion is mapped
> + * into any address space.
> + *
> + * @mr: a #MemoryRegion which should be checked if it's mapped
> + */
> +bool memory_region_is_mapped(MemoryRegion *mr);
> +
> +/**
>   * memory_region_find: translate an address/size relative to a
>   * MemoryRegion into a #MemoryRegionSection.
>   *
> diff --git a/memory.c b/memory.c
> index 3f1df23..f4d8e69 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -492,7 +492,7 @@ static AddressSpace 
> *memory_region_to_address_space(MemoryRegion *mr)
>              return as;
>          }
>      }
> -    abort();
> +    return NULL;
>  }
>
>  /* Render a memory region into the global view.  Ranges in @view obscure
> @@ -1569,6 +1569,16 @@ bool memory_region_present(MemoryRegion *parent, 
> hwaddr addr)
>      return true;
>  }
>
> +bool memory_region_is_mapped(MemoryRegion *mr)
> +{

Is it not enough to just return mr->parent? Memory mapping assertion
will happen if you try and map the same twice, even if one of the
mappings is not contained within an AddressSpace. Checking for just
the parent mr may be a simpler and more accurate check.

Regards,
Peter

> +    mr = memory_region_find(mr, 0, 1).mr;
> +    if (!mr) {
> +        return false;
> +    }
> +    memory_region_unref(mr);
> +    return true;
> +}
> +
>  MemoryRegionSection memory_region_find(MemoryRegion *mr,
>                                         hwaddr addr, uint64_t size)
>  {
> @@ -1586,6 +1596,9 @@ MemoryRegionSection memory_region_find(MemoryRegion *mr,
>      }
>
>      as = memory_region_to_address_space(root);
> +    if (!as) {
> +        return ret;
> +    }
>      range = addrrange_make(int128_make64(addr), int128_make64(size));
>
>      view = address_space_get_flatview(as);
> --
> 1.7.1
>
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]