Merge branch 'core-rcu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 6 Aug 2010 16:23:07 +0000 (09:23 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 6 Aug 2010 16:23:07 +0000 (09:23 -0700)
* 'core-rcu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip:
  Revert "net: Make accesses to ->br_port safe for sparse RCU"
  mce: convert to rcu_dereference_index_check()
  net: Make accesses to ->br_port safe for sparse RCU
  vfs: add fs.h to define struct file
  lockdep: Add an in_workqueue_context() lockdep-based test function
  rcu: add __rcu API for later sparse checking
  rcu: add an rcu_dereference_index_check()
  tree/tiny rcu: Add debug RCU head objects
  mm: remove all rcu head initializations
  fs: remove all rcu head initializations, except on_stack initializations
  powerpc: remove all rcu head initializations

14 files changed:
arch/x86/kernel/cpu/mcheck/mce.c
fs/file.c
fs/partitions/check.c
include/linux/compiler.h
include/linux/fdtable.h
include/linux/rcupdate.h
include/linux/workqueue.h
kernel/rcupdate.c
kernel/rcutiny.c
kernel/rcutree.c
kernel/workqueue.c
lib/Kconfig.debug
mm/backing-dev.c
mm/slob.c

index 1970ef911c99b368e2f1f9e947bcdae71d2a2d84..e1269d62c569a3ec79f59516712c89192c2071bb 100644 (file)
@@ -51,7 +51,7 @@
 static DEFINE_MUTEX(mce_read_mutex);
 
 #define rcu_dereference_check_mce(p) \
-       rcu_dereference_check((p), \
+       rcu_dereference_index_check((p), \
                              rcu_read_lock_sched_held() || \
                              lockdep_is_held(&mce_read_mutex))
 
index 34bb7f71d99404e8b91a4bfb0654505d1e537318..cccaead962c2efe31c01029ca1ffa34676cffc8a 100644 (file)
--- a/fs/file.c
+++ b/fs/file.c
@@ -178,7 +178,6 @@ static struct fdtable * alloc_fdtable(unsigned int nr)
        fdt->open_fds = (fd_set *)data;
        data += nr / BITS_PER_BYTE;
        fdt->close_on_exec = (fd_set *)data;
-       INIT_RCU_HEAD(&fdt->rcu);
        fdt->next = NULL;
 
        return fdt;
@@ -312,7 +311,6 @@ struct files_struct *dup_fd(struct files_struct *oldf, int *errorp)
        new_fdt->close_on_exec = (fd_set *)&newf->close_on_exec_init;
        new_fdt->open_fds = (fd_set *)&newf->open_fds_init;
        new_fdt->fd = &newf->fd_array[0];
-       INIT_RCU_HEAD(&new_fdt->rcu);
        new_fdt->next = NULL;
 
        spin_lock(&oldf->file_lock);
@@ -430,7 +428,6 @@ struct files_struct init_files = {
                .fd             = &init_files.fd_array[0],
                .close_on_exec  = (fd_set *)&init_files.close_on_exec_init,
                .open_fds       = (fd_set *)&init_files.open_fds_init,
-               .rcu            = RCU_HEAD_INIT,
        },
        .file_lock      = __SPIN_LOCK_UNLOCKED(init_task.file_lock),
 };
index 5dcd4b0c5533346e360f12bc6c62c510a0722d28..72c52656dc2e7a00fd2f05b072002fe88302afe9 100644 (file)
@@ -459,7 +459,6 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
        }
 
        /* everything is up and running, commence */
-       INIT_RCU_HEAD(&p->rcu_head);
        rcu_assign_pointer(ptbl->part[partno], p);
 
        /* suppress uevent if the disk supresses it */
index a5a472b10746c662450059d8af969d58c7dcac6c..c1a62c56a660226b1592bc6bc269087adac58649 100644 (file)
@@ -16,6 +16,7 @@
 # define __release(x)  __context__(x,-1)
 # define __cond_lock(x,c)      ((c) ? ({ __acquire(x); 1; }) : 0)
 # define __percpu      __attribute__((noderef, address_space(3)))
+# define __rcu
 extern void __chk_user_ptr(const volatile void __user *);
 extern void __chk_io_ptr(const volatile void __iomem *);
 #else
@@ -34,6 +35,7 @@ extern void __chk_io_ptr(const volatile void __iomem *);
 # define __release(x) (void)0
 # define __cond_lock(x,c) (c)
 # define __percpu
+# define __rcu
 #endif
 
 #ifdef __KERNEL__
index d147461bc2712b9c9fb7aae84d65e600d6c60fd4..f59ed297b661fceb086a6ca188b54c3ff0006f85 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/rcupdate.h>
 #include <linux/types.h>
 #include <linux/init.h>
+#include <linux/fs.h>
 
 #include <asm/atomic.h>
 
index b653b4aaa8a6332c8d783f2cd9afb7c8882028b4..9fbc54a2585d42cb9276adf2c2d168f53e883f63 100644 (file)
@@ -40,6 +40,7 @@
 #include <linux/seqlock.h>
 #include <linux/lockdep.h>
 #include <linux/completion.h>
+#include <linux/debugobjects.h>
 
 #ifdef CONFIG_RCU_TORTURE_TEST
 extern int rcutorture_runnable; /* for sysctl */
@@ -79,6 +80,16 @@ extern void rcu_init(void);
        (ptr)->next = NULL; (ptr)->func = NULL; \
 } while (0)
 
+/*
+ * init_rcu_head_on_stack()/destroy_rcu_head_on_stack() are needed for dynamic
+ * initialization and destruction of rcu_head on the stack. rcu_head structures
+ * allocated dynamically in the heap or defined statically don't need any
+ * initialization.
+ */
+#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
+extern void init_rcu_head_on_stack(struct rcu_head *head);
+extern void destroy_rcu_head_on_stack(struct rcu_head *head);
+#else /* !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
 static inline void init_rcu_head_on_stack(struct rcu_head *head)
 {
 }
@@ -86,6 +97,7 @@ static inline void init_rcu_head_on_stack(struct rcu_head *head)
 static inline void destroy_rcu_head_on_stack(struct rcu_head *head)
 {
 }
+#endif /* #else !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 
@@ -517,4 +529,74 @@ extern void call_rcu(struct rcu_head *head,
 extern void call_rcu_bh(struct rcu_head *head,
                        void (*func)(struct rcu_head *head));
 
+/*
+ * debug_rcu_head_queue()/debug_rcu_head_unqueue() are used internally
+ * by call_rcu() and rcu callback execution, and are therefore not part of the
+ * RCU API. Leaving in rcupdate.h because they are used by all RCU flavors.
+ */
+
+#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
+# define STATE_RCU_HEAD_READY  0
+# define STATE_RCU_HEAD_QUEUED 1
+
+extern struct debug_obj_descr rcuhead_debug_descr;
+
+static inline void debug_rcu_head_queue(struct rcu_head *head)
+{
+       debug_object_activate(head, &rcuhead_debug_descr);
+       debug_object_active_state(head, &rcuhead_debug_descr,
+                                 STATE_RCU_HEAD_READY,
+                                 STATE_RCU_HEAD_QUEUED);
+}
+
+static inline void debug_rcu_head_unqueue(struct rcu_head *head)
+{
+       debug_object_active_state(head, &rcuhead_debug_descr,
+                                 STATE_RCU_HEAD_QUEUED,
+                                 STATE_RCU_HEAD_READY);
+       debug_object_deactivate(head, &rcuhead_debug_descr);
+}
+#else  /* !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
+static inline void debug_rcu_head_queue(struct rcu_head *head)
+{
+}
+
+static inline void debug_rcu_head_unqueue(struct rcu_head *head)
+{
+}
+#endif /* #else !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
+
+#ifndef CONFIG_PROVE_RCU
+#define __do_rcu_dereference_check(c) do { } while (0)
+#endif /* #ifdef CONFIG_PROVE_RCU */
+
+#define __rcu_dereference_index_check(p, c) \
+       ({ \
+               typeof(p) _________p1 = ACCESS_ONCE(p); \
+               __do_rcu_dereference_check(c); \
+               smp_read_barrier_depends(); \
+               (_________p1); \
+       })
+
+/**
+ * rcu_dereference_index_check() - rcu_dereference for indices with debug checking
+ * @p: The pointer to read, prior to dereferencing
+ * @c: The conditions under which the dereference will take place
+ *
+ * Similar to rcu_dereference_check(), but omits the sparse checking.
+ * This allows rcu_dereference_index_check() to be used on integers,
+ * which can then be used as array indices.  Attempting to use
+ * rcu_dereference_check() on an integer will give compiler warnings
+ * because the sparse address-space mechanism relies on dereferencing
+ * the RCU-protected pointer.  Dereferencing integers is not something
+ * that even gcc will put up with.
+ *
+ * Note that this function does not implicitly check for RCU read-side
+ * critical sections.  If this function gains lots of uses, it might
+ * make sense to provide versions for each flavor of RCU, but it does
+ * not make sense as of early 2010.
+ */
+#define rcu_dereference_index_check(p, c) \
+       __rcu_dereference_index_check((p), (c))
+
 #endif /* __LINUX_RCUPDATE_H */
index 9466e860d8c2a6dd816da1f7363117ebd56291f5..d0f7c8178498dbc8cd2fff32577a000a2bc1db8e 100644 (file)
@@ -297,4 +297,8 @@ static inline long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg)
 #else
 long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg);
 #endif /* CONFIG_SMP */
+
+#ifdef CONFIG_LOCKDEP
+int in_workqueue_context(struct workqueue_struct *wq);
+#endif
 #endif
index 72a8dc9567f5825ee24bb52174b67953ca372b63..4d169835fb362dcd6eb52a916a0d8e85e48c8fb8 100644 (file)
@@ -114,3 +114,163 @@ int rcu_my_thread_group_empty(void)
 }
 EXPORT_SYMBOL_GPL(rcu_my_thread_group_empty);
 #endif /* #ifdef CONFIG_PROVE_RCU */
+
+#ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD
+static inline void debug_init_rcu_head(struct rcu_head *head)
+{
+       debug_object_init(head, &rcuhead_debug_descr);
+}
+
+static inline void debug_rcu_head_free(struct rcu_head *head)
+{
+       debug_object_free(head, &rcuhead_debug_descr);
+}
+
+/*
+ * fixup_init is called when:
+ * - an active object is initialized
+ */
+static int rcuhead_fixup_init(void *addr, enum debug_obj_state state)
+{
+       struct rcu_head *head = addr;
+
+       switch (state) {
+       case ODEBUG_STATE_ACTIVE:
+               /*
+                * Ensure that queued callbacks are all executed.
+                * If we detect that we are nested in a RCU read-side critical
+                * section, we should simply fail, otherwise we would deadlock.
+                */
+               if (rcu_preempt_depth() != 0 || preempt_count() != 0 ||
+                   irqs_disabled()) {
+                       WARN_ON(1);
+                       return 0;
+               }
+               rcu_barrier();
+               rcu_barrier_sched();
+               rcu_barrier_bh();
+               debug_object_init(head, &rcuhead_debug_descr);
+               return 1;
+       default:
+               return 0;
+       }
+}
+
+/*
+ * fixup_activate is called when:
+ * - an active object is activated
+ * - an unknown object is activated (might be a statically initialized object)
+ * Activation is performed internally by call_rcu().
+ */
+static int rcuhead_fixup_activate(void *addr, enum debug_obj_state state)
+{
+       struct rcu_head *head = addr;
+
+       switch (state) {
+
+       case ODEBUG_STATE_NOTAVAILABLE:
+               /*
+                * This is not really a fixup. We just make sure that it is
+                * tracked in the object tracker.
+                */
+               debug_object_init(head, &rcuhead_debug_descr);
+               debug_object_activate(head, &rcuhead_debug_descr);
+               return 0;
+
+       case ODEBUG_STATE_ACTIVE:
+               /*
+                * Ensure that queued callbacks are all executed.
+                * If we detect that we are nested in a RCU read-side critical
+                * section, we should simply fail, otherwise we would deadlock.
+                */
+               if (rcu_preempt_depth() != 0 || preempt_count() != 0 ||
+                   irqs_disabled()) {
+                       WARN_ON(1);
+                       return 0;
+               }
+               rcu_barrier();
+               rcu_barrier_sched();
+               rcu_barrier_bh();
+               debug_object_activate(head, &rcuhead_debug_descr);
+               return 1;
+       default:
+               return 0;
+       }
+}
+
+/*
+ * fixup_free is called when:
+ * - an active object is freed
+ */
+static int rcuhead_fixup_free(void *addr, enum debug_obj_state state)
+{
+       struct rcu_head *head = addr;
+
+       switch (state) {
+       case ODEBUG_STATE_ACTIVE:
+               /*
+                * Ensure that queued callbacks are all executed.
+                * If we detect that we are nested in a RCU read-side critical
+                * section, we should simply fail, otherwise we would deadlock.
+                */
+#ifndef CONFIG_PREEMPT
+               WARN_ON(1);
+               return 0;
+#else
+               if (rcu_preempt_depth() != 0 || preempt_count() != 0 ||
+                   irqs_disabled()) {
+                       WARN_ON(1);
+                       return 0;
+               }
+               rcu_barrier();
+               rcu_barrier_sched();
+               rcu_barrier_bh();
+               debug_object_free(head, &rcuhead_debug_descr);
+               return 1;
+#endif
+       default:
+               return 0;
+       }
+}
+
+/**
+ * init_rcu_head_on_stack() - initialize on-stack rcu_head for debugobjects
+ * @head: pointer to rcu_head structure to be initialized
+ *
+ * This function informs debugobjects of a new rcu_head structure that
+ * has been allocated as an auto variable on the stack.  This function
+ * is not required for rcu_head structures that are statically defined or
+ * that are dynamically allocated on the heap.  This function has no
+ * effect for !CONFIG_DEBUG_OBJECTS_RCU_HEAD kernel builds.
+ */
+void init_rcu_head_on_stack(struct rcu_head *head)
+{
+       debug_object_init_on_stack(head, &rcuhead_debug_descr);
+}
+EXPORT_SYMBOL_GPL(init_rcu_head_on_stack);
+
+/**
+ * destroy_rcu_head_on_stack() - destroy on-stack rcu_head for debugobjects
+ * @head: pointer to rcu_head structure to be initialized
+ *
+ * This function informs debugobjects that an on-stack rcu_head structure
+ * is about to go out of scope.  As with init_rcu_head_on_stack(), this
+ * function is not required for rcu_head structures that are statically
+ * defined or that are dynamically allocated on the heap.  Also as with
+ * init_rcu_head_on_stack(), this function has no effect for
+ * !CONFIG_DEBUG_OBJECTS_RCU_HEAD kernel builds.
+ */
+void destroy_rcu_head_on_stack(struct rcu_head *head)
+{
+       debug_object_free(head, &rcuhead_debug_descr);
+}
+EXPORT_SYMBOL_GPL(destroy_rcu_head_on_stack);
+
+struct debug_obj_descr rcuhead_debug_descr = {
+       .name = "rcu_head",
+       .fixup_init = rcuhead_fixup_init,
+       .fixup_activate = rcuhead_fixup_activate,
+       .fixup_free = rcuhead_fixup_free,
+};
+EXPORT_SYMBOL_GPL(rcuhead_debug_descr);
+#endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
index 38729d3cd23692887afac015b442c052a150f38c..196ec02f8be0c1ad884b7d69599005a6fc3a4429 100644 (file)
@@ -169,6 +169,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
        while (list) {
                next = list->next;
                prefetch(next);
+               debug_rcu_head_unqueue(list);
                list->func(list);
                list = next;
        }
@@ -211,6 +212,7 @@ static void __call_rcu(struct rcu_head *head,
 {
        unsigned long flags;
 
+       debug_rcu_head_queue(head);
        head->func = func;
        head->next = NULL;
 
index d4437345706f8a539eee6dba201662fd791978ef..d5bc43976c5ad202fa41be0456797d40bdde0c0d 100644 (file)
@@ -1112,6 +1112,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
        while (list) {
                next = list->next;
                prefetch(next);
+               debug_rcu_head_unqueue(list);
                list->func(list);
                list = next;
                if (++count >= rdp->blimit)
@@ -1388,6 +1389,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
        unsigned long flags;
        struct rcu_data *rdp;
 
+       debug_rcu_head_queue(head);
        head->func = func;
        head->next = NULL;
 
index 327d2deb44515b438c8e43cec56415d85b22342d..59fef1531dd2eba5dd5547cc732e97e3496c05d0 100644 (file)
@@ -68,6 +68,21 @@ struct workqueue_struct {
 #endif
 };
 
+#ifdef CONFIG_LOCKDEP
+/**
+ * in_workqueue_context() - in context of specified workqueue?
+ * @wq: the workqueue of interest
+ *
+ * Checks lockdep state to see if the current task is executing from
+ * within a workqueue item.  This function exists only if lockdep is
+ * enabled.
+ */
+int in_workqueue_context(struct workqueue_struct *wq)
+{
+       return lock_is_held(&wq->lockdep_map);
+}
+#endif
+
 #ifdef CONFIG_DEBUG_OBJECTS_WORK
 
 static struct debug_obj_descr work_debug_descr;
index 67fa774f9572cd21c6dc160e67bb2e509ec54db2..e80d6bf1c43d39050ab09fe55198073e4a585b3c 100644 (file)
@@ -307,6 +307,12 @@ config DEBUG_OBJECTS_WORK
          work queue routines to track the life time of work objects and
          validate the work operations.
 
+config DEBUG_OBJECTS_RCU_HEAD
+       bool "Debug RCU callbacks objects"
+       depends on DEBUG_OBJECTS && PREEMPT
+       help
+         Enable this to turn on debugging of RCU list heads (call_rcu() usage).
+
 config DEBUG_OBJECTS_ENABLE_DEFAULT
        int "debug_objects bootup default value (0-1)"
         range 0 1
index 123bcef13e51806ce3d57232d4ad665a60d7d172..f9fd3dd3916b97067fbac7b2742c2195c04f4748 100644 (file)
@@ -665,7 +665,6 @@ int bdi_init(struct backing_dev_info *bdi)
        bdi->max_ratio = 100;
        bdi->max_prop_frac = PROP_FRAC_BASE;
        spin_lock_init(&bdi->wb_lock);
-       INIT_RCU_HEAD(&bdi->rcu_head);
        INIT_LIST_HEAD(&bdi->bdi_list);
        INIT_LIST_HEAD(&bdi->wb_list);
        INIT_LIST_HEAD(&bdi->work_list);
index 23631e2bb57af43c5cb577a75323cc9768798016..19d2e5d46724824864055612ddcda295f9871d4c 100644 (file)
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -639,7 +639,6 @@ void kmem_cache_free(struct kmem_cache *c, void *b)
        if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
                struct slob_rcu *slob_rcu;
                slob_rcu = b + (c->size - sizeof(struct slob_rcu));
-               INIT_RCU_HEAD(&slob_rcu->head);
                slob_rcu->size = c->size;
                call_rcu(&slob_rcu->head, kmem_rcu_free);
        } else {