Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5173570rdb; Sat, 16 Sep 2023 06:05:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFH1PtHTKyYcFw5XVvk0pGx2YNrpL/sZTARQhmk9mA2bPx9iuVGoD8rXgF22+5GxmwOd82P X-Received: by 2002:a17:903:246:b0:1bf:6ad7:2286 with SMTP id j6-20020a170903024600b001bf6ad72286mr4265084plh.43.1694869556453; Sat, 16 Sep 2023 06:05:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694869556; cv=none; d=google.com; s=arc-20160816; b=qG4OWRGl/SjfPIcq9nSfUEVeqIrbHA9vh3EyanUuSkQstjyq8UPbm8V0sAJ7uCVni2 b5Whz7UVMNBxjLsRj4Qusum/gDPJ1wXRl1qXekDrat6Jy2v/o5NKvN/oSgnZHmhXsFd2 L0OTzeyd+aQIAMDqFRoO3eY8nWwVDfgp9SflYH27dkw2hAfzUN1azFF+Z1Bttm4uZ8Qj xsROpW1AtP7ScVCGWHiisBy06E0currqFGwHrtlr3lit6MrQPS75vbZX/lkImOj5lHNe 5m8vwIewzKeWdV4TD2I+tmXgWmAp0+vCDzhPYlG0mnEncXFNHFUAdIxKmmsA/N7ptUnS iIpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=19++vR8OerylIUBCdkXPucDjEPQq7qHru1d4PS1ijhY=; fh=FxxuQyV5zt5uOZlISi71Gibj4pONM7+jzC8ls2GxgWY=; b=hvge34I3i95sPEkaiR3rY4QtoctCJu8P4yLCWCRRAbMAXMl0quhAYtB8dOHAtywV1/ /MTTCjAYIfrqDctU4RGC4iMGg8kbjQrcoSdPxT7KYXyItTjnrIc54u/2mB3ZQ6dm5WIt vU4dGPUHVNy2Jd1KTDggBzj4oPVuu7LV+c65WBXmRjJapjNP8/KojB4lOpaKPjGz1PVT Hkd6nJzYApFKzYmtbg8SHV+L5ayefCqQnoXn81FCcHBPJmzAG9sW0AWWbivnW3Qomi1a Ncm9iSNwHZYIP260Eh9Q8DZ8G5jo1QhrIGkJ+VoiS778M8MMn2hZ9hMFNB81HRBWGLc0 5o8Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id kf3-20020a17090305c300b001bdf225d158si4825872plb.284.2023.09.16.06.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 06:05:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id E708A8357665; Sat, 16 Sep 2023 06:05:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239332AbjIPND5 (ORCPT + 99 others); Sat, 16 Sep 2023 09:03:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233025AbjIPNDj (ORCPT ); Sat, 16 Sep 2023 09:03:39 -0400 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95FC1CC2; Sat, 16 Sep 2023 06:03:31 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=xueshuai@linux.alibaba.com;NM=1;PH=DS;RN=22;SR=0;TI=SMTPD_---0VsA36vM_1694869406; Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0VsA36vM_1694869406) by smtp.aliyun-inc.com; Sat, 16 Sep 2023 21:03:28 +0800 From: Shuai Xue To: keescook@chromium.org, tony.luck@intel.com, gpiccoli@igalia.com, rafael@kernel.org, lenb@kernel.org, james.morse@arm.com, bp@alien8.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, ardb@kernel.org, robert.moore@intel.com Cc: linux-hardening@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-edac@vger.kernel.org, linux-efi@vger.kernel.org, acpica-devel@lists.linuxfoundation.org, xueshuai@linux.alibaba.com, baolin.wang@linux.alibaba.com Subject: [RFC PATCH 5/9] ACPI: APEI: GHES: Use ERST to serialize APEI generic error before panic Date: Sat, 16 Sep 2023 21:03:12 +0800 Message-Id: <20230916130316.65815-6-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230916130316.65815-1-xueshuai@linux.alibaba.com> References: <20230916130316.65815-1-xueshuai@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sat, 16 Sep 2023 06:05:26 -0700 (PDT) In certain scenarios (ie. hosts/guests with root filesystems on NFS/iSCSI where networking software and/or hardware fails, and thus kdump fails), it is necessary to serialize hardware error information available for post-mortem debugging. Save the hardware error log into flash via ERST before go panic, the hardware error log can be gotten from the flash after system boot successful again, which is very useful in production. Signed-off-by: Shuai Xue --- drivers/acpi/apei/ghes.c | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index d14e00751161..16701f889b73 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -636,6 +637,43 @@ static void ghes_defer_non_standard_event(struct acpi_hest_generic_data *gdata, schedule_work(&entry->work); } +static int ghes_serialize_estatus(struct acpi_hest_generic_data *gdata, u8 notify_type) +{ + void *err = acpi_hest_get_payload(gdata); + int data_len = gdata->error_data_length; + struct cper_pstore_record *rcd; + int record_len = data_len + sizeof(*rcd); + + rcd = kmalloc(record_len, GFP_KERNEL); + memset(rcd, 0, sizeof(rcd)); + + memcpy(rcd->hdr.signature, CPER_SIG_RECORD, CPER_SIG_SIZE); + rcd->hdr.revision = CPER_RECORD_REV; + rcd->hdr.signature_end = CPER_SIG_END; + rcd->hdr.section_count = 1; + rcd->hdr.error_severity = CPER_SEV_FATAL; + /* timestamp, platform_id, partition_id are all invalid */ + rcd->hdr.validation_bits = 0; + rcd->hdr.record_length = record_len; + rcd->hdr.creator_id = CPER_CREATOR_PSTORE; + rcd->hdr.notification_type = CPER_NOTIFY_MCE; + rcd->hdr.record_id = cper_next_record_id(); + rcd->hdr.flags = CPER_HW_ERROR_FLAGS_PREVERR; + + rcd->sec_hdr.section_offset = (void *)&rcd->data - (void *)&rcd; + rcd->sec_hdr.section_length = data_len; + rcd->sec_hdr.revision = CPER_SEC_REV; + /* ->ru_id and fru_text is invalid */ + rcd->sec_hdr.validation_bits = 0; + rcd->sec_hdr.flags = CPER_SEC_PRIMARY; + rcd->sec_hdr.section_type = gdata->section_type; + rcd->sec_hdr.section_severity = gdata->error_severity; + + memcpy(&rcd->data, err, data_len); + + return erst_write(&rcd->hdr); +} + static bool ghes_do_proc(struct ghes *ghes, const struct acpi_hest_generic_status *estatus) { @@ -861,10 +899,16 @@ static void __ghes_panic(struct ghes *ghes, struct acpi_hest_generic_status *estatus, u64 buf_paddr, enum fixed_addresses fixmap_idx) { + struct acpi_hest_generic_data *gdata; + u8 notify_type = ghes->generic->notify.type; + __ghes_print_estatus(KERN_EMERG, ghes->generic, estatus); ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx); + apei_estatus_for_each_section(estatus, gdata) + ghes_serialize_estatus(gdata, notify_type); + /* reboot to log the error! */ if (!panic_timeout) panic_timeout = ghes_panic_timeout; -- 2.41.0