linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Heiner Kallweit <hkallweit1@gmail.com>
To: AceLan Kao <acelan.kao@canonical.com>
Cc: "Jakub Kicinski" <kuba@kernel.org>,
	"Eric Dumazet" <edumazet@google.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Andrii Nakryiko" <andriin@fb.com>,
	"Wei Wang" <weiwan@google.com>,
	"Cong Wang" <cong.wang@bytedance.com>,
	"Taehee Yoo" <ap420073@gmail.com>,
	"Björn Töpel" <bjorn@kernel.org>, netdev <netdev@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] net: called rtnl_unlock() before runpm resumes devices
Date: Sat, 24 Apr 2021 22:07:50 +0200	[thread overview]
Message-ID: <f06e0e2b-c6bb-ef5a-f629-d1ab82b7aee2@gmail.com> (raw)
In-Reply-To: <CAFv23QkUsTf5M0MoUEFNYeFCtShAn3EmA3u8vXVeZyJa20Bx=g@mail.gmail.com>

On 23.04.2021 05:42, AceLan Kao wrote:
> Heiner Kallweit <hkallweit1@gmail.com> 於 2021年4月22日 週四 下午3:09寫道:
>>
>> On 22.04.2021 08:30, AceLan Kao wrote:
>>> Yes, should add
>>>
>>> Fixes: 9474933caf21 ("igb: close/suspend race in netif_device_detach")
>>> and also
>>> Fixes: 9513d2a5dc7f ("igc: Add legacy power management support")
>>>
>> Please don't top-post. Apart from that:
>> If the issue was introduced with driver changes, then adding a workaround
>> in net core may not be the right approach.
> It's hard to say who introduces this issue, we probably could point
> our finger to below commit
> bd869245a3dc net: core: try to runtime-resume detached device in __dev_open
> 
> This calling path is not usual, in my case, the NIC is not plugged in
> any Ethernet cable,
> and we are doing networking tests on another NIC on the system. So,
> remove the rtnl lock from igb driver will affect other scenarios.
> 
>>
>>> Jakub Kicinski <kuba@kernel.org> 於 2021年4月21日 週三 上午3:27寫道:
>>>>
>>>> On Tue, 20 Apr 2021 10:34:17 +0200 Eric Dumazet wrote:
>>>>> On Tue, Apr 20, 2021 at 9:54 AM AceLan Kao <acelan.kao@canonical.com> wrote:
>>>>>>
>>>>>> From: "Chia-Lin Kao (AceLan)" <acelan.kao@canonical.com>
>>>>>>
>>>>>> The rtnl_lock() has been called in rtnetlink_rcv_msg(), and then in
>>>>>> __dev_open() it calls pm_runtime_resume() to resume devices, and in
>>>>>> some devices' resume function(igb_resum,igc_resume) they calls rtnl_lock()
>>>>>> again. That leads to a recursive lock.
>>>>>>
>>>>>> It should leave the devices' resume function to decide if they need to
>>>>>> call rtnl_lock()/rtnl_unlock(), so call rtnl_unlock() before calling
>>>>>> pm_runtime_resume() and then call rtnl_lock() after it in __dev_open().
>>>>>>
>>>>>>
>>>>>
>>>>> Hi Acelan
>>>>>
>>>>> When was the bugg added ?
>>>>> Please add a Fixes: tag
>>>>
>>>> For immediate cause probably:
>>>>
>>>> Fixes: 9474933caf21 ("igb: close/suspend race in netif_device_detach")
>>>>
>>>>> By doing so, you give more chances for reviewers to understand why the
>>>>> fix is not risky,
>>>>> and help stable teams work.
>>>>
>>>> IMO the driver lacks internal locking. Taking 看rtnl from resume is just
>>>> one example, git history shows many more places that lacked locking and
>>>> got papered over with rtnl here.
>>

You could alternatively try the following. It should avoid the deadlock,
and when runtime-resuming if __IGB_DOWN is set all we do is marking the
net_device as present (because of PCI D3 -> D0 transition).
I do basically the same in r8169 and it works as intended.

Disclaimer: I don't have an igb-driven device and therefore can't test
the proposal.

diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index 038a9fd1a..21436626a 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -9300,6 +9300,14 @@ static int __maybe_unused igb_runtime_suspend(struct device *dev)
 
 static int __maybe_unused igb_runtime_resume(struct device *dev)
 {
+	struct net_device *netdev = dev_get_drvdata(dev);
+	struct igb_adapter *adapter = netdev_priv(netdev);
+
+	if (test_bit(__IGB_DOWN, &adapter->state)) {
+		netif_device_attach(netdev);
+		return 0;
+	}
+
 	return igb_resume(dev);
 }
 
-- 
2.31.1


  reply	other threads:[~2021-04-24 20:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-20  7:54 [PATCH] net: called rtnl_unlock() before runpm resumes devices AceLan Kao
2021-04-20  8:34 ` Eric Dumazet
2021-04-20 19:27   ` Jakub Kicinski
2021-04-22  6:30     ` AceLan Kao
2021-04-22  7:09       ` Heiner Kallweit
2021-04-23  3:42         ` AceLan Kao
2021-04-24 20:07           ` Heiner Kallweit [this message]
2021-04-26  7:36             ` AceLan Kao
2021-04-26  8:42               ` Heiner Kallweit
2021-04-27  1:58                 ` AceLan Kao
2021-04-27  6:18                   ` Heiner Kallweit
2021-04-29 11:58 ` Krzysztof Kozlowski
2021-04-29 19:33   ` Heiner Kallweit
2021-06-30  5:19     ` AceLan Kao

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=f06e0e2b-c6bb-ef5a-f629-d1ab82b7aee2@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=acelan.kao@canonical.com \
    --cc=andriin@fb.com \
    --cc=ap420073@gmail.com \
    --cc=ast@kernel.org \
    --cc=bjorn@kernel.org \
    --cc=cong.wang@bytedance.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=weiwan@google.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).