From nobody Thu May 2 18:35:58 2024 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=1617185690; cv=none; d=zohomail.com; s=zohoarc; b=THD+ZTvBhL9NPoHb4tWist+iDcQshrXxU7zXnCI1NXZ8yPJp7TXo/Npw9iehu0MxWO3ltZYXU4ItPeG71a98vErKJRpo5cDuNj7qG5TqkAZ/Wx9xnkcwI7hABkOtIcLyHzTx8s2tlaMubtEsmPqsdlAgJFCzsSTFoKZpgLTi5b4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617185690; 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=jMLQBH9nqoQ0/Lg8nw+ls07p0AACJPYr4QSxSVYSFJk=; b=WDv9al7PC5Kct99/odppn53wpi2Q6AcuYCPxrfVx5Q0ODh0g9zWGTf+lupZJMCSe2AeTPocjqgP+0lXRG+h9+x6gjcrpEjoxGTx3BBfqTDrbGdsHDPVP2uVW+B5xkW40SVn3QO42QxtU+JjJVqFdWHABeB4kqr8oWts81LAeb9w= 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 1617185690101142.41890980948938; Wed, 31 Mar 2021 03:14:50 -0700 (PDT) Received: from localhost ([::1]:46264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRXs9-0003g5-1M for importer@patchew.org; Wed, 31 Mar 2021 06:14:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRXr1-0002U3-4B; Wed, 31 Mar 2021 06:13:40 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4310) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRXqw-0005iF-Jz; Wed, 31 Mar 2021 06:13:38 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4F9MXF1lGKznVL4; Wed, 31 Mar 2021 18:10:53 +0800 (CST) Received: from DESKTOP-6NKE0BC.china.huawei.com (10.174.185.210) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.498.0; Wed, 31 Mar 2021 18:13:21 +0800 From: Kunkun Jiang To: Eric Auger , Peter Maydell , Alex Williamson , , Yi Sun , "open list:ARM SMMU" , "open list:All patches CC here" Subject: [RFC PATCH v2 1/4] vfio: Introduce helpers to mark dirty pages of a RAM section Date: Wed, 31 Mar 2021 18:12:56 +0800 Message-ID: <20210331101259.2153-2-jiangkunkun@huawei.com> X-Mailer: git-send-email 2.26.2.windows.1 In-Reply-To: <20210331101259.2153-1-jiangkunkun@huawei.com> References: <20210331101259.2153-1-jiangkunkun@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.185.210] 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.190; envelope-from=jiangkunkun@huawei.com; helo=szxga04-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, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: Liu Yi L , shameerali.kolothum.thodi@huawei.com, 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" Extract part of the code from vfio_sync_dirty_bitmap to form a new helper, which allows to mark dirty pages of a RAM section. This helper will be called for nested stage. Signed-off-by: Kunkun Jiang --- hw/vfio/common.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 7da1e95b43..3117979307 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1271,6 +1271,19 @@ err_out: return ret; } =20 +static int vfio_dma_sync_ram_section_dirty_bitmap(VFIOContainer *container, + MemoryRegionSection *sec= tion) +{ + ram_addr_t ram_addr; + + ram_addr =3D memory_region_get_ram_addr(section->mr) + + section->offset_within_region; + + return vfio_get_dirty_bitmap(container, + REAL_HOST_PAGE_ALIGN(section->offset_within_address_sp= ace), + int128_get64(section->size), ram_addr); +} + typedef struct { IOMMUNotifier n; VFIOGuestIOMMU *giommu; @@ -1312,8 +1325,6 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier= *n, IOMMUTLBEntry *iotlb) static int vfio_sync_dirty_bitmap(VFIOContainer *container, MemoryRegionSection *section) { - ram_addr_t ram_addr; - if (memory_region_is_iommu(section->mr)) { VFIOGuestIOMMU *giommu; =20 @@ -1342,12 +1353,7 @@ static int vfio_sync_dirty_bitmap(VFIOContainer *con= tainer, return 0; } =20 - ram_addr =3D memory_region_get_ram_addr(section->mr) + - section->offset_within_region; - - return vfio_get_dirty_bitmap(container, - REAL_HOST_PAGE_ALIGN(section->offset_within_address_spa= ce), - int128_get64(section->size), ram_addr); + return vfio_dma_sync_ram_section_dirty_bitmap(container, section); } =20 static void vfio_listener_log_sync(MemoryListener *listener, --=20 2.23.0 From nobody Thu May 2 18:35:58 2024 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=1617185933; cv=none; d=zohomail.com; s=zohoarc; b=TfZ8m/tyU+K9khB4/nFbXfu5dN/S19hSCkNgWhi5Kqyw5mkirMnCEmITMPROfJa2yqF252boJgIF2LBvPZuKhqRtcJJMy1l2ZuCH2/RdXS+2btk5hd2+6mphX7Qe+HIuJV3+9ubsVTbPUlPnzBx1wRzaFucD1ETUfSzraG+qwR8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617185933; 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=Wd/LNLzH/B5LIrkjQpQpI069Xz3QxI3LbFznEjlUcCM=; b=jCJeH1MrzhDb5KougsuKGRuTmy1q0heyR4y23G7AljgoT23Fq/md8y7ZGo90QkenxPSELiocQ1vUo7zZ36Qm0nO2vKNi3GVD/kONGoP/KOCvT6SwAdyKcGq5v35Pafthl5cQ4UTtReOnGEum/9k+Wom8Rxhbg1E3502Z6tL7g8k= 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 1617185933675768.8116444496388; Wed, 31 Mar 2021 03:18:53 -0700 (PDT) Received: from localhost ([::1]:57370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRXw4-0008H5-Kb for importer@patchew.org; Wed, 31 Mar 2021 06:18:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56336) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRXr5-0002X4-MB; Wed, 31 Mar 2021 06:13:43 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4842) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRXr0-0005iE-0N; Wed, 31 Mar 2021 06:13:43 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4F9MXt33c5z1BG04; Wed, 31 Mar 2021 18:11:26 +0800 (CST) Received: from DESKTOP-6NKE0BC.china.huawei.com (10.174.185.210) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.498.0; Wed, 31 Mar 2021 18:13:25 +0800 From: Kunkun Jiang To: Eric Auger , Peter Maydell , Alex Williamson , , Yi Sun , "open list:ARM SMMU" , "open list:All patches CC here" Subject: [RFC PATCH v2 2/4] vfio: Add vfio_prereg_listener_log_sync in nested stage Date: Wed, 31 Mar 2021 18:12:57 +0800 Message-ID: <20210331101259.2153-3-jiangkunkun@huawei.com> X-Mailer: git-send-email 2.26.2.windows.1 In-Reply-To: <20210331101259.2153-1-jiangkunkun@huawei.com> References: <20210331101259.2153-1-jiangkunkun@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.185.210] 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.190; envelope-from=jiangkunkun@huawei.com; helo=szxga04-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, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: Liu Yi L , shameerali.kolothum.thodi@huawei.com, 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" On Intel, the DMA mapped through the host single stage. Instead we set up the stage 2 and stage 1 separately in nested mode as there is no "Caching Mode". Legacy vfio_listener_log_sync cannot be used in nested stage as we don't need to pay close attention to stage 1 mapping. 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 3117979307..86722814d4 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 From nobody Thu May 2 18:35:58 2024 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=1617185860; cv=none; d=zohomail.com; s=zohoarc; b=PdB9NyPF2KUMbT2+8x3gO1dXXsCVauTLFd075/zEkpkz6P7NP9zeMr7ic8EzxQv6VexXDjxAfG+3mgrsL2uPvYkF69oXXsj2/IZpuqQb1bOgrJbA1T+lWVQG8bYyzaDilPS+CHd4jh+QzPk+Jricya7SJdjXVZH1/9ehQ1CNJG0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617185860; 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=bOxz6/H8ZKGrq1dhuw4YPqmAjy7bSaP6shHOpluIELU=; b=GgQJxpGLBdm14NCBSQKc+2n+WyYRTXdbtEzKY3upLoCl3BGcYyxhBTexWdQqjRBRloLSN1CaI8t6vaCr4geiqBAQJpWHb+lc+AgwN1g3XyG2G3pg8VwOAd/F6KjuZhDcEiIHAbyTLYV6fWozOPb0J+jiRScL0jfmxxJEhqTRnYk= 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 1617185860624611.065662560594; Wed, 31 Mar 2021 03:17:40 -0700 (PDT) Received: from localhost ([::1]:53976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRXut-0006uX-BA for importer@patchew.org; Wed, 31 Mar 2021 06:17:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRXr7-0002a4-EW; Wed, 31 Mar 2021 06:13:45 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4492) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRXr5-0005kV-8j; Wed, 31 Mar 2021 06:13:45 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4F9MXz4YfJzyNQb; Wed, 31 Mar 2021 18:11:31 +0800 (CST) Received: from DESKTOP-6NKE0BC.china.huawei.com (10.174.185.210) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.498.0; Wed, 31 Mar 2021 18:13:27 +0800 From: Kunkun Jiang To: Eric Auger , Peter Maydell , Alex Williamson , , Yi Sun , "open list:ARM SMMU" , "open list:All patches CC here" Subject: [RFC PATCH v2 3/4] vfio: Add vfio_prereg_listener_global_log_start/stop in nested stage Date: Wed, 31 Mar 2021 18:12:58 +0800 Message-ID: <20210331101259.2153-4-jiangkunkun@huawei.com> X-Mailer: git-send-email 2.26.2.windows.1 In-Reply-To: <20210331101259.2153-1-jiangkunkun@huawei.com> References: <20210331101259.2153-1-jiangkunkun@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.185.210] 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.191; envelope-from=jiangkunkun@huawei.com; helo=szxga05-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, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: Liu Yi L , shameerali.kolothum.thodi@huawei.com, 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 and stage 1 separately. In my opinion, vfio_memory_prereg_listener is used for stage 2 and vfio_memory_listener is used for stage 1. So it feels weird to call the global_log_start/stop interface in vfio_memory_listener to switch dirty tracking, although this won't cause any errors. Add global_log_start/stop interface in vfio_memory_prereg_listener can separate stage 2 from stage 1. Signed-off-by: Kunkun Jiang --- hw/vfio/common.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 86722814d4..efea252e46 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1209,6 +1209,16 @@ static void vfio_listener_log_global_start(MemoryLis= tener *listener) { VFIOContainer *container =3D container_of(listener, VFIOContainer, lis= tener); =20 + if (container->iommu_type !=3D VFIO_TYPE1_NESTING_IOMMU) { + vfio_set_dirty_page_tracking(container, true); + } +} + +static void vfio_prereg_listener_log_global_start(MemoryListener *listener) +{ + VFIOContainer *container =3D + container_of(listener, VFIOContainer, prereg_listener); + vfio_set_dirty_page_tracking(container, true); } =20 @@ -1216,6 +1226,16 @@ static void vfio_listener_log_global_stop(MemoryList= ener *listener) { VFIOContainer *container =3D container_of(listener, VFIOContainer, lis= tener); =20 + if (container->iommu_type !=3D VFIO_TYPE1_NESTING_IOMMU) { + vfio_set_dirty_page_tracking(container, false); + } +} + +static void vfio_prereg_listener_log_global_stop(MemoryListener *listener) +{ + VFIOContainer *container =3D + container_of(listener, VFIOContainer, prereg_listener); + vfio_set_dirty_page_tracking(container, false); } =20 @@ -1408,6 +1428,8 @@ 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_global_start =3D vfio_prereg_listener_log_global_start, + .log_global_stop =3D vfio_prereg_listener_log_global_stop, .log_sync =3D vfio_prereg_listener_log_sync, }; =20 --=20 2.23.0 From nobody Thu May 2 18:35:58 2024 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=1617185696; cv=none; d=zohomail.com; s=zohoarc; b=SuBABZdZ0dqta/XtEg3x0TP9QRWnv8/WRMad8eIRJpmrWu/B3+vJb+/Dy/trQSnou4owy33/YQr2wc60ieGsXseIqRZgjFOPXAXpQaFS2VgGpvVSGl0juVO0BfJs4hzaxKHgmBRDnfH96xxWd9yaJuU+wy7qNKxGszj/Y2GCddk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617185696; 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=JFc4iUl+TF1Kv/+g9sxHerbPugYuCc1plpVbH0DQub4=; b=mNkn4PSMGpuSmr3cQ6wPk6ep8ONGiOGwWMKsP7mK7S+xNHyxRkvN1RxQbbYrK+/trce14LudCFI+Nk2jdin5mBQ0hI+LNTvRho3xnlsfz3pnCZ2G/1L9JNoslqdBVw+rMSIS4OijUAXAch/MFaR3k2ZE63Hjqw3ifWK3G2gZLo4= 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 1617185696483577.918937076638; Wed, 31 Mar 2021 03:14:56 -0700 (PDT) Received: from localhost ([::1]:46798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lRXsE-0003st-8d for importer@patchew.org; Wed, 31 Mar 2021 06:14:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRXr8-0002dk-Uh; Wed, 31 Mar 2021 06:13:46 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:4491) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lRXr5-0005kU-AL; Wed, 31 Mar 2021 06:13:46 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4F9MXz4wbQzyNQh; Wed, 31 Mar 2021 18:11:31 +0800 (CST) Received: from DESKTOP-6NKE0BC.china.huawei.com (10.174.185.210) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.498.0; Wed, 31 Mar 2021 18:13:30 +0800 From: Kunkun Jiang To: Eric Auger , Peter Maydell , Alex Williamson , , Yi Sun , "open list:ARM SMMU" , "open list:All patches CC here" Subject: [RFC PATCH v2 4/4] hw/arm/smmuv3: Post-load stage 1 configurations to the host Date: Wed, 31 Mar 2021 18:12:59 +0800 Message-ID: <20210331101259.2153-5-jiangkunkun@huawei.com> X-Mailer: git-send-email 2.26.2.windows.1 In-Reply-To: <20210331101259.2153-1-jiangkunkun@huawei.com> References: <20210331101259.2153-1-jiangkunkun@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.185.210] 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.191; envelope-from=jiangkunkun@huawei.com; helo=szxga05-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, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: Liu Yi L , shameerali.kolothum.thodi@huawei.com, 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 call the set_pasid_table() callback on each STE update to pass the guest stage 1 configuration to the host and apply it at physical level. In the case of live migration, we need to manual call the set_pasid_table() to load the guest stage 1 configurations to the host. If this operation is fail, the migration is fail. Signed-off-by: Kunkun Jiang --- hw/arm/smmuv3.c | 62 +++++++++++++++++++++++++++++++++++++++++++++ hw/arm/trace-events | 1 + 2 files changed, 63 insertions(+) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 55aa6ad874..4d28ca3777 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -1534,6 +1534,67 @@ static void smmu_realize(DeviceState *d, Error **err= p) smmu_init_irq(s, dev); } =20 +static int smmuv3_manual_set_pci_device_pasid_table(SMMUDevice *sdev) +{ +#ifdef __linux__ + IOMMUMemoryRegion *mr =3D &(sdev->iommu); + int sid =3D smmu_get_sid(sdev); + SMMUEventInfo event =3D {.type =3D SMMU_EVT_NONE, .sid =3D sid, + .inval_ste_allowed =3D true}; + IOMMUConfig iommu_config =3D {}; + SMMUTransCfg *cfg; + int ret =3D -1; + + cfg =3D smmuv3_get_config(sdev, &event); + if (!cfg) { + return ret; + } + + iommu_config.pasid_cfg.argsz =3D sizeof(struct iommu_pasid_table_confi= g); + iommu_config.pasid_cfg.version =3D PASID_TABLE_CFG_VERSION_1; + iommu_config.pasid_cfg.format =3D IOMMU_PASID_FORMAT_SMMUV3; + iommu_config.pasid_cfg.base_ptr =3D cfg->s1ctxptr; + iommu_config.pasid_cfg.pasid_bits =3D cfg->s1cdmax; + iommu_config.pasid_cfg.vendor_data.smmuv3.version =3D PASID_TABLE_SMMU= V3_CFG_VERSION_1; + iommu_config.pasid_cfg.vendor_data.smmuv3.s1fmt =3D cfg->s1fmt; + iommu_config.pasid_cfg.vendor_data.smmuv3.s1dss =3D cfg->s1dss; + + if (cfg->disabled || cfg->bypassed) { + iommu_config.pasid_cfg.config =3D IOMMU_PASID_CONFIG_BYPASS; + } else if (cfg->aborted) { + iommu_config.pasid_cfg.config =3D IOMMU_PASID_CONFIG_ABORT; + } else { + iommu_config.pasid_cfg.config =3D IOMMU_PASID_CONFIG_TRANSLATE; + } + + ret =3D pci_device_set_pasid_table(sdev->bus, sdev->devfn, &iommu_conf= ig); + if (ret) { + error_report("Failed to pass PASID table to host for iommu mr %s (= %m)", + mr->parent_obj.name); + } + + return ret; +#endif +} + +static int smmuv3_post_load(void *opaque, int version_id) +{ + SMMUv3State *s3 =3D opaque; + SMMUState *s =3D &(s3->smmu_state); + SMMUDevice *sdev; + int ret =3D 0; + + QLIST_FOREACH(sdev, &s->devices_with_notifiers, next) { + trace_smmuv3_post_load_sdev(sdev->devfn, sdev->iommu.parent_obj.na= me); + ret =3D smmuv3_manual_set_pci_device_pasid_table(sdev); + if (ret) { + break; + } + } + + return ret; +} + static const VMStateDescription vmstate_smmuv3_queue =3D { .name =3D "smmuv3_queue", .version_id =3D 1, @@ -1552,6 +1613,7 @@ static const VMStateDescription vmstate_smmuv3 =3D { .version_id =3D 1, .minimum_version_id =3D 1, .priority =3D MIG_PRI_IOMMU, + .post_load =3D smmuv3_post_load, .fields =3D (VMStateField[]) { VMSTATE_UINT32(features, SMMUv3State), VMSTATE_UINT8(sid_size, SMMUv3State), diff --git a/hw/arm/trace-events b/hw/arm/trace-events index b0b0030d24..2f093286ec 100644 --- a/hw/arm/trace-events +++ b/hw/arm/trace-events @@ -54,4 +54,5 @@ smmuv3_notify_flag_add(const char *iommu) "ADD SMMUNotifi= er node for iommu mr=3D%s smmuv3_notify_flag_del(const char *iommu) "DEL SMMUNotifier node for iommu= mr=3D%s" smmuv3_inv_notifiers_iova(const char *name, uint16_t asid, uint64_t iova, = uint8_t tg, uint64_t num_pages) "iommu mr=3D%s asid=3D%d iova=3D0x%"PRIx64"= tg=3D%d num_pages=3D0x%"PRIx64 smmuv3_notify_config_change(const char *name, uint8_t config, uint64_t s1c= txptr) "iommu mr=3D%s config=3D%d s1ctxptr=3D0x%"PRIx64 +smmuv3_post_load_sdev(int devfn, const char *name) "sdev devfn=3D%d iommu = mr=3D%s"PRIx64 =20 --=20 2.23.0