Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp470571pxb; Tue, 3 Nov 2020 04:37:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJxRaymUuhITgonuutWcHa7nGfKodFEmp2ntHUyQ9Nzd8N3N9GYoMHtfuzRNPk0snOWF/KRm X-Received: by 2002:a17:906:edd9:: with SMTP id sb25mr1081680ejb.430.1604407043509; Tue, 03 Nov 2020 04:37:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604407043; cv=none; d=google.com; s=arc-20160816; b=s1Nv93xD+2AoMcnaFOX99NKlRUSPs3owwp1f4C05mTlReJcnq+Kqn0TueIgWEanpjI euqMt3Q32mF1dAJhQdBpiadtyWA6MTgN+zbL5GFs+dZz8GfuMGcDlyuh4TVwpbl6CCPp LQf8L5nh2Zyv4Y65kMSWxX6GNuHNm1MWD0qHvt3fzI8Y4k7Yi0Pl5C3qwnqvz3biwISq 01vKfs/myHf/q4TMOYB+YN+rsJLplY+ZljYIuThLDq4U9KPQ2dPavCAs0zmaijZi8vjw TwRrWhJt299xrcuoAE/prZraZXLTkYeyBLOWEkBUGsOI5x7EbZbIfsi80kGvdiQrwpwd XowQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=llwiduAG2rhaS/88tZPlz7RWGpaYhnpRKEidk6M2Mc4=; b=Kv3O6L4RIJ712pBSi3XTUFMlpSQc+pMmyJe3cH8bq3gMeLg18h6rD0HHx2DNsSD4Sa rJP+xe5c5JqWe2VBREhK4pKbGX6bgiB+6RQq+n/rdumSBIUYV1nqm1ihW59M/B7aBDeD WBjcPVL5YPHz5SAg4l2rk92DGRqDzQ3ZFjbRnL0n7NwpDSgIhJLtVhQUbmVkBy8fvv/l Ysdx8cp2fJ1bsZ05cZwd9MngYGqr71NG7TSXjxnB/+su4r3bzoSZOpZeq5d3lh3VMIfF 1+PKWWLLcvif64F4kVeuodVkGn+zKxDr2l72c6bTk6CcvSR7K0QVun7xmJ7KUC8rXRFi CLzg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j62si11753797edd.159.2020.11.03.04.36.58; Tue, 03 Nov 2020 04:37:23 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728373AbgKCMfX (ORCPT + 99 others); Tue, 3 Nov 2020 07:35:23 -0500 Received: from foss.arm.com ([217.140.110.172]:48046 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726388AbgKCMfX (ORCPT ); Tue, 3 Nov 2020 07:35:23 -0500 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 50202106F; Tue, 3 Nov 2020 04:35:22 -0800 (PST) Received: from [10.57.54.223] (unknown [10.57.54.223]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 20EFF3F718; Tue, 3 Nov 2020 04:35:21 -0800 (PST) Subject: Re: [PATCH v5 2/2] iommu/iova: Free global iova rcache on iova alloc failure To: vjitta@codeaurora.org, joro@8bytes.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: vinmenon@codeaurora.org, kernel-team@android.com References: <1601451864-5956-1-git-send-email-vjitta@codeaurora.org> <1601451864-5956-2-git-send-email-vjitta@codeaurora.org> From: Robin Murphy Message-ID: Date: Tue, 3 Nov 2020 12:35:19 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <1601451864-5956-2-git-send-email-vjitta@codeaurora.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-09-30 08:44, vjitta@codeaurora.org wrote: > From: Vijayanand Jitta > > When ever an iova alloc request fails we free the iova > ranges present in the percpu iova rcaches and then retry > but the global iova rcache is not freed as a result we could > still see iova alloc failure even after retry as global > rcache is holding the iova's which can cause fragmentation. > So, free the global iova rcache as well and then go for the > retry. This looks reasonable to me - it's mildly annoying that we end up with so many similar-looking functions, but the necessary differences are right down in the middle of the loops so nothing can reasonably be factored out :( Reviewed-by: Robin Murphy > Signed-off-by: Vijayanand Jitta > --- > drivers/iommu/iova.c | 23 +++++++++++++++++++++++ > 1 file changed, 23 insertions(+) > > diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c > index c3a1a8e..faf9b13 100644 > --- a/drivers/iommu/iova.c > +++ b/drivers/iommu/iova.c > @@ -25,6 +25,7 @@ static void init_iova_rcaches(struct iova_domain *iovad); > static void free_iova_rcaches(struct iova_domain *iovad); > static void fq_destroy_all_entries(struct iova_domain *iovad); > static void fq_flush_timeout(struct timer_list *t); > +static void free_global_cached_iovas(struct iova_domain *iovad); > > void > init_iova_domain(struct iova_domain *iovad, unsigned long granule, > @@ -442,6 +443,7 @@ alloc_iova_fast(struct iova_domain *iovad, unsigned long size, > flush_rcache = false; > for_each_online_cpu(cpu) > free_cpu_cached_iovas(cpu, iovad); > + free_global_cached_iovas(iovad); > goto retry; > } > > @@ -1057,5 +1059,26 @@ void free_cpu_cached_iovas(unsigned int cpu, struct iova_domain *iovad) > } > } > > +/* > + * free all the IOVA ranges of global cache > + */ > +static void free_global_cached_iovas(struct iova_domain *iovad) > +{ > + struct iova_rcache *rcache; > + unsigned long flags; > + int i, j; > + > + for (i = 0; i < IOVA_RANGE_CACHE_MAX_SIZE; ++i) { > + rcache = &iovad->rcaches[i]; > + spin_lock_irqsave(&rcache->lock, flags); > + for (j = 0; j < rcache->depot_size; ++j) { > + iova_magazine_free_pfns(rcache->depot[j], iovad); > + iova_magazine_free(rcache->depot[j]); > + rcache->depot[j] = NULL; > + } > + rcache->depot_size = 0; > + spin_unlock_irqrestore(&rcache->lock, flags); > + } > +} > MODULE_AUTHOR("Anil S Keshavamurthy "); > MODULE_LICENSE("GPL"); >