xen: arm: various p2m handling fixups
cover xen: arm: various p2m handling fixups
Three pretty much independent fixes.
Some of these were introduced by my recent superpages series, others may or may not have been ;-).
Ian.
PATCH 1/3 xen: arm: avoid reusing incorrect mappings when walking the p2m.
If we handle a change in a superpage then we need to invalidate any cached mappings further down, otherwise we risk using them because their offset might match but be based on a different offset further up the table.
--- xen/arch/arm/p2m.c | 4 ++++ 1 file changed, 4 insertions(+)
xen/arch/arm/p2m.c +4 -0
@@ -719,6 +719,8 @@ static int apply_p2m_changes(struct domain *d, goto out; } cur_first_page =p2m_first_level_index (addr); +/* Any mapping further down is now invalid */ + cur_second_offset = ~0 ; }/* We only use a 3 level p2m at the moment, so no level 0,
@@ -741,6 +743,8 @@ static int apply_p2m_changes(struct domain *d,if (second)unmap_domain_page (second); second =map_domain_page (first[first_table_offset (addr)].p2m.base); cur_first_offset =first_table_offset (addr); +/* Any mapping further down is now invalid */ + cur_second_offset = ~0 ; }/* else: second already valid */
Signature · 1 line
1.7.10.4
Re: [PATCH 1/3] xen: arm: avoid reusing incorrect mappings when walking the p2m.
Hi Ian,
Quoted 14 lines · Ian Campbell
If we handle a change in a superpage then we need to invalidate any cached mappings further down, otherwise we risk using them because their offset might match but be based on a different offset further up the table.
Signed-off-by Ian Campbell <[email protected]>--- xen/arch/arm/p2m.c | 4 ++++ 1 file changed, 4 insertions(+)xen/arch/arm/p2m.c +0
-0
xen/arch/arm/p2m.c static int apply_p2m_changes(struct domain *d, · line 723
Quoted 5 lines
xen/arch/arm/p2m.c +2
-0@@ -719,6 +719,8 @@ static int apply_p2m_changes(struct domain *d, goto out; } cur_first_page =p2m_first_level_index (addr); +/* Any mapping further down is now invalid */ + cur_second_offset = ~0 ;
I think you miss to invalid cur_first_offset.
Also, I think we have the same issue on Xen 4.4.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH 1/3] xen: arm: avoid reusing incorrect mappings when walking the p2m.
Quoted 12 lines · Julien Grall
Hi Ian,
Quoted 9 lines · Ian Campbell
If we handle a change in a superpage then we need to invalidate any cached mappings further down, otherwise we risk using them because their offset might match but be based on a different offset further up the table.
Signed-off-by Ian Campbell <[email protected]>--- xen/arch/arm/p2m.c | 4 ++++ 1 file changed, 4 insertions(+)
Quoted 12 lines
xen/arch/arm/p2m.c static int apply_p2m_changes(struct domain *d, · line 723
Quoted 10 lines
xen/arch/arm/p2m.c +2
-0@@ -719,6 +719,8 @@ static int apply_p2m_changes(struct domain *d, goto out; } cur_first_page =p2m_first_level_index (addr); +/* Any mapping further down is now invalid */ + cur_second_offset = ~0 ;I think you miss to invalid
cur_first_offset.
I think you are right.
Quoted 1 line
Also, I think we have the same issue on Xen 4.4.
I'll add it to my list to check. I suspect the fix will need reimplementing there rather than backporting.
Ian.
PATCH 2/3 xen: arm: when ALLOCATING p2m entries maddr is meaningless
In reply to Ian CampbellThe maddr differs on each loop depending on the pages which happen to get allocated.
There is already an assertion that maddr == 0.
--- xen/arch/arm/p2m.c | 1 - 1 file changed, 1 deletion(-)
xen/arch/arm/p2m.c +0 -1
@@ -501,7 +501,6 @@ static int apply_one_level(struct domain *d, p2m->stats.mappings[level]++; *addr += level_size; - *maddr += level_size;return P2M_ONE_PROGRESS ; }
Signature · 1 line
1.7.10.4
Re: [PATCH 2/3] xen: arm: when ALLOCATING p2m entries maddr is meaningless
Hi Ian,
Quoted 4 lines · Ian Campbell
The maddr differs on each loop depending on the pages which happen to get allocated.
There is already an assertion that maddr == 0.
I think we hit the assert we don't use 1:1 mapping for DOM0.
Quoted 1 line
Signed-off-by Ian Campbell <[email protected]>
Quoted 10 lines
--- xen/arch/arm/p2m.c | 1 - 1 file changed, 1 deletion(-)xen/arch/arm/p2m.c +0
-0
xen/arch/arm/p2m.c static int apply_one_level(struct domain *d, · line 506
Quoted 7 lines
xen/arch/arm/p2m.c +0
-1@@ -501,7 +501,6 @@ static int apply_one_level(struct domain *d, p2m->stats.mappings[level]++; *addr += level_size; - *maddr += level_size;return P2M_ONE_PROGRESS ; }
Regards,
Signature · 1 line
Julien Grall
Ian Campbell
AppliedRe: [PATCH 2/3] xen: arm: when ALLOCATING p2m entries maddr is meaningless
Quoted 1 line · Julien Grall
Acked-by Julien Grall <[email protected]>
Applied, thanks.
PATCH 3/3 xen: arm: correctly handle removing a subset of a superpage mapping.
In reply to Ian CampbellThis can be exercised for example via ballooning which will remove 4K regions fromanywhere in the address space.
--- xen/arch/arm/p2m.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)
xen/arch/arm/p2m.c +27 -2
@@ -604,8 +604,33 @@ static int apply_one_level(struct domain *d,return P2M_ONE_PROGRESS_NOP ; } -if ( level <3 &&p2m_table (orig_pte) ) -return P2M_ONE_DESCEND ; +if ( level <3 ) + { +if (p2m_table (orig_pte) ) +return P2M_ONE_DESCEND ; + +if ( op ==REMOVE && + !is_mapping_aligned (*addr, end_gpaddr, +0 ,/* maddr doesn't matter for remove */ + level_size) ) + { +/* +* Removing a mapping from the middle of a superpage. Shatter +* and descend. +*/ + *flush = true; + rc =p2m_create_table (d, entry, + level_shift -PAGE_SHIFT , flush_cache); +if ( rc <0 ) +return rc; + + p2m->stats.shattered[level]++; + p2m->stats.mappings[level]--; + p2m->stats.mappings[level+1 ] +=LPAE_ENTRIES ; + +return P2M_ONE_DESCEND ; + } + } *flush = true;
Signature · 1 line
1.7.10.4
Re: [PATCH 3/3] xen: arm: correctly handle removing a subset of a superpage mapping.
Hi Ian,
Quoted 2 lines · Ian Campbell
This can be exercised for example via ballooning which will remove 4K regions fromanywhere in the address space.
Missing space between "from" and "anywhere"
Quoted 34 lines
Reported-by Julien Grall <[email protected]>Signed-off-by Ian Campbell <[email protected]>--- xen/arch/arm/p2m.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)xen/arch/arm/p2m.c +17
-2@@ -604,8 +604,33 @@ static int apply_one_level(struct domain *d,return P2M_ONE_PROGRESS_NOP ; } -if ( level <3 &&p2m_table (orig_pte) ) -return P2M_ONE_DESCEND ; +if ( level <3 ) + { +if (p2m_table (orig_pte) ) +return P2M_ONE_DESCEND ; + +if ( op ==REMOVE && + !is_mapping_aligned (*addr, end_gpaddr, +0 ,/* maddr doesn't matter for remove */ + level_size) ) + { +/* +* Removing a mapping from the middle of a superpage. Shatter +* and descend. +*/ + *flush = true; + rc =p2m_create_table (d, entry, + level_shift -PAGE_SHIFT , flush_cache);
xen/arch/arm/p2m.c static int apply_one_level(struct domain *d, · line 633
Quoted 10 lines
xen/arch/arm/p2m.c +10
-0+if ( rc <0 ) +return rc; + + p2m->stats.shattered[level]++; + p2m->stats.mappings[level]--; + p2m->stats.mappings[level+1 ] +=LPAE_ENTRIES ; + +return P2M_ONE_DESCEND ; + } + }
I would put the code below (which is only for level3) in the else part. This will also remove now useless "if ( level == 3 )".
xen/arch/arm/p2m.c static int apply_one_level(struct domain *d,
Quoted 3 lines
xen/arch/arm/p2m.c +0
-0*flush = true;
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH 3/3] xen: arm: correctly handle removing a subset of a superpage mapping.
Quoted 47 lines · Julien Grall
Hi Ian,
Quoted 2 lines · Ian Campbell
This can be exercised for example via ballooning which will remove 4K regions fromanywhere in the address space.
Missing space between "from" and "anywhere"
Quoted 39 lines
Reported-by Julien Grall <[email protected]>Signed-off-by Ian Campbell <[email protected]>--- xen/arch/arm/p2m.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)xen/arch/arm/p2m.c +22
-2@@ -604,8 +604,33 @@ static int apply_one_level(struct domain *d,return P2M_ONE_PROGRESS_NOP ; } -if ( level <3 &&p2m_table (orig_pte) ) -return P2M_ONE_DESCEND ; +if ( level <3 ) + { +if (p2m_table (orig_pte) ) +return P2M_ONE_DESCEND ; + +if ( op ==REMOVE && + !is_mapping_aligned (*addr, end_gpaddr, +0 ,/* maddr doesn't matter for remove */ + level_size) ) + { +/* +* Removing a mapping from the middle of a superpage. Shatter +* and descend. +*/ + *flush = true; + rc =p2m_create_table (d, entry, + level_shift -PAGE_SHIFT , flush_cache); +if ( rc <0 ) +return rc; + + p2m->stats.shattered[level]++; + p2m->stats.mappings[level]--;
Quoted 8 lines
xen/arch/arm/p2m.c static int apply_one_level(struct domain *d, · line 633
Quoted 5 lines
xen/arch/arm/p2m.c +5
-0+ p2m->stats.mappings[level+1 ] +=LPAE_ENTRIES ; + +return P2M_ONE_DESCEND ; + } + }I would put the code below (which is only for level3) in the else part. This will also remove now useless "if ( level == 3 )".
This would break the relinquish case, I think.
Although thinking about it perhaps relinquish should behave like remove and shatter. My original thinking was that we only ever relinquish the entire address space so we shouldn't really be hitting that case.
Ian.
Julien Grall
Acked-byRe: [PATCH 3/3] xen: arm: correctly handle removing a subset of a superpage mapping.
Quoted 57 lines · Ian Campbell
Quoted 47 lines · Julien Grall
Hi Ian,
Quoted 2 lines · Ian Campbell
This can be exercised for example via ballooning which will remove 4K regions fromanywhere in the address space.
Missing space between "from" and "anywhere"
Quoted 39 lines
Reported-by Julien Grall <[email protected]>Signed-off-by Ian Campbell <[email protected]>--- xen/arch/arm/p2m.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-)xen/arch/arm/p2m.c +22
-2@@ -604,8 +604,33 @@ static int apply_one_level(struct domain *d,return P2M_ONE_PROGRESS_NOP ; } -if ( level <3 &&p2m_table (orig_pte) ) -return P2M_ONE_DESCEND ; +if ( level <3 ) + { +if (p2m_table (orig_pte) ) +return P2M_ONE_DESCEND ; + +if ( op ==REMOVE && + !is_mapping_aligned (*addr, end_gpaddr, +0 ,/* maddr doesn't matter for remove */ + level_size) ) + { +/* +* Removing a mapping from the middle of a superpage. Shatter +* and descend. +*/ + *flush = true; + rc =p2m_create_table (d, entry, + level_shift -PAGE_SHIFT , flush_cache); +if ( rc <0 ) +return rc; + + p2m->stats.shattered[level]++; + p2m->stats.mappings[level]--;Quoted 8 lines
xen/arch/arm/p2m.c static int apply_one_level(struct domain *d, · line 633
Quoted 5 lines
xen/arch/arm/p2m.c +5
-0+ p2m->stats.mappings[level+1 ] +=LPAE_ENTRIES ; + +return P2M_ONE_DESCEND ; + } + }I would put the code below (which is only for level3) in the else part. This will also remove now useless "if ( level == 3 )".
Quoted 5 lines
This would break the relinquish case, I think.
Although thinking about it perhaps relinquish should behave like remove and shatter. My original thinking was that we only ever relinquish the entire address space so we shouldn't really be hitting that case.
Oh right, I though there was a return on every part of this if. Sorry for the noise.
With the minor change in the commit message:
Regards,
Signature · 1 line
Julien Grall
Ian Campbell
AppliedRe: [PATCH 3/3] xen: arm: correctly handle removing a subset of a superpage mapping.
Quoted 5 lines · Julien Grall
On 15/07/14 10:38, Ian Campbell wrote:
With the minor change in the commit message:Acked-by Julien Grall <[email protected]>
Thanks, applied.
Ian.