From nobody Mon Feb 9 22:39:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=huawei.com ARC-Seal: i=1; a=rsa-sha256; t=1620699597; cv=none; d=zohomail.com; s=zohoarc; b=cgaj44NIIBOrTSQ1dsz5LCtABy8xMj4MUyAyI+p61G5Y3/XPaFv3Hmb0kyoshgfgN/6UlML2C0+s+W7W0HHHxIYGCVCtHtAoBfxA19Bf7qHI+wfnYEhUm+QL6ub6mtbT7S1W/xrSwtD9HJHglAYeu9r8G7E0J77IvEmzuhy2Zy8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620699597; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=r6ax6kbx0l+h6O+KQQha6LxyT/9G3OW4yfZI6G0NctU=; b=fecfaOb27gct/b4ib1JcZ+Sn5PuhpPrCK/vqJ8qV7FpbFfPA6ZVaPhffnYI9fM/YdoSL3evc7Pm5cfG7UdxcgQPzfbZehVQT6ovGNA76dsd+pbiqCd3w7/qfARxj/e4oNPTCoh5LZNb/u1+Bcf5UNriiUa2TLotgsxi+3j3AwZU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16206995970801021.529133944127; Mon, 10 May 2021 19:19:57 -0700 (PDT) Received: from localhost ([::1]:42264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgI01-00054h-TZ for importer@patchew.org; Mon, 10 May 2021 22:19:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55820) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgHyb-0002ev-Qu; Mon, 10 May 2021 22:18:26 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:2048) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgHyQ-0001vN-4X; Mon, 10 May 2021 22:18:25 -0400 Received: from dggeml703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4FfM3139pczYhYs; Tue, 11 May 2021 10:15:41 +0800 (CST) Received: from dggema765-chm.china.huawei.com (10.1.198.207) by dggeml703-chm.china.huawei.com (10.3.17.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Tue, 11 May 2021 10:18:08 +0800 Received: from DESKTOP-6NKE0BC.china.huawei.com (10.174.185.210) by dggema765-chm.china.huawei.com (10.1.198.207) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Tue, 11 May 2021 10:18:07 +0800 From: Kunkun Jiang To: Eric Auger , Peter Maydell , Alex Williamson , "open list:ARM SMMU" , "open list:All patches CC here" Subject: [RFC PATCH v3 2/4] vfio: Add vfio_prereg_listener_log_sync in nested stage Date: Tue, 11 May 2021 10:08:14 +0800 Message-ID: <20210511020816.2905-3-jiangkunkun@huawei.com> X-Mailer: git-send-email 2.26.2.windows.1 In-Reply-To: <20210511020816.2905-1-jiangkunkun@huawei.com> References: <20210511020816.2905-1-jiangkunkun@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.185.210] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggema765-chm.china.huawei.com (10.1.198.207) X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.188; envelope-from=jiangkunkun@huawei.com; helo=szxga02-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevin.tian@intel.com, Kunkun Jiang , Kirti Wankhede , Zenghui Yu , wanghaibin.wang@huawei.com, Keqian Zhu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" In nested mode, we set up the stage 2 (gpa->hpa)and stage 1 (giova->gpa) separately by vfio_prereg_listener_region_add() and vfio_listener_region_add(). So when marking dirty pages we just need to pay attention to stage 2 mappings. Legacy vfio_listener_log_sync cannot be used in nested stage. This patch adds vfio_prereg_listener_log_sync to mark dirty pages in nested mode. Signed-off-by: Kunkun Jiang --- hw/vfio/common.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 9fb8d44a6d..149e535a75 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1284,6 +1284,22 @@ static int vfio_dma_sync_ram_section_dirty_bitmap(VF= IOContainer *container, int128_get64(section->size), ram_addr); } =20 +static void vfio_prereg_listener_log_sync(MemoryListener *listener, + MemoryRegionSection *section) +{ + VFIOContainer *container =3D + container_of(listener, VFIOContainer, prereg_listener); + + if (!memory_region_is_ram(section->mr) || + !container->dirty_pages_supported) { + return; + } + + if (vfio_devices_all_dirty_tracking(container)) { + vfio_dma_sync_ram_section_dirty_bitmap(container, section); + } +} + typedef struct { IOMMUNotifier n; VFIOGuestIOMMU *giommu; @@ -1328,6 +1344,16 @@ static int vfio_sync_dirty_bitmap(VFIOContainer *con= tainer, if (memory_region_is_iommu(section->mr)) { VFIOGuestIOMMU *giommu; =20 + /* + * In nested mode, stage 2 (gpa->hpa) and stage 1 (giova->gpa) are + * set up separately. It is inappropriate to pass 'giova' to kernel + * to get dirty pages. We only need to focus on stage 2 mapping wh= en + * marking dirty pages. + */ + if (container->iommu_type =3D=3D VFIO_TYPE1_NESTING_IOMMU) { + return 0; + } + QLIST_FOREACH(giommu, &container->giommu_list, giommu_next) { if (MEMORY_REGION(giommu->iommu) =3D=3D section->mr && giommu->n.start =3D=3D section->offset_within_region) { @@ -1382,6 +1408,7 @@ static const MemoryListener vfio_memory_listener =3D { static MemoryListener vfio_memory_prereg_listener =3D { .region_add =3D vfio_prereg_listener_region_add, .region_del =3D vfio_prereg_listener_region_del, + .log_sync =3D vfio_prereg_listener_log_sync, }; =20 static void vfio_listener_release(VFIOContainer *container) --=20 2.23.0