Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4809156pxu; Thu, 10 Dec 2020 06:07:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJxgjbkoiavEdpmPXva2oNMM04Yvm1T3k3JOcd1bByTpkbbsZypPJo07mAyjBRfjU0C8euki X-Received: by 2002:adf:a3c1:: with SMTP id m1mr8857323wrb.28.1607609241103; Thu, 10 Dec 2020 06:07:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607609241; cv=none; d=google.com; s=arc-20160816; b=wJOKBI4d+VKJuAy5jQopt5CeK0c7TWjsmoaC/8DOOlMCkfnuURh/szMYns9VXgcYj8 IwipB2bvU2KQa+vURR5U2ukC0VFs+LiOsy2NCLFI8++GpZSvJZYfwfmHi2anrYDKVfca 0QAppC8p/nyqVlKJxk1s6AdANwKw1RvhfbxIxlJzbDlcqqq6Ya/gcBVoWuY0tfMN08OV GoqTTBKaxmk/NFgeTkWv24BtGhzdTj+ncKeaCaKFwSDGUd88IqHHdMULgOi+AAU2vtth 1XPpbSbAVW6TK0HZOdfOPesPnbO2WjtAWbZ+3NBi8EyxoBvMKSEoR6lRoM/IO+XRHPcH 4xDg== 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=/Oc7QfuhIRP5Q2M4nN862kk4+u228EGXDqy1nBbqRis=; b=Drfoqyo66FCkDVTZ/IcxkK54K1W8s0fKbgijedB5PHJyC32qxqpg1rTsKmDg3ahdFo hldRAirAQxkdYnIUMggH7uYUCIlC4q0VFIK8K8jjoYkAwpthRHd13WTCor9rZTYD915v mBC56uW8KFIIaYFbs8X+cjaFNpJImdGWHRIaF3WYftjEBpejfCjSPEj42yQTGDMkFLIl Fyn9EoIvh6R2h+wtSzq+WHquMO6HKvUmy9uJVdjP8hzRbrqCvDQcqyzGq7VOdcOBbJ/I AgRXohbBZIXc91sCQj4hgLAsYmg0ZzAD/1cUexIhXAPenB08YxlPXAlG9ddAZhR8eBfl t96Q== 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 bt25si2580310ejb.653.2020.12.10.06.06.50; Thu, 10 Dec 2020 06:07:21 -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 S1733261AbgLJHgv (ORCPT + 99 others); Thu, 10 Dec 2020 02:36:51 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:9575 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728974AbgLJHgX (ORCPT ); Thu, 10 Dec 2020 02:36:23 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Cs5KV1B12zM362; Thu, 10 Dec 2020 15:34:54 +0800 (CST) Received: from DESKTOP-5IS4806.china.huawei.com (10.174.187.37) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Thu, 10 Dec 2020 15:35:27 +0800 From: Keqian Zhu To: , , , , , Alex Williamson , Cornelia Huck , Marc Zyngier , Will Deacon , Robin Murphy CC: Joerg Roedel , Catalin Marinas , James Morse , Suzuki K Poulose , Sean Christopherson , Julien Thierry , Mark Brown , "Thomas Gleixner" , Andrew Morton , Alexios Zavras , , , Keqian Zhu Subject: [PATCH 3/7] vfio: iommu_type1: Make an explicit "promote" semantic Date: Thu, 10 Dec 2020 15:34:21 +0800 Message-ID: <20201210073425.25960-4-zhukeqian1@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20201210073425.25960-1-zhukeqian1@huawei.com> References: <20201210073425.25960-1-zhukeqian1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.187.37] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we want to promote pinned_page_scope of vfio_iommu, we should call the "update" function to visit all vfio_group, but when we want to downgrade it, we can set the flag directly. Giving above, we can give an explicit "promote" semantic to that function. BTW, if vfio_iommu has been promoted, then it can return early. Signed-off-by: Keqian Zhu --- drivers/vfio/vfio_iommu_type1.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index c52bcefba96b..bd9a94590ebc 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -148,7 +148,7 @@ static int put_pfn(unsigned long pfn, int prot); static struct vfio_group *vfio_iommu_find_iommu_group(struct vfio_iommu *iommu, struct iommu_group *iommu_group); -static void update_pinned_page_dirty_scope(struct vfio_iommu *iommu); +static void promote_pinned_page_dirty_scope(struct vfio_iommu *iommu); /* * This code handles mapping and unmapping of user data buffers * into DMA'ble space using the IOMMU @@ -719,7 +719,7 @@ static int vfio_iommu_type1_pin_pages(void *iommu_data, group = vfio_iommu_find_iommu_group(iommu, iommu_group); if (!group->pinned_page_dirty_scope) { group->pinned_page_dirty_scope = true; - update_pinned_page_dirty_scope(iommu); + promote_pinned_page_dirty_scope(iommu); } goto pin_done; @@ -1633,27 +1633,26 @@ static struct vfio_group *vfio_iommu_find_iommu_group(struct vfio_iommu *iommu, return group; } -static void update_pinned_page_dirty_scope(struct vfio_iommu *iommu) +static void promote_pinned_page_dirty_scope(struct vfio_iommu *iommu) { struct vfio_domain *domain; struct vfio_group *group; + if (iommu->pinned_page_dirty_scope) + return; + list_for_each_entry(domain, &iommu->domain_list, next) { list_for_each_entry(group, &domain->group_list, next) { - if (!group->pinned_page_dirty_scope) { - iommu->pinned_page_dirty_scope = false; + if (!group->pinned_page_dirty_scope) return; - } } } if (iommu->external_domain) { domain = iommu->external_domain; list_for_each_entry(group, &domain->group_list, next) { - if (!group->pinned_page_dirty_scope) { - iommu->pinned_page_dirty_scope = false; + if (!group->pinned_page_dirty_scope) return; - } } } @@ -2348,7 +2347,7 @@ static void vfio_iommu_type1_detach_group(void *iommu_data, struct vfio_iommu *iommu = iommu_data; struct vfio_domain *domain; struct vfio_group *group; - bool update_dirty_scope = false; + bool promote_dirty_scope = false; LIST_HEAD(iova_copy); mutex_lock(&iommu->lock); @@ -2356,7 +2355,7 @@ static void vfio_iommu_type1_detach_group(void *iommu_data, if (iommu->external_domain) { group = find_iommu_group(iommu->external_domain, iommu_group); if (group) { - update_dirty_scope = !group->pinned_page_dirty_scope; + promote_dirty_scope = !group->pinned_page_dirty_scope; list_del(&group->next); kfree(group); @@ -2386,7 +2385,7 @@ static void vfio_iommu_type1_detach_group(void *iommu_data, continue; vfio_iommu_detach_group(domain, group); - update_dirty_scope = !group->pinned_page_dirty_scope; + promote_dirty_scope = !group->pinned_page_dirty_scope; list_del(&group->next); kfree(group); /* @@ -2422,8 +2421,8 @@ static void vfio_iommu_type1_detach_group(void *iommu_data, * Removal of a group without dirty tracking may allow the iommu scope * to be promoted. */ - if (update_dirty_scope) - update_pinned_page_dirty_scope(iommu); + if (promote_dirty_scope) + promote_pinned_page_dirty_scope(iommu); mutex_unlock(&iommu->lock); } -- 2.23.0