Commit 8f9de51a4a98ba32f839903b7d009788bc2c295d

Authored by Kirill Korotaev
Committed by Linus Torvalds
1 parent d501e62bc7

[PATCH] printk() should not be called under zone->lock

This patch fixes printk() under zone->lock in show_free_areas().  It can be
unsafe to call printk() under this lock, since caller can try to
allocate/free some memory and selfdeadlock on this lock.  I found
allocations/freeing mem both in netconsole and serial console.

This issue was faced in reallity when meminfo was periodically printed for
debug purposes and netconsole was used.

Signed-off-by: Kirill Korotaev <dev@openvz.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

Showing 1 changed file with 5 additions and 4 deletions Side-by-side Diff

... ... @@ -1491,7 +1491,7 @@
1491 1491 }
1492 1492  
1493 1493 for_each_zone(zone) {
1494   - unsigned long nr, flags, order, total = 0;
  1494 + unsigned long nr[MAX_ORDER], flags, order, total = 0;
1495 1495  
1496 1496 show_node(zone);
1497 1497 printk("%s: ", zone->name);
1498 1498  
... ... @@ -1502,11 +1502,12 @@
1502 1502  
1503 1503 spin_lock_irqsave(&zone->lock, flags);
1504 1504 for (order = 0; order < MAX_ORDER; order++) {
1505   - nr = zone->free_area[order].nr_free;
1506   - total += nr << order;
1507   - printk("%lu*%lukB ", nr, K(1UL) << order);
  1505 + nr[order] = zone->free_area[order].nr_free;
  1506 + total += nr[order] << order;
1508 1507 }
1509 1508 spin_unlock_irqrestore(&zone->lock, flags);
  1509 + for (order = 0; order < MAX_ORDER; order++)
  1510 + printk("%lu*%lukB ", nr[order], K(1UL) << order);
1510 1511 printk("= %lukB\n", K(total));
1511 1512 }
1512 1513