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 E9187C43603 for ; Thu, 19 Dec 2019 09:51:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B79CF2064B for ; Thu, 19 Dec 2019 09:51:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726846AbfLSJvT (ORCPT ); Thu, 19 Dec 2019 04:51:19 -0500 Received: from lhrrgout.huawei.com ([185.176.76.210]:2208 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726709AbfLSJvT (ORCPT ); Thu, 19 Dec 2019 04:51:19 -0500 Received: from LHREML714-CAH.china.huawei.com (unknown [172.18.7.108]) by Forcepoint Email with ESMTP id 1ACD64D20BC1B19E079B; Thu, 19 Dec 2019 09:51:17 +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; Thu, 19 Dec 2019 09:51:16 +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; Thu, 19 Dec 2019 09:51:16 +0000 Subject: Re: [Patch v3 3/3] iommu: avoid taking iova_rbtree_lock twice To: Cong Wang , CC: , , References: <20191218043951.10534-1-xiyou.wangcong@gmail.com> <20191218043951.10534-4-xiyou.wangcong@gmail.com> From: John Garry Message-ID: Date: Thu, 19 Dec 2019 09:51:15 +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: <20191218043951.10534-4-xiyou.wangcong@gmail.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.226.46] X-ClientProxiedBy: lhreml712-chm.china.huawei.com (10.201.108.63) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 18/12/2019 04:39, 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 one critical section by calling the unlock > versions instead. > > Cc: Joerg Roedel > Cc: John Garry > Signed-off-by: Cong Wang FWIW: Reviewed-by: John Garry > --- > 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); > 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 81DEDC43603 for ; Thu, 19 Dec 2019 09:51:26 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (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 4F8F92064B for ; Thu, 19 Dec 2019 09:51:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4F8F92064B 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 silver.osuosl.org (Postfix) with ESMTP id 1149720381; Thu, 19 Dec 2019 09:51:26 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ohkWDC3WgVX0; Thu, 19 Dec 2019 09:51:23 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 79DAC23086; Thu, 19 Dec 2019 09:51:23 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5E651C18DC; Thu, 19 Dec 2019 09:51:23 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id D800AC077D for ; Thu, 19 Dec 2019 09:51:21 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id CEEBD86E24 for ; Thu, 19 Dec 2019 09:51:21 +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 5GnPStJyouwB for ; Thu, 19 Dec 2019 09:51:20 +0000 (UTC) X-Greylist: domain 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 880F286B77 for ; Thu, 19 Dec 2019 09:51:20 +0000 (UTC) Received: from LHREML714-CAH.china.huawei.com (unknown [172.18.7.108]) by Forcepoint Email with ESMTP id 1ACD64D20BC1B19E079B; Thu, 19 Dec 2019 09:51:17 +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; Thu, 19 Dec 2019 09:51:16 +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; Thu, 19 Dec 2019 09:51:16 +0000 Subject: Re: [Patch v3 3/3] iommu: avoid taking iova_rbtree_lock twice To: Cong Wang , References: <20191218043951.10534-1-xiyou.wangcong@gmail.com> <20191218043951.10534-4-xiyou.wangcong@gmail.com> From: John Garry Message-ID: Date: Thu, 19 Dec 2019 09:51:15 +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: <20191218043951.10534-4-xiyou.wangcong@gmail.com> Content-Language: en-US X-Originating-IP: [10.202.226.46] X-ClientProxiedBy: lhreml712-chm.china.huawei.com (10.201.108.63) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected Cc: robin.murphy@arm.com, 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 18/12/2019 04:39, 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 one critical section by calling the unlock > versions instead. > > Cc: Joerg Roedel > Cc: John Garry > Signed-off-by: Cong Wang FWIW: Reviewed-by: John Garry > --- > 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