From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 575843B184; Mon, 11 Dec 2023 15:30:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KYfQtKQq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0802C433C8; Mon, 11 Dec 2023 15:30:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702308633; bh=/Q/CO2qks8dFDHzFLXjWAPDdN+fTVkPHlrET0acGnpo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KYfQtKQqfbt28442XHv+EFC1AIN9ykQs7HiHfK60S/GFWPuNrPR21RFeG3odtUkj1 PQdLGeQ7Dj9r9gomv7Y96bzm6rEEb67gBL2swNErG64/tjOWml+uGFCNDutqFUuWYs bKBc92oC+gJTZ0cfo7pFXmwpv39v4hvlCtH6EU8vp21o/fwt1yuuSsG9ltmFSw8owj pjY2vBqTtpgm49TFlcShfsiAXfzygLabIQUSGpeLeOaEHtxso6Pa10H7OrmwC9fNMf 3KGgA+dzYMGZmEjxO0FYuwqeOOiSuZv9xx39lZD6s2m40mGFrGCHxmzsic+6dFyIe0 ymi88cjfcV9Ng== Date: Mon, 11 Dec 2023 15:30:24 +0000 From: Will Deacon To: Robin Murphy 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 Subject: Re: [PATCH 3/7] ACPI/IORT: Handle memory address size limits as limits Message-ID: <20231211153023.GA26048@willie-the-truck> References: <2ae6199a9cf035c1defd42e48675b827f41cdc95.1701268753.git.robin.murphy@arm.com> <20231211132757.GE25681@willie-the-truck> <91b22090-485f-49c9-a536-849fd7f92f8e@arm.com> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <91b22090-485f-49c9-a536-849fd7f92f8e@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) On Mon, Dec 11, 2023 at 03:01:27PM +0000, Robin Murphy wrote: > 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. Oh, I'd have thought you'd have gotten one of those "left shift count >= width of type" warnings if you did that. Will 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 97CDDC4167B for ; Mon, 11 Dec 2023 15:31:07 +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=qk/amIluJG65XCu5lYyqYi9XF5tl+5jym3u5yCxxqTw=; b=2P16K4Gd8Ds6Uc d+N9kGynplygo6dyFqeNksdhKDF7HkONx9lsCAw9z7E16xSTXWBkNoCqttdZGT0h3fr7WgmY+n729 7L93bJVrQMkSpYkhrkC6QmlKup3589cnKXOucwoLR/+v4UmZI7uSYxRVdqMYszmQJ3FJFmaaaugSS 2NkvFHOmzUAspFxpS1JF6hG9q3uU665DcPl85ph9WR99WEUynR8+Ou00fKVKMtvqmed5iKsdVSnk3 VK6w8bQ9zS0R67y5OzOANGWay8JC1l/+XwaILfA/NQKFin79Z1JLUs1B4IOcV7zJOIb12Mq35OQ3x P8r3zx4xgQfNgqxjRjvQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rCiEw-005RXh-2Z; Mon, 11 Dec 2023 15:30:38 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rCiEt-005RV5-2x for linux-arm-kernel@lists.infradead.org; Mon, 11 Dec 2023 15:30:37 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 5C724B80E9D; Mon, 11 Dec 2023 15:30:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0802C433C8; Mon, 11 Dec 2023 15:30:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702308633; bh=/Q/CO2qks8dFDHzFLXjWAPDdN+fTVkPHlrET0acGnpo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KYfQtKQqfbt28442XHv+EFC1AIN9ykQs7HiHfK60S/GFWPuNrPR21RFeG3odtUkj1 PQdLGeQ7Dj9r9gomv7Y96bzm6rEEb67gBL2swNErG64/tjOWml+uGFCNDutqFUuWYs bKBc92oC+gJTZ0cfo7pFXmwpv39v4hvlCtH6EU8vp21o/fwt1yuuSsG9ltmFSw8owj pjY2vBqTtpgm49TFlcShfsiAXfzygLabIQUSGpeLeOaEHtxso6Pa10H7OrmwC9fNMf 3KGgA+dzYMGZmEjxO0FYuwqeOOiSuZv9xx39lZD6s2m40mGFrGCHxmzsic+6dFyIe0 ymi88cjfcV9Ng== Date: Mon, 11 Dec 2023 15:30:24 +0000 From: Will Deacon To: Robin Murphy 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 Subject: Re: [PATCH 3/7] ACPI/IORT: Handle memory address size limits as limits Message-ID: <20231211153023.GA26048@willie-the-truck> References: <2ae6199a9cf035c1defd42e48675b827f41cdc95.1701268753.git.robin.murphy@arm.com> <20231211132757.GE25681@willie-the-truck> <91b22090-485f-49c9-a536-849fd7f92f8e@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <91b22090-485f-49c9-a536-849fd7f92f8e@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231211_073036_284602_048F2A82 X-CRM114-Status: GOOD ( 20.82 ) 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, Dec 11, 2023 at 03:01:27PM +0000, Robin Murphy wrote: > 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. Oh, I'd have thought you'd have gotten one of those "left shift count >= width of type" warnings if you did that. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel