From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B72B0C432C3 for ; Fri, 29 Nov 2019 13:34:09 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 88E4F20880 for ; Fri, 29 Nov 2019 13:34:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 88E4F20880 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 625A3869AB; Fri, 29 Nov 2019 13:34:09 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id knvONsEnadyd; Fri, 29 Nov 2019 13:34:08 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 60B0B86BC9; Fri, 29 Nov 2019 13:34:08 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 318A5C1DD9; Fri, 29 Nov 2019 13:34:08 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 4CAFBC0881 for ; Fri, 29 Nov 2019 13:34:07 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 47BBA86BC9 for ; Fri, 29 Nov 2019 13:34:07 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PN_9ZRmZjVxh for ; Fri, 29 Nov 2019 13:34:06 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from huawei.com (lhrrgout.huawei.com [185.176.76.210]) by fraxinus.osuosl.org (Postfix) with ESMTPS id B2065869AB for ; Fri, 29 Nov 2019 13:34:06 +0000 (UTC) Received: from LHREML714-CAH.china.huawei.com (unknown [172.18.7.108]) by Forcepoint Email with ESMTP id AF5A731C83F1C5CE58D3; Fri, 29 Nov 2019 13:34:04 +0000 (GMT) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by LHREML714-CAH.china.huawei.com (10.201.108.37) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 29 Nov 2019 13:34:04 +0000 Received: from [127.0.0.1] (10.202.226.46) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Fri, 29 Nov 2019 13:34:04 +0000 Subject: Re: [Patch v2 3/3] iommu: avoid taking iova_rbtree_lock twice To: Cong Wang , References: <20191129004855.18506-1-xiyou.wangcong@gmail.com> <20191129004855.18506-4-xiyou.wangcong@gmail.com> From: John Garry Message-ID: Date: Fri, 29 Nov 2019 13:34:03 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.1.2 MIME-Version: 1.0 In-Reply-To: <20191129004855.18506-4-xiyou.wangcong@gmail.com> Content-Language: en-US X-Originating-IP: [10.202.226.46] X-ClientProxiedBy: lhreml720-chm.china.huawei.com (10.201.108.71) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected Cc: linux-kernel@vger.kernel.org X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" On 29/11/2019 00:48, Cong Wang wrote: > Both find_iova() and __free_iova() take iova_rbtree_lock, > there is no reason to take and release it twice inside > free_iova(). > > Fold them into the critical section by calling the unlock > versions instead. Since generally the iova would be non-NULL, this seems a reasonable change (which could be mentioned in the commit log) John > > Cc: Joerg Roedel > Signed-off-by: Cong Wang > --- > drivers/iommu/iova.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c > index 184d4c0e20b5..f46f8f794678 100644 > --- a/drivers/iommu/iova.c > +++ b/drivers/iommu/iova.c > @@ -390,10 +390,14 @@ EXPORT_SYMBOL_GPL(__free_iova); > void > free_iova(struct iova_domain *iovad, unsigned long pfn) > { > - struct iova *iova = find_iova(iovad, pfn); > + unsigned long flags; > + struct iova *iova; > > + spin_lock_irqsave(&iovad->iova_rbtree_lock, flags); > + iova = private_find_iova(iovad, pfn); > if (iova) > - __free_iova(iovad, iova); > + private_free_iova(iovad, iova); > + spin_unlock_irqrestore(&iovad->iova_rbtree_lock, flags); > > } > EXPORT_SYMBOL_GPL(free_iova); > _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu