Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp45286pxu; Wed, 6 Jan 2021 20:46:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJx7y6JYm8IEAbS5VWdqd97wV0CnKfr5b2pSrtfzCRsEZj8KJeVdpr9YdywqEGa9vSmmRi7j X-Received: by 2002:a17:906:2b50:: with SMTP id b16mr4890933ejg.255.1609994810723; Wed, 06 Jan 2021 20:46:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609994810; cv=none; d=google.com; s=arc-20160816; b=kQQeulvKJInHYsvymulw9lJpl5ljXjYOL4vZvi/x+673XM5gLSNAu9xCQFiFJXY/xi Z5qn5FHSsDSwqxL3oFMdRPzEwMv4YAyFXkIN/Mo4eVGF5/YvG67CTqELDsfNCdETQJ4I YEw6b1DTeOzOsnGrdg7GZANAJvUNkR/gVAhtbQlkWHfZvqLms5MyMi+YrhRsPYnAlWge GJo1B3zxSWKEhRPwt1Cdxoxops14xud9Po2wzG5rd1EqmcL5LsE3VTxSvXvd6n6iGrzK dtNB/9pKLnrrHTYNMr+eFFawSKEoEREU2y3dD8bFOdFq/pAPhZSMS4coRt1g5q22h8bd WuSg== 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=O1MdXnNnDYYdZeduZT8dxjlQezVuAe3zDV3yWMr4wj0=; b=qPAEuF1dG4I+oMmC8YvPf4KjyHh8WTn6dKmLkg4OSjvEwlOyGTCZSPapqmE37o6bz4 EOg+dJu39Yct8ceUB/EgtrQGWYdgZx9sf0FRpmNVlNbmxLcwXIvpnJ2icVozS0/xCZmf bFhw3CcXa3HF4JjcW/0wUbeW5wUXC/2oJShtLfdY/Viw2bQj337cdMh6CPnOqPzlvRNZ tf2gLbqWt5FCUIDAczFOhbEGPQki78EP9he4FE/zsCfhy27i/15HrPJRa7g92rwHCq0H tZxBE2h/adNkjpafdJANEl0pT0lWQhZc+GjRJzpoqvH4dcErQV3GSjLz0RWm7rBAsE3g mGfg== 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 nt21si1677498ejb.739.2021.01.06.20.46.27; Wed, 06 Jan 2021 20:46:50 -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 S1727171AbhAGEpS (ORCPT + 99 others); Wed, 6 Jan 2021 23:45:18 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:9965 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726641AbhAGEpR (ORCPT ); Wed, 6 Jan 2021 23:45:17 -0500 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4DBDC85hsHzj2pY; Thu, 7 Jan 2021 12:43:48 +0800 (CST) Received: from DESKTOP-5IS4806.china.huawei.com (10.174.184.42) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.498.0; Thu, 7 Jan 2021 12:44:26 +0800 From: Keqian Zhu To: , , , , , Alex Williamson , 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 1/6] vfio/iommu_type1: Make an explicit "promote" semantic Date: Thu, 7 Jan 2021 12:43:56 +0800 Message-ID: <20210107044401.19828-2-zhukeqian1@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210107044401.19828-1-zhukeqian1@huawei.com> References: <20210107044401.19828-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 When we want to promote the pinned_page_dirty_scope of vfio_iommu, we call the "update" function to visit all vfio_group, but when we want to downgrade this, we can set the flag as false directly. So we'd better make an explicit "promote" semantic to the "update" function. BTW, if vfio_iommu already has been promoted, then return early. Signed-off-by: Keqian Zhu --- drivers/vfio/vfio_iommu_type1.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 0b4dedaa9128..334a8240e1da 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 @@ -714,7 +714,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; @@ -1622,27 +1622,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; - } } } @@ -2057,8 +2056,7 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, * addition of a dirty tracking group. */ group->pinned_page_dirty_scope = true; - if (!iommu->pinned_page_dirty_scope) - update_pinned_page_dirty_scope(iommu); + promote_pinned_page_dirty_scope(iommu); mutex_unlock(&iommu->lock); return 0; @@ -2341,7 +2339,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); @@ -2349,7 +2347,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); @@ -2379,7 +2377,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); /* @@ -2415,8 +2413,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.19.1