linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: "David S. Miller" <davem@davemloft.net>,
	Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Christoph Hellwig <hch@infradead.org>, Andi Kleen <ak@suse.de>,
	Andrew Morton <akpm@linux-foundation.org>,
	virtualization@lists.osdl.org,
	lkml <linux-kernel@vger.kernel.org>,
	Chris Wright <chrisw@sous-sol.org>,
	Ian Pratt <ian.pratt@xensource.com>,
	Christian Limpach <Christian.Limpach@cl.cam.ac.uk>,
	netdev@vger.kernel.org, Jeff Garzik <jeff@garzik.org>,
	Stephen Hemminger <shemminge@linux-foundation.org>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Keir Fraser <Keir.Fraser@cl.cam.ac.uk>
Subject: [1/2] [NET] link_watch: Move link watch list into net_device
Date: Tue, 8 May 2007 22:13:22 +1000	[thread overview]
Message-ID: <20070508121322.GA21647@gondor.apana.org.au> (raw)
In-Reply-To: <463F95C3.60407@goop.org>

On Mon, May 07, 2007 at 02:10:27PM -0700, Jeremy Fitzhardinge wrote:
>
> > We should just change this to use netif_device_attach and
> > netif_device_detach.
> 
> Like this?

Sorry, I had forgotten that I've already concluded previously that
this doesn't work because we don't want to prevent the interface
from being brought up (and other reasons).  My memory is failing me :)

So I think the best option now is to get rid of the delay on carrier
on events for everyone.

Here is the first of 2 patches.

[NET] link_watch: Move link watch list into net_device

These days the link watch mechanism is an integral part of the
network subsystem as it manages the carrier status.  So it now
makes sense to allocate some memory for it in net_device rather
than allocating it on demand.

In fact, this is necessary because we can't tolerate a memory
allocation failure since that means we'd have to potentially
throw a link up event away.

It also simplifies the code greatly.

In doing so I discovered a subtle race condition in the use
of singleevent.  This race condition still exists (and is
somewhat magnified) without singleevent but it's now plugged
thanks to an smp_mb__before_clear_bit.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
a6c194d06da9aed2a8f5a4ea07e3cbf9266db4ef
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 3044622..f671cd2 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -467,6 +467,8 @@ struct net_device
 	/* device index hash chain */
 	struct hlist_node	index_hlist;
 
+	struct net_device	*link_watch_next;
+
 	/* register/unregister state machine */
 	enum { NETREG_UNINITIALIZED=0,
 	       NETREG_REGISTERED,	/* completed register_netdevice */
diff --git a/net/core/link_watch.c b/net/core/link_watch.c
index e3c26a9..71a35da 100644
--- a/net/core/link_watch.c
+++ b/net/core/link_watch.c
@@ -19,7 +19,6 @@
 #include <linux/rtnetlink.h>
 #include <linux/jiffies.h>
 #include <linux/spinlock.h>
-#include <linux/list.h>
 #include <linux/slab.h>
 #include <linux/workqueue.h>
 #include <linux/bitops.h>
@@ -28,7 +27,6 @@
 
 enum lw_bits {
 	LW_RUNNING = 0,
-	LW_SE_USED
 };
 
 static unsigned long linkwatch_flags;
@@ -37,17 +35,9 @@ static unsigned long linkwatch_nextevent;
 static void linkwatch_event(struct work_struct *dummy);
 static DECLARE_DELAYED_WORK(linkwatch_work, linkwatch_event);
 
-static LIST_HEAD(lweventlist);
+static struct net_device *lweventlist;
 static DEFINE_SPINLOCK(lweventlist_lock);
 
-struct lw_event {
-	struct list_head list;
-	struct net_device *dev;
-};
-
-/* Avoid kmalloc() for most systems */
-static struct lw_event singleevent;
-
 static unsigned char default_operstate(const struct net_device *dev)
 {
 	if (!netif_carrier_ok(dev))
@@ -90,21 +80,23 @@ static void rfc2863_policy(struct net_device *dev)
 /* Must be called with the rtnl semaphore held */
 void linkwatch_run_queue(void)
 {
-	struct list_head head, *n, *next;
+	struct net_device *next;
 
 	spin_lock_irq(&lweventlist_lock);
-	list_replace_init(&lweventlist, &head);
+	next = lweventlist;
+	lweventlist = NULL;
 	spin_unlock_irq(&lweventlist_lock);
 
-	list_for_each_safe(n, next, &head) {
-		struct lw_event *event = list_entry(n, struct lw_event, list);
-		struct net_device *dev = event->dev;
+	while (next) {
+		struct net_device *dev = next;
 
-		if (event == &singleevent) {
-			clear_bit(LW_SE_USED, &linkwatch_flags);
-		} else {
-			kfree(event);
-		}
+		next = dev->link_watch_next;
+
+		/*
+		 * Make sure the above read is complete since it can be
+		 * rewritten as soon as we clear the bit below.
+		 */
+		smp_mb__before_clear_bit();
 
 		/* We are about to handle this device,
 		 * so new events can be accepted
@@ -147,24 +139,12 @@ void linkwatch_fire_event(struct net_device *dev)
 {
 	if (!test_and_set_bit(__LINK_STATE_LINKWATCH_PENDING, &dev->state)) {
 		unsigned long flags;
-		struct lw_event *event;
-
-		if (test_and_set_bit(LW_SE_USED, &linkwatch_flags)) {
-			event = kmalloc(sizeof(struct lw_event), GFP_ATOMIC);
-
-			if (unlikely(event == NULL)) {
-				clear_bit(__LINK_STATE_LINKWATCH_PENDING, &dev->state);
-				return;
-			}
-		} else {
-			event = &singleevent;
-		}
 
 		dev_hold(dev);
-		event->dev = dev;
 
 		spin_lock_irqsave(&lweventlist_lock, flags);
-		list_add_tail(&event->list, &lweventlist);
+		dev->link_watch_next = lweventlist;
+		lweventlist = dev;
 		spin_unlock_irqrestore(&lweventlist_lock, flags);
 
 		if (!test_and_set_bit(LW_RUNNING, &linkwatch_flags)) {

  reply	other threads:[~2007-05-08 12:15 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-04 23:20 [patch 00/29] xen: Xen implementation for paravirt_ops Jeremy Fitzhardinge
2007-05-04 23:20 ` [patch 01/29] xen: Add apply_to_page_range() which applies a function to a pte range Jeremy Fitzhardinge
2007-05-04 23:20 ` [patch 02/29] xen: Allocate and free vmalloc areas Jeremy Fitzhardinge
2007-05-04 23:20 ` [patch 03/29] xen: Add nosegneg capability to the vsyscall page notes Jeremy Fitzhardinge
2007-05-04 23:20 ` [patch 04/29] xen: Add Xen interface header files Jeremy Fitzhardinge
2007-05-04 23:20 ` [patch 05/29] xen: Core Xen implementation Jeremy Fitzhardinge
2007-05-04 23:20 ` [patch 06/29] xen: Xen virtual mmu Jeremy Fitzhardinge
2007-05-04 23:20 ` [patch 07/29] xen: xen event channels Jeremy Fitzhardinge
2007-05-04 23:20 ` [patch 08/29] xen: xen time implementation Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 09/29] xen: xen configuration Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 10/29] xen: Complete pagetable pinning for Xen Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 11/29] xen: ignore RW mapping of RO pages in pagetable_init Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 12/29] xen: fix multicall batching Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 13/29] xen: Account for time stolen by Xen Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 14/29] xen: Implement xen_sched_clock Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 15/29] xen: Xen SMP guest support Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 16/29] xen: Add support for preemption Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 17/29] xen: lazy-mmu operations Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 18/29] xen: deal with negative stolen time Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 19/29] xen: Use the hvc console infrastructure for Xen console Jeremy Fitzhardinge
2007-05-06 16:31   ` Olof Johansson
2007-05-04 23:21 ` [patch 20/29] xen: Add early printk support via hvc console Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 21/29] xen: Add Xen grant table support Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 22/29] xen: Add the Xenbus sysfs and virtual device hotplug driver Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 23/29] xen: Add Xen virtual block device driver Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 24/29] xen: rename xen netif_ structures to xen_netif_ Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 25/29] xen: Add the Xen virtual network device driver Jeremy Fitzhardinge
2007-05-05  9:16   ` Christoph Hellwig
2007-05-05 10:05     ` Jeremy Fitzhardinge
2007-05-05 10:23       ` Herbert Xu
2007-05-07 21:10         ` Jeremy Fitzhardinge
2007-05-08 12:13           ` Herbert Xu [this message]
2007-05-08 12:16             ` [2/2] [NET] link_watch: Remove delay for up even when we're down Herbert Xu
2007-05-09  1:36               ` David Miller
2007-05-08 20:19             ` [1/2] [NET] link_watch: Move link watch list into net_device Jeremy Fitzhardinge
2007-05-09  1:49               ` Herbert Xu
2007-05-09  1:35             ` David Miller
2007-05-10 22:00             ` Jeremy Fitzhardinge
2007-05-10 22:07               ` David Miller
2007-05-10 22:12                 ` Jeremy Fitzhardinge
2007-05-10 22:14               ` Andrew Morton
2007-05-10 22:22                 ` Jeremy Fitzhardinge
2007-05-10 22:25                   ` David Miller
2007-05-10 22:45                     ` Jeremy Fitzhardinge
2007-05-10 22:53                       ` Chris Wright
2007-05-10 22:53                       ` David Miller
2007-05-05 10:16     ` [patch 25/29] xen: Add the Xen virtual network device driver Rusty Russell
2007-05-07 21:11     ` Jeremy Fitzhardinge
2007-05-07 22:35       ` Rusty Russell
2007-05-08  6:30         ` Jeremy Fitzhardinge
2007-05-08  6:42           ` Rusty Russell
2007-05-04 23:21 ` [patch 26/29] xen: fix netfront checksums Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 27/29] xen: Xen machine operations Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 28/29] xen: Place vcpu_info structure into per-cpu memory, if possible Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 29/29] xen: Attempt to patch inline versions of common operations Jeremy Fitzhardinge

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=20070508121322.GA21647@gondor.apana.org.au \
    --to=herbert@gondor.apana.org.au \
    --cc=Christian.Limpach@cl.cam.ac.uk \
    --cc=Keir.Fraser@cl.cam.ac.uk \
    --cc=ak@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=chrisw@sous-sol.org \
    --cc=davem@davemloft.net \
    --cc=hch@infradead.org \
    --cc=ian.pratt@xensource.com \
    --cc=jeff@garzik.org \
    --cc=jeremy@goop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=shemminge@linux-foundation.org \
    --cc=virtualization@lists.osdl.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).