Skip to contentSkip to conversation

Coverity fixes for map_domain_page() mismatches

PATCH Superseded Andrew Cooper 4 participants 17 messages Dec 4, 2013 – Dec 9, 2013

lore
Share & tools
lore
#0 lore raw

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.

#1 lore raw

PATCH 1/2 amd/passthrough: Do not leak domain mappings from do_invalidate_dte()

Coverity ID: 1135379

CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Suravee Suthikulpanit <[email protected]>
---
 xen/drivers/passthrough/amd/iommu_guest.c |    4 ++++
 1 file changed, 4 insertions(+)
xen/drivers/passthrough/amd/iommu_guest.c +4 -0
index 952600a..7687cf1 100644
@@ -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
#2 lore raw

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

#3 lore raw

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

#4 lore raw

PATCH v2 1/2 amd/passthrough: Do not leak domain mappings from do_invalidate_dte()

In reply to Jan Beulich

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.

CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Suravee Suthikulpanit <[email protected]>

---

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
index 952600a..0e0a7bb 100644
@@ -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
#5 lore raw

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

#6 lore raw

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.

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 +4 -5
index 952600a..c1fa0ff 100644
@@ -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
Reviewed-by on v3 1/2
#7 lore raw

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.

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
index 952600a..c1fa0ff 100644
@@ -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
#8 lore raw

Re: [PATCH v3 1/2] amd/passthrough: Do not leak domain mappings from do_invalidate_dte()

In reply to Andrew Cooper
Quoted 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.

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
index 952600a..c1fa0ff 100644
@@ -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
#9 lore raw

Re: [PATCH v3 1/2] amd/passthrough: Do not leak domain mappings from do_invalidate_dte()

In reply to Andrew Cooper
Quoted 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.

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
index 952600a..c1fa0ff 100644

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

#10 lore raw

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.

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
index 952600a..c1fa0ff 100644
@@ -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 -4
          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);

Also, the comment saying "/* Read guest dte information */ " should probably be moved as well.

Quoted 2 lines

Suravee

Sure - v4 on its way.

~Andrew

#11 lore raw

PATCH v4 1/2 amd/passthrough: Do not leak domain mappings from do_invalidate_dte()

In reply to Suravee Suthikulanit

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.

CC Keir Fraser <[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 -6
index 952600a..477de20 100644
@@ -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
Acked-by on v4 1/2
#12 lore raw

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.

CC Keir Fraser <[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
index 952600a..477de20 100644
@@ -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

#13 lore raw

PATCH 2/2 xen/page_alloc: Defer the domain mapping in scrub_one_page()

In reply to Andrew Cooper

This avoids a resource leak and needless playing with the pagetables in the case that the page is broken.

CC Keir Fraser <[email protected]>
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
index 8002bd2..5f484a2 100644
@@ -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
Reviewed-by on v1 2/2
#14 lore raw

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.

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
index 8002bd2..5f484a2 100644
@@ -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
#15 lore raw

Re: [PATCH 2/2] xen/page_alloc: Defer the domain mapping in scrub_one_page()

In reply to Andrew Cooper
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.

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
index 8002bd2..5f484a2 100644
@@ -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
Reviewed-by
#16 lore raw

Re: [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.

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
index 8002bd2..5f484a2 100644
@@ -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