Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4373326pxk; Wed, 30 Sep 2020 00:49:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwiOCuPsPMCfrhlFgpZtMWueoyWzDdYDS06BgxIcr6cp05u0mOVntySOOfGWeAHC+tBD3z8 X-Received: by 2002:a50:9f6f:: with SMTP id b102mr1322201edf.272.1601452153450; Wed, 30 Sep 2020 00:49:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601452153; cv=none; d=google.com; s=arc-20160816; b=akSR3F4PuPEvDNBDp6gtSWt33F1hvFUNzU5V12S42jvLK5Wqam4qjgJZ7QIH2jHg7w tJ//JRnQ+fUWtaAsOmqpXrsFNtfSAJ39AStk2zoOaqiov1RMrLFMxJya/eJeark9X2pM IpXR6P5qP9cctEAOE1iVcar4LnwR+1H+if34aGec5mo8TpG//sUh0lCe6UqK4UZDXjQd bhhC3Qu5RKG2pHSU5gayPZ2mEwtK+1aR6ulWm8yNJ0OjWLzEjOjCUJil6ENhKfb0GDbz EKX1lQ4bCTJwU2nmRDWmYhImiA4hZDLV3o0jQiIsi54VIT9TItFtAwdFmj5VShrev+ZM AA9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dmarc-filter:sender:dkim-signature; bh=y2RACSNbM/VuhRY0W6oMfPilp6Rd9tTfRILzRpy1sVY=; b=H7vpfQuC+OcejvET15+hG1qIhQygMtTC+oWWc78O1IL6CI2T+O3h3g0658rZ1tOxAu lRfzJrBVW3Dpz8aX5sx/+dNEfAg1YrBp2y2/G6KuBppZp8sjVX8R217ggLITRSDqEdbP vCr9Rv/CgjAKFF9le1/TnLyWz8K1QD26WKIMaNz/exq6NYAKwZ/riOpqNqz2fn5n9Nu+ FWA9pd8yHYw31rGhn9YlqMZgd+bVevOjOeItZDhp/bifEv1ox0Jx8/kMDg3dpOxUMJMy td4W+hWu/MAYnPDlvkX0sf3PXSZUqxGFbnEeKAKi68v+c/Si034OqCxC+5Zj4RQ5C+vE UAqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b="OAb5/teD"; 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 i12si518414edy.604.2020.09.30.00.48.51; Wed, 30 Sep 2020 00:49:13 -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="OAb5/teD"; 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 S1728329AbgI3Hop (ORCPT + 99 others); Wed, 30 Sep 2020 03:44:45 -0400 Received: from m42-4.mailgun.net ([69.72.42.4]:34054 "EHLO m42-4.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725440AbgI3Hop (ORCPT ); Wed, 30 Sep 2020 03:44:45 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1601451884; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=y2RACSNbM/VuhRY0W6oMfPilp6Rd9tTfRILzRpy1sVY=; b=OAb5/teDS/FSc4VXcai9dKVh08POHLJg+74qFEpo+zRqo5e53DLAiuF4iiMFVLMpGaraDf2F JqnaQzjrO/0+YW6vhXpWqYuVN0iMP7Oi2/ONo6h1cqkB6ax6wk2+DVFMvbdtEk6lpw/hbw3l mGdeQoUSNsyqz9/cpHC2+h5k84Q= 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-n07.prod.us-east-1.postgun.com with SMTP id 5f74376cf38f205ebccb3cf7 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Wed, 30 Sep 2020 07:44:44 GMT Sender: vjitta=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 7302DC433CB; Wed, 30 Sep 2020 07:44:43 +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,SPF_FAIL, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from vjitta-linux.qualcomm.com (unknown [202.46.22.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vjitta) by smtp.codeaurora.org (Postfix) with ESMTPSA id D7ADDC433CA; Wed, 30 Sep 2020 07:44:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org D7ADDC433CA 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 From: vjitta@codeaurora.org To: joro@8bytes.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: vinmenon@codeaurora.org, kernel-team@android.com, vjitta@codeaurora.org, robin.murphy@arm.com Subject: [PATCH v5 2/2] iommu/iova: Free global iova rcache on iova alloc failure Date: Wed, 30 Sep 2020 13:14:24 +0530 Message-Id: <1601451864-5956-2-git-send-email-vjitta@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1601451864-5956-1-git-send-email-vjitta@codeaurora.org> References: <1601451864-5956-1-git-send-email-vjitta@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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"); -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation 2.7.4