Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3925223pxu; Tue, 20 Oct 2020 04:18:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHMe08D49brQUNkALBFsZ2vmURYapyEgzF6aMHRS7jvxsnHONr1iKLuN2CeZum3GcXnoKO X-Received: by 2002:aa7:c259:: with SMTP id y25mr2130590edo.249.1603192686154; Tue, 20 Oct 2020 04:18:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603192686; cv=none; d=google.com; s=arc-20160816; b=yDfFHqzAqk4rkWI69wmVarkujOmVPq3E0zuGVkzXt831/ZOsnZlCF4MkEQmwSTBCbK OnlF9Pw1tmPkMV3MT8dbLK8E9fjwDoHcMxW/gTI1v8YU2fLbcZXAhI4pjp/i2S1n8gke g3pT4tLQQNTXmRDcTQNLjrq9nNXjCqdfRNq6ZkiwmF8WY3ziKg+wvle7iBRct00WfyOx 63UZWExxWlVBLL3F2sI+kucmwYFN70HhOiEIvDPh44cf0UxsAsCRpkTez4+OWnSynuvt LAGQ3hSAUMqCFMYihWN3bNTPzLgnKXLAcFiDjwOx0GfgEFV89Y7yqZ7Q6d/IbA+i7tIG GYvQ== 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:dmarc-filter:sender:dkim-signature; bh=2BhXAVt0m1txB89CYu9H5b4aqh3hJMtlYcEGVRUsolE=; b=r4rpZn+gxfOixuDrdQ5G1JLn+uVu1yoryK1b/8JtVAFovNOE9uDtWj/bKS3kvNavGQ e3qm4tNsm26HJPVuHSDFoeOk8gtkEK+5ytY7ER8h3p2+82HxNo1oKGJeabGkaAfBaFA6 RYABSEAOxdUAp1ZU4HpGOgz8y3DdFiAjzVU+jqApbtNNk8d7iTSn5rYvFK9LagcmnW+P ERuVJUH2H3R3wsZSb9G69Vt6kGceKcjPGm7ggO1gLvhlb4OiaYrZ9DLSWH83sHpHsAGx qQCBwz+si4+CqQGVhZ8kHxZFEcSCSX2ykCCrH1H8TeDIspwKzVIHG0enoSk+F1U8NOg6 +wyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=DqbeqOQk; 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 dp4si924891ejc.117.2020.10.20.04.17.43; Tue, 20 Oct 2020 04:18:06 -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; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=DqbeqOQk; 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 S2391263AbgJTJS7 (ORCPT + 99 others); Tue, 20 Oct 2020 05:18:59 -0400 Received: from m42-4.mailgun.net ([69.72.42.4]:53210 "EHLO m42-4.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391205AbgJTJS7 (ORCPT ); Tue, 20 Oct 2020 05:18:59 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1603185538; h=Content-Transfer-Encoding: Content-Type: In-Reply-To: MIME-Version: Date: Message-ID: From: References: Cc: To: Subject: Sender; bh=2BhXAVt0m1txB89CYu9H5b4aqh3hJMtlYcEGVRUsolE=; b=DqbeqOQkd8rYGDq3Fxf+UM+/2mst5N5U78pytnYoz+fcRdGQVhw3tkJxlYhs+oAOeZdxHmxE 0X2A2HncMDGu35FWhxTaVNz5CzXrftYnHeBs6HxuWUISP0PBPZJkGGCt9kMuP8W3eBKT21d/ xkAzZq0i51RgFtdA4JGX3/ktIq0= X-Mailgun-Sending-Ip: 69.72.42.4 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n04.prod.us-west-2.postgun.com with SMTP id 5f8eab8183370fa1c1d539dd (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Tue, 20 Oct 2020 09:18:57 GMT Sender: vjitta=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 1AFA3C433F1; Tue, 20 Oct 2020 09:18:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00, NICE_REPLY_A,SPF_FAIL,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from [192.168.0.103] (unknown [106.0.37.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vjitta) by smtp.codeaurora.org (Postfix) with ESMTPSA id C97CBC433CB; Tue, 20 Oct 2020 09:18:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org C97CBC433CB Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=vjitta@codeaurora.org Subject: Re: [PATCH v5 2/2] iommu/iova: Free global iova rcache on iova alloc failure To: joro@8bytes.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: vinmenon@codeaurora.org, kernel-team@android.com, robin.murphy@arm.com References: <1601451864-5956-1-git-send-email-vjitta@codeaurora.org> <1601451864-5956-2-git-send-email-vjitta@codeaurora.org> From: Vijayanand Jitta Message-ID: <490cb495-3c08-6058-13f7-da381b88cf76@codeaurora.org> Date: Tue, 20 Oct 2020 14:48:43 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 MIME-Version: 1.0 In-Reply-To: <1601451864-5956-2-git-send-email-vjitta@codeaurora.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/30/2020 1:14 PM, 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. > > 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"); > Gentle ping. Thanks, Vijay -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation