Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4077778rdb; Mon, 11 Dec 2023 08:13:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXlbR8er5xtgy16ao+ybvUqsdHwVZAz0Rd2b08M7PiZMH6ZJ7/RSXUuZS9IP31d0qEQk7t X-Received: by 2002:a05:6a20:320c:b0:190:3991:e0f0 with SMTP id hl12-20020a056a20320c00b001903991e0f0mr2066734pzc.36.1702311237208; Mon, 11 Dec 2023 08:13:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702311237; cv=none; d=google.com; s=arc-20160816; b=fwSG9P3o4UJU2U5Iice5Y8xiEagbqkjwarHq2T0ZFZsW5Kh8E0yET9iwt2yvkJF09M xlyC29xmqExpojz7Hub+fgkBNlFBTQ5hHZI3TUnyBgW1714JRgSDZdp+lczAaF+JcpQ7 dWC7Enc/frx6z0o9zAWVjJk7Rbao53F7Q2vkaoDnZvqzpvIyE3Bu2abYE4JFqPXNYusR VDjkYEqDxGPwniK4mC8WdObsA/ZSECuIl5IbXudN5J4APvSz7s/fo4MZ7wUUClZDmFUh YUY/OOrKx46uCSugoj1V36JIzSge69TzJuGM74Zk8OY+Lpum8uSjdCX0uJDsgEcVlUO8 6HSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=SdY8G4YH0kcogMdF95QYsvlRKuwCntobR5ZHwJ2UKbI=; fh=ILDmfEGD53W64/aY7wbw51aCzidjPSMfjM7xVOGpml0=; b=nIeLsmhizigTbmjBDxDQofR5sVg5OAj5F0jJ/a8ZSVFr0JTuXreN+4Zl+NSu2pB+wZ Hrkq4HB28o+N+UZ6pmJ9hdL8342uK39D+jLIYUFXhvqTdOkD08CO+jm3syeSivdv3Iqm qDJ0AVot6GMS4tU03sVs1oFZ1YYiHhxfv0ayzNuXrvdKtRUI5odc3E74jXUrynBtrr5g BtU+BEr+Wj/Jn/HQgRUugBPb+vKjfIXIORG033nndLxVc1Xoe844xKUhnj7J/OzD+Lnb /QG/4RqDxL/uEYgINkrdE4T2aCJaanQAIi6yW2R+w0hEcTYVGEWjOkRA0B113bZH/oeq CbQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id b8-20020a6541c8000000b005c626072edfsi6073818pgq.773.2023.12.11.08.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 08:13:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 983998044824; Mon, 11 Dec 2023 08:13:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344235AbjLKQNk (ORCPT + 99 others); Mon, 11 Dec 2023 11:13:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344188AbjLKQNj (ORCPT ); Mon, 11 Dec 2023 11:13:39 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2FBA98E; Mon, 11 Dec 2023 08:13:45 -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 44658FEC; Mon, 11 Dec 2023 08:14:31 -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 7959B3F738; Mon, 11 Dec 2023 08:13:39 -0800 (PST) Message-ID: Date: Mon, 11 Dec 2023 16:13:38 +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: Mark Rutland , 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> <91b22090-485f-49c9-a536-849fd7f92f8e@arm.com> <20231211153023.GA26048@willie-the-truck> From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Mon, 11 Dec 2023 08:13:54 -0800 (PST) On 2023-12-11 3:39 pm, Mark Rutland wrote: > 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. > > I think you'll get a UBSAN splat, but here the compiler doesn't know what > 'ncomp->memory_address_limit' will be and so doesn't produce a compile-time > warning. > > Regardless, it's undefined behaviour. Urgh, you're right... I double-checked 6.5.7.4 in the standard but managed to miss 6.5.7.3. So yeah, even though "4 << 62" or "2 << 63" are well-defined here, "1 << 64" isn't, dang. Thanks, funky old ISAs which did weird things for crazy large shifts and have no relevance to this code :( Cheers, Robin.