Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp585229ybm; Wed, 27 May 2020 03:03:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRQ6vZDlU65U3gOrCrAeTjvwaphF8QC0sIdF1eZbqOLi3l1OcJ4C39iLtXBtkFvDJX3rUa X-Received: by 2002:a50:b961:: with SMTP id m88mr23626909ede.4.1590573789297; Wed, 27 May 2020 03:03:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590573789; cv=none; d=google.com; s=arc-20160816; b=bzP3q+8/9nv6xHnG3iOHhptohdfSZgPIz35aXE8V8xIFZ1kGwjHzG+EotaGGe4S2PI phi7V6LzDXbIROfSSrgiL9xkNqwaTbTdknOnhoWKp0rMnNm0Hpma1ODrf4ZklSeT3RG0 gjGJ/jyX5mRTRfhV12eGUNoBarxvY00tOzyMpBOVD9+ERp5/oifHK4Z2a95M5MwR+7EV D6j+AHhIlhd2YcsKEa1awsOXdYGSxIcR+KlJ0yQfq6sDwBN2M94TYs74VTcUlTqPZuIX tyxmeJ2K9vyHpv2p6C0S4195y5YReSRR8jcL9KYKIu0zGzJj31lMfpNim8O5lbDqASVW 8MGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dmarc-filter:dkim-signature; bh=jh63g7zVfWyaLq4vPu9kEFHYtKDWPkdQ7ls9thvyg1Y=; b=cjJwnxs2JhjYb4B6ANMBpTN7PTu0AdxDRq6b5GtbyJdegnsbnbRL9kKoOcZ/4K6FBt pi/IbBEC33hGOyRFhX6b8SoBX8vTFBWUWkPNfamhQJjbsxLXlNpJkr/MsF/RvgfsJP2O EN6TYRiUhCaBjIy5jmgIXf7uDlBXpRXXx0t/1LesdNo8p47aUUZsnRmk5R3V5e2YGqWl t7d4suU712HbtPUzecyLielz+WRd2ont1OrLmgqsWN8XwgL1rp85nVQjeudzHjImWFeE KxAuatByjBuhW0bKQarhh2aWONzgdFxl8nc7M8zuknPWpPaZz08mH/QnDXTBJXTQtakT /JDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=tLnG5r3z; 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 t9si1617197eds.213.2020.05.27.03.02.45; Wed, 27 May 2020 03:03:09 -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=fail header.i=@mg.codeaurora.org header.s=smtp header.b=tLnG5r3z; 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 S1728314AbgE0GZe (ORCPT + 99 others); Wed, 27 May 2020 02:25:34 -0400 Received: from mail27.static.mailgun.info ([104.130.122.27]:37805 "EHLO mail27.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728007AbgE0GZe (ORCPT ); Wed, 27 May 2020 02:25:34 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1590560733; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=jh63g7zVfWyaLq4vPu9kEFHYtKDWPkdQ7ls9thvyg1Y=; b=tLnG5r3zqoOxUUZZx5EParrDKHJV3yYNsg4ANZDWIe+lbOPssQSBQ2y3pmMYR3LFDO8MLuKO +g/2jR82RF6hbfPycEmFkhgcFGRBkkoqor4WbST34vEGKWi0shXyGKqEAfRT5w/yMskHNfPx U9YADv16bkvJqbEILUYYtyXPS0I= X-Mailgun-Sending-Ip: 104.130.122.27 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-n03.prod.us-east-1.postgun.com with SMTP id 5ece07bf27386861267c2265 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Wed, 27 May 2020 06:25:03 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id C7B16C433CB; Wed, 27 May 2020 06:25:02 +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=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from vjitta-linux.qualcomm.com (blr-c-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.19.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 03CC2C433C9; Wed, 27 May 2020 06:24:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 03CC2C433C9 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=none 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 Subject: [PATCH] iommu/iova: Free global iova rcache on iova alloc failure Date: Wed, 27 May 2020 11:54:39 +0530 Message-Id: <1590560679-11927-1-git-send-email-vjitta@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.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 still 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 | 22 ++++++++++++++++++++++ include/linux/iova.h | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index 0e6a953..5ae0328 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -431,6 +431,7 @@ struct iova *find_iova(struct iova_domain *iovad, unsigned long pfn) flush_rcache = false; for_each_online_cpu(cpu) free_cpu_cached_iovas(cpu, iovad); + free_global_cached_iovas(iovad); goto retry; } @@ -1044,5 +1045,26 @@ void free_cpu_cached_iovas(unsigned int cpu, struct iova_domain *iovad) } } +/* + * free all the IOVA ranges of global cache + */ +void free_global_cached_iovas(struct iova_domain *iovad) +{ + struct iova_rcache *rcache; + int i, j; + + for (i = 0; i < IOVA_RANGE_CACHE_MAX_SIZE; ++i) { + rcache = &iovad->rcaches[i]; + spin_lock(&rcache->lock); + 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(&rcache->lock); + } +} + MODULE_AUTHOR("Anil S Keshavamurthy "); MODULE_LICENSE("GPL"); diff --git a/include/linux/iova.h b/include/linux/iova.h index a0637ab..a905726 100644 --- a/include/linux/iova.h +++ b/include/linux/iova.h @@ -163,6 +163,7 @@ int init_iova_flush_queue(struct iova_domain *iovad, struct iova *split_and_remove_iova(struct iova_domain *iovad, struct iova *iova, unsigned long pfn_lo, unsigned long pfn_hi); void free_cpu_cached_iovas(unsigned int cpu, struct iova_domain *iovad); +void free_global_cached_iovas(struct iova_domain *iovad); #else static inline int iova_cache_get(void) { @@ -270,6 +271,11 @@ static inline void free_cpu_cached_iovas(unsigned int cpu, struct iova_domain *iovad) { } + +static inline void free_global_cached_iovas(struct iova_domain *iovad) +{ +} + #endif #endif -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation