Skip to contentSkip to conversation

netfilter: ebt_ulog: remove useless spin lock protection

PATCH New Gao feng 1 participant 2 messages Feb 19, 2013

Subsystems (3)
lore
Share & tools
lore

Gao feng

author
#0 lore raw

PATCH 1/2 netfilter: ebt_ulog: remove useless spin lock protection

when removing the module ebt_ulog,expect ebt_ulog_fini, there are no other codes to operate ebt_ulog_buffer's skb. So it is no need to add spin lock protection in ebt_ulog_fini.

---
 net/bridge/netfilter/ebt_ulog.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/bridge/netfilter/ebt_ulog.c +1 -2
index 3bf43f7..442b032 100644
@@ -319,12 +319,11 @@ static void __exit ebt_ulog_fini(void)
 	for (i = 0; i < EBT_ULOG_MAXNLGROUPS; i++) {
 		ub = &ulog_buffers[i];
 		del_timer(&ub->timer);
-		spin_lock_bh(&ub->lock);
+
 		if (ub->skb) {
 			kfree_skb(ub->skb);
 			ub->skb = NULL;
 		}
-		spin_unlock_bh(&ub->lock);
 	}
 	netlink_kernel_release(ebtulognl);
 }
Signature · 1 line
1.7.11.7
author
#1 lore raw

PATCH 2/2 netfilter: ipt_ULOG: make spinlock per nlgroup

This patch makes the spin lock per group instead of global spin lock,just like ebt_ulog.

---
 net/ipv4/netfilter/ipt_ULOG.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
net/ipv4/netfilter/ipt_ULOG.c +9 -7
index 7d168dc..3f9f810 100644
@@ -76,12 +76,12 @@ typedef struct {
 	struct nlmsghdr *lastnlh;	/* netlink header of last msg in skb */
 	struct sk_buff *skb;		/* the pre-allocated skb */
 	struct timer_list timer;	/* the timer function */
+	spinlock_t lock;		/* the per-queue lock */
 } ulog_buff_t;
 
 static ulog_buff_t ulog_buffers[ULOG_MAXNLGROUPS];	/* array of buffers */
 
 static struct sock *nflognl;		/* our socket */
-static DEFINE_SPINLOCK(ulog_lock);	/* spinlock */
 
 /* send one ulog_buff_t to userspace */
 static void ulog_send(unsigned int nlgroupnum)
@@ -118,9 +118,9 @@ static void ulog_timer(unsigned long data)
 
 	/* lock to protect against somebody modifying our structure
 	 * from ipt_ulog_target at the same time */
-	spin_lock_bh(&ulog_lock);
+	spin_lock_bh(&ulog_buffers[data].lock);
 	ulog_send(data);
-	spin_unlock_bh(&ulog_lock);
+	spin_unlock_bh(&ulog_buffers[data].lock);
 }
 
 static struct sk_buff *ulog_alloc_skb(unsigned int size)
@@ -176,7 +176,7 @@ static void ipt_ulog_packet(unsigned int hooknum,
 
 	ub = &ulog_buffers[groupnum];
 
-	spin_lock_bh(&ulog_lock);
+	spin_lock_bh(&ub->lock);
 
 	if (!ub->skb) {
 		if (!(ub->skb = ulog_alloc_skb(size)))
@@ -263,13 +263,13 @@ static void ipt_ulog_packet(unsigned int hooknum,
 		ulog_send(groupnum);
 	}
 out_unlock:
-	spin_unlock_bh(&ulog_lock);
+	spin_unlock_bh(&ub->lock);
 
 	return;
 
 alloc_failure:
 	pr_debug("Error building netlink message\n");
-	spin_unlock_bh(&ulog_lock);
+	spin_unlock_bh(&ub->lock);
 }
 
 static unsigned int
@@ -391,8 +391,10 @@ static int __init ulog_tg_init(void)
 	}
 
 	/* initialize ulog_buffers */
-	for (i = 0; i < ULOG_MAXNLGROUPS; i++)
+	for (i = 0; i < ULOG_MAXNLGROUPS; i++) {
 		setup_timer(&ulog_buffers[i].timer, ulog_timer, i);
+		spin_lock_init(&ulog_buffers[i].lock);
+	}
 
 	nflognl = netlink_kernel_create(&init_net, NETLINK_NFLOG, &cfg);
 	if (!nflognl)
Signature · 1 line
1.7.11.7