Skip to contentSkip to conversation

slightly consolidate code in free_domheap_pages()

PATCH Superseded Jan Beulich 3 participants 14 messages Jun 20, 2014 – Jun 24, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 slightly consolidate code in free_domheap_pages()

... to combine the three scrubbing paths into a single one.

xen/common/page_alloc.c +29 -31
@@ -1724,47 +1724,45 @@ void free_domheap_pages(struct page_info
 
         spin_unlock_recursive(&d->page_alloc_lock);
     }
-    else if ( likely(d != NULL) && likely(d != dom_cow) )
+    else
     {
-        /* NB. May recursively lock from relinquish_memory(). */
-        spin_lock_recursive(&d->page_alloc_lock);
+        bool_t scrub;
 
-        for ( i = 0; i < (1 << order); i++ )
+        if ( likely(d) && likely(d != dom_cow) )
         {
-            BUG_ON((pg[i].u.inuse.type_info & PGT_count_mask) != 0);
-            page_list_del2(&pg[i], &d->page_list, &d->arch.relmem_list);
-        }
+            /* NB. May recursively lock from relinquish_memory(). */
+            spin_lock_recursive(&d->page_alloc_lock);
 
-        drop_dom_ref = !domain_adjust_tot_pages(d, -(1 << order));
-
-        spin_unlock_recursive(&d->page_alloc_lock);
+            for ( i = 0; i < (1 << order); i++ )
+            {
+                BUG_ON((pg[i].u.inuse.type_info & PGT_count_mask) != 0);
+                page_list_del2(&pg[i], &d->page_list, &d->arch.relmem_list);
+            }
+
+            drop_dom_ref = !domain_adjust_tot_pages(d, -(1 << order));
+
+            spin_unlock_recursive(&d->page_alloc_lock);
+
+            /*
+             * Normally we expect a domain to clear pages before freeing them,
+             * if it cares about the secrecy of their contents. However, after
+             * a domain has died we assume responsibility for erasure.
+             */
+            scrub = !!d->is_dying;
+        }
+        else
+        {
+            ASSERT(!d || !order);
+            drop_dom_ref = 0;
+            scrub = 1;
+        }
 
-        /*
-         * Normally we expect a domain to clear pages before freeing them, if 
-         * it cares about the secrecy of their contents. However, after a 
-         * domain has died we assume responsibility for erasure.
-         */
-        if ( unlikely(d->is_dying) )
+        if ( unlikely(scrub) )
             for ( i = 0; i < (1 << order); i++ )
                 scrub_one_page(&pg[i]);
 
         free_heap_pages(pg, order);
     }
-    else if ( unlikely(d == dom_cow) )
-    {
-        ASSERT(order == 0); 
-        scrub_one_page(pg);
-        free_heap_pages(pg, 0);
-        drop_dom_ref = 0;
-    }
-    else
-    {
-        /* Freeing anonymous domain-heap pages. */
-        for ( i = 0; i < (1 << order); i++ )
-            scrub_one_page(&pg[i]);
-        free_heap_pages(pg, order);
-        drop_dom_ref = 0;
-    }
 
     if ( drop_dom_ref )
         put_domain(d);

slightly consolidate code in free_domheap_pages()

... to combine the three scrubbing paths into a single one.

xen/common/page_alloc.c +29 -31

76 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#1 lore raw
Quoted 35 lines · Jan Beulich

... to combine the three scrubbing paths into a single one.

xen/common/page_alloc.c +11 -10
@@ -1724,47 +1724,45 @@ void free_domheap_pages(struct page_info
 
         spin_unlock_recursive(&d->page_alloc_lock);
     }
-    else if ( likely(d != NULL) && likely(d != dom_cow) )
+    else
     {
-        /* NB. May recursively lock from relinquish_memory(). */
-        spin_lock_recursive(&d->page_alloc_lock);
+        bool_t scrub;
 
-        for ( i = 0; i < (1 << order); i++ )
+        if ( likely(d) && likely(d != dom_cow) )
         {
-            BUG_ON((pg[i].u.inuse.type_info & PGT_count_mask) != 0);
-            page_list_del2(&pg[i], &d->page_list, &d->arch.relmem_list);
-        }
+            /* NB. May recursively lock from relinquish_memory(). */
+            spin_lock_recursive(&d->page_alloc_lock);
 
-        drop_dom_ref = !domain_adjust_tot_pages(d, -(1 << order));
-
-        spin_unlock_recursive(&d->page_alloc_lock);
+            for ( i = 0; i < (1 << order); i++ )
+            {
+                BUG_ON((pg[i].u.inuse.type_info & PGT_count_mask) != 0);
+                page_list_del2(&pg[i], &d->page_list, &d->arch.relmem_list);
+            }
+

xen/common/page_alloc.c void free_domheap_pages(struct page_info · line 1751

Quoted 10 lines
xen/common/page_alloc.c +10 -0
+            drop_dom_ref = !domain_adjust_tot_pages(d, -(1 << order));
+
+            spin_unlock_recursive(&d->page_alloc_lock);
+
+            /*
+             * Normally we expect a domain to clear pages before freeing them,
+             * if it cares about the secrecy of their contents. However, after
+             * a domain has died we assume responsibility for erasure.
+             */
+            scrub = !!d->is_dying;

d->is_dying is technically protected by d->page_alloc_lock, and one extra boolean read isn't going to extend the critical region too much.

Unrelated to the content of the patch, I can't see a codepath where we would relinquish domain memory from a clean shutdown without setting d->is_dying. Does this mean that we are even scrubbing pages from cleanly shut down domains?

~Andrew

Quoted 43 lines
xen/common/page_alloc.c +8 -21
+        }
+        else
+        {
+            ASSERT(!d || !order);
+            drop_dom_ref = 0;
+            scrub = 1;
+        }
 
-        /*
-         * Normally we expect a domain to clear pages before freeing them, if 
-         * it cares about the secrecy of their contents. However, after a 
-         * domain has died we assume responsibility for erasure.
-         */
-        if ( unlikely(d->is_dying) )
+        if ( unlikely(scrub) )
             for ( i = 0; i < (1 << order); i++ )
                 scrub_one_page(&pg[i]);
 
         free_heap_pages(pg, order);
     }
-    else if ( unlikely(d == dom_cow) )
-    {
-        ASSERT(order == 0); 
-        scrub_one_page(pg);
-        free_heap_pages(pg, 0);
-        drop_dom_ref = 0;
-    }
-    else
-    {
-        /* Freeing anonymous domain-heap pages. */
-        for ( i = 0; i < (1 << order); i++ )
-            scrub_one_page(&pg[i]);
-        free_heap_pages(pg, order);
-        drop_dom_ref = 0;
-    }
 
     if ( drop_dom_ref )
         put_domain(d);
Quoted 4 lines

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
Quoted 42 lines
Quoted 1 line
Quoted 1 line · On 20.06.14 at 15:16, <[email protected]> wrote:
Quoted 40 lines · Jan Beulich

... to combine the three scrubbing paths into a single one.

xen/common/page_alloc.c +16 -10
@@ -1724,47 +1724,45 @@ void free_domheap_pages(struct page_info
 
         spin_unlock_recursive(&d->page_alloc_lock);
     }
-    else if ( likely(d != NULL) && likely(d != dom_cow) )
+    else
     {
-        /* NB. May recursively lock from relinquish_memory(). */
-        spin_lock_recursive(&d->page_alloc_lock);
+        bool_t scrub;
 
-        for ( i = 0; i < (1 << order); i++ )
+        if ( likely(d) && likely(d != dom_cow) )
         {
-            BUG_ON((pg[i].u.inuse.type_info & PGT_count_mask) != 0);
-            page_list_del2(&pg[i], &d->page_list, &d->arch.relmem_list);
-        }
+            /* NB. May recursively lock from relinquish_memory(). */
+            spin_lock_recursive(&d->page_alloc_lock);
 
-        drop_dom_ref = !domain_adjust_tot_pages(d, -(1 << order));
-
-        spin_unlock_recursive(&d->page_alloc_lock);
+            for ( i = 0; i < (1 << order); i++ )
+            {
+                BUG_ON((pg[i].u.inuse.type_info & PGT_count_mask) != 0);
+                page_list_del2(&pg[i], &d->page_list, &d->arch.relmem_list);
+            }
+
+            drop_dom_ref = !domain_adjust_tot_pages(d, -(1 << order));
+
+            spin_unlock_recursive(&d->page_alloc_lock);
+
+            /*
Quoted 8 lines

xen/common/page_alloc.c void free_domheap_pages(struct page_info · line 1751

Quoted 5 lines
xen/common/page_alloc.c +5 -0
+             * Normally we expect a domain to clear pages before freeing them,
+             * if it cares about the secrecy of their contents. However, after
+             * a domain has died we assume responsibility for erasure.
+             */
+            scrub = !!d->is_dying;

d->is_dying is technically protected by d->page_alloc_lock, and one extra boolean read isn't going to extend the critical region too much.

Right, but this isn't the subject of the patch - the check got moved from further down (i.e. even farther outside the locked region) up here. Moving it into the locked region ought to probably be a separate (potentially backportable) patch. Otoh this is a read, and we don't really care for races here as is_dying would never get cleared once it was set.

Quoted 4 lines

Unrelated to the content of the patch, I can't see a codepath where we would relinquish domain memory from a clean shutdown without setting d->is_dying. Does this mean that we are even scrubbing pages from cleanly shut down domains?

Yes, just like the comment says.

Jan

#3 lore raw
Quoted 8 lines · Jan Beulich
Quoted 4 lines

Unrelated to the content of the patch, I can't see a codepath where we would relinquish domain memory from a clean shutdown without setting d->is_dying. Does this mean that we are even scrubbing pages from cleanly shut down domains?

Yes, just like the comment says.

Jan

But it means that we will scrub all pages for all domains no matter how it died, which is contrary to the statement in the comment which says that we don't scrub a cleanly shut down domain.

Quoted 1 line

From what I can see, the only pages Xen won't scrub are pages handed

back via decrease reservation, but I don't see how that is relevant in this context.

~Andrew

#4 lore raw
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 20.06.14 at 16:35, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 4 lines

Unrelated to the content of the patch, I can't see a codepath where we would relinquish domain memory from a clean shutdown without setting d->is_dying. Does this mean that we are even scrubbing pages from cleanly shut down domains?

Yes, just like the comment says.

Quoted 7 lines

But it means that we will scrub all pages for all domains no matter how it died, which is contrary to the statement in the comment which says that we don't scrub a cleanly shut down domain.

From what I can see, the only pages Xen won't scrub are pages handed back via decrease reservation, but I don't see how that is relevant in this context.

Nothing like this is being said in that comment:

/*
* Normally we expect a domain to clear pages before freeing them,
* if it cares about the secrecy of their contents. However, after
* a domain has died we assume responsibility for erasure. */

("has died" doesn't [to me at least] exclude the clean shutdown case).

Jan

#5 lore raw
In reply to Jan Beulich
Quoted 1 line · Jan Beulich

+ if ( likely(d) && likely(d != dom_cow) )

OOI is this more or less efficient than a single likely around the entire thing?

xen/common/page_alloc.c void free_domheap_pages(struct page_info · line 1755

Quoted 3 lines
xen/common/page_alloc.c +3 -0
+        else
+        {
+            ASSERT(!d || !order);

Is this effectively replacing the ASSERT(order == 0) In the previous d == dom_cow case?

If so, can d at this point ever be anything other than dom_cow or NULL? I don't think so. Given that I think ASSERT(!(d == dom_cow && order != 0)) would more clearly capture the intent of the test (with the spelling out of the conditions being more important than the de morganing of the expression).

Ian.

#6 lore raw
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 24.06.14 at 12:04, <[email protected]> wrote:
Quoted 1 line · Jan Beulich

+ if ( likely(d) && likely(d != dom_cow) )

OOI is this more or less efficient than a single likely around the entire thing?

likely()/unlikely() around && or || expressions is never having the intended effect unless these expressions can be guaranteed to result in only a single branch instruction in the compiled code. That's because branch likelihood needs to be determined for each branch instruction individually (and e.g. likely(x && y) doesn't necessarily mean likely(x) && likely(y), i.e. it may only be the particular combination of the two that is likely).

Quoted 6 lines

xen/common/page_alloc.c void free_domheap_pages(struct page_info · line 1755

Quoted 3 lines
xen/common/page_alloc.c +3 -0
+        else
+        {
+            ASSERT(!d || !order);

Is this effectively replacing the ASSERT(order == 0) In the previous d == dom_cow case?

Yes.

Quoted 5 lines

If so, can d at this point ever be anything other than dom_cow or NULL? I don't think so. Given that I think ASSERT(!(d == dom_cow && order != 0)) would more clearly capture the intent of the test (with the spelling out of the conditions being more important than the de morganing of the expression).

Indeed, d can only be NULL or dom_cow here (being in the else part of the if() you quoted at the top). So an alternative might indeed be ASSERT(d != dom_cow || !order), but that seems less desirable to me as it opens up ways to pass the ASSERT() with d != NULL should the if() condition ever get modified. I.e. I'd prefer the assertion to be as restrictive as possible, getting relaxed only when in fact necessary.

Jan

#7 lore raw
Quoted 8 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 24.06.14 at 12:04, <[email protected]> wrote:
Quoted 1 line · Jan Beulich

+ if ( likely(d) && likely(d != dom_cow) )

OOI is this more or less efficient than a single likely around the entire thing?

Quoted 7 lines

likely()/unlikely() around && or || expressions is never having the intended effect unless these expressions can be guaranteed to result in only a single branch instruction in the compiled code. That's because branch likelihood needs to be determined for each branch instruction individually (and e.g. likely(x && y) doesn't necessarily mean likely(x) && likely(y), i.e. it may only be the particular combination of the two that is likely).

Make sense, thanks.

Quoted 15 lines
Quoted 6 lines

xen/common/page_alloc.c void free_domheap_pages(struct page_info · line 1755

Quoted 3 lines
xen/common/page_alloc.c +3 -0
+        else
+        {
+            ASSERT(!d || !order);

Is this effectively replacing the ASSERT(order == 0) In the previous d == dom_cow case?

Yes.

Quoted 5 lines

If so, can d at this point ever be anything other than dom_cow or NULL? I don't think so. Given that I think ASSERT(!(d == dom_cow && order != 0)) would more clearly capture the intent of the test (with the spelling out of the conditions being more important than the de morganing of the expression).

Quoted 6 lines

Indeed, d can only be NULL or dom_cow here (being in the else part of the if() you quoted at the top). So an alternative might indeed be ASSERT(d != dom_cow || !order), but that seems less desirable to me as it opens up ways to pass the ASSERT() with d != NULL should the if() condition ever get modified. I.e. I'd prefer the assertion to be as restrictive as possible, getting relaxed only when in fact necessary.

Since the original if involves d == dom_cow but nothing to do with order it seemed that the check was somehow specific to dom_cow's relationship to higher order allocations.

I suppose the question is what relationship would a non-NULL d have to the order of the allocation. i.e. if the if were changed to also consider dom_foo why would we expect now that dom_foo had any order requirements?

Ian.

#8 lore raw
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 24.06.14 at 13:27, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 24.06.14 at 12:04, <[email protected]> wrote:

If so, can d at this point ever be anything other than dom_cow or NULL? I don't think so. Given that I think ASSERT(!(d == dom_cow && order != 0)) would more clearly capture the intent of the test (with the spelling out of the conditions being more important than the de morganing of the expression).

Quoted 6 lines

Indeed, d can only be NULL or dom_cow here (being in the else part of the if() you quoted at the top). So an alternative might indeed be ASSERT(d != dom_cow || !order), but that seems less desirable to me as it opens up ways to pass the ASSERT() with d != NULL should the if() condition ever get modified. I.e. I'd prefer the assertion to be as restrictive as possible, getting relaxed only when in fact necessary.

Quoted 8 lines

Since the original if involves d == dom_cow but nothing to do with order it seemed that the check was somehow specific to dom_cow's relationship to higher order allocations.

I suppose the question is what relationship would a non-NULL d have to the order of the allocation. i.e. if the if were changed to also consider dom_foo why would we expect now that dom_foo had any order requirements?

We won't know, but by having it the way it is now in the patch we're on the safe side (nothing unintended will slip through), whereas if we change to comparing against dom_cow a not sufficiently careful future change may introduce an issue.

Jan

#9 lore raw
Quoted 25 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 24.06.14 at 13:27, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 24.06.14 at 12:04, <[email protected]> wrote:

If so, can d at this point ever be anything other than dom_cow or NULL? I don't think so. Given that I think ASSERT(!(d == dom_cow && order != 0)) would more clearly capture the intent of the test (with the spelling out of the conditions being more important than the de morganing of the expression).

Quoted 6 lines

Indeed, d can only be NULL or dom_cow here (being in the else part of the if() you quoted at the top). So an alternative might indeed be ASSERT(d != dom_cow || !order), but that seems less desirable to me as it opens up ways to pass the ASSERT() with d != NULL should the if() condition ever get modified. I.e. I'd prefer the assertion to be as restrictive as possible, getting relaxed only when in fact necessary.

Quoted 8 lines

Since the original if involves d == dom_cow but nothing to do with order it seemed that the check was somehow specific to dom_cow's relationship to higher order allocations.

I suppose the question is what relationship would a non-NULL d have to the order of the allocation. i.e. if the if were changed to also consider dom_foo why would we expect now that dom_foo had any order requirements?

Quoted 4 lines

We won't know, but by having it the way it is now in the patch we're on the safe side (nothing unintended will slip through), whereas if we change to comparing against dom_cow a not sufficiently careful future change may introduce an issue.

That's true I . Could you add a comment though, since as it is the current relationship to dom_cow and order is somewhat obscured.

ASSERT(d == NULL || ( d == dom_cow && !order ) ) is too much?

Ian.

#10 lore raw
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 24.06.14 at 14:10, <[email protected]> wrote:
Quoted 25 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 24.06.14 at 13:27, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 24.06.14 at 12:04, <[email protected]> wrote:

If so, can d at this point ever be anything other than dom_cow or NULL? I don't think so. Given that I think ASSERT(!(d == dom_cow && order != 0)) would more clearly capture the intent of the test (with the spelling out of the conditions being more important than the de morganing of the expression).

Quoted 6 lines

Indeed, d can only be NULL or dom_cow here (being in the else part of the if() you quoted at the top). So an alternative might indeed be ASSERT(d != dom_cow || !order), but that seems less desirable to me as it opens up ways to pass the ASSERT() with d != NULL should the if() condition ever get modified. I.e. I'd prefer the assertion to be as restrictive as possible, getting relaxed only when in fact necessary.

Since the original if involves d == dom_cow but nothing to do with order it seemed that the check was somehow specific to dom_cow's relationship to higher order allocations.

I suppose the question is what relationship would a non-NULL d have to the order of the allocation. i.e. if the if were changed to also consider dom_foo why would we expect now that dom_foo had any order requirements?

Quoted 7 lines
Quoted 4 lines

We won't know, but by having it the way it is now in the patch we're on the safe side (nothing unintended will slip through), whereas if we change to comparing against dom_cow a not sufficiently careful future change may introduce an issue.

That's true I . Could you add a comment though, since as it is the current relationship to dom_cow and order is somewhat obscured.

That I can do, ...

Quoted 1 line

ASSERT(d == NULL || ( d == dom_cow && !order ) ) is too much?

... but this looks too ugly to me (namely in the else path to an if checking d against exactly these two values).

Jan

#11 lore raw
Quoted 32 lines · Jan Beulich
Quoted 32 lines
Quoted 1 line
Quoted 1 line · On 24.06.14 at 14:10, <[email protected]> wrote:
Quoted 29 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 24.06.14 at 13:27, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 24.06.14 at 12:04, <[email protected]> wrote:

If so, can d at this point ever be anything other than dom_cow or NULL? I don't think so. Given that I think ASSERT(!(d == dom_cow && order != 0)) would more clearly capture the intent of the test (with the spelling out of the conditions being more important than the de morganing of the expression).

Quoted 6 lines

Indeed, d can only be NULL or dom_cow here (being in the else part of the if() you quoted at the top). So an alternative might indeed be ASSERT(d != dom_cow || !order), but that seems less desirable to me as it opens up ways to pass the ASSERT() with d != NULL should the if() condition ever get modified. I.e. I'd prefer the assertion to be as restrictive as possible, getting relaxed only when in fact necessary.

Quoted 8 lines

Since the original if involves d == dom_cow but nothing to do with order it seemed that the check was somehow specific to dom_cow's relationship to higher order allocations.

I suppose the question is what relationship would a non-NULL d have to the order of the allocation. i.e. if the if were changed to also consider dom_foo why would we expect now that dom_foo had any order requirements?

We won't know, but by having it the way it is now in the patch we're on the safe side (nothing unintended will slip through), whereas if we change to comparing against dom_cow a not sufficiently careful future change may introduce an issue.

Quoted 4 lines
Quoted 2 lines

That's true I . Could you add a comment though, since as it is the current relationship to dom_cow and order is somewhat obscured.

That I can do,

Thanks.

Quoted 6 lines

...

Quoted 1 line

ASSERT(d == NULL || ( d == dom_cow && !order ) ) is too much?

... but this looks too ugly to me (namely in the else path to an if checking d against exactly these two values).

There's three values in the assert, the third of which is constrained by the other two, which is rather the point. Anyway, a comment will suffice.

Ian.

#12 lore raw

PATCH v2 1/1 slightly consolidate code in free_domheap_pages()

In reply to Ian Campbell

... to combine the three scrubbing paths into a single one.

---
v2: Add a comment to an ASSERT() deemed unclear/non-obvious otherwise.

xen/common/page_alloc.c +36 -31
@@ -1724,47 +1724,52 @@ void free_domheap_pages(struct page_info
 
         spin_unlock_recursive(&d->page_alloc_lock);
     }
-    else if ( likely(d != NULL) && likely(d != dom_cow) )
+    else
     {
-        /* NB. May recursively lock from relinquish_memory(). */
-        spin_lock_recursive(&d->page_alloc_lock);
+        bool_t scrub;
 
-        for ( i = 0; i < (1 << order); i++ )
+        if ( likely(d) && likely(d != dom_cow) )
         {
-            BUG_ON((pg[i].u.inuse.type_info & PGT_count_mask) != 0);
-            page_list_del2(&pg[i], &d->page_list, &d->arch.relmem_list);
-        }
+            /* NB. May recursively lock from relinquish_memory(). */
+            spin_lock_recursive(&d->page_alloc_lock);
 
-        drop_dom_ref = !domain_adjust_tot_pages(d, -(1 << order));
-
-        spin_unlock_recursive(&d->page_alloc_lock);
+            for ( i = 0; i < (1 << order); i++ )
+            {
+                BUG_ON((pg[i].u.inuse.type_info & PGT_count_mask) != 0);
+                page_list_del2(&pg[i], &d->page_list, &d->arch.relmem_list);
+            }
+
+            drop_dom_ref = !domain_adjust_tot_pages(d, -(1 << order));
+
+            spin_unlock_recursive(&d->page_alloc_lock);
+
+            /*
+             * Normally we expect a domain to clear pages before freeing them,
+             * if it cares about the secrecy of their contents. However, after
+             * a domain has died we assume responsibility for erasure.
+             */
+            scrub = !!d->is_dying;
+        }
+        else
+        {
+            /*
+             * All we need to check is that on dom_cow only order-0 chunks
+             * make it here. Due to the if() above, the only two possible
+             * cases right now are d == NULL and d == dom_cow. To protect
+             * against relaxation of that if() condition without updating the
+             * check here, don't check d != dom_cow for now.
+             */
+            ASSERT(!d || !order);
+            drop_dom_ref = 0;
+            scrub = 1;
+        }
 
-        /*
-         * Normally we expect a domain to clear pages before freeing them, if 
-         * it cares about the secrecy of their contents. However, after a 
-         * domain has died we assume responsibility for erasure.
-         */
-        if ( unlikely(d->is_dying) )
+        if ( unlikely(scrub) )
             for ( i = 0; i < (1 << order); i++ )
                 scrub_one_page(&pg[i]);
 
         free_heap_pages(pg, order);
     }
-    else if ( unlikely(d == dom_cow) )
-    {
-        ASSERT(order == 0); 
-        scrub_one_page(pg);
-        free_heap_pages(pg, 0);
-        drop_dom_ref = 0;
-    }
-    else
-    {
-        /* Freeing anonymous domain-heap pages. */
-        for ( i = 0; i < (1 << order); i++ )
-            scrub_one_page(&pg[i]);
-        free_heap_pages(pg, order);
-        drop_dom_ref = 0;
-    }
 
     if ( drop_dom_ref )
         put_domain(d);

slightly consolidate code in free_domheap_pages()

... to combine the three scrubbing paths into a single one.

---
v2: Add a comment to an ASSERT() deemed unclear/non-obvious otherwise.

xen/common/page_alloc.c +36 -31

83 lines not on this page · raw message

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel