Commit b2782920e0 for qemu.org

commit b2782920e039a1d6bc0eff03a0cad316ec10a8e5
Author: Gavin Shan <gshan@redhat.com>
Date:   Tue Dec 2 00:18:02 2025 +1000

    acpi/ghes: Bail early on error from get_ghes_source_offsets()

    In ghes_record_cper_errors(), get_ghes_source_offsets() can return
    a error initialized by error_setg(). Without bailing on this error,
    it can call into the second error_setg() due to the unexpected value
    returned from the read acknowledgement register. The second error_setg()
    can trigger assert(*errp == NULL) in its callee error_setv(), which
    isn't expected.

    Bail early in ghes_record_cper_errors() when error is received from
    get_ghes_source_offsets() to avoid the unexpected behavior.

    Signed-off-by: Gavin Shan <gshan@redhat.com>
    Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
    Reviewed-by: Markus Armbruster <armbru@redhat.com>
    Reviewed-by: Igor Mammedov <imammedo@redhat.com>
    Reviewed-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
    Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
    Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
    Message-Id: <20251201141803.2386129-5-gshan@redhat.com>

diff --git a/hw/acpi/ghes.c b/hw/acpi/ghes.c
index 4e6903a8d3..d51d4bd466 100644
--- a/hw/acpi/ghes.c
+++ b/hw/acpi/ghes.c
@@ -444,7 +444,7 @@ static void get_hw_error_offsets(uint64_t ghes_addr,
     *read_ack_register_addr = ghes_addr + sizeof(uint64_t);
 }

-static void get_ghes_source_offsets(uint16_t source_id,
+static bool get_ghes_source_offsets(uint16_t source_id,
                                     uint64_t hest_addr,
                                     uint64_t *cper_addr,
                                     uint64_t *read_ack_start_addr,
@@ -475,7 +475,7 @@ static void get_ghes_source_offsets(uint16_t source_id,
         /* For now, we only know the size of GHESv2 table */
         if (type != ACPI_GHES_SOURCE_GENERIC_ERROR_V2) {
             error_setg(errp, "HEST: type %d not supported.", type);
-            return;
+            return false;
         }

         /* Compare CPER source ID at the GHESv2 structure */
@@ -489,7 +489,7 @@ static void get_ghes_source_offsets(uint16_t source_id,
     }
     if (i == num_sources) {
         error_setg(errp, "HEST: Source %d not found.", source_id);
-        return;
+        return false;
     }

     /* Navigate through table address pointers */
@@ -509,6 +509,8 @@ static void get_ghes_source_offsets(uint16_t source_id,
     cpu_physical_memory_read(hest_read_ack_addr, read_ack_start_addr,
                              sizeof(*read_ack_start_addr));
     *read_ack_start_addr = le64_to_cpu(*read_ack_start_addr);
+
+    return true;
 }

 NotifierList acpi_generic_error_notifiers =
@@ -527,9 +529,10 @@ void ghes_record_cper_errors(AcpiGhesState *ags, const void *cper, size_t len,
     if (!ags->use_hest_addr) {
         get_hw_error_offsets(le64_to_cpu(ags->hw_error_le),
                              &cper_addr, &read_ack_register_addr);
-    } else {
-        get_ghes_source_offsets(source_id, le64_to_cpu(ags->hest_addr_le),
-                                &cper_addr, &read_ack_register_addr, errp);
+    } else if (!get_ghes_source_offsets(source_id,
+                    le64_to_cpu(ags->hest_addr_le),
+                    &cper_addr, &read_ack_register_addr, errp)) {
+            return;
     }

     cpu_physical_memory_read(read_ack_register_addr,