Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp172778pxu; Thu, 7 Jan 2021 01:33:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJybauVc1fwkdM45cmuIr/72x36Ud3N29s6hSMbbNaxRoL5iXchLf39i//hzKDa1eRWh9Xl/ X-Received: by 2002:a50:ed17:: with SMTP id j23mr1027786eds.218.1610011985351; Thu, 07 Jan 2021 01:33:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610011985; cv=none; d=google.com; s=arc-20160816; b=Jau1HeZl4qivM6ze9g6RN1orMNstu1koXh+2ZeJ+td20LpTrJFMxxNirjmZkoKcCDI 98YMXA7xD0hSZqPDSnRUvSxjKZY+9BjNFKpaAgWB8JDgb3HrqYL0r7tP+gCoFt5+GQL9 6C7xV5xtbCmQ98SGxKETHi1PfqTUp8ZquH60D8ZU8YC07oX80RZeR2sUngpxI+WgdsAA IwXz+oGQmeSflFQLm7CEQKT1fm7QmhViK0YMFFoz1L8uuy1l8BGNeGiY2oGXpK/KbZoN lzr0IcaxCSzvadpFCnoaY7lT2u0dW1YGjsp6xMOF66WdHCTg3FsZmP5V8lbH6IjnHPui IVGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=OBpZpQg6o4Hh04alXVeDi/KyUf3VDEWZa8JQwKWL6l0=; b=c1JQABZNWj1UZwHWs5gmc4S1tjn2F0nM++fWnC5XG/uoQiHV7Kfdx3NN25K/BFizmV DpWArJRvXJqyefB1Og9v9JUwflnTkG3QaS6k9dbMGOclghOEhC1UbtT8bgymQJ2d7Z+e g1Wsrhvxz9I4wRnY6s7sfEKlT601JgcohTj/HexrAn9jurxVFNiBxDH1g/6CNItMBIwW BwYdqzbbn0/YQ6cDaZez4aI2jxAdHKeyCIzoJi7+l6IN2iq0fMN9cnlDafjvEFFGVuZ1 g91ZuY6L+Ne7c/rkU0Uia35VxFnbaUj0QFsNstBkp3C4hMunWdOGTKlucGkXgFj0grRZ 3vMw== ARC-Authentication-Results: i=1; mx.google.com; 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 f19si1992553ejx.368.2021.01.07.01.32.41; Thu, 07 Jan 2021 01:33:05 -0800 (PST) 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; 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 S1727847AbhAGJa3 (ORCPT + 99 others); Thu, 7 Jan 2021 04:30:29 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:10034 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727816AbhAGJa2 (ORCPT ); Thu, 7 Jan 2021 04:30:28 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DBLX02xl0zj491; Thu, 7 Jan 2021 17:28:48 +0800 (CST) Received: from DESKTOP-5IS4806.china.huawei.com (10.174.184.42) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Thu, 7 Jan 2021 17:29:34 +0800 From: Keqian Zhu To: , , , , , Alex Williamson , Kirti Wankhede , Cornelia Huck , Will Deacon , Marc Zyngier , Catalin Marinas CC: Mark Rutland , James Morse , Robin Murphy , Joerg Roedel , "Daniel Lezcano" , Thomas Gleixner , Suzuki K Poulose , Julien Thierry , Andrew Morton , Alexios Zavras , , Subject: [PATCH 5/5] vfio/iommu_type1: Move sanity_check_pfn_list to unmap_unpin_all Date: Thu, 7 Jan 2021 17:29:01 +0800 Message-ID: <20210107092901.19712-6-zhukeqian1@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210107092901.19712-1-zhukeqian1@huawei.com> References: <20210107092901.19712-1-zhukeqian1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.184.42] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Both external domain and iommu backend domain can use pinning interface, thus both can add pfn to dma pfn_list. By moving the sanity_check_pfn_list to unmap_unpin_all can apply it to all types of domain. Fixes: a54eb55045ae ("vfio iommu type1: Add support for mediated devices") Signed-off-by: Keqian Zhu --- drivers/vfio/vfio_iommu_type1.c | 38 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 9776a059904d..d796be8bcbc5 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -2225,10 +2225,28 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, return ret; } +static void vfio_sanity_check_pfn_list(struct vfio_iommu *iommu) +{ + struct rb_node *n; + + n = rb_first(&iommu->dma_list); + for (; n; n = rb_next(n)) { + struct vfio_dma *dma; + + dma = rb_entry(n, struct vfio_dma, node); + + if (WARN_ON(!RB_EMPTY_ROOT(&dma->pfn_list))) + break; + } + /* mdev vendor driver must unregister notifier */ + WARN_ON(iommu->notifier.head); +} + static void vfio_iommu_unmap_unpin_all(struct vfio_iommu *iommu) { struct rb_node *node; + vfio_sanity_check_pfn_list(iommu); while ((node = rb_first(&iommu->dma_list))) vfio_remove_dma(iommu, rb_entry(node, struct vfio_dma, node)); } @@ -2256,23 +2274,6 @@ static void vfio_iommu_unmap_unpin_reaccount(struct vfio_iommu *iommu) } } -static void vfio_sanity_check_pfn_list(struct vfio_iommu *iommu) -{ - struct rb_node *n; - - n = rb_first(&iommu->dma_list); - for (; n; n = rb_next(n)) { - struct vfio_dma *dma; - - dma = rb_entry(n, struct vfio_dma, node); - - if (WARN_ON(!RB_EMPTY_ROOT(&dma->pfn_list))) - break; - } - /* mdev vendor driver must unregister notifier */ - WARN_ON(iommu->notifier.head); -} - /* * Called when a domain is removed in detach. It is possible that * the removed domain decided the iova aperture window. Modify the @@ -2371,8 +2372,6 @@ static void vfio_iommu_type1_detach_group(void *iommu_data, kfree(group); if (list_empty(&iommu->external_domain->group_list)) { - vfio_sanity_check_pfn_list(iommu); - /* * During dirty page tracking, we can't remove * vfio_dma because dirty log will lose. @@ -2503,7 +2502,6 @@ static void vfio_iommu_type1_release(void *iommu_data) if (iommu->external_domain) { vfio_release_domain(iommu->external_domain, true); - vfio_sanity_check_pfn_list(iommu); kfree(iommu->external_domain); } -- 2.19.1