linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anatoli Antonovitch <a.antonovitch@gmail.com>
To: linux-pci@vger.kernel.org
Cc: bhelgaas@google.com, lukas@wunner.de, Alexander.Deucher@amd.com,
	christian.koenig@amd.com,
	Anatoli Antonovitch <anatoli.antonovitch@amd.com>
Subject: [PATCH] PCI/hotplug: Replaced down_write_nested with hotplug_slot_rwsem if ctrl->depth > 0 when taking the ctrl->reset_lock.
Date: Fri, 13 Jan 2023 12:01:31 -0500	[thread overview]
Message-ID: <20230113170131.5086-1-a.antonovitch@gmail.com> (raw)

From: Anatoli Antonovitch <anatoli.antonovitch@amd.com>

It is to avoid any potential issues when S3 resume but at the same time we want to hot-unplug.

To fix the race between pciehp and AER reported in https://bugzilla.kernel.org/show_bug.cgi?id=215590

INFO: task irq/26-aerdrv:95 blocked for more than 120 seconds.
Tainted: G        W          6.2.0-rc3-custom-norework-jan11+ #29
"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
task:irq/26-aerdrv   state:D stack:0     pid:95    ppid:2      flags:0x00004000
Call Trace:
<TASK>
__schedule+0x3df/0xec0
? rcu_read_lock_held_common+0x12/0x60
schedule+0x6b/0x100
rwsem_down_write_slowpath+0x3b2/0x9c0
down_write_nested+0x16b/0x220
pciehp_reset_slot+0x63/0x160
pci_reset_hotplug_slot+0x44/0x80
pci_slot_reset+0x10d/0x1a0
pci_bus_error_reset+0xb2/0xe0
aer_root_reset+0x144/0x1a0
pcie_do_recovery+0x15a/0x280
? __pfx_aer_root_reset+0x20/0x20
aer_process_err_devices+0xfa/0x115
aer_isr.cold+0x52/0xa1
? __kmem_cache_free+0x36a/0x3c0
? irq_thread+0xb0/0x1e0
? irq_thread+0xb0/0x1e0
irq_thread_fn+0x28/0x80
irq_thread+0x106/0x1e0
? __pfx_irq_thread_fn+0x20/0x20
? __pfx_irq_thread_dtor+0x20/0x20
? __pfx_irq_thread+0x20/0x20
kthread+0x10a/0x140
? __pfx_kthread+0x20/0x20
ret_from_fork+0x35/0x60
</TASK>

INFO: task irq/26-pciehp:96 blocked for more than 120 seconds.
Tainted: G        W          6.2.0-rc3-custom-norework-jan11+ #29
"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
task:irq/26-pciehp   state:D stack:0     pid:96    ppid:2      flags:0x00004000
Call Trace:
<TASK>
__schedule+0x3df/0xec0
? rcu_read_lock_sched_held+0x25/0x80
schedule+0x6b/0x100
schedule_preempt_disabled+0x18/0x40
__mutex_lock+0x685/0xf60
? rcu_read_lock_sched_held+0x25/0x80
? rcu_read_lock_held_common+0x12/0x60
? pci_dev_set_disconnected+0x1b/0x80
mutex_lock_nested+0x1b/0x40
? mutex_lock_nested+0x1b/0x40
pci_dev_set_disconnected+0x1b/0x80
? __pfx_pci_dev_set_disconnected+0x20/0x20
pci_walk_bus+0x48/0xa0
pciehp_unconfigure_device+0x129/0x140
pciehp_disable_slot+0x6e/0x120
pciehp_handle_presence_or_link_change+0xf1/0x320
pciehp_ist+0x1a0/0x1c0
? irq_thread+0xb0/0x1e0
irq_thread_fn+0x28/0x80
irq_thread+0x106/0x1e0
? __pfx_irq_thread_fn+0x20/0x20
? __pfx_irq_thread_dtor+0x20/0x20
? __pfx_irq_thread+0x20/0x20
kthread+0x10a/0x140
? __pfx_kthread+0x20/0x20
ret_from_fork+0x35/0x60
</TASK>

Signed-off-by: Anatoli Antonovitch <anatoli.antonovitch@amd.com>
---
 drivers/pci/hotplug/pciehp_hpc.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index 10e9670eea0b..b1084e67f798 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -27,6 +27,8 @@
 #include "../pci.h"
 #include "pciehp.h"
 
+static DECLARE_RWSEM(hotplug_slot_rwsem);
+
 static const struct dmi_system_id inband_presence_disabled_dmi_table[] = {
 	/*
 	 * Match all Dell systems, as some Dell systems have inband
@@ -911,7 +913,10 @@ int pciehp_reset_slot(struct hotplug_slot *hotplug_slot, bool probe)
 	if (probe)
 		return 0;
 
-	down_write_nested(&ctrl->reset_lock, ctrl->depth);
+	if (ctrl->depth > 0)
+		down_write_nested(&ctrl->reset_lock, ctrl->depth);
+	else
+		down_write(&hotplug_slot_rwsem);
 
 	if (!ATTN_BUTTN(ctrl)) {
 		ctrl_mask |= PCI_EXP_SLTCTL_PDCE;
@@ -931,7 +936,11 @@ int pciehp_reset_slot(struct hotplug_slot *hotplug_slot, bool probe)
 	ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__,
 		 pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, ctrl_mask);
 
-	up_write(&ctrl->reset_lock);
+	if (ctrl->depth > 0)
+		up_write(&ctrl->reset_lock);
+	else
+		up_write(&hotplug_slot_rwsem);
+
 	return rc;
 }
 
-- 
2.25.1


             reply	other threads:[~2023-01-13 17:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-13 17:01 Anatoli Antonovitch [this message]
2023-01-20  9:28 ` [PATCH] PCI/hotplug: Replaced down_write_nested with hotplug_slot_rwsem if ctrl->depth > 0 when taking the ctrl->reset_lock Lukas Wunner
2023-01-20 21:35   ` Anatoli Antonovitch
2023-01-21  7:21     ` Lukas Wunner
2023-01-23 19:30       ` Anatoli Antonovitch
2023-02-13 14:59         ` Anatoli Antonovitch
2023-02-17 16:03           ` Bjorn Helgaas
2023-02-17 18:37             ` Deucher, Alexander
2023-02-19 20:21               ` Lukas Wunner
2023-04-10 20:36                 ` Anatoli Antonovitch
  -- strict thread matches above, loose matches on Subject: below --
2023-01-05 18:43 Anatoli Antonovitch
2023-01-05 19:18 ` Bjorn Helgaas
     [not found]   ` <5b9a2dc7-54ab-82c5-81e7-1770a4ec891c@amd.com>
2023-01-16 18:37     ` Bjorn Helgaas

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=20230113170131.5086-1-a.antonovitch@gmail.com \
    --to=a.antonovitch@gmail.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=anatoli.antonovitch@amd.com \
    --cc=bhelgaas@google.com \
    --cc=christian.koenig@amd.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas@wunner.de \
    /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).