From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5ACA0C433DB for ; Tue, 26 Jan 2021 20:30:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 26BF2221FC for ; Tue, 26 Jan 2021 20:30:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730496AbhAZFPG (ORCPT ); Tue, 26 Jan 2021 00:15:06 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:11438 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726674AbhAYJ3Z (ORCPT ); Mon, 25 Jan 2021 04:29:25 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4DPP6x1KZ8zjBx9; Mon, 25 Jan 2021 17:03:53 +0800 (CST) Received: from DESKTOP-7FEPK9S.china.huawei.com (10.174.186.182) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Mon, 25 Jan 2021 17:04:43 +0800 From: Shenming Lu To: Alex Williamson , Cornelia Huck , , CC: Jean-Philippe Brucker , Eric Auger , Lu Baolu , Kevin Tian , , , Subject: [RFC PATCH v1 1/4] vfio/type1: Add a bitmap to track IOPF mapped pages Date: Mon, 25 Jan 2021 17:03:59 +0800 Message-ID: <20210125090402.1429-2-lushenming@huawei.com> X-Mailer: git-send-email 2.27.0.windows.1 In-Reply-To: <20210125090402.1429-1-lushenming@huawei.com> References: <20210125090402.1429-1-lushenming@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.174.186.182] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When IOPF enabled, the pages are pinned and mapped on demand, we add a bitmap to track them. Signed-off-by: Shenming Lu --- drivers/vfio/vfio_iommu_type1.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 0b4dedaa9128..f1d4de5ab094 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -95,6 +95,7 @@ struct vfio_dma { struct task_struct *task; struct rb_root pfn_list; /* Ex-user pinned pfn list */ unsigned long *bitmap; + unsigned long *iommu_mapped_bitmap; /* IOPF mapped bitmap */ }; struct vfio_group { @@ -143,6 +144,8 @@ struct vfio_regions { #define DIRTY_BITMAP_PAGES_MAX ((u64)INT_MAX) #define DIRTY_BITMAP_SIZE_MAX DIRTY_BITMAP_BYTES(DIRTY_BITMAP_PAGES_MAX) +#define IOMMU_MAPPED_BITMAP_BYTES(n) DIRTY_BITMAP_BYTES(n) + static int put_pfn(unsigned long pfn, int prot); static struct vfio_group *vfio_iommu_find_iommu_group(struct vfio_iommu *iommu, @@ -949,6 +952,7 @@ static void vfio_remove_dma(struct vfio_iommu *iommu, struct vfio_dma *dma) vfio_unlink_dma(iommu, dma); put_task_struct(dma->task); vfio_dma_bitmap_free(dma); + kfree(dma->iommu_mapped_bitmap); kfree(dma); iommu->dma_avail++; } @@ -1354,6 +1358,14 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu, goto out_unlock; } + dma->iommu_mapped_bitmap = kvzalloc(IOMMU_MAPPED_BITMAP_BYTES(size / PAGE_SIZE), + GFP_KERNEL); + if (!dma->iommu_mapped_bitmap) { + ret = -ENOMEM; + kfree(dma); + goto out_unlock; + } + iommu->dma_avail--; dma->iova = iova; dma->vaddr = vaddr; -- 2.19.1