From patchwork Mon Sep 25 07:44:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuai Xue X-Patchwork-Id: 144273 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1054328vqu; Mon, 25 Sep 2023 01:20:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGr/iIsgQBShWvHPeVoIdZqDRcyflMb4xWmb4zJ5TqloR1ejK6QC1d+/5oFYmxOdClhcH9s X-Received: by 2002:a17:90b:1103:b0:269:154b:6290 with SMTP id gi3-20020a17090b110300b00269154b6290mr5101477pjb.24.1695630054002; Mon, 25 Sep 2023 01:20:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695630053; cv=none; d=google.com; s=arc-20160816; b=RQeQB61LwmzFiTdEAEGN5rBFbZuYnoExB3Y8yfAn25HboAaYJ4ccj1NQ8BHvqwkegk j5gfJ0oOCysO4T81UuAqn4KZsdTKG667KUA7ItcpoqQuPc1nWc1lPvFZvGZTl8gBvnRD DK/hbfeCB/G1OYHonvgFFzrTSfjIu1q38BRczV2Xey5FtvVy6MeGD9MVfLznXyABNvCy n49yuTTIfVdRmdCna9NfymePp0DVF7jgCLVjKW+KM2ZyV26wtkH3XjXuesS9iopxLTSx Hyyp0SuziYXumDHY+0rci6xhhzFC3vzoUppjk/frVtYQxdDVnlGFrPNd58ctnLVkuKk1 u4wA== 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=jQh3T0VYNzdVNjcoAb/56Rb1Mc3Qg+EexF0fmrIY7jY=; fh=FxxuQyV5zt5uOZlISi71Gibj4pONM7+jzC8ls2GxgWY=; b=E3iaX/9rxz6tiMWHAWzcN+2UW4Ko6dGIj/zTr6em7yuJ/0xWxnyZnarC6lUCifdlyI boFHR3YmRqQlE3a4aU7O2UMi/khpPwKcH1hrlUxBcBckkiQdAoFUU3Aal3B68H7Wty7V m6TXEb60qpRg5eojSjzqaWRe1+Ne/LwBXdPIujG0rKEpWXIi9F6nNA4dtr9e942U6Q/n acibCSZVAKhoIDvis2/zPo7xinJUbGJ6zg/q/vtQMo3R28gK8lxOR335L969FFj3hh9/ Jia+XunY036ExCEltXYLk7iJh8J8qRZEvbguCZqltQ3aDZgasOfFOiVZ8oVdn/UaEL8S X5AQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id ob3-20020a17090b390300b00277496b6ec1si3253644pjb.34.2023.09.25.01.20.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 01:20:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 28EB182A676D; Mon, 25 Sep 2023 00:45:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232513AbjIYHpH (ORCPT + 30 others); Mon, 25 Sep 2023 03:45:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232494AbjIYHox (ORCPT ); Mon, 25 Sep 2023 03:44:53 -0400 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9C64FC; Mon, 25 Sep 2023 00:44:45 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=xueshuai@linux.alibaba.com;NM=1;PH=DS;RN=22;SR=0;TI=SMTPD_---0Vsmvt.x_1695627880; Received: from localhost.localdomain(mailfrom:xueshuai@linux.alibaba.com fp:SMTPD_---0Vsmvt.x_1695627880) by smtp.aliyun-inc.com; Mon, 25 Sep 2023 15:44:41 +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 v2 5/9] ACPI: APEI: GHES: Use ERST to serialize APEI generic error before panic Date: Mon, 25 Sep 2023 15:44:22 +0800 Message-Id: <20230925074426.97856-6-xueshuai@linux.alibaba.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230925074426.97856-1-xueshuai@linux.alibaba.com> References: <20230925074426.97856-1-xueshuai@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (howler.vger.email [0.0.0.0]); Mon, 25 Sep 2023 00:45:15 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777996979810099310 X-GMAIL-MSGID: 1777996979810099310 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..306bced16884 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;