Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1073412pxb; Thu, 28 Jan 2021 07:26:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJyRdi3wrY3J3rVaK17KTNVxIlbXsbYBnz5DsoXuL3PRiqDqd+mkr2pnwBvvbPO1GsMr84Vy X-Received: by 2002:a05:6402:31a4:: with SMTP id dj4mr51782edb.156.1611847597564; Thu, 28 Jan 2021 07:26:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611847597; cv=none; d=google.com; s=arc-20160816; b=AeNOdgcVyrOGLBxKXhOhDAF2/1HXIKBxXMmEJazBICXHgDSKVEkJQFAvEvqbh37q8w f8CZcUTA5ytYUh2EKcfV1dxous5et5Gi690WZvYVhEw00D7r+PPM1FL17ucAyYlf5AGU 1rQxHvgZVgzDaVrNVsIru0rEfFSgYQYUh7okEJTiE+tZ/wt53vIiivwMx5QCJB+t9RmD TxtC1uKjnD48wRNiEYDIHvlH9NqyeYFWmmQT6BywcYykavtmQ0cYwkdtSRNmaV+trBbd ACKfzZs+NGtb0CisBSIWCnhxj7CH+S7DU1Lo1f/cicmoQLn2OVyAzGzNC734AGCStosG fOvw== 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=S6PMWgMFxCRy3iw0QhIIBw5PQGUa8XkOOutHbkn/Zh4=; b=Lk8y5ONLfV3Uh9djTBPIGsTiTcuUKADtS6+iKzXTnoRwLZeYbIRx/ffXzdc6rQlHLo TqTIXZDr+Lexr/qi99/jh/fYX6mjn7u5vmsRBSfcmaVplPpnZ6qomDjeB/92u/wLaP1P w5e+wOhS0hpAcwQnon1Uvwnu9c6dyBz8g9xnED2/+Av51VTB3kSiE74a6IecqfMLEFhQ a5xO/BAvyXzl8oEfMEBaSZNtdmYZKcYubFnJi8OJ5XweM7UD25KYA82ImfZdoWPDCEM7 XDuC2MuWTYAN0frdjTQ/NcTa89SJK8PNSzujj1tqmZMMNIb8AvSXzdAYFUb9+T8AS3NA mfYQ== 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 be2si3143967edb.533.2021.01.28.07.26.11; Thu, 28 Jan 2021 07:26:37 -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 S231945AbhA1PWs (ORCPT + 99 others); Thu, 28 Jan 2021 10:22:48 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:12342 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231388AbhA1PSz (ORCPT ); Thu, 28 Jan 2021 10:18:55 -0500 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4DRPG04PzBz7bL1; Thu, 28 Jan 2021 23:16:56 +0800 (CST) Received: from DESKTOP-5IS4806.china.huawei.com (10.174.184.42) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Thu, 28 Jan 2021 23:18:01 +0800 From: Keqian Zhu To: , , , , , Will Deacon , "Alex Williamson" , Marc Zyngier , Catalin Marinas CC: Kirti Wankhede , Cornelia Huck , Mark Rutland , James Morse , "Robin Murphy" , Suzuki K Poulose , , , , Subject: [RFC PATCH 09/11] vfio/iommu_type1: Add HWDBM status maintanance Date: Thu, 28 Jan 2021 23:17:40 +0800 Message-ID: <20210128151742.18840-10-zhukeqian1@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210128151742.18840-1-zhukeqian1@huawei.com> References: <20210128151742.18840-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 From: jiangkunkun We are going to optimize dirty log tracking based on iommu HWDBM feature, but the dirty log from iommu is useful only when all iommu backed groups are connected to iommu with HWDBM feature. This maintains a counter for this feature. Co-developed-by: Keqian Zhu Signed-off-by: Kunkun Jiang --- drivers/vfio/vfio_iommu_type1.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 0b4dedaa9128..3b8522ebf955 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -74,6 +74,7 @@ struct vfio_iommu { bool nesting; bool dirty_page_tracking; bool pinned_page_dirty_scope; + uint64_t num_non_hwdbm_groups; }; struct vfio_domain { @@ -102,6 +103,7 @@ struct vfio_group { struct list_head next; bool mdev_group; /* An mdev group */ bool pinned_page_dirty_scope; + bool iommu_hwdbm; /* Valid for non-mdev group */ }; struct vfio_iova { @@ -976,6 +978,27 @@ static void vfio_update_pgsize_bitmap(struct vfio_iommu *iommu) } } +static int vfio_dev_has_feature(struct device *dev, void *data) +{ + enum iommu_dev_features *feat = data; + + if (!iommu_dev_has_feature(dev, *feat)) + return -ENODEV; + + return 0; +} + +static bool vfio_group_supports_hwdbm(struct vfio_group *group) +{ + enum iommu_dev_features feat = IOMMU_DEV_FEAT_HWDBM; + + if (iommu_group_for_each_dev(group->iommu_group, &feat, + vfio_dev_has_feature)) + return false; + + return true; +} + static int update_user_bitmap(u64 __user *bitmap, struct vfio_iommu *iommu, struct vfio_dma *dma, dma_addr_t base_iova, size_t pgsize) @@ -2189,6 +2212,12 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, * capable via the page pinning interface. */ iommu->pinned_page_dirty_scope = false; + + /* Update the hwdbm status of group and iommu */ + group->iommu_hwdbm = vfio_group_supports_hwdbm(group); + if (!group->iommu_hwdbm) + iommu->num_non_hwdbm_groups++; + mutex_unlock(&iommu->lock); vfio_iommu_resv_free(&group_resv_regions); @@ -2342,6 +2371,7 @@ static void vfio_iommu_type1_detach_group(void *iommu_data, struct vfio_domain *domain; struct vfio_group *group; bool update_dirty_scope = false; + bool update_iommu_hwdbm = false; LIST_HEAD(iova_copy); mutex_lock(&iommu->lock); @@ -2380,6 +2410,7 @@ static void vfio_iommu_type1_detach_group(void *iommu_data, vfio_iommu_detach_group(domain, group); update_dirty_scope = !group->pinned_page_dirty_scope; + update_iommu_hwdbm = !group->iommu_hwdbm; list_del(&group->next); kfree(group); /* @@ -2417,6 +2448,8 @@ static void vfio_iommu_type1_detach_group(void *iommu_data, */ if (update_dirty_scope) update_pinned_page_dirty_scope(iommu); + if (update_iommu_hwdbm) + iommu->num_non_hwdbm_groups--; mutex_unlock(&iommu->lock); } -- 2.19.1