From patchwork Wed May 4 08:06:30 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 1021 Return-Path: Received: from v3-1039.vlinux.de (narfation.org [79.140.41.39]) by open-mesh.org (Postfix) with ESMTPS id 5ABAF1543FE for ; Wed, 4 May 2011 10:07:01 +0200 (CEST) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key) header.i=@narfation.org; dkim-adsp=pass Received: from sven-desktop.home.narfation.org (bathseba.informatik.tu-chemnitz.de [134.109.192.185]) by v3-1039.vlinux.de (Postfix) with ESMTPSA id 20775940E6 for ; Wed, 4 May 2011 10:07:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=narfation.org; s=mail; t=1304496429; bh=FvjIxvDSwyrhH2yP5rzLyzS7E/sZestZ8aerQVdZ5h0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References; b=N7gY1Gd+ks90vf3muf+oVGYs5g4z+bcXToZiz2iVy/X+TGhE/HRNqZMTsEqpQvI3p hH5opUQ7cHhW+COtirND1A/Ws2mIL/WauFmojvHI0ID7KyTZnTzpFsHLNucZWSD+Hh Vh4j6gj1Lucp1amGb5ADmAwinmO9+7Q1HxN4umrM= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Wed, 4 May 2011 10:06:30 +0200 Message-Id: <1304496393-16405-3-git-send-email-sven@narfation.org> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1304496393-16405-1-git-send-email-sven@narfation.org> References: <1304496393-16405-1-git-send-email-sven@narfation.org> Subject: [B.A.T.M.A.N.] [PATCH 2/5] batman-adv: Add compatibility code for kfree_rcu X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 May 2011 08:07:01 -0000 Signed-off-by: Sven Eckelmann --- compat.c | 37 +++++++++++++++++++++++++++++++++++++ compat.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 0 deletions(-) diff --git a/compat.c b/compat.c index f4561c3..881420f 100644 --- a/compat.c +++ b/compat.c @@ -1,4 +1,7 @@ #include +#include +#include +#include "compat.h" #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29) @@ -959,3 +962,37 @@ int bat_seq_printf(struct seq_file *m, const char *f, ...) } #endif /* < KERNEL_VERSION(2, 6, 29) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 1234) + +#define BAT_KFREE_RCU0(n, x) \ + static void bat_kfree_rcu_##n(struct rcu_head *head) \ + {\ + unsigned long offset = (unsigned long)(x);\ + kfree((void *)head - offset);\ + } + +#define BAT_KFREE_RCU1(n,x) BAT_KFREE_RCU0(n##z,x) BAT_KFREE_RCU0(n##o,x+1UL) +#define BAT_KFREE_RCU2(n,x) BAT_KFREE_RCU1(n##z,x) BAT_KFREE_RCU1(n##o,x+2UL) +#define BAT_KFREE_RCU3(n,x) BAT_KFREE_RCU2(n##z,x) BAT_KFREE_RCU2(n##o,x+4UL) +#define BAT_KFREE_RCU4(n,x) BAT_KFREE_RCU3(n##z,x) BAT_KFREE_RCU3(n##o,x+8UL) +#define BAT_KFREE_RCU5(n,x) BAT_KFREE_RCU4(n##z,x) BAT_KFREE_RCU4(n##o,x+16UL) +#define BAT_KFREE_RCU6(n,x) BAT_KFREE_RCU5(n##z,x) BAT_KFREE_RCU5(n##o,x+32UL) +#define BAT_KFREE_RCU7(n,x) BAT_KFREE_RCU6(n##z,x) BAT_KFREE_RCU6(n##o,x+64UL) +#define BAT_KFREE_RCU8(n,x) BAT_KFREE_RCU7(n##z,x) BAT_KFREE_RCU7(n##o,x+128UL) + +BAT_KFREE_RCU8(s, 0UL) + +#define LKRCU0(n) &bat_kfree_rcu_##n +#define LKRCU1(n) LKRCU0(n##z), LKRCU0(n##o) +#define LKRCU2(n) LKRCU1(n##z), LKRCU1(n##o) +#define LKRCU3(n) LKRCU2(n##z), LKRCU2(n##o) +#define LKRCU4(n) LKRCU3(n##z), LKRCU3(n##o) +#define LKRCU5(n) LKRCU4(n##z), LKRCU4(n##o) +#define LKRCU6(n) LKRCU5(n##z), LKRCU5(n##o) +#define LKRCU7(n) LKRCU6(n##z), LKRCU6(n##o) +#define LKRCU8(n) LKRCU7(n##z), LKRCU7(n##o) + +bat_rcu_callback bat_kfree_rcu_offset[_BAT_MAX_KFREE_RCU_OFFSET] = {LKRCU8(s)}; + +#endif /* < KERNEL_VERSION(2, 6, 1234) */ diff --git a/compat.h b/compat.h index 0c5ad82..59bd752 100644 --- a/compat.h +++ b/compat.h @@ -288,4 +288,32 @@ int bat_seq_printf(struct seq_file *m, const char *f, ...); #endif /* < KERNEL_VERSION(2, 6, 36) */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 1234) + +#define _BAT_MAX_KFREE_RCU_OFFSET 256 +typedef void (*bat_rcu_callback)(struct rcu_head *); +extern bat_rcu_callback bat_kfree_rcu_offset[_BAT_MAX_KFREE_RCU_OFFSET]; + +static __always_inline bool __is_kfree_rcu_offset(unsigned long offset) +{ + return offset < _BAT_MAX_KFREE_RCU_OFFSET; +} + +static __always_inline +void __kfree_rcu(struct rcu_head *head, unsigned long offset) +{ + BUILD_BUG_ON(!__builtin_constant_p(offset)); + BUILD_BUG_ON(!__is_kfree_rcu_offset(offset)); + + call_rcu(head, (bat_rcu_callback)bat_kfree_rcu_offset[offset]); +} + +extern void kfree(const void *); + +#define kfree_rcu(ptr, rcu_head) \ + __kfree_rcu(&((ptr)->rcu_head), offsetof(typeof(*(ptr)), rcu_head)) + + +#endif /* < KERNEL_VERSION(2, 6, 1234) */ + #endif /* _NET_BATMAN_ADV_COMPAT_H_ */