Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp101657rdb; Mon, 18 Sep 2023 09:15:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhuSxDGdGc/qAg1wrfltXFAjfu+IUC8qyHjFUKh0qo7FaJjG8eEX2BIHbhqLTqf5ZD3Qc2 X-Received: by 2002:a05:6a20:3d24:b0:135:110c:c6e1 with SMTP id y36-20020a056a203d2400b00135110cc6e1mr9588306pzi.7.1695053717232; Mon, 18 Sep 2023 09:15:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695053717; cv=none; d=google.com; s=arc-20160816; b=0+MRykadbm90FvyH+d2l4t2l9pmxK52rXFDVEqNWsv7KlHJcyuK5/ws9CZxB51ZHEh caFeps+RM0tSqMCe13ucWkLRQC5YAmLcI/Lx9JdQddMlHiRpssBstb3W2uhMDdbJA+U+ PYKO7SCRrAmD4RdJsFu95RYZGjE9WEK/DMG3UM28lhofQGktY1/Eu/DGF5l+AyD/t6zO 0Kdf55jlDLzNzNM4aXty4uSZu8dFc74Dh4NP20MkSJlOFVYD43yvkqRbzvPrs1JT1tMl +APu+uTRF1s3mYfpI7E+x3Er0r1dsMPFaYfOp7DpjLyWLBpPZNoa7hlB08K4id5aqroQ Ewqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from; bh=pburVoZYDMinQmMTUj6vg0ILOtcoaoqXgilbsYyhz4Q=; fh=bIlvLLeasAf44w49GHnto/12mz01W/FK871Xxy9PAlg=; b=obNuvvINW6xJfd3MR8JUXOHf448EInBaHOPicuW9zCIj01VGqvwA6VmQ/G2qH/ndsW wlTpGLVHJrHi21fGLvPJ/OPwq/VVLKk4oPKosEtOTmv6MxV8yEtHlJ/gCH5FHOk1ngEB fKwKfSP+3namxYXvDpjLCyx/fZhjWN50aWF0y1sY+hGYDsi4vUdHGXMtaQn2ulsg9yiv PAfESk9tll6wfS6yKwNrULhrfYH1C3jYIUCeMaG4DmG9UsSnvD4QWkIM6mhGIty6Gi4R ocda/aYbO1ODr33Wed7F6p5MmxNpdysI9kMIg7i2gsQWLgZ2uR+Cg75JN37b5Q+uuCMh A1Wg== 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:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id e15-20020a6558cf000000b0055c8ad484a1si8192422pgu.125.2023.09.18.09.15.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 09:15:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id D287F80BB1D3; Mon, 18 Sep 2023 08:43:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229556AbjIRPm6 convert rfc822-to-8bit (ORCPT + 99 others); Mon, 18 Sep 2023 11:42:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229478AbjIRPm5 (ORCPT ); Mon, 18 Sep 2023 11:42:57 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E62A210CF; Mon, 18 Sep 2023 08:41:15 -0700 (PDT) Received: from lhrpeml500002.china.huawei.com (unknown [172.18.147.206]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Rq4nZ3dp0z6K6VQ; Mon, 18 Sep 2023 21:06:58 +0800 (CST) Received: from lhrpeml500006.china.huawei.com (7.191.161.198) by lhrpeml500002.china.huawei.com (7.191.160.78) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 18 Sep 2023 14:07:46 +0100 Received: from lhrpeml500006.china.huawei.com ([7.191.161.198]) by lhrpeml500006.china.huawei.com ([7.191.161.198]) with mapi id 15.01.2507.031; Mon, 18 Sep 2023 14:07:46 +0100 From: Shiju Jose To: Bjorn Helgaas CC: "rafael@kernel.org" , "lenb@kernel.org" , "tony.luck@intel.com" , "james.morse@arm.com" , "bp@alien8.de" , "ying.huang@intel.com" , "linux-acpi@vger.kernel.org" , "linux-pci@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Linuxarm , "Jonathan Cameron" , tanxiaofei , "Zengtao (B)" , Dave Jiang Subject: RE: [RFC PATCH 1/1] ACPI / APEI: Fix for overwriting aer info when error status data have multiple sections Thread-Topic: [RFC PATCH 1/1] ACPI / APEI: Fix for overwriting aer info when error status data have multiple sections Thread-Index: AQHZ5/xlHFbbDa4AFUWselBa5XX/GbAcX9qAgAQE/5A= Date: Mon, 18 Sep 2023 13:07:45 +0000 Message-ID: References: <20230915174435.779-1-shiju.jose@huawei.com> <20230915220219.GA122811@bhelgaas> In-Reply-To: <20230915220219.GA122811@bhelgaas> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.48.156.14] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 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 fry.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 (fry.vger.email [0.0.0.0]); Mon, 18 Sep 2023 08:43:07 -0700 (PDT) Hi Bjorn, >-----Original Message----- >From: Bjorn Helgaas >Sent: 15 September 2023 23:02 >To: Shiju Jose >Cc: rafael@kernel.org; lenb@kernel.org; tony.luck@intel.com; >james.morse@arm.com; bp@alien8.de; ying.huang@intel.com; linux- >acpi@vger.kernel.org; linux-pci@vger.kernel.org; linux-kernel@vger.kernel.org; >Linuxarm ; Jonathan Cameron >; tanxiaofei ; >Zengtao (B) ; Dave Jiang >Subject: Re: [RFC PATCH 1/1] ACPI / APEI: Fix for overwriting aer info when error >status data have multiple sections > >[+cc Dave, since CXL is also fiddling with aer.c] > >On Sat, Sep 16, 2023 at 01:44:35AM +0800, shiju.jose@huawei.com wrote: >> From: Shiju Jose >> >> ghes_handle_aer() lacks synchronization with aer_recover_work_func(), >> so when error status data have multiple sections, >> aer_recover_work_func() may use estatus data for aer_capability_regs after it >has been overwritten. >> >> The problem statement is here, >> https://lore.kernel.org/all/20230901225755.GA90053@bhelgaas/ >> >> In ghes_handle_aer() allocates memory for aer_capability_regs from the >> ghes_estatus_pool and copy data for aer_capability_regs from the >> estatus buffer. Free the memory in aer_recover_work_func() after >> processing the data using the ghes_estatus_pool_region_free() added. > >Thanks for working this up! I had it on my to-do list, but obviously had not gotten >to it yet. > >> Reported-by: Bjorn Helgaas >> Signed-off-by: Shiju Jose >> --- >> drivers/acpi/apei/ghes.c | 23 ++++++++++++++++++++++- >> drivers/pci/pcie/aer.c | 10 ++++++++++ >> include/acpi/ghes.h | 1 + >> 3 files changed, 33 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)); > >This is a very straightforward approach to fixing this, and it looks pretty >reasonable, although I'd rather not have to pull more GHES stuff into aer.c >(ghes.h and ghes_estatus_pool_region_free()). > >What I had in mind was to put a queue of aer_capability_regs on the PCI side >that could be used by both the APEI path and the native path. > >In the APEI path, platform firmware reads the error information from the >hardware, and it feeds into PCI AER via aer_recover_queue(). > >In the native path, Linux should be reading reads the same error information >from the hardware, but it feeds into PCI AER quite differently, via >aer_process_err_devices() and handle_error_source(). > >These paths are fundamentally doing the exact same thing, but the data >handling and dmesg logging are needlessly different. I'd like to see them get a >little more unified, so the native path could someday also feed into >aer_recover_queue(). > >Does that make any sense? Thanks for letting us know. Make sense, solution with in the AER looks better. > >> 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..388b614c11fd 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..40d89e161076 100644 >> --- a/include/acpi/ghes.h >> +++ b/include/acpi/ghes.h >> @@ -78,6 +78,7 @@ static inline struct list_head >> *ghes_get_devices(void) { return NULL; } #endif >> >> int ghes_estatus_pool_init(unsigned int num_ghes); >> +void ghes_estatus_pool_region_free(unsigned long addr, u32 size); >> >> static inline int acpi_hest_get_version(struct acpi_hest_generic_data >> *gdata) { >> -- >> 2.34.1 >> Thanks, Shiju