From patchwork Wed Sep 20 18:03:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 142548 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp4332534vqi; Wed, 20 Sep 2023 11:13:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHQ53WeCz9RNFQlgwhhiu4CZFErxnTGrsGMDw/PKRIFsdBi9n/g/BzLbkdGQaNURkBC4HJ4 X-Received: by 2002:a05:6a20:2592:b0:15a:13f3:49ca with SMTP id k18-20020a056a20259200b0015a13f349camr3277904pzd.9.1695233634120; Wed, 20 Sep 2023 11:13:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695233634; cv=none; d=google.com; s=arc-20160816; b=fX6f6vejl9K6d+nBVcRRkzb/OOvYs1zZZAgxadJABLHUId42rieQ1Vm1BeOcV3lE+b eKM0TDktxDDpDy6movpEci27vi+J1bRABEP4AUq4MxHwnccRT2bZI4WMR7HE0iVEexEp 3M2OM7jfy0wfKC5jhPDRXAjnlAP2ovu9nfuquKbar//u9GJQCzG0oEQfdc+ouh0FSjDI kSa8w25j7Y3Nj9jWcvGwQZeAGJt97CK7ziaUENtxW8GcoISgnhFRX7IGC6ZlrPEZBH5Q suYfH00vb7gKVOPNeZ6l7zeJGfBPEale+ODSvacjm9VAUmEvbuaclH87PzbFx7SDty8J pJjg== 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 :message-id:date:subject:cc:to:from; bh=KQ7PTcHDexIVgC2qSHsF+qszhuIvKVLRqnZ7b1ah6HA=; fh=+2uhTD+U5suitMK/ECMS7aYIjYC0OEFTOViwMabGiiM=; b=UYpxPpsg4eH/+A436yyq7WL2twtFLFuTlGdQhfjmsDIx35l3WqpqvG70EMGDO8648A PJQwysxoEehorchlGZevcuxqumZpQJunLLUXmSUr+6Ck8AOSpQtBo1RyazA8wD3C55Gj PaT1kcJTYPBjio1C7VwdbzbvEt7VLPHtQiO12Evn08k1wZOhaEWTwqcJPsXn6E1uupLu YOpHGTCBzMAeRE3ntH/oL1+X28Rbj7JqbruuddGqJ29ExUoQsp0G0AbL7MuFfAKSQzV6 KoTrCf63G9RWU4hfLZH+gNLOF6GyhsRmqrxQdNy8W7e5cP8SpgGHRY11hfwZReLUWADP KU9A== 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:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id o66-20020a634145000000b00563de199314si12114419pga.896.2023.09.20.11.13.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 11:13:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 4C77181B4ADC; Wed, 20 Sep 2023 11:04:10 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229606AbjITSD7 (ORCPT + 27 others); Wed, 20 Sep 2023 14:03:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229600AbjITSD5 (ORCPT ); Wed, 20 Sep 2023 14:03:57 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7385A94; Wed, 20 Sep 2023 11:03:51 -0700 (PDT) Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4RrR9b1jYgz67hvQ; Thu, 21 Sep 2023 01:58:59 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Wed, 20 Sep 2023 19:03:48 +0100 From: To: , , , , , , , , , CC: , , , , Subject: [PATCH v3 1/1] ACPI / APEI: Fix for overwriting AER info when error status data has multiple sections Date: Thu, 21 Sep 2023 02:03:36 +0800 Message-ID: <20230920180337.809-1-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml500003.china.huawei.com (7.191.162.67) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Wed, 20 Sep 2023 11:04:10 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777456980143922455 X-GMAIL-MSGID: 1777581303160624283 From: Shiju Jose ghes_handle_aer() passes AER data to the PCI core for logging and recovery by calling aer_recover_queue() with a pointer to struct aer_capability_regs. The problem was that aer_recover_queue() queues the pointer directly without copying the aer_capability_regs data. The pointer was to the ghes->estatus buffer, which could be reused before aer_recover_work_func() reads the data. To avoid this problem, allocate a new aer_capability_regs structure from the ghes_estatus_pool, copy the AER data from the ghes->estatus buffer into it, pass a pointer to the new struct to aer_recover_queue(), and free it after aer_recover_work_func() has processed it. Reported-by: Bjorn Helgaas Acked-by: Bjorn Helgaas Signed-off-by: Shiju Jose --- Changes from v2 to v3: 1. Add stub code for ghes_estatus_pool_region_free() to fix following build error, reported by kernel test robot, if CONFIG_ACPI_APEI_GHES is not enabled. ld: drivers/pci/pcie/aer.o: in function `aer_recover_work_func': aer.c:(.text+0xec5): undefined reference to `ghes_estatus_pool_region_free' Changes from v1 to v2: 1. Updated patch description with the description Bjorn has suggested. 2. Add Acked-by: Bjorn Helgaas . --- drivers/acpi/apei/ghes.c | 23 ++++++++++++++++++++++- drivers/pci/pcie/aer.c | 10 ++++++++++ include/acpi/ghes.h | 4 ++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index ef59d6ea16da..63ad0541db38 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -209,6 +209,20 @@ int ghes_estatus_pool_init(unsigned int num_ghes) return -ENOMEM; } +/** + * ghes_estatus_pool_region_free - free previously allocated memory + * from the ghes_estatus_pool. + * @addr: address of memory to free. + * @size: size of memory to free. + * + * Returns none. + */ +void ghes_estatus_pool_region_free(unsigned long addr, u32 size) +{ + gen_pool_free(ghes_estatus_pool, addr, size); +} +EXPORT_SYMBOL_GPL(ghes_estatus_pool_region_free); + static int map_gen_v2(struct ghes *ghes) { return apei_map_generic_address(&ghes->generic_v2->read_ack_register); @@ -564,6 +578,7 @@ static void ghes_handle_aer(struct acpi_hest_generic_data *gdata) pcie_err->validation_bits & CPER_PCIE_VALID_AER_INFO) { unsigned int devfn; int aer_severity; + u8 *aer_info; devfn = PCI_DEVFN(pcie_err->device_id.device, pcie_err->device_id.function); @@ -577,11 +592,17 @@ static void ghes_handle_aer(struct acpi_hest_generic_data *gdata) if (gdata->flags & CPER_SEC_RESET) aer_severity = AER_FATAL; + aer_info = (void *)gen_pool_alloc(ghes_estatus_pool, + sizeof(struct aer_capability_regs)); + if (!aer_info) + return; + memcpy(aer_info, pcie_err->aer_info, sizeof(struct aer_capability_regs)); + aer_recover_queue(pcie_err->device_id.segment, pcie_err->device_id.bus, devfn, aer_severity, (struct aer_capability_regs *) - pcie_err->aer_info); + aer_info); } #endif } diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c index e85ff946e8c8..ba1ce820c141 100644 --- a/drivers/pci/pcie/aer.c +++ b/drivers/pci/pcie/aer.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include "../pci.h" @@ -996,6 +997,15 @@ static void aer_recover_work_func(struct work_struct *work) continue; } cper_print_aer(pdev, entry.severity, entry.regs); + /* + * Memory for aer_capability_regs(entry.regs) is being allocated from the + * ghes_estatus_pool to protect it from overwriting when multiple sections + * are present in the error status. Thus free the same after processing + * the data. + */ + ghes_estatus_pool_region_free((unsigned long)entry.regs, + sizeof(struct aer_capability_regs)); + if (entry.severity == AER_NONFATAL) pcie_do_recovery(pdev, pci_channel_io_normal, aer_root_reset); diff --git a/include/acpi/ghes.h b/include/acpi/ghes.h index 3c8bba9f1114..be1dd4c1a917 100644 --- a/include/acpi/ghes.h +++ b/include/acpi/ghes.h @@ -73,8 +73,12 @@ int ghes_register_vendor_record_notifier(struct notifier_block *nb); void ghes_unregister_vendor_record_notifier(struct notifier_block *nb); struct list_head *ghes_get_devices(void); + +void ghes_estatus_pool_region_free(unsigned long addr, u32 size); #else static inline struct list_head *ghes_get_devices(void) { return NULL; } + +static inline void ghes_estatus_pool_region_free(unsigned long addr, u32 size) { return; } #endif int ghes_estatus_pool_init(unsigned int num_ghes);