From: David Miller <davem@davemloft.net>
To: nhorman@redhat.com
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH v3] netpoll: Close race condition between poll_one_napi and napi_disable
Date: Wed, 23 Sep 2015 14:33:12 -0700 (PDT) [thread overview]
Message-ID: <20150923.143312.404914990603153762.davem@davemloft.net> (raw)
In-Reply-To: <1443034678-1475-1-git-send-email-nhorman@redhat.com>
From: Neil Horman <nhorman@redhat.com>
Date: Wed, 23 Sep 2015 14:57:58 -0400
> Drivers might call napi_disable while not holding the napi instance poll_lock.
> In those instances, its possible for a race condition to exist between
> poll_one_napi and napi_disable. That is to say, poll_one_napi only tests the
> NAPI_STATE_SCHED bit to see if there is work to do during a poll, and as such
> the following may happen:
>
> CPU0 CPU1
> ndo_tx_timeout napi_poll_dev
> napi_disable poll_one_napi
> test_and_set_bit (ret 0)
> test_bit (ret 1)
> reset adapter napi_poll_routine
>
> If the adapter gets a tx timeout without a napi instance scheduled, its possible
> for the adapter to think it has exclusive access to the hardware (as the napi
> instance is now scheduled via the napi_disable call), while the netpoll code
> thinks there is simply work to do. The result is parallel hardware access
> leading to corrupt data structures in the driver, and a crash.
>
> Additionaly, there is another, more critical race between netpoll and
> napi_disable. The disabled napi state is actually identical to the scheduled
> state for a given napi instance. The implication being that, if a napi instance
> is disabled, a netconsole instance would see the napi state of the device as
> having been scheduled, and poll it, likely while the driver was dong something
> requiring exclusive access. In the case above, its fairly clear that not having
> the rings in a state ready to be polled will cause any number of crashes.
>
> The fix should be pretty easy. netpoll uses its own bit to indicate that that
> the napi instance is in a state of being serviced by netpoll (NAPI_STATE_NPSVC).
> We can just gate disabling on that bit as well as the sched bit. That should
> prevent netpoll from conducting a napi poll if we convert its set bit to a
> test_and_set_bit operation to provide mutual exclusion
>
> Change notes:
> V2)
> Remove a trailing whtiespace
> Resubmit with proper subject prefix
>
> V3)
> Clean up spacing nits
>
> Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
> CC: "David S. Miller" <davem@davemloft.net>
> CC: jmaxwell@redhat.com
> Tested-by: jmaxwell@redhat.com
Applied, thanks Neil.
prev parent reply other threads:[~2015-09-23 21:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-22 18:00 [RHEL6.6 PATCH] netpoll: Close race condition between poll_one_napi and napi_disable Neil Horman
2015-09-22 19:01 ` Neil Horman
2015-09-22 19:46 ` Alexander Duyck
2015-09-22 19:57 ` Neil Horman
2015-09-22 20:01 ` [PATCH v2] " Neil Horman
2015-09-22 22:09 ` Stephen Hemminger
2015-09-23 10:39 ` Neil Horman
2015-09-23 18:03 ` David Miller
2015-09-23 18:57 ` [PATCH v3] " Neil Horman
2015-09-23 21:33 ` David Miller [this message]
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=20150923.143312.404914990603153762.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=nhorman@redhat.com \
/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).