From: Jarek Poplawski <jarkao2@o2.pl>
To: Olaf Kirch <olaf.kirch@oracle.com>
Cc: Ingo Molnar <mingo@elte.hu>,
Linus Torvalds <torvalds@linux-foundation.org>,
linux-kernel@vger.kernel.org, davem@davemloft.net
Subject: Re: [patch] revert: [NET]: Fix races in net_rx_action vs netpoll
Date: Wed, 18 Jul 2007 13:48:20 +0200 [thread overview]
Message-ID: <20070718114820.GA1734@ff.dom.local> (raw)
In-Reply-To: <200707172034.20581.olaf.kirch@oracle.com>
Hi,
Here is my proposal of a solution based on dev->state flag,
but intended mainly to prevent poll_napi from disturbing
while net_rx_action is running and polling the device.
It doesn't look very nice or clean but I hope it could
guard net_rx_action enough with some room for netpoll too.
I'd be very glad if it could be verified and/or tested.
Regards,
Jarek P.
PS: not tested!
---
diff -Nurp 2.6.22-git9-/include/linux/netdevice.h 2.6.22-git9/include/linux/netdevice.h
--- 2.6.22-git9-/include/linux/netdevice.h 2007-07-18 07:50:56.000000000 +0200
+++ 2.6.22-git9/include/linux/netdevice.h 2007-07-18 13:21:12.000000000 +0200
@@ -262,6 +262,8 @@ enum netdev_state_t
__LINK_STATE_LINKWATCH_PENDING,
__LINK_STATE_DORMANT,
__LINK_STATE_QDISC_RUNNING,
+ /* Set by net_rx_action vs poll_napi */
+ __LINK_STATE_POLL_LIST_FROZEN,
};
diff -Nurp 2.6.22-git9-/net/core/dev.c 2.6.22-git9/net/core/dev.c
--- 2.6.22-git9-/net/core/dev.c 2007-07-18 07:50:58.000000000 +0200
+++ 2.6.22-git9/net/core/dev.c 2007-07-18 13:18:23.000000000 +0200
@@ -2025,6 +2025,7 @@ static void net_rx_action(struct softirq
unsigned long start_time = jiffies;
int budget = netdev_budget;
void *have;
+ struct net_device *dev_frozen = NULL;
local_irq_disable();
@@ -2040,15 +2041,35 @@ static void net_rx_action(struct softirq
struct net_device, poll_list);
have = netpoll_poll_lock(dev);
+#ifdef CONFIG_NETPOLL
+ /* prevent a race with poll_napi() */
+ if (dev_frozen && dev_frozen != dev) {
+ clear_bit(__LINK_STATE_POLL_LIST_FROZEN,
+ &dev_frozen->state);
+ set_bit(__LINK_STATE_POLL_LIST_FROZEN,
+ &dev->state);
+ dev_frozen = dev;
+ } else if (!dev_frozen) {
+ set_bit(__LINK_STATE_POLL_LIST_FROZEN,
+ &dev->state);
+ dev_frozen = dev;
+ }
+#endif
if (dev->quota <= 0 || dev->poll(dev, &budget)) {
netpoll_poll_unlock(have);
local_irq_disable();
- list_move_tail(&dev->poll_list, &queue->poll_list);
+ list_move_tail(&dev->poll_list,
+ &queue->poll_list);
if (dev->quota < 0)
dev->quota += dev->weight;
else
dev->quota = dev->weight;
} else {
+#ifdef CONFIG_NETPOLL
+ clear_bit(__LINK_STATE_POLL_LIST_FROZEN,
+ &dev->state);
+ dev_frozen = NULL;
+#endif
netpoll_poll_unlock(have);
dev_put(dev);
local_irq_disable();
@@ -2056,6 +2077,14 @@ static void net_rx_action(struct softirq
}
out:
local_irq_enable();
+#ifdef CONFIG_NETPOLL
+ if (dev_frozen) {
+ have = netpoll_poll_lock(dev_frozen);
+ clear_bit(__LINK_STATE_POLL_LIST_FROZEN,
+ &dev_frozen->state);
+ netpoll_poll_unlock(have);
+ }
+#endif
#ifdef CONFIG_NET_DMA
/*
* There may not be any more sk_buffs coming right now, so push
diff -Nurp 2.6.22-git9-/net/core/netpoll.c 2.6.22-git9/net/core/netpoll.c
--- 2.6.22-git9-/net/core/netpoll.c 2007-07-18 07:50:58.000000000 +0200
+++ 2.6.22-git9/net/core/netpoll.c 2007-07-18 12:09:43.000000000 +0200
@@ -124,13 +124,20 @@ static void poll_napi(struct netpoll *np
if (test_bit(__LINK_STATE_RX_SCHED, &np->dev->state) &&
npinfo->poll_owner != smp_processor_id() &&
spin_trylock(&npinfo->poll_lock)) {
- npinfo->rx_flags |= NETPOLL_RX_DROP;
- atomic_inc(&trapped);
+ /*
+ * If POLL_LIST_FROZEN is set net_rx_action
+ * is working with this device.
+ */
+ if (!test_bit(__LINK_STATE_POLL_LIST_FROZEN,
+ &np->dev->state)) {
+ npinfo->rx_flags |= NETPOLL_RX_DROP;
+ atomic_inc(&trapped);
- np->dev->poll(np->dev, &budget);
+ np->dev->poll(np->dev, &budget);
- atomic_dec(&trapped);
- npinfo->rx_flags &= ~NETPOLL_RX_DROP;
+ atomic_dec(&trapped);
+ npinfo->rx_flags &= ~NETPOLL_RX_DROP;
+ }
spin_unlock(&npinfo->poll_lock);
}
}
next prev parent reply other threads:[~2007-07-18 11:39 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-16 9:12 [patch] revert: [NET]: Fix races in net_rx_action vs netpoll Ingo Molnar
2007-07-16 10:35 ` Olaf Kirch
2007-07-16 11:26 ` David Miller
2007-07-16 12:18 ` Olaf Kirch
2007-07-16 13:29 ` Ingo Molnar
2007-07-16 21:09 ` Ingo Molnar
2007-07-16 22:06 ` David Miller
2007-07-16 21:40 ` Linus Torvalds
2007-07-16 21:51 ` Ingo Molnar
2007-07-16 22:09 ` David Miller
2007-07-16 22:37 ` Ingo Molnar
2007-07-16 22:57 ` David Miller
2007-07-17 18:09 ` Ingo Molnar
2007-07-16 22:08 ` David Miller
2007-07-16 22:29 ` Linus Torvalds
2007-07-16 22:52 ` David Miller
2007-07-16 23:17 ` Matt Mackall
2007-07-16 23:34 ` Linus Torvalds
2007-07-17 7:37 ` Olaf Kirch
2007-07-17 8:16 ` Olaf Kirch
2007-07-17 5:46 ` Jarek Poplawski
2007-07-17 6:14 ` Jarek Poplawski
2007-07-17 7:55 ` Olaf Kirch
2007-07-17 8:28 ` Olaf Kirch
2007-07-17 8:57 ` Ingo Molnar
2007-07-17 9:29 ` Jarek Poplawski
2007-07-17 14:07 ` Olaf Kirch
2007-07-17 16:57 ` Ingo Molnar
2007-07-17 18:06 ` Olaf Kirch
2007-07-17 18:18 ` Ingo Molnar
2007-07-17 18:34 ` Olaf Kirch
2007-07-17 18:56 ` Ingo Molnar
2007-07-18 12:04 ` Olaf Kirch
2007-07-18 12:41 ` Ingo Molnar
2007-07-18 12:48 ` Ingo Molnar
2007-07-18 14:41 ` Olaf Kirch
2007-07-18 16:43 ` Ingo Molnar
2007-07-19 9:09 ` Ingo Molnar
2007-07-19 9:44 ` Olaf Kirch
2007-07-19 10:01 ` Ingo Molnar
2007-07-19 10:37 ` Olaf Kirch
2007-07-19 10:47 ` Ingo Molnar
2007-07-19 10:58 ` Ingo Molnar
2007-07-19 12:52 ` Olaf Kirch
2007-07-19 12:54 ` Olaf Kirch
2007-07-19 15:42 ` Kok, Auke
2007-07-19 16:07 ` Ingo Molnar
2007-07-19 19:13 ` Olaf Kirch
2007-07-19 19:22 ` Ingo Molnar
2007-07-19 19:35 ` Olaf Kirch
2007-07-19 19:56 ` Ingo Molnar
2007-07-19 20:02 ` Olaf Kirch
2007-07-20 9:45 ` Ingo Molnar
2007-07-19 15:07 ` Ingo Molnar
2007-07-19 15:27 ` Olaf Kirch
2007-07-19 15:32 ` Ingo Molnar
2007-07-19 15:52 ` Ingo Molnar
2007-07-19 16:05 ` Ingo Molnar
2007-07-19 16:13 ` Ingo Molnar
2007-07-19 17:36 ` Olaf Kirch
2007-07-19 17:41 ` Ingo Molnar
2007-07-19 17:51 ` Olaf Kirch
2007-07-19 10:17 ` Ingo Molnar
2007-07-18 11:48 ` Jarek Poplawski [this message]
2007-07-19 5:58 ` Jarek Poplawski
2007-07-17 17:49 ` Linus Torvalds
2007-07-17 9:12 ` Jarek Poplawski
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=20070718114820.GA1734@ff.dom.local \
--to=jarkao2@o2.pl \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=olaf.kirch@oracle.com \
--cc=torvalds@linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.