public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* linux-next: build failure after merge of the percpu tree
@ 2010-09-10  2:45 Stephen Rothwell
  2010-09-10  5:31 ` [PATCH] x86, percpu: Fix __this_cpu_ptr with const pointers Brian Gerst
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Rothwell @ 2010-09-10  2:45 UTC (permalink / raw)
  To: Tejun Heo, Rusty Russell, Christoph Lameter, Ingo Molnar
  Cc: linux-next, linux-kernel, Brian Gerst

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

Hi all,

After merging the percpu tree, today's linux-next build (x86_64
allmodconfig) failed like this:

In file included from drivers/vhost/net.c:26:
include/linux/if_macvlan.h: In function 'macvlan_count_rx':
include/linux/if_macvlan.h:69: error: read-only variable 'tcp_ptr__' used as 'asm' output
In file included from drivers/net/macvlan.c:30:
include/linux/if_macvlan.h: In function 'macvlan_count_rx':
include/linux/if_macvlan.h:69: error: read-only variable 'tcp_ptr__' used as 'asm' output
In file included from drivers/net/macvtap.c:2:
include/linux/if_macvlan.h: In function 'macvlan_count_rx':
include/linux/if_macvlan.h:69: error: read-only variable 'tcp_ptr__' used as 'asm' output

Caused by commit 7f56c13698abfb1bdf6cf2b5cfcd80626d44c12e ("x86, percpu:
Optimize this_cpu_ptr").

That line in if_macvlan.h is:

	rx_stats = this_cpu_ptr(vlan->rx_stats);

Where vlan is a "const struct macvlan_dev *".

I have used the percpu tree from next-20100909 for today.
-- 
Cheers,
Stephen Rothwell                    sfr@canb.auug.org.au
http://www.canb.auug.org.au/~sfr/

[-- Attachment #2: Type: application/pgp-signature, Size: 490 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] x86, percpu: Fix __this_cpu_ptr with const pointers
  2010-09-10  2:45 linux-next: build failure after merge of the percpu tree Stephen Rothwell
@ 2010-09-10  5:31 ` Brian Gerst
  2010-09-10  8:34   ` Tejun Heo
  0 siblings, 1 reply; 3+ messages in thread
From: Brian Gerst @ 2010-09-10  5:31 UTC (permalink / raw)
  To: tj; +Cc: linux-kernel, Stephen Rothwell

Fix this error when the pointer is marked const:
error: read-only variable 'tcp_ptr__' used as 'asm' output

Signed-off-by: Brian Gerst <brgerst@gmail.com>
CC: Stephen Rothwell <sfr@canb.auug.org.au>
---
 arch/x86/include/asm/percpu.h |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index fe418dd..f62b52c 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -54,12 +54,12 @@
  */
 #define __this_cpu_ptr(ptr)				\
 ({							\
-	typeof(ptr) tcp_ptr__ = (ptr);			\
+	unsigned long tcp_ptr__;			\
 	__verify_pcpu_ptr(ptr);				\
 	asm volatile("add " __percpu_arg(1) ", %0"	\
-		     : "+r" (tcp_ptr__)			\
-		     : "m" (this_cpu_off));		\
-	tcp_ptr__;					\
+		     : "=r" (tcp_ptr__)			\
+		     : "m" (this_cpu_off), "0" (ptr));	\
+	(typeof(ptr) __kernel __force) tcp_ptr__;	\
 })
 #else
 #define __percpu_arg(x)		"%P" #x
-- 
1.7.2.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86, percpu: Fix __this_cpu_ptr with const pointers
  2010-09-10  5:31 ` [PATCH] x86, percpu: Fix __this_cpu_ptr with const pointers Brian Gerst
@ 2010-09-10  8:34   ` Tejun Heo
  0 siblings, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2010-09-10  8:34 UTC (permalink / raw)
  To: Brian Gerst; +Cc: linux-kernel, Stephen Rothwell

I folded the fix into the original patch and also updated the address
space casting for sparse.

Thanks.

>From 9c5b46f782cde2c88a5e4f02a6112bfcfb105f8f Mon Sep 17 00:00:00 2001
From: Brian Gerst <brgerst@gmail.com>
Date: Thu, 9 Sep 2010 18:17:26 +0200
Subject: [PATCH] x86, percpu: Optimize this_cpu_ptr

Allow arches to implement __this_cpu_ptr, and provide an x86 version.

Before:
	movq $foo, %rax
	movq %gs:this_cpu_off, %rdx
	addq %rdx, %rax

After:
	movq $foo, %rax
	addq %gs:this_cpu_off, %rax

The benefit is doing it in one less instruction and not clobbering
a temporary register.

tj: * Beefed up the comment a bit and renamed in-macro temp variable
      to match neighboring macros.

    * Folded fix for const pointer case found in linux-next.

    * Fixed sparse notation.

Signed-off-by: Brian Gerst <brgerst@gmail.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
---
 arch/x86/include/asm/percpu.h |   14 ++++++++++++++
 include/asm-generic/percpu.h  |    9 +++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index cd28f9a..f899e01 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -47,6 +47,20 @@
 #ifdef CONFIG_SMP
 #define __percpu_arg(x)		"%%"__stringify(__percpu_seg)":%P" #x
 #define __my_cpu_offset		percpu_read(this_cpu_off)
+
+/*
+ * Compared to the generic __my_cpu_offset version, the following
+ * saves one instruction and avoids clobbering a temp register.
+ */
+#define __this_cpu_ptr(ptr)				\
+({							\
+	unsigned long tcp_ptr__;			\
+	__verify_pcpu_ptr(ptr);				\
+	asm volatile("add " __percpu_arg(1) ", %0"	\
+		     : "=r" (tcp_ptr__)			\
+		     : "m" (this_cpu_off), "0" (ptr));	\
+	(typeof(*(ptr)) __kernel __force *)tcp_ptr__;	\
+})
 #else
 #define __percpu_arg(x)		"%P" #x
 #endif
diff --git a/include/asm-generic/percpu.h b/include/asm-generic/percpu.h
index 08923b6..ec64311 100644
--- a/include/asm-generic/percpu.h
+++ b/include/asm-generic/percpu.h
@@ -60,9 +60,14 @@ extern unsigned long __per_cpu_offset[NR_CPUS];
 #define __raw_get_cpu_var(var) \
 	(*SHIFT_PERCPU_PTR(&(var), __my_cpu_offset))

-#define this_cpu_ptr(ptr) SHIFT_PERCPU_PTR(ptr, my_cpu_offset)
+#ifndef __this_cpu_ptr
 #define __this_cpu_ptr(ptr) SHIFT_PERCPU_PTR(ptr, __my_cpu_offset)
-
+#endif
+#ifdef CONFIG_DEBUG_PREEMPT
+#define this_cpu_ptr(ptr) SHIFT_PERCPU_PTR(ptr, my_cpu_offset)
+#else
+#define this_cpu_ptr(ptr) __this_cpu_ptr(ptr)
+#endif

 #ifdef CONFIG_HAVE_SETUP_PER_CPU_AREA
 extern void setup_per_cpu_areas(void);
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-09-10  8:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-10  2:45 linux-next: build failure after merge of the percpu tree Stephen Rothwell
2010-09-10  5:31 ` [PATCH] x86, percpu: Fix __this_cpu_ptr with const pointers Brian Gerst
2010-09-10  8:34   ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox