Skip to contentSkip to conversation

powerpc/ioda/npu: Call skiboot's hot reset hook when disabling NPU2

PATCH Superseded Alexey Kardashevskiy 2 participants 13 messages Oct 2, 2018 – Oct 19, 2018 PowerPC

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 powerpc/ioda/npu: Call skiboot's hot reset hook when disabling NPU2

The skiboot firmware has a hot reset handler which fences the NVIDIA V100 GPU RAM on Witherspoons and makes accesses no-op instead of throwing HMIs:
https://github.com/open-power/skiboot/commit/fca2b2b839a67

Now we are going to pass V100 via VFIO which most certainly involves KVM guests which are often terminated without getting a chance to offline GPU RAM so we end up with a running machine with misconfigured memory. Accessing this memory produces hardware management interrupts (HMI) which bring the host down.

To suppress HMIs, this wires up this hot reset hook to vfio_pci_disable() via pci_disable_device() which switches NPU2 to a safe mode and prevents HMIs.

---
Changes:
v2:
* updated the commit log

---
 arch/powerpc/platforms/powernv/pci-ioda.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/powerpc/platforms/powernv/pci-ioda.c +10 -0
index cde7102..e37b9cc 100644
@@ -3688,6 +3688,15 @@ static void pnv_pci_release_device(struct pci_dev *pdev)
 		pnv_ioda_release_pe(pe);
 }
 
+static void pnv_npu_disable_device(struct pci_dev *pdev)
+{
+	struct eeh_dev *edev = pci_dev_to_eeh_dev(pdev);
+	struct eeh_pe *eehpe = edev ? edev->pe : NULL;
+
+	if (eehpe && eeh_ops && eeh_ops->reset)
+		eeh_ops->reset(eehpe, EEH_RESET_HOT);
+}
+
 static void pnv_pci_ioda_shutdown(struct pci_controller *hose)
 {
 	struct pnv_phb *phb = hose->private_data;
@@ -3732,6 +3741,7 @@ static const struct pci_controller_ops pnv_npu_ioda_controller_ops = {
 	.reset_secondary_bus	= pnv_pci_reset_secondary_bus,
 	.dma_set_mask		= pnv_npu_dma_set_mask,
 	.shutdown		= pnv_pci_ioda_shutdown,
+	.disable_device		= pnv_npu_disable_device,
 };
 
 static const struct pci_controller_ops pnv_npu_ocapi_ioda_controller_ops = {
Signature · 1 line
2.11.0
#1 lore raw

Ping?

Quoted 52 lines · Alexey Kardashevskiy

The skiboot firmware has a hot reset handler which fences the NVIDIA V100 GPU RAM on Witherspoons and makes accesses no-op instead of throwing HMIs:
https://github.com/open-power/skiboot/commit/fca2b2b839a67

Now we are going to pass V100 via VFIO which most certainly involves KVM guests which are often terminated without getting a chance to offline GPU RAM so we end up with a running machine with misconfigured memory. Accessing this memory produces hardware management interrupts (HMI) which bring the host down.

To suppress HMIs, this wires up this hot reset hook to vfio_pci_disable() via pci_disable_device() which switches NPU2 to a safe mode and prevents HMIs.

---
Changes:
v2:
* updated the commit log

---
 arch/powerpc/platforms/powernv/pci-ioda.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/powerpc/platforms/powernv/pci-ioda.c +10 -0
index cde7102..e37b9cc 100644
@@ -3688,6 +3688,15 @@ static void pnv_pci_release_device(struct pci_dev *pdev)
 		pnv_ioda_release_pe(pe);
 }
 
+static void pnv_npu_disable_device(struct pci_dev *pdev)
+{
+	struct eeh_dev *edev = pci_dev_to_eeh_dev(pdev);
+	struct eeh_pe *eehpe = edev ? edev->pe : NULL;
+
+	if (eehpe && eeh_ops && eeh_ops->reset)
+		eeh_ops->reset(eehpe, EEH_RESET_HOT);
+}
+
 static void pnv_pci_ioda_shutdown(struct pci_controller *hose)
 {
 	struct pnv_phb *phb = hose->private_data;
@@ -3732,6 +3741,7 @@ static const struct pci_controller_ops pnv_npu_ioda_controller_ops = {
 	.reset_secondary_bus	= pnv_pci_reset_secondary_bus,
 	.dma_set_mask		= pnv_npu_dma_set_mask,
 	.shutdown		= pnv_pci_ioda_shutdown,
+	.disable_device		= pnv_npu_disable_device,
 };
 
 static const struct pci_controller_ops pnv_npu_ocapi_ioda_controller_ops = {
Signature · 1 line
Alexey
#2 lore raw

Hi Alexey,

Looking at the skiboot side I think we only fence the NVLink bricks as part of a PCIe function level reset (FLR) rather than a PCI Hot or Fundamental reset which I believe is what the code here does. So to fence the bricks you would need to do either a FLR on the given link or alter Skiboot to fence a given link as part of a hot reset.

- Alistair

Quoted 58 lines · AEDT Alexey Kardashevskiy

Ping?

Quoted 52 lines · Alexey Kardashevskiy

The skiboot firmware has a hot reset handler which fences the NVIDIA V100 GPU RAM on Witherspoons and makes accesses no-op instead of throwing HMIs:
https://github.com/open-power/skiboot/commit/fca2b2b839a67

Now we are going to pass V100 via VFIO which most certainly involves KVM guests which are often terminated without getting a chance to offline GPU RAM so we end up with a running machine with misconfigured memory. Accessing this memory produces hardware management interrupts (HMI) which bring the host down.

To suppress HMIs, this wires up this hot reset hook to vfio_pci_disable() via pci_disable_device() which switches NPU2 to a safe mode and prevents HMIs.

---
Changes:
v2:
* updated the commit log

---
 arch/powerpc/platforms/powernv/pci-ioda.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/powerpc/platforms/powernv/pci-ioda.c +10 -0
index cde7102..e37b9cc 100644
@@ -3688,6 +3688,15 @@ static void pnv_pci_release_device(struct pci_dev *pdev)
 		pnv_ioda_release_pe(pe);
 }
 
+static void pnv_npu_disable_device(struct pci_dev *pdev)
+{
+	struct eeh_dev *edev = pci_dev_to_eeh_dev(pdev);
+	struct eeh_pe *eehpe = edev ? edev->pe : NULL;
+
+	if (eehpe && eeh_ops && eeh_ops->reset)
+		eeh_ops->reset(eehpe, EEH_RESET_HOT);
+}
+
 static void pnv_pci_ioda_shutdown(struct pci_controller *hose)
 {
 	struct pnv_phb *phb = hose->private_data;
@@ -3732,6 +3741,7 @@ static const struct pci_controller_ops pnv_npu_ioda_controller_ops = {
 	.reset_secondary_bus	= pnv_pci_reset_secondary_bus,
 	.dma_set_mask		= pnv_npu_dma_set_mask,
 	.shutdown		= pnv_pci_ioda_shutdown,
+	.disable_device		= pnv_npu_disable_device,
 };
 
 static const struct pci_controller_ops pnv_npu_ocapi_ioda_controller_ops = {
#3 lore raw
Quoted 7 lines · Alistair Popple

Hi Alexey,

Looking at the skiboot side I think we only fence the NVLink bricks as part of a PCIe function level reset (FLR) rather than a PCI Hot or Fundamental reset which I believe is what the code here does. So to fence the bricks you would need to do either a FLR on the given link or alter Skiboot to fence a given link as part of a hot reset.

The code here calls OPAL to execute this code:

https://github.com/open-power/skiboot/commit/fca2b2b839a673a1e52fc6b19ee6d33b2dfbc003

This resets all links on an NPU which is fine for now as we pass GPUs in groups only. Or I missed something?

Quoted 64 lines

- Alistair

Quoted 58 lines · AEDT Alexey Kardashevskiy

Ping?

Quoted 52 lines · Alexey Kardashevskiy

The skiboot firmware has a hot reset handler which fences the NVIDIA V100 GPU RAM on Witherspoons and makes accesses no-op instead of throwing HMIs:
https://github.com/open-power/skiboot/commit/fca2b2b839a67

Now we are going to pass V100 via VFIO which most certainly involves KVM guests which are often terminated without getting a chance to offline GPU RAM so we end up with a running machine with misconfigured memory. Accessing this memory produces hardware management interrupts (HMI) which bring the host down.

To suppress HMIs, this wires up this hot reset hook to vfio_pci_disable() via pci_disable_device() which switches NPU2 to a safe mode and prevents HMIs.

---
Changes:
v2:
* updated the commit log

---
 arch/powerpc/platforms/powernv/pci-ioda.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/powerpc/platforms/powernv/pci-ioda.c +10 -0
index cde7102..e37b9cc 100644
@@ -3688,6 +3688,15 @@ static void pnv_pci_release_device(struct pci_dev *pdev)
 		pnv_ioda_release_pe(pe);
 }
 
+static void pnv_npu_disable_device(struct pci_dev *pdev)
+{
+	struct eeh_dev *edev = pci_dev_to_eeh_dev(pdev);
+	struct eeh_pe *eehpe = edev ? edev->pe : NULL;
+
+	if (eehpe && eeh_ops && eeh_ops->reset)
+		eeh_ops->reset(eehpe, EEH_RESET_HOT);
+}
+
 static void pnv_pci_ioda_shutdown(struct pci_controller *hose)
 {
 	struct pnv_phb *phb = hose->private_data;
@@ -3732,6 +3741,7 @@ static const struct pci_controller_ops pnv_npu_ioda_controller_ops = {
 	.reset_secondary_bus	= pnv_pci_reset_secondary_bus,
 	.dma_set_mask		= pnv_npu_dma_set_mask,
 	.shutdown		= pnv_pci_ioda_shutdown,
+	.disable_device		= pnv_npu_disable_device,
 };
 
 static const struct pci_controller_ops pnv_npu_ocapi_ioda_controller_ops = {
Signature · 1 line
Alexey
#4 lore raw

Hi Alexey,

Quoted 10 lines · AEDT Alexey Kardashevskiy
Quoted 7 lines · Alistair Popple

Hi Alexey,

Looking at the skiboot side I think we only fence the NVLink bricks as part of a PCIe function level reset (FLR) rather than a PCI Hot or Fundamental reset which I believe is what the code here does. So to fence the bricks you would need to do either a FLR on the given link or alter Skiboot to fence a given link as part of a hot reset.

Quoted 6 lines

The code here calls OPAL to execute this code:

https://github.com/open-power/skiboot/commit/fca2b2b839a673a1e52fc6b19ee6d33b2dfbc003

This resets all links on an NPU which is fine for now as we pass GPUs in groups only. Or I missed something?

From what I can see in
https://github.com/open-power/skiboot/commit/2947eaa14e771e572d4e84bf003318c590c1c7d4
we only fence the bricks in npu2_dev_procedure_reset()
(https://github.com/open-power/skiboot/blob/master/hw/npu2-hw-procedures.c#L937)
which itself is only called from the FLR path and not the code path you point out above.

The code path above only resets the NTL which I don't believe is sufficient to prevent HMIs.

- Alistair

Quoted 69 lines
Quoted 67 lines

- Alistair

Quoted 58 lines · AEDT Alexey Kardashevskiy

Ping?

Quoted 52 lines · Alexey Kardashevskiy

The skiboot firmware has a hot reset handler which fences the NVIDIA V100 GPU RAM on Witherspoons and makes accesses no-op instead of throwing HMIs:
https://github.com/open-power/skiboot/commit/fca2b2b839a67

Now we are going to pass V100 via VFIO which most certainly involves KVM guests which are often terminated without getting a chance to offline GPU RAM so we end up with a running machine with misconfigured memory. Accessing this memory produces hardware management interrupts (HMI) which bring the host down.

To suppress HMIs, this wires up this hot reset hook to vfio_pci_disable() via pci_disable_device() which switches NPU2 to a safe mode and prevents HMIs.

---
Changes:
v2:
* updated the commit log

---
 arch/powerpc/platforms/powernv/pci-ioda.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/powerpc/platforms/powernv/pci-ioda.c +10 -0
index cde7102..e37b9cc 100644
@@ -3688,6 +3688,15 @@ static void pnv_pci_release_device(struct pci_dev *pdev)
 		pnv_ioda_release_pe(pe);
 }
 
+static void pnv_npu_disable_device(struct pci_dev *pdev)
+{
+	struct eeh_dev *edev = pci_dev_to_eeh_dev(pdev);
+	struct eeh_pe *eehpe = edev ? edev->pe : NULL;
+
+	if (eehpe && eeh_ops && eeh_ops->reset)
+		eeh_ops->reset(eehpe, EEH_RESET_HOT);
+}
+
 static void pnv_pci_ioda_shutdown(struct pci_controller *hose)
 {
 	struct pnv_phb *phb = hose->private_data;
@@ -3732,6 +3741,7 @@ static const struct pci_controller_ops pnv_npu_ioda_controller_ops = {
 	.reset_secondary_bus	= pnv_pci_reset_secondary_bus,
 	.dma_set_mask		= pnv_npu_dma_set_mask,
 	.shutdown		= pnv_pci_ioda_shutdown,
+	.disable_device		= pnv_npu_disable_device,
 };
 
 static const struct pci_controller_ops pnv_npu_ocapi_ioda_controller_ops = {
#5 lore raw
Quoted 27 lines · Alistair Popple

Hi Alexey,

Quoted 10 lines · AEDT Alexey Kardashevskiy
Quoted 7 lines · Alistair Popple

Hi Alexey,

Looking at the skiboot side I think we only fence the NVLink bricks as part of a PCIe function level reset (FLR) rather than a PCI Hot or Fundamental reset which I believe is what the code here does. So to fence the bricks you would need to do either a FLR on the given link or alter Skiboot to fence a given link as part of a hot reset.

Quoted 6 lines

The code here calls OPAL to execute this code:

https://github.com/open-power/skiboot/commit/fca2b2b839a673a1e52fc6b19ee6d33b2dfbc003

This resets all links on an NPU which is fine for now as we pass GPUs in groups only. Or I missed something?

From what I can see in
https://github.com/open-power/skiboot/commit/2947eaa14e771e572d4e84bf003318c590c1c7d4
we only fence the bricks in npu2_dev_procedure_reset()
(https://github.com/open-power/skiboot/blob/master/hw/npu2-hw-procedures.c#L937)
which itself is only called from the FLR path and not the code path you point out above.

Quoted 2 lines

The code path above only resets the NTL which I don't believe is sufficient to prevent HMIs.

reset_ntl() does what npu2_dev_procedure_reset() does plus more stuff, there nothing really in npu2_dev_procedure_reset() which reset_ntl() does not do already from the hardware standpoint. And it did stop HMIs for me though.

but ok, what will be sufficient then if not reset_ntl()?

Quoted 74 lines

- Alistair

Quoted 69 lines
Quoted 67 lines

- Alistair

Quoted 58 lines · AEDT Alexey Kardashevskiy

Ping?

Quoted 52 lines · Alexey Kardashevskiy

The skiboot firmware has a hot reset handler which fences the NVIDIA V100 GPU RAM on Witherspoons and makes accesses no-op instead of throwing HMIs:
https://github.com/open-power/skiboot/commit/fca2b2b839a67

Now we are going to pass V100 via VFIO which most certainly involves KVM guests which are often terminated without getting a chance to offline GPU RAM so we end up with a running machine with misconfigured memory. Accessing this memory produces hardware management interrupts (HMI) which bring the host down.

To suppress HMIs, this wires up this hot reset hook to vfio_pci_disable() via pci_disable_device() which switches NPU2 to a safe mode and prevents HMIs.

---
Changes:
v2:
* updated the commit log

---
 arch/powerpc/platforms/powernv/pci-ioda.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/powerpc/platforms/powernv/pci-ioda.c +10 -0
index cde7102..e37b9cc 100644
@@ -3688,6 +3688,15 @@ static void pnv_pci_release_device(struct pci_dev *pdev)
 		pnv_ioda_release_pe(pe);
 }
 
+static void pnv_npu_disable_device(struct pci_dev *pdev)
+{
+	struct eeh_dev *edev = pci_dev_to_eeh_dev(pdev);
+	struct eeh_pe *eehpe = edev ? edev->pe : NULL;
+
+	if (eehpe && eeh_ops && eeh_ops->reset)
+		eeh_ops->reset(eehpe, EEH_RESET_HOT);
+}
+
 static void pnv_pci_ioda_shutdown(struct pci_controller *hose)
 {
 	struct pnv_phb *phb = hose->private_data;
@@ -3732,6 +3741,7 @@ static const struct pci_controller_ops pnv_npu_ioda_controller_ops = {
 	.reset_secondary_bus	= pnv_pci_reset_secondary_bus,
 	.dma_set_mask		= pnv_npu_dma_set_mask,
 	.shutdown		= pnv_pci_ioda_shutdown,
+	.disable_device		= pnv_npu_disable_device,
 };
 
 static const struct pci_controller_ops pnv_npu_ocapi_ioda_controller_ops = {
Signature · 1 line
Alexey
#6 lore raw
Quoted 6 lines

reset_ntl() does what npu2_dev_procedure_reset() does plus more stuff, there nothing really in npu2_dev_procedure_reset() which reset_ntl() does not do already from the hardware standpoint. And it did stop HMIs for me though.

but ok, what will be sufficient then if not reset_ntl()?

Argh, yes you are correct. Specifically both npu2_dev_procedure_reset() and reset_ntl() contain:

	/* NTL Reset */
	val = npu2_read(ndev->npu, NPU2_NTL_MISC_CFG1(ndev));
	val |= PPC_BIT(8) | PPC_BIT(9);
	npu2_write(ndev->npu, NPU2_NTL_MISC_CFG1(ndev), val);

Which should fence the brick. However from what I recall there was more to reliably preventing HMIs than merely fencing the brick. It invovled a sequence of fencing and flushing the cache with dcbf instructions at the right time which is why we also have the FLR. Unfortunately I don't know the precise details, perhaps if we send enough coffee Balbir's way he might be able remind us?

- Alistair

Quoted 78 lines
Quoted 76 lines

- Alistair

Quoted 69 lines
Quoted 67 lines

- Alistair

Quoted 58 lines · AEDT Alexey Kardashevskiy

Ping?

Quoted 52 lines · Alexey Kardashevskiy

The skiboot firmware has a hot reset handler which fences the NVIDIA V100 GPU RAM on Witherspoons and makes accesses no-op instead of throwing HMIs:
https://github.com/open-power/skiboot/commit/fca2b2b839a67

Now we are going to pass V100 via VFIO which most certainly involves KVM guests which are often terminated without getting a chance to offline GPU RAM so we end up with a running machine with misconfigured memory. Accessing this memory produces hardware management interrupts (HMI) which bring the host down.

To suppress HMIs, this wires up this hot reset hook to vfio_pci_disable() via pci_disable_device() which switches NPU2 to a safe mode and prevents HMIs.

---
Changes:
v2:
* updated the commit log

---
 arch/powerpc/platforms/powernv/pci-ioda.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/powerpc/platforms/powernv/pci-ioda.c +10 -0
index cde7102..e37b9cc 100644
@@ -3688,6 +3688,15 @@ static void pnv_pci_release_device(struct pci_dev *pdev)
 		pnv_ioda_release_pe(pe);
 }
 
+static void pnv_npu_disable_device(struct pci_dev *pdev)
+{
+	struct eeh_dev *edev = pci_dev_to_eeh_dev(pdev);
+	struct eeh_pe *eehpe = edev ? edev->pe : NULL;
+
+	if (eehpe && eeh_ops && eeh_ops->reset)
+		eeh_ops->reset(eehpe, EEH_RESET_HOT);
+}
+
 static void pnv_pci_ioda_shutdown(struct pci_controller *hose)
 {
 	struct pnv_phb *phb = hose->private_data;
@@ -3732,6 +3741,7 @@ static const struct pci_controller_ops pnv_npu_ioda_controller_ops = {
 	.reset_secondary_bus	= pnv_pci_reset_secondary_bus,
 	.dma_set_mask		= pnv_npu_dma_set_mask,
 	.shutdown		= pnv_pci_ioda_shutdown,
+	.disable_device		= pnv_npu_disable_device,
 };
 
 static const struct pci_controller_ops pnv_npu_ocapi_ioda_controller_ops = {
#7 lore raw
Quoted 15 lines · Alistair Popple
Quoted 6 lines

reset_ntl() does what npu2_dev_procedure_reset() does plus more stuff, there nothing really in npu2_dev_procedure_reset() which reset_ntl() does not do already from the hardware standpoint. And it did stop HMIs for me though.

but ok, what will be sufficient then if not reset_ntl()?

Argh, yes you are correct. Specifically both npu2_dev_procedure_reset() and reset_ntl() contain:

	/* NTL Reset */
	val = npu2_read(ndev->npu, NPU2_NTL_MISC_CFG1(ndev));
	val |= PPC_BIT(8) | PPC_BIT(9);
	npu2_write(ndev->npu, NPU2_NTL_MISC_CFG1(ndev), val);
Quoted 5 lines

Which should fence the brick. However from what I recall there was more to reliably preventing HMIs than merely fencing the brick. It invovled a sequence of fencing and flushing the cache with dcbf instructions at the right time which is why we also have the FLR. Unfortunately I don't know the precise details, perhaps if we send enough coffee Balbir's way he might be able remind us?

He suggested and ack'ed that skiboot patch, I can repeat beers^wcoffee but it won't change much ;)

Quoted 83 lines

- Alistair

Quoted 78 lines
Quoted 76 lines

- Alistair

Quoted 69 lines
Quoted 67 lines

- Alistair

Quoted 58 lines · AEDT Alexey Kardashevskiy

Ping?

Quoted 52 lines · Alexey Kardashevskiy

The skiboot firmware has a hot reset handler which fences the NVIDIA V100 GPU RAM on Witherspoons and makes accesses no-op instead of throwing HMIs:
https://github.com/open-power/skiboot/commit/fca2b2b839a67

Now we are going to pass V100 via VFIO which most certainly involves KVM guests which are often terminated without getting a chance to offline GPU RAM so we end up with a running machine with misconfigured memory. Accessing this memory produces hardware management interrupts (HMI) which bring the host down.

To suppress HMIs, this wires up this hot reset hook to vfio_pci_disable() via pci_disable_device() which switches NPU2 to a safe mode and prevents HMIs.

---
Changes:
v2:
* updated the commit log

---
 arch/powerpc/platforms/powernv/pci-ioda.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/powerpc/platforms/powernv/pci-ioda.c +10 -0
index cde7102..e37b9cc 100644
@@ -3688,6 +3688,15 @@ static void pnv_pci_release_device(struct pci_dev *pdev)
 		pnv_ioda_release_pe(pe);
 }
 
+static void pnv_npu_disable_device(struct pci_dev *pdev)
+{
+	struct eeh_dev *edev = pci_dev_to_eeh_dev(pdev);
+	struct eeh_pe *eehpe = edev ? edev->pe : NULL;
+
+	if (eehpe && eeh_ops && eeh_ops->reset)
+		eeh_ops->reset(eehpe, EEH_RESET_HOT);
+}
+
 static void pnv_pci_ioda_shutdown(struct pci_controller *hose)
 {
 	struct pnv_phb *phb = hose->private_data;
@@ -3732,6 +3741,7 @@ static const struct pci_controller_ops pnv_npu_ioda_controller_ops = {
 	.reset_secondary_bus	= pnv_pci_reset_secondary_bus,
 	.dma_set_mask		= pnv_npu_dma_set_mask,
 	.shutdown		= pnv_pci_ioda_shutdown,
+	.disable_device		= pnv_npu_disable_device,
 };
 
 static const struct pci_controller_ops pnv_npu_ocapi_ioda_controller_ops = {
Signature · 1 line
Alexey
#8 lore raw
Quoted 24 lines · AEDT Alexey Kardashevskiy
Quoted 15 lines · Alistair Popple
Quoted 6 lines

reset_ntl() does what npu2_dev_procedure_reset() does plus more stuff, there nothing really in npu2_dev_procedure_reset() which reset_ntl() does not do already from the hardware standpoint. And it did stop HMIs for me though.

but ok, what will be sufficient then if not reset_ntl()?

Argh, yes you are correct. Specifically both npu2_dev_procedure_reset() and reset_ntl() contain:

	/* NTL Reset */
	val = npu2_read(ndev->npu, NPU2_NTL_MISC_CFG1(ndev));
	val |= PPC_BIT(8) | PPC_BIT(9);
	npu2_write(ndev->npu, NPU2_NTL_MISC_CFG1(ndev), val);
Quoted 5 lines

Which should fence the brick. However from what I recall there was more to reliably preventing HMIs than merely fencing the brick. It invovled a sequence of fencing and flushing the cache with dcbf instructions at the right time which is why we also have the FLR. Unfortunately I don't know the precise details, perhaps if we send enough coffee Balbir's way he might be able remind us?

Quoted 2 lines

He suggested and ack'ed that skiboot patch, I can repeat beers^wcoffee but it won't change much ;)

Ha. Couldn't hurt ;)

I was pretty sure flushing the caches was an important part of the sequence to avoid HMI's. I believe you are trying to deal with unexpected guest terminations which means the driver won't have a chance to flush the caches prior to termination so wouldn't you also need to do that somewhere? Unless the driver does it at startup?

- Alistair

Quoted 85 lines
Quoted 83 lines

- Alistair

Quoted 78 lines
Quoted 76 lines

- Alistair

Quoted 69 lines
Quoted 67 lines

- Alistair

Quoted 58 lines · AEDT Alexey Kardashevskiy

Ping?

Quoted 52 lines · Alexey Kardashevskiy

The skiboot firmware has a hot reset handler which fences the NVIDIA V100 GPU RAM on Witherspoons and makes accesses no-op instead of throwing HMIs:
https://github.com/open-power/skiboot/commit/fca2b2b839a67

Now we are going to pass V100 via VFIO which most certainly involves KVM guests which are often terminated without getting a chance to offline GPU RAM so we end up with a running machine with misconfigured memory. Accessing this memory produces hardware management interrupts (HMI) which bring the host down.

To suppress HMIs, this wires up this hot reset hook to vfio_pci_disable() via pci_disable_device() which switches NPU2 to a safe mode and prevents HMIs.

---
Changes:
v2:
* updated the commit log

---
 arch/powerpc/platforms/powernv/pci-ioda.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/powerpc/platforms/powernv/pci-ioda.c +10 -0
index cde7102..e37b9cc 100644
@@ -3688,6 +3688,15 @@ static void pnv_pci_release_device(struct pci_dev *pdev)
 		pnv_ioda_release_pe(pe);
 }
 
+static void pnv_npu_disable_device(struct pci_dev *pdev)
+{
+	struct eeh_dev *edev = pci_dev_to_eeh_dev(pdev);
+	struct eeh_pe *eehpe = edev ? edev->pe : NULL;
+
+	if (eehpe && eeh_ops && eeh_ops->reset)
+		eeh_ops->reset(eehpe, EEH_RESET_HOT);
+}
+
 static void pnv_pci_ioda_shutdown(struct pci_controller *hose)
 {
 	struct pnv_phb *phb = hose->private_data;
@@ -3732,6 +3741,7 @@ static const struct pci_controller_ops pnv_npu_ioda_controller_ops = {
 	.reset_secondary_bus	= pnv_pci_reset_secondary_bus,
 	.dma_set_mask		= pnv_npu_dma_set_mask,
 	.shutdown		= pnv_pci_ioda_shutdown,
+	.disable_device		= pnv_npu_disable_device,
 };
 
 static const struct pci_controller_ops pnv_npu_ocapi_ioda_controller_ops = {
#9 lore raw
Quoted 28 lines · Alistair Popple
Quoted 24 lines · AEDT Alexey Kardashevskiy
Quoted 15 lines · Alistair Popple
Quoted 6 lines

reset_ntl() does what npu2_dev_procedure_reset() does plus more stuff, there nothing really in npu2_dev_procedure_reset() which reset_ntl() does not do already from the hardware standpoint. And it did stop HMIs for me though.

but ok, what will be sufficient then if not reset_ntl()?

Argh, yes you are correct. Specifically both npu2_dev_procedure_reset() and reset_ntl() contain:

	/* NTL Reset */
	val = npu2_read(ndev->npu, NPU2_NTL_MISC_CFG1(ndev));
	val |= PPC_BIT(8) | PPC_BIT(9);
	npu2_write(ndev->npu, NPU2_NTL_MISC_CFG1(ndev), val);
Quoted 5 lines

Which should fence the brick. However from what I recall there was more to reliably preventing HMIs than merely fencing the brick. It invovled a sequence of fencing and flushing the cache with dcbf instructions at the right time which is why we also have the FLR. Unfortunately I don't know the precise details, perhaps if we send enough coffee Balbir's way he might be able remind us?

Quoted 2 lines

He suggested and ack'ed that skiboot patch, I can repeat beers^wcoffee but it won't change much ;)

Quoted 6 lines

Ha. Couldn't hurt ;)

I was pretty sure flushing the caches was an important part of the sequence to avoid HMI's. I believe you are trying to deal with unexpected guest terminations which means the driver won't have a chance to flush the caches prior to termination so

Correct.

Quoted 2 lines

wouldn't you also need to do that somewhere? Unless the driver does it at startup?

VFIO performs GPU reset so I'd expect the GPUs to flush its caches without any software interactions. Am I hoping for too much here?

Quoted 90 lines

- Alistair

Quoted 85 lines
Quoted 83 lines

- Alistair

Quoted 78 lines
Quoted 76 lines

- Alistair

Quoted 69 lines
Quoted 67 lines

- Alistair

Quoted 58 lines · AEDT Alexey Kardashevskiy

Ping?

Quoted 52 lines · Alexey Kardashevskiy

The skiboot firmware has a hot reset handler which fences the NVIDIA V100 GPU RAM on Witherspoons and makes accesses no-op instead of throwing HMIs:
https://github.com/open-power/skiboot/commit/fca2b2b839a67

Now we are going to pass V100 via VFIO which most certainly involves KVM guests which are often terminated without getting a chance to offline GPU RAM so we end up with a running machine with misconfigured memory. Accessing this memory produces hardware management interrupts (HMI) which bring the host down.

To suppress HMIs, this wires up this hot reset hook to vfio_pci_disable() via pci_disable_device() which switches NPU2 to a safe mode and prevents HMIs.

---
Changes:
v2:
* updated the commit log

---
 arch/powerpc/platforms/powernv/pci-ioda.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/powerpc/platforms/powernv/pci-ioda.c +10 -0
index cde7102..e37b9cc 100644
@@ -3688,6 +3688,15 @@ static void pnv_pci_release_device(struct pci_dev *pdev)
 		pnv_ioda_release_pe(pe);
 }
 
+static void pnv_npu_disable_device(struct pci_dev *pdev)
+{
+	struct eeh_dev *edev = pci_dev_to_eeh_dev(pdev);
+	struct eeh_pe *eehpe = edev ? edev->pe : NULL;
+
+	if (eehpe && eeh_ops && eeh_ops->reset)
+		eeh_ops->reset(eehpe, EEH_RESET_HOT);
+}
+
 static void pnv_pci_ioda_shutdown(struct pci_controller *hose)
 {
 	struct pnv_phb *phb = hose->private_data;
@@ -3732,6 +3741,7 @@ static const struct pci_controller_ops pnv_npu_ioda_controller_ops = {
 	.reset_secondary_bus	= pnv_pci_reset_secondary_bus,
 	.dma_set_mask		= pnv_npu_dma_set_mask,
 	.shutdown		= pnv_pci_ioda_shutdown,
+	.disable_device		= pnv_npu_disable_device,
 };
 
 static const struct pci_controller_ops pnv_npu_ocapi_ioda_controller_ops = {
Signature · 1 line
Alexey
#10 lore raw

Hi Alexey,

Quoted 5 lines
Quoted 2 lines

wouldn't you also need to do that somewhere? Unless the driver does it at startup?

VFIO performs GPU reset so I'd expect the GPUs to flush its caches without any software interactions. Am I hoping for too much here?

Sadly you are. It's not the GPU caches that need flushing, it's the CPU caches. This needs to happen as part of the reset sequence, so I guess you would need to add it to the VFIO driver.

- Alistair

Quoted 10 lines
Quoted 10 lines

- Alistair

Quoted 7 lines
Quoted 7 lines

- Alistair

Quoted 5 lines
Quoted 5 lines

- Alistair

Quoted 3 lines
Quoted 3 lines

- Alistair

On Monday, 15 October 2018 6:17:51 PM AEDT Alexey Kardashevskiy

Quoted 73 lines · wrote:
Quoted 73 lines
Quoted 73 lines
Quoted 73 lines
Quoted 73 lines
Quoted 73 lines
Quoted 73 lines
Quoted 73 lines
Quoted 73 lines

Ping?

Quoted 70 lines · Alexey Kardashevskiy

The skiboot firmware has a hot reset handler which fences the NVIDIA V100
GPU RAM on Witherspoons and makes accesses no-op instead of throwing HMIs:
https://github.com/open-power/skiboot/commit/fca2b2b839a67

Now we are going to pass V100 via VFIO which most certainly involves
KVM guests which are often terminated without getting a chance to offline
GPU RAM so we end up with a running machine with misconfigured memory.
Accessing this memory produces hardware management interrupts (HMI)
which bring the host down.

To suppress HMIs, this wires up this hot reset hook to vfio_pci_disable()
via pci_disable_device() which switches NPU2 to a safe mode and prevents
HMIs.

---
Changes:
v2:
* updated the commit log
---

 arch/powerpc/platforms/powernv/pci-ioda.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
(quoted diff) +0 -0

b/arch/powerpc/platforms/powernv/pci-ioda.c index
cde7102..e37b9cc 100644

arch/powerpc/platforms/powernv/pci-ioda.c +0 -0
@@ -3688,6 +3688,15 @@ static void pnv_pci_release_device(struct

pci_dev *pdev)>>>>>>>>>

arch/powerpc/platforms/powernv/pci-ioda.c +9 -0
 		pnv_ioda_release_pe(pe);
 
 }
 
+static void pnv_npu_disable_device(struct pci_dev *pdev)
+{
+	struct eeh_dev *edev = pci_dev_to_eeh_dev(pdev);
+	struct eeh_pe *eehpe = edev ? edev->pe : NULL;
+
+	if (eehpe && eeh_ops && eeh_ops->reset)
+		eeh_ops->reset(eehpe, EEH_RESET_HOT);
+}
+
 
 static void pnv_pci_ioda_shutdown(struct pci_controller *hose)
 {
 
 	struct pnv_phb *phb = hose->private_data;
@@ -3732,6 +3741,7 @@ static const struct pci_controller_ops

pnv_npu_ioda_controller_ops = {>>>>>>>>>

arch/powerpc/platforms/powernv/pci-ioda.c +1 -0
 	.reset_secondary_bus	= pnv_pci_reset_secondary_bus,
 	.dma_set_mask		= pnv_npu_dma_set_mask,
 	.shutdown		= pnv_pci_ioda_shutdown,
 
+	.disable_device		= pnv_npu_disable_device,
 
 };
 
 static const struct pci_controller_ops
 pnv_npu_ocapi_ioda_controller_ops = {
#11 lore raw
Quoted 11 lines · Alistair Popple

Hi Alexey,

Quoted 5 lines
Quoted 2 lines

wouldn't you also need to do that somewhere? Unless the driver does it at startup?

VFIO performs GPU reset so I'd expect the GPUs to flush its caches without any software interactions. Am I hoping for too much here?

Sadly you are. It's not the GPU caches that need flushing, it's the CPU caches. This needs to happen as part of the reset sequence, so I guess you would need to add it to the VFIO driver.

Well, ok. Caches need flushing, will look into this but this fencing is still needed, is not it?

Quoted 89 lines

- Alistair

Quoted 10 lines
Quoted 10 lines

- Alistair

Quoted 7 lines
Quoted 7 lines

- Alistair

Quoted 5 lines
Quoted 5 lines

- Alistair

Quoted 3 lines
Quoted 3 lines

- Alistair

On Monday, 15 October 2018 6:17:51 PM AEDT Alexey Kardashevskiy

Quoted 73 lines · wrote:
Quoted 73 lines
Quoted 73 lines
Quoted 73 lines
Quoted 73 lines
Quoted 73 lines
Quoted 73 lines
Quoted 73 lines
Quoted 73 lines

Ping?

Quoted 70 lines · Alexey Kardashevskiy

The skiboot firmware has a hot reset handler which fences the NVIDIA V100
GPU RAM on Witherspoons and makes accesses no-op instead of throwing HMIs:
https://github.com/open-power/skiboot/commit/fca2b2b839a67

Now we are going to pass V100 via VFIO which most certainly involves
KVM guests which are often terminated without getting a chance to offline
GPU RAM so we end up with a running machine with misconfigured memory.
Accessing this memory produces hardware management interrupts (HMI)
which bring the host down.

To suppress HMIs, this wires up this hot reset hook to vfio_pci_disable()
via pci_disable_device() which switches NPU2 to a safe mode and prevents
HMIs.

---
Changes:
v2:
* updated the commit log
---

 arch/powerpc/platforms/powernv/pci-ioda.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
(quoted diff) +0 -0

b/arch/powerpc/platforms/powernv/pci-ioda.c index
cde7102..e37b9cc 100644

arch/powerpc/platforms/powernv/pci-ioda.c +0 -0
@@ -3688,6 +3688,15 @@ static void pnv_pci_release_device(struct

pci_dev *pdev)>>>>>>>>>

arch/powerpc/platforms/powernv/pci-ioda.c +9 -0
 		pnv_ioda_release_pe(pe);
 
 }
 
+static void pnv_npu_disable_device(struct pci_dev *pdev)
+{
+	struct eeh_dev *edev = pci_dev_to_eeh_dev(pdev);
+	struct eeh_pe *eehpe = edev ? edev->pe : NULL;
+
+	if (eehpe && eeh_ops && eeh_ops->reset)
+		eeh_ops->reset(eehpe, EEH_RESET_HOT);
+}
+
 
 static void pnv_pci_ioda_shutdown(struct pci_controller *hose)
 {
 
 	struct pnv_phb *phb = hose->private_data;
@@ -3732,6 +3741,7 @@ static const struct pci_controller_ops

pnv_npu_ioda_controller_ops = {>>>>>>>>>

arch/powerpc/platforms/powernv/pci-ioda.c +1 -0
 	.reset_secondary_bus	= pnv_pci_reset_secondary_bus,
 	.dma_set_mask		= pnv_npu_dma_set_mask,
 	.shutdown		= pnv_pci_ioda_shutdown,
 
+	.disable_device		= pnv_npu_disable_device,
 
 };
 
 static const struct pci_controller_ops
 pnv_npu_ocapi_ioda_controller_ops = {
Signature · 1 line
Alexey
#12 lore raw
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

wouldn't you also need to do that somewhere? Unless the driver does it at startup?

VFIO performs GPU reset so I'd expect the GPUs to flush its caches without any software interactions. Am I hoping for too much here?

Quoted 6 lines
Quoted 3 lines

Sadly you are. It's not the GPU caches that need flushing, it's the CPU caches. This needs to happen as part of the reset sequence, so I guess you would need to add it to the VFIO driver.

Well, ok. Caches need flushing, will look into this but this fencing is still needed, is not it?

Yes. Although without the flushing I think you may get HMI's on any subsequent driver loads.

So from the point of view of what happens on the Skiboot/HW side this looks ok so long as all links on an NPU are assigned to the same guest (as this call resets every link on a given NPU).

Quoted 89 lines
Quoted 89 lines

- Alistair

Quoted 9 lines
Quoted 9 lines

- Alistair

Quoted 7 lines
Quoted 7 lines

- Alistair

Quoted 5 lines
Quoted 5 lines

- Alistair

Quoted 3 lines
Quoted 3 lines

- Alistair

On Monday, 15 October 2018 6:17:51 PM AEDT Alexey Kardashevskiy

Quoted 76 lines · wrote:
Quoted 76 lines
Quoted 76 lines
Quoted 76 lines
Quoted 76 lines
Quoted 76 lines
Quoted 76 lines
Quoted 76 lines
Quoted 76 lines

Ping?

Quoted 73 lines · Alexey Kardashevskiy

The skiboot firmware has a hot reset handler which fences the NVIDIA V100
GPU RAM on Witherspoons and makes accesses no-op instead of throwing HMIs:
https://github.com/open-power/skiboot/commit/fca2b2b839a67

Now we are going to pass V100 via VFIO which most certainly involves
KVM guests which are often terminated without getting a chance to
offline
GPU RAM so we end up with a running machine with misconfigured memory.
Accessing this memory produces hardware management interrupts (HMI)
which bring the host down.

To suppress HMIs, this wires up this hot reset hook to vfio_pci_disable()
via pci_disable_device() which switches NPU2 to a safe mode and prevents
HMIs.

---
Changes:
v2:
* updated the commit log
---

 arch/powerpc/platforms/powernv/pci-ioda.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
(quoted diff) +0 -0

b/arch/powerpc/platforms/powernv/pci-ioda.c index
cde7102..e37b9cc 100644

arch/powerpc/platforms/powernv/pci-ioda.c +0 -0
@@ -3688,6 +3688,15 @@ static void pnv_pci_release_device(struct

pci_dev *pdev)>>>>>>>>>

arch/powerpc/platforms/powernv/pci-ioda.c +9 -0
 		pnv_ioda_release_pe(pe);
 
 }
 
+static void pnv_npu_disable_device(struct pci_dev *pdev)
+{
+	struct eeh_dev *edev = pci_dev_to_eeh_dev(pdev);
+	struct eeh_pe *eehpe = edev ? edev->pe : NULL;
+
+	if (eehpe && eeh_ops && eeh_ops->reset)
+		eeh_ops->reset(eehpe, EEH_RESET_HOT);
+}
+
 
 static void pnv_pci_ioda_shutdown(struct pci_controller *hose)
 {
 
 	struct pnv_phb *phb = hose->private_data;
@@ -3732,6 +3741,7 @@ static const struct pci_controller_ops

pnv_npu_ioda_controller_ops = {>>>>>>>>>

arch/powerpc/platforms/powernv/pci-ioda.c +1 -0
 	.reset_secondary_bus	= pnv_pci_reset_secondary_bus,
 	.dma_set_mask		= pnv_npu_dma_set_mask,
 	.shutdown		= pnv_pci_ioda_shutdown,
 
+	.disable_device		= pnv_npu_disable_device,
 
 };
 
 static const struct pci_controller_ops
 pnv_npu_ocapi_ioda_controller_ops = {