Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4590138pxu; Wed, 9 Dec 2020 23:47:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJxy7Dfyrjb+bPu1IOlGZraBZwVH6J4fO97bKVuU4i3fIJvq8VnjcRlkjbq0qbsU2C1ZPz3d X-Received: by 2002:a17:906:3294:: with SMTP id 20mr5343595ejw.239.1607586435364; Wed, 09 Dec 2020 23:47:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607586435; cv=none; d=google.com; s=arc-20160816; b=fLkgP1auyjWmJda8Vh5slOoXXR/UvQWLakA1zQkthB0Ci8J9b0MXr9ZyYlkDxtQ3Hp uzsPc/W2nRAFDOSjaL28Vv8ApwUyDdkSrDGSiGtIDaid2KDI26CIQe3qU6ImfmxTNO0f W+gKPhK70zymLJ6wnf6O7Z/BOYzvOlSBBBl6lawlBw9pMDbpWuHd3VeWUOZJEmKryXPI 8Ya6/9ft+lL+5TaQRY21U5MsToqUn0bYD1RrFaoSarffXVn+q5NGhUk9LoGHnvMiCRBI 3ucmiBvPGE0eyOqAhA8iGRKisWtmMIlaJkRrTgk7Om/YbpTkgMcq4s48bTJKSnIUfl1w Jraw== 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=x4pp94mzeNLP0i/9S+r06AhSy8CJ7C69vNCj7SmEmiY=; b=YuT1Yjv1ZgxabaNtECtyfH5Qfseivy4m4EDvwGv6GpDJuK6RKzxBT8b7JzmsffzhRv Mta7r1wEtPGCCtyebMZtCXsCESZh4Q2e4XSe86u/JsV8pvWav5fRBepICdhZrLCZzoJH WQCP4jUMUdQtce0/adTtcacyM47Z4BnJBZQnqMb31BzsKHT+JNrofkjQ3fi4ioiOUF8u 65DNPzODowmHIQm1k+1FkBWxCmp/FuGniqqgRZDGs17SG1N6jPRSx1xJfyNN03b8p2vG dRPsrVnnsI5vfw5IBjXnEFkQK+1U/uZBlxB7x9fQgWUvD32J7ugw5eLJkfS8KLpDLWZ6 yAFw== 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 n23si2011511ejr.321.2020.12.09.23.46.52; Wed, 09 Dec 2020 23:47:15 -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 S1733161AbgLJHgT (ORCPT + 99 others); Thu, 10 Dec 2020 02:36:19 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:9574 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729945AbgLJHgT (ORCPT ); Thu, 10 Dec 2020 02:36:19 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Cs5KV1ZwPzM365; Thu, 10 Dec 2020 15:34:54 +0800 (CST) Received: from DESKTOP-5IS4806.china.huawei.com (10.174.187.37) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Thu, 10 Dec 2020 15:35:28 +0800 From: Keqian Zhu To: , , , , , Alex Williamson , Cornelia Huck , Marc Zyngier , Will Deacon , Robin Murphy CC: Joerg Roedel , Catalin Marinas , James Morse , Suzuki K Poulose , Sean Christopherson , Julien Thierry , Mark Brown , "Thomas Gleixner" , Andrew Morton , Alexios Zavras , , , Keqian Zhu Subject: [PATCH 4/7] vfio: iommu_type1: Fix missing dirty page when promote pinned_scope Date: Thu, 10 Dec 2020 15:34:22 +0800 Message-ID: <20201210073425.25960-5-zhukeqian1@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20201210073425.25960-1-zhukeqian1@huawei.com> References: <20201210073425.25960-1-zhukeqian1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.187.37] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When we pin or detach a group which is not dirty tracking capable, we will try to promote pinned_scope of vfio_iommu. If we succeed to do so, vfio only report pinned_scope as dirty to userspace next time, but these memory written before pin or detach is missed. The solution is that we must populate all dma range as dirty before promoting pinned_scope of vfio_iommu. Signed-off-by: Keqian Zhu --- drivers/vfio/vfio_iommu_type1.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index bd9a94590ebc..00684597b098 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -1633,6 +1633,20 @@ static struct vfio_group *vfio_iommu_find_iommu_group(struct vfio_iommu *iommu, return group; } +static void vfio_populate_bitmap_all(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); + unsigned long nbits = dma->size >> pgshift; + + if (dma->iommu_mapped) + bitmap_set(dma->bitmap, 0, nbits); + } +} + static void promote_pinned_page_dirty_scope(struct vfio_iommu *iommu) { struct vfio_domain *domain; @@ -1657,6 +1671,10 @@ static void promote_pinned_page_dirty_scope(struct vfio_iommu *iommu) } iommu->pinned_page_dirty_scope = true; + + /* Set all bitmap to avoid missing dirty page */ + if (iommu->dirty_page_tracking) + vfio_populate_bitmap_all(iommu); } static bool vfio_iommu_has_sw_msi(struct list_head *group_resv_regions, -- 2.23.0