diff mbox

[v2,6/7] exec: Factor out section_covers_addr

Message ID 1456813104-25902-7-git-send-email-famz@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Fam Zheng March 1, 2016, 6:18 a.m. UTC
This will be shared by the next patch.

Also add a comment explaining the unobvious condition on "size.hi".

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 exec.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Comments

Peter Xu March 1, 2016, 7:23 a.m. UTC | #1
On Tue, Mar 01, 2016 at 02:18:23PM +0800, Fam Zheng wrote:
> This will be shared by the next patch.
> 
> Also add a comment explaining the unobvious condition on "size.hi".
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>

Reviewed-by: Peter Xu <peterx@redhat.com>

> ---
>  exec.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index ad8b826..b4e2eb5 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -307,6 +307,16 @@ static void phys_page_compact_all(AddressSpaceDispatch *d, int nodes_nb)
>      }
>  }
>  
> +static inline bool section_covers_addr(const MemoryRegionSection *section,
> +                                       hwaddr addr)
> +{
> +    /* Memory topology clips a memory region to 2^64, size.hi >= 0 means the
> +     * section must cover any addr. */
> +    return section->size.hi ||
> +           range_covers_byte(section->offset_within_address_space,
> +                             section->size.lo, addr);
> +}
> +
>  static MemoryRegionSection *phys_page_find(PhysPageEntry lp, hwaddr addr,
>                                             Node *nodes, MemoryRegionSection *sections)
>  {
> @@ -322,9 +332,7 @@ static MemoryRegionSection *phys_page_find(PhysPageEntry lp, hwaddr addr,
>          lp = p[(index >> (i * P_L2_BITS)) & (P_L2_SIZE - 1)];
>      }
>  
> -    if (sections[lp.ptr].size.hi ||
> -        range_covers_byte(sections[lp.ptr].offset_within_address_space,
> -                          sections[lp.ptr].size.lo, addr)) {
> +    if (section_covers_addr(&sections[lp.ptr], addr)) {
>          return &sections[lp.ptr];
>      } else {
>          return &sections[PHYS_SECTION_UNASSIGNED];
> -- 
> 2.4.3
>
Paolo Bonzini March 1, 2016, 9:42 a.m. UTC | #2
On 01/03/2016 07:18, Fam Zheng wrote:
> +    /* Memory topology clips a memory region to 2^64, size.hi >= 0 means the
> +     * section must cover any addr. */

Small improvement:

    /* Memory topology clips a memory region to [0, 2^64); size.hi > 0 means
     * the section must cover the entire address space.
     */

Paolo
Fam Zheng March 2, 2016, 2:24 a.m. UTC | #3
On Tue, 03/01 10:42, Paolo Bonzini wrote:
> 
> 
> On 01/03/2016 07:18, Fam Zheng wrote:
> > +    /* Memory topology clips a memory region to 2^64, size.hi >= 0 means the
> > +     * section must cover any addr. */
> 
> Small improvement:
> 
>     /* Memory topology clips a memory region to [0, 2^64); size.hi > 0 means
>      * the section must cover the entire address space.
>      */

Better! Thanks.

Fam
diff mbox

Patch

diff --git a/exec.c b/exec.c
index ad8b826..b4e2eb5 100644
--- a/exec.c
+++ b/exec.c
@@ -307,6 +307,16 @@  static void phys_page_compact_all(AddressSpaceDispatch *d, int nodes_nb)
     }
 }
 
+static inline bool section_covers_addr(const MemoryRegionSection *section,
+                                       hwaddr addr)
+{
+    /* Memory topology clips a memory region to 2^64, size.hi >= 0 means the
+     * section must cover any addr. */
+    return section->size.hi ||
+           range_covers_byte(section->offset_within_address_space,
+                             section->size.lo, addr);
+}
+
 static MemoryRegionSection *phys_page_find(PhysPageEntry lp, hwaddr addr,
                                            Node *nodes, MemoryRegionSection *sections)
 {
@@ -322,9 +332,7 @@  static MemoryRegionSection *phys_page_find(PhysPageEntry lp, hwaddr addr,
         lp = p[(index >> (i * P_L2_BITS)) & (P_L2_SIZE - 1)];
     }
 
-    if (sections[lp.ptr].size.hi ||
-        range_covers_byte(sections[lp.ptr].offset_within_address_space,
-                          sections[lp.ptr].size.lo, addr)) {
+    if (section_covers_addr(&sections[lp.ptr], addr)) {
         return &sections[lp.ptr];
     } else {
         return &sections[PHYS_SECTION_UNASSIGNED];