[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 44/68] pcie_sriov: Reset SR-IOV extended capability
From: |
Michael S. Tsirkin |
Subject: |
[PULL 44/68] pcie_sriov: Reset SR-IOV extended capability |
Date: |
Tue, 12 Mar 2024 18:27:48 -0400 |
From: Akihiko Odaki <akihiko.odaki@daynix.com>
pcie_sriov_pf_disable_vfs() is called when resetting the PF, but it only
disables VFs and does not reset SR-IOV extended capability, leaking the
state and making the VF Enable register inconsistent with the actual
state.
Replace pcie_sriov_pf_disable_vfs() with pcie_sriov_pf_reset(), which
does not only disable VFs but also resets the capability.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Message-Id: <20240228-reuse-v8-3-282660281e60@daynix.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Sriram Yagnaraman <sriram.yagnaraman@ericsson.com>
---
include/hw/pci/pcie_sriov.h | 4 ++--
hw/net/igb.c | 2 +-
hw/nvme/ctrl.c | 2 +-
hw/pci/pcie_sriov.c | 26 ++++++++++++++++++--------
4 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/include/hw/pci/pcie_sriov.h b/include/hw/pci/pcie_sriov.h
index 095fb0c9ed..b77eb7bf58 100644
--- a/include/hw/pci/pcie_sriov.h
+++ b/include/hw/pci/pcie_sriov.h
@@ -58,8 +58,8 @@ void pcie_sriov_pf_add_sup_pgsize(PCIDevice *dev, uint16_t
opt_sup_pgsize);
void pcie_sriov_config_write(PCIDevice *dev, uint32_t address,
uint32_t val, int len);
-/* Reset SR/IOV VF Enable bit to unregister all VFs */
-void pcie_sriov_pf_disable_vfs(PCIDevice *dev);
+/* Reset SR/IOV */
+void pcie_sriov_pf_reset(PCIDevice *dev);
/* Get logical VF number of a VF - only valid for VFs */
uint16_t pcie_sriov_vf_number(PCIDevice *dev);
diff --git a/hw/net/igb.c b/hw/net/igb.c
index 0b5c31a58b..9345506f81 100644
--- a/hw/net/igb.c
+++ b/hw/net/igb.c
@@ -493,7 +493,7 @@ static void igb_qdev_reset_hold(Object *obj)
trace_e1000e_cb_qdev_reset_hold();
- pcie_sriov_pf_disable_vfs(d);
+ pcie_sriov_pf_reset(d);
igb_core_reset(&s->core);
}
diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 2860a9bed1..447c4de6fd 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -7116,7 +7116,7 @@ static void nvme_ctrl_reset(NvmeCtrl *n, NvmeResetType
rst)
}
if (rst != NVME_RESET_CONTROLLER) {
- pcie_sriov_pf_disable_vfs(pci_dev);
+ pcie_sriov_pf_reset(pci_dev);
}
}
diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c
index da209b7f47..51b66d1bb3 100644
--- a/hw/pci/pcie_sriov.c
+++ b/hw/pci/pcie_sriov.c
@@ -249,16 +249,26 @@ void pcie_sriov_config_write(PCIDevice *dev, uint32_t
address,
}
-/* Reset SR/IOV VF Enable bit to trigger an unregister of all VFs */
-void pcie_sriov_pf_disable_vfs(PCIDevice *dev)
+/* Reset SR/IOV */
+void pcie_sriov_pf_reset(PCIDevice *dev)
{
uint16_t sriov_cap = dev->exp.sriov_cap;
- if (sriov_cap) {
- uint32_t val = pci_get_byte(dev->config + sriov_cap + PCI_SRIOV_CTRL);
- if (val & PCI_SRIOV_CTRL_VFE) {
- val &= ~PCI_SRIOV_CTRL_VFE;
- pcie_sriov_config_write(dev, sriov_cap + PCI_SRIOV_CTRL, val, 1);
- }
+ if (!sriov_cap) {
+ return;
+ }
+
+ pci_set_word(dev->config + sriov_cap + PCI_SRIOV_CTRL, 0);
+ unregister_vfs(dev);
+
+ /*
+ * Default is to use 4K pages, software can modify it
+ * to any of the supported bits
+ */
+ pci_set_word(dev->config + sriov_cap + PCI_SRIOV_SYS_PGSIZE, 0x1);
+
+ for (uint16_t i = 0; i < PCI_NUM_REGIONS; i++) {
+ pci_set_quad(dev->config + sriov_cap + PCI_SRIOV_BAR + i * 4,
+ dev->exp.sriov_pf.vf_bar_type[i]);
}
}
--
MST
- [PULL 35/68] hw/mem/cxl_type3: Fix missing ERRP_GUARD() in ct3_realize(), (continued)
- [PULL 35/68] hw/mem/cxl_type3: Fix missing ERRP_GUARD() in ct3_realize(), Michael S. Tsirkin, 2024/03/12
- [PULL 37/68] hw/pci-bridge/cxl_upstream: Fix missing ERRP_GUARD() in cxl_usp_realize(), Michael S. Tsirkin, 2024/03/12
- [PULL 42/68] hw/nvme: Use pcie_sriov_num_vfs(), Michael S. Tsirkin, 2024/03/12
- [PULL 36/68] hw/misc/xlnx-versal-trng: Check returned bool in trng_prop_fault_event_set(), Michael S. Tsirkin, 2024/03/12
- [PULL 38/68] hw/vfio/iommufd: Fix missing ERRP_GUARD() in iommufd_cdev_getfd(), Michael S. Tsirkin, 2024/03/12
- [PULL 39/68] hw/intc: Check @errp to handle the error of IOAPICCommonClass.realize(), Michael S. Tsirkin, 2024/03/12
- [PULL 40/68] Implement base of SMBIOS type 9 descriptor., Michael S. Tsirkin, 2024/03/12
- [PULL 41/68] Implement SMBIOS type 9 v2.6, Michael S. Tsirkin, 2024/03/12
- [PULL 43/68] pcie_sriov: Validate NumVFs, Michael S. Tsirkin, 2024/03/12
- [PULL 48/68] Revert "hw/i386/pc_sysfw: Inline pc_system_flash_create() and remove it", Michael S. Tsirkin, 2024/03/12
- [PULL 44/68] pcie_sriov: Reset SR-IOV extended capability,
Michael S. Tsirkin <=
- [PULL 53/68] hw/i386/pc: Inline pc_cmos_init() into pc_cmos_init_late() and remove it, Michael S. Tsirkin, 2024/03/12
- [PULL 51/68] hw/i386/pc: Avoid one use of the current_machine global, Michael S. Tsirkin, 2024/03/12
- [PULL 46/68] hw/pci: Always call pcie_sriov_pf_reset(), Michael S. Tsirkin, 2024/03/12
- [PULL 45/68] pcie_sriov: Do not reset NumVFs after disabling VFs, Michael S. Tsirkin, 2024/03/12
- [PULL 47/68] pc: q35: Bump max_cpus to 4096 vcpus, Michael S. Tsirkin, 2024/03/12
- [PULL 49/68] Revert "hw/i386/pc: Confine system flash handling to pc_sysfw", Michael S. Tsirkin, 2024/03/12
- [PULL 50/68] hw/i386/pc: Remove "rtc_state" link again, Michael S. Tsirkin, 2024/03/12
- [PULL 52/68] hw/i386/pc: Set "normal" boot device order in pc_basic_device_init(), Michael S. Tsirkin, 2024/03/12
- [PULL 54/68] qom: new object to associate device to NUMA node, Michael S. Tsirkin, 2024/03/12
- [PULL 58/68] virtio-iommu: Change the default granule to the host page size, Michael S. Tsirkin, 2024/03/12