Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp255311rdh; Thu, 23 Nov 2023 03:13:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6S30vVOFFvvEKB6sCEP8tt1tKHkRaCXSxpsaIkspQ9QeOv8u2h8fTprmHVerKEUi1d4i5 X-Received: by 2002:a05:6808:1295:b0:3b8:45eb:1e81 with SMTP id a21-20020a056808129500b003b845eb1e81mr4065933oiw.49.1700738021432; Thu, 23 Nov 2023 03:13:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700738021; cv=none; d=google.com; s=arc-20160816; b=b1FbkBmzDH3yMHUW2hESnEz7ib11FhPotDkPiox+f0ROmsW5vv6p/MXmi1ci1YKuae lVeDJHvPqu2ru47FDyl0PADcmtlzwfAX78UMK/cd4UikYXrwwqL3dHoYSwV864iN++nu sB0unJuC/S0+K+tPxONH5KBpxMvYgUwrU84AGWUpQDKYwGsH5OQOqiZuJKGrHC/CHnJv /s70OA/2xBZTZWDOjBoa6aVInQ7aIdawP8gSNa39xnxrp8ucqc4ifrb/r87eaXBVF2JF 4PpRS43alFMbNbNdw76+MSTAxmSUH9NVbf1mESsQbaQQC5KnY9+fCodqendYs0cd8ewd nuqw== 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 :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id; bh=dZPRo3fCejOiLd0tqOUFNr6J1yllphToOgF2uKtsWwk=; fh=lABbLW28RqN+qKA1Ug6qUSdpTexZX9P2oINi0lrSXRk=; b=xT45OV2EmSliWVhwSMydp7ZXt2EnBgbs7kPeL8wV+luOn6Q5tRilBCap21kB7tqSoU 6MP3wpqt0bRWWbAoctELytHUZzi80G1GvDip197UqNDKG2PZyYdG4v+oACt191/9gDtB CV8sTx8PrXLd1Idqg92t3O0Hqk8tJQP3CQcZoQzf6fD5rVQqdEGrDUnI4+/vjm9MQ1j9 b4hfkxdhNu2104buSrGtgAUSXBP/qmLLjzqvWxQ0uiVVtOG/roil3n1t6/s8+IwouSks CnbOoNhVGEp5pQYuN7sc07YayGxxldKJdv6b9wlLKwCVogUjSamnhS2ifF5cOResdr8c ChHQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id 75-20020a63014e000000b005c1ce3c9614si1094712pgb.892.2023.11.23.03.13.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 03:13:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id DEEF48293C7A; Thu, 23 Nov 2023 03:13:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344957AbjKWLNZ (ORCPT + 99 others); Thu, 23 Nov 2023 06:13:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344907AbjKWLNY (ORCPT ); Thu, 23 Nov 2023 06:13:24 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 251B5D49; Thu, 23 Nov 2023 03:13:30 -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 56C701042; Thu, 23 Nov 2023 03:14:16 -0800 (PST) Received: from [10.57.70.183] (unknown [10.57.70.183]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 502F33F73F; Thu, 23 Nov 2023 03:13:28 -0800 (PST) Message-ID: <2ba7bab4-daee-4883-acd4-ec9a10c82103@arm.com> Date: Thu, 23 Nov 2023 11:13:13 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] iommu: Don't reserve IOVA when address and size are zero To: Ashish Mhetre , joro@8bytes.org, will@kernel.org, robh@kernel.org, treding@nvidia.com Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org References: <20231123061201.16614-1-amhetre@nvidia.com> Content-Language: en-GB From: Robin Murphy In-Reply-To: <20231123061201.16614-1-amhetre@nvidia.com> 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 23 Nov 2023 03:13:39 -0800 (PST) On 2023-11-23 6:12 am, Ashish Mhetre wrote: > When the bootloader/firmware doesn't setup the framebuffers, their > address and size are zero in "iommu-addresses" property. If we intend to > use display driver in kernel without framebuffer then it's causing > the display IOMMU mappings to fail as IOVA is reserved with size and > address as zero. Can you clarify the problem there? Looking at the code in iova_reserve_iommu_regions() I'm guessing it's that "region->start + region->length - 1" underflows so reserve_iova() actually ends up reserving the entire valid IOVA space? > An ideal solution would be firmware removing the "iommu-addresses" > property and corresponding "memory-region" if display is not present. > But the kernel should be able to handle this by checking for size and > address of IOVA and skipping the IOVA reservation if both are 0. Surely it doesn't make sense to reserve a 0-length region at *any* base address? The symptom above wouldn't be quite the same if the base was nonzero, but corrupting the rbtree with an entry where pfn_hi < pfn_lo would definitely not be good either. > Fixes: a5bf3cfce8cb ("iommu: Implement of_iommu_get_resv_regions()") > Signed-off-by: Ashish Mhetre > --- > drivers/iommu/of_iommu.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/iommu/of_iommu.c b/drivers/iommu/of_iommu.c > index 157b286e36bf..150ef65d357a 100644 > --- a/drivers/iommu/of_iommu.c > +++ b/drivers/iommu/of_iommu.c > @@ -255,6 +255,10 @@ void of_iommu_get_resv_regions(struct device *dev, struct list_head *list) > size_t length; > > maps = of_translate_dma_region(np, maps, &iova, &length); > + if (iova == 0 && length == 0) { > + dev_dbg(dev, "Skipping IOVA reservation as address and size are zero\n"); FWIW I'd be inclined to log a visible warning that firmware is giving us nonsense. Thanks, Robin. > + continue; > + } > type = iommu_resv_region_get_type(dev, &phys, iova, length); > > region = iommu_alloc_resv_region(iova, length, prot, type,