Skip to contentSkip to conversation

xen/timers: Fix memory leak with cpu unplug/plug (take 2)

PATCH In review Andrew Cooper 2 participants 2 messages Apr 23, 2019 – Apr 25, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/timers: Fix memory leak with cpu unplug/plug (take 2)

Previous attempts to fix this leak failed to identify the root cause, and ultimately failed. The cause is the CPU_UP_PREPARE case (re)initialising ts->heap back to dummy_heap, which leaks the previous allocation.

Rearrange the logic to only initialise ts once. This also avoids the redundant (but benign, due to ts->inactive always being empty) initialising of the other ts fields.

---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Wei Liu <[email protected]>
CC: Julien Grall <[email protected]>

---
 xen/common/timer.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
xen/common/timer.c +7 -3
index f60712a..650e398 100644
@@ -657,9 +657,13 @@ static int cpu_callback(
     switch ( action )
     {
     case CPU_UP_PREPARE:
-        INIT_LIST_HEAD(&ts->inactive);
-        spin_lock_init(&ts->lock);
-        ts->heap = dummy_heap;
+        /* Only initialise ts once. */
+        if ( !ts->heap )
+        {
+            INIT_LIST_HEAD(&ts->inactive);
+            spin_lock_init(&ts->lock);
+            ts->heap = dummy_heap;
+        }
         break;
 
     case CPU_UP_CANCELED:
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 23.04.19 at 17:49, <[email protected]> wrote:

Previous attempts to fix this leak failed to identify the root cause, and ultimately failed. The cause is the CPU_UP_PREPARE case (re)initialising ts->heap back to dummy_heap, which leaks the previous allocation.

Rearrange the logic to only initialise ts once. This also avoids the redundant (but benign, due to ts->inactive always being empty) initialising of the other ts fields.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel