netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
To: davem@davemloft.net
Cc: Dean Nelson <dnelson@redhat.com>,
	netdev@vger.kernel.org, gospo@redhat.com,
	Andy Gospodarek <andy@greyhouse.net>,
	Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Subject: [net-next 01/10] e1000: don't enable dma receives until after dma address has been setup
Date: Sat, 24 Sep 2011 02:17:34 -0700	[thread overview]
Message-ID: <1316855863-6091-2-git-send-email-jeffrey.t.kirsher@intel.com> (raw)
In-Reply-To: <1316855863-6091-1-git-send-email-jeffrey.t.kirsher@intel.com>

From: Dean Nelson <dnelson@redhat.com>

Doing an 'ifconfig ethN down' followed by an 'ifconfig ethN up' on a qemu-kvm
guest system configured with two e1000 NICs can result in an 'unable to handle
kernel paging request at 0000000100000000' or 'bad page map in process ...' or
something similar.

These result from a 4096-byte page being corrupted with the following two-word
pattern (16-bytes) repeated throughout the entire page:

  0x0000000000000000
  0x0000000100000000

There can be other bits set as well. What is a constant is that the 2nd word
has the 32nd bit set. So one could see:

        :
  0x0000000000000000
  0x0000000100000000
  0x0000000000000000
  0x0000000172adc067    <<< bad pte
  0x800000006ec60067
  0x0000000700000040
  0x0000000000000000
  0x0000000100000000
        :

Which came from from a process' page table I dumped out when the marked line
was seen as bad by print_bad_pte().

The repeating pattern represents the e1000's two-word receive descriptor:

struct e1000_rx_desc {
        __le64 buffer_addr;   /* Address of the descriptor's data buffer */
        __le16 length;        /* Length of data DMAed into data buffer */
        __le16 csum;          /* Packet checksum */
        u8 status;            /* Descriptor status */
        u8 errors;            /* Descriptor Errors */
        __le16 special;
};

And the 32nd bit of the 2nd word maps to the 'u8 status' member, and
corresponds to E1000_RXD_STAT_DD which indicates the descriptor is done.

The corruption appears to result from the following...

 . An 'ifconfig ethN down' gets us into e1000_close(), which through a number
   of subfunctions results in:
     1. E1000_RCTL_EN being cleared in RCTL register.  [e1000_down()]
     2. dma_free_coherent() being called.  [e1000_free_rx_resources()]

 . An 'ifconfig ethN up' gets us into e1000_open(), which through a number of
   subfunctions results in:
     1. dma_alloc_coherent() being called.  [e1000_setup_rx_resources()]
     2. E1000_RCTL_EN being set in RCTL register.  [e1000_setup_rctl()]
     3. E1000_RCTL_EN being cleared in RCTL register.  [e1000_configure_rx()]
     4. RDLEN, RDBAH and RDBAL registers being set to reflect the dma page
        allocated in step 1.  [e1000_configure_rx()]
     5. E1000_RCTL_EN being set in RCTL register.  [e1000_configure_rx()]

During the 'ifconfig ethN up' there is a window opened, starting in step 2
where the receives are enabled up until they are disabled in step 3, in which
the address of the receive descriptor dma page known by the NIC is still the
previous one which was freed during the 'ifconfig ethN down'. If this memory
has been reallocated for some other use and the NIC feels so inclined, it will
write to that former dma page with predictably unpleasant results.

I realize that in the guest, we're dealing with an e1000 NIC that is software
emulated by qemu-kvm. The problem doesn't appear to occur on bare-metal. Andy
suspects that this is because in the emulator link-up is essentially instant
and traffic can start flowing immediately. Whereas on bare-metal, link-up
usually seems to take at least a few milliseconds. And this might be enough
to prevent traffic from flowing into the device inside the window where
E1000_RCTL_EN is set.

So perhaps a modification needs to be made to the qemu-kvm e1000 NIC emulator
to delay the link-up. But in defense of the emulator, it seems like a bad idea
to enable dma operations before the address of the memory to be involved has
been made known.

The following patch no longer enables receives in e1000_setup_rctl() but leaves
them however they were. It only enables receives in e1000_configure_rx(), and
only after the dma address has been made known to the hardware.

There are two places where e1000_setup_rctl() gets called. The one in
e1000_configure() is followed immediately by a call to e1000_configure_rx(), so
there's really no change functionally (except for the removal of the problem
window. The other is in __e1000_shutdown() and is not followed by a call to
e1000_configure_rx(), so there is a change functionally. But consider...

 . An 'ifconfig ethN down' (just as described above).

 . A 'suspend' of the system, which (I'm assuming) will find its way into
   e1000_suspend() which calls __e1000_shutdown() resulting in:
     1. E1000_RCTL_EN being set in RCTL register.  [e1000_setup_rctl()]

And again we've re-opened the problem window for some unknown amount of time.

Signed-off-by: Andy Gospodarek <andy@greyhouse.net>
Signed-off-by: Dean Nelson <dnelson@redhat.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
---
 drivers/net/ethernet/intel/e1000/e1000_main.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/intel/e1000/e1000_main.c b/drivers/net/ethernet/intel/e1000/e1000_main.c
index 27f586a..4bbc05a 100644
--- a/drivers/net/ethernet/intel/e1000/e1000_main.c
+++ b/drivers/net/ethernet/intel/e1000/e1000_main.c
@@ -1814,8 +1814,8 @@ static void e1000_setup_rctl(struct e1000_adapter *adapter)
 
 	rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
 
-	rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
-		E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
+	rctl |= E1000_RCTL_BAM | E1000_RCTL_LBM_NO |
+		E1000_RCTL_RDMTS_HALF |
 		(hw->mc_filter_type << E1000_RCTL_MO_SHIFT);
 
 	if (hw->tbi_compatibility_on == 1)
@@ -1917,7 +1917,7 @@ static void e1000_configure_rx(struct e1000_adapter *adapter)
 	}
 
 	/* Enable Receives */
-	ew32(RCTL, rctl);
+	ew32(RCTL, rctl | E1000_RCTL_EN);
 }
 
 /**
-- 
1.7.6.2

  reply	other threads:[~2011-09-24  9:17 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-24  9:17 [net-next 00/10][pull request] Intel Wired LAN Drivers Update Jeff Kirsher
2011-09-24  9:17 ` Jeff Kirsher [this message]
2011-09-24  9:17 ` [net-next 02/10] ixgbevf: Fix broken trunk vlan Jeff Kirsher
2011-09-24 16:33   ` Jesse Gross
2011-09-25  5:47     ` Jeff Kirsher
2011-09-26 15:57     ` Rose, Gregory V
2011-09-26 23:08       ` Jesse Gross
2011-09-26 23:24         ` Rose, Gregory V
2011-09-27  0:54           ` Jesse Gross
2011-09-27 16:39             ` Rose, Gregory V
2011-09-27 16:49               ` Jesse Gross
2011-09-24  9:17 ` [net-next 03/10] ixgbe: Cleanup q_vector interrupt throttle rate logic Jeff Kirsher
2011-09-24  9:17 ` [net-next 04/10] ixgbe: disable LLI for FCoE Jeff Kirsher
2011-09-24  9:17 ` [net-next 05/10] if_link: Add additional parameter to IFLA_VF_INFO for spoof checking Jeff Kirsher
2011-09-24 16:40   ` Ben Hutchings
2011-09-25  5:54     ` Jeff Kirsher
2011-09-26 16:06     ` Rose, Gregory V
2011-09-25 17:22   ` Stephen Hemminger
2011-09-25 20:06     ` Ben Hutchings
2011-09-26 16:14       ` Stephen Hemminger
2011-09-26 16:32         ` Rose, Gregory V
2011-09-26 16:37           ` Stephen Hemminger
2011-09-26 16:18     ` Rose, Gregory V
2011-09-26 16:21       ` Stephen Hemminger
2011-09-26 16:57         ` Rose, Gregory V
2011-09-24  9:17 ` [net-next 06/10] ixgbe: Add new netdev op to turn spoof checking on or off per VF Jeff Kirsher
2011-09-24  9:17 ` [net-next 07/10] ixgbe: update {P}FC thresholds to account for X540 and loopback Jeff Kirsher
2011-09-24  9:17 ` [net-next 08/10] ixgbe add thermal sensor support for x540 hardware Jeff Kirsher
2011-09-24  9:17 ` [net-next 09/10] ixgbe: cleanup ixgbe_setup_gpie() for X540 Jeff Kirsher
2011-09-24  9:17 ` [net-next 10/10] ixgbe: add ECC warning for legacy interrupts Jeff Kirsher

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=1316855863-6091-2-git-send-email-jeffrey.t.kirsher@intel.com \
    --to=jeffrey.t.kirsher@intel.com \
    --cc=andy@greyhouse.net \
    --cc=davem@davemloft.net \
    --cc=dnelson@redhat.com \
    --cc=gospo@redhat.com \
    --cc=netdev@vger.kernel.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).