Skip to contentSkip to conversation

Refine exec

PATCH Applied Wei Yang 3 participants 12 messages Apr 22, 2019 – Sep 16, 2019 2 messages not in the archive

lore
Share & tools
lore

Wei Yang

author
#1 lore raw
In reply to a message not in the archive

Ping for this trivial series.

Quoted 16 lines · Wei Yang

This serial refine exec a little.

Wei Yang (6):
exec.c: replace hwaddr with uint64_t for better understanding exec.c: remove an unnecessary assert on PHYS_MAP_NODE_NIL in
phys_map_node_alloc()
exec.c: get nodes_nb_alloc with one MAX calculation exec.c: subpage->sub_section is already initialized to 0 exec.c: correct the maximum skip value during compact exec.c: add a check between constants to see whether we could skip

exec.c | 21 ++++++++++-----------

1 file changed, 10 insertions(+), 11 deletions(-)
Signature · 1 line
2.19.1
Signature · 2 lines
Wei Yang
Help you, Help me
author
#2 lore raw
In reply to a message not in the archive
Quoted 2 lines · Wei Yang

This serial refine exec a little.

Ping again.

Quoted 14 lines

Wei Yang (6):
exec.c: replace hwaddr with uint64_t for better understanding exec.c: remove an unnecessary assert on PHYS_MAP_NODE_NIL in
phys_map_node_alloc()
exec.c: get nodes_nb_alloc with one MAX calculation exec.c: subpage->sub_section is already initialized to 0 exec.c: correct the maximum skip value during compact exec.c: add a check between constants to see whether we could skip

exec.c | 21 ++++++++++-----------

1 file changed, 10 insertions(+), 11 deletions(-)
Signature · 1 line
2.19.1
Signature · 2 lines
Wei Yang
Help you, Help me
#6 lore raw

Re: [Qemu-devel] [PATCH 2/6] exec.c: remove an unnecessary assert on PHYS_MAP_NODE_NIL in phys_map_node_alloc()

In reply to a message not in the archive
Quoted 4 lines · Wei Yang

PHYS_MAP_NODE_NIL is assigned to PhysPageEntry.ptr in case this is not a leaf entry, while map->nodes_nb range in [0, nodes_nb_alloc).

Seems we are asserting on two different things, just remove it.

The assertion checks that this "if" is not entered incorrectly:

    if (lp->skip && lp->ptr == PHYS_MAP_NODE_NIL) {
        lp->ptr = phys_map_node_alloc(map, level == 0);
    }

Paolo

Quoted 18 lines
---
 exec.c | 1 -
 1 file changed, 1 deletion(-)
exec.c +0 -1
index 98ebd0dd1d..8e8b6bb1f9 100644
@@ -242,7 +242,6 @@ static uint32_t phys_map_node_alloc(PhysPageMap *map, bool leaf)
 
     ret = map->nodes_nb++;
     p = map->nodes[ret];
-    assert(ret != PHYS_MAP_NODE_NIL);
     assert(ret != map->nodes_nb_alloc);
 
     e.skip = leaf ? 0 : 1;
#3 lore raw
In reply to Wei Yang
Quoted 5 lines · Wei Yang
Quoted 2 lines · Wei Yang

This serial refine exec a little.

Ping again.

Queued all except 2, thanks!

Paolo

Quoted 15 lines
Quoted 14 lines

Wei Yang (6):
exec.c: replace hwaddr with uint64_t for better understanding exec.c: remove an unnecessary assert on PHYS_MAP_NODE_NIL in
phys_map_node_alloc()
exec.c: get nodes_nb_alloc with one MAX calculation exec.c: subpage->sub_section is already initialized to 0 exec.c: correct the maximum skip value during compact exec.c: add a check between constants to see whether we could skip

exec.c | 21 ++++++++++-----------

1 file changed, 10 insertions(+), 11 deletions(-)
Signature · 1 line
2.19.1
#4 lore raw
Quoted 9 lines · Paolo Bonzini
Quoted 5 lines · Wei Yang
Quoted 2 lines · Wei Yang

This serial refine exec a little.

Ping again.

Queued all except 2, thanks!

Thanks~

Quoted 18 lines

Paolo

Quoted 15 lines
Quoted 14 lines

Wei Yang (6):
exec.c: replace hwaddr with uint64_t for better understanding exec.c: remove an unnecessary assert on PHYS_MAP_NODE_NIL in
phys_map_node_alloc()
exec.c: get nodes_nb_alloc with one MAX calculation exec.c: subpage->sub_section is already initialized to 0 exec.c: correct the maximum skip value during compact exec.c: add a check between constants to see whether we could skip

exec.c | 21 ++++++++++-----------

1 file changed, 10 insertions(+), 11 deletions(-)
Signature · 1 line
2.19.1
Signature · 2 lines
Wei Yang
Help you, Help me
author
#7 lore raw

Re: [Qemu-devel] [PATCH 2/6] exec.c: remove an unnecessary assert on PHYS_MAP_NODE_NIL in phys_map_node_alloc()

In reply to Paolo Bonzini
Quoted 4 lines · Paolo Bonzini
Quoted 3 lines · Wei Yang

PHYS_MAP_NODE_NIL is assigned to PhysPageEntry.ptr in case this is not a leaf entry, while map->nodes_nb range in [0, nodes_nb_alloc).

Quoted 8 lines
Quoted 1 line

Seems we are asserting on two different things, just remove it.

The assertion checks that this "if" is not entered incorrectly:

   if (lp->skip && lp->ptr == PHYS_MAP_NODE_NIL) {
       lp->ptr = phys_map_node_alloc(map, level == 0);
   }

Hmm... I may not get your point.

phys_map_node_alloc() will get an available PhysPageEntry and return its index, which will be assigned to its parent's ptr.

The "if" checks on the parent's ptr, while the assertion asserts the index for the new child. I may miss something?

Quoted 20 lines

Paolo

Quoted 18 lines
---
 exec.c | 1 -
 1 file changed, 1 deletion(-)
exec.c +0 -1
index 98ebd0dd1d..8e8b6bb1f9 100644
@@ -242,7 +242,6 @@ static uint32_t phys_map_node_alloc(PhysPageMap *map, bool leaf)
 
     ret = map->nodes_nb++;
     p = map->nodes[ret];
-    assert(ret != PHYS_MAP_NODE_NIL);
     assert(ret != map->nodes_nb_alloc);
 
     e.skip = leaf ? 0 : 1;
Signature · 2 lines
Wei Yang
Help you, Help me
author
#8 lore raw

Re: [Qemu-devel] [PATCH 2/6] exec.c: remove an unnecessary assert on PHYS_MAP_NODE_NIL in phys_map_node_alloc()

Quoted 14 lines · Wei Yang
Quoted 4 lines · Paolo Bonzini
Quoted 3 lines · Wei Yang

PHYS_MAP_NODE_NIL is assigned to PhysPageEntry.ptr in case this is not a leaf entry, while map->nodes_nb range in [0, nodes_nb_alloc).

Quoted 8 lines
Quoted 1 line

Seems we are asserting on two different things, just remove it.

The assertion checks that this "if" is not entered incorrectly:

   if (lp->skip && lp->ptr == PHYS_MAP_NODE_NIL) {
       lp->ptr = phys_map_node_alloc(map, level == 0);
   }
Quoted 8 lines

Hmm... I may not get your point.

phys_map_node_alloc() will get an available PhysPageEntry and return its index, which will be assigned to its parent's ptr.

The "if" checks on the parent's ptr, while the assertion asserts the index for the new child. I may miss something?

Hi, Paolo,

Do I miss something?

Signature · 2 lines
Wei Yang
Help you, Help me
#9 lore raw

Re: [Qemu-devel] [PATCH 2/6] exec.c: remove an unnecessary assert on PHYS_MAP_NODE_NIL in phys_map_node_alloc()

Quoted 20 lines · Wei Yang
Quoted 19 lines · Wei Yang
Quoted 4 lines · Paolo Bonzini
Quoted 3 lines · Wei Yang

PHYS_MAP_NODE_NIL is assigned to PhysPageEntry.ptr in case this is not a leaf entry, while map->nodes_nb range in [0, nodes_nb_alloc).

Quoted 8 lines
Quoted 1 line

Seems we are asserting on two different things, just remove it.

The assertion checks that this "if" is not entered incorrectly:

   if (lp->skip && lp->ptr == PHYS_MAP_NODE_NIL) {
       lp->ptr = phys_map_node_alloc(map, level == 0);
   }

Hmm... I may not get your point.

phys_map_node_alloc() will get an available PhysPageEntry and return its index, which will be assigned to its parent's ptr.

Quoted 7 lines
Quoted 3 lines

The "if" checks on the parent's ptr, while the assertion asserts the index for the new child. I may miss something?

Hi, Paolo,

Do I miss something?

Sorry, I was on vacation. phys_page_set_level can be called multiple times, with the same lp. The assertion checks that only the first call will reach phys_map_node_alloc.

Paolo

#10 lore raw

Re: [Qemu-devel] [PATCH 2/6] exec.c: remove an unnecessary assert on PHYS_MAP_NODE_NIL in phys_map_node_alloc()

Quoted 25 lines · Paolo Bonzini
Quoted 24 lines · Wei Yang
Quoted 22 lines · Wei Yang
Quoted 4 lines · Paolo Bonzini
Quoted 3 lines · Wei Yang

PHYS_MAP_NODE_NIL is assigned to PhysPageEntry.ptr in case this is not a leaf entry, while map->nodes_nb range in [0, nodes_nb_alloc).

Quoted 8 lines
Quoted 1 line

Seems we are asserting on two different things, just remove it.

The assertion checks that this "if" is not entered incorrectly:

   if (lp->skip && lp->ptr == PHYS_MAP_NODE_NIL) {
       lp->ptr = phys_map_node_alloc(map, level == 0);
   }

Hmm... I may not get your point.

phys_map_node_alloc() will get an available PhysPageEntry and return its index, which will be assigned to its parent's ptr.

The "if" checks on the parent's ptr, while the assertion asserts the index for the new child. I may miss something?

Quoted 8 lines
Quoted 3 lines

Hi, Paolo,

Do I miss something?

Sorry, I was on vacation. phys_page_set_level can be called multiple times, with the same lp. The assertion checks that only the first call will reach phys_map_node_alloc.

Ah, I am just back from vacation too. The mountain makes me painful. :-)

So I guess you are talking about the situation of wrap around. PHYS_MAP_NODE_NIL is an indicator that this lp is not used yet. And we are not expecting any valid lp has its ptr with value equal or bigger than PHYS_MAP_NODE_NIL.

If this is the case, I am thinking this won't happen in current implementation. Because if my understanding is correct, the total number of PhysPageEntry would be less than PHYS_MAP_NODE_NIL.

First let's look at the PHYS_MAP_NODE_NIL's value

    PHYS_MAP_NODE_NIL = 2^26 = 6710 8864.

So we could represent 6710 8864 PhysPageEntry at most.

Then let's look how many PhysPageEntry would be. The PhysPageEntry structure forms a tree with 9 nodes on each level with P_L2_LEVELS levels. This means the tree could have 9^P_L2_LEVELS nodes at most.

Since

#define ADDR_SPACE_BITS 64
#define P_L2_BITS 9
#define P_L2_LEVELS (((ADDR_SPACE_BITS - TARGET_PAGE_BITS - 1) / P_L2_BITS) + 1)

And TARGET_PAGE_BITS >= 12, so P_L2_LEVELS is smaller than

    7 = (64 - 12 - 1) / 9 + 1.

This leads to

    9^P_L2_LEVELS <= 9^7 = 478 2969

It shows PHYS_MAP_NODE_NIL may represents more node the tree could hold.

The assert here is not harmful, while maybe we can have a better way to handle it?

Quoted 1 line

Paolo

Signature · 2 lines
Wei Yang
Help you, Help me
#11 lore raw

Re: [Qemu-devel] [PATCH 2/6] exec.c: remove an unnecessary assert on PHYS_MAP_NODE_NIL in phys_map_node_alloc()

Quoted 1 line · Wei Yang

It shows PHYS_MAP_NODE_NIL may represents more node the tree could hold.

Which is good, it means the assert can trigger.

Quoted 2 lines

The assert here is not harmful, while maybe we can have a better way to handle it?

I don't know... The assert just says "careful, someone treats PHYS_MAP_NODE_NIL specially!". It's documentation too.

Paolo

author
#12 lore raw

Re: [Qemu-devel] [PATCH 2/6] exec.c: remove an unnecessary assert on PHYS_MAP_NODE_NIL in phys_map_node_alloc()

Quoted 5 lines · Paolo Bonzini
Quoted 1 line · Wei Yang

It shows PHYS_MAP_NODE_NIL may represents more node the tree could hold.

Which is good, it means the assert can trigger.

Per my understanding, it means the assert can't trigger.

Quoted 7 lines
Quoted 2 lines

The assert here is not harmful, while maybe we can have a better way to handle it?

I don't know... The assert just says "careful, someone treats PHYS_MAP_NODE_NIL specially!". It's documentation too.

Paolo

Signature · 2 lines
Wei Yang
Help you, Help me
#13 lore raw

Re: [Qemu-devel] [PATCH 2/6] exec.c: remove an unnecessary assert on PHYS_MAP_NODE_NIL in phys_map_node_alloc()

Quoted 8 lines · Wei Yang
Quoted 5 lines · Paolo Bonzini
Quoted 1 line · Wei Yang

It shows PHYS_MAP_NODE_NIL may represents more node the tree could hold.

Which is good, it means the assert can trigger.

Per my understanding, it means the assert can't trigger.

You're right, sorry. That's what I meant.

Paolo

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

The assert here is not harmful, while maybe we can have a better way to handle it?

I don't know... The assert just says "careful, someone treats PHYS_MAP_NODE_NIL specially!". It's documentation too.

Paolo