Fix kernel panic on niu bind
Subsystems (4)
A message that is not in the archive (sent off-list or not yet received): [email protected]
cover Fix kernel panic on niu bind
From: Jonathan Currier <[email protected]>
Currently, the niu module causes a fatal trap (tested on SPARC system) when setting up it's MSIX interrupt vectors. A simple write to each MSIX's vector table entries' ENTRY_DATA register is sufficient to work around the issue for the current power cycle (note: this means booting a working kernel, and then rebooting without power cycling will allow a kernel without this fix to boot and work).
This series implements a struct pci_dev flag indicating ENTRY_DATA must be written to before reads, and then sets the flag in the niu driver.
This series is based off of and tested on v6.11.5.
Testing on next-20241115 was also done successfully with the following
caveats: On my test case (SPARC T2),
commit 03cfe0e05650 ("PCI/pwrctl: Ensure that the pwrctl drivers are probed before the PCI client drivers") prevented all PCIe drivers from binding, including niu.
For my test case I disabled 03cfe0e05650's device_link_add().
Original mailing list discussion:
Jonathan Currier (2):
PCI/MSI: Add MSIX option to write to ENTRY_DATA before any reads net/niu: niu requires MSIX ENTRY_DATA fields touch before entry reads
drivers/net/ethernet/sun/niu.c | 2 ++ drivers/pci/msi/msi.c | 2 ++ include/linux/pci.h | 2 ++ 3 files changed, 6 insertions(+)
base-commit: 05b1367d372aca98a4e09c1a0e7ff0b9d721b2bc
Signature · 1 line
2.45.2
PATCH 1/2 PCI/MSI: Add MSIX option to write to ENTRY_DATA before any reads
From: Jonathan Currier <[email protected]>
Commit 7d5ec3d36123 ("PCI/MSI: Mask all unused MSI-X entries") introduces a readl() from ENTRY_VECTOR_CTRL before the writel() to ENTRY_DATA. This is correct, however some hardware, like the Sun Neptune chips, the niu module, will cause an error and/or fatal trap if any MSIX table entry is read before the corresponding ENTRY_DATA field is written to. This patch adds an optional early writel() in msix_prepare_msi_desc().
--- drivers/pci/msi/msi.c | 2 ++ include/linux/pci.h | 2 ++ 2 files changed, 4 insertions(+)
drivers/pci/msi/msi.c +2 -0
@@ -611,6 +611,8 @@ void msix_prepare_msi_desc(struct pci_dev *dev, struct msi_desc *desc)if (desc->pci.msi_attrib.can_mask) {void __iomem *addr =pci_msix_desc_addr (desc); +if (dev->dev_flags &PCI_DEV_FLAGS_MSIX_TOUCH_ENTRY_DATA_FIRST ) +writel (0 , addr +PCI_MSIX_ENTRY_DATA ); desc->pci.msix_ctrl =readl (addr +PCI_MSIX_ENTRY_VECTOR_CTRL ); } }
include/linux/pci.h +2 -0
@@ -245,6 +245,8 @@ enum pci_dev_flags {PCI_DEV_FLAGS_NO_RELAXED_ORDERING = (__force pci_dev_flags_t) (1 <<11 ),/* Device does honor MSI masking despite saying otherwise */ PCI_DEV_FLAGS_HAS_MSI_MASKING = (__force pci_dev_flags_t) (1 <<12 ), +/* Device requires write to PCI_MSIX_ENTRY_DATA before any MSIX reads */ + PCI_DEV_FLAGS_MSIX_TOUCH_ENTRY_DATA_FIRST = (__force pci_dev_flags_t) (1 << 13), }; enum pci_irq_reroute_variant {
Signature · 1 line
2.45.2
Paolo Abeni
maintainerRe: [PATCH 1/2] PCI/MSI: Add MSIX option to write to ENTRY_DATA before any reads
Quoted 8 lines · On 11/18/24 00:48, [email protected] wrote:
From: Jonathan Currier <[email protected]>
Commit
7d5ec3d36123("PCI/MSI: Mask all unused MSI-X entries") introduces areadl()fromENTRY_VECTOR_CTRLbefore thewritel()toENTRY_DATA. This is correct, however some hardware, like the Sun Neptune chips, the niu module, will cause an error and/or fatal trap if any MSIX table entry is read before the correspondingENTRY_DATAfield is written to. This patch adds an optional earlywritel()inmsix_prepare_msi_desc().
Why the issue can't be addressed into the relevant device driver? It looks like an H/W bug, a driver specific fix looks IMHO more fitting.
A cross subsystem series, like this one, gives some extra complication to maintainers.
Thanks,
Paolo
Re: [PATCH 1/2] PCI/MSI: Add MSIX option to write to ENTRY_DATA before any reads
Quoted 4 lines · Paolo Abeni
Quoted 2 lines · On 11/18/24 00:48, [email protected] wrote:
From: Jonathan Currier <[email protected]>
Quoted 8 lines
Quoted 6 lines
Commit
7d5ec3d36123("PCI/MSI: Mask all unused MSI-X entries") introduces areadl()fromENTRY_VECTOR_CTRLbefore thewritel()toENTRY_DATA. This is correct, however some hardware, like the Sun Neptune chips, the niu module, will cause an error and/or fatal trap if any MSIX table entry is read before the correspondingENTRY_DATAfield is written to. This patch adds an optional earlywritel()inmsix_prepare_msi_desc().Why the issue can't be addressed into the relevant device driver? It looks like an H/W bug, a driver specific fix looks IMHO more fitting.
I considered this approach, and thus asked about it in the mailing lists here:
https://lore.kernel.org/sparclinux/[email protected]/T/
It sounds like you are suggesting approach 1 (add the MSIX register writes to niu). I did do a quick and dirty test of that. However it ended up requiring msix_map_region(), and pci_msix_desc_addr(), both of are internal to the msi code, and not exported or in pubic headers. The msix_table_size() macro was also needed. I could either export those functions, or reproduce their code in the niu driver. However, as Thomas' suggestion seemed very simple and elegant to me, I decided to got with it.
If it is actually preferable to either copy those msix functions into niu, they are not very large, or export them (GPL I would assume?) let me know and I can make that change.
Quoted 7 lines
A cross subsystem series, like this one, gives some extra complication to maintainers.
Thanks,
Paolo
Sincerely,
Jonathan Currier
Paolo Abeni
maintainerRe: [PATCH 1/2] PCI/MSI: Add MSIX option to write to ENTRY_DATA before any reads
Quoted 10 lines · Dullfire
Quoted 9 lines · Paolo Abeni
Quoted 8 lines · On 11/18/24 00:48, [email protected] wrote:
From: Jonathan Currier <[email protected]>
Commit
7d5ec3d36123("PCI/MSI: Mask all unused MSI-X entries") introduces areadl()fromENTRY_VECTOR_CTRLbefore thewritel()toENTRY_DATA. This is correct, however some hardware, like the Sun Neptune chips, the niu module, will cause an error and/or fatal trap if any MSIX table entry is read before the correspondingENTRY_DATAfield is written to. This patch adds an optional earlywritel()inmsix_prepare_msi_desc().
Quoted 5 lines
Quoted 2 lines
Why the issue can't be addressed into the relevant device driver? It looks like an H/W bug, a driver specific fix looks IMHO more fitting.
I considered this approach, and thus asked about it in the mailing lists here:
https://lore.kernel.org/sparclinux/[email protected]/T/
I forgot about such thread, thank you for the reminder. Since the more hackish code is IRQ specific, if Thomas is fine with that, I'll not oppose.
Quoted 2 lines
Quoted 2 lines
A cross subsystem series, like this one, gives some extra complication to maintainers.
The niu driver is not exactly under very active development, I guess the whole series could go via the IRQ subsystem, if Thomas agrees.
Cheers,
Paolo
Re: [PATCH 1/2] PCI/MSI: Add MSIX option to write to ENTRY_DATA before any reads
Quoted 23 lines · Paolo Abeni
Quoted 10 lines · Dullfire
Quoted 9 lines · Paolo Abeni
Quoted 8 lines · On 11/18/24 00:48, [email protected] wrote:
From: Jonathan Currier <[email protected]>
Commit
7d5ec3d36123("PCI/MSI: Mask all unused MSI-X entries") introduces areadl()fromENTRY_VECTOR_CTRLbefore thewritel()toENTRY_DATA. This is correct, however some hardware, like the Sun Neptune chips, the niu module, will cause an error and/or fatal trap if any MSIX table entry is read before the correspondingENTRY_DATAfield is written to. This patch adds an optional earlywritel()inmsix_prepare_msi_desc().Quoted 5 lines
Quoted 2 lines
Why the issue can't be addressed into the relevant device driver? It looks like an H/W bug, a driver specific fix looks IMHO more fitting.
I considered this approach, and thus asked about it in the mailing lists here:
https://lore.kernel.org/sparclinux/[email protected]/T/I forgot about such thread, thank you for the reminder. Since the more hackish code is IRQ specific, if Thomas is fine with that, I'll not oppose.
Quoted 2 lines
Quoted 2 lines
A cross subsystem series, like this one, gives some extra complication to maintainers.
Quoted 7 lines
The niu driver is not exactly under very active development, I guess the whole series could go via the IRQ subsystem, if Thomas agrees.
Cheers,
Paolo
Thomas, does this work for you, or is there something else you would to see in this series?
Sincerely,
Jonathan Currier
Re: [PATCH 1/2] PCI/MSI: Add MSIX option to write to ENTRY_DATA before any reads
Quoted 2 lines · Dullfire
On 11/21/24 04:28, Paolo Abeni wrote:
[...]
Quoted 9 lines
Quoted 7 lines
The niu driver is not exactly under very active development, I guess the whole series could go via the IRQ subsystem, if Thomas agrees.
Cheers,
Paolo
Thomas, does this work for you, or is there something else you would to see in this series?
Since it's been a few months, just wanted to give this a bump, and see if the series is lacking anything. Thanks,
Sincerely,
Jonathan Currier
Re: [PATCH 1/2] PCI/MSI: Add MSIX option to write to ENTRY_DATA before any reads
Quoted 8 lines · On Mon, Apr 14 2025 at 11:22, [email protected] wrote:
Quoted 1 line · Dullfire
On 11/21/24 04:28, Paolo Abeni wrote:
[...]
Quoted 5 lines
Quoted 5 lines
The niu driver is not exactly under very active development, I guess the whole series could go via the IRQ subsystem, if Thomas agrees.
Cheers,
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Paolo
Thomas, does this work for you, or is there something else you would to see in this series?
Since it's been a few months, just wanted to give this a bump, and see if the series is lacking anything. Thanks,
Sorry for letting this fall through the cracks. I put it back on my todo list...
Thanks,
tglx
[tip: irq/urgent] PCI/MSI: Add an option to write MSIX ENTRY_DATA before any reads
In reply to [email protected]The following commit has been merged into the irq/urgent branch of tip:
The following commit has been merged into the irq/urgent branch of tip:
Commit-ID: cf761e3dacc6ad5f65a4886d00da1f9681e6805a Gitweb: https://git.kernel.org/tip/cf761e3dacc6ad5f65a4886d00da1f9681e6805a Author: Jonathan Currier <[email protected]> AuthorDate: Sun, 17 Nov 2024 17:48:42 -06:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 15 Apr 2025 08:32:18 +02:00
PCI/MSI: Add an option to write MSIX ENTRY_DATA before any reads
Commit 7d5ec3d36123 ("PCI/MSI: Mask all unused MSI-X entries") introduced a readl() from ENTRY_VECTOR_CTRL before the writel() to ENTRY_DATA.
This is correct, however some hardware, like the Sun Neptune chips, the NIU module, will cause an error and/or fatal trap if any MSIX table entry is read before the corresponding ENTRY_DATA field is written to.
Add an optional early writel() in msix_prepare_msi_desc().
--- drivers/pci/msi/msi.c | 3 +++ include/linux/pci.h | 2 ++ 2 files changed, 5 insertions(+)
drivers/pci/msi/msi.c +3 -0
@@ -615,6 +615,9 @@ void msix_prepare_msi_desc(struct pci_dev *dev, struct msi_desc *desc)void __iomem *addr =pci_msix_desc_addr (desc); desc->pci.msi_attrib.can_mask =1 ; +/* Workaround for SUN NIU insanity, which requires write before read */ +if (dev->dev_flags &PCI_DEV_FLAGS_MSIX_TOUCH_ENTRY_DATA_FIRST ) +writel (0 , addr +PCI_MSIX_ENTRY_DATA ); desc->pci.msix_ctrl =readl (addr +PCI_MSIX_ENTRY_VECTOR_CTRL ); } }
include/linux/pci.h +2 -0
@@ -245,6 +245,8 @@ enum pci_dev_flags {PCI_DEV_FLAGS_NO_RELAXED_ORDERING = (__force pci_dev_flags_t) (1 <<11 ),/* Device does honor MSI masking despite saying otherwise */ PCI_DEV_FLAGS_HAS_MSI_MASKING = (__force pci_dev_flags_t) (1 <<12 ), +/* Device requires write to PCI_MSIX_ENTRY_DATA before any MSIX reads */ + PCI_DEV_FLAGS_MSIX_TOUCH_ENTRY_DATA_FIRST = (__force pci_dev_flags_t) (1 << 13), }; enum pci_irq_reroute_variant {
PATCH 2/2 net/niu: niu requires MSIX ENTRY_DATA fields touch before entry reads
In reply to [email protected]From: Jonathan Currier <[email protected]>
Fix niu_try_msix() to not cause a fatal trap on sparc systems.
Set PCI_DEV_FLAGS_MSIX_TOUCH_ENTRY_DATA_FIRST on the struct pci_dev to work around a bug in the hardware or firmware.
For each vector entry in the msix table, niu chips will cause a fatal trap if any registers in that entry are read before that entries' ENTRY_DATA register is written to. Testing indicates writes to other registers are not sufficient to prevent the fatal trap, however the value does not appear to matter. This only needs to happen once after power up, so simply rebooting into a kernel lacking this fix will NOT cause the trap.
NON-RESUMABLE ERROR: Reporting on cpu 64
NON-RESUMABLE ERROR: TPC [0x00000000005f6900] <msix_prepare_msi_desc+0x90/0xa0> NON-RESUMABLE ERROR: RAW [4010000000000016:00000e37f93e32ff:0000000202000080:ffffffffffffffff
NON-RESUMABLE ERROR: 0000000800000000:0000000000000000:0000000000000000:0000000000000000]
NON-RESUMABLE ERROR: handle [0x4010000000000016] stick [0x00000e37f93e32ff] NON-RESUMABLE ERROR: type [precise nonresumable]
NON-RESUMABLE ERROR: attrs [0x02000080] < ASI sp-faulted priv >
NON-RESUMABLE ERROR: raddr [0xffffffffffffffff]
NON-RESUMABLE ERROR: insn effective address [0x000000c50020000c]
NON-RESUMABLE ERROR: size [0x8]
NON-RESUMABLE ERROR: asi [0x00]
CPU: 64 UID: 0 PID: 745 Comm: kworker/64:1 Not tainted 6.11.5 #63 Workqueue: events work_for_cpu_fn TSTATE: 0000000011001602 TPC: 00000000005f6900 TNPC: 00000000005f6904 Y: 00000000 Not tainted TPC: <msix_prepare_msi_desc+0x90/0xa0> g0: 00000000000002e9 g1: 000000000000000c g2: 000000c50020000c g3: 0000000000000100 g4: ffff8000470307c0 g5: ffff800fec5be000 g6: ffff800047a08000 g7: 0000000000000000 o0: ffff800014feb000 o1: ffff800047a0b620 o2: 0000000000000011 o3: ffff800047a0b620 o4: 0000000000000080 o5: 0000000000000011 sp: ffff800047a0ad51 ret_pc: 00000000005f7128 RPC: <__pci_enable_msix_range+0x3cc/0x460> l0: 000000000000000d l1: 000000000000c01f l2: ffff800014feb0a8 l3: 0000000000000020 l4: 000000000000c000 l5: 0000000000000001 l6: 0000000020000000 l7: ffff800047a0b734 i0: ffff800014feb000 i1: ffff800047a0b730 i2: 0000000000000001 i3: 000000000000000d i4: 0000000000000000 i5: 0000000000000000 i6: ffff800047a0ae81 i7: 00000000101888b0 I7: <niu_try_msix.constprop.0+0xc0/0x130 [niu]> Call Trace: [<00000000101888b0>] niu_try_msix.constprop.0+0xc0/0x130 [niu] [<000000001018f840>] niu_get_invariants+0x183c/0x207c [niu] [<00000000101902fc>] niu_pci_init_one+0x27c/0x2fc [niu] [<00000000005ef3e4>] local_pci_probe+0x28/0x74 [<0000000000469240>] work_for_cpu_fn+0x8/0x1c [<000000000046b008>] process_scheduled_works+0x144/0x210 [<000000000046b518>] worker_thread+0x13c/0x1c0 [<00000000004710e0>] kthread+0xb8/0xc8 [<00000000004060c8>] ret_from_fork+0x1c/0x2c [<0000000000000000>] 0x0 Kernel panic - not syncing: Non-resumable error.
--- drivers/net/ethernet/sun/niu.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/sun/niu.c +2 -0
@@ -9058,6 +9058,8 @@ static void niu_try_msix(struct niu *np, u8 *ldg_num_map) msi_vec[i].entry = i; } + pdev->dev_flags |=PCI_DEV_FLAGS_MSIX_TOUCH_ENTRY_DATA_FIRST ; + num_irqs =pci_enable_msix_range (pdev, msi_vec,1 , num_irqs);if (num_irqs <0 ) { np->flags &= ~NIU_FLAGS_MSIX ;
Signature · 1 line
2.45.2
[tip: irq/urgent] net/niu: Niu requires MSIX ENTRY_DATA fields touch before entry reads
The following commit has been merged into the irq/urgent branch of tip:
The following commit has been merged into the irq/urgent branch of tip:
Commit-ID: fbb429ddff5c8e479edcc7dde5a542c9295944e6 Gitweb: https://git.kernel.org/tip/fbb429ddff5c8e479edcc7dde5a542c9295944e6 Author: Jonathan Currier <[email protected]> AuthorDate: Sun, 17 Nov 2024 17:48:43 -06:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Tue, 15 Apr 2025 08:32:19 +02:00
net/niu: Niu requires MSIX ENTRY_DATA fields touch before entry reads
Fix niu_try_msix() to not cause a fatal trap on sparc systems.
Set PCI_DEV_FLAGS_MSIX_TOUCH_ENTRY_DATA_FIRST on the struct pci_dev to work around a bug in the hardware or firmware.
For each vector entry in the msix table, niu chips will cause a fatal trap if any registers in that entry are read before that entries' ENTRY_DATA register is written to. Testing indicates writes to other registers are not sufficient to prevent the fatal trap, however the value does not appear to matter. This only needs to happen once after power up, so simply rebooting into a kernel lacking this fix will NOT cause the trap.
NON-RESUMABLE ERROR: Reporting on cpu 64
NON-RESUMABLE ERROR: TPC [0x00000000005f6900] <msix_prepare_msi_desc+0x90/0xa0> NON-RESUMABLE ERROR: RAW [4010000000000016:00000e37f93e32ff:0000000202000080:ffffffffffffffff
NON-RESUMABLE ERROR: 0000000800000000:0000000000000000:0000000000000000:0000000000000000]
NON-RESUMABLE ERROR: handle [0x4010000000000016] stick [0x00000e37f93e32ff] NON-RESUMABLE ERROR: type [precise nonresumable]
NON-RESUMABLE ERROR: attrs [0x02000080] < ASI sp-faulted priv >
NON-RESUMABLE ERROR: raddr [0xffffffffffffffff]
NON-RESUMABLE ERROR: insn effective address [0x000000c50020000c]
NON-RESUMABLE ERROR: size [0x8]
NON-RESUMABLE ERROR: asi [0x00]
CPU: 64 UID: 0 PID: 745 Comm: kworker/64:1 Not tainted 6.11.5 #63 Workqueue: events work_for_cpu_fn TSTATE: 0000000011001602 TPC: 00000000005f6900 TNPC: 00000000005f6904 Y: 00000000 Not tainted TPC: <msix_prepare_msi_desc+0x90/0xa0> g0: 00000000000002e9 g1: 000000000000000c g2: 000000c50020000c g3: 0000000000000100 g4: ffff8000470307c0 g5: ffff800fec5be000 g6: ffff800047a08000 g7: 0000000000000000 o0: ffff800014feb000 o1: ffff800047a0b620 o2: 0000000000000011 o3: ffff800047a0b620 o4: 0000000000000080 o5: 0000000000000011 sp: ffff800047a0ad51 ret_pc: 00000000005f7128 RPC: <__pci_enable_msix_range+0x3cc/0x460> l0: 000000000000000d l1: 000000000000c01f l2: ffff800014feb0a8 l3: 0000000000000020 l4: 000000000000c000 l5: 0000000000000001 l6: 0000000020000000 l7: ffff800047a0b734 i0: ffff800014feb000 i1: ffff800047a0b730 i2: 0000000000000001 i3: 000000000000000d i4: 0000000000000000 i5: 0000000000000000 i6: ffff800047a0ae81 i7: 00000000101888b0 I7: <niu_try_msix.constprop.0+0xc0/0x130 [niu]> Call Trace: [<00000000101888b0>] niu_try_msix.constprop.0+0xc0/0x130 [niu] [<000000001018f840>] niu_get_invariants+0x183c/0x207c [niu] [<00000000101902fc>] niu_pci_init_one+0x27c/0x2fc [niu] [<00000000005ef3e4>] local_pci_probe+0x28/0x74 [<0000000000469240>] work_for_cpu_fn+0x8/0x1c [<000000000046b008>] process_scheduled_works+0x144/0x210 [<000000000046b518>] worker_thread+0x13c/0x1c0 [<00000000004710e0>] kthread+0xb8/0xc8 [<00000000004060c8>] ret_from_fork+0x1c/0x2c [<0000000000000000>] 0x0 Kernel panic - not syncing: Non-resumable error.
--- drivers/net/ethernet/sun/niu.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/sun/niu.c +2 -0
@@ -9064,6 +9064,8 @@ static void niu_try_msix(struct niu *np, u8 *ldg_num_map) msi_vec[i].entry = i; } + pdev->dev_flags |=PCI_DEV_FLAGS_MSIX_TOUCH_ENTRY_DATA_FIRST ; + num_irqs =pci_enable_msix_range (pdev, msi_vec,1 , num_irqs);if (num_irqs <0 ) { np->flags &= ~NIU_FLAGS_MSIX ;