From: Arnd Bergmann <arnd@arndb.de>
To: Andrew Morton <akpm@osdl.org>
Cc: rusty@rustcorp.com.au, linux-arch@vger.kernel.org,
epasch@de.ibm.com, hare@suse.de
Subject: Re: static DEFINE_PER_CPU vs. modules
Date: Tue, 4 May 2004 16:17:29 +0200 [thread overview]
Message-ID: <200405041617.37371.arnd@arndb.de> (raw)
In-Reply-To: <20040503193835.72c62ad8.akpm@osdl.org>
On Tuesday 04 May 2004 04:38, Andrew Morton wrote:
> Arnd Bergmann <arnd@arndb.de> wrote:
> >
> > The idea I had for preventing the same bug from happening
> > in the future is to provoke a compile error for modules using
> > 'static DEFINE_PER_CPU', see patch below.
>
> It's not a big success with CONFIG_SMP=n.
>
> kernel/fork.c:55: warning: return-type defaults to `int'
> kernel/fork.c: In function `__PER_CPU_NOSTATIC':
Sorry about that, I accidentally defined __PER_CPU_NOSTATIC
inside '#ifdef CONFIG_SMP'. This now builds with and without
SMP.
Arnd <><
===== drivers/scsi/scsi.c 1.142 vs edited =====
--- 1.142/drivers/scsi/scsi.c Sun Apr 4 17:01:05 2004
+++ edited/drivers/scsi/scsi.c Thu Apr 29 17:59:34 2004
@@ -672,7 +672,7 @@
/*
* Per-CPU I/O completion queue.
*/
-static DEFINE_PER_CPU(struct list_head, scsi_done_q);
+DEFINE_PER_CPU(struct list_head, scsi_done_q);
/**
* scsi_done - Enqueue the finished SCSI command into the done queue.
===== include/asm-generic/percpu.h 1.10 vs edited =====
--- 1.10/include/asm-generic/percpu.h Mon Jan 19 07:28:34 2004
+++ edited/include/asm-generic/percpu.h Tue May 4 15:59:18 2004
@@ -3,12 +3,23 @@
#include <linux/compiler.h>
#define __GENERIC_PER_CPU
+
+/* modules must not use "static DEFINE_PER_CPU", so add an
+ * extern declaration that causes a compile error if somebody
+ * attempts */
+#ifndef MODULE
+#define __PER_CPU_NOSTATIC(decl)
+#else
+#define __PER_CPU_NOSTATIC(decl) extern decl;
+#endif
+
#ifdef CONFIG_SMP
extern unsigned long __per_cpu_offset[NR_CPUS];
/* Separate out the type, so (int[3], foo) works. */
#define DEFINE_PER_CPU(type, name) \
+ __PER_CPU_NOSTATIC(__typeof__(type) per_cpu__##name) \
__attribute__((__section__(".data.percpu"))) __typeof__(type) per_cpu__##name
/* var is in discarded region: offset to particular copy we want */
@@ -27,6 +38,7 @@
#else /* ! SMP */
#define DEFINE_PER_CPU(type, name) \
+ __PER_CPU_NOSTATIC(__typeof__(type) per_cpu__##name) \
__typeof__(type) per_cpu__##name
#define per_cpu(var, cpu) (*((void)cpu, &per_cpu__##var))
===== net/ipv6/icmp.c 1.49 vs edited =====
--- 1.49/net/ipv6/icmp.c Fri Apr 16 22:54:44 2004
+++ edited/net/ipv6/icmp.c Thu Apr 29 17:59:58 2004
@@ -76,7 +76,7 @@
*
* On SMP we have one ICMP socket per-cpu.
*/
-static DEFINE_PER_CPU(struct socket *, __icmpv6_socket) = NULL;
+DEFINE_PER_CPU(struct socket *, __icmpv6_socket) = NULL;
#define icmpv6_socket __get_cpu_var(__icmpv6_socket)
static int icmpv6_rcv(struct sk_buff **pskb, unsigned int *nhoffp);
next prev parent reply other threads:[~2004-05-04 14:18 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-03 15:41 static DEFINE_PER_CPU vs. modules Arnd Bergmann
2004-05-03 17:50 ` David Mosberger
2004-05-03 18:01 ` Richard Henderson
2004-05-03 18:37 ` David Mosberger
2004-05-03 22:24 ` Arnd Bergmann
2004-05-03 23:12 ` David Mosberger
2004-05-04 8:56 ` Arnd Bergmann
2004-05-04 2:38 ` Andrew Morton
2004-05-04 14:17 ` Arnd Bergmann [this message]
2004-05-04 16:29 ` David Mosberger
2004-05-04 19:03 ` Andrew Morton
2004-05-04 19:15 ` David Mosberger
2004-05-04 19:23 ` Andrew Morton
2004-05-04 19:45 ` David Mosberger
2004-05-05 8:21 ` Arnd Bergmann
2004-05-05 8:29 ` Andrew Morton
2004-05-05 9:24 ` Arnd Bergmann
2004-05-05 9:33 ` Rusty Russell
2004-05-05 16:17 ` David Mosberger
2004-05-05 3:18 ` Richard Henderson
-- strict thread matches above, loose matches on Subject: below --
2004-05-05 17:42 Martin Schwidefsky
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=200405041617.37371.arnd@arndb.de \
--to=arnd@arndb.de \
--cc=akpm@osdl.org \
--cc=epasch@de.ibm.com \
--cc=hare@suse.de \
--cc=linux-arch@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
/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