Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp291725pxk; Wed, 9 Sep 2020 05:36:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTQLAZRcgSsTEFeeoJqLICuUb62+Sg4BqTDGodOxjLSBg1KvO3jOvCsEpbDNQY19/xOPCJ X-Received: by 2002:a05:6402:1818:: with SMTP id g24mr3757887edy.332.1599655019375; Wed, 09 Sep 2020 05:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599655019; cv=none; d=google.com; s=arc-20160816; b=JtYgIEZyGFDusg+wKzs0Hd2s6HN/9HDx5ISJ2uXNmLbliF7FT4uU9BSLZApCHMTqFR 1+5FVb3ZUGSK51ZWLJAKUgRKmXDlbZ2NbKkdAScNk5vR7k8XsnR6H5BzzVo6/k7vPh6j XG4Cg1DB49T4lxx3nAdvTa2jBm5IEHvBly4qABh/5pqOxl4SQu/TfTtXhxjS7Lwy+nx2 LgCHNJbvW1wNErUXvQ1a+Vyqmbr/DZQfFR+uAUJypdZk/mLVpDL1TSREnbKO6K/6gHD/ 9v9jUbDsjyqbqaXC6FeMwjX4NyqJejJqFegCp3T1us+KqeHkmhaVp/++MzJ+xfUmLc3M hKYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=NECcTNEAmr+FAUCDmiRSWYxT5O54egIbQfvOGcwYhI0=; b=HmUxVAcZicLmgoMmTBFBFGznX7FFc2tX7VSMMD1oR02WHlv/sToNeJFbIqzYNNJXcE efjj2/kZ+zhIyLUIrOavyPO1XAw6QNyhOQ8AVSaSvivlpccD8DxrmfGfpUjubuD4mBPy bdcaBCdRebFeRg9Rlaqa6gIgNALkWJiDXyC+qJ/QUohx4+liS9fIrlCoYoXUjCHjSE9s SZEe06oMFPNkaGk+0T3KN+DYgynUZhR0ICwmSXc4Nb6fQQBUr3LHOFodv1Y/gavX9yKh 207iHn71UR2TImEob05Lm6BaxlKCWNV4snVIAWFufts9NZDauvxlgUa2H4P0xMk5UN0M 9BAA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s24si1478194ejd.606.2020.09.09.05.36.36; Wed, 09 Sep 2020 05:36:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730180AbgIIMey (ORCPT + 99 others); Wed, 9 Sep 2020 08:34:54 -0400 Received: from foss.arm.com ([217.140.110.172]:42528 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730166AbgIIMae (ORCPT ); Wed, 9 Sep 2020 08:30:34 -0400 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 86F7C31B; Wed, 9 Sep 2020 05:05:54 -0700 (PDT) Received: from [10.57.40.122] (unknown [10.57.40.122]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8A4743F68F; Wed, 9 Sep 2020 05:05:52 -0700 (PDT) Subject: Re: [PATCH] iommu/dma: Fix IOVA reserve dma ranges To: Srinath Mannam , Joerg Roedel , Lorenzo Pieralisi , Bjorn Helgaas , poza@codeaurora.org Cc: bcm-kernel-feedback-list@broadcom.com, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org References: <20200909053234.17027-1-srinath.mannam@broadcom.com> From: Robin Murphy Message-ID: <1996b772-774c-3475-05cc-77ae87176c3f@arm.com> Date: Wed, 9 Sep 2020 13:05:49 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20200909053234.17027-1-srinath.mannam@broadcom.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-09-09 06:32, Srinath Mannam wrote: > Fix IOVA reserve failure for memory regions listed in dma-ranges in the > following cases. > > - start address of memory region is 0x0. That's fair enough, and in fact generalises to the case of zero-sized gaps between regions, which is indeed an oversight. > - end address of a memory region is equal to start address of next memory > region. This part doesn't make much sense, however - if the regions described in bridge->dma_ranges overlap, that's a bug in whoever created a malformed list to begin with. Possibly it's just poor wording, and you're using "memory regions" to refer to any or all of the dma_ranges, the reserved IOVA ranges, and what "start" and "end" in this function represent which isn't quite either of those. > Fixes: aadad097cd46f ("iommu/dma: Reserve IOVA for PCIe inaccessible DMA address") > Signed-off-by: Srinath Mannam > --- > drivers/iommu/dma-iommu.c | 15 +++++++++++---- > 1 file changed, 11 insertions(+), 4 deletions(-) > > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c > index 5141d49a046b..0a3f67a4f9ae 100644 > --- a/drivers/iommu/dma-iommu.c > +++ b/drivers/iommu/dma-iommu.c > @@ -213,14 +213,21 @@ static int iova_reserve_pci_windows(struct pci_dev *dev, > resource_list_for_each_entry(window, &bridge->dma_ranges) { > end = window->res->start - window->offset; > resv_iova: > + if (end < start) { > + /* dma_ranges list should be sorted */ > + dev_err(&dev->dev, "Failed to reserve IOVA\n"); > + return -EINVAL; > + } > + /* > + * Skip the cases when start address of first memory region is > + * 0x0 and end address of one memory region and start address > + * of next memory region are equal. Reserve IOVA for rest of > + * addresses fall in between given memory ranges. > + */ > if (end > start) { > lo = iova_pfn(iovad, start); > hi = iova_pfn(iovad, end); > reserve_iova(iovad, lo, hi); > - } else { Surely this only needs to be a one-liner? - } else { + } else if (end < start) { (or possibly "end != start"; I can't quite decide which expresses the semantic intent better) The rest just looks like unnecessary churn - I don't think it needs commenting that a sorted list may simply not have gaps between entries, and as above I think the wording of that comment is actively misleading. Robin. > - /* dma_ranges list should be sorted */ > - dev_err(&dev->dev, "Failed to reserve IOVA\n"); > - return -EINVAL; > } > > start = window->res->end - window->offset + 1; >