Skip to contentSkip to conversation

Add more commands to scripts/ghes_inject.py

PATCH Superseded Mauro Carvalho Chehab 3 participants 25 messages Jan 23 – Feb 23

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#4 lore raw

PATCH v2 3/13 scripts/qmp_helper: add support for FRU Memory Poison

In reply to Mauro Carvalho Chehab

This GUID record descriptor was added on UEFI 2.11. Add support for it.

---
 scripts/qmp_helper.py | 4 ++++
 1 file changed, 4 insertions(+)
scripts/qmp_helper.py +4 -0
index 46b85d68b793..d37fb0ae11cc 100755
@@ -741,3 +741,7 @@ class cper_guid:
     CPER_CXL_EVT_DYNA_CAP = guid(0xCA95AFA7, 0xF183, 0x4018,
                                  [0x8C, 0x2F, 0x95, 0x26,
                                   0x8E, 0x10, 0x1A, 0x2A])
+
+    CPER_FRU_MEM_POISON = guid(0x5E4706C1, 0x5356, 0x48C6,
+                               [0x93, 0x0B, 0x52, 0xF2,
+                                0x12, 0x0A, 0x44, 0x58])
Signature · 1 line
2.52.0
#7 lore raw

PATCH v2 6/13 scripts/qmp_helper: add support for a timeout logic

In reply to Mauro Carvalho Chehab

We can't inject a new GHES record to the same source before it has been acked. There is an async mechanism to verify when the Kernel is ready, which is implemented at QEMU's ghes driver.

If error inject is too fast, QEMU may return an error. When such errors occur, implement a retry mechanism, based on a maximum timeout.

---
 scripts/qmp_helper.py | 47 +++++++++++++++++++++++++++++++------------
 1 file changed, 34 insertions(+), 13 deletions(-)
scripts/qmp_helper.py +34 -13
index 1587492807fe..d5ffd51f161e 100755
@@ -14,6 +14,7 @@
 
 from datetime import datetime
 from os import path as os_path
+from time import sleep
 
 try:
     qemu_dir = os_path.abspath(os_path.dirname(os_path.dirname(__file__)))
@@ -324,7 +325,8 @@ class qmp:
     Opens a connection and send/receive QMP commands.
     """
 
-    def send_cmd(self, command, args=None, may_open=False, return_error=True):
+    def send_cmd(self, command, args=None, may_open=False, return_error=True,
+                 timeout=None):
         """Send a command to QMP, optinally opening a connection"""
 
         if may_open:
@@ -336,12 +338,31 @@ def send_cmd(self, command, args=None, may_open=False, return_error=True):
         if args:
             msg['arguments'] = args
 
-        try:
-            obj = self.qmp_monitor.cmd_obj(msg)
-        # Can we use some other exception class here?
-        except Exception as e:                         # pylint: disable=W0718
-            print(f"Command: {command}")
-            print(f"Failed to inject error: {e}.")
+        if timeout and timeout > 0:
+            attempts = int(timeout * 10)
+        else:
+            attempts = 1
+
+        # Try up to attempts
+        for i in range(0, attempts):
+            try:
+                obj = self.qmp_monitor.cmd_obj(msg)
+
+                if obj and "return" in obj and not obj["return"]:
+                    break
+
+            except Exception as e:                     # pylint: disable=W0718
+                print(f"Command: {command}")
+                print(f"Failed to inject error: {e}.")
+                obj = None
+
+            if attempts > 1:
+                print(f"Error inject attempt {i + 1}/{attempts} failed.")
+
+            if i + 1 < attempts:
+                sleep(0.1)
+
+        if not obj:
             return None
 
         if "return" in obj:
@@ -531,7 +552,7 @@ def __init__(self, host, port, debug=False):
     #
     # Socket QMP send command
     #
-    def send_cper_raw(self, cper_data):
+    def send_cper_raw(self, cper_data, timeout=None):
         """
         Send a raw CPER data to QEMU though QMP TCP socket.
 
@@ -546,11 +567,11 @@ def send_cper_raw(self, cper_data):
 
         self._connect()
 
-        if self.send_cmd("inject-ghes-v2-error", cmd_arg):
+        ret = self.send_cmd("inject-ghes-v2-error", cmd_arg, timeout=timeout)
+        if ret:
             print("Error injected.")
-            return True
 
-        return False
+        return ret
 
     def get_gede(self, notif_type, payload_length):
         """
@@ -597,7 +618,7 @@ def get_gebs(self, payload_length):
         return gebs
 
     def send_cper(self, notif_type, payload,
-                  gede=None, gebs=None, raw_data=None):
+                  gede=None, gebs=None, raw_data=None, timeout=None):
         """
         Send commands to QEMU though QMP TCP socket.
 
@@ -656,7 +677,7 @@ def send_cper(self, notif_type, payload,
 
             util.dump_bytearray("Payload", payload)
 
-        return self.send_cper_raw(cper_data)
+        return self.send_cper_raw(cper_data, timeout=timeout)
 
     def search_qom(self, path, prop, regex):
         """
Signature · 1 line
2.52.0
#5 lore raw

PATCH v2 4/13 scripts/qmp_helper: make send_cper() more generic

In reply to Mauro Carvalho Chehab

Allow the caller to set GEDE, GEBS and raw data. This can be useful if one wants to replicate a CPER with the same parameters as the original one.

---
 scripts/qmp_helper.py | 69 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 55 insertions(+), 14 deletions(-)
scripts/qmp_helper.py +55 -14
index d37fb0ae11cc..ac3abc794c69 100755
@@ -551,22 +551,11 @@ def send_cper_raw(self, cper_data):
 
         return False
 
-    def send_cper(self, notif_type, payload):
+    def get_gede(self, notif_type, cper_length):
         """
-        Send commands to QEMU though QMP TCP socket.
-
-        Return True on success, False otherwise.
+        Return a Generic Error Data Entry bytearray
         """
 
-        # Fill CPER record header
-
-        # NOTE: bits 4 to 13 of block status contain the number of
-        # data entries in the data section. This is currently unsupported.
-
-        cper_length = len(payload)
-        data_length = cper_length + len(self.raw_data) + self.GENERIC_DATA_SIZE
-
-        #  Generic Error Data Entry
         gede = bytearray()
 
         gede.extend(notif_type.to_bytes())
@@ -579,7 +568,13 @@ def send_cper(self, notif_type, payload):
         gede.extend(self.fru_text)
         gede.extend(self.timestamp)
 
-        # Generic Error Status Block
+        return gede
+
+    def get_gebs(self, data_length):
+        """
+        Return a Generic Error Status Block bytearray
+        """
+
         gebs = bytearray()
 
         if self.raw_data:
@@ -593,6 +588,52 @@ def send_cper(self, notif_type, payload):
         util.data_add(gebs, data_length, 4)
         util.data_add(gebs, self.error_severity, 4)
 
+        return gebs
+
+    def send_cper(self, notif_type, payload,
+                  gede=None, gebs=None, raw_data=None):
+        """
+        Send commands to QEMU though QMP TCP socket.
+
+        Return True on success, False otherwise.
+
+        Arguments:
+            notif_type: Notification type (GUID)
+            payload: bytearray with the payload
+            gede: Generic Error Data Entry. If None, the code will generate
+                  one using the defaults and generic error data arguments
+            gebs: Generic Error Status block. If None, the code will generate
+                  one using the defaults and generic error data arguments
+            raw_data: Raw data to be added after GEBS. If not specified,
+                      the code will generate one if Generic Error Data
+                      --raw-data parameter is specified.
+        """
+
+        # Fill CPER record header
+
+        # NOTE: bits 4 to 13 of block status contain the number of
+        # data entries in the data section. This is currently unsupported.
+
+        if raw_data:
+            self.raw_data = raw_data
+
+        cper_length = len(payload)
+        data_length = cper_length + len(self.raw_data) + self.GENERIC_DATA_SIZE
+
+        if gede and len(gede) != 72:
+            print(f"Invalid Generic Error Data Entry length: {len(gede)}. Ignoring it")
+            gede = None
+
+        if gebs and len(gebs) != 20:
+            print(f"Invalid Generic Error Status Block length: {len(gebs)}. Ignoring it")
+            gebs = None
+
+        if not gede:
+            gede = self.get_gede(notif_type, cper_length)
+
+        if not gebs:
+            gebs = self.get_gebs(data_length)
+
         cper_data = bytearray()
         cper_data.extend(gebs)
         cper_data.extend(gede)
Signature · 1 line
2.52.0
#14 lore raw

PATCH v2 10/13 scripts/ghes_inject: add support for fuzzy logic testing

In reply to Mauro Carvalho Chehab

Add a command to inject random errors for fuzzy logic testing.

By default, it will generate a single test for a random valid GUID with random bytes inside the CPER payload.

The command allows specifying:
- a single type of CPER;
- a range of minimum/maximum payload size;
- change its default to fill with zero instead of random;
- multiple CPERs with an specified count;
- ensure a delay between them;
- setup a timeout to retry if an attempt fails (useful when count > 1).

---
 MAINTAINERS            |   1 +
 scripts/fuzzy_error.py | 206 +++++++++++++++++++++++++++++++++++++++++
 scripts/ghes_inject.py |   2 +
 3 files changed, 209 insertions(+)
 create mode 100644 scripts/fuzzy_error.py
MAINTAINERS +1 -0
index 1e62064a8672..967aafc35a92 100644
@@ -2228,6 +2228,7 @@ F: qapi/acpi-hest.json
 F: scripts/ghes_decode.py
 F: scripts/ghes_inject.py
 F: scripts/arm_processor_error.py
+F: scripts/fuzzy_error.py
 F: scripts/pci_bus_error.py
 F: scripts/qmp_helper.py
 
scripts/fuzzy_error.py new file +206 -0

206 lines not on this page · raw message

scripts/ghes_inject.py +2 -0
index be2384a59b3e..bcbfffc586e1 100755
@@ -13,6 +13,7 @@
 
 from arm_processor_error import ArmProcessorEinj
 from pci_bus_error import PciBusError
+from fuzzy_error import FuzzyError
 
 EINJ_DESC = """
 Handle ACPI GHESv2 error injection logic QEMU QMP interface.
@@ -42,6 +43,7 @@ def main():
 
     ArmProcessorEinj(subparsers)
     PciBusError(subparsers)
+    FuzzyError(subparsers)
 
     args = parser.parse_args()
     if "func" in args:
Signature · 1 line
2.52.0
#1 lore raw

PATCH v2 1/13 scripts/qmp_helper: add a return code to send_cper

In reply to Mauro Carvalho Chehab

When used inside a loop, it is useful to have a return code to indicate whether a send cper command succedded or not.

---
 scripts/qmp_helper.py | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
scripts/qmp_helper.py +14 -4
index c1e7e0fd80ce..249a8c7187d1 100755
@@ -531,7 +531,11 @@ def __init__(self, host, port, debug=False):
     # Socket QMP send command
     #
     def send_cper_raw(self, cper_data):
-        """Send a raw CPER data to QEMU though QMP TCP socket"""
+        """
+        Send a raw CPER data to QEMU though QMP TCP socket.
+
+        Return True on success, False otherwise.
+        """
 
         data = b64encode(bytes(cper_data)).decode('ascii')
 
@@ -543,9 +547,16 @@ def send_cper_raw(self, cper_data):
 
         if self.send_cmd("inject-ghes-v2-error", cmd_arg):
             print("Error injected.")
+            return True
+
+        return False
 
     def send_cper(self, notif_type, payload):
-        """Send commands to QEMU though QMP TCP socket"""
+        """
+        Send commands to QEMU though QMP TCP socket.
+
+        Return True on success, False otherwise.
+        """
 
         # Fill CPER record header
 
@@ -599,8 +610,7 @@ def send_cper(self, notif_type, payload):
 
             util.dump_bytearray("Payload", payload)
 
-        self.send_cper_raw(cper_data)
-
+        return self.send_cper_raw(cper_data)
 
     def search_qom(self, path, prop, regex):
         """
Signature · 1 line
2.52.0
#6 lore raw

PATCH v2 5/13 scripts/qmp_helper: fix raw_data logic

In reply to Mauro Carvalho Chehab

According with UEFI 6.4 spec Table 18.11 Generic Error Status Block:

Raw Data Offset: Offset in bytes from the beginning of the
Error Status Block to raw error data. The raw data must follow any Generic Error Data Entries.

Data Length: Length in bytes of the generic error data.

So, basically, we have:

        +----------+                 /
        | GEBS     |                 |
        +----------+   /             |
        | GEDE     |   |             |
        | header   |   |             +--> raw data
        +----------+   +--> data     |    offset
        | GEDE     |   |    length   |
        | payload  |   |             |
        +----------+   /             /
        | Raw data |
        +----------+

where:

- raw data offset is relative to the beginning of GEBS;
- data length is only for GEDE header and payload.

The previous code was not calculating it right, as it was filling it with the size of GEBS and placing raw data before payload.

This is not a problem with default values, as they set raw data length to zero, but, at the moment raw data is filled, the generated CPERs becomes invalid.

Fix the code to calculate the offset according with the specs.

---
 scripts/qmp_helper.py | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
scripts/qmp_helper.py +14 -9
index ac3abc794c69..1587492807fe 100755
@@ -411,6 +411,7 @@ def _connect(self):
         "simulated":    util.bit(2),
     }
 
+    GENERIC_ERROR_STATUS_SIZE = 20
     GENERIC_DATA_SIZE = 72
 
     def argparse(parser):
@@ -551,7 +552,7 @@ def send_cper_raw(self, cper_data):
 
         return False
 
-    def get_gede(self, notif_type, cper_length):
+    def get_gede(self, notif_type, payload_length):
         """
         Return a Generic Error Data Entry bytearray
         """
@@ -563,22 +564,27 @@ def get_gede(self, notif_type, cper_length):
         util.data_add(gede, 0x300, 2)
         util.data_add(gede, self.validation_bits, 1)
         util.data_add(gede, self.flags, 1)
-        util.data_add(gede, cper_length, 4)
+        util.data_add(gede, payload_length, 4)
         gede.extend(self.fru_id)
         gede.extend(self.fru_text)
         gede.extend(self.timestamp)
 
         return gede
 
-    def get_gebs(self, data_length):
+    def get_gebs(self, payload_length):
         """
         Return a Generic Error Status Block bytearray
         """
 
+        data_length = payload_length
+        data_length += self.GENERIC_DATA_SIZE
+
         gebs = bytearray()
 
         if self.raw_data:
-            raw_data_offset = len(gebs)
+            raw_data_offset = payload_length
+            raw_data_offset += self.GENERIC_ERROR_STATUS_SIZE
+            raw_data_offset += self.GENERIC_DATA_SIZE
         else:
             raw_data_offset = 0
 
@@ -617,8 +623,7 @@ def send_cper(self, notif_type, payload,
         if raw_data:
             self.raw_data = raw_data
 
-        cper_length = len(payload)
-        data_length = cper_length + len(self.raw_data) + self.GENERIC_DATA_SIZE
+        payload_length = len(payload)
 
         if gede and len(gede) != 72:
             print(f"Invalid Generic Error Data Entry length: {len(gede)}. Ignoring it")
@@ -629,16 +634,16 @@ def send_cper(self, notif_type, payload,
             gebs = None
 
         if not gede:
-            gede = self.get_gede(notif_type, cper_length)
+            gede = self.get_gede(notif_type, payload_length)
 
         if not gebs:
-            gebs = self.get_gebs(data_length)
+            gebs = self.get_gebs(payload_length)
 
         cper_data = bytearray()
         cper_data.extend(gebs)
         cper_data.extend(gede)
-        cper_data.extend(bytearray(self.raw_data))
         cper_data.extend(bytearray(payload))
+        cper_data.extend(bytearray(self.raw_data))
 
         if self.debug:
             print(f"GUID: {notif_type}")
Signature · 1 line
2.52.0
#11 lore raw

PATCH v2 8/13 scripts/ghes_inject: exit 1 if command was not sent

In reply to Mauro Carvalho Chehab

add a return code to subparser func() and return 1 if the command failed.

---
 scripts/arm_processor_error.py | 2 +-
 scripts/ghes_inject.py         | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
scripts/arm_processor_error.py +1 -1
index 73d069f070d4..d9845adb0c0a 100644
@@ -473,4 +473,4 @@ def send_cper(self, args):
 
         self.data = data
 
-        qmp_cmd.send_cper(cper_guid.CPER_PROC_ARM, self.data)
+        return qmp_cmd.send_cper(cper_guid.CPER_PROC_ARM, self.data)
scripts/ghes_inject.py +2 -1
index 9a235201418b..6ac917d0b5db 100755
@@ -43,7 +43,8 @@ def main():
 
     args = parser.parse_args()
     if "func" in args:
-        args.func(args)
+        if not args.func(args):
+            sys.exit(1)
     else:
         sys.exit(f"Please specify a valid command for {sys.argv[0]}")
 
Signature · 1 line
2.52.0
#0 lore raw

v2 cover Add more commands to scripts/ghes_inject.py

Now that we have the basic stuff merged on QEMU, add more commands to scripts/ghes_inject.py. After this patch, this tool will support the following commands:

arm Inject an ARM processor error CPER, compatible with
UEFI 2.9A Errata.
pcie-bus Inject a PCIe bus error CPER
fuzzy-test (fuzzy) Inject fuzzy test CPER packets
raw-error (raw) Inject CPER records from previously recorded ones.

Where arm is a pre-existing one.

The pcie-bus command injects a PCIe bus error - currently not supported on Linux (GUID: c5753963-3b84-4095-bf78-eddad3f9c9dd).

The fuzzy-test command allows injecting one or more CPER records for all GUID types supported on UEFI 2.11, with its contents being either zero or random, and with the payload size that can also be random.

The raw-error command allow reproducing a CPER from a text file. It is helpful in conjunction with fuzzy-test to re-test the OSPM after some fixes.

Besides the commands, a new helper logic was added at scripts/ghes_decode.py: when the tool is called with the --debug command line argument, it will translate the injected record, allowing to compare what it was injected with what the OSPM/userspace tools would interpret.

The first 6 patches on this series improve the qmp_helper logic to support the new functionality.

The next 6 patches add the extra functionality to ghes_inject.

The final patch improves its help message when called without a command.

---

v2:
- the bus error injection is for PCI/PCI-X, not PCIe, so

    the command was renamed;
  - added notes that not all CXL types may occur in practice;
  - removed a field from common_fields at DecodeGhesEntry
    decode class and make it more robust;

- some cleanups at patch description.

Mauro Carvalho Chehab (13):
scripts/qmp_helper: add a return code to send_cper scripts/qmp_helper: add missing CXL UEFI GUID scripts/qmp_helper: add support for FRU Memory Poison scripts/qmp_helper: make send_cper() more generic scripts/qmp_helper: fix raw_data logic scripts/qmp_helper: add support for a timeout logic scripts/ghes_inject: add a logic to decode CPER scripts/ghes_inject: exit 1 if command was not sent scripts/ghes_inject: add a handler for PCI/PCI-X bus error scripts/ghes_inject: add support for fuzzy logic testing scripts/ghes_inject: add a raw error inject command scripts/ghes_inject: print help if no command specified scripts/ghes_inject: improve help message

 MAINTAINERS                    |    4 +
 scripts/arm_processor_error.py |    8 +-
 scripts/fuzzy_error.py         |  208 ++++++
 scripts/ghes_decode.py         | 1158 ++++++++++++++++++++++++++++++++
 scripts/ghes_inject.py         |   30 +-
 scripts/pci_bus_error.py       |  148 ++++
 scripts/qmp_helper.py          |  164 ++++-
 scripts/raw_error.py           |  175 +++++
 8 files changed, 1857 insertions(+), 38 deletions(-)
 create mode 100644 scripts/fuzzy_error.py
 create mode 100644 scripts/ghes_decode.py
 create mode 100644 scripts/pci_bus_error.py
 create mode 100644 scripts/raw_error.py
Signature · 1 line
2.52.0
#2 lore raw

PATCH v2 2/13 scripts/qmp_helper: add missing CXL UEFI GUID

The UEFI 2.11 - N.2.14. CXL Component Events Section states that CXL events are described at CXL specification 3.2:
8.2.10.2.1 Event Records
Table 8-55. Common Event Record Format

Add the GUIDs defined here to fuzzy logic error injection code.

It should be noticed that, while the section states that:

"This section defines the standard event record format
that all CXL devices shall use when reporting events to the host."

And the field at byte offset 0 has all the GUIDs below, in practice, not all those events will reach the OSPM, as some are fabric management events and OS management flows for dynamic capacity.

Yet, it is easier to keep the table in sync with the specs than to filter them out and justify why they won't need within CPER scope.

---
 scripts/qmp_helper.py | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
scripts/qmp_helper.py +30 -0
index 249a8c7187d1..46b85d68b793 100755
@@ -711,3 +711,33 @@ class cper_guid:
     CPER_CXL_PROT_ERR = guid(0x80B9EFB4, 0x52B5, 0x4DE3,
                              [0xA7, 0x77, 0x68, 0x78,
                               0x4B, 0x77, 0x10, 0x48])
+
+    # CXL GUIDs, as defined at CXL specification 3.2: 8.2.10.2.1 Event Records
+    # on Table 8-55. Common Event Record Format
+    #
+    # Please notice that, in practice, not all those events will be passed
+    # to OSPM. Some may be consumed internally
+    CPER_CXL_EVT_GEN_MEDIA = guid(0xFBCD0A77, 0xC260, 0x417F,
+                                  [0x85, 0xA9, 0x08, 0x8B,
+                                   0x16, 0x21, 0xEB, 0xA6])
+    CPER_CXL_EVT_DRAM = guid(0x601DCBB3, 0x9C06, 0x4EAB,
+                             [0xB8, 0xAF, 0x4E, 0x9B,
+                              0xFB, 0x5C, 0x96, 0x24])
+    CPER_CXL_EVT_MEM_MODULE = guid(0xFE927475, 0xDD59, 0x4339,
+                                   [0xA5, 0x86, 0x79, 0xBA,
+                                    0xB1, 0x13, 0xBC, 0x74])
+    CPER_CXL_EVT_MEM_SPARING = guid(0xE71F3A40, 0x2D29, 0x4092,
+                                    [0x8A, 0x39, 0x4D, 0x1C,
+                                     0x96, 0x6C, 0x7C, 0x65])
+    CPER_CXL_EVT_PHY_SW = guid(0x77CF9271, 0x9C02, 0x470B,
+                               [0x9F, 0xE4, 0xBC, 0x7B,
+                                0x75, 0xF2, 0xDA, 0x97])
+    CPER_CXL_EVT_VIRT_SW = guid(0x40D26425, 0x3396, 0x4C4D,
+                                [0xA5, 0xDA, 0x3D, 0x47,
+                                  0x2A, 0x63, 0xAF, 0x25])
+    CPER_CXL_EVT_MLD_PORT = guid(0x8DC44363, 0x0C96, 0x4710,
+                                 [0xB7, 0xBF, 0x04, 0xBB,
+                                  0x99, 0x53, 0x4C, 0x3F])
+    CPER_CXL_EVT_DYNA_CAP = guid(0xCA95AFA7, 0xF183, 0x4018,
+                                 [0x8C, 0x2F, 0x95, 0x26,
+                                  0x8E, 0x10, 0x1A, 0x2A])
Signature · 1 line
2.52.0
#9 lore raw

PATCH v2 7/13 scripts/ghes_inject: add a logic to decode CPER

In reply to Mauro Carvalho Chehab

Add a decoder to help debugging injected CPERs. This is more relevant when we add fuzzy-testing error inject, as the decoder is helpful to identify what it packages will be sent via QEMU to the firmware-fist logic.

By purpose, I opted to keep this completely independent from the encoders implementation, as this can be used even when there are no encoders for a certain GUID type (except for a fuzzy logic test, which is pretty much independent of the records meaning).

---
 MAINTAINERS            |    1 +
 scripts/ghes_decode.py | 1158 ++++++++++++++++++++++++++++++++++++++++
 scripts/qmp_helper.py  |    3 +
 3 files changed, 1162 insertions(+)
 create mode 100644 scripts/ghes_decode.py
MAINTAINERS +1 -0
index 36a2be3ddba7..a970c47dd089 100644
@@ -2225,6 +2225,7 @@ S: Maintained
 F: hw/arm/ghes_cper.c
 F: hw/acpi/ghes_cper_stub.c
 F: qapi/acpi-hest.json
+F: scripts/ghes_decode.py
 F: scripts/ghes_inject.py
 F: scripts/arm_processor_error.py
 F: scripts/qmp_helper.py
scripts/ghes_decode.py new file +1158 -0

1,158 lines not on this page · raw message

scripts/qmp_helper.py +3 -0
index d5ffd51f161e..3e5b7a6853cf 100755
@@ -21,6 +21,7 @@
     sys.path.append(os_path.join(qemu_dir, 'python'))
 
     from qemu.qmp.legacy import QEMUMonitorProtocol
+    from ghes_decode import DecodeGhesEntry
 
 except ModuleNotFoundError as exc:
     print(f"Module '{exc.name}' not found.")
@@ -677,6 +678,8 @@ def send_cper(self, notif_type, payload,
 
             util.dump_bytearray("Payload", payload)
 
+            DecodeGhesEntry(cper_data)
+
         return self.send_cper_raw(cper_data, timeout=timeout)
 
     def search_qom(self, path, prop, regex):
Signature · 1 line
2.52.0
#19 lore raw

PATCH v2 12/13 scripts/ghes_inject: print help if no command specified

In reply to Mauro Carvalho Chehab

The first positional argument (command) is mandatory. If not specified, instead of a simple error message, show help as well.

---
 scripts/ghes_inject.py | 3 +++
 1 file changed, 3 insertions(+)
scripts/ghes_inject.py +3 -0
index 63a8b28002e7..dd2b34a64f15 100755
@@ -52,6 +52,9 @@ def main():
         if not args.func(args):
             sys.exit(1)
     else:
+        print("Error: no command specified\n", file=sys.stderr)
+        parser.print_help(file=sys.stderr)
+        print(file=sys.stderr)
         sys.exit(f"Please specify a valid command for {sys.argv[0]}")
 
 if __name__ == "__main__":
Signature · 1 line
2.52.0
#17 lore raw

PATCH v2 11/13 scripts/ghes_inject: add a raw error inject command

In reply to Mauro Carvalho Chehab

Add a command to repeat a raw CPER record.

This helps to reproduce some condition that happened before.

The input format of the file is identical to the hexadecimal dump generated by ghes_inject tool.

---
 MAINTAINERS            |   1 +
 scripts/ghes_inject.py |   2 +
 scripts/raw_error.py   | 175 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 178 insertions(+)
 create mode 100644 scripts/raw_error.py
MAINTAINERS +1 -0
index 967aafc35a92..2e48df7abfb5 100644
@@ -2231,6 +2231,7 @@ F: scripts/arm_processor_error.py
 F: scripts/fuzzy_error.py
 F: scripts/pci_bus_error.py
 F: scripts/qmp_helper.py
+F: scripts/raw_error.py
 
 ppc4xx
 L: [email protected]
scripts/ghes_inject.py +2 -0
index bcbfffc586e1..63a8b28002e7 100755
@@ -14,6 +14,7 @@
 from arm_processor_error import ArmProcessorEinj
 from pci_bus_error import PciBusError
 from fuzzy_error import FuzzyError
+from raw_error import RawError
 
 EINJ_DESC = """
 Handle ACPI GHESv2 error injection logic QEMU QMP interface.
@@ -44,6 +45,7 @@ def main():
     ArmProcessorEinj(subparsers)
     PciBusError(subparsers)
     FuzzyError(subparsers)
+    RawError(subparsers)
 
     args = parser.parse_args()
     if "func" in args:
scripts/raw_error.py new file +175 -0

175 lines not on this page · raw message

Signature · 1 line
2.52.0
#21 lore raw

PATCH v2 13/13 scripts/ghes_inject: improve help message

In reply to Mauro Carvalho Chehab

Add a one-liner help message for each type of error inject command, and use raw formatter to keep line breaks.

While here, use a more uniform language.

With that, "ghes_inject -h" will now show:

usage: ghes_inject.py [options]

Handles ACPI GHESv2 error injection via the QEMU QMP interface.

It uses UEFI BIOS APEI features to generate GHES records, which helps to test CPER and GHES drivers on the guest OS and see how user‑space applications on that guest handle such errors.

positional arguments:
{arm,pci-bus,fuzzy-test,fuzzy,raw-error,raw}
arm Inject an ARM processor error CPER, compatible with
UEFI 2.9A Errata.
pci-bus Inject a PCI/PCI-X bus error CPER
fuzzy-test (fuzzy) Inject fuzzy test CPER packets
raw-error (raw) Inject CPER records from previously recorded ones.

options:
-h, --help show this help message and exit

QEMU QMP socket options:

    -H, --host HOST       host name (default: localhost)
    -P, --port PORT       TCP port number (default: 4445)
    -d, --debug           enable debug output (default: False)
---
 scripts/arm_processor_error.py |  6 ++++--
 scripts/fuzzy_error.py         |  4 +++-
 scripts/ghes_inject.py         | 18 +++++++++---------
 scripts/pci_bus_error.py       |  4 +++-
 scripts/raw_error.py           |  6 +++---
 5 files changed, 22 insertions(+), 16 deletions(-)
scripts/arm_processor_error.py +4 -2
index d9845adb0c0a..597382031ab8 100644
@@ -122,7 +122,7 @@ class ArmProcessorEinj:
     """
 
     DESC = """
-    Generates an ARM processor error CPER, compatible with
+    Inject an ARM processor error CPER, compatible with
     UEFI 2.9A Errata.
     """
 
@@ -169,7 +169,9 @@ def __init__(self, subparsers):
 
         self.data = bytearray()
 
-        parser = subparsers.add_parser("arm", description=self.DESC)
+        parser = subparsers.add_parser("arm",
+                                       help=self.DESC,
+                                       description=self.DESC)
 
         arm_valid_bits = ",".join(self.arm_valid_bits.keys())
         flags = ",".join(self.pei_flags.keys())
scripts/fuzzy_error.py +3 -1
index 9f80abb72319..3ddb90f743a1 100644
@@ -121,8 +121,10 @@ def __init__(self, subparsers):
             },
         }
 
+        DESC = "Inject fuzzy test CPER packets"
+
         parser = subparsers.add_parser("fuzzy-test", aliases=['fuzzy'],
-                                       description="Inject a fuzzy test CPER",
+                                       help=DESC, description=DESC,
                                        formatter_class=argparse.RawTextHelpFormatter)
         g_fuzzy = parser.add_argument_group("Fuzz testing error inject")
 
scripts/ghes_inject.py +9 -9
index dd2b34a64f15..21cdea774f17 100755
@@ -17,28 +17,28 @@
 from raw_error import RawError
 
 EINJ_DESC = """
-Handle ACPI GHESv2 error injection logic QEMU QMP interface.
+Handles ACPI GHESv2 error injection via the QEMU QMP interface.
 
-It allows using UEFI BIOS EINJ features to generate GHES records.
-
-It helps testing CPER and GHES drivers at the guest OS and how
-userspace applications at the guest handle them.
+It uses UEFI BIOS APEI features to generate GHES records, which helps to
+test CPER and GHES drivers on the guest OS and see how user‑space
+applications on that guest handle such errors.
 """
 
 def main():
     """Main program"""
 
     # Main parser - handle generic args like QEMU QMP TCP socket options
-    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
+    parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
                                      usage="%(prog)s [options]",
                                      description=EINJ_DESC)
 
     g_options = parser.add_argument_group("QEMU QMP socket options")
     g_options.add_argument("-H", "--host", default="localhost", type=str,
-                           help="host name")
+                           help="host name (default: %(default)s)")
     g_options.add_argument("-P", "--port", default=4445, type=int,
-                           help="TCP port number")
-    g_options.add_argument('-d', '--debug', action='store_true')
+                           help="TCP port number (default: %(default)s)")
+    g_options.add_argument('-d', '--debug', action='store_true',
+                           help="enable debug output (default: %(default)s)")
 
     subparsers = parser.add_subparsers()
 
scripts/pci_bus_error.py +3 -1
index 5abfdf11c868..87d1f7c95dd2 100644
@@ -35,8 +35,10 @@ def __init__(self, subparsers):
 
         self.data = bytearray()
 
+        DESC = "Inject a PCI/PCI-X bus error CPER"
+
         parser = subparsers.add_parser("pci-bus",
-                                       description="Generate PCI/PCI-X bus error CPER")
+                                       help=DESC, description=DESC)
         g_pci = parser.add_argument_group("PCI/PCI-X bus error")
 
         valid_bits = ",".join(self.valid_bits.keys())
scripts/raw_error.py +3 -3
index f5e77bdfcead..1e9eb1bcf15b 100644
@@ -21,8 +21,8 @@ class RawError:
 
     SCRIPT_NAME = sys.argv[0]
 
-    HELP=f"""
-    Inject a CPER record from a previously recorded one.
+    HELP="Inject CPER records from previously recorded ones."
+    DESC=HELP + f"""
 
     One or more CPER records can be recorded. The records to be
     injected are read from an specified file or from stdin and should
@@ -58,7 +58,7 @@ def __init__(self, subparsers):
         self.size = 0
 
         parser = subparsers.add_parser("raw-error",  aliases=['raw'],
-                                       description=self.HELP,
+                                       help=self.HELP, description=self.DESC,
                                        formatter_class=argparse.RawTextHelpFormatter)
 
         parser.add_argument("-f", "--file",
Signature · 1 line
2.52.0
#12 lore raw

PATCH v2 9/13 scripts/ghes_inject: add a handler for PCI/PCI-X bus error

In reply to Mauro Carvalho Chehab

Add a logic to do PCIe BUS error injection.

On Linux Kernel, despite CPER_SEC_PCI_X_BUS macro is defined for such event, ghes.c doesn't implement support for it yet:

[16950.077494] {26}[Hardware Error]: Hardware error from APEI Generic Hardware Error Source: 1
[16950.077866] {26}[Hardware Error]: event severity: recoverable
[16950.078118] {26}[Hardware Error]:  Error 0, type: recoverable
[16950.078444] {26}[Hardware Error]:   section type: unknown, c5753963-3b84-4095-bf78-eddad3f9c9dd
[16950.078800] {26}[Hardware Error]:   section length: 0x48
[16950.079069] {26}[Hardware Error]:   00000000: 00000000 00000000 00000000 00000000  ................
[16950.079442] {26}[Hardware Error]:   00000010: 00000001 00000000 00000000 00000000  ................
[16950.079811] {26}[Hardware Error]:   00000020: 00000000 00000000 00000000 00000000  ................
[16950.080181] {26}[Hardware Error]:   00000030: 00000000 00000000 00000000 00000000  ................
[16950.080538] {26}[Hardware Error]:   00000040: 00000000 00000000                    ........
---
 MAINTAINERS              |   1 +
 scripts/ghes_inject.py   |   2 +
 scripts/pci_bus_error.py | 146 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 149 insertions(+)
 create mode 100644 scripts/pci_bus_error.py
MAINTAINERS +1 -0
index a970c47dd089..1e62064a8672 100644
@@ -2228,6 +2228,7 @@ F: qapi/acpi-hest.json
 F: scripts/ghes_decode.py
 F: scripts/ghes_inject.py
 F: scripts/arm_processor_error.py
+F: scripts/pci_bus_error.py
 F: scripts/qmp_helper.py
 
 ppc4xx
scripts/ghes_inject.py +2 -0
index 6ac917d0b5db..be2384a59b3e 100755
@@ -12,6 +12,7 @@
 import sys
 
 from arm_processor_error import ArmProcessorEinj
+from pci_bus_error import PciBusError
 
 EINJ_DESC = """
 Handle ACPI GHESv2 error injection logic QEMU QMP interface.
@@ -40,6 +41,7 @@ def main():
     subparsers = parser.add_subparsers()
 
     ArmProcessorEinj(subparsers)
+    PciBusError(subparsers)
 
     args = parser.parse_args()
     if "func" in args:
scripts/pci_bus_error.py new file +146 -0

146 lines not on this page · raw message

Signature · 1 line
2.52.0
Reviewed-by Jonathan Cameron on v2 2/13
#3 lore raw

Re: [PATCH v2 02/13] scripts/qmp_helper: add missing CXL UEFI GUID

In reply to Mauro Carvalho Chehab
Quoted 13 lines · On Fri, 23 Jan 2026 14:35:16 +0100 Mauro Carvalho Chehab…

The UEFI 2.11 - N.2.14. CXL Component Events Section states that CXL events are described at CXL specification 3.2:
8.2.10.2.1 Event Records
Table 8-55. Common Event Record Format

Add the GUIDs defined here to fuzzy logic error injection code.

It should be noticed that, while the section states that:

"This section defines the standard event record format
that all CXL devices shall use when reporting events to the host."

Quoted 8 lines

And the field at byte offset 0 has all the GUIDs below, in practice, not all those events will reach the OSPM, as some are fabric management events and OS management flows for dynamic capacity.

Yet, it is easier to keep the table in sync with the specs than to filter them out and justify why they won't need within CPER scope.

Reviewed-by Jonathan Cameron on v2 6/13
#8 lore raw

Re: [PATCH v2 06/13] scripts/qmp_helper: add support for a timeout logic

In reply to Mauro Carvalho Chehab
Quoted 10 lines · On Fri, 23 Jan 2026 14:35:20 +0100 Mauro Carvalho Chehab…

We can't inject a new GHES record to the same source before it has been acked. There is an async mechanism to verify when the Kernel is ready, which is implemented at QEMU's ghes driver.

If error inject is too fast, QEMU may return an error. When such errors occur, implement a retry mechanism, based on a maximum timeout.

One comment where I think you intended to make a comment clearer.

Not important though

Quoted 32 lines
---
 scripts/qmp_helper.py | 47 +++++++++++++++++++++++++++++++------------
 1 file changed, 34 insertions(+), 13 deletions(-)
scripts/qmp_helper.py +3 -3
index 1587492807fe..d5ffd51f161e 100755
@@ -14,6 +14,7 @@
 
 from datetime import datetime
 from os import path as os_path
+from time import sleep
 
 try:
     qemu_dir = os_path.abspath(os_path.dirname(os_path.dirname(__file__)))
@@ -324,7 +325,8 @@ class qmp:
     Opens a connection and send/receive QMP commands.
     """
 
-    def send_cmd(self, command, args=None, may_open=False, return_error=True):
+    def send_cmd(self, command, args=None, may_open=False, return_error=True,
+                 timeout=None):
         """Send a command to QMP, optinally opening a connection"""
 
         if may_open:
@@ -336,12 +338,31 @@ def send_cmd(self, command, args=None, may_open=False, return_error=True):
         if args:
             msg['arguments'] = args
 
-        try:
-            obj = self.qmp_monitor.cmd_obj(msg)

scripts/qmp_helper.py def send_cmd(self, command, args=None, may_open=False, return_error=True): · line 346

Quoted 10 lines
scripts/qmp_helper.py +6 -4
-        # Can we use some other exception class here?
-        except Exception as e:                         # pylint: disable=W0718
-            print(f"Command: {command}")
-            print(f"Failed to inject error: {e}.")
+        if timeout and timeout > 0:
+            attempts = int(timeout * 10)
+        else:
+            attempts = 1
+
+        # Try up to attempts

From v1 thread:
https://lore.kernel.org/qemu-devel/[email protected]/T/#m5e70aed9fca30a24106ca39196bcf935da745722

I thought plan was to update this message?

Quoted 3 lines
scripts/qmp_helper.py +3 -0
+        for i in range(0, attempts):
+            try:
+                obj = self.qmp_monitor.cmd_obj(msg)
Reviewed-by Jonathan Cameron on v2 10/13
#15 lore raw

Re: [PATCH v2 10/13] scripts/ghes_inject: add support for fuzzy logic testing

In reply to Mauro Carvalho Chehab
Quoted 14 lines · On Fri, 23 Jan 2026 14:35:24 +0100 Mauro Carvalho Chehab…

Add a command to inject random errors for fuzzy logic testing.

By default, it will generate a single test for a random valid GUID with random bytes inside the CPER payload.

The command allows specifying:
- a single type of CPER;
- a range of minimum/maximum payload size;
- change its default to fill with zero instead of random;
- multiple CPERs with an specified count;
- ensure a delay between them;
- setup a timeout to retry if an attempt fails (useful when count > 1).

Quoted 1 line
Reviewed-by Jonathan Cameron on v2 7/13
#10 lore raw

Re: [PATCH v2 07/13] scripts/ghes_inject: add a logic to decode CPER

In reply to Mauro Carvalho Chehab
Quoted 5 lines · On Fri, 23 Jan 2026 14:35:21 +0100 Mauro Carvalho Chehab…

Add a decoder to help debugging injected CPERs. This is more relevant when we add fuzzy-testing error inject, as the decoder is helpful to identify what it packages will be sent via QEMU to the firmware-fist logic.

Quoted 7 lines

By purpose, I opted to keep this completely independent from the encoders implementation, as this can be used even when there are no encoders for a certain GUID type (except for a fuzzy logic test, which is pretty much independent of the records meaning).

Reviewed-by Jonathan Cameron on v2 12/13
#20 lore raw

Re: [PATCH v2 12/13] scripts/ghes_inject: print help if no command specified

In reply to Mauro Carvalho Chehab
Quoted 4 lines · On Fri, 23 Jan 2026 14:35:26 +0100 Mauro Carvalho Chehab…

The first positional argument (command) is mandatory. If not specified, instead of a simple error message, show help as well.

Seems unchanged so still...

#13 lore raw

Re: [PATCH v2 09/13] scripts/ghes_inject: add a handler for PCI/PCI-X bus error

In reply to Mauro Carvalho Chehab

scripts/pci_bus_error.py line 4

Quoted 10 lines · Mauro Carvalho Chehab
scripts/pci_bus_error.py new file +4 -0
new file mode 100644
index 000000000000..5abfdf11c868
@@ -0,0 +1,146 @@
+#!/usr/bin/env python3
+#
+# pylint: disable=C0114,R0903
+# SPDX-License-Identifier: GPL-2.0

GPL-2.0-or-later for qemu, please.

Or if there's a reason it's 2.0 only, pls document it.

Signature · 1 line
MST
#16 lore raw

Re: [PATCH v2 10/13] scripts/ghes_inject: add support for fuzzy logic testing

In reply to Mauro Carvalho Chehab

scripts/fuzzy_error.py line 4

Quoted 10 lines · Mauro Carvalho Chehab
scripts/fuzzy_error.py new file +4 -0
new file mode 100644
index 000000000000..9f80abb72319
@@ -0,0 +1,206 @@
+#!/usr/bin/env python3
+#
+# pylint: disable=C0114,R0903,R0912
+# SPDX-License-Identifier: GPL-2.0

2.0-or-later

#18 lore raw

Re: [PATCH v2 11/13] scripts/ghes_inject: add a raw error inject command

In reply to Mauro Carvalho Chehab

scripts/raw_error.py line 4

Quoted 10 lines
scripts/raw_error.py new file +4 -0
new file mode 100644
index 000000000000..f5e77bdfcead
@@ -0,0 +1,175 @@
+#!/usr/bin/env python3
+#
+# pylint: disable=C0114,R0903,R0912,R0914,R0915,R1732
+# SPDX-License-Identifier: GPL-2.0

GPL-2.0-or-later

#22 lore raw
In reply to Mauro Carvalho Chehab
Quoted 30 lines · Mauro Carvalho Chehab

Now that we have the basic stuff merged on QEMU, add more commands to scripts/ghes_inject.py. After this patch, this tool will support the following commands:

arm Inject an ARM processor error CPER, compatible with
UEFI 2.9A Errata.
pcie-bus Inject a PCIe bus error CPER
fuzzy-test (fuzzy) Inject fuzzy test CPER packets
raw-error (raw) Inject CPER records from previously recorded ones.

Where arm is a pre-existing one.

The pcie-bus command injects a PCIe bus error - currently not supported on Linux (GUID: c5753963-3b84-4095-bf78-eddad3f9c9dd).

The fuzzy-test command allows injecting one or more CPER records for all GUID types supported on UEFI 2.11, with its contents being either zero or random, and with the payload size that can also be random.

The raw-error command allow reproducing a CPER from a text file. It is helpful in conjunction with fuzzy-test to re-test the OSPM after some fixes.

Besides the commands, a new helper logic was added at scripts/ghes_decode.py: when the tool is called with the --debug command line argument, it will translate the injected record, allowing to compare what it was injected with what the OSPM/userspace tools would interpret.

Quoted 7 lines

The first 6 patches on this series improve the qmp_helper logic to support the new functionality.

The next 6 patches add the extra functionality to ghes_inject.

The final patch improves its help message when called without a command.

Pls run checkpatch on this and make sure the output is clean. Thanks!

Quoted 41 lines

---

v2:
- the bus error injection is for PCI/PCI-X, not PCIe, so

    the command was renamed;
  - added notes that not all CXL types may occur in practice;
  - removed a field from common_fields at DecodeGhesEntry
    decode class and make it more robust;

- some cleanups at patch description.

Mauro Carvalho Chehab (13):
scripts/qmp_helper: add a return code to send_cper scripts/qmp_helper: add missing CXL UEFI GUID scripts/qmp_helper: add support for FRU Memory Poison scripts/qmp_helper: make send_cper() more generic scripts/qmp_helper: fix raw_data logic scripts/qmp_helper: add support for a timeout logic scripts/ghes_inject: add a logic to decode CPER scripts/ghes_inject: exit 1 if command was not sent scripts/ghes_inject: add a handler for PCI/PCI-X bus error scripts/ghes_inject: add support for fuzzy logic testing scripts/ghes_inject: add a raw error inject command scripts/ghes_inject: print help if no command specified scripts/ghes_inject: improve help message

 MAINTAINERS                    |    4 +
 scripts/arm_processor_error.py |    8 +-
 scripts/fuzzy_error.py         |  208 ++++++
 scripts/ghes_decode.py         | 1158 ++++++++++++++++++++++++++++++++
 scripts/ghes_inject.py         |   30 +-
 scripts/pci_bus_error.py       |  148 ++++
 scripts/qmp_helper.py          |  164 ++++-
 scripts/raw_error.py           |  175 +++++
 8 files changed, 1857 insertions(+), 38 deletions(-)
 create mode 100644 scripts/fuzzy_error.py
 create mode 100644 scripts/ghes_decode.py
 create mode 100644 scripts/pci_bus_error.py
 create mode 100644 scripts/raw_error.py
Signature · 1 line
2.52.0
#23 lore raw
Quoted 34 lines · On Fri, 20 Feb 2026 13:03:01 -0500 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 33 lines · Mauro Carvalho Chehab

Now that we have the basic stuff merged on QEMU, add more commands to scripts/ghes_inject.py. After this patch, this tool will support the following commands:

arm Inject an ARM processor error CPER, compatible with
UEFI 2.9A Errata.
pcie-bus Inject a PCIe bus error CPER
fuzzy-test (fuzzy) Inject fuzzy test CPER packets
raw-error (raw) Inject CPER records from previously recorded ones.

Where arm is a pre-existing one.

The pcie-bus command injects a PCIe bus error - currently not supported on Linux (GUID: c5753963-3b84-4095-bf78-eddad3f9c9dd).

The fuzzy-test command allows injecting one or more CPER records for all GUID types supported on UEFI 2.11, with its contents being either zero or random, and with the payload size that can also be random.

The raw-error command allow reproducing a CPER from a text file. It is helpful in conjunction with fuzzy-test to re-test the OSPM after some fixes.

Besides the commands, a new helper logic was added at scripts/ghes_decode.py: when the tool is called with the --debug command line argument, it will translate the injected record, allowing to compare what it was injected with what the OSPM/userspace tools would interpret.

The first 6 patches on this series improve the qmp_helper logic to support the new functionality.

Quoted 8 lines
Quoted 4 lines

The next 6 patches add the extra functionality to ghes_inject.

The final patch improves its help message when called without a command.

Pls run checkpatch on this and make sure the output is clean. Thanks!

There are 3 warnings there due to the usage of the old SPDX "GPL2.0" which is identical to "GPL2.0-only", but were deprecated on SPDX 3.0. I'll fix those.

The remaining ones are mainly due to long strings, or, on two cases, related to very long class and/or method names that should be passed as long name parmeters, like here (*):

parser = subparsers.add_parser("raw-error", aliases=['raw'],
help=self.HELP, description=self.DESC, formatter_class=argparse.RawTextHelpFormatter)

I'll be fixing the ones that won't require mangling strings nor use some tricks that would otherwise make the source code for, IMO, no good reason.

(*) on this specific case, the "fix" would be to create an
"alias" class:

class Formatter(argparse.RawTextHelpFormatter):
pass

Just to make checkpatch happy. IMHO not worth it.

---

On a side note, IMHO checkpatch should be using a better default for Python, setting max columns max requirement to be 120 columns and ignoring or relaxing such limits on triple-quoted strings like here:

ERROR: line over 90 characters
#83: FILE: scripts/arm_processor_error.py:83:
+[Hardware Error]: bus error, operation type: Generic read (type of instruction or data request cannot be determined)

(this is part of a comment there describing the Linux Kernel output for an ARM Processor Error - we should not enforce any max column limit there)

Quoted 42 lines
Quoted 42 lines

---

v2:
- the bus error injection is for PCI/PCI-X, not PCIe, so

    the command was renamed;
  - added notes that not all CXL types may occur in practice;
  - removed a field from common_fields at DecodeGhesEntry
    decode class and make it more robust;

- some cleanups at patch description.

Mauro Carvalho Chehab (13):
scripts/qmp_helper: add a return code to send_cper scripts/qmp_helper: add missing CXL UEFI GUID scripts/qmp_helper: add support for FRU Memory Poison scripts/qmp_helper: make send_cper() more generic scripts/qmp_helper: fix raw_data logic scripts/qmp_helper: add support for a timeout logic scripts/ghes_inject: add a logic to decode CPER scripts/ghes_inject: exit 1 if command was not sent scripts/ghes_inject: add a handler for PCI/PCI-X bus error scripts/ghes_inject: add support for fuzzy logic testing scripts/ghes_inject: add a raw error inject command scripts/ghes_inject: print help if no command specified scripts/ghes_inject: improve help message

 MAINTAINERS                    |    4 +
 scripts/arm_processor_error.py |    8 +-
 scripts/fuzzy_error.py         |  208 ++++++
 scripts/ghes_decode.py         | 1158 ++++++++++++++++++++++++++++++++
 scripts/ghes_inject.py         |   30 +-
 scripts/pci_bus_error.py       |  148 ++++
 scripts/qmp_helper.py          |  164 ++++-
 scripts/raw_error.py           |  175 +++++
 8 files changed, 1857 insertions(+), 38 deletions(-)
 create mode 100644 scripts/fuzzy_error.py
 create mode 100644 scripts/ghes_decode.py
 create mode 100644 scripts/pci_bus_error.py
 create mode 100644 scripts/raw_error.py
Signature · 1 line
2.52.  
Signature · 2 lines
Thanks,
Mauro
#24 lore raw
Quoted 62 lines · Mauro Carvalho Chehab
Quoted 34 lines · On Fri, 20 Feb 2026 13:03:01 -0500 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 33 lines · Mauro Carvalho Chehab

Now that we have the basic stuff merged on QEMU, add more commands to scripts/ghes_inject.py. After this patch, this tool will support the following commands:

arm Inject an ARM processor error CPER, compatible with
UEFI 2.9A Errata.
pcie-bus Inject a PCIe bus error CPER
fuzzy-test (fuzzy) Inject fuzzy test CPER packets
raw-error (raw) Inject CPER records from previously recorded ones.

Where arm is a pre-existing one.

The pcie-bus command injects a PCIe bus error - currently not supported on Linux (GUID: c5753963-3b84-4095-bf78-eddad3f9c9dd).

The fuzzy-test command allows injecting one or more CPER records for all GUID types supported on UEFI 2.11, with its contents being either zero or random, and with the payload size that can also be random.

The raw-error command allow reproducing a CPER from a text file. It is helpful in conjunction with fuzzy-test to re-test the OSPM after some fixes.

Besides the commands, a new helper logic was added at scripts/ghes_decode.py: when the tool is called with the --debug command line argument, it will translate the injected record, allowing to compare what it was injected with what the OSPM/userspace tools would interpret.

The first 6 patches on this series improve the qmp_helper logic to support the new functionality.

Quoted 8 lines
Quoted 4 lines

The next 6 patches add the extra functionality to ghes_inject.

The final patch improves its help message when called without a command.

Pls run checkpatch on this and make sure the output is clean. Thanks!

There are 3 warnings there due to the usage of the old SPDX "GPL2.0" which is identical to "GPL2.0-only", but were deprecated on SPDX 3.0. I'll fix those.

The remaining ones are mainly due to long strings, or, on two cases, related to very long class and/or method names that should be passed as long name parmeters, like here (*):

parser = subparsers.add_parser("raw-error", aliases=['raw'],
help=self.HELP, description=self.DESC, formatter_class=argparse.RawTextHelpFormatter)

I'll be fixing the ones that won't require mangling strings nor use some tricks that would otherwise make the source code for, IMO, no good reason.

Quoted 7 lines

(*) on this specific case, the "fix" would be to create an
"alias" class:

class Formatter(argparse.RawTextHelpFormatter):
pass

Just to make checkpatch happy. IMHO not worth it.

Agreed.

Quoted 7 lines

---

On a side note, IMHO checkpatch should be using a better default for Python, setting max columns max requirement to be 120 columns and ignoring or relaxing such limits on triple-quoted strings like here:

Quoted 7 lines

ERROR: line over 90 characters
#83: FILE: scripts/arm_processor_error.py:83:
+[Hardware Error]: bus error, operation type: Generic read (type of instruction or data request cannot be determined)

(this is part of a comment there describing the Linux Kernel output for an ARM Processor Error - we should not enforce any max column limit there)

Linux switched to 100 for everything and I think we should, too.

Quoted 48 lines
Quoted 43 lines
Quoted 43 lines

---

v2:
- the bus error injection is for PCI/PCI-X, not PCIe, so

    the command was renamed;
  - added notes that not all CXL types may occur in practice;
  - removed a field from common_fields at DecodeGhesEntry
    decode class and make it more robust;

- some cleanups at patch description.

Mauro Carvalho Chehab (13):
scripts/qmp_helper: add a return code to send_cper scripts/qmp_helper: add missing CXL UEFI GUID scripts/qmp_helper: add support for FRU Memory Poison scripts/qmp_helper: make send_cper() more generic scripts/qmp_helper: fix raw_data logic scripts/qmp_helper: add support for a timeout logic scripts/ghes_inject: add a logic to decode CPER scripts/ghes_inject: exit 1 if command was not sent scripts/ghes_inject: add a handler for PCI/PCI-X bus error scripts/ghes_inject: add support for fuzzy logic testing scripts/ghes_inject: add a raw error inject command scripts/ghes_inject: print help if no command specified scripts/ghes_inject: improve help message

 MAINTAINERS                    |    4 +
 scripts/arm_processor_error.py |    8 +-
 scripts/fuzzy_error.py         |  208 ++++++
 scripts/ghes_decode.py         | 1158 ++++++++++++++++++++++++++++++++
 scripts/ghes_inject.py         |   30 +-
 scripts/pci_bus_error.py       |  148 ++++
 scripts/qmp_helper.py          |  164 ++++-
 scripts/raw_error.py           |  175 +++++
 8 files changed, 1857 insertions(+), 38 deletions(-)
 create mode 100644 scripts/fuzzy_error.py
 create mode 100644 scripts/ghes_decode.py
 create mode 100644 scripts/pci_bus_error.py
 create mode 100644 scripts/raw_error.py
Signature · 1 line
2.52.  
Signature · 2 lines
Thanks,
Mauro