Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp940616pxb; Fri, 22 Jan 2021 03:13:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJwOCCZEkBAJpoBMDIh5yzzpuuxJiJSRdWRupjzyZyYGgEyFsvS8t8rp+gr5Km8JrIehfnML X-Received: by 2002:a17:906:fc5:: with SMTP id c5mr2217800ejk.538.1611314002226; Fri, 22 Jan 2021 03:13:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611314002; cv=none; d=google.com; s=arc-20160816; b=F4UtQE64P0UWYAcb8VKLyKRmckpmhID/lE8RCA9J4q+kTMEX1Xrg9+uYs49BTzNkKT owO21WeNkKOaxV6G9zWfUDgFN2vOr7WY0TxszlIJ+ZZILYxz+jrGoXZG7LV5Itskh5ZU z4BMTlP7qPhujjHDXvZQQTteBRlLpURNS+YJdm4VF/LESpo6jvketlc5Qun4JW+slODF oG3GWGFs0x5I1G6c14dJ5YK6UjdRsPPQBADL+ybv5qzzzNPF6cjaWtZ30G6OgMu/964L 2H2axefImVSuBBiAbqozV7CtJ+Ued3hE9AqaK6BN7fgbNL8OvUN3ByEewWVmT7jlTEu1 T3cg== 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=3dTtQzUAlXgcWO88kyL+HR6olZNUkSZ4V1VoVhwm/ws=; b=L+kdVC8C9dbJ773RFtQu/Dk5IqikfE6ET4nrOvqyXcCHgbIOmRNbW/OfA+IYHw+udT XJu/HvtphX1bLLoj0PD8moRXlW1Gy2anvn+11wXbDuqWXp+NtBD4IgSVKaW4stxe6mOJ Cd9o3Ew9/Te5Adga24leEdEGbQQXNGydcGAIUrL4d4dQ09Bg8O0XNzdeP/PUFH2E7Big +8I7fWLDYBXDimanNvPFFaEljBQ+5DACwAdRkK799nV9WUF4waLrHY0Vo3GlFEKrguyU S7oxZoVdG/fdEzVVSPtp2OgiFJuJgSgghJdDla82jEm+XJcjpO95M+2F6NbTOGp0A7Pl HEEQ== 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 uz17si2924296ejb.591.2021.01.22.03.12.58; Fri, 22 Jan 2021 03:13:22 -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 S1727993AbhAVLHi (ORCPT + 99 others); Fri, 22 Jan 2021 06:07:38 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:11125 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727215AbhAVJ1o (ORCPT ); Fri, 22 Jan 2021 04:27:44 -0500 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DMYld4qd8z15vnr; Fri, 22 Jan 2021 17:25:49 +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; Fri, 22 Jan 2021 17:26:48 +0800 From: Keqian Zhu To: , , , , , Alex Williamson , Kirti Wankhede , "Cornelia Huck" CC: Will Deacon , Marc Zyngier , "Catalin Marinas" , Mark Rutland , "James Morse" , Robin Murphy , "Joerg Roedel" , Daniel Lezcano , "Thomas Gleixner" , Suzuki K Poulose , Julien Thierry , Andrew Morton , Alexios Zavras , , Subject: [PATCH v3 1/2] vfio/iommu_type1: Populate full dirty when detach non-pinned group Date: Fri, 22 Jan 2021 17:26:34 +0800 Message-ID: <20210122092635.19900-2-zhukeqian1@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210122092635.19900-1-zhukeqian1@huawei.com> References: <20210122092635.19900-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 If a group with non-pinned-page dirty scope is detached with dirty logging enabled, we should fully populate the dirty bitmaps at the time it's removed since we don't know the extent of its previous DMA, nor will the group be present to trigger the full bitmap when the user retrieves the dirty bitmap. Fixes: d6a4c185660c ("vfio iommu: Implementation of ioctl for dirty pages tracking") Suggested-by: Alex Williamson Signed-off-by: Keqian Zhu --- drivers/vfio/vfio_iommu_type1.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 0b4dedaa9128..161725395f2f 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -236,6 +236,18 @@ static void vfio_dma_populate_bitmap(struct vfio_dma *dma, size_t pgsize) } } +static void vfio_iommu_populate_bitmap_full(struct vfio_iommu *iommu) +{ + struct rb_node *n; + unsigned long pgshift = __ffs(iommu->pgsize_bitmap); + + for (n = rb_first(&iommu->dma_list); n; n = rb_next(n)) { + struct vfio_dma *dma = rb_entry(n, struct vfio_dma, node); + + bitmap_set(dma->bitmap, 0, dma->size >> pgshift); + } +} + static int vfio_dma_bitmap_alloc_all(struct vfio_iommu *iommu, size_t pgsize) { struct rb_node *n; @@ -2415,8 +2427,11 @@ 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) + if (update_dirty_scope) { update_pinned_page_dirty_scope(iommu); + if (iommu->dirty_page_tracking) + vfio_iommu_populate_bitmap_full(iommu); + } mutex_unlock(&iommu->lock); } -- 2.19.1