Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp230821imm; Tue, 18 Sep 2018 20:38:59 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZKkFALWq/sl22F5pvCkOCBpOYBA8DshDrh+CH26HoGQN65NIvLQ+LYRsiQCierZGnPoxwA X-Received: by 2002:a63:88c8:: with SMTP id l191-v6mr30537349pgd.340.1537328339005; Tue, 18 Sep 2018 20:38:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537328338; cv=none; d=google.com; s=arc-20160816; b=SzTBAKx3Tj3jzx/duyYpdXJ9paV3E7/HBpS9MtyEgcny6wSExW19CFrxSltlAvTHQx OaJsehxx8PAGM/O2t9e5hFjhpyYozcbsfrm1Lni3wOVpNVZSpriKiTQp1RKYh4qEQ8yL w8vH6MqH6t/o5kZ9u6G5lyseD3HqkM696rMUf/vb9k/O9KaxDpLliCc2C89uhUXqzIsa z0oUl78KP7AXMRUckdnYMnZtowyIf1uDvIA4eFrfZTjSm/UFow3VboUL+mPvJYpEFRS6 pc7WaHfP+FDUx2ga8Nzsh0aNXKM5MsI4xxjUHyhef67cHnYDoiycDhJE3pdvx8djXAvK mTEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Is/kiqCUVr99kg0KI+RzyHvmwWvwglppJkETJIOoEL0=; b=QQdigyxdQRObsiREXQZa3efORUYNP3c6XaHTQ+w6/IxgoQmy4zAx2DIkHeRNDHsOHC 81FrmsfsB/4OmrCQciAx4f3OXTTVnk2nxsNAjS0WwNQR9wpsxPQqi8Hz9rcTORYSXsyd 3dE8TwE4xOi2aVGUlWP7wsA+EjtERUCmJXfapwcGs618o4puRiVR5btREoRv8YAnh1nA 47rkfTfTH8+8xAnTldSb/Q7fz/GeHoZvLf2BVqGJ/Tv6U02DNlWxRRxplhBXivLP6lvL jabxDcJ4YJ6WQ5NEzfbTWZPPu/JU9VTp817L6VWMiUrxS/HLm9ro+f5w6G/dFSSgk7N5 sdzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=i5yScQ6r; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m21-v6si22433978pgd.48.2018.09.18.20.38.43; Tue, 18 Sep 2018 20:38:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=i5yScQ6r; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727958AbeISJO3 (ORCPT + 99 others); Wed, 19 Sep 2018 05:14:29 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:36262 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725875AbeISJO3 (ORCPT ); Wed, 19 Sep 2018 05:14:29 -0400 Received: by mail-ot1-f67.google.com with SMTP id w17-v6so4312016otk.3 for ; Tue, 18 Sep 2018 20:38:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Is/kiqCUVr99kg0KI+RzyHvmwWvwglppJkETJIOoEL0=; b=i5yScQ6rrkrmgNBUQjItKyzosqSToiYJqaoPZjjcwbTdk/POqR3iaYdk6De73TF78C CFKiWgTwQXHPFAWTT2++uZRC/2FHPvQHq8dfgjNpESh9722GAGok9EUmz8qKqYtN/I3S +plm7njrLnjN7NRhxFQO8ojTOpSdeAZi9G/gIcnOSKVlApXZqWMGQTX0b3/L4xb1Sqfc 5vzfVFfWDbN31WppxhhcVkVXjjOR0Htg4lGJFrmsiIo0fQcKtZfZIS7dLFFr1dGMwvRV zOzhPPESFyJ5bx4WbzjL5qApL7mSOLlW/Ac0txhxjpfDkU5nPO4yZKhEDKWM3RuH9JWT hxlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Is/kiqCUVr99kg0KI+RzyHvmwWvwglppJkETJIOoEL0=; b=IvnDp48iyrmpYiknD4QPMr/bt0PdkIizdimiQeTINukNZOyQlwS4enze0z/1+pSEur A59qvvmyd8e05Dh2HstvxeII7d0hhzmz3Y2lhhhGqxxR/+C64cF7gmQPtnS3EO6ifQ6m iQUF9zodSqHYDK+ym4GNKcP8PAwPQ+sNxMloSOgYxd2SLn8ggIcl7dH+JrjOevV+UGTC FunV+ByvPT16Z/dOqQuIw2I1JUVf3SSRbIGCAOD22mL5PAZHZmZwzmQtboXoJxvEs+j+ ZMmGe8ygXusssgW2xm8BzEbXYoQUE118SZJfb067h1fM3T6PoIcr9U/itoJdJ4wFHMdZ OEqA== X-Gm-Message-State: APzg51Az2vvVs0kexUrbSWk/tZ4HZjkWXmOQ7UMGzxjxZR6GIWjurQxo 2ZOKRBCMDomEupHT4LfPNMxRTX0LvLjJheD77Yw= X-Received: by 2002:a9d:2ac8:: with SMTP id e66-v6mr18421452otb.143.1537328316297; Tue, 18 Sep 2018 20:38:36 -0700 (PDT) MIME-Version: 1.0 References: <20180905042736.11904-1-ganapatrao.kulkarni@cavium.com> In-Reply-To: <20180905042736.11904-1-ganapatrao.kulkarni@cavium.com> From: Ganapatrao Kulkarni Date: Wed, 19 Sep 2018 09:08:25 +0530 Message-ID: Subject: Re: [PATCH v4] iommu/iova: Optimise attempts to allocate iova from 32bit address range To: Ganapatrao Kulkarni Cc: Joerg Roedel , iommu@lists.linux-foundation.org, LKML , Robin Murphy , tomasz.nowicki@cavium.com, jnair@caviumnetworks.com, Robert Richter , Vadim.Lomovtsev@cavium.com, Jan.Glauber@cavium.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Joerg, can you please pull this patch? On Wed, Sep 5, 2018 at 9:58 AM Ganapatrao Kulkarni wrote: > > As an optimisation for PCI devices, there is always first attempt > been made to allocate iova from SAC address range. This will lead > to unnecessary attempts, when there are no free ranges > available. Adding fix to track recently failed iova address size and > allow further attempts, only if requested size is lesser than a failed > size. The size is updated when any replenish happens. > > Reviewed-by: Robin Murphy > Signed-off-by: Ganapatrao Kulkarni > --- > v4: > Rebsaed to 4.19-rc2 > v3: > Update with comments [3] from Robin Murphy > > [3] https://lkml.org/lkml/2018/8/13/116 > > v2: update with comments [2] from Robin Murphy > > [2] https://lkml.org/lkml/2018/8/7/166 > > v1: Based on comments from Robin Murphy > for patch [1] > > [1] https://lkml.org/lkml/2018/4/19/780 > > drivers/iommu/iova.c | 22 +++++++++++++++------- > include/linux/iova.h | 1 + > 2 files changed, 16 insertions(+), 7 deletions(-) > > diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c > index 83fe2621effe..f8d3ba247523 100644 > --- a/drivers/iommu/iova.c > +++ b/drivers/iommu/iova.c > @@ -56,6 +56,7 @@ init_iova_domain(struct iova_domain *iovad, unsigned long granule, > iovad->granule = granule; > iovad->start_pfn = start_pfn; > iovad->dma_32bit_pfn = 1UL << (32 - iova_shift(iovad)); > + iovad->max32_alloc_size = iovad->dma_32bit_pfn; > iovad->flush_cb = NULL; > iovad->fq = NULL; > iovad->anchor.pfn_lo = iovad->anchor.pfn_hi = IOVA_ANCHOR; > @@ -139,8 +140,10 @@ __cached_rbnode_delete_update(struct iova_domain *iovad, struct iova *free) > > cached_iova = rb_entry(iovad->cached32_node, struct iova, node); > if (free->pfn_hi < iovad->dma_32bit_pfn && > - free->pfn_lo >= cached_iova->pfn_lo) > + free->pfn_lo >= cached_iova->pfn_lo) { > iovad->cached32_node = rb_next(&free->node); > + iovad->max32_alloc_size = iovad->dma_32bit_pfn; > + } > > cached_iova = rb_entry(iovad->cached_node, struct iova, node); > if (free->pfn_lo >= cached_iova->pfn_lo) > @@ -190,6 +193,10 @@ static int __alloc_and_insert_iova_range(struct iova_domain *iovad, > > /* Walk the tree backwards */ > spin_lock_irqsave(&iovad->iova_rbtree_lock, flags); > + if (limit_pfn <= iovad->dma_32bit_pfn && > + size >= iovad->max32_alloc_size) > + goto iova32_full; > + > curr = __get_cached_rbnode(iovad, limit_pfn); > curr_iova = rb_entry(curr, struct iova, node); > do { > @@ -200,10 +207,8 @@ static int __alloc_and_insert_iova_range(struct iova_domain *iovad, > curr_iova = rb_entry(curr, struct iova, node); > } while (curr && new_pfn <= curr_iova->pfn_hi); > > - if (limit_pfn < size || new_pfn < iovad->start_pfn) { > - spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); > - return -ENOMEM; > - } > + if (limit_pfn < size || new_pfn < iovad->start_pfn) > + goto iova32_full; > > /* pfn_lo will point to size aligned address if size_aligned is set */ > new->pfn_lo = new_pfn; > @@ -214,9 +219,12 @@ static int __alloc_and_insert_iova_range(struct iova_domain *iovad, > __cached_rbnode_insert_update(iovad, new); > > spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); > - > - > return 0; > + > +iova32_full: > + iovad->max32_alloc_size = size; > + spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); > + return -ENOMEM; > } > > static struct kmem_cache *iova_cache; > diff --git a/include/linux/iova.h b/include/linux/iova.h > index 928442dda565..0b93bf96693e 100644 > --- a/include/linux/iova.h > +++ b/include/linux/iova.h > @@ -75,6 +75,7 @@ struct iova_domain { > unsigned long granule; /* pfn granularity for this domain */ > unsigned long start_pfn; /* Lower limit for this domain */ > unsigned long dma_32bit_pfn; > + unsigned long max32_alloc_size; /* Size of last failed allocation */ > struct iova anchor; /* rbtree lookup anchor */ > struct iova_rcache rcaches[IOVA_RANGE_CACHE_MAX_SIZE]; /* IOVA range caches */ > > -- > 2.18.0 > thanks, Ganapat