Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3408870pxy; Mon, 26 Apr 2021 00:40:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwU9KObJkezBSrdPxfD8NMzYRAtHZxIJYezMOZHks5dJaXyMAJcxRMbcePWHZJ139PbnJNW X-Received: by 2002:a63:1e62:: with SMTP id p34mr15528796pgm.355.1619422838782; Mon, 26 Apr 2021 00:40:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619422838; cv=none; d=google.com; s=arc-20160816; b=LtdOpp6iB3WwwlZwkKGm0FPf+CSe3sC+ES9IOTz0AeNN/PLe/P0o4h4hlxMzEZ6BVh ykfnfQrnpWgYOyhrQqxAymhkbSAgPPTXd7PVdcSjcM/D7KwCMyxpUToqnRE/3obb2uE2 tOA6BfHnbvEg8RjZ7KAdxU50GEOF6pvVjAIPUn0eHq7B62qJ2JlUMmboiyoQVKdfIbm+ 1smWiPJLYQA7M1582ZH1hI1fCsZ9IWgot0kvyxrk/g/Dql34SmMs+oCwHOwR8q+awTP2 HvyWL49Y9brDvxt1vkYsJrMn0dqUcOc3GWVFGsGO4f5cVzmp1cjly//tqM0YuWXB1qlf qtng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=grpgZ3off8goWzKG70he/Z9/qgDb05wzbH4P75yJlIM=; b=SymGmeHI4n+IdlAsDvf8lrKhNHBYaaB3QVVET7D3nfudF02zYVs7lYAARvinBoPS/a gGtI92QWywE9AgKr+n1gc5qJgN7cA1sAzvNCTVnWutRjhNB9vfV/NcL8DamSqwNkIJ3H WlUKPMMy7LhAOemipa8QxuK6o0bLeVgn/qGCM0uXgJquORzoYniIo7d7G717fcMJ8kly jsIvbrL6uQosSUqTDQrDRrH4EbjI290l35FIH1ivXP6ZGNEJZqWtDTRaDbTyaMnrg+XL pchwAM4rKMQO3Sx7/x02ALOprYe5er9/Yr3HDho4IYIfF3JwXQMsbsrOho9Rm8k6W7Di lxcg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i22si5982487pjl.16.2021.04.26.00.40.26; Mon, 26 Apr 2021 00:40:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232598AbhDZHkf convert rfc822-to-8bit (ORCPT + 99 others); Mon, 26 Apr 2021 03:40:35 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:40156 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232907AbhDZHhS (ORCPT ); Mon, 26 Apr 2021 03:37:18 -0400 Received: from mail-wr1-f70.google.com ([209.85.221.70]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lavnI-00054i-HN for linux-kernel@vger.kernel.org; Mon, 26 Apr 2021 07:36:36 +0000 Received: by mail-wr1-f70.google.com with SMTP id s9-20020a5d51090000b02901028ea30da6so18484556wrt.7 for ; Mon, 26 Apr 2021 00:36:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=Hv+x9onO5eW3FH66okgrjnOSHrmS6UheiLB3gLXIK+w=; b=XxHoNHHtHmj6oBlsYME8yZEC8Ym0XPtuij+P+B+CpgNgq0WJKhMOm2ZcswgmYEETdz Ayp8dO0937D7Ii/ExYUKonfaznhvafoz1RogAau2grUeVv0DwcklxsDqx22g/xq8VYNW s8Z4il2LN7IyIHYZrG8HChkWZxPizVDwfCkHrUEwBp1ObIb61z95pCSZVcIdpu/1fC+X xOpE7v+F4OFKteDrUbpju9YrKA0E+cGrspJKhOHS9+NtZsPlqOrqGW9srcLU/3R7zVts RVtENTORV1ds6E36/zV+uPr06BCGTWck1gfs+T3YOsFk5kqTFGY5CPqqC+L0xzzI1Ogd udLg== X-Gm-Message-State: AOAM533TLKxKd4sKMkmfviSyJrzltG+YhU3LThuQd0SQfY8ExbCfpCEI rsoFdRs1n9dCQLjr/MoDt4ecWZOxXrAkz4/X7vlFyHps8vTWQVUlestO95diWrkx/PBXLS7gH7r 82oFvta4ao4Hi8D3zpTdYosK5gHPuzWdEphY7HC67PxuraYMAsLBlpj+6IQ== X-Received: by 2002:a5d:47cc:: with SMTP id o12mr21081335wrc.227.1619422596219; Mon, 26 Apr 2021 00:36:36 -0700 (PDT) X-Received: by 2002:a5d:47cc:: with SMTP id o12mr21081311wrc.227.1619422595990; Mon, 26 Apr 2021 00:36:35 -0700 (PDT) MIME-Version: 1.0 References: <20210420075406.64105-1-acelan.kao@canonical.com> <20210420122715.2066b537@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> In-Reply-To: From: AceLan Kao Date: Mon, 26 Apr 2021 15:36:24 +0800 Message-ID: Subject: Re: [PATCH] net: called rtnl_unlock() before runpm resumes devices To: Heiner Kallweit Cc: Jakub Kicinski , Eric Dumazet , "David S. Miller" , Alexei Starovoitov , Andrii Nakryiko , Wei Wang , Cong Wang , Taehee Yoo , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , netdev , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Heiner Kallweit 於 2021年4月25日 週日 上午4:07寫道: > > On 23.04.2021 05:42, AceLan Kao wrote: > > Heiner Kallweit 於 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 於 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 wrote: > >>>>>> > >>>>>> From: "Chia-Lin Kao (AceLan)" > >>>>>> > >>>>>> 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 > Hi Heiner, I encountered below error after applied your patch. [ 121.489970] u kernel: ------------[ cut here ]------------ [ 121.489979] u kernel: igb 0000:05:00.0: disabling already-disabled device [ 121.490008] u kernel: WARNING: CPU: 7 PID: 258 at drivers/pci/pci.c:2146 pci_disable_device+0x91/0xb0 [ 121.490028] u kernel: Modules linked in: rfcomm cmac algif_hash algif_skcipher af_alg bnep btusb btrtl btbcm btintel bluetooth ecdh_generic ecc joydev input_leds inte l_rapl_msr intel_rapl_common x86_pkg_temp_thermal intel_powerclamp coretemp ath10k_pci ath10k_core kvm_intel ath mac80211 kvm snd_sof_pci_intel_tgl snd_soc_acpi_intel_ma tch snd_sof_intel_hda_common nls_iso8859_1 soundwire_intel soundwire_generic_allocation soundwire_cadence soundwire_bus snd_sof_pci snd_soc_acpi snd_sof snd_soc_core snd _hda_codec_realtek snd_hda_codec_generic snd_hda_codec_hdmi crct10dif_pclmul crc32_pclmul snd_sof_xtensa_dsp ghash_clmulni_intel ledtrig_audio aesni_intel snd_hda_intel libarc4 crypto_simd snd_intel_dspcfg snd_intel_sdw_acpi cryptd snd_hda_codec cfg80211 mei_hdcp snd_hwdep snd_hda_core intel_wmi_thunderbolt snd_pcm wmi_bmof snd_seq inte l_cstate efi_pstore snd_timer snd_seq_device ee1004 mei_me snd mei ucsi_acpi soundcore typec_ucsi typec wmi mac_hid acpi_pad acpi_tad sch_fq_codel [ 121.490314] u kernel: parport_pc ppdev lp parport ip_tables x_tables autofs4 btrfs blake2b_generic zstd_compress raid10 raid456 async_raid6_recov async_memcpy async_ pq async_xor async_tx libcrc32c xor raid6_pq raid1 raid0 multipath linear hid_generic usbhid hid i915 drm_kms_helper syscopyarea sysfillrect sysimgblt fb_sys_fops cec rc _core igb drm nvme e1000e nvme_core i2c_i801 dca i2c_smbus i2c_algo_bit intel_lpss_pci intel_lpss ahci idma64 video xhci_pci libahci virt_dma xhci_pci_renesas pinctrl_ti gerlake [ 121.490508] u kernel: CPU: 7 PID: 258 Comm: kworker/7:2 Tainted: G U 5.12.0-rc7+ #79 [ 121.490518] u kernel: Hardware name: Dell Inc. OptiPlex 7090/, BIOS 0.12.80 02/23/2021 [ 121.490525] u kernel: Workqueue: pm pm_runtime_work [ 121.490540] u kernel: RIP: 0010:pci_disable_device+0x91/0xb0 [ 121.490550] u kernel: Code: 4d 85 e4 75 07 4c 8b a3 c8 00 00 00 48 8d bb c8 00 00 00 e8 61 8d 17 00 4c 89 e2 48 c7 c7 60 5a e0 a5 48 89 c6 e8 9b a3 59 00 <0f> 0b eb 8 d 48 89 df e8 e3 fe ff ff 80 a3 49 0a 00 00 df 5b 41 5c [ 121.490558] u kernel: RSP: 0018:ffffb76b4169fc90 EFLAGS: 00010286 [ 121.490569] u kernel: RAX: 0000000000000000 RBX: ffff9e2581ee6000 RCX: 0000000000000027 [ 121.490576] u kernel: RDX: 0000000000000027 RSI: ffffffffa493bca0 RDI: ffff9e27073e89b8 [ 121.490582] u kernel: RBP: ffffb76b4169fca0 R08: ffff9e27073e89b0 R09: 0000000000000000 [ 121.490588] u kernel: R10: 0000000000000000 R11: 0000000000000001 R12: ffff9e2581af7c80 [ 121.490594] u kernel: R13: ffff9e2581ee6000 R14: ffff9e25a0914000 R15: ffff9e25a0915280 [ 121.490600] u kernel: FS: 0000000000000000(0000) GS:ffff9e2707200000(0000) knlGS:0000000000000000 [ 121.490608] u kernel: CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 121.490614] u kernel: CR2: 00007ff86ec8d024 CR3: 0000000189c28002 CR4: 0000000000770ee0 [ 121.490621] u kernel: PKRU: 55555554 [ 121.490626] u kernel: Call Trace: [ 121.490638] u kernel: __igb_shutdown+0xf2/0x1c0 [igb] [ 121.490676] u kernel: igb_runtime_suspend+0x1c/0x20 [igb] [ 121.490703] u kernel: pci_pm_runtime_suspend+0x63/0x180 [ 121.490715] u kernel: ? pci_pm_runtime_resume+0x90/0x90 [ 121.490727] u kernel: __rpm_callback+0xc7/0x140 [ 121.490740] u kernel: rpm_callback+0x57/0x80 [ 121.490750] u kernel: ? pci_pm_runtime_resume+0x90/0x90 [ 121.490759] u kernel: rpm_suspend+0x119/0x640 [ 121.490774] u kernel: pm_runtime_work+0x64/0xc0 [ 121.490784] u kernel: process_one_work+0x2af/0x5d0 [ 121.490803] u kernel: worker_thread+0x4d/0x3e0 [ 121.490814] u kernel: ? process_one_work+0x5d0/0x5d0 [ 121.490825] u kernel: kthread+0x12a/0x160 [ 121.490834] u kernel: ? kthread_park+0x90/0x90 [ 121.490844] u kernel: ret_from_fork+0x1f/0x30 [ 121.490867] u kernel: irq event stamp: 0[ 121.490871] u kernel: hardirqs last enabled at (0): [<0000000000000000>] 0x0 [ 121.490916] u kernel: hardirqs last disabled at (0): [] copy_process+0x714/0x1cc0 [ 121.490929] u kernel: softirqs last enabled at (0): [] copy_process+0x714/0x1cc0 [ 121.490938] u kernel: softirqs last disabled at (0): [<0000000000000000>] 0x0 [ 121.490949] u kernel: ---[ end trace a9c7ffc27c226979 ]---