* [PATCH v2 1/2] PCI/AER: Make aer_mask_override effective for injected errors
2026-11-25 5:50 [PATCH v2 0/2] PCI/AER: Fix and document aer_inject's aer_mask_override Priyank Rathod
@ 2026-11-25 5:50 ` Priyank Rathod
2026-11-25 5:50 ` [PATCH v2 2/2] Documentation: PCI: Document aer_inject's aer_mask_override parameter Priyank Rathod
2026-11-25 5:57 ` [PATCH v2 0/2] PCI/AER: Fix and document aer_inject's aer_mask_override sashiko-bot
2 siblings, 0 replies; 4+ messages in thread
From: Priyank Rathod @ 2026-11-25 5:50 UTC (permalink / raw)
To: Bjorn Helgaas
Cc: Lukas Wunner, Kuppuswamy Sathyanarayanan, Ilpo Järvinen,
Dave Jiang, Prarit Bhargava, Huang Ying, Terry Bowman,
Jonathan Corbet, linux-doc, linux-pci, linux-kernel,
Priyank Rathod, Daniel Pereira, Jonathan Cameron
aer_mask_override=1 is supposed to allow injecting masked errors, but
aer_inject() corrupts the hardware Mask registers with "&= !" and
restores them before irq_inject_interrupt(), so aer_isr() still drops
the error as masked. Emulate aer_mask_override in config space reads
and writes instead of modifying the hardware Mask registers, and
document the parameter with MODULE_PARM_DESC().
Fixes: 457d9d088b02 ("PCI: aer-inject: Override PCIe AER Mask Registers")
Signed-off-by: Priyank Rathod <rathodpriyank@google.com>
---
drivers/pci/pcie/aer_inject.c | 74 +++++++++++++++++++++++++++++--------------
1 file changed, 51 insertions(+), 23 deletions(-)
diff --git a/drivers/pci/pcie/aer_inject.c b/drivers/pci/pcie/aer_inject.c
index 09bfc7194ef3..a71313964c66 100644
--- a/drivers/pci/pcie/aer_inject.c
+++ b/drivers/pci/pcie/aer_inject.c
@@ -27,9 +27,16 @@
#include "portdrv.h"
-/* Override the existing corrected and uncorrected error masks */
+/*
+ * Allow injecting errors that are masked in PCI_ERR_COR_MASK or
+ * PCI_ERR_UNCOR_MASK. aer_inject never writes the hardware Mask registers
+ * itself: aer_inj_read_config() emulates the override and
+ * aer_inj_write_config() keeps the emulated value from being written back.
+ */
static bool aer_mask_override;
module_param(aer_mask_override, bool, 0);
+MODULE_PARM_DESC(aer_mask_override,
+ "Allow injecting errors that the device masks");
struct aer_error_inj {
u8 bus;
@@ -59,6 +66,9 @@ struct aer_error {
u32 header_log3;
u32 root_status;
u32 source_id;
+ /* Hardware Mask bits hidden from readers by aer_inj_read_config() */
+ u32 uncor_mask_hidden;
+ u32 cor_mask_hidden;
};
struct pci_bus_ops {
@@ -218,7 +228,7 @@ static int aer_inj_read_config(struct pci_bus *bus, unsigned int devfn,
int where, int size, u32 *val)
{
u32 *sim;
- struct aer_error *err;
+ struct aer_error *err = NULL;
unsigned long flags;
int domain;
int rv;
@@ -241,6 +251,27 @@ static int aer_inj_read_config(struct pci_bus *bus, unsigned int devfn,
}
out:
rv = aer_inj_read(bus, devfn, where, size, val);
+
+ /*
+ * Report the injected errors as unmasked while they are pending in
+ * the emulated Status registers, and remember which hardware Mask
+ * bits were hidden that way so that aer_inj_write_config() can keep
+ * a value derived from this read (e.g., by pci_save_state()) from
+ * clearing them. *val is unspecified if the read failed and ~0 if
+ * the device is gone, so leave it alone then.
+ */
+ if (!rv && !PCI_POSSIBLE_ERROR(*val) && aer_mask_override && err) {
+ switch (where - err->pos_cap_err) {
+ case PCI_ERR_UNCOR_MASK:
+ err->uncor_mask_hidden |= *val & err->uncor_status;
+ *val &= ~err->uncor_status;
+ break;
+ case PCI_ERR_COR_MASK:
+ err->cor_mask_hidden |= *val & err->cor_status;
+ *val &= ~err->cor_status;
+ break;
+ }
+ }
spin_unlock_irqrestore(&inject_lock, flags);
return rv;
}
@@ -249,7 +280,7 @@ static int aer_inj_write_config(struct pci_bus *bus, unsigned int devfn,
int where, int size, u32 val)
{
u32 *sim;
- struct aer_error *err;
+ struct aer_error *err = NULL;
unsigned long flags;
int rw1cs;
int domain;
@@ -275,6 +306,22 @@ static int aer_inj_write_config(struct pci_bus *bus, unsigned int devfn,
return 0;
}
out:
+ /*
+ * Set the hardware Mask bits hidden from readers again, so that a
+ * value derived from such a read (e.g., by pci_save_state()) can't
+ * clear them. The record is never cleared, so until aer_inject is
+ * unloaded no dword write can unmask those bits.
+ */
+ if (aer_mask_override && err) {
+ switch (where - err->pos_cap_err) {
+ case PCI_ERR_UNCOR_MASK:
+ val |= err->uncor_mask_hidden;
+ break;
+ case PCI_ERR_COR_MASK:
+ val |= err->cor_mask_hidden;
+ break;
+ }
+ }
rv = aer_inj_write(bus, devfn, where, size, val);
spin_unlock_irqrestore(&inject_lock, flags);
return rv;
@@ -326,7 +373,7 @@ static int aer_inject(struct aer_error_inj *einj)
unsigned long flags;
unsigned int devfn = PCI_DEVFN(einj->dev, einj->fn);
int pos_cap_err, rp_pos_cap_err;
- u32 sever, cor_mask, uncor_mask, cor_mask_orig = 0, uncor_mask_orig = 0;
+ u32 sever, cor_mask, uncor_mask;
int ret = 0;
dev = pci_get_domain_bus_and_slot(einj->domain, einj->bus, devfn);
@@ -371,18 +418,6 @@ static int aer_inject(struct aer_error_inj *einj)
goto out_put;
}
- if (aer_mask_override) {
- cor_mask_orig = cor_mask;
- cor_mask &= !(einj->cor_status);
- pci_write_config_dword(dev, pos_cap_err + PCI_ERR_COR_MASK,
- cor_mask);
-
- uncor_mask_orig = uncor_mask;
- uncor_mask &= !(einj->uncor_status);
- pci_write_config_dword(dev, pos_cap_err + PCI_ERR_UNCOR_MASK,
- uncor_mask);
- }
-
spin_lock_irqsave(&inject_lock, flags);
err = __find_aer_error_by_dev(dev);
@@ -447,13 +482,6 @@ static int aer_inject(struct aer_error_inj *einj)
}
spin_unlock_irqrestore(&inject_lock, flags);
- if (aer_mask_override) {
- pci_write_config_dword(dev, pos_cap_err + PCI_ERR_COR_MASK,
- cor_mask_orig);
- pci_write_config_dword(dev, pos_cap_err + PCI_ERR_UNCOR_MASK,
- uncor_mask_orig);
- }
-
ret = pci_bus_set_aer_ops(dev->bus);
if (ret)
goto out_put;
--
2.56.1.831.g720f3f5937-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v2 2/2] Documentation: PCI: Document aer_inject's aer_mask_override parameter
2026-11-25 5:50 [PATCH v2 0/2] PCI/AER: Fix and document aer_inject's aer_mask_override Priyank Rathod
2026-11-25 5:50 ` [PATCH v2 1/2] PCI/AER: Make aer_mask_override effective for injected errors Priyank Rathod
@ 2026-11-25 5:50 ` Priyank Rathod
2026-11-25 5:57 ` [PATCH v2 0/2] PCI/AER: Fix and document aer_inject's aer_mask_override sashiko-bot
2 siblings, 0 replies; 4+ messages in thread
From: Priyank Rathod @ 2026-11-25 5:50 UTC (permalink / raw)
To: Bjorn Helgaas
Cc: Lukas Wunner, Kuppuswamy Sathyanarayanan, Ilpo Järvinen,
Dave Jiang, Prarit Bhargava, Huang Ying, Terry Bowman,
Jonathan Corbet, linux-doc, linux-pci, linux-kernel,
Priyank Rathod, Daniel Pereira, Jonathan Cameron
aer_inject has had the aer_mask_override module parameter since commit
457d9d088b02 ("PCI: aer-inject: Override PCIe AER Mask Registers"), but
the AER HOWTO never mentioned it. Describe what it is for (injecting
errors that the device masks, in particular those masked by default)
and how it behaves now that it works: the device's Mask registers are
left alone, the injected bits are only reported as unmasked while they
are pending, and the hidden Mask bits stay set in writes until the
module is unloaded.
Signed-off-by: Priyank Rathod <rathodpriyank@google.com>
---
Documentation/PCI/pcieaer-howto.rst | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/Documentation/PCI/pcieaer-howto.rst b/Documentation/PCI/pcieaer-howto.rst
index 90fdfddd3ae5..8994cbf9611a 100644
--- a/Documentation/PCI/pcieaer-howto.rst
+++ b/Documentation/PCI/pcieaer-howto.rst
@@ -265,3 +265,26 @@ from:
More information about aer-inject can be found in the document in
its source code.
+
+Injecting masked errors
+-----------------------
+
+By default aer_inject refuses, with -EINVAL, to inject an error that the
+device masks in its Correctable or Uncorrectable Error Mask register,
+because the AER driver would ignore it just like a real masked error.
+To exercise the handling of such errors anyway, e.g., of those that are
+masked by default like Header Log Overflow or Internal Errors, load the
+module with::
+
+ modprobe aer_inject aer_mask_override=1
+
+or boot with aer_inject.aer_mask_override=1 if it is built in.
+
+The device's Mask registers are not modified. Instead, as long as the
+injected error bits are pending in the emulated Status registers, reads
+of the Mask registers through the PCI core report them as unmasked, so
+the AER driver handles the injected error as if the device had it
+unmasked. The Mask register bits hidden this way are kept set in
+writes to the Mask registers until aer_inject is unloaded, so that a
+value saved through the emulation (e.g., by pci_save_state()) cannot
+unmask them in the device.
--
2.56.1.831.g720f3f5937-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread