* [PATCH] RCU: Better explain the condition parameter of rcu_dereference_check()
@ 2010-04-07 17:15 David Howells
2010-04-07 17:28 ` Paul E. McKenney
2010-04-08 2:50 ` Yong Zhang
0 siblings, 2 replies; 4+ messages in thread
From: David Howells @ 2010-04-07 17:15 UTC (permalink / raw)
To: paulmck, eric.dumazet; +Cc: linux-kernel, David Howells
Better explain the condition parameter of rcu_dereference_check() that
describes the conditions under which the dereference is permitted to take
place. This condition is only checked under lockdep proving.
Signed-off-by: David Howells <dhowells@redhat.com>
---
include/linux/rcupdate.h | 28 +++++++++++++++++++++++-----
1 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 872a98e..acf9958 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -195,12 +195,30 @@ static inline int rcu_read_lock_sched_held(void)
/**
* rcu_dereference_check - rcu_dereference with debug checking
+ * @p: The pointer to read, prior to dereferencing
+ * @c: The conditions under which the dereference will take place
*
- * Do an rcu_dereference(), but check that the context is correct.
- * For example, rcu_dereference_check(gp, rcu_read_lock_held()) to
- * ensure that the rcu_dereference_check() executes within an RCU
- * read-side critical section. It is also possible to check for
- * locks being held, for example, by using lockdep_is_held().
+ * Do an rcu_dereference(), but check that the conditions under which the
+ * dereference will take place are correct. Typically the conditions indicate
+ * the various locking conditions that should be held at that point. The check
+ * should return true if the conditions are satisfied.
+ *
+ * For example:
+ *
+ * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() ||
+ * lockdep_is_held(&foo->lock));
+ *
+ * could be used to indicate to lockdep that foo->bar may only be dereferenced
+ * if either the RCU read lock is held, or that the lock required to replace
+ * the bar struct at foo->bar is held.
+ *
+ * Note that the list of conditions may also include indications of when a lock
+ * need not be held, for example during initialisation or destruction of the
+ * target struct:
+ *
+ * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() ||
+ * lockdep_is_held(&foo->lock),
+ * atomic_read(&foo->usage) == 0);
*/
#define rcu_dereference_check(p, c) \
({ \
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] RCU: Better explain the condition parameter of rcu_dereference_check()
2010-04-07 17:15 [PATCH] RCU: Better explain the condition parameter of rcu_dereference_check() David Howells
@ 2010-04-07 17:28 ` Paul E. McKenney
2010-04-08 2:50 ` Yong Zhang
1 sibling, 0 replies; 4+ messages in thread
From: Paul E. McKenney @ 2010-04-07 17:28 UTC (permalink / raw)
To: David Howells; +Cc: eric.dumazet, linux-kernel
On Wed, Apr 07, 2010 at 06:15:00PM +0100, David Howells wrote:
> Better explain the condition parameter of rcu_dereference_check() that
> describes the conditions under which the dereference is permitted to take
> place. This condition is only checked under lockdep proving.
Very good, I have queued this. Thank you!
Thanx, Paul
> Signed-off-by: David Howells <dhowells@redhat.com>
> ---
>
> include/linux/rcupdate.h | 28 +++++++++++++++++++++++-----
> 1 files changed, 23 insertions(+), 5 deletions(-)
>
> diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
> index 872a98e..acf9958 100644
> --- a/include/linux/rcupdate.h
> +++ b/include/linux/rcupdate.h
> @@ -195,12 +195,30 @@ static inline int rcu_read_lock_sched_held(void)
>
> /**
> * rcu_dereference_check - rcu_dereference with debug checking
> + * @p: The pointer to read, prior to dereferencing
> + * @c: The conditions under which the dereference will take place
> *
> - * Do an rcu_dereference(), but check that the context is correct.
> - * For example, rcu_dereference_check(gp, rcu_read_lock_held()) to
> - * ensure that the rcu_dereference_check() executes within an RCU
> - * read-side critical section. It is also possible to check for
> - * locks being held, for example, by using lockdep_is_held().
> + * Do an rcu_dereference(), but check that the conditions under which the
> + * dereference will take place are correct. Typically the conditions indicate
> + * the various locking conditions that should be held at that point. The check
> + * should return true if the conditions are satisfied.
> + *
> + * For example:
> + *
> + * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() ||
> + * lockdep_is_held(&foo->lock));
> + *
> + * could be used to indicate to lockdep that foo->bar may only be dereferenced
> + * if either the RCU read lock is held, or that the lock required to replace
> + * the bar struct at foo->bar is held.
> + *
> + * Note that the list of conditions may also include indications of when a lock
> + * need not be held, for example during initialisation or destruction of the
> + * target struct:
> + *
> + * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() ||
> + * lockdep_is_held(&foo->lock),
> + * atomic_read(&foo->usage) == 0);
> */
> #define rcu_dereference_check(p, c) \
> ({ \
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] RCU: Better explain the condition parameter of rcu_dereference_check()
2010-04-07 17:15 [PATCH] RCU: Better explain the condition parameter of rcu_dereference_check() David Howells
2010-04-07 17:28 ` Paul E. McKenney
@ 2010-04-08 2:50 ` Yong Zhang
2010-04-08 4:36 ` Paul E. McKenney
1 sibling, 1 reply; 4+ messages in thread
From: Yong Zhang @ 2010-04-08 2:50 UTC (permalink / raw)
To: David Howells; +Cc: paulmck, eric.dumazet, linux-kernel
On Wed, Apr 07, 2010 at 06:15:00PM +0100, David Howells wrote:
> Better explain the condition parameter of rcu_dereference_check() that
> describes the conditions under which the dereference is permitted to take
> place. This condition is only checked under lockdep proving.
>
> Signed-off-by: David Howells <dhowells@redhat.com>
> ---
>
> include/linux/rcupdate.h | 28 +++++++++++++++++++++++-----
> 1 files changed, 23 insertions(+), 5 deletions(-)
>
> diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
> index 872a98e..acf9958 100644
> --- a/include/linux/rcupdate.h
> +++ b/include/linux/rcupdate.h
> @@ -195,12 +195,30 @@ static inline int rcu_read_lock_sched_held(void)
>
> /**
> * rcu_dereference_check - rcu_dereference with debug checking
> + * @p: The pointer to read, prior to dereferencing
> + * @c: The conditions under which the dereference will take place
> *
> - * Do an rcu_dereference(), but check that the context is correct.
> - * For example, rcu_dereference_check(gp, rcu_read_lock_held()) to
> - * ensure that the rcu_dereference_check() executes within an RCU
> - * read-side critical section. It is also possible to check for
> - * locks being held, for example, by using lockdep_is_held().
> + * Do an rcu_dereference(), but check that the conditions under which the
> + * dereference will take place are correct. Typically the conditions indicate
> + * the various locking conditions that should be held at that point. The check
> + * should return true if the conditions are satisfied.
> + *
> + * For example:
> + *
> + * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() ||
> + * lockdep_is_held(&foo->lock));
> + *
> + * could be used to indicate to lockdep that foo->bar may only be dereferenced
> + * if either the RCU read lock is held, or that the lock required to replace
> + * the bar struct at foo->bar is held.
> + *
> + * Note that the list of conditions may also include indications of when a lock
> + * need not be held, for example during initialisation or destruction of the
> + * target struct:
> + *
> + * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() ||
> + * lockdep_is_held(&foo->lock),
^^
|| ?
Thanks,
Yong
> + * atomic_read(&foo->usage) == 0);
> */
> #define rcu_dereference_check(p, c) \
> ({ \
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] RCU: Better explain the condition parameter of rcu_dereference_check()
2010-04-08 2:50 ` Yong Zhang
@ 2010-04-08 4:36 ` Paul E. McKenney
0 siblings, 0 replies; 4+ messages in thread
From: Paul E. McKenney @ 2010-04-08 4:36 UTC (permalink / raw)
To: Yong Zhang; +Cc: David Howells, eric.dumazet, linux-kernel
On Thu, Apr 08, 2010 at 10:50:50AM +0800, Yong Zhang wrote:
> On Wed, Apr 07, 2010 at 06:15:00PM +0100, David Howells wrote:
> > Better explain the condition parameter of rcu_dereference_check() that
> > describes the conditions under which the dereference is permitted to take
> > place. This condition is only checked under lockdep proving.
> >
> > Signed-off-by: David Howells <dhowells@redhat.com>
> > ---
> >
> > include/linux/rcupdate.h | 28 +++++++++++++++++++++++-----
> > 1 files changed, 23 insertions(+), 5 deletions(-)
> >
> > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
> > index 872a98e..acf9958 100644
> > --- a/include/linux/rcupdate.h
> > +++ b/include/linux/rcupdate.h
> > @@ -195,12 +195,30 @@ static inline int rcu_read_lock_sched_held(void)
> >
> > /**
> > * rcu_dereference_check - rcu_dereference with debug checking
> > + * @p: The pointer to read, prior to dereferencing
> > + * @c: The conditions under which the dereference will take place
> > *
> > - * Do an rcu_dereference(), but check that the context is correct.
> > - * For example, rcu_dereference_check(gp, rcu_read_lock_held()) to
> > - * ensure that the rcu_dereference_check() executes within an RCU
> > - * read-side critical section. It is also possible to check for
> > - * locks being held, for example, by using lockdep_is_held().
> > + * Do an rcu_dereference(), but check that the conditions under which the
> > + * dereference will take place are correct. Typically the conditions indicate
> > + * the various locking conditions that should be held at that point. The check
> > + * should return true if the conditions are satisfied.
> > + *
> > + * For example:
> > + *
> > + * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() ||
> > + * lockdep_is_held(&foo->lock));
> > + *
> > + * could be used to indicate to lockdep that foo->bar may only be dereferenced
> > + * if either the RCU read lock is held, or that the lock required to replace
> > + * the bar struct at foo->bar is held.
> > + *
> > + * Note that the list of conditions may also include indications of when a lock
> > + * need not be held, for example during initialisation or destruction of the
> > + * target struct:
> > + *
> > + * bar = rcu_dereference_check(foo->bar, rcu_read_lock_held() ||
> > + * lockdep_is_held(&foo->lock),
> ^^
> || ?
Good catch, fixed!
Thanx, Paul
> Thanks,
> Yong
>
> > + * atomic_read(&foo->usage) == 0);
> > */
> > #define rcu_dereference_check(p, c) \
> > ({ \
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-04-08 4:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-07 17:15 [PATCH] RCU: Better explain the condition parameter of rcu_dereference_check() David Howells
2010-04-07 17:28 ` Paul E. McKenney
2010-04-08 2:50 ` Yong Zhang
2010-04-08 4:36 ` Paul E. McKenney
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).