All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kirill Korotaev <dev@openvz.org>
To: Andrew Morton <akpm@osdl.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH] printk() should not be called under zone->lock
Date: Thu, 15 Jun 2006 13:01:41 +0400	[thread overview]
Message-ID: <449121F5.7040706@openvz.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 434 bytes --]

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>


[-- Attachment #2: diff-show-free-areas --]
[-- Type: text/plain, Size: 929 bytes --]

--- linux-2.6.17-rc6-mm1s.orig/mm/page_alloc.c	2006-06-09 15:37:09.000000000 +0400
+++ linux-2.6.16-rc6-mm1/mm/page_alloc.c	2006-06-15 12:42:31.000000000 +0400
@@ -1580,7 +1580,7 @@ void show_free_areas(void)
 	}
 
 	for_each_zone(zone) {
- 		unsigned long nr, flags, order, total = 0;
+ 		unsigned long nr[MAX_ORDER], flags, order, total = 0;
 
 		show_node(zone);
 		printk("%s: ", zone->name);
@@ -1591,11 +1591,12 @@ void show_free_areas(void)
 
 		spin_lock_irqsave(&zone->lock, flags);
 		for (order = 0; order < MAX_ORDER; order++) {
-			nr = zone->free_area[order].nr_free;
-			total += nr << order;
-			printk("%lu*%lukB ", nr, K(1UL) << order);
+			nr[order] = zone->free_area[order].nr_free;
+			total += nr[order] << order;
 		}
 		spin_unlock_irqrestore(&zone->lock, flags);
+		for (order = 0; order < MAX_ORDER; order++)
+			printk("%lu*%lukB ", nr[order], K(1UL) << order);
 		printk("= %lukB\n", K(total));
 	}
 

                 reply	other threads:[~2006-06-15  9:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=449121F5.7040706@openvz.org \
    --to=dev@openvz.org \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.