Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp510138pxb; Wed, 3 Mar 2021 08:33:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJx1b3IVwfanRGwtfOOmW8xR4GgbGEFjzVgxoCMYeFIZO0j95yr7A3HQ62ZZlbmPgCRZwPAV X-Received: by 2002:a17:906:a147:: with SMTP id bu7mr25962059ejb.383.1614789223957; Wed, 03 Mar 2021 08:33:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614789223; cv=none; d=google.com; s=arc-20160816; b=Tdvwcd49wnZgd5GAi876PQ64itb7sDFyTSsaviNUgR4ibhXWjNGfwTqPkJ6hbi4ilp hdASNkwYcTk3mPoDkdIapphDDqRjFjrmJobZnM80UKsg7VZCglImgGUzeCL7Wg6PFW+V ooVBa5PbfCDrUxjPLf78BVzO+RqV8hRLWqnVr3hY2iG0ddm1yO9G8VL+NAwPmh1KW9P5 ArFKcZ1kqj3DIKdrv2WjUkChVVs1IJ7b6uePqcSi2zPmLNDlUe/a2ByJWlX5ArryBD0Z YSe/UFR8/KU4VT2DpkKSkqVR0Tk/a9i3349/d2uVsox3IGv41upbSIhd7I3NxA8RzDcW 3SkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6SpMIkv03u+ZtW0ekHIttiPtGRoDBAc0X/RdwzTpyTk=; b=oHTBA8BYCChCfVUIx2rnItv7ZPwLOZ2haBm/I6Vq1fDBDvDzfgzkoK6Cb0WitzFVTP IzzwFOLgKIrx1/a+sNckrXd7G0nUH6HJ51ZEaIv/Lszx171K5ULfMrUOsUOtBiTBWd+Y d2DESoOso9F5fbjBM7ZQ6WbZku28Qp77MT1X7BqvblDW46Q/eeDkkicvPR08WNJGCfXf 1mgKpq25yBv5eLk2P6m8QYnfCBPFOfCdJol2FvgYSLjMee2ebQnMTosweqZoKWT9lmAX 0ghPd9tMBmKiz8keb9tQwhbVlszSq8L1VG0SW+ZOimyYFQ7t6wIMmgNMLUaGprnxoPFX on5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CJPdT2Vf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q3si4169837edc.7.2021.03.03.08.32.51; Wed, 03 Mar 2021 08:33:43 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=CJPdT2Vf; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347312AbhCAXws (ORCPT + 99 others); Mon, 1 Mar 2021 18:52:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:39682 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239357AbhCASTJ (ORCPT ); Mon, 1 Mar 2021 13:19:09 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9AFF66520B; Mon, 1 Mar 2021 17:22:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614619326; bh=cuH7aAYOZaYAQgG1PzHdVOOD6HC21+jin1SqcQACh8k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CJPdT2VfRy+nRU7v3jmu9WCkI9YFgiSW9qABy8foEfD8iDAXp4I3kgIDJvTIFnhEc cMtBPE48KyR2aN4jSYOiKroVd6uJ9tt5MuXFReRQ0tdCOA5ybhReYrHTOA2y3wf1uh khQvDNoTizGeje0pyq5U/hFtFlOvLVFBfSvCCo/U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alex Williamson , Keqian Zhu , Sasha Levin Subject: [PATCH 5.10 414/663] vfio/iommu_type1: Populate full dirty when detach non-pinned group Date: Mon, 1 Mar 2021 17:11:02 +0100 Message-Id: <20210301161202.359213278@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Keqian Zhu [ Upstream commit d0a78f91761fcd837da1e7a4b0f8368873adc646 ] 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 Signed-off-by: Alex Williamson Signed-off-by: Sasha Levin --- 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 67e8276389951..a08b2cb4ec66e 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 @@ detach_group_done: * 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.27.0