Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3925312pxu; Tue, 20 Oct 2020 04:18:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRn4GDfZmC4FO6tmhz6g+ssaGSwYOk8U1gCEo3xoQoZhYR1xxgThgp9cf8bl4NuB9jwfZa X-Received: by 2002:a50:b904:: with SMTP id m4mr2160991ede.304.1603192694425; Tue, 20 Oct 2020 04:18:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603192694; cv=none; d=google.com; s=arc-20160816; b=eGcjALytuUWi5/cIDhmXVpjkw/Ly5OJFj4fJaBrggEUy+gB2/+dqZfyz+uQrnA8Esy 5cX9iTH7cugoVpgY5Hmu2IsqU6xlnpZYkljHkK+uf8he/E/nAEimVWDXUaBJd6hC44Y5 w6Ora1s7Y7cyTNLrbZiXF7mbPqc2Ojiib4AYBNbP0AEFxjn82jxIKRsCDaE+5WKl2u1z xaLtGY8GUJmoph71n902ilX0Yck1CkEFl1nkepVWLF+/payomOr2UfXph30J8+S0khFo MkDK+etKRqeP/18Mi5Mz8m5QvZLbABEmYES9jfHozSmUXP0qW4M8krLAvMPk+H0rwRNk RbJA== 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=fRpg67/kQgrcOOelRNUriikxCORsSNuzcjvbqGQ2QS8=; b=OQZISVrmUkzmV2ufZrCIt6niQltPpFGv1q2dVMcxBJteyShcWq0BgAuQyBDCoiUtbf M+ILpaI0C71wAFepkC4UOUKnGSXJfSWxXixRf+CGMCrV+fY+CX7kh8FXCODhKIfyfK1v dJ2WYPFs1Pj5fq5kVh9qjLHfpbGGR9U2p6/chv46zALepnmWV4IuQlZtjruAvtgA56xe ds4s4lGuaEhZJ3uIGcmd0kTrs1P8NOFQsbSQJGLk3Qt5UslHvmy5H1uy5fdpMDFDEk+4 5iyk6n5vK2ea/BBO//wR7n2B8Bnkku7bydGe+i96G5b2zlBpSCLGhj2VoNwD6uCETVKm 1VgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b="o/e/9qI4"; 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 k19si916047eds.17.2020.10.20.04.17.52; Tue, 20 Oct 2020 04:18:14 -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="o/e/9qI4"; 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 S2392630AbgJTJSF (ORCPT + 99 others); Tue, 20 Oct 2020 05:18:05 -0400 Received: from z5.mailgun.us ([104.130.96.5]:52660 "EHLO z5.mailgun.us" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391217AbgJTJSF (ORCPT ); Tue, 20 Oct 2020 05:18:05 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1603185484; h=Content-Transfer-Encoding: Content-Type: In-Reply-To: MIME-Version: Date: Message-ID: From: References: Cc: To: Subject: Sender; bh=fRpg67/kQgrcOOelRNUriikxCORsSNuzcjvbqGQ2QS8=; b=o/e/9qI4wC0SVtgFVx4z2YvITGz66ZecfO7loA51/4tZU7oze7Te+rYl6HrjL/Oj8CkyI765 LvpwNsJGCV2iKwhRIE3/syHbv+CG6rlEGepjSMmPdr7URKW0QzJ3lqmjAH0IuSyKBCPMnY5j yTidophaNm0UtafSHzPmFK2QC30= X-Mailgun-Sending-Ip: 104.130.96.5 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-west-2.postgun.com with SMTP id 5f8eab2aad37af35ec334ecf (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Tue, 20 Oct 2020 09:17:30 GMT Sender: vjitta=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 0C5CCC43385; Tue, 20 Oct 2020 09:17:30 +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 24665C433CB; Tue, 20 Oct 2020 09:17:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 24665C433CB 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 1/2] iommu/iova: Retry from last rb tree node if iova search fails 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> From: Vijayanand Jitta Message-ID: <7705f57b-54d1-9c0a-2d41-c1309b0e7168@codeaurora.org> Date: Tue, 20 Oct 2020 14:47:06 +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-1-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 a new iova alloc request comes iova is always searched > from the cached node and the nodes which are previous to cached > node. So, even if there is free iova space available in the nodes > which are next to the cached node iova allocation can still fail > because of this approach. > > Consider the following sequence of iova alloc and frees on > 1GB of iova space > > 1) alloc - 500MB > 2) alloc - 12MB > 3) alloc - 499MB > 4) free - 12MB which was allocated in step 2 > 5) alloc - 13MB > > After the above sequence we will have 12MB of free iova space and > cached node will be pointing to the iova pfn of last alloc of 13MB > which will be the lowest iova pfn of that iova space. Now if we get an > alloc request of 2MB we just search from cached node and then look > for lower iova pfn's for free iova and as they aren't any, iova alloc > fails though there is 12MB of free iova space. > > To avoid such iova search failures do a retry from the last rb tree node > when iova search fails, this will search the entire tree and get an iova > if its available. > > Signed-off-by: Vijayanand Jitta > Reviewed-by: Robin Murphy > --- > drivers/iommu/iova.c | 23 +++++++++++++++++------ > 1 file changed, 17 insertions(+), 6 deletions(-) > > diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c > index 30d969a..c3a1a8e 100644 > --- a/drivers/iommu/iova.c > +++ b/drivers/iommu/iova.c > @@ -184,8 +184,9 @@ static int __alloc_and_insert_iova_range(struct iova_domain *iovad, > struct rb_node *curr, *prev; > struct iova *curr_iova; > unsigned long flags; > - unsigned long new_pfn; > + unsigned long new_pfn, retry_pfn; > unsigned long align_mask = ~0UL; > + unsigned long high_pfn = limit_pfn, low_pfn = iovad->start_pfn; > > if (size_aligned) > align_mask <<= fls_long(size - 1); > @@ -198,15 +199,25 @@ static int __alloc_and_insert_iova_range(struct iova_domain *iovad, > > curr = __get_cached_rbnode(iovad, limit_pfn); > curr_iova = rb_entry(curr, struct iova, node); > + retry_pfn = curr_iova->pfn_hi + 1; > + > +retry: > do { > - limit_pfn = min(limit_pfn, curr_iova->pfn_lo); > - new_pfn = (limit_pfn - size) & align_mask; > + high_pfn = min(high_pfn, curr_iova->pfn_lo); > + new_pfn = (high_pfn - size) & align_mask; > prev = curr; > curr = rb_prev(curr); > curr_iova = rb_entry(curr, struct iova, node); > - } while (curr && new_pfn <= curr_iova->pfn_hi); > - > - if (limit_pfn < size || new_pfn < iovad->start_pfn) { > + } while (curr && new_pfn <= curr_iova->pfn_hi && new_pfn >= low_pfn); > + > + if (high_pfn < size || new_pfn < low_pfn) { > + if (low_pfn == iovad->start_pfn && retry_pfn < limit_pfn) { > + high_pfn = limit_pfn; > + low_pfn = retry_pfn; > + curr = &iovad->anchor.node; > + curr_iova = rb_entry(curr, struct iova, node); > + goto retry; > + } > iovad->max32_alloc_size = size; > goto iova32_full; > } > 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