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=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 73DB2C4361B for ; Tue, 15 Dec 2020 00:06:51 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 27DED221EF for ; Tue, 15 Dec 2020 00:06:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 27DED221EF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=wm0gLGIWTMGcpqvTXtlIcd7b5XQrx6uTUi+JX4uTOz4=; b=yG/xzEdEhoYvltqLe8duKTGpU 69dbWlJX3h17y8MUrae+mc+1Pk18KxG1nUTRQsk5A9zuO98IXJLu7aa+fxe3b3trNnJVCFFm3ZMDC qkM6zB57yyuV2YAS5vkHVL1Sz3S2ZovwZTVJ6fTVbr6yKsSytXgGDpuc2LzB3FplZMwzLA5/sDxAb Ln/G8yFb6zvRpzg8ypW3hSgk/r6wP6NiGDeJTTolOb9mhtpZ5RyyW2AA3MHh6sD+SxL2KmVjn3K/D 1AeQaDbcgU6eRU+3tM1HeK6H+K9bIzBsK48X+lCizmELEBXdv6SHZrmNQ+R5Zahej8lGaQ2Dx+qzU ZtHOtEcnQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1koxq6-0007XJ-V6; Tue, 15 Dec 2020 00:05:14 +0000 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1koxq3-0007Wu-AJ for linux-arm-kernel@lists.infradead.org; Tue, 15 Dec 2020 00:05:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607990709; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6g3IZkefy8eigv1Fk+b3mkHNOWy4CEh/CsuZ+osvTpg=; b=fAd4ojfk+K+BE0ipl5Tiav+YiAwJwtnXuGlsRVtddeooTaDs5pKfOAVbot5GybQzgT9TZj 3GBzH5UICeWFoUtoQ5yo0y6Yocr9SwS9FwYXMTzaXwMNsA1j1OsnHAjeMfvEyLE/8Ww79A EHKmU2p4YytPzqO9fatgyG5qAzLnph4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-521-SlUMOcjYPhqQzRsC2yXrMQ-1; Mon, 14 Dec 2020 19:05:04 -0500 X-MC-Unique: SlUMOcjYPhqQzRsC2yXrMQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7820C59; Tue, 15 Dec 2020 00:05:01 +0000 (UTC) Received: from omen.home (ovpn-112-193.phx2.redhat.com [10.3.112.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id A28DC5D9DC; Tue, 15 Dec 2020 00:04:59 +0000 (UTC) Date: Mon, 14 Dec 2020 17:04:59 -0700 From: Alex Williamson To: Keqian Zhu Subject: Re: [PATCH 4/7] vfio: iommu_type1: Fix missing dirty page when promote pinned_scope Message-ID: <20201214170459.50cb8729@omen.home> In-Reply-To: <20201210073425.25960-5-zhukeqian1@huawei.com> References: <20201210073425.25960-1-zhukeqian1@huawei.com> <20201210073425.25960-5-zhukeqian1@huawei.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201214_190511_408178_BA7D58E4 X-CRM114-Status: GOOD ( 23.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jiangkunkun@huawei.com, Andrew Morton , kvm@vger.kernel.org, Suzuki K Poulose , Marc Zyngier , Joerg Roedel , Cornelia Huck , linux-kernel@vger.kernel.org, Sean Christopherson , Alexios Zavras , iommu@lists.linux-foundation.org, Mark Brown , James Morse , Julien Thierry , Catalin Marinas , wanghaibin.wang@huawei.com, Thomas Gleixner , Will Deacon , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, Robin Murphy Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 10 Dec 2020 15:34:22 +0800 Keqian Zhu wrote: > 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. Please don't bury fixes patches into a series with other optimizations and semantic changes. Send it separately. > > 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); > + } > +} If we detach a group which results in only non-IOMMU backed mdevs, don't we also clear dma->iommu_mapped as part of vfio_unmap_unpin() such that this test is invalid? Thanks, Alex > + > 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, _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel