Thomas Zimmermann c8f8ee
From 5ec0a6fcb60ea430f8ee7e0bec22db9b22f856d3 Mon Sep 17 00:00:00 2001
Thomas Zimmermann c8f8ee
From: Selvin Xavier <selvin.xavier@broadcom.com>
Thomas Zimmermann c8f8ee
Date: Sat, 11 Sep 2021 03:03:05 -0700
Thomas Zimmermann c8f8ee
Subject: PCI: Do not enable AtomicOps on VFs
Thomas Zimmermann c8f8ee
Git-commit: 5ec0a6fcb60ea430f8ee7e0bec22db9b22f856d3
Thomas Zimmermann c8f8ee
Patch-mainline: v5.16-rc1
Thomas Zimmermann c8f8ee
References: bsc#1129770
Thomas Zimmermann c8f8ee
Thomas Zimmermann c8f8ee
Host crashes when pci_enable_atomic_ops_to_root() is called for VFs with
Thomas Zimmermann c8f8ee
virtual buses. The virtual buses added to SR-IOV have bus->self set to NULL
Thomas Zimmermann c8f8ee
and host crashes due to this.
Thomas Zimmermann c8f8ee
Thomas Zimmermann c8f8ee
  PID: 4481   TASK: ffff89c6941b0000  CPU: 53  COMMAND: "bash"
Thomas Zimmermann c8f8ee
  ...
Thomas Zimmermann c8f8ee
   #3 [ffff9a9481713808] oops_end at ffffffffb9025cd6
Thomas Zimmermann c8f8ee
   #4 [ffff9a9481713828] page_fault_oops at ffffffffb906e417
Thomas Zimmermann c8f8ee
   #5 [ffff9a9481713888] exc_page_fault at ffffffffb9a0ad14
Thomas Zimmermann c8f8ee
   #6 [ffff9a94817138b0] asm_exc_page_fault at ffffffffb9c00ace
Thomas Zimmermann c8f8ee
      [exception RIP: pcie_capability_read_dword+28]
Thomas Zimmermann c8f8ee
      RIP: ffffffffb952fd5c  RSP: ffff9a9481713960  RFLAGS: 00010246
Thomas Zimmermann c8f8ee
      RAX: 0000000000000001  RBX: ffff89c6b1096000  RCX: 0000000000000000
Thomas Zimmermann c8f8ee
      RDX: ffff9a9481713990  RSI: 0000000000000024  RDI: 0000000000000000
Thomas Zimmermann c8f8ee
      RBP: 0000000000000080   R8: 0000000000000008   R9: ffff89c64341a2f8
Thomas Zimmermann c8f8ee
      R10: 0000000000000002  R11: 0000000000000000  R12: ffff89c648bab000
Thomas Zimmermann c8f8ee
      R13: 0000000000000000  R14: 0000000000000000  R15: ffff89c648bab0c8
Thomas Zimmermann c8f8ee
      ORIG_RAX: ffffffffffffffff  CS: 0010  SS: 0018
Thomas Zimmermann c8f8ee
   #7 [ffff9a9481713988] pci_enable_atomic_ops_to_root at ffffffffb95359a6
Thomas Zimmermann c8f8ee
   #8 [ffff9a94817139c0] bnxt_qplib_determine_atomics at ffffffffc08c1a33 [bnxt_re]
Thomas Zimmermann c8f8ee
   #9 [ffff9a94817139d0] bnxt_re_dev_init at ffffffffc08ba2d1 [bnxt_re]
Thomas Zimmermann c8f8ee
Thomas Zimmermann c8f8ee
Per PCIe r5.0, sec 9.3.5.10, the AtomicOp Requester Enable bit in Device
Thomas Zimmermann c8f8ee
Control 2 is reserved for VFs.  The PF value applies to all associated VFs.
Thomas Zimmermann c8f8ee
Thomas Zimmermann c8f8ee
Return -EINVAL if pci_enable_atomic_ops_to_root() is called for a VF.
Thomas Zimmermann c8f8ee
Thomas Zimmermann c8f8ee
Link: https://lore.kernel.org/r/1631354585-16597-1-git-send-email-selvin.xavier@broadcom.com
Thomas Zimmermann c8f8ee
Fixes: 35f5ace5dea4 ("RDMA/bnxt_re: Enable global atomic ops if platform supports")
Thomas Zimmermann c8f8ee
Fixes: 430a23689dea ("PCI: Add pci_enable_atomic_ops_to_root()")
Thomas Zimmermann c8f8ee
Signed-off-by: Selvin Xavier <selvin.xavier@broadcom.com>
Thomas Zimmermann c8f8ee
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Thomas Zimmermann c8f8ee
Reviewed-by: Andy Gospodarek <gospo@broadcom.com>
Thomas Zimmermann c8f8ee
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Thomas Zimmermann c8f8ee
---
Thomas Zimmermann c8f8ee
 drivers/pci/pci.c | 8 ++++++++
Thomas Zimmermann c8f8ee
 1 file changed, 8 insertions(+)
Thomas Zimmermann c8f8ee
Thomas Zimmermann c8f8ee
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
Thomas Zimmermann c8f8ee
index c63598c1cdd85..e55d944ff30f1 100644
Thomas Zimmermann c8f8ee
--- a/drivers/pci/pci.c
Thomas Zimmermann c8f8ee
+++ b/drivers/pci/pci.c
Thomas Zimmermann c8f8ee
@@ -3719,6 +3719,14 @@ int pci_enable_atomic_ops_to_root(struct pci_dev *dev, u32 cap_mask)
Thomas Zimmermann c8f8ee
 	struct pci_dev *bridge;
Thomas Zimmermann c8f8ee
 	u32 cap, ctl2;
Thomas Zimmermann c8f8ee
 
Thomas Zimmermann c8f8ee
+	/*
Thomas Zimmermann c8f8ee
+	 * Per PCIe r5.0, sec 9.3.5.10, the AtomicOp Requester Enable bit
Thomas Zimmermann c8f8ee
+	 * in Device Control 2 is reserved in VFs and the PF value applies
Thomas Zimmermann c8f8ee
+	 * to all associated VFs.
Thomas Zimmermann c8f8ee
+	 */
Thomas Zimmermann c8f8ee
+	if (dev->is_virtfn)
Thomas Zimmermann c8f8ee
+		return -EINVAL;
Thomas Zimmermann c8f8ee
+
Thomas Zimmermann c8f8ee
 	if (!pci_is_pcie(dev))
Thomas Zimmermann c8f8ee
 		return -EINVAL;
Thomas Zimmermann c8f8ee
 
Thomas Zimmermann c8f8ee
-- 
Thomas Zimmermann c8f8ee
2.36.0
Thomas Zimmermann c8f8ee