Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp96641pxf; Wed, 10 Mar 2021 01:09:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJxcHDRUq3nnrjnr/zbMtiula5y3dYkbfyQ6lp8OxC5BUG9ktBErGrvfjaOMJlWQCYHrfVtu X-Received: by 2002:aa7:dc56:: with SMTP id g22mr2118389edu.219.1615367368705; Wed, 10 Mar 2021 01:09:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615367368; cv=none; d=google.com; s=arc-20160816; b=BRQNBrReibGHiUQTNWaaniXBKeL79cp6C6hanLkcvmj+C0Z7yO7iINh/IIJ2bnX585 Ah55rwkPE2d9yw67gRzeFusjWS07nzMsXCopqFmwPtQzDE8Ip2HPBLtYIWcTYifV9I61 1VS3FLKP8LUA2jT07P+qLLEhDlDOI/f/JlV7wmAscmRDFd6B7KSClASszZZa9By1rPTG xY+DI2R2G/b4bcUC6AZ87a1IO8wj14i89WCofRRXKXRO5qAPqedx63/SAndxTrF1IDL0 wOMDs9rhuDbOQ3YJOY67OOr6TIzNIE4ax6/Dj7cnqcpzXROaZ5R1y4yJtdZ9FcpomzP5 jONQ== 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=CaOe+TShJrqoNK8L3/eJAXUdFEv2R9b3g7ZggUY95mk=; b=uhnRORZNX4jDb80g0XwzsFWtN2fPtcD9t9QZ4nuj395NXrn1BKAmAIb9FFVxdnHEL/ 61AWy1rJl2Bn/76KPz33bTE2+WX6yU8GcupJh+xavnqXvpSyTE+DbXCDlmkJSbBbk4tZ eYXV06qfvmnDnj+YA855tZA9YjsXntAu3Vr4mtzr5Mw04yvS3xNMNwHFNQSTJqoCHhsn xbXFOoKRLN3DihtKRJrJ+Tj1++MmnN4N/vv9qNnCYN7iBkr37fG/PsWvGkGY0oIZSGqY hdzzS905Qzgsn+LHn2AWCnuAnSAu7awUgewN57Sby+D9QNYRpL38HXhrw3wfJ4IsbkW7 jHDw== 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 p5si11236091edt.50.2021.03.10.01.09.06; Wed, 10 Mar 2021 01:09:28 -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 S232790AbhCJJH1 (ORCPT + 99 others); Wed, 10 Mar 2021 04:07:27 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:13877 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232672AbhCJJGy (ORCPT ); Wed, 10 Mar 2021 04:06:54 -0500 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4DwR400qkwz8vtv; Wed, 10 Mar 2021 17:05:04 +0800 (CST) Received: from DESKTOP-5IS4806.china.huawei.com (10.174.184.42) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.498.0; Wed, 10 Mar 2021 17:06:26 +0800 From: Keqian Zhu To: , , , Alex Williamson , Robin Murphy , Yi Sun , Will Deacon CC: Kirti Wankhede , Cornelia Huck , Marc Zyngier , Catalin Marinas , Mark Rutland , James Morse , Suzuki K Poulose , , , , Subject: [PATCH v2 09/11] vfio/iommu_type1: Add HWDBM status maintanance Date: Wed, 10 Mar 2021 17:06:12 +0800 Message-ID: <20210310090614.26668-10-zhukeqian1@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210310090614.26668-1-zhukeqian1@huawei.com> References: <20210310090614.26668-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 --- changelog: v2: - Simplify vfio_group_supports_hwdbm(). - AS feature report of HWDBM has been changed, so change vfio_dev_has_feature() to vfio_dev_enable_feature(). --- drivers/vfio/vfio_iommu_type1.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 4bb162c1d649..876351c061e4 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -79,6 +79,7 @@ struct vfio_iommu { bool dirty_page_tracking; bool pinned_page_dirty_scope; bool container_open; + uint64_t num_non_hwdbm_groups; }; struct vfio_domain { @@ -116,6 +117,7 @@ struct vfio_group { struct list_head next; bool mdev_group; /* An mdev group */ bool pinned_page_dirty_scope; + bool iommu_hwdbm; /* For iommu-backed group */ }; struct vfio_iova { @@ -1187,6 +1189,24 @@ static void vfio_update_pgsize_bitmap(struct vfio_iommu *iommu) } } +static int vfio_dev_enable_feature(struct device *dev, void *data) +{ + enum iommu_dev_features *feat = data; + + if (iommu_dev_feature_enabled(dev, *feat)) + return 0; + + return iommu_dev_enable_feature(dev, *feat); +} + +static bool vfio_group_supports_hwdbm(struct vfio_group *group) +{ + enum iommu_dev_features feat = IOMMU_DEV_FEAT_HWDBM; + + return !iommu_group_for_each_dev(group->iommu_group, &feat, + vfio_dev_enable_feature); +} + static int update_user_bitmap(u64 __user *bitmap, struct vfio_iommu *iommu, struct vfio_dma *dma, dma_addr_t base_iova, size_t pgsize) @@ -2435,6 +2455,12 @@ static int vfio_iommu_type1_attach_group(void *iommu_data, * capable via the page pinning interface. */ iommu->num_non_pinned_groups++; + + /* 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); @@ -2571,6 +2597,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); @@ -2609,6 +2636,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); /* @@ -2651,6 +2679,8 @@ static void vfio_iommu_type1_detach_group(void *iommu_data, if (iommu->dirty_page_tracking) vfio_iommu_populate_bitmap_full(iommu); } + if (update_iommu_hwdbm) + iommu->num_non_hwdbm_groups--; mutex_unlock(&iommu->lock); } -- 2.19.1