From nobody Sat Sep 6 17:00:14 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1757085356; cv=none; d=zohomail.com; s=zohoarc; b=Kgm7msmMCML96ddXFK+BkIjkXdT2PrjdIU9mJL9/XwKfXpj+bcj2zY8WO+8f/kHzw4II8b+JccXFvUt5gN0ndNlzUn4EtHj/NqHDfG5nNeehJ/h+uchxXh6D2Md18dNItftySV98ZbmMO51D6CZY1nyGZtnGHLn1uSopPY9mDI8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757085356; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vo5lVA+7jyRcODhOn70YU2AntMKomYts+WseF5AQARk=; b=HipqXH8bH1s3rwSnvT/LHQwutCRAMs34uJmQnX/aBNLqiTnitg7+vt1UstIQ0j7ZOL2oRuISDQGZdSnUKWZFnsg4Hi0TF6ky6qy+KuDR8ruyW1JO5/N2RmBax+ux6BcubvpE0ZgwFxkHplh0Do9O3hPBt+CjSOALBeetaod0hAs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1757085356431629.9764068725485; Fri, 5 Sep 2025 08:15:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uuY5s-0008Oa-Fv; Fri, 05 Sep 2025 11:11:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uuY5D-0007rG-Ka; Fri, 05 Sep 2025 11:10:36 -0400 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uuY50-0006SX-7K; Fri, 05 Sep 2025 11:10:34 -0400 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 22C41602A8; Fri, 5 Sep 2025 15:09:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 597E9C4CEFA; Fri, 5 Sep 2025 15:09:34 +0000 (UTC) Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1uuY49-0000000HEUj-2krY; Fri, 05 Sep 2025 17:09:29 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757084974; bh=zV1XxfwVkfujXO5/PMLy6iMH+Ny7TgwfatkfWtj2WZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BD1BpeOzVFQer9StSfvxuBuHbW1o+14yg5BlpPcHsHPTfML4Tz0ZPW5L/F9g8FbkJ 3b6V0h/NTaG69/pdjVViIIT+tKtAvCfXlXRSLUCL3KyQNuyt1yeTwjHqBcM9pPVMa4 Yd5V7fGvh1VK8P1qqSX5dpjXtMyI3iC+RY2kl+h113Bu5KGxjk9A96MDZS6/KHOmR1 OujtJTl2a3tHLdAZaJW9OBj6Cmi1bYJ1QMPX4uY1Ao5sSAVggGzZckySqRjirMA1NQ oDGiFCO90jF1DxIOsF/PKK7njt3NdtbFthR4WJF7xWFSO55ynM1pk+pOH1BWOb73z6 ZbP/cz+TJGvUQ== From: Mauro Carvalho Chehab To: Igor Mammedov , "Michael S . Tsirkin" Cc: Jonathan Cameron , Shiju Jose , qemu-arm@nongnu.org, qemu-devel@nongnu.org, Mauro Carvalho Chehab , Ani Sinha , Dongjiu Geng , Paolo Bonzini , Peter Maydell , kvm@vger.kernel.org Subject: [PATCH v11 02/17] acpi/ghes: Cleanup the code which gets ghes ged state Date: Fri, 5 Sep 2025 17:09:09 +0200 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2600:3c04:e001:324:0:1991:8:25; envelope-from=mchehab+huawei@kernel.org; helo=tor.source.kernel.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1757085357278116600 Move the check logic into a common function and simplify the code which checks if GHES is enabled and was properly setup. Signed-off-by: Mauro Carvalho Chehab Reviewed-by: Jonathan Cameron Reviewed-by: Igor Mammedov --- hw/acpi/ghes-stub.c | 7 ++++--- hw/acpi/ghes.c | 38 +++++++++++--------------------------- include/hw/acpi/ghes.h | 14 +++++++------- target/arm/kvm.c | 7 +++++-- 4 files changed, 27 insertions(+), 39 deletions(-) diff --git a/hw/acpi/ghes-stub.c b/hw/acpi/ghes-stub.c index 7cec1812dad9..40f660c246fe 100644 --- a/hw/acpi/ghes-stub.c +++ b/hw/acpi/ghes-stub.c @@ -11,12 +11,13 @@ #include "qemu/osdep.h" #include "hw/acpi/ghes.h" =20 -int acpi_ghes_memory_errors(uint16_t source_id, uint64_t physical_address) +int acpi_ghes_memory_errors(AcpiGhesState *ags, uint16_t source_id, + uint64_t physical_address) { return -1; } =20 -bool acpi_ghes_present(void) +AcpiGhesState *acpi_ghes_get_state(void) { - return false; + return NULL; } diff --git a/hw/acpi/ghes.c b/hw/acpi/ghes.c index b709c177cdea..84b891fd3dcf 100644 --- a/hw/acpi/ghes.c +++ b/hw/acpi/ghes.c @@ -360,18 +360,12 @@ void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgSt= ate *s, /* Create a read-write fw_cfg file for Address */ fw_cfg_add_file_callback(s, ACPI_HW_ERROR_ADDR_FW_CFG_FILE, NULL, NULL, NULL, &(ags->hw_error_le), sizeof(ags->hw_error_le), false); - - ags->present =3D true; } =20 static void get_hw_error_offsets(uint64_t ghes_addr, uint64_t *cper_addr, uint64_t *read_ack_register_addr) { - if (!ghes_addr) { - return; - } - /* * non-HEST version supports only one source, so no need to change * the start offset based on the source ID. Also, we can't validate @@ -390,35 +384,20 @@ static void get_hw_error_offsets(uint64_t ghes_addr, *read_ack_register_addr =3D ghes_addr + sizeof(uint64_t); } =20 -void ghes_record_cper_errors(const void *cper, size_t len, +void ghes_record_cper_errors(AcpiGhesState *ags, const void *cper, size_t = len, uint16_t source_id, Error **errp) { uint64_t cper_addr =3D 0, read_ack_register_addr =3D 0, read_ack_regis= ter; - AcpiGedState *acpi_ged_state; - AcpiGhesState *ags; =20 if (len > ACPI_GHES_MAX_RAW_DATA_LENGTH) { error_setg(errp, "GHES CPER record is too big: %zd", len); return; } =20 - acpi_ged_state =3D ACPI_GED(object_resolve_path_type("", TYPE_ACPI_GED, - NULL)); - if (!acpi_ged_state) { - error_setg(errp, "Can't find ACPI_GED object"); - return; - } - ags =3D &acpi_ged_state->ghes_state; - assert(ACPI_GHES_ERROR_SOURCE_COUNT =3D=3D 1); get_hw_error_offsets(le64_to_cpu(ags->hw_error_le), &cper_addr, &read_ack_register_addr); =20 - if (!cper_addr) { - error_setg(errp, "can not find Generic Error Status Block"); - return; - } - cpu_physical_memory_read(read_ack_register_addr, &read_ack_register, sizeof(read_ack_register)= ); =20 @@ -444,7 +423,8 @@ void ghes_record_cper_errors(const void *cper, size_t l= en, return; } =20 -int acpi_ghes_memory_errors(uint16_t source_id, uint64_t physical_address) +int acpi_ghes_memory_errors(AcpiGhesState *ags, uint16_t source_id, + uint64_t physical_address) { /* Memory Error Section Type */ const uint8_t guid[] =3D @@ -470,7 +450,7 @@ int acpi_ghes_memory_errors(uint16_t source_id, uint64_= t physical_address) acpi_ghes_build_append_mem_cper(block, physical_address); =20 /* Report the error */ - ghes_record_cper_errors(block->data, block->len, source_id, &errp); + ghes_record_cper_errors(ags, block->data, block->len, source_id, &errp= ); =20 g_array_free(block, true); =20 @@ -482,7 +462,7 @@ int acpi_ghes_memory_errors(uint16_t source_id, uint64_= t physical_address) return 0; } =20 -bool acpi_ghes_present(void) +AcpiGhesState *acpi_ghes_get_state(void) { AcpiGedState *acpi_ged_state; AcpiGhesState *ags; @@ -491,8 +471,12 @@ bool acpi_ghes_present(void) NULL)); =20 if (!acpi_ged_state) { - return false; + return NULL; } ags =3D &acpi_ged_state->ghes_state; - return ags->present; + + if (!ags->hw_error_le) { + return NULL; + } + return ags; } diff --git a/include/hw/acpi/ghes.h b/include/hw/acpi/ghes.h index 39619a2457cb..f96ac3e85ca2 100644 --- a/include/hw/acpi/ghes.h +++ b/include/hw/acpi/ghes.h @@ -66,7 +66,6 @@ enum { =20 typedef struct AcpiGhesState { uint64_t hw_error_le; - bool present; /* True if GHES is present at all on this board */ } AcpiGhesState; =20 void acpi_build_hest(GArray *table_data, GArray *hardware_errors, @@ -74,15 +73,16 @@ void acpi_build_hest(GArray *table_data, GArray *hardwa= re_errors, const char *oem_id, const char *oem_table_id); void acpi_ghes_add_fw_cfg(AcpiGhesState *vms, FWCfgState *s, GArray *hardware_errors); -int acpi_ghes_memory_errors(uint16_t source_id, uint64_t error_physical_ad= dr); -void ghes_record_cper_errors(const void *cper, size_t len, +int acpi_ghes_memory_errors(AcpiGhesState *ags, uint16_t source_id, + uint64_t error_physical_addr); +void ghes_record_cper_errors(AcpiGhesState *ags, const void *cper, size_t = len, uint16_t source_id, Error **errp); =20 /** - * acpi_ghes_present: Report whether ACPI GHES table is present + * acpi_ghes_get_state: Get a pointer for ACPI ghes state * - * Returns: true if the system has an ACPI GHES table and it is - * safe to call acpi_ghes_memory_errors() to record a memory error. + * Returns: a pointer to ghes state if the system has an ACPI GHES table, + * NULL, otherwise. */ -bool acpi_ghes_present(void); +AcpiGhesState *acpi_ghes_get_state(void); #endif diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 667234485547..cce89f45fe6b 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -2357,10 +2357,12 @@ void kvm_arch_on_sigbus_vcpu(CPUState *c, int code,= void *addr) { ram_addr_t ram_addr; hwaddr paddr; + AcpiGhesState *ags; =20 assert(code =3D=3D BUS_MCEERR_AR || code =3D=3D BUS_MCEERR_AO); =20 - if (acpi_ghes_present() && addr) { + ags =3D acpi_ghes_get_state(); + if (ags && addr) { ram_addr =3D qemu_ram_addr_from_host(addr); if (ram_addr !=3D RAM_ADDR_INVALID && kvm_physical_memory_addr_from_host(c->kvm_state, addr, &paddr)= ) { @@ -2378,7 +2380,8 @@ void kvm_arch_on_sigbus_vcpu(CPUState *c, int code, v= oid *addr) */ if (code =3D=3D BUS_MCEERR_AR) { kvm_cpu_synchronize_state(c); - if (!acpi_ghes_memory_errors(ACPI_HEST_SRC_ID_SEA, paddr))= { + if (!acpi_ghes_memory_errors(ags, ACPI_HEST_SRC_ID_SEA, + paddr)) { kvm_inject_arm_sea(c); } else { error_report("failed to record the error"); --=20 2.51.0