public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: stable-review@kernel.org, torvalds@linux-foundation.org,
	akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
	David Dillow <dave@thedillows.org>,
	"David S. Miller" <davem@davemloft.net>
Subject: [patch 35/37] r8169: avoid losing MSI interrupts
Date: Tue, 28 Jul 2009 15:59:03 -0700	[thread overview]
Message-ID: <20090728225946.186554282@mini.kroah.org> (raw)
In-Reply-To: <20090728230145.GA10486@kroah.com>

[-- Attachment #1: r8169-avoid-losing-msi-interrupts.patch --]
[-- Type: text/plain, Size: 4906 bytes --]


2.6.27-stable review patch.  If anyone has any objections, please let us know.

------------------

From: David Dillow <dave@thedillows.org>

[ Upstream commit f11a377b3f4e897d11f0e8d1fc688667e2f19708 ]

The 8169 chip only generates MSI interrupts when all enabled event
sources are quiescent and one or more sources transition to active. If
not all of the active events are acknowledged, or a new event becomes
active while the existing ones are cleared in the handler, we will not
see a new interrupt.

The current interrupt handler masks off the Rx and Tx events once the
NAPI handler has been scheduled, which opens a race window in which we
can get another Rx or Tx event and never ACK'ing it, stopping all
activity until the link is reset (ifconfig down/up). Fix this by always
ACK'ing all event sources, and loop in the handler until we have all
sources quiescent.

Signed-off-by: David Dillow <dave@thedillows.org>
Tested-by: Michael Buesch <mb@bu3sch.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/net/r8169.c |  102 +++++++++++++++++++++++++++++-----------------------
 1 file changed, 57 insertions(+), 45 deletions(-)

--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -2850,54 +2850,64 @@ static irqreturn_t rtl8169_interrupt(int
 	int handled = 0;
 	int status;
 
+	/* loop handling interrupts until we have no new ones or
+	 * we hit a invalid/hotplug case.
+	 */
 	status = RTL_R16(IntrStatus);
+	while (status && status != 0xffff) {
+		handled = 1;
 
-	/* hotplug/major error/no more work/shared irq */
-	if ((status == 0xffff) || !status)
-		goto out;
-
-	handled = 1;
+		/* Handle all of the error cases first. These will reset
+		 * the chip, so just exit the loop.
+		 */
+		if (unlikely(!netif_running(dev))) {
+			rtl8169_asic_down(ioaddr);
+			break;
+		}
 
-	if (unlikely(!netif_running(dev))) {
-		rtl8169_asic_down(ioaddr);
-		goto out;
-	}
+		/* Work around for rx fifo overflow */
+		if (unlikely(status & RxFIFOOver) &&
+		(tp->mac_version == RTL_GIGA_MAC_VER_11)) {
+			netif_stop_queue(dev);
+			rtl8169_tx_timeout(dev);
+			break;
+		}
 
-	status &= tp->intr_mask;
-	RTL_W16(IntrStatus,
-		(status & RxFIFOOver) ? (status | RxOverflow) : status);
+		if (unlikely(status & SYSErr)) {
+			rtl8169_pcierr_interrupt(dev);
+			break;
+		}
 
-	if (!(status & tp->intr_event))
-		goto out;
+		if (status & LinkChg)
+			rtl8169_check_link_status(dev, tp, ioaddr);
 
-	/* Work around for rx fifo overflow */
-	if (unlikely(status & RxFIFOOver) &&
-	    (tp->mac_version == RTL_GIGA_MAC_VER_11)) {
-		netif_stop_queue(dev);
-		rtl8169_tx_timeout(dev);
-		goto out;
-	}
+		/* We need to see the lastest version of tp->intr_mask to
+		 * avoid ignoring an MSI interrupt and having to wait for
+		 * another event which may never come.
+		 */
+		smp_rmb();
+		if (status & tp->intr_mask & tp->napi_event) {
+			RTL_W16(IntrMask, tp->intr_event & ~tp->napi_event);
+			tp->intr_mask = ~tp->napi_event;
+
+			if (likely(napi_schedule_prep(&tp->napi)))
+				__napi_schedule(&tp->napi);
+			else if (netif_msg_intr(tp)) {
+				printk(KERN_INFO "%s: interrupt %04x in poll\n",
+				dev->name, status);
+			}
+		}
 
-	if (unlikely(status & SYSErr)) {
-		rtl8169_pcierr_interrupt(dev);
-		goto out;
+		/* We only get a new MSI interrupt when all active irq
+		 * sources on the chip have been acknowledged. So, ack
+		 * everything we've seen and check if new sources have become
+		 * active to avoid blocking all interrupts from the chip.
+		 */
+		RTL_W16(IntrStatus,
+			(status & RxFIFOOver) ? (status | RxOverflow) : status);
+		status = RTL_R16(IntrStatus);
 	}
 
-	if (status & LinkChg)
-		rtl8169_check_link_status(dev, tp, ioaddr);
-
-	if (status & tp->napi_event) {
-		RTL_W16(IntrMask, tp->intr_event & ~tp->napi_event);
-		tp->intr_mask = ~tp->napi_event;
-
-		if (likely(netif_rx_schedule_prep(dev, &tp->napi)))
-			__netif_rx_schedule(dev, &tp->napi);
-		else if (netif_msg_intr(tp)) {
-			printk(KERN_INFO "%s: interrupt %04x in poll\n",
-			       dev->name, status);
-		}
-	}
-out:
 	return IRQ_RETVAL(handled);
 }
 
@@ -2913,13 +2923,15 @@ static int rtl8169_poll(struct napi_stru
 
 	if (work_done < budget) {
 		netif_rx_complete(dev, napi);
-		tp->intr_mask = 0xffff;
-		/*
-		 * 20040426: the barrier is not strictly required but the
-		 * behavior of the irq handler could be less predictable
-		 * without it. Btw, the lack of flush for the posted pci
-		 * write is safe - FR
+
+		/* We need for force the visibility of tp->intr_mask
+		 * for other CPUs, as we can loose an MSI interrupt
+		 * and potentially wait for a retransmit timeout if we don't.
+		 * The posted write to IntrMask is safe, as it will
+		 * eventually make it to the chip and we won't loose anything
+		 * until it does.
 		 */
+		tp->intr_mask = 0xffff;
 		smp_wmb();
 		RTL_W16(IntrMask, tp->intr_event);
 	}



  parent reply	other threads:[~2009-07-28 23:04 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20090728225828.431071451@mini.kroah.org>
2009-07-28 23:01 ` [patch 00/37] 2.6.27.29-stable review Greg KH
2009-07-28 22:58   ` [patch 01/37] fix RCU-callback-after-kmem_cache_destroy problem in sl[aou]b Greg KH
2009-07-28 22:58   ` [patch 02/37] gigaset: accept connection establishment messages in any order Greg KH
2009-07-28 22:58   ` [patch 03/37] SCSI: zalon: fix oops on attach failure Greg KH
2009-07-28 22:58   ` [patch 04/37] sound: usb-audio: add workaround for Blue Microphones devices Greg KH
2009-07-28 22:58   ` [patch 05/37] sound: virtuoso: fix Xonar D1/DX silence after resume Greg KH
2009-07-28 22:58   ` [patch 06/37] USB: EHCI: report actual_length for iso transfers Greg KH
2009-07-28 22:58   ` [patch 07/37] USB: fix memleak in usbfs Greg KH
2009-07-28 22:58   ` [patch 08/37] USB: fix uninitialised variable in ti_do_download Greg KH
2009-07-28 22:58   ` [patch 09/37] USB: handle zero-length usbfs submissions correctly Greg KH
2009-07-28 22:58   ` [patch 10/37] USB: RNDIS gadget, fix issues talking from PXA Greg KH
2009-07-28 22:58   ` [patch 11/37] USB: ti_usb_3410_5052: fix duplicate device ids Greg KH
2009-07-28 22:58   ` [patch 12/37] ALSA: ca0106 - Fix the max capture buffer size Greg KH
2009-07-28 22:58   ` [patch 13/37] ALSA: hda - Fix mute control with some ALC262 models Greg KH
2009-07-28 22:58   ` [patch 14/37] HID: hiddev, fix lock imbalance Greg KH
2009-07-28 22:58   ` [patch 15/37] elf: fix one check-after-use Greg KH
2009-07-28 22:58   ` [patch 16/37] hwmon: (max6650) Fix lock imbalance Greg KH
2009-07-28 22:58   ` [patch 17/37] md: avoid dereferencing NULL pointer when accessing suspend_* sysfs attributes Greg KH
2009-07-28 22:58   ` [patch 18/37] mm: mark page accessed before we write_end() Greg KH
2009-07-28 22:58   ` [patch 19/37] x86-64: Fix bad_srat() to clear all state Greg KH
2009-07-28 22:58   ` [patch 20/37] x86: dont use access_ok() as a range check in get_user_pages_fast() Greg KH
2009-07-28 22:58   ` [patch 21/37] SUNRPC: Avoid an unnecessary task reschedule on ENOTCONN Greg KH
2009-07-28 22:58   ` [patch 22/37] SUNRPC: Ensure we set XPRT_CLOSING only after weve sent a tcp FIN Greg KH
2009-07-28 22:58   ` [patch 23/37] SUNRPC: Dont disconnect if a connection is still in progress Greg KH
2009-07-28 22:58   ` [patch 24/37] ACPI: EC: Limit workaround for ASUS notebooks even more Greg KH
2009-07-28 22:58   ` [patch 25/37] Enable PNPACPI _PSx Support, v3 Greg KH
2009-07-28 22:58   ` [patch 26/37] ACPI: suspend: dont let device _PS3 failure prevent suspend Greg KH
2009-07-28 22:58   ` [patch 27/37] Input: wistron_btns - recognize Maxdata Pro 7000 notebooks Greg KH
2009-07-28 22:58   ` [patch 28/37] eCryptfs: Check Tag 11 literal data buffer size (CVE-2009-2406) Greg KH
2009-07-28 22:58   ` [patch 29/37] eCryptfs: parse_tag_3_packet check tag 3 packet encrypted key size (CVE-2009-2407) Greg KH
2009-07-28 22:58   ` [patch 30/37] ipsec: Fix name of CAST algorithm Greg KH
2009-07-28 22:58   ` [patch 31/37] pegasus usb-net: Fix endianness bugs Greg KH
2009-07-28 22:59   ` [patch 32/37] sky2: Fix checksum endianness Greg KH
2009-07-28 22:59   ` [patch 33/37] x25: Fix sleep from timer on socket destroy Greg KH
2009-07-28 22:59   ` [patch 34/37] usbnet cdc_subset: fix issues talking to PXA gadgets Greg KH
2009-07-28 22:59   ` Greg KH [this message]
2009-07-28 22:59   ` [patch 36/37] E100: work around the driver using streaming DMA mapping for RX descriptors Greg KH
2009-07-28 22:59   ` [patch 37/37] NET: Fix locking issues in PPP, 6pack, mkiss and strip line disciplines Greg KH
2009-07-28 23:39   ` [patch 00/37] 2.6.27.29-stable review Greg KH

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=20090728225946.186554282@mini.kroah.org \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=dave@thedillows.org \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable-review@kernel.org \
    --cc=stable@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox