Coverity fixes for map_domain_page() mismatches
cover Coverity fixes for map_domain_page() mismatches
In the most recent Coverity run, we submitted a modelling file which tried to teach Coverity about map_domain_page() as allocating resource, and needing an accompanying unmap_domain_page().
Here are two fixes directly identified by the modelling.
There were further issues identified, but I believe they are spurious and caused by issues with the modelling itself.
There were also problems identified for tmem (which was the original cause of trying to model this in the first place). As I have already submitted a patch which is also a cleanup, it can be dealt with separately.
PATCH 1/2 amd/passthrough: Do not leak domain mappings from do_invalidate_dte()
Coverity ID: 1135379
--- xen/drivers/passthrough/amd/iommu_guest.c | 4 ++++ 1 file changed, 4 insertions(+)
xen/drivers/passthrough/amd/iommu_guest.c +4 -0
@@ -433,7 +433,10 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd)/* Do not update host dte before gcr3 has been set */ if ( gcr3_gfn ==0 ) + { +unmap_domain_page (dte_base);return 0 ; + } gcr3_mfn =mfn_x (get_gfn (d, gcr3_gfn, &p2mt));put_gfn (d, gcr3_gfn);
@@ -446,6 +449,7 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd) {AMD_IOMMU_DEBUG ("%s: Fail to find iommu for bdf %x!\n" , __func__, mbdf); +unmap_domain_page (dte_base);return -ENODEV ; }
Signature · 1 line
1.7.10.4
Re: [PATCH 1/2] amd/passthrough: Do not leak domain mappings from do_invalidate_dte()
Quoted 15 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
xen/drivers/passthrough/amd/iommu_guest.c +3
-0@@ -433,7 +433,10 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd)/* Do not update host dte before gcr3 has been set */ if ( gcr3_gfn ==0 ) + { +unmap_domain_page (dte_base);return 0 ; + } gcr3_mfn =mfn_x (get_gfn (d, gcr3_gfn, &p2mt));put_gfn (d, gcr3_gfn);
xen/drivers/passthrough/amd/iommu_guest.c static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd) · line 454
Quoted 6 lines
xen/drivers/passthrough/amd/iommu_guest.c +1
-0@@ -446,6 +449,7 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd) {AMD_IOMMU_DEBUG ("%s: Fail to find iommu for bdf %x!\n" , __func__, mbdf); +unmap_domain_page (dte_base);return -ENODEV ; }
I think the better way to fix this would be to move
glx = get_glx_from_dte(gdte);
gv = get_gv_from_dte(gdte);
unmap_domain_page(dte_base);up ahead of the first exit path.
Jan
Re: [PATCH 1/2] amd/passthrough: Do not leak domain mappings from do_invalidate_dte()
Quoted 23 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
xen/drivers/passthrough/amd/iommu_guest.c +3
-0@@ -433,7 +433,10 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd)/* Do not update host dte before gcr3 has been set */ if ( gcr3_gfn ==0 ) + { +unmap_domain_page (dte_base);return 0 ; + } gcr3_mfn =mfn_x (get_gfn (d, gcr3_gfn, &p2mt));put_gfn (d, gcr3_gfn);xen/drivers/passthrough/amd/iommu_guest.c static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd) · line 454
Quoted 6 lines
xen/drivers/passthrough/amd/iommu_guest.c +1
-0@@ -446,6 +449,7 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd) {AMD_IOMMU_DEBUG ("%s: Fail to find iommu for bdf %x!\n" , __func__, mbdf); +unmap_domain_page (dte_base);return -ENODEV ; }I think the better way to fix this would be to move
Quoted 9 lines
glx = get_glx_from_dte(gdte); gv = get_gv_from_dte(gdte); unmap_domain_page(dte_base);up ahead of the first exit path.
Jan
So it would - v2 on its way.
~Andrew
PATCH v2 1/2 amd/passthrough: Do not leak domain mappings from do_invalidate_dte()
In reply to Jan BeulichCoverity ID: 1135379
As the code stands, the domain mapping will be leaked on each error path.
The mapping can be for a much shorter period of time, and all the relevent information can be pulled out at once.
---
Changes in v2:
* Reduce the mapping period (Suggested by Jan)
--- xen/drivers/passthrough/amd/iommu_guest.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
xen/drivers/passthrough/amd/iommu_guest.c +6 -9
@@ -399,7 +399,7 @@ static int do_completion_wait(struct domain *d, cmd_entry_t *cmd)static int do_invalidate_dte (struct domain *d,cmd_entry_t *cmd) {uint16_t gbdf, mbdf, req_id, gdom_id, hdom_id; -dev_entry_t *gdte, *mdte, *dte_base; +dev_entry_t *gdte, *mdte;struct amd_iommu *iommu =NULL ;struct guest_iommu *g_iommu;uint64_t gcr3_gfn, gcr3_mfn;
@@ -424,12 +424,14 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd) sizeof(dev_entry_t), gbdf);ASSERT (mfn_valid (dte_mfn)); - dte_base =map_domain_page (dte_mfn); - - gdte = dte_base + gbdf % (PAGE_SIZE /sizeof (dev_entry_t)); + gdte =map_domain_page (dte_mfn) + gbdf % (PAGE_SIZE /sizeof (dev_entry_t)); gdom_id =get_domid_from_dte (gdte); gcr3_gfn =get_guest_cr3_from_dte (gdte); + glx =get_glx_from_dte (gdte); + gv =get_gv_from_dte (gdte); + +unmap_domain_page (gdte);/* Do not update host dte before gcr3 has been set */ if ( gcr3_gfn ==0 )
@@ -449,11 +451,6 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd)return -ENODEV ; } - glx =get_glx_from_dte (gdte); - gv =get_gv_from_dte (gdte); - -unmap_domain_page (dte_base); -/* Setup host device entry */ hdom_id =host_domid (d, gdom_id); req_id =get_dma_requestor_id (iommu->seg, mbdf);
Signature · 1 line
1.7.10.4
Re: [PATCH v2 1/2] amd/passthrough: Do not leak domain mappings from do_invalidate_dte()
xen/drivers/passthrough/amd/iommu_guest.c static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd) · line 427
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
xen/drivers/passthrough/amd/iommu_guest.c +1
-3@@ -424,12 +424,14 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd) sizeof(dev_entry_t), gbdf);ASSERT (mfn_valid (dte_mfn)); - dte_base =map_domain_page (dte_mfn); - - gdte = dte_base + gbdf % (PAGE_SIZE /sizeof (dev_entry_t)); + gdte =map_domain_page (dte_mfn) + gbdf % (PAGE_SIZE /sizeof (dev_entry_t));
You would better have avoided the extra cleanup, as the arithmetic now is different from what it was before (acting on void * now, i.e. byte granular, instead of in dev_entry_t *).
Jan
PATCH v3 1/2 amd/passthrough: Do not leak domain mappings from do_invalidate_dte()
Coverity ID: 1135379
As the code stands, the domain mapping will be leaked on each error path.
The mapping can be for a much shorter period of time, and all the relevent information can be pulled out at once.
---
Changes in v3:
* Dont break the pointer arithmatic on gdte
--- xen/drivers/passthrough/amd/iommu_guest.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
xen/drivers/passthrough/amd/iommu_guest.c +4 -5
@@ -430,6 +430,10 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd) gdom_id =get_domid_from_dte (gdte); gcr3_gfn =get_guest_cr3_from_dte (gdte); + glx =get_glx_from_dte (gdte); + gv =get_gv_from_dte (gdte); + +unmap_domain_page (gdte);/* Do not update host dte before gcr3 has been set */ if ( gcr3_gfn ==0 )
@@ -449,11 +453,6 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd)return -ENODEV ; } - glx =get_glx_from_dte (gdte); - gv =get_gv_from_dte (gdte); - -unmap_domain_page (dte_base); -/* Setup host device entry */ hdom_id =host_domid (d, gdom_id); req_id =get_dma_requestor_id (iommu->seg, mbdf);
Signature · 1 line
1.7.10.4
Re: [PATCH v3 1/2] amd/passthrough: Do not leak domain mappings from do_invalidate_dte()
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
Coverity ID: 1135379
As the code stands, the domain mapping will be leaked on each error path.
The mapping can be for a much shorter period of time, and all the relevent information can be pulled out at once.
Signed-off-by Andrew Cooper <[email protected]>CC Keir Fraser <[email protected]>
Quoted 42 lines
CC Suravee Suthikulpanit <[email protected]>---
Changes in v3:
* Dont break the pointer arithmatic on gdte--- xen/drivers/passthrough/amd/iommu_guest.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)xen/drivers/passthrough/amd/iommu_guest.c +4
-0@@ -430,6 +430,10 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd) gdom_id =get_domid_from_dte (gdte); gcr3_gfn =get_guest_cr3_from_dte (gdte); + glx =get_glx_from_dte (gdte); + gv =get_gv_from_dte (gdte); + +unmap_domain_page (gdte);/* Do not update host dte before gcr3 has been set */ if ( gcr3_gfn == 0 )xen/drivers/passthrough/amd/iommu_guest.c +0
-5@@ -449,11 +453,6 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd)return -ENODEV ; } - glx =get_glx_from_dte (gdte); - gv =get_gv_from_dte (gdte); - -unmap_domain_page (dte_base); -/* Setup host device entry */ hdom_id =host_domid (d, gdom_id);req_id = get_dma_requestor_id(iommu->seg, mbdf);Signature · 1 line
1.7.10.4
Re: [PATCH v3 1/2] amd/passthrough: Do not leak domain mappings from do_invalidate_dte()
In reply to Andrew CooperQuoted 5 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
Coverity ID: 1135379
As the code stands, the domain mapping will be leaked on each error path.
Quoted 7 lines
The mapping can be for a much shorter period of time, and all the relevent information can be pulled out at once.
Signed-off-by Andrew Cooper <[email protected]>CC Keir Fraser <[email protected]>CC Jan Beulich <[email protected]>CC Suravee Suthikulpanit <[email protected]>
Suravee?
Quoted 40 lines
---
Changes in v3:
* Dont break the pointer arithmatic on gdte--- xen/drivers/passthrough/amd/iommu_guest.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)xen/drivers/passthrough/amd/iommu_guest.c +4
-0@@ -430,6 +430,10 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd) gdom_id =get_domid_from_dte (gdte); gcr3_gfn =get_guest_cr3_from_dte (gdte); + glx =get_glx_from_dte (gdte); + gv =get_gv_from_dte (gdte); + +unmap_domain_page (gdte);/* Do not update host dte before gcr3 has been set */ if ( gcr3_gfn == 0 )xen/drivers/passthrough/amd/iommu_guest.c +0
-5@@ -449,11 +453,6 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd)return -ENODEV ; } - glx =get_glx_from_dte (gdte); - gv =get_gv_from_dte (gdte); - -unmap_domain_page (dte_base); -/* Setup host device entry */ hdom_id =host_domid (d, gdom_id);req_id = get_dma_requestor_id(iommu->seg, mbdf);Signature · 1 line
1.7.10.4
Re: [PATCH v3 1/2] amd/passthrough: Do not leak domain mappings from do_invalidate_dte()
In reply to Andrew CooperQuoted 25 lines · Andrew Cooper
Coverity ID: 1135379
As the code stands, the domain mapping will be leaked on each error path.
The mapping can be for a much shorter period of time, and all the relevent information can be pulled out at once.
Signed-off-by Andrew Cooper <[email protected]>CC Keir Fraser <[email protected]>CC Jan Beulich <[email protected]>CC Suravee Suthikulpanit <[email protected]>---
Changes in v3:
* Dont break the pointer arithmatic on gdte--- xen/drivers/passthrough/amd/iommu_guest.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)xen/drivers/passthrough/amd/iommu_guest.c +0
-0
xen/drivers/passthrough/amd/iommu_guest.c static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd) · line 436
Quoted 7 lines
xen/drivers/passthrough/amd/iommu_guest.c +4
-0@@ -430,6 +430,10 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd) gdom_id =get_domid_from_dte (gdte); gcr3_gfn =get_guest_cr3_from_dte (gdte); + glx =get_glx_from_dte (gdte); + gv =get_gv_from_dte (gdte); + +unmap_domain_page (gdte);
Shouldn't this be "unmap_domain_page (dte_base)" instead?
Quoted 5 lines
xen/drivers/passthrough/amd/iommu_guest.c +0
-0/* Do not update host dte before gcr3 has been set */ if ( gcr3_gfn ==0 )@@ -449,11 +453,6 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd)return -ENODEV ;
xen/drivers/passthrough/amd/iommu_guest.c static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd) · line 458
Quoted 10 lines
xen/drivers/passthrough/amd/iommu_guest.c +0
-5} - glx =get_glx_from_dte (gdte); - gv =get_gv_from_dte (gdte); - -unmap_domain_page (dte_base); -/* Setup host device entry */ hdom_id =host_domid (d, gdom_id); req_id =get_dma_requestor_id (iommu->seg, mbdf);
Also, the comment saying "/* Read guest dte information */ " should probably be moved as well.
Suravee
Re: [PATCH v3 1/2] amd/passthrough: Do not leak domain mappings from do_invalidate_dte()
Quoted 23 lines · Suravee Suthikulanit
Quoted 22 lines · Andrew Cooper
Coverity ID: 1135379
As the code stands, the domain mapping will be leaked on each error path.
The mapping can be for a much shorter period of time, and all the relevent
information can be pulled out at once.Signed-off-by Andrew Cooper <[email protected]>CC Keir Fraser <[email protected]>CC Jan Beulich <[email protected]>CC Suravee Suthikulpanit <[email protected]>---
Changes in v3:
* Dont break the pointer arithmatic on gdte--- xen/drivers/passthrough/amd/iommu_guest.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
Quoted 14 lines
xen/drivers/passthrough/amd/iommu_guest.c static int do_invalidate_dte(struct domain *d, · line 436
Quoted 13 lines
xen/drivers/passthrough/amd/iommu_guest.c +4
-0@@ -430,6 +430,10 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd) gdom_id =get_domid_from_dte (gdte); gcr3_gfn =get_guest_cr3_from_dte (gdte); + glx =get_glx_from_dte (gdte); + gv =get_gv_from_dte (gdte); + +unmap_domain_page (gdte);Shouldn't this be "
unmap_domain_page(dte_base)" instead?
Probably should be.
Quoted 18 lines
Quoted 5 lines
xen/drivers/passthrough/amd/iommu_guest.c +0
-0/* Do not update host dte before gcr3 has been set */ if ( gcr3_gfn ==0 )@@ -449,11 +453,6 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd)xen/drivers/passthrough/amd/iommu_guest.c static int do_invalidate_dte(struct domain *d, · line 458
Quoted 10 lines
xen/drivers/passthrough/amd/iommu_guest.c +0
-4return -ENODEV ; } - glx =get_glx_from_dte (gdte); - gv =get_gv_from_dte (gdte); - -unmap_domain_page (dte_base); -/* Setup host device entry */ hdom_id =host_domid (d, gdom_id); req_id =get_dma_requestor_id (iommu->seg, mbdf);Also, the comment saying "/* Read guest dte information */ " should probably be moved as well.
Quoted 2 lines
Suravee
Sure - v4 on its way.
~Andrew
PATCH v4 1/2 amd/passthrough: Do not leak domain mappings from do_invalidate_dte()
In reply to Suravee SuthikulanitCoverity ID: 1135379
As the code stands, the domain mapping will be leaked on each error path.
The mapping can be for a much shorter period of time, and all the relevent information can be pulled out at once.
---
Changes in v4:
* Move comment, and unmap the base pointer.
--- xen/drivers/passthrough/amd/iommu_guest.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
xen/drivers/passthrough/amd/iommu_guest.c +5 -6
@@ -424,12 +424,17 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd) sizeof(dev_entry_t), gbdf);ASSERT (mfn_valid (dte_mfn)); +/* Read guest dte information */ dte_base =map_domain_page (dte_mfn); gdte = dte_base + gbdf % (PAGE_SIZE /sizeof (dev_entry_t)); gdom_id =get_domid_from_dte (gdte); gcr3_gfn =get_guest_cr3_from_dte (gdte); + glx =get_glx_from_dte (gdte); + gv =get_gv_from_dte (gdte); + +unmap_domain_page (dte_base);/* Do not update host dte before gcr3 has been set */ if ( gcr3_gfn ==0 )
@@ -440,7 +445,6 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd)ASSERT (mfn_valid (gcr3_mfn)); -/* Read guest dte information */ iommu =find_iommu_for_device (0 , mbdf);if ( !iommu ) {
@@ -449,11 +453,6 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd)return -ENODEV ; } - glx =get_glx_from_dte (gdte); - gv =get_gv_from_dte (gdte); - -unmap_domain_page (dte_base); -/* Setup host device entry */ hdom_id =host_domid (d, gdom_id); req_id =get_dma_requestor_id (iommu->seg, mbdf);
Signature · 1 line
1.7.10.4
Re: [PATCH v4 1/2] amd/passthrough: Do not leak domain mappings from do_invalidate_dte()
Quoted 52 lines · Andrew Cooper
Coverity ID: 1135379
As the code stands, the domain mapping will be leaked on each error path.
The mapping can be for a much shorter period of time, and all the relevent information can be pulled out at once.
Signed-off-by Andrew Cooper <[email protected]>CC Keir Fraser <[email protected]>Reviewed-by Jan Beulich <[email protected]>CC Suravee Suthikulpanit <[email protected]>---
Changes in v4:
* Move comment, and unmap the base pointer.--- xen/drivers/passthrough/amd/iommu_guest.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)xen/drivers/passthrough/amd/iommu_guest.c +5
-1@@ -424,12 +424,17 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd) sizeof(dev_entry_t), gbdf);ASSERT (mfn_valid (dte_mfn)); +/* Read guest dte information */ dte_base =map_domain_page (dte_mfn); gdte = dte_base + gbdf % (PAGE_SIZE /sizeof (dev_entry_t)); gdom_id =get_domid_from_dte (gdte); gcr3_gfn =get_guest_cr3_from_dte (gdte); + glx =get_glx_from_dte (gdte); + gv =get_gv_from_dte (gdte); + +unmap_domain_page (dte_base);/* Do not update host dte before gcr3 has been set */ if ( gcr3_gfn ==0 )@@ -440,7 +445,6 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd)ASSERT (mfn_valid (gcr3_mfn)); -/* Read guest dte information */ iommu =find_iommu_for_device (0 , mbdf);if ( !iommu ) {@@ -449,11 +453,6 @@ static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd)return -ENODEV ;
xen/drivers/passthrough/amd/iommu_guest.c static int do_invalidate_dte(struct domain *d, cmd_entry_t *cmd) · line 458
Quoted 10 lines
xen/drivers/passthrough/amd/iommu_guest.c +0
-5} - glx =get_glx_from_dte (gdte); - gv =get_gv_from_dte (gdte); - -unmap_domain_page (dte_base); -/* Setup host device entry */ hdom_id =host_domid (d, gdom_id); req_id =get_dma_requestor_id (iommu->seg, mbdf);
Reviewed and Tested.
Thanks,
Suravee
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH 2/2 xen/page_alloc: Defer the domain mapping in scrub_one_page()
In reply to Andrew CooperThis avoids a resource leak and needless playing with the pagetables in the case that the page is broken.
--- xen/common/page_alloc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
xen/common/page_alloc.c +3 -1
@@ -1652,11 +1652,13 @@ __initcall(pagealloc_keyhandler_init);void scrub_one_page (struct page_info *pg) { -void *p =__map_domain_page (pg); +void *p;if (unlikely (pg->count_info & PGC_broken) )return ; + p =__map_domain_page (pg); +#ifndef NDEBUG /* Avoid callers relying on allocations returning zeroed pages. */ memset (p,0xc2 ,PAGE_SIZE );
Signature · 1 line
1.7.10.4
Re: [PATCH 2/2] xen/page_alloc: Defer the domain mapping in scrub_one_page()
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
This avoids a resource leak and needless playing with the pagetables in the case that the page is broken.
Signed-off-by Andrew Cooper <[email protected]>CC Keir Fraser <[email protected]>
Quoted 26 lines
CC Tim Deegan <[email protected]>--- xen/common/page_alloc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)xen/common/page_alloc.c +3
-1@@ -1652,11 +1652,13 @@ __initcall(pagealloc_keyhandler_init);void scrub_one_page (struct page_info *pg) { -void *p =__map_domain_page (pg); +void *p;if (unlikely (pg->count_info & PGC_broken) )return ; + p =__map_domain_page (pg); +#ifndef NDEBUG /* Avoid callers relying on allocations returning zeroed pages. */ memset (p,0xc2 ,PAGE_SIZE );Signature · 1 line
1.7.10.4
Re: [PATCH 2/2] xen/page_alloc: Defer the domain mapping in scrub_one_page()
In reply to Andrew CooperQuoted 6 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
This avoids a resource leak and needless playing with the pagetables in the case that the page is broken.
Signed-off-by Andrew Cooper <[email protected]>CC Keir Fraser <[email protected]>
Keir?
Quoted 27 lines
CC Jan Beulich <[email protected]>CC Tim Deegan <[email protected]>--- xen/common/page_alloc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)xen/common/page_alloc.c +3
-1@@ -1652,11 +1652,13 @@ __initcall(pagealloc_keyhandler_init);void scrub_one_page (struct page_info *pg) { -void *p =__map_domain_page (pg); +void *p;if (unlikely (pg->count_info & PGC_broken) )return ; + p =__map_domain_page (pg); +#ifndef NDEBUG /* Avoid callers relying on allocations returning zeroed pages. */ memset (p,0xc2 ,PAGE_SIZE );Signature · 1 line
1.7.10.4
Keir Fraser
Reviewed-byRe: [PATCH 2/2] xen/page_alloc: Defer the domain mapping in scrub_one_page()
Quoted 8 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper
This avoids a resource leak and needless playing with the pagetables in the case that the page is broken.
Signed-off-by Andrew Cooper <[email protected]>CC Keir Fraser <[email protected]>Keir?
Quoted 30 lines
Quoted 27 lines
CC Jan Beulich <[email protected]>CC Tim Deegan <[email protected]>--- xen/common/page_alloc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)xen/common/page_alloc.c +3
-1@@ -1652,11 +1652,13 @@ __initcall(pagealloc_keyhandler_init);void scrub_one_page (struct page_info *pg) { -void *p =__map_domain_page (pg); +void *p;if (unlikely (pg->count_info & PGC_broken) )return ; + p =__map_domain_page (pg); +#ifndef NDEBUG /* Avoid callers relying on allocations returning zeroed pages. */ memset (p,0xc2 ,PAGE_SIZE );Signature · 1 line
1.7.10.4