From patchwork Thu May 18 07:59:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 100048 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp602146qge; Thu, 18 May 2017 01:02:40 -0700 (PDT) X-Received: by 10.99.65.7 with SMTP id o7mr3019290pga.90.1495094560214; Thu, 18 May 2017 01:02:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495094560; cv=none; d=google.com; s=arc-20160816; b=p6jWfS6+QBEOk2UFOORI3JnpAJJUmpc1kwLgOUI4exf+agwzkMsmsqhREBiBR71sNm vQwj4f9BdnHlQgfYKcmaxW5Mp6rj53c5d6Q2VlwQGoVkToTqrQHkVjhDBdAfyj3dpj+g a5jphnE9AQlHqK5YgnVt/7AmFzikwn7zAObJqydbu8W06td3uo4GeDE1EZysV3tCNfap EX5GncjwNGKOdMqbtWWHM5xcMSQ/wHhicoADIS1Je0Fo3w2rRIy39SaNbxH3uyu3bMmt H5qXW1ulgXAB8ACubWbvq6k1RmAYewRxlGSAO5PCHJBAjEWqfyo//ttXYluZDK4ZeWfm nsWg== 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=VwWm+GgqVSBYwesekh+vJUbritFQbY9ON0sMZC7vGdQ=; b=nhU8He21daJCqpkHHbOzllPeRi66spIB3ze17dyEe3F2T0DK2BCCYWOuxdnNOZuWEn HkPHBNNrbW1bAAh+Ihro9GzPq9Crfxq+E0MCTMB8v0ZBzixv1p0Zc0agoawE3D+WLlrg GFGev3bXDCIflLCYAkhEB7ig4zVPLD7rNCGq7LPaizTKTcFpFKD+OjljH9o+gRyB9Idq UKwmqoypf66aG0pH8AzYO6kVlI+PmVCb4NxHIzCnw7QRpwR1zsW/lA/S/9x2ZwCIDOL9 AawkcftgnXu1WrNXrpapc3wEOyQZiwrEeVMNjQyCIm+lXEV6GO8431mXznWXGTodIg+J xtVg== 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:40 -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 S1755022AbdERICQ (ORCPT + 25 others); Thu, 18 May 2017 04:02:16 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:6776 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752741AbdERICG (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 AOU59819; Thu, 18 May 2017 16:02:00 +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:50 +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 1/6] iommu/iova: cut down judgement times Date: Thu, 18 May 2017 15:59:52 +0800 Message-ID: <1495094397-9132-2-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.0A020204.591D54F9.0050, 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: 9f9b23571aa8cd23945a3af93237799a Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Below judgement can only be satisfied at the last time, which produced 2N judgements(suppose N times failed, 0 or 1 time successed) in vain. if ((pfn >= iova->pfn_lo) && (pfn <= iova->pfn_hi)) { return iova; } Signed-off-by: Zhen Lei Reviewed-by: Robin Murphy --- drivers/iommu/iova.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) -- 2.5.0 diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index 5c88ba7..333a9cc 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -291,15 +291,12 @@ private_find_iova(struct iova_domain *iovad, unsigned long pfn) while (node) { struct iova *iova = rb_entry(node, struct iova, node); - /* If pfn falls within iova's range, return iova */ - if ((pfn >= iova->pfn_lo) && (pfn <= iova->pfn_hi)) { - return iova; - } - if (pfn < iova->pfn_lo) node = node->rb_left; - else if (pfn > iova->pfn_lo) + else if (pfn > iova->pfn_hi) node = node->rb_right; + else + return iova; /* pfn falls within iova's range */ } return NULL;