From 3d1c4cbe9964b749260dba64bf687d320dce64d3 Mon Sep 17 00:00:00 2001 From: Jesse Gross Date: Mon, 6 Dec 2010 15:39:19 -0800 Subject: [PATCH] datapath: Compatibility code for RCU check functions. The rcu_dereference_rtnl() and rtnl_dereference() functions will be introduced in 2.6.37. They provide nice documentation of locking expectations as well as checking on recent kernels. Signed-off-by: Jesse Gross Acked-by: Ben Pfaff --- .../compat-2.6/include/linux/rtnetlink.h | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/datapath/linux-2.6/compat-2.6/include/linux/rtnetlink.h b/datapath/linux-2.6/compat-2.6/include/linux/rtnetlink.h index 66025361..b6bf7cb9 100644 --- a/datapath/linux-2.6/compat-2.6/include/linux/rtnetlink.h +++ b/datapath/linux-2.6/compat-2.6/include/linux/rtnetlink.h @@ -46,4 +46,52 @@ static inline int rtnl_is_locked(void) #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) +#ifdef CONFIG_PROVE_LOCKING +static inline int lockdep_rtnl_is_held(void) +{ + return 1; +} +#endif + +static inline int rcu_read_lock_held(void) +{ + return 1; +} +#endif + +#ifndef rcu_dereference_check +#define rcu_dereference_check(p, c) rcu_dereference(p) +#endif + +#ifndef rcu_dereference_protected +#define rcu_dereference_protected(p, c) (p) +#endif + +#ifndef rcu_dereference_rtnl +/** + * rcu_dereference_rtnl - rcu_dereference with debug checking + * @p: The pointer to read, prior to dereferencing + * + * Do an rcu_dereference(p), but check caller either holds rcu_read_lock() + * or RTNL. Note : Please prefer rtnl_dereference() or rcu_dereference() + */ +#define rcu_dereference_rtnl(p) \ + rcu_dereference_check(p, rcu_read_lock_held() || \ + lockdep_rtnl_is_held()) +#endif + +#ifndef rtnl_dereference +/** + * rtnl_dereference - fetch RCU pointer when updates are prevented by RTNL + * @p: The pointer to read, prior to dereferencing + * + * Return the value of the specified RCU-protected pointer, but omit + * both the smp_read_barrier_depends() and the ACCESS_ONCE(), because + * caller holds RTNL. + */ +#define rtnl_dereference(p) \ + rcu_dereference_protected(p, lockdep_rtnl_is_held()) +#endif + #endif /* linux/rtnetlink.h wrapper */ -- 2.30.2