From patchwork Thu May 18 07:59:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 100047 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp602143qge; Thu, 18 May 2017 01:02:39 -0700 (PDT) X-Received: by 10.98.178.72 with SMTP id x69mr3001941pfe.74.1495094559828; Thu, 18 May 2017 01:02:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495094559; cv=none; d=google.com; s=arc-20160816; b=fu8Ltl7V2k/1XqdgZGnE9cugEtYrIU1/R9ILWN435eoAstgH91sQYQI6LZxVabaepx XxFc2yLGsDZkgJY3uAw1M8Wrl6LlpG3w9suTc1DcjHa3bvw0j2Oiegor8fQlBN+tUcPs CArcAv6kLy74LHlmPVaacpkDSiYIzMNAX9+2zouhM+NK1RzcV0KM4ophDSbXWKQTRVz7 WGwbXaBnjwydHcyWPUfBSER2oa+w3tVsv2JrHRNevyU8Oy9XVh7SjkpiokjyYmR3V7wh 7vr6XoFRtUEVYGWM1uN2MAahEA24wXFP76iu4qR89jZsr0iXAn0VXJBj2fjCikoCbthP fd+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=XULl0vjEF28g48mlR3M2fpD2sAIfsJhd1xRg3VXF868=; b=A8RVbDIBCMSIUOlc5T6EFUq2QsxF9gANpFgjGJguKm/Ro2psqFpHX923S3e0niBLLY 3KXgQk9Spj3i4FBb1YhBtj36tELc2to6SA+Q3guvg0OwPgwRdKco3T3RCzqGqfG8Tequ +vr4VqGqruO6/rJTnkJfZ9OeQtIqtEVngFn/Ve4b2CMTLLcGIrxsweixeFa+XVXazk83 JLYbZ4fVGlai/+Bp77DVMF3flGwHdLpGnBb/ZPh89JpoEm7Jb/F3/PKJ6UK6NZ4gJ2Y8 /n5HOUuOgCrAbUfpD8Dw6FR1Y9Irwf81lqFtIzjPYDE6ulJrCHIZ8kbWH6TKep8iI8/K RRmg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y10si4532358pgo.351.2017.05.18.01.02.39; Thu, 18 May 2017 01:02:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754948AbdERICJ (ORCPT + 25 others); Thu, 18 May 2017 04:02:09 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:6777 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751348AbdERICG (ORCPT ); Thu, 18 May 2017 04:02:06 -0400 Received: from 172.30.72.56 (EHLO DGGEML401-HUB.china.huawei.com) ([172.30.72.56]) by dggrg01-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id AOU59816; Thu, 18 May 2017 16:01:59 +0800 (CST) Received: from localhost (10.177.23.164) by DGGEML401-HUB.china.huawei.com (10.3.17.32) with Microsoft SMTP Server id 14.3.301.0; Thu, 18 May 2017 16:01:51 +0800 From: Zhen Lei To: Joerg Roedel , iommu , Robin Murphy , David Woodhouse , Sudeep Dutt , Ashutosh Dixit , linux-kernel CC: Zefan Li , Xinwei Hu , "Tianhong Ding" , Hanjun Guo , Zhen Lei Subject: [PATCH v3 3/6] iommu/iova: adjust __cached_rbnode_insert_update Date: Thu, 18 May 2017 15:59:54 +0800 Message-ID: <1495094397-9132-4-git-send-email-thunder.leizhen@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1495094397-9132-1-git-send-email-thunder.leizhen@huawei.com> References: <1495094397-9132-1-git-send-email-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.23.164] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.591D54F8.00DB, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: ac71f869336dc4e7f60f5e7e973b19eb Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For case 2 and 3, adjust cached32_node to the new place, case 1 keep no change. For example: case1: (the right part was allocated) |------------------------------| |<-----free---->|<--new_iova-->| | | cached32_node case2: (all was allocated) |------------------------------| |<---------new_iova----------->| | | cached32_node case3: |-----------------------|......|---------| |..free..|<--new_iova-->| | | | | cached32_node(new) cached32_node(old) Signed-off-by: Zhen Lei --- drivers/iommu/iova.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) -- 2.5.0 diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index d0c19ec..1b8e136 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -91,12 +91,16 @@ __get_cached_rbnode(struct iova_domain *iovad, unsigned long *limit_pfn) } static void -__cached_rbnode_insert_update(struct iova_domain *iovad, - unsigned long limit_pfn, struct iova *new) +__cached_rbnode_insert_update(struct iova_domain *iovad, struct iova *new) { - if (limit_pfn != iovad->dma_32bit_pfn) + struct iova *cached_iova; + + if (new->pfn_hi > iovad->dma_32bit_pfn) return; - iovad->cached32_node = &new->node; + + cached_iova = rb_entry(iovad->cached32_node, struct iova, node); + if (new->pfn_lo <= cached_iova->pfn_lo) + iovad->cached32_node = rb_prev(&new->node); } static void @@ -159,12 +163,10 @@ static int __alloc_and_insert_iova_range(struct iova_domain *iovad, { struct rb_node *prev, *curr; unsigned long flags; - unsigned long saved_pfn; unsigned int pad_size = 0; /* Walk the tree backwards */ spin_lock_irqsave(&iovad->iova_rbtree_lock, flags); - saved_pfn = limit_pfn; curr = __get_cached_rbnode(iovad, &limit_pfn); prev = curr; while (curr) { @@ -198,11 +200,10 @@ static int __alloc_and_insert_iova_range(struct iova_domain *iovad, /* If we have 'prev', it's a valid place to start the insertion. */ iova_insert_rbtree(&iovad->rbroot, new, prev); - __cached_rbnode_insert_update(iovad, saved_pfn, new); + __cached_rbnode_insert_update(iovad, new); spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); - return 0; }