Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2360828ybt; Fri, 3 Jul 2020 07:20:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfBS+MUVyxdD/WvxEC17AenDxiYcaoFk2k1cUB/cMSh0DGYYAcMiC+lr0IwgJVPG3CTLTa X-Received: by 2002:a17:906:57c6:: with SMTP id u6mr31781243ejr.194.1593786033841; Fri, 03 Jul 2020 07:20:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593786033; cv=none; d=google.com; s=arc-20160816; b=mFYiZD4YcpDlTkVffRJ/lHq5hTPuwzSRyz540GK4GcZOCvXWe7tx2jKFCuwfEHMrkn zs38OFNEH4gNK0ya75l7lWEbqV9qU4EB1x4iOz4n2ItWV0HIfuCBiniHQYOxtrl6A3kL kua9H7HZ/AR03dmfkLOhLhBD+ll+gOSZL0XUv3l+PR4m8XerbNsRwhUnaproLFMFi4ov XZk6ddVQaZUXCV9iIHNGy9Gxu6rXFIz6vuX/2Tlx1J5xKj6bBP65hBcCV1afcgAvZ564 neB6MuaVw0pOFmtW9/PuOIiymKZCQc8+272bA6pRoPO82ljhmAoltS+ym5cS+GegmI6k c8+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature; bh=XI/M6Pcw+RwtbXFkwoRsxR1H4DU4dG64igoe60J1Q3o=; b=l3lxC23N7BJoaZBd3MqbvNCoj04a/sMwEMiEsa62yGJ0PrxP2HetWh6g7/HXWXs6GT x5O+hqus5sBHKovm7Za04QeY/fQJQJTIbWuoLLWTYLaVTwUAEA6pOOzU4/GY3SYDpb3z gpgI4DQ4TdxbFbm73TtP0nFeD1ZjIX7q2CcSir1YjYpPuT+rTxyzQYBIr7C9Ab6wB7la UXE9jjn5w+mbqp+IaWEz3tCrkRiWLKQC6xbtKv7k3Tjpy/oM3lI9dNyzREebn8T5Kk8w 9+PyK+kwl2gz9mB+6fFixPAyNcAlCe5xkZbWMIQTC3rEP7o5btK4YzzxcEO7nVUpZnJd FFfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=DazCLmVv; 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 z8si7589373edp.515.2020.07.03.07.20.10; Fri, 03 Jul 2020 07:20:33 -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=DazCLmVv; 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 S1726361AbgGCOSD (ORCPT + 99 others); Fri, 3 Jul 2020 10:18:03 -0400 Received: from mail29.static.mailgun.info ([104.130.122.29]:16318 "EHLO mail29.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726039AbgGCOSD (ORCPT ); Fri, 3 Jul 2020 10:18:03 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1593785882; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=XI/M6Pcw+RwtbXFkwoRsxR1H4DU4dG64igoe60J1Q3o=; b=DazCLmVvZRX24CJfpHUaUgpGk3Uzoy3/0NGvtmDVelgOGXk1wmbKX4ixwqsZZerq70G7/lyc 817jZVv0HIvBv3Ikd9d3mrEtDUzFlLWaxQywyP0gQgWt6uwLWgQhdXml2UaR7ycdbWZHm2MN PKMVX3YcNCyA7tNtgC3muXVeVUQ= X-Mailgun-Sending-Ip: 104.130.122.29 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-n18.prod.us-east-1.postgun.com with SMTP id 5eff3e0386de6ccd448d89cc (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Fri, 03 Jul 2020 14:17:39 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 1F0ABC43391; Fri, 3 Jul 2020 14:17:39 +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 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 E77C0C433C6; Fri, 3 Jul 2020 14:17:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org E77C0C433C6 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 2/2] iommu/iova: Free global iova rcache on iova alloc failure Date: Fri, 3 Jul 2020 19:47:15 +0530 Message-Id: <1593785835-27250-2-git-send-email-vjitta@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1593785835-27250-1-git-send-email-vjitta@codeaurora.org> References: <1593785835-27250-1-git-send-email-vjitta@codeaurora.org> 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 holding the iova's which can cause fragmentation. So, free the global iova rcache as well and then go for the retry. Change-Id: Ib8236dc88ba5516b73d4fbf6bf8e68bbf09bbad2 Signed-off-by: Vijayanand Jitta --- drivers/iommu/iova.c | 23 +++++++++++++++++++++++ include/linux/iova.h | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index 4e77116..5836c87 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -442,6 +442,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; } @@ -1055,5 +1056,27 @@ 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; + 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"); 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 1.9.1