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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA464C4167B for ; Mon, 11 Dec 2023 15:01:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234943AbjLKPB3 (ORCPT ); Mon, 11 Dec 2023 10:01:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234618AbjLKPB2 (ORCPT ); Mon, 11 Dec 2023 10:01:28 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DF65FAB; Mon, 11 Dec 2023 07:01:33 -0800 (PST) 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 14658FEC; Mon, 11 Dec 2023 07:02:20 -0800 (PST) Received: from [10.57.85.194] (unknown [10.57.85.194]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 87DA73F738; Mon, 11 Dec 2023 07:01:28 -0800 (PST) Message-ID: <91b22090-485f-49c9-a536-849fd7f92f8e@arm.com> Date: Mon, 11 Dec 2023 15:01:27 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 3/7] ACPI/IORT: Handle memory address size limits as limits Content-Language: en-GB To: Will Deacon Cc: Joerg Roedel , Christoph Hellwig , Vineet Gupta , Russell King , Catalin Marinas , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Suravee Suthikulpanit , David Woodhouse , Lu Baolu , Niklas Schnelle , Matthew Rosato , Gerald Schaefer , Jean-Philippe Brucker , Rob Herring , Frank Rowand , Marek Szyprowski , Jason Gunthorpe , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, iommu@lists.linux.dev, devicetree@vger.kernel.org References: <2ae6199a9cf035c1defd42e48675b827f41cdc95.1701268753.git.robin.murphy@arm.com> <20231211132757.GE25681@willie-the-truck> From: Robin Murphy In-Reply-To: <20231211132757.GE25681@willie-the-truck> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023-12-11 1:27 pm, Will Deacon wrote: > On Wed, Nov 29, 2023 at 05:43:00PM +0000, Robin Murphy wrote: >> Return the Root Complex/Named Component memory address size limit as an >> inclusive limit value, rather than an exclusive size. This saves us >> having to special-case 64-bit overflow, and simplifies our caller too. >> >> Signed-off-by: Robin Murphy >> --- >> drivers/acpi/arm64/dma.c | 9 +++------ >> drivers/acpi/arm64/iort.c | 18 ++++++++---------- >> include/linux/acpi_iort.h | 4 ++-- >> 3 files changed, 13 insertions(+), 18 deletions(-) > > [...] > >> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c >> index 6496ff5a6ba2..eb64d8e17dd1 100644 >> --- a/drivers/acpi/arm64/iort.c >> +++ b/drivers/acpi/arm64/iort.c >> @@ -1367,7 +1367,7 @@ int iort_iommu_configure_id(struct device *dev, const u32 *input_id) >> { return -ENODEV; } >> #endif >> >> -static int nc_dma_get_range(struct device *dev, u64 *size) >> +static int nc_dma_get_range(struct device *dev, u64 *limit) >> { >> struct acpi_iort_node *node; >> struct acpi_iort_named_component *ncomp; >> @@ -1384,13 +1384,12 @@ static int nc_dma_get_range(struct device *dev, u64 *size) >> return -EINVAL; >> } >> >> - *size = ncomp->memory_address_limit >= 64 ? U64_MAX : >> - 1ULL<memory_address_limit; >> + *limit = (1ULL << ncomp->memory_address_limit) - 1; > > The old code handled 'ncomp->memory_address_limit >= 64' -- why is it safe > to drop that? You mention it in the cover letter, so clearly I'm missing > something! Because an unsigned shift by 64 or more generates 0 (modulo 2^64), thus subtracting 1 results in the correct all-bits-set value for an inclusive 64-bit limit. Thanks, Robin. >> >> return 0; >> } >> >> -static int rc_dma_get_range(struct device *dev, u64 *size) >> +static int rc_dma_get_range(struct device *dev, u64 *limit) >> { >> struct acpi_iort_node *node; >> struct acpi_iort_root_complex *rc; >> @@ -1408,8 +1407,7 @@ static int rc_dma_get_range(struct device *dev, u64 *size) >> return -EINVAL; >> } >> >> - *size = rc->memory_address_limit >= 64 ? U64_MAX : >> - 1ULL<memory_address_limit; >> + *limit = (1ULL << rc->memory_address_limit) - 1; > > Same thing here. > > Will