Skip to contentSkip to conversation

genirq/msi: Dynamic remove/add stroage adapter hits EEH

PATCH In review [email protected] 2 participants 9 messages Mar 19, 2025 – Apr 2, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 genirq/msi: Dynamic remove/add stroage adapter hits EEH

From: Wen Xiong <[email protected]>

When enable irqbalance daemon, Dynamic remove/add stroage adapter(Scsi IPR and FC Qlogic) test hits EEH on PPC.

EEH: [c00000000004f75c] __eeh_send_failure_event+0x7c/0x160
EEH: [c000000000048444] eeh_dev_check_failure.part.0+0x254/0x650
EEH: [c008000001650678] eeh_readl+0x60/0x90 [ipr]
EEH: [c00800000166746c] ipr_cancel_op+0x2b8/0x524 [ipr]
EEH: [c008000001656524] ipr_eh_abort+0x6c/0x130 [ipr]
EEH: [c000000000ab0d20] scmd_eh_abort_handler+0x140/0x440
EEH: [c00000000017e558] process_one_work+0x298/0x590
EEH: [c00000000017eef8] worker_thread+0xa8/0x620
EEH: [c00000000018be34] kthread+0x124/0x130
EEH: [c00000000000cd64] ret_from_kernel_thread+0x5c/0x64
EEH: This PCI device has failed 1 times in the last hour and will be.

We took a pcie bus trace and found out that a vector of msix is clear to 0 by irqbalance daemon. If we disable irqbalance daemon, we won't see the issue on both of adapters.

We enabled debug in ipr driver,

[   44.103071] ipr: Entering __ipr_remove
[   44.103083] ipr: Entering ipr_initiate_ioa_bringdown
[   44.103091] ipr: Entering ipr_reset_shutdown_ioa
[   44.103099] ipr: Leaving ipr_reset_shutdown_ioa
[   44.103105] ipr: Leaving ipr_initiate_ioa_bringdown
[   44.149918] ipr: Entering ipr_reset_ucode_download
[   44.149935] ipr: Entering ipr_reset_alert
[   44.150032] ipr: Entering ipr_reset_start_timer
[   44.150038] ipr: Leaving ipr_reset_alert
[   44.244343] scsi 1:2:3:0: alua: Detached
[   44.254300] ipr: Entering ipr_reset_start_bist
[   44.254320] ipr: Entering ipr_reset_start_timer
[   44.254325] ipr: Leaving ipr_reset_start_bist
[   44.364329] scsi 1:2:4:0: alua: Detached
[   45.134341] scsi 1:2:5:0: alua: Detached
[   45.860949] ipr: Entering ipr_reset_shutdown_ioa
[   45.860962] ipr: Leaving ipr_reset_shutdown_ioa
[   45.860966] ipr: Entering ipr_reset_alert
[   45.861028] ipr: Entering ipr_reset_start_timer
[   45.861035] ipr: Leaving ipr_reset_alert
[   45.964302] ipr: Entering ipr_reset_start_bist
[   45.964309] ipr: Entering ipr_reset_start_timer
[   45.964313] ipr: Leaving ipr_reset_start_bist
[   46.264301] ipr: Entering ipr_reset_bist_done
[   46.264309] ipr: Leaving ipr_reset_bist_done

--->
There is very small window: irqbalance daemon kicks in before ipr driver calls pci_restore_state(pdev), irqbalance daemon read back all 0 for that msix vector in __pci_read_msi_msg(). When ipr driver call pci_restore_state(pdev) in ipr_reset_restore_cfg_space(), the msix vector has been cleared by irqbalance daemon in pci_write_msg_msix().

Below is MSIX table for ipr adapter after 'irqbalance" dameon kicked in.

Dump MSIx table: index=0 address_lo=c800 address_hi=10000000 msg_data=0 Dump MSIx table: index=1 address_lo=c810 address_hi=10000000 msg_data=0 Dump MSIx table: index=2 address_lo=c820 address_hi=10000000 msg_data=0 Dump MSIx table: index=3 address_lo=c830 address_hi=10000000 msg_data=0 Dump MSIx table: index=4 address_lo=c840 address_hi=10000000 msg_data=0 Dump MSIx table: index=5 address_lo=c850 address_hi=10000000 msg_data=0 Dump MSIx table: index=6 address_lo=c860 address_hi=10000000 msg_data=0 Dump MSIx table: index=7 address_lo=c870 address_hi=10000000 msg_data=0 Dump MSIx table: index=8 address_lo=0 address_hi=0 msg_data=0

					-------> hit EEH

Dump MSIx table: index=9 address_lo=c890 address_hi=10000000 msg_data=0 Dump MSIx table: index=10 address_lo=c8a0 address_hi=10000000 msg_data=0 Dump MSIx table: index=11 address_lo=c8b0 address_hi=10000000 msg_data=0 Dump MSIx table: index=12 address_lo=c8c0 address_hi=10000000 msg_data=0 Dump MSIx table: index=13 address_lo=c8d0 address_hi=10000000 msg_data=0 Dump MSIx table: index=14 address_lo=c8e0 address_hi=10000000 msg_data=0 Dump MSIx table: index=15 address_lo=c8f0 address_hi=10000000 msg_data=0

[   46.264312] ipr: Entering ipr_reset_restore_cfg_space
[   46.267439] ipr: Entering ipr_fail_all_ops
[   46.267447] ipr: Leaving ipr_fail_all_ops
[   46.267451] ipr: Leaving ipr_reset_restore_cfg_space
[   46.267454] ipr: Entering ipr_ioa_bringdown_done
[   46.267458] ipr: Leaving ipr_ioa_bringdown_done
[   46.267467] ipr: Entering ipr_worker_thread
[   46.267470] ipr: Leaving ipr_worker_thread

irabalance daemon calls this:
In _pci_read_msi_msg(),
void __pci_read_msi_msg(struct msi_desc *entry, struct msi_msg *msg)

{
    struct pci_dev *dev = msi_desc_to_pci_dev(entry);

    BUG_ON(dev->current_state != PCI_D0);

    if (entry->pci.msi_attrib.is_msix) {
        void __iomem *base = pci_msix_desc_addr(entry);

        if (WARN_ON_ONCE(entry->pci.msi_attrib.is_virtual))
            return;

        msg->address_lo = readl(base + PCI_MSIX_ENTRY_LOWER_ADDR);
			-> it is 0 before calling pci_restore_state()

        msg->address_hi = readl(base + PCI_MSIX_ENTRY_UPPER_ADDR);
			-> it is 0 before calling pci_restore_state()

        msg->data = readl(base + PCI_MSIX_ENTRY_DATA);

...
...
}

Then call pseries_msi_write_msg to set 0 to entry->msg.

static void pseries_msi_write_msg(struct irq_data *data,...)

{
    struct msi_desc *entry = irq_data_get_msi_desc(data);

    entry->msg = *msg;
}

Later ipr driver calls pci_restore_save(pdev)
-> __pci_restore_msix_state()

pci_restore_msix_state(struct pci_dev *dev)
-> pci_write_msg_msix()

static inline void pci_write_msg_msix()
{

..   writel(msg->address_lo, base + PCI_MSIX_ENTRY_LOWER_ADDR);
			->already clear to 0 by irqbalance daemon

    writel(msg->address_hi, base + PCI_MSIX_ENTRY_UPPER_ADDR); 
			->already clear to 0 by irqbalance daemon
    writel(msg->data, base + PCI_MSIX_ENTRY_DATA);

}

I tried the following patch and we didn't hit the issue. If you are familiar with MSI domain code, Please suggest the better solution.

Thanks,
Wendy

---
 kernel/irq/msi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/irq/msi.c +2 -1
index 396a067a8a56..fcde35efb64c 100644
@@ -671,7 +671,8 @@ int msi_domain_set_affinity(struct irq_data *irq_data,
 	if (ret >= 0 && ret != IRQ_SET_MASK_OK_DONE) {
 		BUG_ON(irq_chip_compose_msi_msg(irq_data, msg));
 		msi_check_level(irq_data->domain, msg);
-		irq_chip_write_msi_msg(irq_data, msg);
+		if ((msg->address_lo != 0) && (msg->address_hi != 0))
+			irq_chip_write_msi_msg(irq_data, msg);
 	}
 
 	return ret;
Signature · 1 line
2.43.5
#1 lore raw
Quoted 3 lines · On Wed, Mar 19 2025 at 07:14, [email protected] wrote:

There is very small window: irqbalance daemon kicks in before ipr driver calls pci_restore_state(pdev), irqbalance daemon read back all 0 for that msix vector in __pci_read_msi_msg().

You fail to explain how irqbalanced is able to invoke __pci_read_msi_msg().

I assume that this happens in the set_affinity() path, which ends up in pseries_msi_compose_msg(). pseries_msi_compose_msg() reads back the message from the device.

kernel/irq/msi.c int msi_domain_set_affinity(struct irq_data *irq_data, · line 675

Quoted 11 lines
kernel/irq/msi.c +2 -1
index 396a067a8a56..fcde35efb64c 100644
@@ -671,7 +671,8 @@ int msi_domain_set_affinity(struct irq_data *irq_data,
 	if (ret >= 0 && ret != IRQ_SET_MASK_OK_DONE) {
 		BUG_ON(irq_chip_compose_msi_msg(irq_data, msg));
 		msi_check_level(irq_data->domain, msg);
-		irq_chip_write_msi_msg(irq_data, msg);
+		if ((msg->address_lo != 0) && (msg->address_hi != 0))
+			irq_chip_write_msi_msg(irq_data, msg);

That's just papering over the underlying problem and thereby breaks all architetures except your machine. address_hi _IS_ zero on most systems and there is no requirement for address_lo to be non-zero when address_hi is non-zero. Not going to happen.

The real problem has nothing to do with a remove/add operation. The problem is solely in the probe function.

It does:

pci_alloc_irq_vectors(); // Exposes interrupts in /proc/irq/

                                // which makes them visible to
                                // irqbalanced
   pci_save_state();

#A reset_device(); // Clears the config space

#B pci_restore_state(); // Restores the config space

So the driver creates inconsistent state between #A and #B, which is wrong to begin with when it first sets up resources which are visible to other entities.

Why are the interrupts set up _before_ the reset? That does not make any sense.

And no, we are not going to do a random undocumented hack in generic code to work around such a driver insanity.

Fix the problem where it was created, i.e. at the driver level.

Thanks,

tglx

author
#2 lore raw
Quoted 2 lines

The real problem has nothing to do with a remove/add operation. The problem is solely in the probe function.

Hi Thomas,
Thanks for your suggestion!

I don't think we have problems in probe function since this driver has been in productions for many many years. Also we didn't see the issue before the "MSI domain" patchset dropping into linux interrupt code(no issue in rhel92 release).

Device reset is not called in probe function. We don't see the issue without dynamically remove/add operation.
There is a small window which irqbalance daemon kicks in during device reset. So it took about over 6 hours to recreate the issue when doing remove/add loop operation.

We can't find the good way to fix the issue in both of device drivers. So we look for some help in interrupt code.

Looks each irq_data has a state(IRQD_AFFINITY_MANAGED), Can we play this flag during the reset in device driver?

* IRQD_NO_BALANCING - Balancing disabled for this IRQ
* IRQD_AFFINITY_ON_ACTIVATE - Affinity is set on activation. Don't
call irq_chip::irq_set_affinity() when deactivated.

OR
If we registered an affinity notifier in device driver, can this tell us the msix vector has been clear to 0 when irqbalance daemon kicks in?

Thank you so much, I really appreciate any suggestion/help! Wendy

#3 lore raw
Quoted 5 lines · Wen Xiong
Quoted 2 lines

The real problem has nothing to do with a remove/add operation. The problem is solely in the probe function.

I don't think we have problems in probe function since this driver has been in productions for many many years.

Seriously?

It does not matter at all whether you had it many years in production or not. Fact is that the driver is operational and after that a device reset happens, which wipes the config space. That _IS_ the problem.

Quoted 2 lines

Also we didn't see the issue before the "MSI domain" patchset dropping into linux interrupt code(no issue in rhel92 release).

That's completely irrelevant. See above.

Quoted 1 line

Device reset is not called in probe function.

Right. The reset is part of PCI error handling, which happens _AFTER_ the driver has set up interrupts.

Quoted 4 lines

We don't see the issue without dynamically remove/add operation. There is a small window which irqbalance daemon kicks in during device reset. So it took about over 6 hours to recreate the issue when doing remove/add loop operation.

Sure. You need a loop to hit the window. And it does not matter whether it's the probe or the remove which triggers it. Fact is that the reset wipes out the config space, which means that any read from the config space between reset and restore will return garbage. That problem is not restricted to the interrupt code. It's a general problem.

Quoted 2 lines

We can't find the good way to fix the issue in both of device drivers. So we look for some help in interrupt code.

No. This is _NOT_ a interrupt specific problem. You are observing the symptom related to interrupts, but any other code which reads from config space during the reset window has exactly the same problem.

The PCI error handling resets the device asynchronously to any other operation which might access the config space. Yes, set_affinity() is one possible way to hit that due to the implementation detail of pseries_msi_compose_msg(), which reads the MSI message composed by the underlying hypervisor back from config space. But even if it would not read back and compose the message itself then set_affinity() would create inconsistent state because:

       reset()
                        compose()
                        write()
       restore()

I.e. the reset machinery overwrites the new message, which means this ends up with inconsistent state.

So this is a general problem with PCI error handling and _not_ a problem of the interrupt subsystem. I have no idea what to do about that, but this needs to be looked at from the PCI error handling side and not papered over at the messenger.

Thanks,

tglx

#4 lore raw
Quoted 11 lines · Thomas Gleixner
Quoted 4 lines · Wen Xiong

We don't see the issue without dynamically remove/add operation. There is a small window which irqbalance daemon kicks in during device reset. So it took about over 6 hours to recreate the issue when doing remove/add loop operation.

Sure. You need a loop to hit the window. And it does not matter whether it's the probe or the remove which triggers it. Fact is that the reset wipes out the config space, which means that any read from the config space between reset and restore will return garbage. That problem is not restricted to the interrupt code. It's a general problem.

After looking at the code again, it's a problem in the remove() function:

__ipr_remove()
ipr_initiate_ioa_bringdown()

    // resets device
    restore_config_space()
  ....
  ipr_free_all_resources()
    free_irqs()

So yes, it's not probe(). But the question is pretty much the same.

Why is a reset issued while the driver is fully operational and resources are still in use?

Don't even think about telling me that this is a problem of the MSI interrupt rework. It is not. It's been broken forever.

You _cannot_ pull the rung under a fully operational driver and expect that all involved parts will just magically handle this gracefully.

What about tearing down resources first and then issuing the reset?

Thanks,

tglx

author
#5 lore raw
Quoted 3 lines

What about tearing down resources first and then issuing the reset?

This SAS adapter supports dual controller configuration. Normally we have two adapters in a system.
We config one of them as Primary adapter and another one as Secondary adapter.
When doing remove operation on primary adapter, the Secondary adapter is going to be failover and config as primary by adapter firmware. During failover process, adapter firmware requests the secondary adapter reset, then sets it as primary adapter.

Secondary adapter failover triggers adapter reset(ipr_reset_get_unit_check_job()).

[  940.742698] ipr 0206:a0:00.0: 9070: IOA requested reset  -> FW requested
[  940.742733] ipr 0206:a0:00.0: Adapter to Adapter Link Failed Due to SAS Fabric Change [PRC: 17101C25]
[  940.742768] ipr 0206:a0:00.0: Remote IOA VPID/SN: IBM 57B4001SISIOA 00458021

When secondary adapter doing a reset, we use the same code path as removing operation. We can’t free irqs for Secondary adapter since kernel has assigned the irqs for Secondary adapter.

Actually we discussed about "calling pci_free_irq_vectors()" before doing bist reset when we trying to fix in device driver.

That might cause other problems. It is also not what a user would expect. For example, if they disabled irq balance and manually setup irq binding and affinity, if we go and free and reallocate the interrupts across a reset, this would wipe out those changes, which would not be expected.

Thanks,
Wendy

#6 lore raw
Quoted 11 lines · Wen Xiong

When secondary adapter doing a reset, we use the same code path as removing operation. We can’t free irqs for Secondary adapter since kernel has assigned the irqs for Secondary adapter.

Actually we discussed about "calling pci_free_irq_vectors()" before doing bist reset when we trying to fix in device driver. That might cause other problems. It is also not what a user would expect. For example, if they disabled irq balance and manually setup irq binding and affinity, if we go and free and reallocate the interrupts across a reset, this would wipe out those changes, which would not be expected.

You are completely missing the point. This is not a problem restricted to PCI/MSI interrupts.

You have interrupts, work, queues and whatever in fully operational state. Then you tell the firmware to reset the adapter and swap the secondary adapter in. This reset operation brings the hardware temporary into an undefined state as you have observed. How is any part of the kernel, which can access and operate on this adapter, supposed to deal with that correctly?

You are now focussing solely on papering over the symptom in PCI/MSI because that's where you actually observed the fallout.

But as you know curing the symptom is not fixing anything because the underlying root cause still persists and will roar its ugly head at some other place sooner than later.

So no, instead of sprinkling horrible band-aids all over the place, you have to sit down and think about a properly orchestrated mechanism for this failover scenario.

I understand that you want to preserve the state of the secondary adapter including interrupt numbers and related settings, but for that you have to properly freeze _all_ related kernel resources first, then let the firmware do the swap and once that's complete unfreeze everything again.

That will need support in other subsystems, like the interrupt layer, but that needs to be properly designed and integrated so that it works with all possible PCI/MSI backend implementations and under all circumstances. Setting affinity is not the only way to make this go wrong, there are other operations which access the underlying hardware and config space. You just haven't triggered them yet, but they exist.

And it's not a problem restricted to the pSeries MSI backend implementation either. That's just one way to expose it.

Even if I put the secondary swap problem aside and just look at a single instance, __ipr_remove() is already broken in itself. As I pointed out to you before:

    __ipr_remove()
      ipr_initiate_ioa_bringdown() 
	// resets device -> undefined state
	restore_config_space()
      ....
      ipr_free_all_resources()
	free_irqs()

Up to the point where interrupts are freed, they are fully operational and exposed to user space. The related functionality can hit the undefined state not only via set_affinity() independent of the swap problem.

The adapter swap is just a worse variant of the above because it affects the secondary side behind its back.

This needs quite some work to resolve properly, but that's the only way to fix it once and forever. Proliferating the 'Plug and Pray' approach with a lot of handwaving is just helping you to close your ticket, but it's not a solution.

Thanks,

tglx

author
#7 lore raw
Quoted 3 lines · Thomas Gleixner

You are completely missing the point. This is not a problem restricted to PCI/MSI interrupts.

Thanks for all suggestions! I will investigate more and check if we can fix it in device driver.

Looks several device drivers in kernel use two kernel APIs to set/clean IRQ_NO_BALACING status for a given irq.

irq_set_status_flags(irq, IRQ_NO_BALANCING);
irq_clear_status_flags(irq, IRQ_NO_BALANCING);

With these two APIs, device driver can decide if using kernel irq balance or setting irq affinity by driver itself?

So we can set/clear IRQ_NO_BALANCING during reset.

Thanks,
Wendy

#8 lore raw
Quoted 11 lines · Wen Xiong
Quoted 3 lines · Thomas Gleixner

You are completely missing the point. This is not a problem restricted to PCI/MSI interrupts.

Thanks for all suggestions! I will investigate more and check if we can fix it in device driver.

Looks several device drivers in kernel use two kernel APIs to set/clean IRQ_NO_BALACING status for a given irq.

Quoted 7 lines

irq_set_status_flags(irq, IRQ_NO_BALANCING);
irq_clear_status_flags(irq, IRQ_NO_BALANCING);

With these two APIs, device driver can decide if using kernel irq balance or setting irq affinity by driver itself?

So we can set/clear IRQ_NO_BALANCING during reset.

That's not sufficient. You are papering over the symptom. I explained you that affinity setting is not the only way to wreckage this.

But feel free to ignore me and apply your bandaid fix as you see fit.

Thanks,

tglx