xen/arm: p2m: Don't create new table when the mapping is removed
PATCH 1/1 xen/arm: p2m: Don't create new table when the mapping is removed
When Xen is removing/relinquishing mapping, it will create second/third tables if they don't exist.
Non-existent table means the address range was never mapped, so Xen can safely skip them.
---
Release: This is an improvement for Xen 4.4. It will save time during relinquish phase and avoid dummy allocation.
The downside is the patch is modifying p2m loop which is used everywhere.
--- xen/arch/arm/p2m.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
xen/arch/arm/p2m.c +20 -2
@@ -246,10 +246,12 @@ static int create_p2m_entries(struct domain *d, cur_first_offset = ~0 , cur_second_offset = ~0 ;unsigned long count =0 ; +bool_t populate = (op ==INSERT || op ==ALLOCATE );spin_lock (&p2m->lock); -for (addr = start_gpaddr; addr < end_gpaddr; addr +=PAGE_SIZE ) + addr = start_gpaddr; +while ( addr < end_gpaddr ) {if ( cur_first_page !=p2m_first_level_index (addr) ) {
@@ -265,8 +267,15 @@ static int create_p2m_entries(struct domain *d,if ( !first[first_table_offset (addr)].p2m.valid ) { +if ( !populate ) + { + addr +=FIRST_SIZE ; +continue ; + } + rc =p2m_create_table (d, &first[first_table_offset (addr)]); -if ( rc <0 ) { +if ( rc <0 ) + {printk ("p2m_populate_ram: L1 failed\n" ); goto out; }
@@ -284,6 +293,12 @@ static int create_p2m_entries(struct domain *d,if ( !second[second_table_offset (addr)].p2m.valid ) { +if ( !populate ) + { + addr +=SECOND_SIZE ; +continue ; + } + rc =p2m_create_table (d, &second[second_table_offset (addr)]);if ( rc <0 ) {printk ("p2m_populate_ram: L2 failed\n" );
@@ -372,6 +387,9 @@ static int create_p2m_entries(struct domain *d, } count =0 ; } + +/* Got the next page */ + addr +=PAGE_SIZE ; }if ( op ==ALLOCATE || op ==INSERT )
Signature · 1 line
1.7.10.4
Quoted 21 lines · Julien Grall
When Xen is removing/relinquishing mapping, it will create second/third tables if they don't exist.
Non-existent table means the address range was never mapped, so Xen can safely skip them.
Signed-off-by Julien Grall <[email protected]>---
Release: This is an improvement for Xen 4.4. It will save time during relinquish phase and avoid dummy allocation.
The downside is the patch is modifying p2m loop which is used everywhere.--- xen/arch/arm/p2m.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)xen/arch/arm/p2m.c +0
-0
xen/arch/arm/p2m.c static int create_p2m_entries(struct domain *d, · line 249
Quoted 4 lines
xen/arch/arm/p2m.c +1
-0@@ -246,10 +246,12 @@ static int create_p2m_entries(struct domain *d, cur_first_offset = ~0 , cur_second_offset = ~0 ;unsigned long count =0 ; +bool_t populate = (op ==INSERT || op ==ALLOCATE );
why don't you just check for op == REMOVE?
Quoted 51 lines
xen/arch/arm/p2m.c +19
-2spin_lock (&p2m->lock); -for (addr = start_gpaddr; addr < end_gpaddr; addr +=PAGE_SIZE ) + addr = start_gpaddr; +while ( addr < end_gpaddr ) {if ( cur_first_page !=p2m_first_level_index (addr) ) {@@ -265,8 +267,15 @@ static int create_p2m_entries(struct domain *d,if ( !first[first_table_offset (addr)].p2m.valid ) { +if ( !populate ) + { + addr +=FIRST_SIZE ; +continue ; + } + rc =p2m_create_table (d, &first[first_table_offset (addr)]); -if ( rc <0 ) { +if ( rc <0 ) + {printk ("p2m_populate_ram: L1 failed\n" ); goto out; }@@ -284,6 +293,12 @@ static int create_p2m_entries(struct domain *d,if ( !second[second_table_offset (addr)].p2m.valid ) { +if ( !populate ) + { + addr +=SECOND_SIZE ; +continue ; + } + rc =p2m_create_table (d, &second[second_table_offset (addr)]);if ( rc <0 ) {printk ("p2m_populate_ram: L2 failed\n" );@@ -372,6 +387,9 @@ static int create_p2m_entries(struct domain *d, } count =0 ; } + +/* Got the next page */ + addr +=PAGE_SIZE ; }if ( op ==ALLOCATE || op ==INSERT )Signature · 1 line
1.7.10.4
Quoted 17 lines · Stefano Stabellini
Quoted 16 lines · Julien Grall
When Xen is removing/relinquishing mapping, it will create second/third tables if they don't exist.
Non-existent table means the address range was never mapped, so Xen can safely skip them.
Signed-off-by Julien Grall <[email protected]>---
Release: This is an improvement for Xen 4.4. It will save time during relinquish phase and avoid dummy allocation.
The downside is the patch is modifying p2m loop which is used everywhere.--- xen/arch/arm/p2m.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
Quoted 11 lines
xen/arch/arm/p2m.c static int create_p2m_entries(struct domain *d, · line 249
Quoted 9 lines
xen/arch/arm/p2m.c +1
-0@@ -246,10 +246,12 @@ static int create_p2m_entries(struct domain *d, cur_first_offset = ~0 , cur_second_offset = ~0 ;unsigned long count =0 ; +bool_t populate = (op ==INSERT || op ==ALLOCATE );why don't you just check for op == REMOVE?
Because you also need to check op == RELINQUISH (added by my patch series on foreign mapping).
Signature · 1 line
Julien Grall
Stefano Stabellini
Acked-byQuoted 33 lines · Julien Grall
Quoted 20 lines · Stefano Stabellini
Quoted 19 lines · Julien Grall
When Xen is removing/relinquishing mapping, it will create second/third tables
if they don't exist.Non-existent table means the address range was never mapped, so Xen can safely
skip them.Signed-off-by Julien Grall <[email protected]>---
Release: This is an improvement for Xen 4.4. It will save time during relinquish phase and avoid dummy allocation.
The downside is the patch is modifying p2m loop which is used
everywhere.--- xen/arch/arm/p2m.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)Quoted 11 lines
xen/arch/arm/p2m.c static int create_p2m_entries(struct domain *d, · line 249
Quoted 9 lines
xen/arch/arm/p2m.c +1
-0@@ -246,10 +246,12 @@ static int create_p2m_entries(struct domain *d, cur_first_offset = ~0 , cur_second_offset = ~0 ;unsigned long count =0 ; +bool_t populate = (op ==INSERT || op ==ALLOCATE );why don't you just check for op == REMOVE?
Quoted 2 lines
Because you also need to check op == RELINQUISH (added by my patch series on foreign mapping).
I see. In that case
Quoted 35 lines · Julien Grall
When Xen is removing/relinquishing mapping, it will create second/third tables if they don't exist.
Non-existent table means the address range was never mapped, so Xen can safely skip them.
Signed-off-by Julien Grall <[email protected]>---
Release: This is an improvement for Xen 4.4. It will save time during relinquish phase and avoid dummy allocation.
The downside is the patch is modifying p2m loop which is used everywhere.--- xen/arch/arm/p2m.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)xen/arch/arm/p2m.c +3
-1@@ -246,10 +246,12 @@ static int create_p2m_entries(struct domain *d, cur_first_offset = ~0 , cur_second_offset = ~0 ;unsigned long count =0 ; +bool_t populate = (op ==INSERT || op ==ALLOCATE );spin_lock (&p2m->lock); -for (addr = start_gpaddr; addr < end_gpaddr; addr +=PAGE_SIZE ) + addr = start_gpaddr; +while ( addr < end_gpaddr ) {if ( cur_first_page !=p2m_first_level_index (addr) ) {
xen/arch/arm/p2m.c static int create_p2m_entries(struct domain *d, · line 272
Quoted 6 lines
xen/arch/arm/p2m.c +3
-0@@ -265,8 +267,15 @@ static int create_p2m_entries(struct domain *d,if ( !first[first_table_offset (addr)].p2m.valid ) { +if ( !populate ) + { + addr +=FIRST_SIZE ;
I think this subtly does the wrong thing if addr is not FIRST_SIZE aligned, which it might be on the first iteration. That will skip the start of the next 1st level block.
I think addr needs to be rounded up to the next first boundary.
Quoted 11 lines
xen/arch/arm/p2m.c +5
-1+continue ; + } + rc =p2m_create_table (d, &first[first_table_offset (addr)]); -if ( rc <0 ) { +if ( rc <0 ) + {printk ("p2m_populate_ram: L1 failed\n" ); goto out; }
xen/arch/arm/p2m.c static int create_p2m_entries(struct domain *d, · line 298
Quoted 6 lines
xen/arch/arm/p2m.c +3
-0@@ -284,6 +293,12 @@ static int create_p2m_entries(struct domain *d,if ( !second[second_table_offset (addr)].p2m.valid ) { +if ( !populate ) + { + addr +=SECOND_SIZE ;
Likewise here.
Quoted 16 lines
xen/arch/arm/p2m.c +6
-0+continue ; + } + rc =p2m_create_table (d, &second[second_table_offset (addr)]);if ( rc <0 ) {printk ("p2m_populate_ram: L2 failed\n" );@@ -372,6 +387,9 @@ static int create_p2m_entries(struct domain *d, } count =0 ; } + +/* Got the next page */ + addr +=PAGE_SIZE ; }if ( op ==ALLOCATE || op ==INSERT )
Quoted 47 lines · Ian Campbell
Quoted 35 lines · Julien Grall
When Xen is removing/relinquishing mapping, it will create second/third tables if they don't exist.
Non-existent table means the address range was never mapped, so Xen can safely skip them.
Signed-off-by Julien Grall <[email protected]>---
Release: This is an improvement for Xen 4.4. It will save time during relinquish phase and avoid dummy allocation.
The downside is the patch is modifying p2m loop which is used everywhere.--- xen/arch/arm/p2m.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)xen/arch/arm/p2m.c +3
-1@@ -246,10 +246,12 @@ static int create_p2m_entries(struct domain *d, cur_first_offset = ~0 , cur_second_offset = ~0 ;unsigned long count =0 ; +bool_t populate = (op ==INSERT || op ==ALLOCATE );spin_lock (&p2m->lock); -for (addr = start_gpaddr; addr < end_gpaddr; addr +=PAGE_SIZE ) + addr = start_gpaddr; +while ( addr < end_gpaddr ) {if ( cur_first_page !=p2m_first_level_index (addr) ) {xen/arch/arm/p2m.c static int create_p2m_entries(struct domain *d, · line 272
Quoted 6 lines
xen/arch/arm/p2m.c +3
-0@@ -265,8 +267,15 @@ static int create_p2m_entries(struct domain *d,if ( !first[first_table_offset (addr)].p2m.valid ) { +if ( !populate ) + { + addr +=FIRST_SIZE ;I think this subtly does the wrong thing if addr is not
FIRST_SIZEaligned, which it might be on the first iteration. That will skip the start of the next 1st level block.
Quoted 1 line
I think addr needs to be rounded up to the next first boundary.
Right, I will send a new version of this patch.
Signature · 1 line
Julien Grall