From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="Kd6WeysL" Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2374E8 for ; Mon, 11 Dec 2023 07:36:35 -0800 (PST) Received: by mail-qv1-xf34.google.com with SMTP id 6a1803df08f44-67a9be1407aso30137886d6.0 for ; Mon, 11 Dec 2023 07:36:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1702308995; x=1702913795; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=h1q90IyUaHdLCptoKkTSBnvLA7N8/ZWOhYeli5kaqA4=; b=Kd6WeysLupP/7Ajdb+oLoJYeErg+1AyWELbof8xQpToPzW0tzf2R/xKDDmgy1XjGKt HCrYIWl8mxLWrPTNhUHjTAftXwheT2qHvkgdG6AX5cNl6IOoaWoNVAAdRn/FhxukcGbF Gfr/8uijIjWY68zll/7HfwzVvSlGRiIg3o+PqNvZyrLDgPMXyA2t9nmIasp6PFZARViZ Ae8OLgjHR4pdnT0tVANBcdHd52mT3enV5K5YddwlpvuwgAhUC0lSH1/1yhosT5ylkpGk QWdfUQRhyaXH0jlq7/h4kFgHsJfp4npTkoWPHF0ESG9MGgQ/Kjhoi+L7hoorSbFDgXV7 dz3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702308995; x=1702913795; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=h1q90IyUaHdLCptoKkTSBnvLA7N8/ZWOhYeli5kaqA4=; b=Ld4vAW2KjjW3aVHHuw0m5M52bpy1CmjOWpe3UU1Ywuv7berurnHRF+5oNoZrKrsJ9e DJeHcurHVHBVjTivtqs6YVDq+RXcoxmjKV4h1ZGMQBb/+DOvdMYDMDudtO8IZ7WNFWFq gx0y8BPjzLzeAhVguvg9IJmQ6j0aP48BCd5P39WR21/7DByLF2cbLZpuDkgNPvv6TDZy 3A8iALjbkylZLZ/FRrp5Jp+Nug6b00Yfg5/JuZ95fYb3VElzlB2SRhTfWCoqHF+EP5SA +mQDNlf2HXXi8mOUhL4tIcnMkQytV3VpjQAgD/BXa+KPpR9lWbjyWjsbpeXiSDzTVZn0 VjpA== X-Gm-Message-State: AOJu0YyNylp/08ijMEhDW6hDVaitD1WsAehVFEvKuAGslup6II3RBlO0 B3209fPxyG+xkySO02TZG1zRwQ== X-Google-Smtp-Source: AGHT+IE8NOv9U3J00bm5dbyWdx4BsSKRZT/5tARJRo3dRn9euR4880YaUsJYjW9+kaMr2xVXZQP3Xw== X-Received: by 2002:a0c:ee47:0:b0:67a:b99e:4228 with SMTP id m7-20020a0cee47000000b0067ab99e4228mr4459026qvs.52.1702308994824; Mon, 11 Dec 2023 07:36:34 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-134-23-187.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.134.23.187]) by smtp.gmail.com with ESMTPSA id g2-20020ad45102000000b0067a1e5ef6b1sm3324868qvp.106.2023.12.11.07.36.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 07:36:34 -0800 (PST) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1rCiKf-00Ccc2-Kg; Mon, 11 Dec 2023 11:36:33 -0400 Date: Mon, 11 Dec 2023 11:36:33 -0400 From: Jason Gunthorpe To: Will Deacon Cc: Robin Murphy , 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 , 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: <20231211153633.GD1489931@ziepe.ca> References: <2ae6199a9cf035c1defd42e48675b827f41cdc95.1701268753.git.robin.murphy@arm.com> <20231211132757.GE25681@willie-the-truck> <91b22090-485f-49c9-a536-849fd7f92f8e@arm.com> <20231211153023.GA26048@willie-the-truck> 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: <20231211153023.GA26048@willie-the-truck> On Mon, Dec 11, 2023 at 03:30:24PM +0000, Will Deacon wrote: > 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. Yes, UBSAN generates warnings for these cases. I'm not sure if it is actually undefined C behavior or just "suspicious", but such is what it is.. Jason 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 A257AC4167B for ; Mon, 11 Dec 2023 17:14:57 +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=f2BsfDUgKuwOoctBI5DxURj092warYgDgeIEfWlpf3k=; b=xw23gE/iQbHIJF RZ87Q7u2eZirskiBhLRIDP4DIzcsSRQ+NgDkwxlLkyJho6XEF/espUzofplfse7mLDr4kRFtpB8ul myzBjo6aQbvix/1rsEjrZCtB7p5AoK57mMCqAikSPek0MFwkX4lr+r54y/v19RmJvfNkZA0gm84b4 KKYvvoeeCSC+tKJiizW4hjHMoluTPnbqi4Mz4LrB+iUWdO4iF9cbDbE5HIVa3vm4M+shlS91sGq7d M2TNaUmbT/CfUQ2ZVBeamkCGi2MvGGS/6GsaIXAjz4m3rmfXJ1teEGkRyqwxR6FqF53aHN6ByZwZy NVonT2mZpdPx0jAkrwNw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rCjrJ-006BOT-0u; Mon, 11 Dec 2023 17:14:21 +0000 Received: from mail-il1-x12b.google.com ([2607:f8b0:4864:20::12b]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rCjrG-006BM0-0g for linux-arm-kernel@lists.infradead.org; Mon, 11 Dec 2023 17:14:19 +0000 Received: by mail-il1-x12b.google.com with SMTP id e9e14a558f8ab-35d718382b7so20202475ab.1 for ; Mon, 11 Dec 2023 09:14:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1702314856; x=1702919656; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=h1q90IyUaHdLCptoKkTSBnvLA7N8/ZWOhYeli5kaqA4=; b=LgrZSvSI3tAtdR6/bqsvIoAZ5yJYsAjay2bDxwSKnPc0V3I85XxLkE4Hh9KASEYdwv inF7yKr+rVReocEdFHl+gC7wDwqQJqSuSYe1EOg5i5WTzBCSA4al28dDgBcGl/DGoMB6 7JCW3geSQynOsOJCTH9zLd7eerejSSY3akfRLQoQzXyq6GkaQZZ5r8jrvlv5XhTR0PYx D5P+GodoIdJi7CC9BD/92gpiWMJtYTHoWkLg3Q/Mg66Us7hvTEe0dUtcPVPJgO1/BF6I keWtOGUV+4dEEsLRGa0hQrsGUEbRA9Co8o8OURJnqeMhoWHA22ZcmWnHJ4GiaWajyZpe DoZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702314856; x=1702919656; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=h1q90IyUaHdLCptoKkTSBnvLA7N8/ZWOhYeli5kaqA4=; b=UIGi1l8OdWLpxiAHhHLUGDlM91+86NyJzIKvz/bnhSzMab17Wtbc0At+QOzSZxhTK3 XldQ3xJ2cVEM/Rvcr10pBs153UhipAytwp1n0VHWnStv75z+P2auft96NrNBY3Xs1qUb xZbvNNBehg/JCjB/tiV3MKLhxiUvE+osr1qW/ls4mNN8hPv0oKRiqRZXwkSpoWK02K2m W/L8glF2j9dkv3o0jdOQs/80i1TOjzhofsaCO6z9LgnLzcUY9yGOrca4V31CKQpAtTe+ I8sJ+s4kIL1hBCwG5Jya8MQQu11C1jSSVSXD13T0PEfeb0tmJ7edUJ9U8GMkMAu1mgEu WN0A== X-Gm-Message-State: AOJu0Yz8A3iQ2WBnkqSchc2VEB5eDImcFNKEOZvKB78J6dJmiMdKy6mg bhn1vgFdR49244IMu8Brejh/+nVd4YzpZ4oEQss= X-Google-Smtp-Source: AGHT+IE8NOv9U3J00bm5dbyWdx4BsSKRZT/5tARJRo3dRn9euR4880YaUsJYjW9+kaMr2xVXZQP3Xw== X-Received: by 2002:a0c:ee47:0:b0:67a:b99e:4228 with SMTP id m7-20020a0cee47000000b0067ab99e4228mr4459026qvs.52.1702308994824; Mon, 11 Dec 2023 07:36:34 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-134-23-187.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.134.23.187]) by smtp.gmail.com with ESMTPSA id g2-20020ad45102000000b0067a1e5ef6b1sm3324868qvp.106.2023.12.11.07.36.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 07:36:34 -0800 (PST) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1rCiKf-00Ccc2-Kg; Mon, 11 Dec 2023 11:36:33 -0400 Date: Mon, 11 Dec 2023 11:36:33 -0400 From: Jason Gunthorpe To: Will Deacon Cc: Robin Murphy , 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 , 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: <20231211153633.GD1489931@ziepe.ca> References: <2ae6199a9cf035c1defd42e48675b827f41cdc95.1701268753.git.robin.murphy@arm.com> <20231211132757.GE25681@willie-the-truck> <91b22090-485f-49c9-a536-849fd7f92f8e@arm.com> <20231211153023.GA26048@willie-the-truck> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20231211153023.GA26048@willie-the-truck> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231211_091418_361834_DE5458C2 X-CRM114-Status: GOOD ( 24.94 ) 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:30:24PM +0000, Will Deacon wrote: > 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. Yes, UBSAN generates warnings for these cases. I'm not sure if it is actually undefined C behavior or just "suspicious", but such is what it is.. Jason _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel