linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@ucw.cz>
To: Lino Sanfilippo <LinoSanfilippo@gmx.de>
Cc: Francois Romieu <romieu@fr.zoreil.com>,
	bh74.an@samsung.com, ks.giri@samsung.com,
	vipul.pandya@samsung.com, peppe.cavallaro@st.com,
	alexandre.torgue@st.com, davem@davemloft.net,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH 1/2] net: ethernet: sxgbe: remove private tx queue lock
Date: Thu, 8 Dec 2016 23:18:30 +0100	[thread overview]
Message-ID: <20161208221830.GD12472@amd> (raw)
In-Reply-To: <9b55b51c-bbbf-7f80-fb67-9df88a288708@gmx.de>

[-- Attachment #1: Type: text/plain, Size: 2997 bytes --]

On Thu 2016-12-08 23:12:10, Lino Sanfilippo wrote:
> Hi,
> 
> On 08.12.2016 22:54, Pavel Machek wrote:
> > On Thu 2016-12-08 21:32:12, Lino Sanfilippo wrote:
> >> Hi,
> >> 
> >> On 08.12.2016 00:15, Francois Romieu wrote:
> >> > Lino Sanfilippo <LinoSanfilippo@gmx.de> :
> >> >> The driver uses a private lock for synchronization between the xmit
> >> >> function and the xmit completion handler, but since the NETIF_F_LLTX flag
> >> >> is not set, the xmit function is also called with the xmit_lock held.
> >> >> 
> >> >> On the other hand the xmit completion handler first takes the private lock
> >> >> and (in case that the tx queue has been stopped) the xmit_lock, leading
> >> >> to a reverse locking order and the potential danger of a deadlock.
> >> > 
> >> > netif_tx_stop_queue is used by:
> >> > 1. xmit function before releasing lock and returning.
> >> > 2. sxgbe_restart_tx_queue()
> >> >    <- sxgbe_tx_interrupt
> >> >    <- sxgbe_reset_all_tx_queues()
> >> >       <- sxgbe_tx_timeout()
> >> > 
> >> > Given xmit won't be called again until tx queue is enabled, it's not clear
> >> > how a deadlock could happen due to #1.
> >> > 
> >> 
> >> 
> >> After spending more thoughts on this I tend to agree with you. Yes, we have the
> >> different locking order for the xmit_lock and the private lock in two concurrent
> >> threads. And one of the first things one learns about locking is that this is a
> >> good way to create a deadlock sooner or later. But in our case the deadlock 
> >> can only occur if the xmit function and the tx completion handler perceive different
> >>  states for the tx queue, or to be more specific: 
> >> the completion handler sees the tx queue in state "stopped" while the xmit handler 
> >> sees it in state "running" at the same time. Only then both functions would try to
> >> take both locks, which could lead to a deadlock.
> >> 
> >> OTOH Pavel said that he actually could produce a deadlock. Now I wonder if this is caused
> >> by that locking scheme (in a way I have not figured out yet) or if it is a different issue.
> > 
> > Pavel has some problems, but that's on different hardware.. and it is
> > possible that it is deadlock (or something else) somewhere else.
> > 
> 
> Right, it is different hardware. But the locking situation in xmit function and tx completion handler
> is very similar in both drivers. So if a deadlock is not possible in sxgbe it should 
> also not be possible in stmmac (at least not due to the different locking order). 
> So maybe there is no real issue that we could fix with removing the private lock and we should
> keep it as it is.

Well.. the locking is pretty confused there. Having private lock that
mirrors lock from network layer is confusing and ugly... that should
be reason to fix it.
									Pavel

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

  reply	other threads:[~2016-12-08 22:18 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-07 20:05 Remove private locks to avoid possible deadlock Lino Sanfilippo
2016-12-07 20:05 ` [PATCH 1/2] net: ethernet: sxgbe: remove private tx queue lock Lino Sanfilippo
2016-12-07 23:15   ` Francois Romieu
2016-12-08 20:32     ` Lino Sanfilippo
2016-12-08 21:54       ` Pavel Machek
2016-12-08 22:12         ` Lino Sanfilippo
2016-12-08 22:18           ` Pavel Machek [this message]
2016-12-08 22:45             ` Lino Sanfilippo
2016-12-08 23:19       ` Francois Romieu
2016-12-09 11:21         ` Pavel Machek
2016-12-10  2:25           ` Lino Sanfilippo
2016-12-11 20:11             ` Pavel Machek
2016-12-15 19:27               ` Lino Sanfilippo
2016-12-15 21:03                 ` Pavel Machek
2016-12-15 21:32                   ` Lino Sanfilippo
2016-12-15 22:33                     ` Lino Sanfilippo
2016-12-17 17:31                       ` Pavel Machek
2016-12-18  0:15                         ` Francois Romieu
2016-12-18 16:15                           ` Lino Sanfilippo
2016-12-18 17:23                             ` Pavel Machek
2016-12-18 18:30                             ` Pavel Machek
2016-12-19 22:49                               ` Lino Sanfilippo
2016-12-18 20:16                             ` Pavel Machek
2016-12-19 10:02                           ` Pavel Machek
2016-12-20  0:05                             ` Francois Romieu
2016-12-07 20:05 ` [PATCH 2/2] net: ethernet: stmmac: " Lino Sanfilippo
2016-12-07 20:55   ` Pavel Machek
2016-12-07 20:59   ` Pavel Machek
2016-12-07 21:37   ` Pavel Machek
2016-12-07 21:43     ` Lino Sanfilippo
2016-12-07 22:34       ` Lino Sanfilippo
2016-12-07 23:21         ` Pavel Machek
2016-12-07 23:41     ` David Miller
2016-12-08 14:08       ` Pavel Machek
2016-12-08 15:26         ` David Miller
2016-12-08 15:46           ` Pavel Machek

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=20161208221830.GD12472@amd \
    --to=pavel@ucw.cz \
    --cc=LinoSanfilippo@gmx.de \
    --cc=alexandre.torgue@st.com \
    --cc=bh74.an@samsung.com \
    --cc=davem@davemloft.net \
    --cc=ks.giri@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=peppe.cavallaro@st.com \
    --cc=romieu@fr.zoreil.com \
    --cc=vipul.pandya@samsung.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).