linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nam Cao <namcao@linutronix.de>
To: Lukas Wunner <lukas@wunner.de>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
	Yinghai Lu <yinghai@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Rajesh Shah <rajesh.shah@intel.com>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH 2/4] PCI: pciehp: bail out if pci_hp_add_bridge() fails
Date: Sat, 4 May 2024 12:56:30 +0200	[thread overview]
Message-ID: <20240504105630.DPSzrgHe@linutronix.de> (raw)
In-Reply-To: <ZjYFOrGlluGW_GzV@wunner.de>

On Sat, May 04, 2024 at 11:51:54AM +0200, Lukas Wunner wrote:
> On Sat, May 04, 2024 at 11:35:29AM +0200, Nam Cao wrote:
> > pci_stop_and_remove_bus_device() is not necessary to prevent kernel
> > crashing. But without this, we cannot hot-plug any other devices to this
> > slot afterward, despite the bridge has already been removed. Below is what
> > happens without pci_stop_and_remove_bus_device().
> > 
> > First, we hotplug a bridge. That fails, so QEMU removes this bridge:
> > (qemu) device_add pci-bridge,id=br2,bus=br1,chassis_nr=19,addr=1
> > [    9.289609] shpchp 0000:01:00.0: Latch close on Slot(1-1)
> > [    9.291145] shpchp 0000:01:00.0: Button pressed on Slot(1-1)
> > [    9.292705] shpchp 0000:01:00.0: Card present on Slot(1-1)
> > [    9.294369] shpchp 0000:01:00.0: PCI slot #1-1 - powering on due to button press
> > [   15.529997] pci 0000:02:01.0: [1b36:0001] type 01 class 0x060400 conventional PCI bridge
> > [   15.533907] pci 0000:02:01.0: BAR 0 [mem 0x00000000-0x000000ff 64bit]
> > [   15.535802] pci 0000:02:01.0: PCI bridge to [bus 00]
> > [   15.538519] pci 0000:02:01.0:   bridge window [io  0x0000-0x0fff]
> > [   15.540261] pci 0000:02:01.0:   bridge window [mem 0x00000000-0x000fffff]
> > [   15.543486] pci 0000:02:01.0:   bridge window [mem 0x00000000-0x000fffff 64bit pref]
> > [   15.547151] pci 0000:02:01.0: No bus number available for hot-added bridge
> > [   15.549067] shpchp 0000:01:00.0: Cannot add device at 0000:02:01
> > [   15.553104] shpchp 0000:01:00.0: Latch open on Slot(1-1)
> > [   15.555246] shpchp 0000:01:00.0: Card not present on Slot(1-1)
> 
> I'm not familiar with shpchp, I don't understand why it's thinking
> that there's no card after it failed to find a bus number.

Sorry, I got mixed up between the two.
 
> Could you reproduce with pciehp instead of shpchp please?

Same thing for pciehp below. I think the problem is because without 
pci_stop_and_remove_bus_device(), no one cleans up the device added in
pci_scan_slot(). When another device get hot-added, pci_get_slot() wrongly
thinks another device is already there, so the hot-plug fails.

Best regards,
Nam

(qemu) device_add pcie-pci-bridge,id=br1,bus=rp1
[   19.840550] pcieport 0000:00:03.0: pciehp: pending interrupts 0x0009 from Slot Status
[   19.842843] pcieport 0000:00:03.0: pciehp: Slot(1): Button press: will power on in 5 sec
[   19.845289] pcieport 0000:00:03.0: pciehp: pending interrupts 0x0010 from Slot Status
[   19.847502] pcieport 0000:00:03.0: pciehp: pciehp_set_indicators: SLOTCTRL 6c write cmd 2c0
[   19.849876] pcieport 0000:00:03.0: pciehp: pciehp_check_link_active: lnk_status = 2011
[   19.852094] pcieport 0000:00:03.0: pciehp: Slot(1): Card present
[   19.853809] pcieport 0000:00:03.0: pciehp: Slot(1): Link Up
[   19.855412] pcieport 0000:00:03.0: pciehp: pciehp_get_power_status: SLOTCTRL 6c value read 6f1
[   19.857975] pcieport 0000:00:03.0: pciehp: pending interrupts 0x0010 from Slot Status
[   19.860199] pcieport 0000:00:03.0: pciehp: pciehp_power_on_slot: SLOTCTRL 6c write cmd 0
[   19.862586] pcieport 0000:00:03.0: pciehp: pending interrupts 0x0010 from Slot Status
[   19.864806] pcieport 0000:00:03.0: pciehp: pciehp_set_indicators: SLOTCTRL 6c write cmd 200
[   20.994936] pcieport 0000:00:03.0: pciehp: pciehp_check_link_status: lnk_status = 2011
[   20.997463] pci 0000:01:00.0: [1b36:000e] type 01 class 0x060400 PCIe to PCI/PCI-X bridge
[   21.001131] pci 0000:01:00.0: BAR 0 [mem 0x00000000-0x000000ff 64bit]
[   21.003071] pci 0000:01:00.0: PCI bridge to [bus 00]
[   21.005417] pci 0000:01:00.0:   bridge window [io  0x0000-0x0fff]
[   21.007181] pci 0000:01:00.0:   bridge window [mem 0x00000000-0x000fffff]
[   21.010084] pci 0000:01:00.0:   bridge window [mem 0x00000000-0x000fffff 64bit pref]
[   21.014162] pci 0000:01:00.0: vgaarb: pci_notify
[   21.015900] pci 0000:01:00.0: No bus number available for hot-added bridge
[   21.017865] pcieport 0000:00:03.0: pciehp: Cannot add device at 0000:01:00
[   21.019931] pcieport 0000:00:03.0: pciehp: pending interrupts 0x0010 from Slot Status
[   21.022178] pcieport 0000:00:03.0: pciehp: pciehp_power_off_slot: SLOTCTRL 6c write cmd 400
[   22.084607] pcieport 0000:00:03.0: pciehp: pending interrupts 0x0018 from Slot Status
[   22.086845] pcieport 0000:00:03.0: pciehp: pciehp_set_indicators: SLOTCTRL 6c write cmd 340
[   22.089323] pcieport 0000:00:03.0: pciehp: pending interrupts 0x0010 from Slot Status
[   22.091539] pcieport 0000:00:03.0: pciehp: pciehp_set_indicators: SLOTCTRL 6c write cmd 300
[   22.093913] pcieport 0000:00:03.0: pciehp: pciehp_check_link_active: lnk_status = 11

(qemu) device_add e1000,bus=rp1,id=eth1
[   58.389527] pcieport 0000:00:03.0: pciehp: pending interrupts 0x0009 from Slot Status
[   58.391789] pcieport 0000:00:03.0: pciehp: Slot(1): Button press: will power on in 5 sec
[   58.394175] pcieport 0000:00:03.0: pciehp: pending interrupts 0x0010 from Slot Status
[   58.396365] pcieport 0000:00:03.0: pciehp: pciehp_set_indicators: SLOTCTRL 6c write cmd 2c0
[   58.398681] pcieport 0000:00:03.0: pciehp: pciehp_check_link_active: lnk_status = 2011
[   58.400871] pcieport 0000:00:03.0: pciehp: Slot(1): Card present
[   58.402542] pcieport 0000:00:03.0: pciehp: Slot(1): Link Up
[   58.404154] pcieport 0000:00:03.0: pciehp: pciehp_get_power_status: SLOTCTRL 6c value read 6f1
[   58.406627] pcieport 0000:00:03.0: pciehp: pending interrupts 0x0010 from Slot Status
[   58.408798] pcieport 0000:00:03.0: pciehp: pciehp_power_on_slot: SLOTCTRL 6c write cmd 0
[   58.411213] pcieport 0000:00:03.0: pciehp: pending interrupts 0x0010 from Slot Status
[   58.413386] pcieport 0000:00:03.0: pciehp: pciehp_set_indicators: SLOTCTRL 6c write cmd 200
[   59.523011] pcieport 0000:00:03.0: pciehp: pciehp_check_link_status: lnk_status = 2011
[   59.525256] pcieport 0000:00:03.0: pciehp: Device 0000:01:00.0 already exists at 0000:01:00, skipping hot-add
[   59.528139] pcieport 0000:00:03.0: pciehp: pending interrupts 0x0010 from Slot Status
[   59.530325] pcieport 0000:00:03.0: pciehp: pciehp_set_indicators: SLOTCTRL 6c write cmd 1c0

  reply	other threads:[~2024-05-04 10:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-03 19:23 [PATCH 0/4] check returned value of pci_hp_add_bridge() Nam Cao
2024-05-03 19:23 ` [PATCH 1/4] PCI: shpchp: bail out if pci_hp_add_bridge() fails Nam Cao
2024-05-03 19:23 ` [PATCH 2/4] PCI: pciehp: " Nam Cao
2024-05-03 21:23   ` Bjorn Helgaas
2024-05-03 21:41     ` Nam Cao
2024-05-04  8:54   ` Lukas Wunner
2024-05-04  9:35     ` Nam Cao
2024-05-04  9:51       ` Lukas Wunner
2024-05-04 10:56         ` Nam Cao [this message]
2024-05-04 15:02           ` Lukas Wunner
2024-05-04 15:48             ` Nam Cao
2024-05-03 19:23 ` [PATCH 3/4] PCI: hotplug: document unchecked return value of pci_hp_add_bridge() Nam Cao
2024-05-03 19:23 ` [PATCH 4/4] PCI: hotplug: remove TODO notes for sgi_hotplug Nam Cao
2024-05-03 21:29 ` [PATCH 0/4] check returned value of pci_hp_add_bridge() 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=20240504105630.DPSzrgHe@linutronix.de \
    --to=namcao@linutronix.de \
    --cc=bhelgaas@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=rajesh.shah@intel.com \
    --cc=stable@vger.kernel.org \
    --cc=yinghai@kernel.org \
    /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).