From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4259DC433EF for ; Wed, 2 Feb 2022 10:14:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=n1R5d2CmYlVDZHUAJF1eYoBk7J7SLAvLAGRWb9s43yw=; b=pd0bYbRImcJTSf 6PqfGVj3ATMKf/5aKWeX3xZbPS4nqZCar/nQewXwOVwh0hB2hSpZM+1nwV6chS7N8oDdteJ3WzPIg zVFZ4hCkIoTxe6iKqsSBviLDiG+ddqHsjSB9i0XnSe+GEnOxvoqL99OMAysKS0LgXS3ewvEhnvOkO ZpZIA9fz0hMEw/bnEHw4WPjxrWtT9aRz8JP7DPIP2FQRrQieJxPu9+yYGVX3qPOuqLJ5JocLFpmO+ ZR/gGFVajzWGz4pvW6VQ1GW5LVPWkGEeWePJTsyiDfye31zjNATzOWSN/OwAjIRU+EJqq6hv7pl14 +3TpqXfGEIkWIzb7eVLQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nFCdc-00EsVE-Hk; Wed, 02 Feb 2022 10:13:20 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nFCdY-00EsUT-Da for linux-arm-kernel@lists.infradead.org; Wed, 02 Feb 2022 10:13:18 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C65551FB; Wed, 2 Feb 2022 02:13:13 -0800 (PST) Received: from lpieralisi (e121166-lin.cambridge.arm.com [10.1.196.255]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DFD913F40C; Wed, 2 Feb 2022 02:13:12 -0800 (PST) Date: Wed, 2 Feb 2022 10:13:07 +0000 From: Lorenzo Pieralisi To: Robin Murphy Cc: guohanjun@huawei.com, sudeep.holla@arm.com, linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Michael Petlan Subject: Re: [PATCH] ACPI/IORT: Check node revision for PMCG resources Message-ID: <20220202101307.GA16459@lpieralisi> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220202_021316_594266_CEFC1299 X-CRM114-Status: GOOD ( 33.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Jan 31, 2022 at 03:03:24PM +0000, Robin Murphy wrote: > The original version of the IORT PMCG definition had an oversight > wherein there was no way to describe the second register page for an > implementation using the recommended RELOC_CTRS feature. Although the > spec was fixed, and the final patches merged to ACPICA and Linux written > against the new version, it seems that some old firmware based on the > original revision has survived and turned up in the wild. > > Add a check for the original PMCG definition, and avoid filling in the > second memory resource with nonsense if so. Otherwise it is likely that > something horrible will happen when the PMCG driver attempts to probe. > > Reported-by: Michael Petlan > Fixes: 24e516049360 ("ACPI/IORT: Add support for PMCG") > Signed-off-by: Robin Murphy > --- > drivers/acpi/arm64/iort.c | 17 ++++++++++------- > 1 file changed, 10 insertions(+), 7 deletions(-) > > diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c > index 3b23fb775ac4..aaa1f0411a5a 100644 > --- a/drivers/acpi/arm64/iort.c > +++ b/drivers/acpi/arm64/iort.c > @@ -1344,16 +1344,17 @@ static int __init arm_smmu_v3_pmcg_count_resources(struct acpi_iort_node *node) > pmcg = (struct acpi_iort_pmcg *)node->node_data; > > /* > - * There are always 2 memory resources. > - * If the overflow_gsiv is present then add that for a total of 3. > + * There should normally be 2 memory resources, but apparently the > + * oversight from IORT rev. C managed to escape into the wild. > */ > - return pmcg->overflow_gsiv ? 3 : 2; > + return 1 + (node->revision > 0) + (pmcg->overflow_gsiv != 0); It is compact but (nit) I'd rather use a construct like: if (node->revision > 0) res_cnt++; with a comment explaining it so that we can remember why the node revision implies an additional resource. Actually - I noticed that the logic in .dev_count_resources() and dev_init_resources() is somewhat duplicated - maybe we can add a resource_count param to dev_init_resources() but I am not sure it will improve things much. > } > > static void __init arm_smmu_v3_pmcg_init_resources(struct resource *res, > struct acpi_iort_node *node) > { > struct acpi_iort_pmcg *pmcg; > + int n = 1; > > /* Retrieve PMCG specific data */ > pmcg = (struct acpi_iort_pmcg *)node->node_data; > @@ -1361,13 +1362,15 @@ static void __init arm_smmu_v3_pmcg_init_resources(struct resource *res, > res[0].start = pmcg->page0_base_address; > res[0].end = pmcg->page0_base_address + SZ_4K - 1; > res[0].flags = IORESOURCE_MEM; > - res[1].start = pmcg->page1_base_address; > - res[1].end = pmcg->page1_base_address + SZ_4K - 1; > - res[1].flags = IORESOURCE_MEM; > + if (node->revision > 0) { > + res[n].start = pmcg->page1_base_address; > + res[n].end = pmcg->page1_base_address + SZ_4K - 1; > + res[n++].flags = IORESOURCE_MEM; > + } See above. If we knew the number of resource we could avoid repeating node->revision > 0 check but I don't think it would improve things anyway (ie we know how many resources we are allocating but we still need to check why a resource has to be added - eg node->revision > 0). Thanks, Lorenzo > if (pmcg->overflow_gsiv) > acpi_iort_register_irq(pmcg->overflow_gsiv, "overflow", > - ACPI_EDGE_SENSITIVE, &res[2]); > + ACPI_EDGE_SENSITIVE, &res[n]); > } > > static struct acpi_platform_list pmcg_plat_info[] __initdata = { > -- > 2.28.0.dirty > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel