PCI: use reset_root_port() for bus reset of devices on a root bus
Subsystems (5)
PATCH 1/2 PCI: use reset_root_port() for bus reset of devices on a root bus
The "bus" reset method resets a device by asserting Secondary Bus Reset on its upstream bridge, so it is not available for a device on a root bus, which has no upstream bridge.
Some platforms have no Root Ports and expose PCI devices directly on a root bus, e.g., Hyper-V vPCI places each assigned PCI function directly on the root bus of a virtual host bridge. Such a device has no reset method at all if it supports neither FLR nor PM reset, even if the platform is able to reset it.
pci_host_bridge::reset_root_port() already allows a host bridge to reset a device on a root bus in a platform-specific way, so far only in place of a Secondary Bus Reset by a Root Port. Use it for the "bus" reset method of a device that is the only device on a root bus, and wait for the device to become ready afterwards, as is done for other reset methods.
--- drivers/pci/pci.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)
drivers/pci/pci.c +30 -2
@@ -4924,18 +4924,46 @@ int pci_bridge_secondary_bus_reset(struct pci_dev *dev) }EXPORT_SYMBOL_GPL (pci_bridge_secondary_bus_reset); +static int pci_root_bus_reset (struct pci_dev *dev,bool probe) +{ +struct pci_host_bridge *host =pci_find_host_bridge (dev->bus); +int rc; + +/* +* Bridges, e.g., Root Ports, are not eligible. Check the header type +* because dev->subordinate is not set up yet when the reset methods +* are probed during enumeration. +*/ +if (pci_is_bridge (dev) || !host->reset_root_port) +return -ENOTTY ; + +if (probe) +return 0 ; + + rc = host->reset_root_port (host, dev); +if (rc) +return rc; + +return pci_dev_wait (dev,"bus reset" ,PCIE_RESET_READY_POLL_MS ); +} +static int pci_parent_bus_reset (struct pci_dev *dev,bool probe) {struct pci_dev *pdev; -if (pci_is_root_bus (dev->bus) || dev->subordinate || - !dev->bus->self || dev->dev_flags &PCI_DEV_FLAGS_NO_BUS_RESET ) +if (dev->subordinate || dev->dev_flags &PCI_DEV_FLAGS_NO_BUS_RESET )return -ENOTTY ;list_for_each_entry (pdev, &dev->bus->devices, bus_list)if (pdev != dev)return -ENOTTY ; +if (pci_is_root_bus (dev->bus)) +return pci_root_bus_reset (dev, probe); + +if (!dev->bus->self) +return -ENOTTY ; +if (probe)return 0 ;
Signature · 1 line
2.56.0
PATCH 2/2 PCI: hv: add vPCI device reset support
Hyper-V vPCI protocol version 1.5 adds a RESET_DEVICE request for projected PCI functions. Negotiate the new protocol version and, when it is in use, implement the pci_host_bridge::reset_root_port() callback by issuing the request through the vPCI VMBus channel.
Hyper-V has no Root Ports and exposes projected functions directly on the root bus, so PCI core uses the callback for the "bus" reset method of a function that is the only one on its vPCI bus.
Use the existing VMBus response path. Return -ENOTTY when the host reports STATUS_NOT_SUPPORTED so PCI core may try another reset method.
--- Documentation/virt/hyperv/vpci.rst | 2 +- drivers/pci/controller/pci-hyperv.c | 54 +++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-)
Documentation/virt/hyperv/vpci.rst +1 -1
@@ -65,7 +65,7 @@ exchange messages with the vPCI VSP for the purpose of setting up and configuring the vPCI device in Linux. Once the device is fully configured in Linux as a PCI device, the VMBus channel is used only if Linux changes the vCPU to be interrupted -in the guest, or if the vPCI device is removed from +in the guest, or if the vPCI device is reset or removed from the VM while the VM is running. The ongoing operation of the device happens directly between the Linux device driver for the device and the hardware, with VMBus and the VMBus channel
drivers/pci/controller/pci-hyperv.c +54 -0
96 lines not on this page · raw message
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH 2/2] PCI: hv: add vPCI device reset support
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] PCI: hv: hv_pci_reset_device() passes 3 arguments to wait_for_response() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] PCI: hv: hv_pci_reset_device() passes 3 arguments to wait_for_response() --
commit 5767f2b6950e5dc7da0b5c142f971d8282c27a56
Author: Hamza Mahfooz <[email protected]>
PCI: hv: add vPCI device reset support
This commit negotiates Hyper-V vPCI protocol version 1.5 and implements the reset_root_port() callback on pci_host_bridge by sending a PCI_RESET_DEVICE request over the vPCI VMBus channel.
Quoted 4 lines
drivers/pci/controller/pci-hyperv.c +0
-0
[ ... ]
Quoted 25 lines
drivers/pci/controller/pci-hyperv.c +21
-0@@ -1397,6 +1401,52 @@ static int hv_pcifront_write_config(struct pci_bus *bus, unsigned int devfn,return PCIBIOS_SUCCESSFUL ; } +static int hv_pci_reset_device (struct pci_host_bridge *bridge, +struct pci_dev *pdev) +{ +struct hv_pcibus_device *hbus = + container_of(bridge->sysdata, struct hv_pcibus_device, sysdata); +struct pci_child_message reset = {}; +struct hv_pci_compl comp_pkt; +struct pci_packet pkt = { + .completion_func = hv_pci_generic_compl, + .compl_ctxt = &comp_pkt, + }; +enum hv_pcibus_state state; +int ret; + +/* Do not take state_lock: eject holds it while removing/locking pdev. */ + state =READ_ONCE (hbus->state); +if (state != hv_pcibus_probed && state != hv_pcibus_installed) +return -ENODEV ; + +init_completion (&comp_pkt.host_event); + reset.message_type.type =PCI_RESET_DEVICE ;
drivers/pci/controller/pci-hyperv.c static int hv_pcifront_write_config(struct pci_bus *bus, unsigned int devfn, · line 1434
Quoted 10 lines
drivers/pci/controller/pci-hyperv.c +10
-0+ reset.wslot.slot =devfn_to_wslot (pdev->devfn); + + ret =vmbus_sendpacket (hbus->hdev->channel, &reset,sizeof (reset), + (unsigned long )&pkt,VM_PKT_DATA_INBAND , +VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED ); +if (ret) +return ret; + + ret =wait_for_response (hbus->hdev, &comp_pkt.host_event, +"PCI_RESET_DEVICE" );
[Severity: Low]
Does this compile when CONFIG_PCI_HYPERV is enabled?
In drivers/pci/controller/pci-hyperv.c, wait_for_response() only accepts two arguments:
static int wait_for_response(struct hv_device *hdev,
struct completion *comp)
Passing "PCI_RESET_DEVICE" as a third argument in hv_pci_reset_device() causes the build to fail with too many arguments to wait_for_response().
Quoted 14 lines
drivers/pci/controller/pci-hyperv.c +14
-0+if (ret) +return ret; + +if (comp_pkt.completion_status ==STATUS_NOT_SUPPORTED ) +return -ENOTTY ; + +if (comp_pkt.completion_status) { +pci_err (pdev,"Hyper-V device reset failed: %#x\n" , + comp_pkt.completion_status); +return -EIO ; + } + +return 0 ; +}
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH 2/2] PCI: hv: add vPCI device reset support
Quoted 59 lines · On Sat, Oct 17, 2026 at 12:12:00AM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] PCI: hv:hv_pci_reset_device()passes 3 arguments towait_for_response()--commit
5767f2b6950e5dc7da0b5c142f971d8282c27a56
Author: Hamza Mahfooz <[email protected]>PCI: hv: add vPCI device reset support
This commit negotiates Hyper-V vPCI protocol version 1.5 and implements the
reset_root_port()callback onpci_host_bridgeby sending aPCI_RESET_DEVICErequest over the vPCI VMBus channel.Quoted 4 lines
drivers/pci/controller/pci-hyperv.c +0
-0[ ... ]
Quoted 25 lines
drivers/pci/controller/pci-hyperv.c +21
-0@@ -1397,6 +1401,52 @@ static int hv_pcifront_write_config(struct pci_bus *bus, unsigned int devfn,return PCIBIOS_SUCCESSFUL ; } +static int hv_pci_reset_device (struct pci_host_bridge *bridge, +struct pci_dev *pdev) +{ +struct hv_pcibus_device *hbus = + container_of(bridge->sysdata, struct hv_pcibus_device, sysdata); +struct pci_child_message reset = {}; +struct hv_pci_compl comp_pkt; +struct pci_packet pkt = { + .completion_func = hv_pci_generic_compl, + .compl_ctxt = &comp_pkt, + }; +enum hv_pcibus_state state; +int ret; + +/* Do not take state_lock: eject holds it while removing/locking pdev. */ + state =READ_ONCE (hbus->state); +if (state != hv_pcibus_probed && state != hv_pcibus_installed) +return -ENODEV ; + +init_completion (&comp_pkt.host_event); + reset.message_type.type =PCI_RESET_DEVICE ;drivers/pci/controller/pci-hyperv.c static int hv_pcifront_write_config(struct pci_bus *bus, unsigned int devfn, · line 1434
Quoted 10 lines
drivers/pci/controller/pci-hyperv.c +10
-0+ reset.wslot.slot =devfn_to_wslot (pdev->devfn); + + ret =vmbus_sendpacket (hbus->hdev->channel, &reset,sizeof (reset), + (unsigned long )&pkt,VM_PKT_DATA_INBAND , +VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED ); +if (ret) +return ret; + + ret =wait_for_response (hbus->hdev, &comp_pkt.host_event, +"PCI_RESET_DEVICE" );[Severity: Low]
Does this compile whenCONFIG_PCI_HYPERVis enabled?
Quoted 9 lines
In
drivers/pci/controller/pci-hyperv.c,wait_for_response()only accepts two arguments:static int wait_for_response(struct
hv_device*hdev,
struct completion *comp)Passing "
PCI_RESET_DEVICE" as a third argument inhv_pci_reset_device()causes the build to fail with too many arguments towait_for_response().
Not sure what tree this was applied to, but that function has 3 params as of mainline commit ca039df94983 ("PCI: hv: Warn when wait_for_response() waits indefinitely").
Quoted 19 lines
Quoted 14 lines
drivers/pci/controller/pci-hyperv.c +14
-0+if (ret) +return ret; + +if (comp_pkt.completion_status ==STATUS_NOT_SUPPORTED ) +return -ENOTTY ; + +if (comp_pkt.completion_status) { +pci_err (pdev,"Hyper-V device reset failed: %#x\n" , + comp_pkt.completion_status); +return -EIO ; + } + +return 0 ; +}[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Wei Liu
maintainerRe: [PATCH 2/2] PCI: hv: add vPCI device reset support
Quoted 66 lines · Hamza Mahfooz
Quoted 65 lines · On Sat, Oct 17, 2026 at 12:12:00AM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] PCI: hv:hv_pci_reset_device()passes 3 arguments towait_for_response()--commit
5767f2b6950e5dc7da0b5c142f971d8282c27a56
Author: Hamza Mahfooz <[email protected]>PCI: hv: add vPCI device reset support
This commit negotiates Hyper-V vPCI protocol version 1.5 and implements the
reset_root_port()callback onpci_host_bridgeby sending aPCI_RESET_DEVICErequest over the vPCI VMBus channel.Quoted 4 lines
drivers/pci/controller/pci-hyperv.c +0
-0[ ... ]
Quoted 25 lines
drivers/pci/controller/pci-hyperv.c +21
-0@@ -1397,6 +1401,52 @@ static int hv_pcifront_write_config(struct pci_bus *bus, unsigned int devfn,return PCIBIOS_SUCCESSFUL ; } +static int hv_pci_reset_device (struct pci_host_bridge *bridge, +struct pci_dev *pdev) +{ +struct hv_pcibus_device *hbus = + container_of(bridge->sysdata, struct hv_pcibus_device, sysdata); +struct pci_child_message reset = {}; +struct hv_pci_compl comp_pkt; +struct pci_packet pkt = { + .completion_func = hv_pci_generic_compl, + .compl_ctxt = &comp_pkt, + }; +enum hv_pcibus_state state; +int ret; + +/* Do not take state_lock: eject holds it while removing/locking pdev. */ + state =READ_ONCE (hbus->state); +if (state != hv_pcibus_probed && state != hv_pcibus_installed) +return -ENODEV ; + +init_completion (&comp_pkt.host_event); + reset.message_type.type =PCI_RESET_DEVICE ;drivers/pci/controller/pci-hyperv.c static int hv_pcifront_write_config(struct pci_bus *bus, unsigned int devfn, · line 1434
Quoted 10 lines
drivers/pci/controller/pci-hyperv.c +10
-0+ reset.wslot.slot =devfn_to_wslot (pdev->devfn); + + ret =vmbus_sendpacket (hbus->hdev->channel, &reset,sizeof (reset), + (unsigned long )&pkt,VM_PKT_DATA_INBAND , +VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED ); +if (ret) +return ret; + + ret =wait_for_response (hbus->hdev, &comp_pkt.host_event, +"PCI_RESET_DEVICE" );[Severity: Low]
Does this compile whenCONFIG_PCI_HYPERVis enabled?In
drivers/pci/controller/pci-hyperv.c,wait_for_response()only accepts two arguments:static int wait_for_response(struct
hv_device*hdev,
struct completion *comp)
Quoted 7 lines
Quoted 3 lines
Passing "
PCI_RESET_DEVICE" as a third argument inhv_pci_reset_device()causes the build to fail with too many arguments towait_for_response().Not sure what tree this was applied to, but that function has 3 params as of mainline commit
ca039df94983("PCI: hv: Warn whenwait_for_response()waits indefinitely").
The link ...
Quoted 2 lines
Quoted 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
... shows that it picked git.lwn.net/docs-next (90d9f76ccb72ec024ef476b4229f3dd1957d7b26).
It looks like it is hallucinating.
Wei
Re: [PATCH 2/2] PCI: hv: add vPCI device reset support
In reply to Hamza MahfoozQuoted 9 lines · Hamza Mahfooz
Hyper-V vPCI protocol version 1.5 adds a
RESET_DEVICErequest for projected PCI functions. Negotiate the new protocol version and, when it is in use, implement thepci_host_bridge::reset_root_port()callback by issuing the request through the vPCI VMBus channel.Hyper-V has no Root Ports and exposes projected functions directly on the root bus, so PCI core uses the callback for the "bus" reset method of a function that is the only one on its vPCI bus.
Quoted 6 lines
Use the existing VMBus response path. Return
-ENOTTYwhen the host reportsSTATUS_NOT_SUPPORTEDso PCI core may try another reset method.Co-developed-by Wei Liu <[email protected]>Signed-off-by Wei Liu <[email protected]>Signed-off-by Hamza Mahfooz <[email protected]>
- Mani
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 10 lines
The "bus" reset method resets a device by asserting Secondary Bus Reset on its upstream bridge, so it is not available for a device on a root bus, which has no upstream bridge.
Some platforms have no Root Ports and expose PCI devices directly on a root bus, e.g., Hyper-V vPCI places each assigned PCI function directly on the root bus of a virtual host bridge. Such a device has no reset method at all if it supports neither FLR nor PM reset, even if the platform is able to reset it.
Quoted 8 lines
pci_host_bridge::reset_root_port()already allows a host bridge to reset a device on a root bus in a platform-specific way, so far only in place of a Secondary Bus Reset by a Root Port. Use it for the "bus" reset method of a device that is the only device on a root bus, and wait for the device to become ready afterwards, as is done for other reset methods.Signed-off-by Hamza Mahfooz <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Hi Bjorn,
Quoted 10 lines · Hamza Mahfooz
The "bus" reset method resets a device by asserting Secondary Bus Reset on its upstream bridge, so it is not available for a device on a root bus, which has no upstream bridge.
Some platforms have no Root Ports and expose PCI devices directly on a root bus, e.g., Hyper-V vPCI places each assigned PCI function directly on the root bus of a virtual host bridge. Such a device has no reset method at all if it supports neither FLR nor PM reset, even if the platform is able to reset it.
Quoted 7 lines
pci_host_bridge::reset_root_port()already allows a host bridge to reset a device on a root bus in a platform-specific way, so far only in place of a Secondary Bus Reset by a Root Port. Use it for the "bus" reset method of a device that is the only device on a root bus, and wait for the device to become ready afterwards, as is done for other reset methods.
Do you have any comments regarding this patch? If not, do you mind if we take it though the hyperv tree?
Quoted 60 lines
Signed-off-by Hamza Mahfooz <[email protected]>--- drivers/pci/pci.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)drivers/pci/pci.c +30
-2@@ -4924,18 +4924,46 @@ int pci_bridge_secondary_bus_reset(struct pci_dev *dev) }EXPORT_SYMBOL_GPL (pci_bridge_secondary_bus_reset); +static int pci_root_bus_reset (struct pci_dev *dev,bool probe) +{ +struct pci_host_bridge *host =pci_find_host_bridge (dev->bus); +int rc; + +/* +* Bridges, e.g., Root Ports, are not eligible. Check the header type +* because dev->subordinate is not set up yet when the reset methods +* are probed during enumeration. +*/ +if (pci_is_bridge (dev) || !host->reset_root_port) +return -ENOTTY ; + +if (probe) +return 0 ; + + rc = host->reset_root_port (host, dev); +if (rc) +return rc; + +return pci_dev_wait (dev,"bus reset" ,PCIE_RESET_READY_POLL_MS ); +} +static int pci_parent_bus_reset (struct pci_dev *dev,bool probe) {struct pci_dev *pdev; -if (pci_is_root_bus (dev->bus) || dev->subordinate || - !dev->bus->self || dev->dev_flags &PCI_DEV_FLAGS_NO_BUS_RESET ) +if (dev->subordinate || dev->dev_flags &PCI_DEV_FLAGS_NO_BUS_RESET )return -ENOTTY ;list_for_each_entry (pdev, &dev->bus->devices, bus_list)if (pdev != dev)return -ENOTTY ; +if (pci_is_root_bus (dev->bus)) +return pci_root_bus_reset (dev, probe); + +if (!dev->bus->self) +return -ENOTTY ; +if (probe)return 0 ;Signature · 1 line
2.56.0
Quoted 10 lines · Hamza Mahfooz
The "bus" reset method resets a device by asserting Secondary Bus Reset on its upstream bridge, so it is not available for a device on a root bus, which has no upstream bridge.
Some platforms have no Root Ports and expose PCI devices directly on a root bus, e.g., Hyper-V vPCI places each assigned PCI function directly on the root bus of a virtual host bridge. Such a device has no reset method at all if it supports neither FLR nor PM reset, even if the platform is able to reset it.
Quoted 8 lines
pci_host_bridge::reset_root_port()already allows a host bridge to reset a device on a root bus in a platform-specific way, so far only in place of a Secondary Bus Reset by a Root Port. Use it for the "bus" reset method of a device that is the only device on a root bus, and wait for the device to become ready afterwards, as is done for other reset methods.Signed-off-by Hamza Mahfooz <[email protected]>
- Mani
Bjorn Helgaas
AppliedQuoted 10 lines · Hamza Mahfooz
The "bus" reset method resets a device by asserting Secondary Bus Reset on its upstream bridge, so it is not available for a device on a root bus, which has no upstream bridge.
Some platforms have no Root Ports and expose PCI devices directly on a root bus, e.g., Hyper-V vPCI places each assigned PCI function directly on the root bus of a virtual host bridge. Such a device has no reset method at all if it supports neither FLR nor PM reset, even if the platform is able to reset it.
Quoted 8 lines
pci_host_bridge::reset_root_port()already allows a host bridge to reset a device on a root bus in a platform-specific way, so far only in place of a Secondary Bus Reset by a Root Port. Use it for the "bus" reset method of a device that is the only device on a root bus, and wait for the device to become ready afterwards, as is done for other reset methods.Signed-off-by Hamza Mahfooz <[email protected]>
Applied both to pci/reset for v7.5, thanks!
Quoted 60 lines
--- drivers/pci/pci.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)drivers/pci/pci.c +30
-2@@ -4924,18 +4924,46 @@ int pci_bridge_secondary_bus_reset(struct pci_dev *dev) }EXPORT_SYMBOL_GPL (pci_bridge_secondary_bus_reset); +static int pci_root_bus_reset (struct pci_dev *dev,bool probe) +{ +struct pci_host_bridge *host =pci_find_host_bridge (dev->bus); +int rc; + +/* +* Bridges, e.g., Root Ports, are not eligible. Check the header type +* because dev->subordinate is not set up yet when the reset methods +* are probed during enumeration. +*/ +if (pci_is_bridge (dev) || !host->reset_root_port) +return -ENOTTY ; + +if (probe) +return 0 ; + + rc = host->reset_root_port (host, dev); +if (rc) +return rc; + +return pci_dev_wait (dev,"bus reset" ,PCIE_RESET_READY_POLL_MS ); +} +static int pci_parent_bus_reset (struct pci_dev *dev,bool probe) {struct pci_dev *pdev; -if (pci_is_root_bus (dev->bus) || dev->subordinate || - !dev->bus->self || dev->dev_flags &PCI_DEV_FLAGS_NO_BUS_RESET ) +if (dev->subordinate || dev->dev_flags &PCI_DEV_FLAGS_NO_BUS_RESET )return -ENOTTY ;list_for_each_entry (pdev, &dev->bus->devices, bus_list)if (pdev != dev)return -ENOTTY ; +if (pci_is_root_bus (dev->bus)) +return pci_root_bus_reset (dev, probe); + +if (!dev->bus->self) +return -ENOTTY ; +if (probe)return 0 ;Signature · 1 line
2.56.0