From: Stephen Hemminger <shemminger@linux-foundation.org>
To: David Miller <davem@davemloft.net>, Satyam Sharma <satyam@infradead.org>
Cc: netdev@vger.kernel.org
Subject: [PATCH 11/11] netpoll: rx use RCU
Date: Sat, 03 Nov 2007 11:43:25 -0700 [thread overview]
Message-ID: <20071103184339.039313598@linux-foundation.org> (raw)
In-Reply-To: 20071103184314.216145305@linux-foundation.org
[-- Attachment #1: netpoll-rcu.patch --]
[-- Type: text/plain, Size: 3049 bytes --]
Get rid of rx_lock and use Read-Copy-Update to make sure
that netpoll info and rx handle are not used after free.
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
--- a/include/linux/netpoll.h 2007-11-03 11:08:36.000000000 -0700
+++ b/include/linux/netpoll.h 2007-11-03 11:15:11.000000000 -0700
@@ -23,7 +23,6 @@ struct netpoll {
struct netpoll_info {
atomic_t refcnt;
- spinlock_t rx_lock;
struct netpoll *rx_np; /* netpoll that registered an rx_hook */
struct sk_buff_head arp_tx; /* list of arp requests to reply to */
struct sk_buff_head txq;
--- a/net/core/netpoll.c 2007-11-03 11:08:36.000000000 -0700
+++ b/net/core/netpoll.c 2007-11-03 11:15:29.000000000 -0700
@@ -463,15 +463,15 @@ bool __netpoll_rx(struct sk_buff *skb)
int proto, len, ulen;
struct iphdr *iph;
struct udphdr *uh;
- struct netpoll_info *npi = skb->dev->npinfo;
+ struct netpoll_info *npi;
struct netpoll *np;
- unsigned long flags;
+ rcu_read_lock();
+ npi = rcu_dereference(skb->dev->npinfo);
if (!npi)
- return false;
+ goto out;
- spin_lock_irqsave(&npi->rx_lock, flags);
- np = npi->rx_np;
+ np = rcu_dereference(npi->rx_np);
if (!np)
goto out;
@@ -535,13 +535,13 @@ bool __netpoll_rx(struct sk_buff *skb)
np->rx_hook(np, ntohs(uh->source),
(char *)(uh+1),
ulen - sizeof(struct udphdr));
- spin_unlock_irqrestore(&npi->rx_lock, flags);
+ rcu_read_unlock();
kfree_skb(skb);
return true;
out:
- spin_unlock_irqrestore(&npi->rx_lock, flags);
+ rcu_read_unlock();
/* If packet received while already in poll then just
* silently drop.
*/
@@ -678,7 +678,6 @@ int netpoll_setup(struct netpoll *np, st
npinfo->rx_np = NULL;
- spin_lock_init(&npinfo->rx_lock);
skb_queue_head_init(&npinfo->arp_tx);
skb_queue_head_init(&npinfo->txq);
INIT_DELAYED_WORK(&npinfo->tx_work, queue_process);
@@ -755,11 +754,8 @@ int netpoll_setup(struct netpoll *np, st
HIPQUAD(np->local_ip));
}
- if (np->rx_hook) {
- spin_lock_irqsave(&npinfo->rx_lock, flags);
- npinfo->rx_np = np;
- spin_unlock_irqrestore(&npinfo->rx_lock, flags);
- }
+ if (np->rx_hook)
+ rcu_assign_pointer(npinfo->rx_np, np);
/* fill up the skb queue */
refill_skbs();
@@ -794,21 +790,21 @@ void netpoll_cleanup(struct netpoll *np)
if (np->dev) {
npinfo = np->dev->npinfo;
if (npinfo) {
- if (npinfo->rx_np == np) {
- spin_lock_irqsave(&npinfo->rx_lock, flags);
- npinfo->rx_np = NULL;
- spin_unlock_irqrestore(&npinfo->rx_lock, flags);
- }
+ if (npinfo->rx_np == np)
+ rcu_assign_pointer(npinfo->rx_np, NULL);
if (atomic_dec_and_test(&npinfo->refcnt)) {
+
skb_queue_purge(&npinfo->arp_tx);
skb_queue_purge(&npinfo->txq);
cancel_rearming_delayed_work(&npinfo->tx_work);
/* clean after last, unfinished work */
__skb_queue_purge(&npinfo->txq);
+
+ rcu_assign_pointer(np->dev->npinfo, NULL);
+ synchronize_net();
kfree(npinfo);
- np->dev->npinfo = NULL;
}
}
--
Stephen Hemminger <shemminger@linux-foundation.org>
next prev parent reply other threads:[~2007-11-03 23:39 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-03 18:43 [PATCH 00/11] netpoll cleanups Stephen Hemminger
2007-11-03 18:43 ` [PATCH 01/11] netpoll: use skb_queue_purge Stephen Hemminger
2007-11-20 3:15 ` David Miller
2007-11-03 18:43 ` [PATCH 02/11] netpoll: netpoll_poll cleanup Stephen Hemminger
2007-11-20 3:21 ` David Miller
2007-11-03 18:43 ` [PATCH 03/11] netpoll: no need to store local_mac Stephen Hemminger
2007-11-20 3:23 ` David Miller
2007-11-03 18:43 ` [PATCH 04/11] netpoll: alternative implementation of dropping Stephen Hemminger
2007-11-20 3:25 ` David Miller
2007-11-03 18:43 ` [PATCH 05/11] netpoll: dont need rx_flags Stephen Hemminger
2007-11-20 3:39 ` David Miller
2007-11-03 18:43 ` [PATCH 06/11] netpoll: remove dev_name for npinfo Stephen Hemminger
2007-11-20 3:47 ` David Miller
2007-11-20 4:07 ` Stephen Hemminger
2007-11-03 18:43 ` [PATCH 07/11] netpoll: get rid of name parameter Stephen Hemminger
2007-11-20 3:49 ` David Miller
2007-11-03 18:43 ` [PATCH 08/11] netpoll: NETPOLL_TRAP configuration change Stephen Hemminger
2007-11-20 3:52 ` David Miller
2007-11-03 18:43 ` [PATCH 09/11] netpoll: ethernet devices only Stephen Hemminger
2007-11-20 3:55 ` David Miller
2007-11-20 4:14 ` Stephen Hemminger
2007-11-03 18:43 ` [PATCH 10/11] netpoll: rx optimization Stephen Hemminger
2007-11-20 4:00 ` David Miller
2007-11-03 18:43 ` Stephen Hemminger [this message]
2007-11-20 4:00 ` [PATCH 11/11] netpoll: rx use RCU David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071103184339.039313598@linux-foundation.org \
--to=shemminger@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=satyam@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).