linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Valdis.Kletnieks@vt.edu
Cc: Peter Zijlstra <peterz@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Ingo Molnar <mingo@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] percpu,lockdep: implement and use is_static_percpu_address()
Date: Tue, 09 Mar 2010 18:12:05 +0900	[thread overview]
Message-ID: <4B9610E5.4080805@kernel.org> (raw)
In-Reply-To: <4B95EE4C.3020606@kernel.org>

lockdep has custom code to check whether a pointer belongs to static
percpu area which is somewhat broken.  Implement proper
is_static_percpu_address() in percpu and replace the custom code.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
---
This wasn't the cause this time but I'll queue the fix in percpu tree
anyway.

Thanks.

 include/linux/percpu.h |    7 +++++++
 kernel/lockdep.c       |   15 ++-------------
 mm/percpu.c            |   26 ++++++++++++++++++++++++++
 3 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/include/linux/percpu.h b/include/linux/percpu.h
index a93e5bf..1eca064 100644
--- a/include/linux/percpu.h
+++ b/include/linux/percpu.h
@@ -137,6 +137,7 @@ extern int __init pcpu_page_first_chunk(size_t reserved_size,
 extern void __percpu *__alloc_reserved_percpu(size_t size, size_t align);
 extern void __percpu *__alloc_percpu(size_t size, size_t align);
 extern void free_percpu(void __percpu *__pdata);
+extern bool is_static_percpu_address(unsigned long addr);
 extern phys_addr_t per_cpu_ptr_to_phys(void *addr);
 
 #ifndef CONFIG_HAVE_SETUP_PER_CPU_AREA
@@ -163,6 +164,12 @@ static inline void free_percpu(void __percpu *p)
 	kfree(p);
 }
 
+/* can't distinguish from other static vars, always false */
+static inline bool is_static_percpu_address(unsigned long addr)
+{
+	return false;
+}
+
 static inline phys_addr_t per_cpu_ptr_to_phys(void *addr)
 {
 	return __pa(addr);
diff --git a/kernel/lockdep.c b/kernel/lockdep.c
index 0c30d04..4206f6f 100644
--- a/kernel/lockdep.c
+++ b/kernel/lockdep.c
@@ -582,9 +582,6 @@ static int static_obj(void *obj)
 	unsigned long start = (unsigned long) &_stext,
 		      end   = (unsigned long) &_end,
 		      addr  = (unsigned long) obj;
-#ifdef CONFIG_SMP
-	int i;
-#endif
 
 	/*
 	 * static variable?
@@ -595,19 +592,11 @@ static int static_obj(void *obj)
 	if (arch_is_kernel_data(addr))
 		return 1;
 
-#ifdef CONFIG_SMP
 	/*
 	 * percpu var?
 	 */
-	for_each_possible_cpu(i) {
-		start = (unsigned long) &__per_cpu_start + per_cpu_offset(i);
-		end   = (unsigned long) &__per_cpu_start + PERCPU_ENOUGH_ROOM
-					+ per_cpu_offset(i);
-
-		if ((addr >= start) && (addr < end))
-			return 1;
-	}
-#endif
+	if (is_static_percpu_address(addr))
+		return 1;
 
 	/*
 	 * module var?
diff --git a/mm/percpu.c b/mm/percpu.c
index 768419d..ae4d058 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -1304,6 +1304,32 @@ void free_percpu(void __percpu *ptr)
 EXPORT_SYMBOL_GPL(free_percpu);
 
 /**
+ * is_static_percpu_address - test whether address is from static percpu area
+ * @addr: address to test
+ *
+ * Test whether @addr belongs to static percpu area.  Module static
+ * percpu areas allocated via __alloc_reserved_percpu() is not
+ * considered.  Use is_module_address() for those.
+ *
+ * RETURNS:
+ * %true if @addr is from static percpu area, %false otherwise.
+ */
+bool is_static_percpu_address(unsigned long addr)
+{
+	const size_t static_size = __per_cpu_end - __per_cpu_start;
+	void __percpu *base = __addr_to_pcpu_ptr(pcpu_base_addr);
+	unsigned int cpu;
+
+	for_each_possible_cpu(cpu) {
+		void *start = per_cpu_ptr(base, cpu);
+
+		if ((void *)addr >= start && (void *)addr < start + static_size)
+			return true;
+        }
+	return false;
+}
+
+/**
  * per_cpu_ptr_to_phys - convert translated percpu address to physical address
  * @addr: the address to be converted to physical address
  *
-- 
1.6.4.2


  parent reply	other threads:[~2010-03-09  9:12 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-08 18:30 odd lockdep messages Valdis.Kletnieks
2010-03-08 18:43 ` Peter Zijlstra
2010-03-08 20:00   ` Valdis.Kletnieks
2010-03-09  1:54   ` Tejun Heo
2010-03-09  6:27     ` Valdis.Kletnieks
2010-03-09  6:44       ` Tejun Heo
2010-03-09  8:51         ` Valdis.Kletnieks
2010-03-09 14:18           ` Greg KH
2010-03-09  9:12         ` Tejun Heo [this message]
2010-03-09 11:25           ` [PATCH] percpu,lockdep: implement and use is_static_percpu_address() Peter Zijlstra
2010-03-09 11:42             ` Tejun Heo
2010-03-09 11:46               ` Tejun Heo
2010-03-09 11:52               ` Peter Zijlstra
2010-03-10  9:56               ` [PATCH 1/2] module: encapsulate percpu handling better and record percpu_size Tejun Heo
2010-03-10  9:57                 ` [PATCH 2/2] percpu,module: implement and use is_kernel/module_percpu_address() Tejun Heo
2010-03-10 10:42                   ` Peter Zijlstra
2010-03-29  8:26                 ` [PATCH 1/2] module: encapsulate percpu handling better and record percpu_size Rusty Russell
2010-03-29 14:12                   ` Tejun Heo

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=4B9610E5.4080805@kernel.org \
    --to=tj@kernel.org \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).